cmd_bootm.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  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);
  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: initrd_start or 0 if no initrd
  715. * r5: initrd_end - unused if r4 is 0
  716. * r6: Start of command line string
  717. * r7: End of command line string
  718. */
  719. (*kernel) ((bd_t *)of_flat_tree, initrd_start, initrd_end, cmd_start, cmd_end);
  720. #endif
  721. }
  722. #endif /* CONFIG_PPC */
  723. static void
  724. do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
  725. int argc, char *argv[],
  726. ulong addr,
  727. ulong *len_ptr,
  728. int verify)
  729. {
  730. DECLARE_GLOBAL_DATA_PTR;
  731. image_header_t *hdr = &header;
  732. void (*loader)(bd_t *, image_header_t *, char *, char *);
  733. image_header_t *img_addr;
  734. char *consdev;
  735. char *cmdline;
  736. /*
  737. * Booting a (NetBSD) kernel image
  738. *
  739. * This process is pretty similar to a standalone application:
  740. * The (first part of an multi-) image must be a stage-2 loader,
  741. * which in turn is responsible for loading & invoking the actual
  742. * kernel. The only differences are the parameters being passed:
  743. * besides the board info strucure, the loader expects a command
  744. * line, the name of the console device, and (optionally) the
  745. * address of the original image header.
  746. */
  747. img_addr = 0;
  748. if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
  749. img_addr = (image_header_t *) addr;
  750. consdev = "";
  751. #if defined (CONFIG_8xx_CONS_SMC1)
  752. consdev = "smc1";
  753. #elif defined (CONFIG_8xx_CONS_SMC2)
  754. consdev = "smc2";
  755. #elif defined (CONFIG_8xx_CONS_SCC2)
  756. consdev = "scc2";
  757. #elif defined (CONFIG_8xx_CONS_SCC3)
  758. consdev = "scc3";
  759. #endif
  760. if (argc > 2) {
  761. ulong len;
  762. int i;
  763. for (i=2, len=0 ; i<argc ; i+=1)
  764. len += strlen (argv[i]) + 1;
  765. cmdline = malloc (len);
  766. for (i=2, len=0 ; i<argc ; i+=1) {
  767. if (i > 2)
  768. cmdline[len++] = ' ';
  769. strcpy (&cmdline[len], argv[i]);
  770. len += strlen (argv[i]);
  771. }
  772. } else if ((cmdline = getenv("bootargs")) == NULL) {
  773. cmdline = "";
  774. }
  775. loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
  776. printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
  777. (ulong)loader);
  778. SHOW_BOOT_PROGRESS (15);
  779. /*
  780. * NetBSD Stage-2 Loader Parameters:
  781. * r3: ptr to board info data
  782. * r4: image address
  783. * r5: console device
  784. * r6: boot args string
  785. */
  786. (*loader) (gd->bd, img_addr, consdev, cmdline);
  787. }
  788. #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
  789. /* Function that returns a character from the environment */
  790. extern uchar (*env_get_char)(int);
  791. static void
  792. do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
  793. int argc, char *argv[],
  794. ulong addr,
  795. ulong *len_ptr,
  796. int verify)
  797. {
  798. DECLARE_GLOBAL_DATA_PTR;
  799. ulong top;
  800. char *s, *cmdline;
  801. char **fwenv, **ss;
  802. int i, j, nxt, len, envno, envsz;
  803. bd_t *kbd;
  804. void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
  805. image_header_t *hdr = &header;
  806. /*
  807. * Booting an ARTOS kernel image + application
  808. */
  809. /* this used to be the top of memory, but was wrong... */
  810. #ifdef CONFIG_PPC
  811. /* get stack pointer */
  812. asm volatile ("mr %0,1" : "=r"(top) );
  813. #endif
  814. debug ("## Current stack ends at 0x%08lX ", top);
  815. top -= 2048; /* just to be sure */
  816. if (top > CFG_BOOTMAPSZ)
  817. top = CFG_BOOTMAPSZ;
  818. top &= ~0xF;
  819. debug ("=> set upper limit to 0x%08lX\n", top);
  820. /* first check the artos specific boot args, then the linux args*/
  821. if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
  822. s = "";
  823. /* get length of cmdline, and place it */
  824. len = strlen(s);
  825. top = (top - (len + 1)) & ~0xF;
  826. cmdline = (char *)top;
  827. debug ("## cmdline at 0x%08lX ", top);
  828. strcpy(cmdline, s);
  829. /* copy bdinfo */
  830. top = (top - sizeof(bd_t)) & ~0xF;
  831. debug ("## bd at 0x%08lX ", top);
  832. kbd = (bd_t *)top;
  833. memcpy(kbd, gd->bd, sizeof(bd_t));
  834. /* first find number of env entries, and their size */
  835. envno = 0;
  836. envsz = 0;
  837. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  838. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  839. ;
  840. envno++;
  841. envsz += (nxt - i) + 1; /* plus trailing zero */
  842. }
  843. envno++; /* plus the terminating zero */
  844. debug ("## %u envvars total size %u ", envno, envsz);
  845. top = (top - sizeof(char **)*envno) & ~0xF;
  846. fwenv = (char **)top;
  847. debug ("## fwenv at 0x%08lX ", top);
  848. top = (top - envsz) & ~0xF;
  849. s = (char *)top;
  850. ss = fwenv;
  851. /* now copy them */
  852. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  853. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  854. ;
  855. *ss++ = s;
  856. for (j = i; j < nxt; ++j)
  857. *s++ = env_get_char(j);
  858. *s++ = '\0';
  859. }
  860. *ss++ = NULL; /* terminate */
  861. entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
  862. (*entry)(kbd, cmdline, fwenv, top);
  863. }
  864. #endif
  865. #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
  866. int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  867. {
  868. int rcode = 0;
  869. #ifndef CFG_HUSH_PARSER
  870. if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
  871. #else
  872. if (parse_string_outer(getenv("bootcmd"),
  873. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
  874. #endif
  875. return rcode;
  876. }
  877. U_BOOT_CMD(
  878. boot, 1, 1, do_bootd,
  879. "boot - boot default, i.e., run 'bootcmd'\n",
  880. NULL
  881. );
  882. /* keep old command name "bootd" for backward compatibility */
  883. U_BOOT_CMD(
  884. bootd, 1, 1, do_bootd,
  885. "bootd - boot default, i.e., run 'bootcmd'\n",
  886. NULL
  887. );
  888. #endif
  889. #if (CONFIG_COMMANDS & CFG_CMD_IMI)
  890. int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  891. {
  892. int arg;
  893. ulong addr;
  894. int rcode=0;
  895. if (argc < 2) {
  896. return image_info (load_addr);
  897. }
  898. for (arg=1; arg <argc; ++arg) {
  899. addr = simple_strtoul(argv[arg], NULL, 16);
  900. if (image_info (addr) != 0) rcode = 1;
  901. }
  902. return rcode;
  903. }
  904. static int image_info (ulong addr)
  905. {
  906. ulong data, len, checksum;
  907. image_header_t *hdr = &header;
  908. printf ("\n## Checking Image at %08lx ...\n", addr);
  909. /* Copy header so we can blank CRC field for re-calculation */
  910. memmove (&header, (char *)addr, sizeof(image_header_t));
  911. if (ntohl(hdr->ih_magic) != IH_MAGIC) {
  912. puts (" Bad Magic Number\n");
  913. return 1;
  914. }
  915. data = (ulong)&header;
  916. len = sizeof(image_header_t);
  917. checksum = ntohl(hdr->ih_hcrc);
  918. hdr->ih_hcrc = 0;
  919. if (crc32 (0, (uchar *)data, len) != checksum) {
  920. puts (" Bad Header Checksum\n");
  921. return 1;
  922. }
  923. /* for multi-file images we need the data part, too */
  924. print_image_hdr ((image_header_t *)addr);
  925. data = addr + sizeof(image_header_t);
  926. len = ntohl(hdr->ih_size);
  927. puts (" Verifying Checksum ... ");
  928. if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
  929. puts (" Bad Data CRC\n");
  930. return 1;
  931. }
  932. puts ("OK\n");
  933. return 0;
  934. }
  935. U_BOOT_CMD(
  936. iminfo, CFG_MAXARGS, 1, do_iminfo,
  937. "iminfo - print header information for application image\n",
  938. "addr [addr ...]\n"
  939. " - print header information for application image starting at\n"
  940. " address 'addr' in memory; this includes verification of the\n"
  941. " image contents (magic number, header and payload checksums)\n"
  942. );
  943. #endif /* CFG_CMD_IMI */
  944. #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
  945. /*-----------------------------------------------------------------------
  946. * List all images found in flash.
  947. */
  948. int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  949. {
  950. flash_info_t *info;
  951. int i, j;
  952. image_header_t *hdr;
  953. ulong data, len, checksum;
  954. for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
  955. if (info->flash_id == FLASH_UNKNOWN)
  956. goto next_bank;
  957. for (j=0; j<info->sector_count; ++j) {
  958. if (!(hdr=(image_header_t *)info->start[j]) ||
  959. (ntohl(hdr->ih_magic) != IH_MAGIC))
  960. goto next_sector;
  961. /* Copy header so we can blank CRC field for re-calculation */
  962. memmove (&header, (char *)hdr, sizeof(image_header_t));
  963. checksum = ntohl(header.ih_hcrc);
  964. header.ih_hcrc = 0;
  965. if (crc32 (0, (uchar *)&header, sizeof(image_header_t))
  966. != checksum)
  967. goto next_sector;
  968. printf ("Image at %08lX:\n", (ulong)hdr);
  969. print_image_hdr( hdr );
  970. data = (ulong)hdr + sizeof(image_header_t);
  971. len = ntohl(hdr->ih_size);
  972. puts (" Verifying Checksum ... ");
  973. if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) {
  974. puts (" Bad Data CRC\n");
  975. }
  976. puts ("OK\n");
  977. next_sector: ;
  978. }
  979. next_bank: ;
  980. }
  981. return (0);
  982. }
  983. U_BOOT_CMD(
  984. imls, 1, 1, do_imls,
  985. "imls - list all images found in flash\n",
  986. "\n"
  987. " - Prints information about all images found at sector\n"
  988. " boundaries in flash.\n"
  989. );
  990. #endif /* CFG_CMD_IMLS */
  991. void
  992. print_image_hdr (image_header_t *hdr)
  993. {
  994. #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
  995. time_t timestamp = (time_t)ntohl(hdr->ih_time);
  996. struct rtc_time tm;
  997. #endif
  998. printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
  999. #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
  1000. to_tm (timestamp, &tm);
  1001. printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
  1002. tm.tm_year, tm.tm_mon, tm.tm_mday,
  1003. tm.tm_hour, tm.tm_min, tm.tm_sec);
  1004. #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
  1005. puts (" Image Type: "); print_type(hdr);
  1006. printf ("\n Data Size: %d Bytes = ", ntohl(hdr->ih_size));
  1007. print_size (ntohl(hdr->ih_size), "\n");
  1008. printf (" Load Address: %08x\n"
  1009. " Entry Point: %08x\n",
  1010. ntohl(hdr->ih_load), ntohl(hdr->ih_ep));
  1011. if (hdr->ih_type == IH_TYPE_MULTI) {
  1012. int i;
  1013. ulong len;
  1014. ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
  1015. puts (" Contents:\n");
  1016. for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
  1017. printf (" Image %d: %8ld Bytes = ", i, len);
  1018. print_size (len, "\n");
  1019. }
  1020. }
  1021. }
  1022. static void
  1023. print_type (image_header_t *hdr)
  1024. {
  1025. char *os, *arch, *type, *comp;
  1026. switch (hdr->ih_os) {
  1027. case IH_OS_INVALID: os = "Invalid OS"; break;
  1028. case IH_OS_NETBSD: os = "NetBSD"; break;
  1029. case IH_OS_LINUX: os = "Linux"; break;
  1030. case IH_OS_VXWORKS: os = "VxWorks"; break;
  1031. case IH_OS_QNX: os = "QNX"; break;
  1032. case IH_OS_U_BOOT: os = "U-Boot"; break;
  1033. case IH_OS_RTEMS: os = "RTEMS"; break;
  1034. #ifdef CONFIG_ARTOS
  1035. case IH_OS_ARTOS: os = "ARTOS"; break;
  1036. #endif
  1037. #ifdef CONFIG_LYNXKDI
  1038. case IH_OS_LYNXOS: os = "LynxOS"; break;
  1039. #endif
  1040. default: os = "Unknown OS"; break;
  1041. }
  1042. switch (hdr->ih_arch) {
  1043. case IH_CPU_INVALID: arch = "Invalid CPU"; break;
  1044. case IH_CPU_ALPHA: arch = "Alpha"; break;
  1045. case IH_CPU_ARM: arch = "ARM"; break;
  1046. case IH_CPU_I386: arch = "Intel x86"; break;
  1047. case IH_CPU_IA64: arch = "IA64"; break;
  1048. case IH_CPU_MIPS: arch = "MIPS"; break;
  1049. case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
  1050. case IH_CPU_PPC: arch = "PowerPC"; break;
  1051. case IH_CPU_S390: arch = "IBM S390"; break;
  1052. case IH_CPU_SH: arch = "SuperH"; break;
  1053. case IH_CPU_SPARC: arch = "SPARC"; break;
  1054. case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
  1055. case IH_CPU_M68K: arch = "M68K"; break;
  1056. case IH_CPU_MICROBLAZE: arch = "Microblaze"; break;
  1057. case IH_CPU_NIOS: arch = "Nios"; break;
  1058. case IH_CPU_NIOS2: arch = "Nios-II"; break;
  1059. default: arch = "Unknown Architecture"; break;
  1060. }
  1061. switch (hdr->ih_type) {
  1062. case IH_TYPE_INVALID: type = "Invalid Image"; break;
  1063. case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
  1064. case IH_TYPE_KERNEL: type = "Kernel Image"; break;
  1065. case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
  1066. case IH_TYPE_MULTI: type = "Multi-File Image"; break;
  1067. case IH_TYPE_FIRMWARE: type = "Firmware"; break;
  1068. case IH_TYPE_SCRIPT: type = "Script"; break;
  1069. default: type = "Unknown Image"; break;
  1070. }
  1071. switch (hdr->ih_comp) {
  1072. case IH_COMP_NONE: comp = "uncompressed"; break;
  1073. case IH_COMP_GZIP: comp = "gzip compressed"; break;
  1074. case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
  1075. default: comp = "unknown compression"; break;
  1076. }
  1077. printf ("%s %s %s (%s)", arch, os, type, comp);
  1078. }
  1079. #define ZALLOC_ALIGNMENT 16
  1080. static void *zalloc(void *x, unsigned items, unsigned size)
  1081. {
  1082. void *p;
  1083. size *= items;
  1084. size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
  1085. p = malloc (size);
  1086. return (p);
  1087. }
  1088. static void zfree(void *x, void *addr, unsigned nb)
  1089. {
  1090. free (addr);
  1091. }
  1092. #define HEAD_CRC 2
  1093. #define EXTRA_FIELD 4
  1094. #define ORIG_NAME 8
  1095. #define COMMENT 0x10
  1096. #define RESERVED 0xe0
  1097. #define DEFLATED 8
  1098. int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
  1099. {
  1100. z_stream s;
  1101. int r, i, flags;
  1102. /* skip header */
  1103. i = 10;
  1104. flags = src[3];
  1105. if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
  1106. puts ("Error: Bad gzipped data\n");
  1107. return (-1);
  1108. }
  1109. if ((flags & EXTRA_FIELD) != 0)
  1110. i = 12 + src[10] + (src[11] << 8);
  1111. if ((flags & ORIG_NAME) != 0)
  1112. while (src[i++] != 0)
  1113. ;
  1114. if ((flags & COMMENT) != 0)
  1115. while (src[i++] != 0)
  1116. ;
  1117. if ((flags & HEAD_CRC) != 0)
  1118. i += 2;
  1119. if (i >= *lenp) {
  1120. puts ("Error: gunzip out of data in header\n");
  1121. return (-1);
  1122. }
  1123. s.zalloc = zalloc;
  1124. s.zfree = zfree;
  1125. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  1126. s.outcb = (cb_func)WATCHDOG_RESET;
  1127. #else
  1128. s.outcb = Z_NULL;
  1129. #endif /* CONFIG_HW_WATCHDOG */
  1130. r = inflateInit2(&s, -MAX_WBITS);
  1131. if (r != Z_OK) {
  1132. printf ("Error: inflateInit2() returned %d\n", r);
  1133. return (-1);
  1134. }
  1135. s.next_in = src + i;
  1136. s.avail_in = *lenp - i;
  1137. s.next_out = dst;
  1138. s.avail_out = dstlen;
  1139. r = inflate(&s, Z_FINISH);
  1140. if (r != Z_OK && r != Z_STREAM_END) {
  1141. printf ("Error: inflate() returned %d\n", r);
  1142. return (-1);
  1143. }
  1144. *lenp = s.next_out - (unsigned char *) dst;
  1145. inflateEnd(&s);
  1146. return (0);
  1147. }
  1148. #ifdef CONFIG_BZIP2
  1149. void bz_internal_error(int errcode)
  1150. {
  1151. printf ("BZIP2 internal error %d\n", errcode);
  1152. }
  1153. #endif /* CONFIG_BZIP2 */
  1154. static void
  1155. do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  1156. ulong addr, ulong *len_ptr, int verify)
  1157. {
  1158. DECLARE_GLOBAL_DATA_PTR;
  1159. image_header_t *hdr = &header;
  1160. void (*entry_point)(bd_t *);
  1161. entry_point = (void (*)(bd_t *)) hdr->ih_ep;
  1162. printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
  1163. (ulong)entry_point);
  1164. SHOW_BOOT_PROGRESS (15);
  1165. /*
  1166. * RTEMS Parameters:
  1167. * r3: ptr to board info data
  1168. */
  1169. (*entry_point ) ( gd->bd );
  1170. }
  1171. #if (CONFIG_COMMANDS & CFG_CMD_ELF)
  1172. static void
  1173. do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  1174. ulong addr, ulong *len_ptr, int verify)
  1175. {
  1176. image_header_t *hdr = &header;
  1177. char str[80];
  1178. sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
  1179. setenv("loadaddr", str);
  1180. do_bootvx(cmdtp, 0, 0, NULL);
  1181. }
  1182. static void
  1183. do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  1184. ulong addr, ulong *len_ptr, int verify)
  1185. {
  1186. image_header_t *hdr = &header;
  1187. char *local_args[2];
  1188. char str[16];
  1189. sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
  1190. local_args[0] = argv[0];
  1191. local_args[1] = str; /* and provide it via the arguments */
  1192. do_bootelf(cmdtp, 0, 2, local_args);
  1193. }
  1194. #endif /* CFG_CMD_ELF */
  1195. #ifdef CONFIG_LYNXKDI
  1196. static void
  1197. do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
  1198. int argc, char *argv[],
  1199. ulong addr,
  1200. ulong *len_ptr,
  1201. int verify)
  1202. {
  1203. lynxkdi_boot( &header );
  1204. }
  1205. #endif /* CONFIG_LYNXKDI */