cmd_bootm.c 33 KB

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