nvm.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * nvm.h - nvm file format definitions and declarations;
  44. *
  45. * Contributor(s):
  46. * Charles Maier
  47. *
  48. *--------------------------------------------------------------------*/
  49. #ifndef NVM_HEADER
  50. #define NVM_HEADER
  51. /*====================================================================*
  52. * system header files;
  53. *--------------------------------------------------------------------*/
  54. #include <unistd.h>
  55. /*====================================================================*
  56. * custom header files;
  57. *--------------------------------------------------------------------*/
  58. #include "../tools/types.h"
  59. /*====================================================================*
  60. * nvm program constants;
  61. *--------------------------------------------------------------------*/
  62. #define NVM_IMAGETYPES 18
  63. #define NVM_PLATFORMS 5
  64. /*====================================================================*
  65. * nvm program flags;
  66. *--------------------------------------------------------------------*/
  67. #define NVM_SILENCE (1 << 0)
  68. #define NVM_VERBOSE (1 << 1)
  69. #define NVM_MANIFEST (1 << 2)
  70. #define NVM_FIRMWARE (1 << 3)
  71. #define NVM_IDENTITY (1 << 4)
  72. #define NVM_SDRAM (1 << 5)
  73. /*====================================================================*
  74. * nvm header execute masks;
  75. *--------------------------------------------------------------------*/
  76. #define NVM_IGNORE_MASK_INT6000 (1 << 0)
  77. #define NVM_IGNORE_MASK_INT6300 (1 << 1)
  78. #define NVM_IGNORE_MASK_INT6400 (1 << 2)
  79. #define NVM_IGNORE_MASK_AR7400 (1 << 4)
  80. #define NVM_IGNORE_MASK_QCA7420 (1 << 8)
  81. /*====================================================================*
  82. * image chain types;
  83. *--------------------------------------------------------------------*/
  84. #define NVM_CHAIN_SOFTLOADER 0
  85. #define NVM_CHAIN_FIRMWARE 1
  86. #define NVM_CHAIN_PIB 2
  87. #define NVM_CHAIN_CUSTOM_MODULE 3
  88. #define NVM_CHAIN_MODULE_OP_SESSION 4
  89. /*====================================================================*
  90. * nvm build types;
  91. *--------------------------------------------------------------------*/
  92. #define NVM_BUILD_NIGHTLY 0
  93. #define NVM_BUILD_RELEASE 1
  94. #define NVM_BUILD_CUSTOM 2
  95. /*====================================================================*
  96. * nvm image types;
  97. *--------------------------------------------------------------------*/
  98. #define NVM_IMAGE_GENERIC 0x0000
  99. #define NVM_IMAGE_CONFIG_SYNOPSIS 0x0001
  100. #define NVM_IMAGE_CONFIG_DENALI 0x0002
  101. #define NVM_IMAGE_APPLET_DENALI 0x0003
  102. #define NVM_IMAGE_FIRMWARE 0x0004
  103. #define NVM_IMAGE_OASCLIENT 0x0005
  104. #define NVM_IMAGE_CUSTOM 0x0006
  105. #define NVM_IMAGE_MEMCTL 0x0007
  106. #define NVM_IMAGE_ADVPWRMGMT 0x0008
  107. #define NVM_IMAGE_OAS_CLIENT_IP_STK 0x0009
  108. #define NVM_IMAGE_OAS_CLIENT_TR069 0x000A
  109. #define NVM_IMAGE_NVM_SOFTLOADER 0x000B
  110. #define NVM_IMAGE_FLASH_LAYOUT 0x000C
  111. #define NVM_IMAGE_MANIFEST 0x000E
  112. #define NVM_IMAGE_PIB 0x000F
  113. /*====================================================================*
  114. * manifest field types;
  115. *--------------------------------------------------------------------*/
  116. #define NVM_FIELD_SIGNATURE 0
  117. #define NVM_FIELD_HARDWARE_COMPAT 1
  118. #define NVM_FIELD_CHAIN_MAJOR_VERSION 2
  119. #define NVM_FIELD_CHAIN_MINOR_VERSION 3
  120. #define NVM_FIELD_CHAIN_TYPE 4
  121. #define NVM_FIELD_BUILD_MAJOR_VERSION 5
  122. #define NVM_FIELD_BUILD_MINOR_VERSION 6
  123. #define NVM_FIELD_BUILD_TYPE 7
  124. #define NVM_FIELD_MANIFEST_VERSION 8
  125. #define NVM_FIELD_BUILD_NUMBER 9
  126. #define NVM_FIELD_BUILD_DATE 10
  127. #define NVM_FIELD_BUILD_TIME 11
  128. #define NVM_FIELD_DEVICE_TYPE 12
  129. #define NVM_FIELD_BUILD_HOSTNAME 13
  130. #define NVM_FIELD_BUILD_USERNAME 14
  131. #define NVM_FIELD_BUILD_DESCRIPTION 15
  132. #define NVM_FIELD_BUILD_VERSION_STRING 16
  133. #define NVM_FIELD_BUILD_SUSTAINING_RELEASE 17
  134. #define NVM_FIELD_BUILD_MAJOR_SUBVERSION 18
  135. #define NVM_FIELD_GENERIC_ID0 19
  136. #define NVM_FIELD_GENERIC_ID1 20
  137. #define NVM_FIELD_SL_MAJOR_VERSION 21
  138. #define NVM_FIELD_SL_MINOR_VERSION 22
  139. #define NVM_FIELD_FREE_SPACE 23
  140. /*====================================================================*
  141. * toolkit nvm error messages;
  142. *--------------------------------------------------------------------*/
  143. #define NVM_HDR_VERSION "%s found bad NVM header version in %s module %d", __func__
  144. #define NVM_HDR_CHECKSUM "%s found bad NVM header checksum in %s module %d", __func__
  145. #define NVM_HDR_LINK "%s found bad NVM header link in %s module %d", __func__
  146. #define NVM_IMG_CHECKSUM "%s found bad image checksum in %s module %d", __func__
  147. #define NVM_HDR_CANTREAD "%s can't read image header in %s module %d", __func__
  148. #define NVM_HDR_CANTSAVE "%s can't save image header in %s module %d", __func__
  149. #define NVM_IMG_CANTREAD "%s can't read image in %s module %d", __func__
  150. #define NVM_IMG_CANTSAVE "%s can't save image in %s module %d", __func__
  151. #define NVM_IMG_RUN "%s applet %d is still running"
  152. /*====================================================================*
  153. * old nvm image header (44 bytes);
  154. *--------------------------------------------------------------------*/
  155. #ifndef __GNUC__
  156. #pragma pack (push,1)
  157. #endif
  158. typedef struct __packed nvm_header1
  159. {
  160. uint32_t HEADERVERSION;
  161. uint32_t IMAGEROMADDR;
  162. uint32_t IMAGEADDRESS;
  163. uint32_t IMAGELENGTH;
  164. uint32_t IMAGECHECKSUM;
  165. uint32_t ENTRYPOINT;
  166. uint8_t HEADERMINORVERSION;
  167. uint8_t IMAGETYPE;
  168. uint16_t IGNOREMASK;
  169. uint32_t MODULEID;
  170. uint32_t MODULESUBID;
  171. uint32_t NEXTHEADER;
  172. uint32_t HEADERCHECKSUM;
  173. }
  174. nvm_header1;
  175. #ifndef __GNUC__
  176. #pragma pack (pop)
  177. #endif
  178. /*====================================================================*
  179. * new nvm image header (96 bytes);
  180. *--------------------------------------------------------------------*/
  181. #ifndef __GNUC__
  182. #pragma pack (push,1)
  183. #endif
  184. typedef struct __packed nvm_header2
  185. {
  186. uint16_t MajorVersion;
  187. uint16_t MinorVersion;
  188. uint32_t ExecuteMask;
  189. uint32_t ImageNvmAddress;
  190. uint32_t ImageAddress;
  191. uint32_t ImageLength;
  192. uint32_t ImageChecksum;
  193. uint32_t EntryPoint;
  194. uint32_t NextHeader;
  195. uint32_t PrevHeader;
  196. uint32_t ImageType;
  197. uint16_t ModuleID;
  198. uint16_t ModuleSubID;
  199. uint16_t AppletEntryVersion;
  200. uint16_t Reserved0;
  201. uint32_t Reserved1;
  202. uint32_t Reserved2;
  203. uint32_t Reserved3;
  204. uint32_t Reserved4;
  205. uint32_t Reserved5;
  206. uint32_t Reserved6;
  207. uint32_t Reserved7;
  208. uint32_t Reserved8;
  209. uint32_t Reserved9;
  210. uint32_t Reserved10;
  211. uint32_t Reserved11;
  212. uint32_t HeaderChecksum;
  213. }
  214. nvm_header2;
  215. #ifndef __GNUC__
  216. #pragma pack (pop)
  217. #endif
  218. /*====================================================================*
  219. * nvm functions;
  220. *--------------------------------------------------------------------*/
  221. signed manifest (void const * memory, size_t extent);
  222. void * manifetch (void const * memory, size_t extent, uint32_t type);
  223. signed nvmfile (struct _file_ const *);
  224. signed nvmfile1 (struct _file_ const *);
  225. signed nvmfile2 (struct _file_ const *);
  226. signed fdmanifest (signed fd, char const * filename, struct nvm_header2 *, unsigned module);
  227. signed nvmseek1 (signed fd, char const * filename, struct nvm_header1 *, uint32_t imagetype);
  228. signed nvmseek2 (signed fd, char const * filename, struct nvm_header2 *, uint32_t imagetype);
  229. void nvmpeek (void const *);
  230. void nvmpeek1 (void const *);
  231. void nvmpeek2 (void const *);
  232. /*====================================================================*
  233. *
  234. *--------------------------------------------------------------------*/
  235. #endif