cmd_bootm.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * Boot support
  25. */
  26. #include <common.h>
  27. #include <watchdog.h>
  28. #include <command.h>
  29. #include <image.h>
  30. #include <malloc.h>
  31. #include <zlib.h>
  32. #include <bzlib.h>
  33. #include <environment.h>
  34. #include <asm/byteorder.h>
  35. #ifdef CONFIG_OF_FLAT_TREE
  36. #include <ft_build.h>
  37. #endif
  38. /*cmd_boot.c*/
  39. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  40. #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
  41. #include <rtc.h>
  42. #endif
  43. #ifdef CFG_HUSH_PARSER
  44. #include <hush.h>
  45. #endif
  46. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  47. # include <status_led.h>
  48. # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
  49. #else
  50. # define SHOW_BOOT_PROGRESS(arg)
  51. #endif
  52. #ifdef CFG_INIT_RAM_LOCK
  53. #include <asm/cache.h>
  54. #endif
  55. #ifdef CONFIG_LOGBUFFER
  56. #include <logbuff.h>
  57. #endif
  58. #ifdef CONFIG_HAS_DATAFLASH
  59. #include <dataflash.h>
  60. #endif
  61. /*
  62. * Some systems (for example LWMON) have very short watchdog periods;
  63. * we must make sure to split long operations like memmove() or
  64. * crc32() into reasonable chunks.
  65. */
  66. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  67. # define CHUNKSZ (64 * 1024)
  68. #endif
  69. int gunzip (void *, int, unsigned char *, unsigned long *);
  70. static void *zalloc(void *, unsigned, unsigned);
  71. static void zfree(void *, void *, unsigned);
  72. #if (CONFIG_COMMANDS & CFG_CMD_IMI)
  73. static int image_info (unsigned long addr);
  74. #endif
  75. #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
  76. #include <flash.h>
  77. extern flash_info_t flash_info[]; /* info for FLASH chips */
  78. static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  79. #endif
  80. static void print_type (image_header_t *hdr);
  81. #ifdef __I386__
  82. image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
  83. #endif
  84. /*
  85. * Continue booting an OS image; caller already has:
  86. * - copied image header to global variable `header'
  87. * - checked header magic number, checksums (both header & image),
  88. * - verified image architecture (PPC) and type (KERNEL or MULTI),
  89. * - loaded (first part of) image to header load address,
  90. * - disabled interrupts.
  91. */
  92. typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
  93. int argc, char *argv[],
  94. ulong addr, /* of image to boot */
  95. ulong *len_ptr, /* multi-file image length table */
  96. int verify); /* getenv("verify")[0] != 'n' */
  97. #ifdef DEBUG
  98. extern int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  99. #endif
  100. #ifdef CONFIG_PPC
  101. static boot_os_Fcn do_bootm_linux;
  102. #else
  103. extern boot_os_Fcn do_bootm_linux;
  104. #endif
  105. #ifdef CONFIG_SILENT_CONSOLE
  106. static void fixup_silent_linux (void);
  107. #endif
  108. static boot_os_Fcn do_bootm_netbsd;
  109. static boot_os_Fcn do_bootm_rtems;
  110. #if (CONFIG_COMMANDS & CFG_CMD_ELF)
  111. static boot_os_Fcn do_bootm_vxworks;
  112. static boot_os_Fcn do_bootm_qnxelf;
  113. int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
  114. int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
  115. #endif /* CFG_CMD_ELF */
  116. #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
  117. static boot_os_Fcn do_bootm_artos;
  118. #endif
  119. #ifdef CONFIG_LYNXKDI
  120. static boot_os_Fcn do_bootm_lynxkdi;
  121. extern void lynxkdi_boot( image_header_t * );
  122. #endif
  123. image_header_t header;
  124. ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
  125. int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  126. {
  127. ulong iflag;
  128. ulong addr;
  129. ulong data, len, checksum;
  130. ulong *len_ptr;
  131. uint unc_len = 0x400000;
  132. int i, verify;
  133. char *name, *s;
  134. int (*appl)(int, char *[]);
  135. image_header_t *hdr = &header;
  136. s = getenv ("verify");
  137. verify = (s && (*s == 'n')) ? 0 : 1;
  138. if (argc < 2) {
  139. addr = load_addr;
  140. } else {
  141. addr = simple_strtoul(argv[1], NULL, 16);
  142. }
  143. SHOW_BOOT_PROGRESS (1);
  144. printf ("## Booting image at %08lx ...\n", addr);
  145. /* Copy header so we can blank CRC field for re-calculation */
  146. #ifdef CONFIG_HAS_DATAFLASH
  147. if (addr_dataflash(addr)){
  148. read_dataflash(addr, sizeof(image_header_t), (char *)&header);
  149. } else
  150. #endif
  151. memmove (&header, (char *)addr, sizeof(image_header_t));
  152. if (ntohl(hdr->ih_magic) != IH_MAGIC) {
  153. #ifdef __I386__ /* correct image format not implemented yet - fake it */
  154. if (fake_header(hdr, (void*)addr, -1) != NULL) {
  155. /* to compensate for the addition below */
  156. addr -= sizeof(image_header_t);
  157. /* turnof verify,
  158. * fake_header() does not fake the data crc
  159. */
  160. verify = 0;
  161. } else
  162. #endif /* __I386__ */
  163. {
  164. puts ("Bad Magic Number\n");
  165. SHOW_BOOT_PROGRESS (-1);
  166. return 1;
  167. }
  168. }
  169. SHOW_BOOT_PROGRESS (2);
  170. data = (ulong)&header;
  171. len = sizeof(image_header_t);
  172. checksum = ntohl(hdr->ih_hcrc);
  173. hdr->ih_hcrc = 0;
  174. if (crc32 (0, (uchar *)data, len) != checksum) {
  175. puts ("Bad Header Checksum\n");
  176. SHOW_BOOT_PROGRESS (-2);
  177. return 1;
  178. }
  179. SHOW_BOOT_PROGRESS (3);
  180. #ifdef CONFIG_HAS_DATAFLASH
  181. if (addr_dataflash(addr)){
  182. len = ntohl(hdr->ih_size) + sizeof(image_header_t);
  183. read_dataflash(addr, len, (char *)CFG_LOAD_ADDR);
  184. addr = CFG_LOAD_ADDR;
  185. }
  186. #endif
  187. /* for multi-file images we need the data part, too */
  188. print_image_hdr ((image_header_t *)addr);
  189. data = addr + sizeof(image_header_t);
  190. len = ntohl(hdr->ih_size);
  191. if (verify) {
  192. puts (" Verifying Checksum ... ");
  193. if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
  194. printf ("Bad Data CRC\n");
  195. SHOW_BOOT_PROGRESS (-3);
  196. return 1;
  197. }
  198. puts ("OK\n");
  199. }
  200. SHOW_BOOT_PROGRESS (4);
  201. len_ptr = (ulong *)data;
  202. #if defined(__PPC__)
  203. if (hdr->ih_arch != IH_CPU_PPC)
  204. #elif defined(__ARM__)
  205. if (hdr->ih_arch != IH_CPU_ARM)
  206. #elif defined(__I386__)
  207. if (hdr->ih_arch != IH_CPU_I386)
  208. #elif defined(__mips__)
  209. if (hdr->ih_arch != IH_CPU_MIPS)
  210. #elif defined(__nios__)
  211. if (hdr->ih_arch != IH_CPU_NIOS)
  212. #elif defined(__M68K__)
  213. if (hdr->ih_arch != IH_CPU_M68K)
  214. #elif defined(__microblaze__)
  215. if (hdr->ih_arch != IH_CPU_MICROBLAZE)
  216. #elif defined(__nios2__)
  217. if (hdr->ih_arch != IH_CPU_NIOS2)
  218. #else
  219. # error Unknown CPU type
  220. #endif
  221. {
  222. printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
  223. SHOW_BOOT_PROGRESS (-4);
  224. return 1;
  225. }
  226. SHOW_BOOT_PROGRESS (5);
  227. switch (hdr->ih_type) {
  228. case IH_TYPE_STANDALONE:
  229. name = "Standalone Application";
  230. /* A second argument overwrites the load address */
  231. if (argc > 2) {
  232. hdr->ih_load = htonl(simple_strtoul(argv[2], NULL, 16));
  233. }
  234. break;
  235. case IH_TYPE_KERNEL:
  236. name = "Kernel Image";
  237. break;
  238. case IH_TYPE_MULTI:
  239. name = "Multi-File Image";
  240. len = ntohl(len_ptr[0]);
  241. /* OS kernel is always the first image */
  242. data += 8; /* kernel_len + terminator */
  243. for (i=1; len_ptr[i]; ++i)
  244. data += 4;
  245. break;
  246. default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
  247. SHOW_BOOT_PROGRESS (-5);
  248. return 1;
  249. }
  250. SHOW_BOOT_PROGRESS (6);
  251. /*
  252. * We have reached the point of no return: we are going to
  253. * overwrite all exception vector code, so we cannot easily
  254. * recover from any failures any more...
  255. */
  256. iflag = disable_interrupts();
  257. #ifdef CONFIG_AMIGAONEG3SE
  258. /*
  259. * We've possible left the caches enabled during
  260. * bios emulation, so turn them off again
  261. */
  262. icache_disable();
  263. invalidate_l1_instruction_cache();
  264. flush_data_cache();
  265. dcache_disable();
  266. #endif
  267. switch (hdr->ih_comp) {
  268. case IH_COMP_NONE:
  269. if(ntohl(hdr->ih_load) == addr) {
  270. printf (" XIP %s ... ", name);
  271. } else {
  272. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  273. size_t l = len;
  274. void *to = (void *)ntohl(hdr->ih_load);
  275. void *from = (void *)data;
  276. printf (" Loading %s ... ", name);
  277. while (l > 0) {
  278. size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
  279. WATCHDOG_RESET();
  280. memmove (to, from, tail);
  281. to += tail;
  282. from += tail;
  283. l -= tail;
  284. }
  285. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  286. memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
  287. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  288. }
  289. break;
  290. case IH_COMP_GZIP:
  291. printf (" Uncompressing %s ... ", name);
  292. if (gunzip ((void *)ntohl(hdr->ih_load), unc_len,
  293. (uchar *)data, &len) != 0) {
  294. puts ("GUNZIP ERROR - must RESET board to recover\n");
  295. SHOW_BOOT_PROGRESS (-6);
  296. do_reset (cmdtp, flag, argc, argv);
  297. }
  298. break;
  299. #ifdef CONFIG_BZIP2
  300. case IH_COMP_BZIP2:
  301. printf (" Uncompressing %s ... ", name);
  302. /*
  303. * If we've got less than 4 MB of malloc() space,
  304. * use slower decompression algorithm which requires
  305. * at most 2300 KB of memory.
  306. */
  307. i = BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr->ih_load),
  308. &unc_len, (char *)data, len,
  309. CFG_MALLOC_LEN < (4096 * 1024), 0);
  310. if (i != BZ_OK) {
  311. printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
  312. SHOW_BOOT_PROGRESS (-6);
  313. udelay(100000);
  314. do_reset (cmdtp, flag, argc, argv);
  315. }
  316. break;
  317. #endif /* CONFIG_BZIP2 */
  318. default:
  319. if (iflag)
  320. enable_interrupts();
  321. printf ("Unimplemented compression type %d\n", hdr->ih_comp);
  322. SHOW_BOOT_PROGRESS (-7);
  323. return 1;
  324. }
  325. puts ("OK\n");
  326. SHOW_BOOT_PROGRESS (7);
  327. switch (hdr->ih_type) {
  328. case IH_TYPE_STANDALONE:
  329. if (iflag)
  330. enable_interrupts();
  331. /* load (and uncompress), but don't start if "autostart"
  332. * is set to "no"
  333. */
  334. if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
  335. char buf[32];
  336. sprintf(buf, "%lX", len);
  337. setenv("filesize", buf);
  338. return 0;
  339. }
  340. appl = (int (*)(int, char *[]))ntohl(hdr->ih_ep);
  341. (*appl)(argc-1, &argv[1]);
  342. return 0;
  343. case IH_TYPE_KERNEL:
  344. case IH_TYPE_MULTI:
  345. /* handled below */
  346. break;
  347. default:
  348. if (iflag)
  349. enable_interrupts();
  350. printf ("Can't boot image type %d\n", hdr->ih_type);
  351. SHOW_BOOT_PROGRESS (-8);
  352. return 1;
  353. }
  354. SHOW_BOOT_PROGRESS (8);
  355. switch (hdr->ih_os) {
  356. default: /* handled by (original) Linux case */
  357. case IH_OS_LINUX:
  358. #ifdef CONFIG_SILENT_CONSOLE
  359. fixup_silent_linux();
  360. #endif
  361. do_bootm_linux (cmdtp, flag, argc, argv,
  362. addr, len_ptr, verify);
  363. break;
  364. case IH_OS_NETBSD:
  365. do_bootm_netbsd (cmdtp, flag, argc, argv,
  366. addr, len_ptr, verify);
  367. break;
  368. #ifdef CONFIG_LYNXKDI
  369. case IH_OS_LYNXOS:
  370. do_bootm_lynxkdi (cmdtp, flag, argc, argv,
  371. addr, len_ptr, verify);
  372. break;
  373. #endif
  374. case IH_OS_RTEMS:
  375. do_bootm_rtems (cmdtp, flag, argc, argv,
  376. addr, len_ptr, verify);
  377. break;
  378. #if (CONFIG_COMMANDS & CFG_CMD_ELF)
  379. case IH_OS_VXWORKS:
  380. do_bootm_vxworks (cmdtp, flag, argc, argv,
  381. addr, len_ptr, verify);
  382. break;
  383. case IH_OS_QNX:
  384. do_bootm_qnxelf (cmdtp, flag, argc, argv,
  385. addr, len_ptr, verify);
  386. break;
  387. #endif /* CFG_CMD_ELF */
  388. #ifdef CONFIG_ARTOS
  389. case IH_OS_ARTOS:
  390. do_bootm_artos (cmdtp, flag, argc, argv,
  391. addr, len_ptr, verify);
  392. break;
  393. #endif
  394. }
  395. SHOW_BOOT_PROGRESS (-9);
  396. #ifdef DEBUG
  397. puts ("\n## Control returned to monitor - resetting...\n");
  398. do_reset (cmdtp, flag, argc, argv);
  399. #endif
  400. return 1;
  401. }
  402. U_BOOT_CMD(
  403. bootm, CFG_MAXARGS, 1, do_bootm,
  404. "bootm - boot application image from memory\n",
  405. "[addr [arg ...]]\n - boot application image stored in memory\n"
  406. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  407. "\t'arg' can be the address of an initrd image\n"
  408. );
  409. #ifdef CONFIG_SILENT_CONSOLE
  410. static void
  411. fixup_silent_linux ()
  412. {
  413. DECLARE_GLOBAL_DATA_PTR;
  414. char buf[256], *start, *end;
  415. char *cmdline = getenv ("bootargs");
  416. /* Only fix cmdline when requested */
  417. if (!(gd->flags & GD_FLG_SILENT))
  418. return;
  419. debug ("before silent fix-up: %s\n", cmdline);
  420. if (cmdline) {
  421. if ((start = strstr (cmdline, "console=")) != NULL) {
  422. end = strchr (start, ' ');
  423. strncpy (buf, cmdline, (start - cmdline + 8));
  424. if (end)
  425. strcpy (buf + (start - cmdline + 8), end);
  426. else
  427. buf[start - cmdline + 8] = '\0';
  428. } else {
  429. strcpy (buf, cmdline);
  430. strcat (buf, " console=");
  431. }
  432. } else {
  433. strcpy (buf, "console=");
  434. }
  435. setenv ("bootargs", buf);
  436. debug ("after silent fix-up: %s\n", buf);
  437. }
  438. #endif /* CONFIG_SILENT_CONSOLE */
  439. #ifdef CONFIG_OF_FLAT_TREE
  440. extern const unsigned char oftree_dtb[];
  441. extern const unsigned int oftree_dtb_len;
  442. #endif
  443. #ifdef CONFIG_PPC
  444. static void
  445. do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
  446. int argc, char *argv[],
  447. ulong addr,
  448. ulong *len_ptr,
  449. int verify)
  450. {
  451. DECLARE_GLOBAL_DATA_PTR;
  452. ulong sp;
  453. ulong len, checksum;
  454. ulong initrd_start, initrd_end;
  455. ulong cmd_start, cmd_end;
  456. ulong initrd_high;
  457. ulong data;
  458. int initrd_copy_to_ram = 1;
  459. char *cmdline;
  460. char *s;
  461. bd_t *kbd;
  462. void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
  463. image_header_t *hdr = &header;
  464. #ifdef CONFIG_OF_FLAT_TREE
  465. char *of_flat_tree;
  466. #endif
  467. if ((s = getenv ("initrd_high")) != NULL) {
  468. /* a value of "no" or a similar string will act like 0,
  469. * turning the "load high" feature off. This is intentional.
  470. */
  471. initrd_high = simple_strtoul(s, NULL, 16);
  472. if (initrd_high == ~0)
  473. initrd_copy_to_ram = 0;
  474. } else { /* not set, no restrictions to load high */
  475. initrd_high = ~0;
  476. }
  477. #ifdef CONFIG_LOGBUFFER
  478. kbd=gd->bd;
  479. /* Prevent initrd from overwriting logbuffer */
  480. if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
  481. initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
  482. debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
  483. #endif
  484. /*
  485. * Booting a (Linux) kernel image
  486. *
  487. * Allocate space for command line and board info - the
  488. * address should be as high as possible within the reach of
  489. * the kernel (see CFG_BOOTMAPSZ settings), but in unused
  490. * memory, which means far enough below the current stack
  491. * pointer.
  492. */
  493. asm( "mr %0,1": "=r"(sp) : );
  494. debug ("## Current stack ends at 0x%08lX ", sp);
  495. sp -= 2048; /* just to be sure */
  496. if (sp > CFG_BOOTMAPSZ)
  497. sp = CFG_BOOTMAPSZ;
  498. sp &= ~0xF;
  499. debug ("=> set upper limit to 0x%08lX\n", sp);
  500. cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
  501. kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
  502. if ((s = getenv("bootargs")) == NULL)
  503. s = "";
  504. strcpy (cmdline, s);
  505. cmd_start = (ulong)&cmdline[0];
  506. cmd_end = cmd_start + strlen(cmdline);
  507. *kbd = *(gd->bd);
  508. #ifdef DEBUG
  509. printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
  510. do_bdinfo (NULL, 0, 0, NULL);
  511. #endif
  512. if ((s = getenv ("clocks_in_mhz")) != NULL) {
  513. /* convert all clock information to MHz */
  514. kbd->bi_intfreq /= 1000000L;
  515. kbd->bi_busfreq /= 1000000L;
  516. #if defined(CONFIG_MPC8220)
  517. kbd->bi_inpfreq /= 1000000L;
  518. kbd->bi_pcifreq /= 1000000L;
  519. kbd->bi_pevfreq /= 1000000L;
  520. kbd->bi_flbfreq /= 1000000L;
  521. kbd->bi_vcofreq /= 1000000L;
  522. #endif
  523. #if defined(CONFIG_CPM2)
  524. kbd->bi_cpmfreq /= 1000000L;
  525. kbd->bi_brgfreq /= 1000000L;
  526. kbd->bi_sccfreq /= 1000000L;
  527. kbd->bi_vco /= 1000000L;
  528. #endif
  529. #if defined(CONFIG_MPC5xxx)
  530. kbd->bi_ipbfreq /= 1000000L;
  531. kbd->bi_pcifreq /= 1000000L;
  532. #endif /* CONFIG_MPC5xxx */
  533. }
  534. kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
  535. /*
  536. * Check if there is an initrd image
  537. */
  538. if (argc >= 3) {
  539. SHOW_BOOT_PROGRESS (9);
  540. addr = simple_strtoul(argv[2], NULL, 16);
  541. printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
  542. /* Copy header so we can blank CRC field for re-calculation */
  543. memmove (&header, (char *)addr, sizeof(image_header_t));
  544. if (hdr->ih_magic != IH_MAGIC) {
  545. puts ("Bad Magic Number\n");
  546. SHOW_BOOT_PROGRESS (-10);
  547. do_reset (cmdtp, flag, argc, argv);
  548. }
  549. data = (ulong)&header;
  550. len = sizeof(image_header_t);
  551. checksum = hdr->ih_hcrc;
  552. hdr->ih_hcrc = 0;
  553. if (crc32 (0, (uchar *)data, len) != checksum) {
  554. puts ("Bad Header Checksum\n");
  555. SHOW_BOOT_PROGRESS (-11);
  556. do_reset (cmdtp, flag, argc, argv);
  557. }
  558. SHOW_BOOT_PROGRESS (10);
  559. print_image_hdr (hdr);
  560. data = addr + sizeof(image_header_t);
  561. len = hdr->ih_size;
  562. if (verify) {
  563. ulong csum = 0;
  564. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  565. ulong cdata = data, edata = cdata + len;
  566. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  567. puts (" Verifying Checksum ... ");
  568. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  569. while (cdata < edata) {
  570. ulong chunk = edata - cdata;
  571. if (chunk > CHUNKSZ)
  572. chunk = CHUNKSZ;
  573. csum = crc32 (csum, (uchar *)cdata, chunk);
  574. cdata += chunk;
  575. WATCHDOG_RESET();
  576. }
  577. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  578. csum = crc32 (0, (uchar *)data, len);
  579. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  580. if (csum != hdr->ih_dcrc) {
  581. puts ("Bad Data CRC\n");
  582. SHOW_BOOT_PROGRESS (-12);
  583. do_reset (cmdtp, flag, argc, argv);
  584. }
  585. puts ("OK\n");
  586. }
  587. SHOW_BOOT_PROGRESS (11);
  588. if ((hdr->ih_os != IH_OS_LINUX) ||
  589. (hdr->ih_arch != IH_CPU_PPC) ||
  590. (hdr->ih_type != IH_TYPE_RAMDISK) ) {
  591. puts ("No Linux PPC Ramdisk Image\n");
  592. SHOW_BOOT_PROGRESS (-13);
  593. do_reset (cmdtp, flag, argc, argv);
  594. }
  595. /*
  596. * Now check if we have a multifile image
  597. */
  598. } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
  599. u_long tail = ntohl(len_ptr[0]) % 4;
  600. int i;
  601. SHOW_BOOT_PROGRESS (13);
  602. /* skip kernel length and terminator */
  603. data = (ulong)(&len_ptr[2]);
  604. /* skip any additional image length fields */
  605. for (i=1; len_ptr[i]; ++i)
  606. data += 4;
  607. /* add kernel length, and align */
  608. data += ntohl(len_ptr[0]);
  609. if (tail) {
  610. data += 4 - tail;
  611. }
  612. len = ntohl(len_ptr[1]);
  613. } else {
  614. /*
  615. * no initrd image
  616. */
  617. SHOW_BOOT_PROGRESS (14);
  618. len = data = 0;
  619. }
  620. if (!data) {
  621. debug ("No initrd\n");
  622. }
  623. if (data) {
  624. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  625. initrd_start = data;
  626. initrd_end = initrd_start + len;
  627. } else {
  628. initrd_start = (ulong)kbd - len;
  629. initrd_start &= ~(4096 - 1); /* align on page */
  630. if (initrd_high) {
  631. ulong nsp;
  632. /*
  633. * the inital ramdisk does not need to be within
  634. * CFG_BOOTMAPSZ as it is not accessed until after
  635. * the mm system is initialised.
  636. *
  637. * do the stack bottom calculation again and see if
  638. * the initrd will fit just below the monitor stack
  639. * bottom without overwriting the area allocated
  640. * above for command line args and board info.
  641. */
  642. asm( "mr %0,1": "=r"(nsp) : );
  643. nsp -= 2048; /* just to be sure */
  644. nsp &= ~0xF;
  645. if (nsp > initrd_high) /* limit as specified */
  646. nsp = initrd_high;
  647. nsp -= len;
  648. nsp &= ~(4096 - 1); /* align on page */
  649. if (nsp >= sp)
  650. initrd_start = nsp;
  651. }
  652. SHOW_BOOT_PROGRESS (12);
  653. debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
  654. data, data + len - 1, len, len);
  655. initrd_end = initrd_start + len;
  656. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  657. initrd_start, initrd_end);
  658. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  659. {
  660. size_t l = len;
  661. void *to = (void *)initrd_start;
  662. void *from = (void *)data;
  663. while (l > 0) {
  664. size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
  665. WATCHDOG_RESET();
  666. memmove (to, from, tail);
  667. to += tail;
  668. from += tail;
  669. l -= tail;
  670. }
  671. }
  672. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  673. memmove ((void *)initrd_start, (void *)data, len);
  674. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  675. puts ("OK\n");
  676. }
  677. } else {
  678. initrd_start = 0;
  679. initrd_end = 0;
  680. }
  681. #ifdef CONFIG_OF_FLAT_TREE
  682. if (initrd_start == 0)
  683. of_flat_tree = (char *)(((ulong)kbd - OF_FLAT_TREE_MAX_SIZE -
  684. sizeof(bd_t)) & ~0xF);
  685. else
  686. of_flat_tree = (char *)((initrd_start - OF_FLAT_TREE_MAX_SIZE -
  687. sizeof(bd_t)) & ~0xF);
  688. #endif
  689. debug ("## Transferring control to Linux (at address %08lx) ...\n",
  690. (ulong)kernel);
  691. SHOW_BOOT_PROGRESS (15);
  692. #ifndef CONFIG_OF_FLAT_TREE
  693. #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
  694. unlock_ram_in_cache();
  695. #endif
  696. /*
  697. * Linux Kernel Parameters:
  698. * r3: ptr to board info data
  699. * r4: initrd_start or 0 if no initrd
  700. * r5: initrd_end - unused if r4 is 0
  701. * r6: Start of command line string
  702. * r7: End of command line string
  703. */
  704. (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
  705. #else
  706. ft_setup(of_flat_tree, OF_FLAT_TREE_MAX_SIZE, kbd, initrd_start, initrd_end);
  707. /* ft_dump_blob(of_flat_tree); */
  708. #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
  709. unlock_ram_in_cache();
  710. #endif
  711. /*
  712. * Linux Kernel Parameters:
  713. * r3: ptr to OF flat tree, followed by the board info data
  714. * r4: physical pointer to the kernel itself
  715. * r5: NULL
  716. * r6: NULL
  717. * r7: NULL
  718. */
  719. if (getenv("disable_of") != NULL)
  720. (*kernel) ((bd_t *)of_flat_tree, initrd_start, initrd_end,
  721. cmd_start, cmd_end);
  722. else
  723. (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0);
  724. #endif
  725. }
  726. #endif /* CONFIG_PPC */
  727. static void
  728. do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
  729. int argc, char *argv[],
  730. ulong addr,
  731. ulong *len_ptr,
  732. int verify)
  733. {
  734. DECLARE_GLOBAL_DATA_PTR;
  735. image_header_t *hdr = &header;
  736. void (*loader)(bd_t *, image_header_t *, char *, char *);
  737. image_header_t *img_addr;
  738. char *consdev;
  739. char *cmdline;
  740. /*
  741. * Booting a (NetBSD) kernel image
  742. *
  743. * This process is pretty similar to a standalone application:
  744. * The (first part of an multi-) image must be a stage-2 loader,
  745. * which in turn is responsible for loading & invoking the actual
  746. * kernel. The only differences are the parameters being passed:
  747. * besides the board info strucure, the loader expects a command
  748. * line, the name of the console device, and (optionally) the
  749. * address of the original image header.
  750. */
  751. img_addr = 0;
  752. if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
  753. img_addr = (image_header_t *) addr;
  754. consdev = "";
  755. #if defined (CONFIG_8xx_CONS_SMC1)
  756. consdev = "smc1";
  757. #elif defined (CONFIG_8xx_CONS_SMC2)
  758. consdev = "smc2";
  759. #elif defined (CONFIG_8xx_CONS_SCC2)
  760. consdev = "scc2";
  761. #elif defined (CONFIG_8xx_CONS_SCC3)
  762. consdev = "scc3";
  763. #endif
  764. if (argc > 2) {
  765. ulong len;
  766. int i;
  767. for (i=2, len=0 ; i<argc ; i+=1)
  768. len += strlen (argv[i]) + 1;
  769. cmdline = malloc (len);
  770. for (i=2, len=0 ; i<argc ; i+=1) {
  771. if (i > 2)
  772. cmdline[len++] = ' ';
  773. strcpy (&cmdline[len], argv[i]);
  774. len += strlen (argv[i]);
  775. }
  776. } else if ((cmdline = getenv("bootargs")) == NULL) {
  777. cmdline = "";
  778. }
  779. loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
  780. printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
  781. (ulong)loader);
  782. SHOW_BOOT_PROGRESS (15);
  783. /*
  784. * NetBSD Stage-2 Loader Parameters:
  785. * r3: ptr to board info data
  786. * r4: image address
  787. * r5: console device
  788. * r6: boot args string
  789. */
  790. (*loader) (gd->bd, img_addr, consdev, cmdline);
  791. }
  792. #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
  793. /* Function that returns a character from the environment */
  794. extern uchar (*env_get_char)(int);
  795. static void
  796. do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
  797. int argc, char *argv[],
  798. ulong addr,
  799. ulong *len_ptr,
  800. int verify)
  801. {
  802. DECLARE_GLOBAL_DATA_PTR;
  803. ulong top;
  804. char *s, *cmdline;
  805. char **fwenv, **ss;
  806. int i, j, nxt, len, envno, envsz;
  807. bd_t *kbd;
  808. void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
  809. image_header_t *hdr = &header;
  810. /*
  811. * Booting an ARTOS kernel image + application
  812. */
  813. /* this used to be the top of memory, but was wrong... */
  814. #ifdef CONFIG_PPC
  815. /* get stack pointer */
  816. asm volatile ("mr %0,1" : "=r"(top) );
  817. #endif
  818. debug ("## Current stack ends at 0x%08lX ", top);
  819. top -= 2048; /* just to be sure */
  820. if (top > CFG_BOOTMAPSZ)
  821. top = CFG_BOOTMAPSZ;
  822. top &= ~0xF;
  823. debug ("=> set upper limit to 0x%08lX\n", top);
  824. /* first check the artos specific boot args, then the linux args*/
  825. if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
  826. s = "";
  827. /* get length of cmdline, and place it */
  828. len = strlen(s);
  829. top = (top - (len + 1)) & ~0xF;
  830. cmdline = (char *)top;
  831. debug ("## cmdline at 0x%08lX ", top);
  832. strcpy(cmdline, s);
  833. /* copy bdinfo */
  834. top = (top - sizeof(bd_t)) & ~0xF;
  835. debug ("## bd at 0x%08lX ", top);
  836. kbd = (bd_t *)top;
  837. memcpy(kbd, gd->bd, sizeof(bd_t));
  838. /* first find number of env entries, and their size */
  839. envno = 0;
  840. envsz = 0;
  841. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  842. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  843. ;
  844. envno++;
  845. envsz += (nxt - i) + 1; /* plus trailing zero */
  846. }
  847. envno++; /* plus the terminating zero */
  848. debug ("## %u envvars total size %u ", envno, envsz);
  849. top = (top - sizeof(char **)*envno) & ~0xF;
  850. fwenv = (char **)top;
  851. debug ("## fwenv at 0x%08lX ", top);
  852. top = (top - envsz) & ~0xF;
  853. s = (char *)top;
  854. ss = fwenv;
  855. /* now copy them */
  856. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  857. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  858. ;
  859. *ss++ = s;
  860. for (j = i; j < nxt; ++j)
  861. *s++ = env_get_char(j);
  862. *s++ = '\0';
  863. }
  864. *ss++ = NULL; /* terminate */
  865. entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
  866. (*entry)(kbd, cmdline, fwenv, top);
  867. }
  868. #endif
  869. #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
  870. int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  871. {
  872. int rcode = 0;
  873. #ifndef CFG_HUSH_PARSER
  874. if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
  875. #else
  876. if (parse_string_outer(getenv("bootcmd"),
  877. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
  878. #endif
  879. return rcode;
  880. }
  881. U_BOOT_CMD(
  882. boot, 1, 1, do_bootd,
  883. "boot - boot default, i.e., run 'bootcmd'\n",
  884. NULL
  885. );
  886. /* keep old command name "bootd" for backward compatibility */
  887. U_BOOT_CMD(
  888. bootd, 1, 1, do_bootd,
  889. "bootd - boot default, i.e., run 'bootcmd'\n",
  890. NULL
  891. );
  892. #endif
  893. #if (CONFIG_COMMANDS & CFG_CMD_IMI)
  894. int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  895. {
  896. int arg;
  897. ulong addr;
  898. int rcode=0;
  899. if (argc < 2) {
  900. return image_info (load_addr);
  901. }
  902. for (arg=1; arg <argc; ++arg) {
  903. addr = simple_strtoul(argv[arg], NULL, 16);
  904. if (image_info (addr) != 0) rcode = 1;
  905. }
  906. return rcode;
  907. }
  908. static int image_info (ulong addr)
  909. {
  910. ulong data, len, checksum;
  911. image_header_t *hdr = &header;
  912. printf ("\n## Checking Image at %08lx ...\n", addr);
  913. /* Copy header so we can blank CRC field for re-calculation */
  914. memmove (&header, (char *)addr, sizeof(image_header_t));
  915. if (ntohl(hdr->ih_magic) != IH_MAGIC) {
  916. puts (" Bad Magic Number\n");
  917. return 1;
  918. }
  919. data = (ulong)&header;
  920. len = sizeof(image_header_t);
  921. checksum = ntohl(hdr->ih_hcrc);
  922. hdr->ih_hcrc = 0;
  923. if (crc32 (0, (uchar *)data, len) != checksum) {
  924. puts (" Bad Header Checksum\n");
  925. return 1;
  926. }
  927. /* for multi-file images we need the data part, too */
  928. print_image_hdr ((image_header_t *)addr);
  929. data = addr + sizeof(image_header_t);
  930. len = ntohl(hdr->ih_size);
  931. puts (" Verifying Checksum ... ");
  932. if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
  933. puts (" Bad Data CRC\n");
  934. return 1;
  935. }
  936. puts ("OK\n");
  937. return 0;
  938. }
  939. U_BOOT_CMD(
  940. iminfo, CFG_MAXARGS, 1, do_iminfo,
  941. "iminfo - print header information for application image\n",
  942. "addr [addr ...]\n"
  943. " - print header information for application image starting at\n"
  944. " address 'addr' in memory; this includes verification of the\n"
  945. " image contents (magic number, header and payload checksums)\n"
  946. );
  947. #endif /* CFG_CMD_IMI */
  948. #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
  949. /*-----------------------------------------------------------------------
  950. * List all images found in flash.
  951. */
  952. int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  953. {
  954. flash_info_t *info;
  955. int i, j;
  956. image_header_t *hdr;
  957. ulong data, len, checksum;
  958. for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
  959. if (info->flash_id == FLASH_UNKNOWN)
  960. goto next_bank;
  961. for (j=0; j<info->sector_count; ++j) {
  962. if (!(hdr=(image_header_t *)info->start[j]) ||
  963. (ntohl(hdr->ih_magic) != IH_MAGIC))
  964. goto next_sector;
  965. /* Copy header so we can blank CRC field for re-calculation */
  966. memmove (&header, (char *)hdr, sizeof(image_header_t));
  967. checksum = ntohl(header.ih_hcrc);
  968. header.ih_hcrc = 0;
  969. if (crc32 (0, (uchar *)&header, sizeof(image_header_t))
  970. != checksum)
  971. goto next_sector;
  972. printf ("Image at %08lX:\n", (ulong)hdr);
  973. print_image_hdr( hdr );
  974. data = (ulong)hdr + sizeof(image_header_t);
  975. len = ntohl(hdr->ih_size);
  976. puts (" Verifying Checksum ... ");
  977. if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
  978. puts (" Bad Data CRC\n");
  979. }
  980. puts ("OK\n");
  981. next_sector: ;
  982. }
  983. next_bank: ;
  984. }
  985. return (0);
  986. }
  987. U_BOOT_CMD(
  988. imls, 1, 1, do_imls,
  989. "imls - list all images found in flash\n",
  990. "\n"
  991. " - Prints information about all images found at sector\n"
  992. " boundaries in flash.\n"
  993. );
  994. #endif /* CFG_CMD_IMLS */
  995. void
  996. print_image_hdr (image_header_t *hdr)
  997. {
  998. #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
  999. time_t timestamp = (time_t)ntohl(hdr->ih_time);
  1000. struct rtc_time tm;
  1001. #endif
  1002. printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
  1003. #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
  1004. to_tm (timestamp, &tm);
  1005. printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
  1006. tm.tm_year, tm.tm_mon, tm.tm_mday,
  1007. tm.tm_hour, tm.tm_min, tm.tm_sec);
  1008. #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
  1009. puts (" Image Type: "); print_type(hdr);
  1010. printf ("\n Data Size: %d Bytes = ", ntohl(hdr->ih_size));
  1011. print_size (ntohl(hdr->ih_size), "\n");
  1012. printf (" Load Address: %08x\n"
  1013. " Entry Point: %08x\n",
  1014. ntohl(hdr->ih_load), ntohl(hdr->ih_ep));
  1015. if (hdr->ih_type == IH_TYPE_MULTI) {
  1016. int i;
  1017. ulong len;
  1018. ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
  1019. puts (" Contents:\n");
  1020. for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
  1021. printf (" Image %d: %8ld Bytes = ", i, len);
  1022. print_size (len, "\n");
  1023. }
  1024. }
  1025. }
  1026. static void
  1027. print_type (image_header_t *hdr)
  1028. {
  1029. char *os, *arch, *type, *comp;
  1030. switch (hdr->ih_os) {
  1031. case IH_OS_INVALID: os = "Invalid OS"; break;
  1032. case IH_OS_NETBSD: os = "NetBSD"; break;
  1033. case IH_OS_LINUX: os = "Linux"; break;
  1034. case IH_OS_VXWORKS: os = "VxWorks"; break;
  1035. case IH_OS_QNX: os = "QNX"; break;
  1036. case IH_OS_U_BOOT: os = "U-Boot"; break;
  1037. case IH_OS_RTEMS: os = "RTEMS"; break;
  1038. #ifdef CONFIG_ARTOS
  1039. case IH_OS_ARTOS: os = "ARTOS"; break;
  1040. #endif
  1041. #ifdef CONFIG_LYNXKDI
  1042. case IH_OS_LYNXOS: os = "LynxOS"; break;
  1043. #endif
  1044. default: os = "Unknown OS"; break;
  1045. }
  1046. switch (hdr->ih_arch) {
  1047. case IH_CPU_INVALID: arch = "Invalid CPU"; break;
  1048. case IH_CPU_ALPHA: arch = "Alpha"; break;
  1049. case IH_CPU_ARM: arch = "ARM"; break;
  1050. case IH_CPU_I386: arch = "Intel x86"; break;
  1051. case IH_CPU_IA64: arch = "IA64"; break;
  1052. case IH_CPU_MIPS: arch = "MIPS"; break;
  1053. case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
  1054. case IH_CPU_PPC: arch = "PowerPC"; break;
  1055. case IH_CPU_S390: arch = "IBM S390"; break;
  1056. case IH_CPU_SH: arch = "SuperH"; break;
  1057. case IH_CPU_SPARC: arch = "SPARC"; break;
  1058. case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
  1059. case IH_CPU_M68K: arch = "M68K"; break;
  1060. case IH_CPU_MICROBLAZE: arch = "Microblaze"; break;
  1061. case IH_CPU_NIOS: arch = "Nios"; break;
  1062. case IH_CPU_NIOS2: arch = "Nios-II"; break;
  1063. default: arch = "Unknown Architecture"; break;
  1064. }
  1065. switch (hdr->ih_type) {
  1066. case IH_TYPE_INVALID: type = "Invalid Image"; break;
  1067. case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
  1068. case IH_TYPE_KERNEL: type = "Kernel Image"; break;
  1069. case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
  1070. case IH_TYPE_MULTI: type = "Multi-File Image"; break;
  1071. case IH_TYPE_FIRMWARE: type = "Firmware"; break;
  1072. case IH_TYPE_SCRIPT: type = "Script"; break;
  1073. default: type = "Unknown Image"; break;
  1074. }
  1075. switch (hdr->ih_comp) {
  1076. case IH_COMP_NONE: comp = "uncompressed"; break;
  1077. case IH_COMP_GZIP: comp = "gzip compressed"; break;
  1078. case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
  1079. default: comp = "unknown compression"; break;
  1080. }
  1081. printf ("%s %s %s (%s)", arch, os, type, comp);
  1082. }
  1083. #define ZALLOC_ALIGNMENT 16
  1084. static void *zalloc(void *x, unsigned items, unsigned size)
  1085. {
  1086. void *p;
  1087. size *= items;
  1088. size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
  1089. p = malloc (size);
  1090. return (p);
  1091. }
  1092. static void zfree(void *x, void *addr, unsigned nb)
  1093. {
  1094. free (addr);
  1095. }
  1096. #define HEAD_CRC 2
  1097. #define EXTRA_FIELD 4
  1098. #define ORIG_NAME 8
  1099. #define COMMENT 0x10
  1100. #define RESERVED 0xe0
  1101. #define DEFLATED 8
  1102. int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
  1103. {
  1104. z_stream s;
  1105. int r, i, flags;
  1106. /* skip header */
  1107. i = 10;
  1108. flags = src[3];
  1109. if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
  1110. puts ("Error: Bad gzipped data\n");
  1111. return (-1);
  1112. }
  1113. if ((flags & EXTRA_FIELD) != 0)
  1114. i = 12 + src[10] + (src[11] << 8);
  1115. if ((flags & ORIG_NAME) != 0)
  1116. while (src[i++] != 0)
  1117. ;
  1118. if ((flags & COMMENT) != 0)
  1119. while (src[i++] != 0)
  1120. ;
  1121. if ((flags & HEAD_CRC) != 0)
  1122. i += 2;
  1123. if (i >= *lenp) {
  1124. puts ("Error: gunzip out of data in header\n");
  1125. return (-1);
  1126. }
  1127. s.zalloc = zalloc;
  1128. s.zfree = zfree;
  1129. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  1130. s.outcb = (cb_func)WATCHDOG_RESET;
  1131. #else
  1132. s.outcb = Z_NULL;
  1133. #endif /* CONFIG_HW_WATCHDOG */
  1134. r = inflateInit2(&s, -MAX_WBITS);
  1135. if (r != Z_OK) {
  1136. printf ("Error: inflateInit2() returned %d\n", r);
  1137. return (-1);
  1138. }
  1139. s.next_in = src + i;
  1140. s.avail_in = *lenp - i;
  1141. s.next_out = dst;
  1142. s.avail_out = dstlen;
  1143. r = inflate(&s, Z_FINISH);
  1144. if (r != Z_OK && r != Z_STREAM_END) {
  1145. printf ("Error: inflate() returned %d\n", r);
  1146. return (-1);
  1147. }
  1148. *lenp = s.next_out - (unsigned char *) dst;
  1149. inflateEnd(&s);
  1150. return (0);
  1151. }
  1152. #ifdef CONFIG_BZIP2
  1153. void bz_internal_error(int errcode)
  1154. {
  1155. printf ("BZIP2 internal error %d\n", errcode);
  1156. }
  1157. #endif /* CONFIG_BZIP2 */
  1158. static void
  1159. do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  1160. ulong addr, ulong *len_ptr, int verify)
  1161. {
  1162. DECLARE_GLOBAL_DATA_PTR;
  1163. image_header_t *hdr = &header;
  1164. void (*entry_point)(bd_t *);
  1165. entry_point = (void (*)(bd_t *)) hdr->ih_ep;
  1166. printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
  1167. (ulong)entry_point);
  1168. SHOW_BOOT_PROGRESS (15);
  1169. /*
  1170. * RTEMS Parameters:
  1171. * r3: ptr to board info data
  1172. */
  1173. (*entry_point ) ( gd->bd );
  1174. }
  1175. #if (CONFIG_COMMANDS & CFG_CMD_ELF)
  1176. static void
  1177. do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  1178. ulong addr, ulong *len_ptr, int verify)
  1179. {
  1180. image_header_t *hdr = &header;
  1181. char str[80];
  1182. sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
  1183. setenv("loadaddr", str);
  1184. do_bootvx(cmdtp, 0, 0, NULL);
  1185. }
  1186. static void
  1187. do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  1188. ulong addr, ulong *len_ptr, int verify)
  1189. {
  1190. image_header_t *hdr = &header;
  1191. char *local_args[2];
  1192. char str[16];
  1193. sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
  1194. local_args[0] = argv[0];
  1195. local_args[1] = str; /* and provide it via the arguments */
  1196. do_bootelf(cmdtp, 0, 2, local_args);
  1197. }
  1198. #endif /* CFG_CMD_ELF */
  1199. #ifdef CONFIG_LYNXKDI
  1200. static void
  1201. do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
  1202. int argc, char *argv[],
  1203. ulong addr,
  1204. ulong *len_ptr,
  1205. int verify)
  1206. {
  1207. lynxkdi_boot( &header );
  1208. }
  1209. #endif /* CONFIG_LYNXKDI */