manifest.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. * signed manifest (void const * memory, size_t extent);
  44. *
  45. * print manifest contents on stdout in human readable format;
  46. *
  47. *
  48. * Contributor(s):
  49. * Charles Maier
  50. *
  51. *--------------------------------------------------------------------*/
  52. #ifndef MANIFEST_SOURCE
  53. #define MANIFEST_SOURCE
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56. #include <stdint.h>
  57. #include <errno.h>
  58. #include "../tools/format.h"
  59. #include "../tools/memory.h"
  60. #include "../tools/endian.h"
  61. #include "../tools/error.h"
  62. #include "../tools/files.h"
  63. #include "../tools/tlv.h"
  64. #include "../nvm/nvm.h"
  65. /*
  66. * strings must appear in order of hardware types;
  67. */
  68. static char const * compatibility [] =
  69. {
  70. "QCA7420",
  71. (char const *) (0)
  72. };
  73. /*
  74. * strings must appear in order of field type; the last string is the error string;
  75. */
  76. static char const * nvm_fields [] =
  77. {
  78. "Signature",
  79. "Hardware Compatibility",
  80. "Chain Major Version",
  81. "Chain Minor Version",
  82. "Chain Type",
  83. "Build Major Version",
  84. "Build Minor Version",
  85. "Build Type",
  86. "Manifest Version",
  87. "Build Number",
  88. "Build Date",
  89. "Build Time",
  90. "Device Type",
  91. "Build Hostname",
  92. "Build Username",
  93. "Build Description",
  94. "Build Version String",
  95. "Build Sustaining Release",
  96. "Build Major Subversion",
  97. "Generic Identifier 0",
  98. "Generic Identifier 1",
  99. "Softloader Major Version",
  100. "Softloader Minor Version",
  101. "Manifest Free Space",
  102. "Unknown Type"
  103. };
  104. /*
  105. * strings must appear in order of chain type;
  106. */
  107. static char const * nvm_chains [] =
  108. {
  109. "Softloader",
  110. "Firmware",
  111. "Parameter Block",
  112. "CustomModule"
  113. };
  114. /*====================================================================*
  115. *
  116. * char * myitoa (unsigned number, char buffer [], size_t length);
  117. *
  118. * non-standard version of itoa () where buffer is packed right-
  119. * to-left to avoid reversing digits; ensure buffer is longer
  120. * than needed;
  121. *
  122. *
  123. * Contributor(s):
  124. * Charles Maier
  125. *
  126. *--------------------------------------------------------------------*/
  127. static char * myitoa (unsigned number, char buffer [], size_t length)
  128. {
  129. buffer [-- length] = (char) (0);
  130. do
  131. {
  132. buffer [-- length] = '0' + (number % 10);
  133. number /= 10;
  134. }
  135. while (number);
  136. return (buffer);
  137. }
  138. /*====================================================================*
  139. *
  140. * signed manifest (void const * memory, size_t extent);
  141. *
  142. * nvm.h
  143. *
  144. * walk through a manifest and print known values, when present;
  145. * known values are those defined in nvm.h and named here;
  146. *
  147. * the TLVNode data structure used here is not the same a that in
  148. * the firmware headers; our structure assumes values are 32-bit
  149. * integers and treats strings are exceptions to that rule;
  150. *
  151. *
  152. * Contributor(s):
  153. * Charles Maier
  154. *
  155. *--------------------------------------------------------------------*/
  156. signed manifest (void const * memory, size_t extent)
  157. {
  158. uint8_t * offset = (uint8_t *) (memory);
  159. uint32_t length = (uint32_t) (extent);
  160. char string [1024];
  161. while (length > 0)
  162. {
  163. struct TLVNode * node = (struct TLVNode *) (offset);
  164. uint32_t type = LE32TOH (node->type);
  165. uint32_t size = LE32TOH (node->size);
  166. uint32_t data = LE32TOH (node->data);
  167. switch (type)
  168. {
  169. case NVM_FIELD_SIGNATURE:
  170. case NVM_FIELD_BUILD_DATE:
  171. printf ("\t%s: %08X\n", nvm_fields [type], data);
  172. break;
  173. case NVM_FIELD_BUILD_TIME:
  174. printf ("\t%s: %06X\n", nvm_fields [type], data);
  175. break;
  176. case NVM_FIELD_DEVICE_TYPE:
  177. printf ("\t%s: %04X\n", nvm_fields [type], data);
  178. break;
  179. case NVM_FIELD_CHAIN_TYPE:
  180. printf ("\t%s: %s\n", nvm_fields [type], data < SIZEOF (nvm_chains)? nvm_chains [data]: myitoa (data, string, sizeof (string)));
  181. break;
  182. case NVM_FIELD_BUILD_HOSTNAME:
  183. case NVM_FIELD_BUILD_USERNAME:
  184. case NVM_FIELD_BUILD_DESCRIPTION:
  185. case NVM_FIELD_BUILD_VERSION_STRING:
  186. case NVM_FIELD_BUILD_TYPE:
  187. printf ("\t%s: %s\n", nvm_fields [type], (char const *) (& node->data));
  188. break;
  189. case NVM_FIELD_HARDWARE_COMPAT:
  190. strfbits (string, sizeof (string), compatibility, "|", data);
  191. printf ("\t%s: %s\n", nvm_fields [type], string);
  192. break;
  193. case NVM_FIELD_MANIFEST_VERSION:
  194. case NVM_FIELD_CHAIN_MAJOR_VERSION:
  195. case NVM_FIELD_CHAIN_MINOR_VERSION:
  196. case NVM_FIELD_BUILD_NUMBER:
  197. case NVM_FIELD_BUILD_MAJOR_VERSION:
  198. case NVM_FIELD_BUILD_MINOR_VERSION:
  199. case NVM_FIELD_BUILD_MAJOR_SUBVERSION:
  200. case NVM_FIELD_BUILD_SUSTAINING_RELEASE:
  201. case NVM_FIELD_GENERIC_ID0:
  202. case NVM_FIELD_GENERIC_ID1:
  203. case NVM_FIELD_SL_MAJOR_VERSION:
  204. case NVM_FIELD_SL_MINOR_VERSION:
  205. printf ("\t%s: %d\n", nvm_fields [type], data);
  206. break;
  207. case NVM_FIELD_FREE_SPACE:
  208. printf ("\t%s: %d/" SIZE_T_SPEC " bytes\n", nvm_fields [type], size, extent);
  209. break;
  210. default:
  211. error (0, 0, "%s: %d", nvm_fields [sizeof (nvm_fields) / sizeof (const char *) - 1], type);
  212. break;
  213. }
  214. length -= sizeof (* node) - sizeof (node->size) + LE32TOH (node->size);
  215. offset += sizeof (* node) - sizeof (node->size) + LE32TOH (node->size);
  216. }
  217. return (0);
  218. }
  219. #endif