WriteExecuteParameters1.c.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. WriteExecuteParameters1.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='WriteExecuteFirmware.c.html' title=' WriteExecuteFirmware.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='WriteExecuteParameters2.c.html' title=' WriteExecuteParameters2.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * signed WriteExecuteParameters1 (struct plc * plc, unsigned module, const struct nvm_header1 * nvm_header);
  64. *
  65. * plc.h
  66. *
  67. * write parameters to SDRAM using VS_WRITE_AND_EXECUTE_APPLET;
  68. *
  69. * we pass in the PIB image header because that is how the caller
  70. * located the PIB image in the file but we must write the entire
  71. * file into SDRAM at the address found in the PIB image header;
  72. * consequenctly, we have to rewind the file position and compute
  73. * the actual file size;
  74. *
  75. * this implementeation will probably never be used because we do
  76. * not distribute parameter files in old image file format; but if
  77. * we then this is it;
  78. *
  79. *
  80. * Contributor(s):
  81. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  82. *
  83. *--------------------------------------------------------------------*/
  84. #ifndef WRITEEXECUTEPARAMETERS1_SOURCE
  85. #define WRITEEXECUTEPARAMETERS1_SOURCE
  86. #include &quot;../tools/files.h&quot;
  87. #include &quot;../tools/error.h&quot;
  88. #include &quot;../plc/plc.h&quot;
  89. signed WriteExecuteParameters1 (struct plc * plc, unsigned module, const struct nvm_header1 * nvm_header)
  90. {
  91. struct channel * channel = (struct channel *)(plc-&gt;channel);
  92. struct message * message = (struct message *)(plc-&gt;message);
  93. #ifndef __GNUC__
  94. #pragma pack (push,1)
  95. #endif
  96. struct nvm_header1 nvm_manifest;
  97. struct __packed vs_write_execute_request
  98. {
  99. struct ethernet_hdr ethernet;
  100. struct qualcomm_hdr qualcomm;
  101. uint32_t CLIENT_SESSION_ID;
  102. uint32_t SERVER_SESSION_ID;
  103. uint32_t FLAGS;
  104. uint8_t ALLOWED_MEM_TYPES [8];
  105. uint32_t TOTAL_LENGTH;
  106. uint32_t CURR_PART_LENGTH;
  107. uint32_t CURR_PART_OFFSET;
  108. uint32_t START_ADDR;
  109. uint32_t CHECKSUM;
  110. uint8_t RESERVED2 [8];
  111. uint8_t IMAGE [PLC_MODULE_SIZE];
  112. }
  113. * request = (struct vs_write_execute_request *) (message);
  114. struct __packed vs_write_execute_confirm
  115. {
  116. struct ethernet_hdr ethernet;
  117. struct qualcomm_hdr qualcomm;
  118. uint32_t MSTATUS;
  119. uint32_t CLIENT_SESSION_ID;
  120. uint32_t SERVER_SESSION_ID;
  121. uint32_t FLAGS;
  122. uint8_t ALLOWED_MEM_TYPES [8];
  123. uint32_t TOTAL_LENGTH;
  124. uint32_t CURR_PART_LENGTH;
  125. uint32_t CURR_PART_OFFSET;
  126. uint32_t START_ADDR;
  127. uint32_t CHECKSUM;
  128. uint8_t RESERVED2 [8];
  129. uint32_t CURR_PART_ABSOLUTE_ADDR;
  130. uint32_t ABSOLUTE_START_ADDR;
  131. }
  132. * confirm = (struct vs_write_execute_confirm *) (message);
  133. #ifndef __GNUC__
  134. #pragma pack (pop)
  135. #endif
  136. uint32_t length = PLC_MODULE_SIZE;
  137. uint32_t offset = LE32TOH (nvm_header-&gt;IMAGEADDRESS);
  138. uint32_t extent = LE32TOH (nvm_header-&gt;IMAGELENGTH);
  139. #if 0
  140. Request (plc, &quot;Write %s (%d) (%08X:%d)&quot;, plc-&gt;PIB.name, module, offset, extent);
  141. #else
  142. /*
  143. * adjust the file extent to include the the manifest image header, the manifest image, the PIB
  144. * image header and the PIB image; this should in principle, equal the PIB filesize for Panther
  145. * and Lynx .pib files;
  146. */
  147. if (lseek (plc-&gt;PIB.file, 0, SEEK_SET))
  148. {
  149. error (1, errno, FILE_CANTHOME, plc-&gt;PIB.name);
  150. }
  151. if (read (plc-&gt;PIB.file, &amp;nvm_manifest, sizeof (nvm_manifest)) != sizeof (nvm_manifest))
  152. {
  153. error (1, errno, FILE_CANTREAD, plc-&gt;PIB.name);
  154. }
  155. extent += sizeof (* nvm_header);
  156. extent += LE32TOH (nvm_manifest.IMAGELENGTH);
  157. extent += sizeof (* nvm_header);
  158. Request (plc, &quot;Write %s (%d) (%08X:%d)&quot;, plc-&gt;PIB.name, module, offset, extent);
  159. #endif
  160. while (extent)
  161. {
  162. memset (message, 0, sizeof (* message));
  163. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  164. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_WRITE_AND_EXECUTE_APPLET | MMTYPE_REQ));
  165. if (length &gt; extent)
  166. {
  167. length = extent;
  168. }
  169. if (read (plc-&gt;PIB.file, request-&gt;IMAGE, length) != (signed)(length))
  170. {
  171. error (1, errno, FILE_CANTREAD, plc-&gt;PIB.name);
  172. }
  173. request-&gt;CLIENT_SESSION_ID = HTOLE32 (plc-&gt;cookie);
  174. request-&gt;SERVER_SESSION_ID = HTOLE32 (0);
  175. request-&gt;FLAGS = HTOLE32 (PLC_MODULE_ABSOLUTE);
  176. request-&gt;ALLOWED_MEM_TYPES [0] = 1;
  177. request-&gt;TOTAL_LENGTH = nvm_header-&gt;IMAGELENGTH;
  178. request-&gt;CURR_PART_LENGTH = HTOLE32 (length);
  179. request-&gt;CURR_PART_OFFSET = HTOLE32 (offset);
  180. request-&gt;START_ADDR = nvm_header-&gt;ENTRYPOINT;
  181. request-&gt;CHECKSUM = nvm_header-&gt;IMAGECHECKSUM;
  182. plc-&gt;packetsize = sizeof (* request);
  183. if (SendMME (plc) &lt;= 0)
  184. {
  185. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  186. return (-1);
  187. }
  188. if (ReadMME (plc, 0, (VS_WRITE_AND_EXECUTE_APPLET | MMTYPE_CNF)) &lt;= 0)
  189. {
  190. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  191. return (-1);
  192. }
  193. if (confirm-&gt;MSTATUS)
  194. {
  195. Failure (plc, PLC_WONTDOIT);
  196. return (-1);
  197. }
  198. if (LE32TOH (confirm-&gt;CURR_PART_LENGTH) != length)
  199. {
  200. error (PLC_EXIT (plc), 0, PLC_ERR_LENGTH);
  201. return (-1);
  202. }
  203. if (LE32TOH (confirm-&gt;CURR_PART_OFFSET) != offset)
  204. {
  205. error (PLC_EXIT (plc), 0, PLC_ERR_OFFSET);
  206. return (-1);
  207. }
  208. offset += length;
  209. extent -= length;
  210. }
  211. return (0);
  212. }
  213. #endif
  214. </pre>
  215. <div class='footerlink'>
  216. [<a href='WriteExecuteFirmware.c.html' title=' WriteExecuteFirmware.c '>PREV</a>]
  217. [<a href='toolkit.html' title=' Index '>HOME</a>]
  218. [<a href='WriteExecuteParameters2.c.html' title=' WriteExecuteParameters2.c '>NEXT</a>]
  219. </div>
  220. </body>
  221. </html>