nvm.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /****************************************************************************
  2. Copyright (c) 2013-2022, Qualcomm Technologies, Inc.
  3. All Rights Reserved.
  4. Confidential and Proprietary - Qualcomm Technologies, Inc.
  5. **********************************************************************
  6. 2013 Qualcomm Atheros, Inc.
  7. ****************************************************************************/
  8. /*====================================================================*
  9. *
  10. * nvm.h - nvm file format definitions and declarations;
  11. *
  12. * Contributor(s):
  13. * Charles Maier <cmaier@qca.qualcomm.com>
  14. *
  15. *--------------------------------------------------------------------*/
  16. #ifndef NVM_HEADER
  17. #define NVM_HEADER
  18. /*====================================================================*
  19. * system header files;
  20. *--------------------------------------------------------------------*/
  21. #include <unistd.h>
  22. /*====================================================================*
  23. * custom header files;
  24. *--------------------------------------------------------------------*/
  25. #include "../tools/types.h"
  26. /*====================================================================*
  27. * nvm program constants;
  28. *--------------------------------------------------------------------*/
  29. #define NVM_IMAGETYPES 18
  30. #define NVM_PLATFORMS 5
  31. /*====================================================================*
  32. * nvm program flags;
  33. *--------------------------------------------------------------------*/
  34. #define NVM_SILENCE (1 << 0)
  35. #define NVM_VERBOSE (1 << 1)
  36. #define NVM_MANIFEST (1 << 2)
  37. #define NVM_REVISION (1 << 3)
  38. #define NVM_IDENTITY (1 << 4)
  39. #define NVM_SDRAM (1 << 5)
  40. #define NVM_PUBLISH (1 << 6)
  41. /*====================================================================*
  42. * nvm header execute masks;
  43. *--------------------------------------------------------------------*/
  44. #define NVM_IGNORE_MASK_INT6000 (1 << 0)
  45. #define NVM_IGNORE_MASK_INT6300 (1 << 1)
  46. #define NVM_IGNORE_MASK_INT6400 (1 << 2)
  47. #define NVM_IGNORE_MASK_AR7400 (1 << 4)
  48. #define NVM_IGNORE_MASK_QCA7420 (1 << 8)
  49. /*====================================================================*
  50. * image chain types;
  51. *--------------------------------------------------------------------*/
  52. #define NVM_CHAIN_SOFTLOADER 0
  53. #define NVM_CHAIN_FIRMWARE 1
  54. #define NVM_CHAIN_PIB 2
  55. #define NVM_CHAIN_CUSTOM_MODULE 3
  56. #define NVM_CHAIN_MODULE_OP_SESSION 4
  57. /*====================================================================*
  58. * nvm build types;
  59. *--------------------------------------------------------------------*/
  60. #define NVM_BUILD_NIGHTLY 0
  61. #define NVM_BUILD_RELEASE 1
  62. #define NVM_BUILD_CUSTOM 2
  63. /*====================================================================*
  64. * nvm image types;
  65. *--------------------------------------------------------------------*/
  66. #define NVM_IMAGE_GENERIC 0x0000
  67. #define NVM_IMAGE_CONFIG_SYNOPSIS 0x0001
  68. #define NVM_IMAGE_CONFIG_DENALI 0x0002
  69. #define NVM_IMAGE_APPLET_DENALI 0x0003
  70. #define NVM_IMAGE_FIRMWARE 0x0004
  71. #define NVM_IMAGE_OASCLIENT 0x0005
  72. #define NVM_IMAGE_CUSTOM 0x0006
  73. #define NVM_IMAGE_MEMCTL 0x0007
  74. #define NVM_IMAGE_ADVPWRMGMT 0x0008
  75. #define NVM_IMAGE_OAS_CLIENT_IP_STK 0x0009
  76. #define NVM_IMAGE_OAS_CLIENT_TR069 0x000A
  77. #define NVM_IMAGE_NVM_SOFTLOADER 0x000B
  78. #define NVM_IMAGE_FLASH_LAYOUT 0x000C
  79. #define NVM_IMAGE_MANIFEST 0x000E
  80. #define NVM_IMAGE_PIB 0x000F
  81. /*====================================================================*
  82. * manifest field types;
  83. *--------------------------------------------------------------------*/
  84. #define NVM_FIELD_SIGNATURE 0
  85. #define NVM_FIELD_HARDWARE_COMPAT 1
  86. #define NVM_FIELD_CHAIN_MAJOR_VERSION 2
  87. #define NVM_FIELD_CHAIN_MINOR_VERSION 3
  88. #define NVM_FIELD_CHAIN_TYPE 4
  89. #define NVM_FIELD_BUILD_MAJOR_VERSION 5
  90. #define NVM_FIELD_BUILD_MINOR_VERSION 6
  91. #define NVM_FIELD_BUILD_TYPE 7
  92. #define NVM_FIELD_MANIFEST_VERSION 8
  93. #define NVM_FIELD_BUILD_NUMBER 9
  94. #define NVM_FIELD_BUILD_DATE 10
  95. #define NVM_FIELD_BUILD_TIME 11
  96. #define NVM_FIELD_DEVICE_TYPE 12
  97. #define NVM_FIELD_BUILD_HOSTNAME 13
  98. #define NVM_FIELD_BUILD_USERNAME 14
  99. #define NVM_FIELD_BUILD_DESCRIPTION 15
  100. #define NVM_FIELD_BUILD_VERSION_STRING 16
  101. #define NVM_FIELD_BUILD_SUSTAINING_RELEASE 17
  102. #define NVM_FIELD_BUILD_MAJOR_SUBVERSION 18
  103. #define NVM_FIELD_GENERIC_ID0 19
  104. #define NVM_FIELD_GENERIC_ID1 20
  105. #define NVM_FIELD_SL_MAJOR_VERSION 21
  106. #define NVM_FIELD_SL_MINOR_VERSION 22
  107. #define NVM_FIELD_FREE_SPACE 23
  108. /*====================================================================*
  109. * toolkit nvm error messages;
  110. *--------------------------------------------------------------------*/
  111. #define NVM_HDR_VERSION "%s found bad NVM header version in %s module %d", __func__
  112. #define NVM_HDR_CHECKSUM "%s found bad NVM header checksum in %s module %d", __func__
  113. #define NVM_HDR_LINK "%s found bad NVM header link in %s module %d", __func__
  114. #define NVM_IMG_CHECKSUM "%s found bad image checksum in %s module %d", __func__
  115. #define NVM_HDR_CANTREAD "%s can't read image header in %s module %d", __func__
  116. #define NVM_HDR_CANTSAVE "%s can't save image header in %s module %d", __func__
  117. #define NVM_IMG_CANTREAD "%s can't read image in %s module %d", __func__
  118. #define NVM_IMG_CANTSAVE "%s can't save image in %s module %d", __func__
  119. #define NVM_IMG_RUN "%s applet %d is still running"
  120. /*====================================================================*
  121. * old nvm image header (44 bytes);
  122. *--------------------------------------------------------------------*/
  123. #ifndef __GNUC__
  124. #pragma pack (push,1)
  125. #endif
  126. typedef struct __packed lightning_nvm_header
  127. {
  128. uint32_t HEADERVERSION;
  129. uint32_t IMAGEROMADDR;
  130. uint32_t IMAGEADDRESS;
  131. uint32_t IMAGELENGTH;
  132. uint32_t IMAGECHECKSUM;
  133. uint32_t ENTRYPOINT;
  134. uint8_t HEADERMINORVERSION;
  135. uint8_t IMAGETYPE;
  136. uint16_t IGNOREMASK;
  137. uint32_t MODULEID;
  138. uint32_t MODULESUBID;
  139. uint32_t NEXTHEADER;
  140. uint32_t HEADERCHECKSUM;
  141. }
  142. lightning_header;
  143. #ifndef __GNUC__
  144. #pragma pack (pop)
  145. #endif
  146. /*====================================================================*
  147. * new nvm image header (96 bytes);
  148. *--------------------------------------------------------------------*/
  149. #ifndef __GNUC__
  150. #pragma pack (push,1)
  151. #endif
  152. typedef struct __packed panther_nvm_header
  153. {
  154. uint16_t MajorVersion;
  155. uint16_t MinorVersion;
  156. uint32_t ExecuteMask;
  157. uint32_t ImageNvmAddress;
  158. uint32_t ImageAddress;
  159. uint32_t ImageLength;
  160. uint32_t ImageChecksum;
  161. uint32_t EntryPoint;
  162. uint32_t NextHeader;
  163. uint32_t PrevHeader;
  164. uint32_t ImageType;
  165. uint16_t ModuleID;
  166. uint16_t ModuleSubID;
  167. uint16_t AppletEntryVersion;
  168. uint16_t Reserved0;
  169. uint32_t Reserved1;
  170. uint32_t Reserved2;
  171. uint32_t Reserved3;
  172. uint32_t Reserved4;
  173. uint32_t Reserved5;
  174. uint32_t Reserved6;
  175. uint32_t Reserved7;
  176. uint32_t Reserved8;
  177. uint32_t Reserved9;
  178. uint32_t Reserved10;
  179. uint32_t Reserved11;
  180. uint32_t HeaderChecksum;
  181. }
  182. panther_header;
  183. #ifndef __GNUC__
  184. #pragma pack (pop)
  185. #endif
  186. #ifndef __GNUC__
  187. #pragma pack (push,1)
  188. #endif
  189. typedef struct __packed Revision
  190. {
  191. char const* hardware;
  192. uint32_t device_type;
  193. char software[4];
  194. uint16_t build;
  195. uint32_t date;
  196. char const* type;
  197. } Revision;
  198. #ifndef __GNUC__
  199. #pragma pack (pop)
  200. #endif
  201. /*====================================================================*
  202. * nvm functions;
  203. *--------------------------------------------------------------------*/
  204. void * manifetch (void const * memory, size_t extent, uint32_t type);
  205. signed nvmfile (struct _file_ const *);
  206. void nvmpeek (void const *);
  207. signed fdmanifest (signed fd, char const * filename, struct panther_nvm_header *);
  208. signed fdrevision (signed fd, char const * filename, struct panther_nvm_header *);
  209. signed lightning_nvm_file (struct _file_ const *);
  210. void lightning_nvm_peek (void const *);
  211. signed lightning_nvm_seek (signed fd, char const * filename, struct lightning_nvm_header *, uint32_t imagetype);
  212. unsigned lightning_nvm_size (signed fd, char const * filename);
  213. signed panther_nvm_file (struct _file_ const *);
  214. void panther_nvm_peek (void const *);
  215. signed panther_nvm_manifest (void const * memory, size_t extent);
  216. signed panther_nvm_revision (void const * memory, size_t extent);
  217. signed panther_nvm_revision_forChkpib(void const* memory, size_t extent, struct Revision*);
  218. signed panther_nvm_seek (signed fd, char const * filename, struct panther_nvm_header *, uint32_t imagetype);
  219. signed panther_nvm_seek2(signed fd, char const* filename, struct panther_nvm_header* header, uint32_t imagetype, bool repairchksum);
  220. unsigned panther_nvm_size (signed fd, char const * filename);
  221. /*====================================================================*
  222. *
  223. *--------------------------------------------------------------------*/
  224. #endif