plcboot.c.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. plcboot.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='Platform.c.html' title=' Platform.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='plc.c.html' title=' plc.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. /*====================================================================*&quot;
  62. *
  63. * plcboot.c -
  64. *
  65. *
  66. *--------------------------------------------------------------------*/
  67. /*====================================================================*&quot;
  68. * system header files;
  69. *--------------------------------------------------------------------*/
  70. #include &lt;unistd.h&gt;
  71. #include &lt;stdlib.h&gt;
  72. #include &lt;string.h&gt;
  73. #include &lt;limits.h&gt;
  74. #include &lt;fcntl.h&gt;
  75. #include &lt;ctype.h&gt;
  76. #include &lt;sys/stat.h&gt;
  77. /*====================================================================*
  78. * custom header files;
  79. *--------------------------------------------------------------------*/
  80. #include &quot;../tools/getoptv.h&quot;
  81. #include &quot;../tools/putoptv.h&quot;
  82. #include &quot;../tools/memory.h&quot;
  83. #include &quot;../tools/symbol.h&quot;
  84. #include &quot;../tools/number.h&quot;
  85. #include &quot;../tools/types.h&quot;
  86. #include &quot;../tools/flags.h&quot;
  87. #include &quot;../tools/files.h&quot;
  88. #include &quot;../tools/error.h&quot;
  89. #include &quot;../ram/nvram.h&quot;
  90. #include &quot;../ram/sdram.h&quot;
  91. #include &quot;../plc/plc.h&quot;
  92. #include &quot;../nvm/nvm.h&quot;
  93. #include &quot;../pib/pib.h&quot;
  94. #include &quot;../mme/mme.h&quot;
  95. /*====================================================================*
  96. * custom source files;
  97. *--------------------------------------------------------------------*/
  98. #ifndef MAKEFILE
  99. #include &quot;../plc/BootDevice2.c&quot;
  100. #include &quot;../plc/BootFirmware2.c&quot;
  101. #include &quot;../plc/BootParameters2.c&quot;
  102. #include &quot;../plc/chipset.c&quot;
  103. #include &quot;../plc/Confirm.c&quot;
  104. #include &quot;../plc/Devices.c&quot;
  105. #include &quot;../plc/Display.c&quot;
  106. #include &quot;../plc/Failure.c&quot;
  107. #include &quot;../plc/FlashDevice2.c&quot;
  108. #include &quot;../plc/FlashNVM.c&quot;
  109. #include &quot;../plc/FlashSoftloader.c&quot;
  110. #include &quot;../plc/FlashParameters.c&quot;
  111. #include &quot;../plc/FlashFirmware.c&quot;
  112. #include &quot;../plc/InitDevice2.c&quot;
  113. #include &quot;../plc/ModuleCommit.c&quot;
  114. #include &quot;../plc/ModuleSession.c&quot;
  115. #include &quot;../plc/ModuleSpec.c&quot;
  116. #include &quot;../plc/ModuleWrite.c&quot;
  117. #include &quot;../plc/NVMSelect.c&quot;
  118. #include &quot;../plc/ReadMME.c&quot;
  119. #include &quot;../plc/Request.c&quot;
  120. #include &quot;../plc/ResetDevice.c&quot;
  121. #include &quot;../plc/SendMME.c&quot;
  122. #include &quot;../plc/WaitForReset.c&quot;
  123. #include &quot;../plc/WaitForStart.c&quot;
  124. #include &quot;../plc/WriteExecuteApplet2.c&quot;
  125. #include &quot;../plc/WriteExecuteFirmware2.c&quot;
  126. #include &quot;../plc/WriteExecuteParameters2.c&quot;
  127. #include &quot;../plc/WriteFirmware2.c&quot;
  128. #include &quot;../plc/WriteMEM.c&quot;
  129. #include &quot;../plc/WriteNVM.c&quot;
  130. #include &quot;../plc/WritePIB.c&quot;
  131. #include &quot;../plc/WriteParameters2.c&quot;
  132. #endif
  133. #ifndef MAKEFILE
  134. #include &quot;../tools/basespec.c&quot;
  135. #include &quot;../tools/checkfilename.c&quot;
  136. #include &quot;../tools/checksum32.c&quot;
  137. #include &quot;../tools/error.c&quot;
  138. #include &quot;../tools/fdchecksum32.c&quot;
  139. #include &quot;../tools/getoptv.c&quot;
  140. #include &quot;../tools/hexdecode.c&quot;
  141. #include &quot;../tools/hexstring.c&quot;
  142. #include &quot;../tools/hexdump.c&quot;
  143. #include &quot;../tools/putoptv.c&quot;
  144. #include &quot;../tools/strfbits.c&quot;
  145. #include &quot;../tools/todigit.c&quot;
  146. #include &quot;../tools/typename.c&quot;
  147. #include &quot;../tools/uintspec.c&quot;
  148. #include &quot;../tools/version.c&quot;
  149. #endif
  150. #ifndef MAKEFILE
  151. #include &quot;../ether/channel.c&quot;
  152. #include &quot;../ether/closechannel.c&quot;
  153. #include &quot;../ether/openchannel.c&quot;
  154. #include &quot;../ether/readpacket.c&quot;
  155. #include &quot;../ether/sendpacket.c&quot;
  156. #endif
  157. #ifndef MAKEFILE
  158. #include &quot;../nvm/nvmfile2.c&quot;
  159. #endif
  160. #ifndef MAKEFILE
  161. #include &quot;../pib/pibfile2.c&quot;
  162. #endif
  163. #ifndef MAKEFILE
  164. #include &quot;../mme/EthernetHeader.c&quot;
  165. #include &quot;../mme/QualcommHeader.c&quot;
  166. #include &quot;../mme/UnwantedMessage.c&quot;
  167. #include &quot;../mme/MMECode.c&quot;
  168. #endif
  169. #ifndef MAKEFILE
  170. #include &quot;../key/keys.c&quot;
  171. #endif
  172. /*====================================================================*
  173. *
  174. * int main (int argc, char const * argv[]);
  175. *
  176. *
  177. *--------------------------------------------------------------------*/
  178. int main (int argc, char const * argv [])
  179. {
  180. extern struct channel channel;
  181. static char const * optv [] =
  182. {
  183. &quot;eFi:N:p:P:qS:t:vx&quot;,
  184. &quot;-N file -P file [device] [device] [...]&quot;,
  185. &quot;Qualcomm Atheros Panther/Lynx Powerline Device Bootstrapper&quot;,
  186. &quot;e\tredirect stderr to stdout&quot;,
  187. &quot;F[F]\tFlash [Force] non-volatile memory after boot&quot;,
  188. #if defined (WINPCAP) || defined (LIBPCAP)
  189. &quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,
  190. #else
  191. &quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,
  192. #endif
  193. &quot;N f\tfirmware file is (f)&quot;,
  194. &quot;P f\tparameter file is (f)&quot;,
  195. &quot;q\tquiet mode&quot;,
  196. &quot;S f\tsoftloader file is (f)&quot;,
  197. &quot;t n\tread timeout is (n) milliseconds [&quot; LITERAL (CHANNEL_TIMEOUT) &quot;]&quot;,
  198. &quot;v\tverbose mode&quot;,
  199. &quot;x\texit on error&quot;,
  200. (char const *) (0)
  201. };
  202. #include &quot;../plc/plc.c&quot;
  203. char firmware [PLC_VERSION_STRING];
  204. signed c;
  205. if (getenv (PLCDEVICE))
  206. {
  207. #if defined (WINPCAP) || defined (LIBPCAP)
  208. channel.ifindex = atoi (getenv (PLCDEVICE));
  209. #else
  210. channel.ifname = strdup (getenv (PLCDEVICE));
  211. #endif
  212. }
  213. optind = 1;
  214. while ((c = getoptv (argc, argv, optv)) != -1)
  215. {
  216. switch (c)
  217. {
  218. case 'e':
  219. dup2 (STDOUT_FILENO, STDERR_FILENO);
  220. break;
  221. case 'F':
  222. _setbits (plc.module, (VS_MODULE_MAC | VS_MODULE_PIB));
  223. if (_anyset (plc.flags, PLC_FLASH_DEVICE))
  224. {
  225. _setbits (plc.module, VS_MODULE_FORCE);
  226. }
  227. _setbits (plc.flags, PLC_FLASH_DEVICE);
  228. break;
  229. case 'i':
  230. #if defined (WINPCAP) || defined (LIBPCAP)
  231. channel.ifindex = atoi (optarg);
  232. #else
  233. channel.ifname = optarg;
  234. #endif
  235. break;
  236. case 'N':
  237. if (!checkfilename (optarg))
  238. {
  239. error (1, EINVAL, &quot;%s&quot;, optarg);
  240. }
  241. if ((plc.NVM.file = open (plc.NVM.name = optarg, O_BINARY|O_RDONLY)) == -1)
  242. {
  243. error (1, errno, &quot;%s&quot;, plc.NVM.name);
  244. }
  245. if (nvmfile2 (&amp;plc.NVM))
  246. {
  247. error (1, errno, &quot;Bad firmware file: %s&quot;, plc.NVM.name);
  248. }
  249. _setbits (plc.flags, PLC_WRITE_MAC);
  250. break;
  251. case 'P':
  252. if (!checkfilename (optarg))
  253. {
  254. error (1, EINVAL, &quot;%s&quot;, optarg);
  255. }
  256. if ((plc.PIB.file = open (plc.PIB.name = optarg, O_BINARY|O_RDONLY)) == -1)
  257. {
  258. error (1, errno, &quot;%s&quot;, plc.PIB.name);
  259. }
  260. if (pibfile2 (&amp;plc.PIB))
  261. {
  262. error (1, errno, &quot;Bad parameter file: %s&quot;, plc.PIB.name);
  263. }
  264. _setbits (plc.flags, PLC_WRITE_PIB);
  265. break;
  266. case 'q':
  267. _setbits (channel.flags, CHANNEL_SILENCE);
  268. _setbits (plc.flags, PLC_SILENCE);
  269. break;
  270. case 'S':
  271. if (!checkfilename (optarg))
  272. {
  273. error (1, EINVAL, &quot;%s&quot;, optarg);
  274. }
  275. if ((plc.CFG.file = open (plc.CFG.name = optarg, O_BINARY|O_RDONLY)) == -1)
  276. {
  277. error (1, errno, &quot;%s&quot;, plc.CFG.name);
  278. }
  279. if (nvmfile2 (&amp;plc.CFG))
  280. {
  281. error (1, errno, &quot;Bad softloader file: %s&quot;, plc.CFG.name);
  282. }
  283. break;
  284. case 't':
  285. channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX));
  286. break;
  287. case 'v':
  288. _setbits (channel.flags, CHANNEL_VERBOSE);
  289. _setbits (plc.flags, PLC_VERBOSE);
  290. break;
  291. case 'x':
  292. _setbits (plc.flags, PLC_BAILOUT);
  293. break;
  294. default:
  295. break;
  296. }
  297. }
  298. argc -= optind;
  299. argv += optind;
  300. if (argc)
  301. {
  302. error (1, ENOTSUP, ERROR_TOOMANY);
  303. }
  304. openchannel (&amp;channel);
  305. if (!(plc.message = malloc (sizeof (* plc.message))))
  306. {
  307. error (1, errno, PLC_NOMEMORY);
  308. }
  309. if (WaitForStart (&amp;plc, firmware, sizeof (firmware)))
  310. {
  311. Failure (&amp;plc, PLC_NODETECT);
  312. exit (1);
  313. }
  314. if (strcmp (firmware, &quot;BootLoader&quot;))
  315. {
  316. Failure (&amp;plc, &quot;Bootloader must be running&quot;);
  317. exit (1);
  318. }
  319. if (plc.hardwareID &lt; CHIPSET_INT6400)
  320. {
  321. Failure (&amp;plc, &quot;Device must be %s or later; Use program int6kboot or ampboot instead.&quot;, chipsetname (CHIPSET_INT6400));
  322. exit (1);
  323. }
  324. if (plc.PIB.file == -1)
  325. {
  326. error (1, ECANCELED, &quot;No Parameter file named&quot;);
  327. }
  328. if (plc.NVM.file == -1)
  329. {
  330. error (1, ECANCELED, &quot;No Firmware file named&quot;);
  331. }
  332. if (plc.CFG.file == -1)
  333. {
  334. if (_anyset (plc.flags, PLC_FLASH_DEVICE))
  335. {
  336. error (1, ECANCELED, &quot;No Softloader file named&quot;);
  337. }
  338. }
  339. if (!InitDevice2 (&amp;plc))
  340. {
  341. if (!BootDevice2 (&amp;plc))
  342. {
  343. if (_anyset (plc.flags, PLC_FLASH_DEVICE))
  344. {
  345. FlashDevice2 (&amp; plc, (PLC_COMMIT_FORCE | PLC_COMMIT_NORESET | PLC_COMMIT_FACTPIB));
  346. }
  347. }
  348. }
  349. free (plc.message);
  350. closechannel (&amp;channel);
  351. exit (0);
  352. }
  353. </pre>
  354. <div class='footerlink'>
  355. [<a href='Platform.c.html' title=' Platform.c '>PREV</a>]
  356. [<a href='toolkit.html' title=' Index '>HOME</a>]
  357. [<a href='plc.c.html' title=' plc.c '>NEXT</a>]
  358. </div>
  359. </body>
  360. </html>