ampboot.c.html 11 KB

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