cmd_bootm.c 35 KB

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