ModuleWrite.c.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. ModuleWrite.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='ModuleSpec.c.html' title=' ModuleSpec.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='NetInfo1.c.html' title=' NetInfo1.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 ModuleWrite (struct plc * plc, struct _file_ * file, unsigned index, struct vs_module_spec * vs_module_spec);
  64. *
  65. * plc.h
  66. *
  67. * write an entire file to flash memory as a single module; write
  68. * the file in 1400 byte records; allow up to 80 seconds for each
  69. * write to complete; extra time is needed because memory must be
  70. * erased;
  71. *
  72. *
  73. * Contributor(s):
  74. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  75. *
  76. *--------------------------------------------------------------------*/
  77. #ifndef MODULEWRITE_SOURCE
  78. #define MODULEWRITE_SOURCE
  79. #include &lt;stdint.h&gt;
  80. #include &lt;limits.h&gt;
  81. #include &lt;unistd.h&gt;
  82. #include &lt;string.h&gt;
  83. #include &lt;memory.h&gt;
  84. #include &quot;../tools/error.h&quot;
  85. #include &quot;../tools/files.h&quot;
  86. #include &quot;../plc/plc.h&quot;
  87. signed ModuleWrite (struct plc * plc, struct _file_ * file, unsigned index, struct vs_module_spec * vs_module_spec)
  88. {
  89. struct channel * channel = (struct channel *)(plc-&gt;channel);
  90. struct message * message = (struct message *)(plc-&gt;message);
  91. #ifndef __GNUC__
  92. #pragma pack (push,1)
  93. #endif
  94. struct __packed vs_module_operation_write_request
  95. {
  96. struct ethernet_hdr ethernet;
  97. struct qualcomm_hdr qualcomm;
  98. uint32_t RESERVED;
  99. uint8_t NUM_OP_DATA;
  100. struct __packed
  101. {
  102. uint16_t MOD_OP;
  103. uint16_t MOD_OP_DATA_LEN;
  104. uint32_t MOD_OP_RSVD;
  105. uint32_t MOD_OP_SESSION_ID;
  106. uint8_t MODULE_IDX;
  107. uint16_t MODULE_ID;
  108. uint16_t MODULE_SUB_ID;
  109. uint16_t MODULE_LENGTH;
  110. uint32_t MODULE_OFFSET;
  111. }
  112. MODULE_SPEC;
  113. uint8_t MODULE_DATA [PLC_MODULE_SIZE];
  114. }
  115. * request = (struct vs_module_operation_write_request *)(message);
  116. struct __packed vs_module_operation_write_confirm
  117. {
  118. struct ethernet_hdr ethernet;
  119. struct qualcomm_hdr qualcomm;
  120. uint16_t MSTATUS;
  121. uint16_t ERR_REC_CODE;
  122. uint32_t RESERVED;
  123. uint8_t NUM_OP_DATA;
  124. struct __packed
  125. {
  126. uint16_t MOD_OP;
  127. uint16_t MOD_OP_DATA_LEN;
  128. uint32_t MOD_OP_RSVD;
  129. uint32_t MOD_OP_SESSION_ID;
  130. uint8_t MODULE_IDX;
  131. uint16_t MODULE_ID;
  132. uint16_t MODULE_SUB_ID;
  133. uint16_t MODULE_LENGTH;
  134. uint32_t MODULE_OFFSET;
  135. }
  136. MODULE_SPEC;
  137. }
  138. * confirm = (struct vs_module_operation_write_confirm *)(message);
  139. #ifndef __GNUC__
  140. #pragma pack (pop)
  141. #endif
  142. unsigned timer = channel-&gt;timeout;
  143. uint16_t length = PLC_MODULE_SIZE;
  144. uint32_t extent = vs_module_spec-&gt;MODULE_LENGTH;
  145. uint32_t offset = 0;
  146. Request (plc, &quot;Flash %s&quot;, file-&gt;name);
  147. while (extent)
  148. {
  149. memset (message, 0, sizeof (* message));
  150. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  151. QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_MODULE_OPERATION | MMTYPE_REQ));
  152. plc-&gt;packetsize = sizeof (struct vs_module_operation_write_request);
  153. if (length &gt; extent)
  154. {
  155. length = extent;
  156. }
  157. if (read (file-&gt;file, request-&gt;MODULE_DATA, length) != length)
  158. {
  159. error (1, errno, FILE_CANTREAD, file-&gt;name);
  160. }
  161. request-&gt;NUM_OP_DATA = 1;
  162. request-&gt;MODULE_SPEC.MOD_OP = HTOLE16 (PLC_MOD_OP_WRITE_MODULE);
  163. request-&gt;MODULE_SPEC.MOD_OP_DATA_LEN = HTOLE16 (sizeof (request-&gt;MODULE_SPEC) + sizeof (request-&gt;MODULE_DATA));
  164. request-&gt;MODULE_SPEC.MOD_OP_SESSION_ID = HTOLE32 (plc-&gt;cookie);
  165. request-&gt;MODULE_SPEC.MODULE_IDX = index;
  166. request-&gt;MODULE_SPEC.MODULE_ID = HTOLE16 (vs_module_spec-&gt;MODULE_ID);
  167. request-&gt;MODULE_SPEC.MODULE_SUB_ID = HTOLE16 (vs_module_spec-&gt;MODULE_SUB_ID);
  168. request-&gt;MODULE_SPEC.MODULE_LENGTH = HTOLE16 (length);
  169. request-&gt;MODULE_SPEC.MODULE_OFFSET = HTOLE32 (offset);
  170. #if 1
  171. fprintf (stderr, &quot;RESERVED 0x%08X\n&quot;, LE32TOH (request-&gt;RESERVED));
  172. fprintf (stderr, &quot;NUM_OP_DATA %d\n&quot;, request-&gt;NUM_OP_DATA);
  173. fprintf (stderr, &quot;MOD_OP 0x%02X\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MOD_OP));
  174. fprintf (stderr, &quot;MOD_OP_DATA_LEN %d\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MOD_OP_DATA_LEN));
  175. fprintf (stderr, &quot;RESERVED 0x%08X\n&quot;, LE32TOH (request-&gt;MODULE_SPEC.MOD_OP_RSVD));
  176. fprintf (stderr, &quot;MODULE_ID 0x%04X\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MODULE_ID));
  177. fprintf (stderr, &quot;MODULE_SUB_ID 0x%04X\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MODULE_SUB_ID));
  178. fprintf (stderr, &quot;MODULE_LENGTH %d\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MODULE_LENGTH));
  179. fprintf (stderr, &quot;MODULE_OFFSET 0x%08X\n&quot;, LE32TOH (request-&gt;MODULE_SPEC.MODULE_OFFSET));
  180. #endif
  181. if (SendMME (plc) &lt;= 0)
  182. {
  183. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  184. return (-1);
  185. }
  186. channel-&gt;timeout = PLC_MODULE_WRITE_TIMEOUT;
  187. if (ReadMME (plc, 0, (VS_MODULE_OPERATION | MMTYPE_CNF)) &lt;= 0)
  188. {
  189. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  190. channel-&gt;timeout = timer;
  191. return (-1);
  192. }
  193. channel-&gt;timeout = timer;
  194. #if 1
  195. fprintf (stderr, &quot;MSTATUS 0x%04X\n&quot;, LE16TOH (confirm-&gt;MSTATUS));
  196. fprintf (stderr, &quot;ERROR_REC_CODE %d\n&quot;, LE16TOH (confirm-&gt;ERR_REC_CODE));
  197. fprintf (stderr, &quot;RESERVED 0x%08X\n&quot;, LE32TOH (confirm-&gt;RESERVED));
  198. fprintf (stderr, &quot;NUM_OP_DATA %d\n&quot;, confirm-&gt;NUM_OP_DATA);
  199. fprintf (stderr, &quot;MOD_OP 0x%02X\n&quot;, LE16TOH (request-&gt;MODULE_SPEC.MOD_OP));
  200. fprintf (stderr, &quot;MOD_OP_DATA_LEN %d\n&quot;, LE16TOH (confirm-&gt;MODULE_SPEC.MOD_OP_DATA_LEN));
  201. fprintf (stderr, &quot;RESERVED 0x%08X\n&quot;, LE32TOH (confirm-&gt;MODULE_SPEC.MOD_OP_RSVD));
  202. fprintf (stderr, &quot;MODULE_ID 0x%04X\n&quot;, LE16TOH (confirm-&gt;MODULE_SPEC.MODULE_ID));
  203. fprintf (stderr, &quot;MODULE_SUB_ID 0x%04X\n&quot;, LE16TOH (confirm-&gt;MODULE_SPEC.MODULE_SUB_ID));
  204. fprintf (stderr, &quot;MODULE_LENGTH %d\n&quot;, LE16TOH (confirm-&gt;MODULE_SPEC.MODULE_LENGTH));
  205. fprintf (stderr, &quot;MODULE_OFFSET 0x%08X\n&quot;, LE32TOH (request-&gt;MODULE_SPEC.MODULE_OFFSET));
  206. #endif
  207. if (confirm-&gt;MSTATUS)
  208. {
  209. Failure (plc, PLC_WONTDOIT);
  210. return (-1);
  211. }
  212. if (LE16TOH (confirm-&gt;MODULE_SPEC.MODULE_LENGTH) != length)
  213. {
  214. error (PLC_EXIT (plc), 0, PLC_ERR_LENGTH);
  215. return (-1);
  216. }
  217. if (LE32TOH (confirm-&gt;MODULE_SPEC.MODULE_OFFSET) != offset)
  218. {
  219. error (PLC_EXIT (plc), 0, PLC_ERR_OFFSET);
  220. return (-1);
  221. }
  222. extent -= length;
  223. offset += length;
  224. }
  225. return (0);
  226. }
  227. #endif
  228. </pre>
  229. <div class='footerlink'>
  230. [<a href='ModuleSpec.c.html' title=' ModuleSpec.c '>PREV</a>]
  231. [<a href='toolkit.html' title=' Index '>HOME</a>]
  232. [<a href='NetInfo1.c.html' title=' NetInfo1.c '>NEXT</a>]
  233. </div>
  234. </body>
  235. </html>