cmd_bootm.c 39 KB

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