FLASH.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * flash - driver for FLASH ROM
  3. *
  4. * Copyright (c) 2009 Openmoko Inc.
  5. *
  6. * Authors Christopher Hall <hsw@openmoko.com>
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #if !defined(_FLASH_H_)
  22. #define _FLASH_H_ 1
  23. #include <stdbool.h>
  24. #include <inttypes.h>
  25. enum {
  26. // basic FLASH parameters
  27. FLASH_PageSize = 256, // maximum bytes to program in one write
  28. FLASH_SectorSize = 4096,
  29. FLASH_TotalBytes = 65536,
  30. FLASH_TotalSectore = FLASH_TotalBytes / FLASH_SectorSize,
  31. // addresses of known items
  32. FLASH_SerialNumberAddress = 0x1fe0, // just ASCII characters (0x00 or 0xff padded)
  33. FLASH_SerialNumberSize = 32,
  34. FLASH_RevisionNumberAddress = 0x02f0, // 1st 4 bytes (uint32_t) used as simple number
  35. FLASH_RevisionNumberSize = 16,
  36. };
  37. void FLASH_initialise(void);
  38. // this is the default case
  39. void FLASH_SelectInternal(void);
  40. // allow access to test jig flash
  41. // only for production testing
  42. void FLASH_SelectExternal(void);
  43. // must call before any write/erase
  44. // it is only active for one command
  45. bool FLASH_WriteEnable(void);
  46. bool FLASH_read(void *buffer, size_t size, uint32_t ROMAddress);
  47. bool FLASH_write(const void *buffer, size_t size, uint32_t ROMAddress);
  48. bool FLASH_verify(const uint8_t *buffer, size_t size, uint32_t ROMAddress);
  49. bool FLASH_SectorErase(uint32_t ROMAddress);
  50. bool FLASH_ChipErase(void);
  51. #endif