image.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /*
  2. * (C) Copyright 2008 Semihalf
  3. *
  4. * (C) Copyright 2000-2006
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #define DEBUG
  26. #ifndef USE_HOSTCC
  27. #include <common.h>
  28. #include <watchdog.h>
  29. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  30. #include <status_led.h>
  31. #endif
  32. #ifdef CONFIG_HAS_DATAFLASH
  33. #include <dataflash.h>
  34. #endif
  35. #ifdef CONFIG_LOGBUFFER
  36. #include <logbuff.h>
  37. #endif
  38. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  39. #ifdef CONFIG_CMD_BDI
  40. extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  41. #endif
  42. DECLARE_GLOBAL_DATA_PTR;
  43. #else
  44. #include "mkimage.h"
  45. #endif /* USE_HOSTCC*/
  46. #include <image.h>
  47. unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
  48. int image_check_hcrc (image_header_t *hdr)
  49. {
  50. ulong hcrc;
  51. ulong len = image_get_header_size ();
  52. image_header_t header;
  53. /* Copy header so we can blank CRC field for re-calculation */
  54. memmove (&header, (char *)hdr, image_get_header_size ());
  55. image_set_hcrc (&header, 0);
  56. hcrc = crc32 (0, (unsigned char *)&header, len);
  57. return (hcrc == image_get_hcrc (hdr));
  58. }
  59. int image_check_dcrc (image_header_t *hdr)
  60. {
  61. ulong data = image_get_data (hdr);
  62. ulong len = image_get_data_size (hdr);
  63. ulong dcrc = crc32 (0, (unsigned char *)data, len);
  64. return (dcrc == image_get_dcrc (hdr));
  65. }
  66. #ifndef USE_HOSTCC
  67. int image_check_dcrc_wd (image_header_t *hdr, ulong chunksz)
  68. {
  69. ulong dcrc = 0;
  70. ulong len = image_get_data_size (hdr);
  71. ulong data = image_get_data (hdr);
  72. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  73. ulong cdata = data;
  74. ulong edata = cdata + len;
  75. while (cdata < edata) {
  76. ulong chunk = edata - cdata;
  77. if (chunk > chunksz)
  78. chunk = chunksz;
  79. dcrc = crc32 (dcrc, (unsigned char *)cdata, chunk);
  80. cdata += chunk;
  81. WATCHDOG_RESET ();
  82. }
  83. #else
  84. dcrc = crc32 (0, (unsigned char *)data, len);
  85. #endif
  86. return (dcrc == image_get_dcrc (hdr));
  87. }
  88. int getenv_verify (void)
  89. {
  90. char *s = getenv ("verify");
  91. return (s && (*s == 'n')) ? 0 : 1;
  92. }
  93. void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
  94. {
  95. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  96. while (len > 0) {
  97. size_t tail = (len > chunksz) ? chunksz : len;
  98. WATCHDOG_RESET ();
  99. memmove (to, from, tail);
  100. to += tail;
  101. from += tail;
  102. len -= tail;
  103. }
  104. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  105. memmove (to, from, len);
  106. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  107. }
  108. #endif /* USE_HOSTCC */
  109. /**
  110. * image_multi_count - get component (sub-image) count
  111. * @hdr: pointer to the header of the multi component image
  112. *
  113. * image_multi_count() returns number of components in a multi
  114. * component image.
  115. *
  116. * Note: no checking of the image type is done, caller must pass
  117. * a valid multi component image.
  118. *
  119. * returns:
  120. * number of components
  121. */
  122. ulong image_multi_count (image_header_t *hdr)
  123. {
  124. ulong i, count = 0;
  125. ulong *size;
  126. /* get start of the image payload, which in case of multi
  127. * component images that points to a table of component sizes */
  128. size = (ulong *)image_get_data (hdr);
  129. /* count non empty slots */
  130. for (i = 0; size[i]; ++i)
  131. count++;
  132. return count;
  133. }
  134. /**
  135. * image_multi_getimg - get component data address and size
  136. * @hdr: pointer to the header of the multi component image
  137. * @idx: index of the requested component
  138. * @data: pointer to a ulong variable, will hold component data address
  139. * @len: pointer to a ulong variable, will hold component size
  140. *
  141. * image_multi_getimg() returns size and data address for the requested
  142. * component in a multi component image.
  143. *
  144. * Note: no checking of the image type is done, caller must pass
  145. * a valid multi component image.
  146. *
  147. * returns:
  148. * data address and size of the component, if idx is valid
  149. * 0 in data and len, if idx is out of range
  150. */
  151. void image_multi_getimg (image_header_t *hdr, ulong idx,
  152. ulong *data, ulong *len)
  153. {
  154. int i;
  155. ulong *size;
  156. ulong offset, tail, count, img_data;
  157. /* get number of component */
  158. count = image_multi_count (hdr);
  159. /* get start of the image payload, which in case of multi
  160. * component images that points to a table of component sizes */
  161. size = (ulong *)image_get_data (hdr);
  162. /* get address of the proper component data start, which means
  163. * skipping sizes table (add 1 for last, null entry) */
  164. img_data = image_get_data (hdr) + (count + 1) * sizeof (ulong);
  165. if (idx < count) {
  166. *len = size[idx];
  167. offset = 0;
  168. tail = 0;
  169. /* go over all indices preceding requested component idx */
  170. for (i = 0; i < idx; i++) {
  171. /* add up i-th component size */
  172. offset += size[i];
  173. /* add up alignment for i-th component */
  174. tail += (4 - size[i] % 4);
  175. }
  176. /* calculate idx-th component data address */
  177. *data = img_data + offset + tail;
  178. } else {
  179. *len = 0;
  180. *data = 0;
  181. }
  182. }
  183. #ifndef USE_HOSTCC
  184. const char* image_get_os_name (uint8_t os)
  185. {
  186. const char *name;
  187. switch (os) {
  188. case IH_OS_INVALID: name = "Invalid OS"; break;
  189. case IH_OS_NETBSD: name = "NetBSD"; break;
  190. case IH_OS_LINUX: name = "Linux"; break;
  191. case IH_OS_VXWORKS: name = "VxWorks"; break;
  192. case IH_OS_QNX: name = "QNX"; break;
  193. case IH_OS_U_BOOT: name = "U-Boot"; break;
  194. case IH_OS_RTEMS: name = "RTEMS"; break;
  195. #ifdef CONFIG_ARTOS
  196. case IH_OS_ARTOS: name = "ARTOS"; break;
  197. #endif
  198. #ifdef CONFIG_LYNXKDI
  199. case IH_OS_LYNXOS: name = "LynxOS"; break;
  200. #endif
  201. default: name = "Unknown OS"; break;
  202. }
  203. return name;
  204. }
  205. const char* image_get_arch_name (uint8_t arch)
  206. {
  207. const char *name;
  208. switch (arch) {
  209. case IH_ARCH_INVALID: name = "Invalid Architecture"; break;
  210. case IH_ARCH_ALPHA: name = "Alpha"; break;
  211. case IH_ARCH_ARM: name = "ARM"; break;
  212. case IH_ARCH_AVR32: name = "AVR32"; break;
  213. case IH_ARCH_BLACKFIN: name = "Blackfin"; break;
  214. case IH_ARCH_I386: name = "Intel x86"; break;
  215. case IH_ARCH_IA64: name = "IA64"; break;
  216. case IH_ARCH_M68K: name = "M68K"; break;
  217. case IH_ARCH_MICROBLAZE:name = "Microblaze"; break;
  218. case IH_ARCH_MIPS64: name = "MIPS 64 Bit"; break;
  219. case IH_ARCH_MIPS: name = "MIPS"; break;
  220. case IH_ARCH_NIOS2: name = "Nios-II"; break;
  221. case IH_ARCH_NIOS: name = "Nios"; break;
  222. case IH_ARCH_PPC: name = "PowerPC"; break;
  223. case IH_ARCH_S390: name = "IBM S390"; break;
  224. case IH_ARCH_SH: name = "SuperH"; break;
  225. case IH_ARCH_SPARC64: name = "SPARC 64 Bit"; break;
  226. case IH_ARCH_SPARC: name = "SPARC"; break;
  227. default: name = "Unknown Architecture"; break;
  228. }
  229. return name;
  230. }
  231. const char* image_get_type_name (uint8_t type)
  232. {
  233. const char *name;
  234. switch (type) {
  235. case IH_TYPE_INVALID: name = "Invalid Image"; break;
  236. case IH_TYPE_STANDALONE:name = "Standalone Program"; break;
  237. case IH_TYPE_KERNEL: name = "Kernel Image"; break;
  238. case IH_TYPE_RAMDISK: name = "RAMDisk Image"; break;
  239. case IH_TYPE_MULTI: name = "Multi-File Image"; break;
  240. case IH_TYPE_FIRMWARE: name = "Firmware"; break;
  241. case IH_TYPE_SCRIPT: name = "Script"; break;
  242. case IH_TYPE_FLATDT: name = "Flat Device Tree"; break;
  243. default: name = "Unknown Image"; break;
  244. }
  245. return name;
  246. }
  247. const char* image_get_comp_name (uint8_t comp)
  248. {
  249. const char *name;
  250. switch (comp) {
  251. case IH_COMP_NONE: name = "uncompressed"; break;
  252. case IH_COMP_GZIP: name = "gzip compressed"; break;
  253. case IH_COMP_BZIP2: name = "bzip2 compressed"; break;
  254. default: name = "unknown compression"; break;
  255. }
  256. return name;
  257. }
  258. /**
  259. * image_get_ramdisk - get and verify ramdisk image
  260. * @cmdtp: command table pointer
  261. * @flag: command flag
  262. * @argc: command argument count
  263. * @argv: command argument list
  264. * @rd_addr: ramdisk image start address
  265. * @arch: expected ramdisk architecture
  266. * @verify: checksum verification flag
  267. *
  268. * image_get_ramdisk() returns a pointer to the verified ramdisk image
  269. * header. Routine receives image start address and expected architecture
  270. * flag. Verification done covers data and header integrity and os/type/arch
  271. * fields checking.
  272. *
  273. * If dataflash support is enabled routine checks for dataflash addresses
  274. * and handles required dataflash reads.
  275. *
  276. * returns:
  277. * pointer to a ramdisk image header, if image was found and valid
  278. * otherwise, board is reset
  279. */
  280. image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
  281. int argc, char *argv[],
  282. ulong rd_addr, uint8_t arch, int verify)
  283. {
  284. image_header_t *rd_hdr;
  285. show_boot_progress (9);
  286. #ifdef CONFIG_HAS_DATAFLASH
  287. if (addr_dataflash (rd_addr)) {
  288. rd_hdr = (image_header_t *)CFG_LOAD_ADDR;
  289. debug (" Reading Ramdisk image header from dataflash address "
  290. "%08lx to %08lx\n", rd_addr, (ulong)rd_hdr);
  291. read_dataflash (rd_addr, image_get_header_size (),
  292. (char *)rd_hdr);
  293. } else
  294. #endif
  295. rd_hdr = (image_header_t *)rd_addr;
  296. if (!image_check_magic (rd_hdr)) {
  297. puts ("Bad Magic Number\n");
  298. show_boot_progress (-10);
  299. do_reset (cmdtp, flag, argc, argv);
  300. }
  301. if (!image_check_hcrc (rd_hdr)) {
  302. puts ("Bad Header Checksum\n");
  303. show_boot_progress (-11);
  304. do_reset (cmdtp, flag, argc, argv);
  305. }
  306. show_boot_progress (10);
  307. print_image_hdr (rd_hdr);
  308. #ifdef CONFIG_HAS_DATAFLASH
  309. if (addr_dataflash (rd_addr)) {
  310. debug (" Reading Ramdisk image data from dataflash address "
  311. "%08lx to %08lx\n", rd_addr + image_get_header_size,
  312. (ulong)image_get_data (rd_hdr));
  313. read_dataflash (rd_addr + image_get_header_size (),
  314. image_get_data_size (rd_hdr),
  315. (char *)image_get_data (rd_hdr));
  316. }
  317. #endif
  318. if (verify) {
  319. puts(" Verifying Checksum ... ");
  320. if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) {
  321. puts ("Bad Data CRC\n");
  322. show_boot_progress (-12);
  323. do_reset (cmdtp, flag, argc, argv);
  324. }
  325. puts("OK\n");
  326. }
  327. show_boot_progress (11);
  328. if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
  329. !image_check_arch (rd_hdr, arch) ||
  330. !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
  331. printf ("No Linux %s Ramdisk Image\n",
  332. image_get_arch_name(arch));
  333. show_boot_progress (-13);
  334. do_reset (cmdtp, flag, argc, argv);
  335. }
  336. return rd_hdr;
  337. }
  338. /**
  339. * get_ramdisk - main ramdisk handling routine
  340. * @cmdtp: command table pointer
  341. * @flag: command flag
  342. * @argc: command argument count
  343. * @argv: command argument list
  344. * @hdr: pointer to the posiibly multi componet kernel image
  345. * @verify: checksum verification flag
  346. * @arch: expected ramdisk architecture
  347. * @rd_start: pointer to a ulong variable, will hold ramdisk start address
  348. * @rd_end: pointer to a ulong variable, will hold ramdisk end
  349. *
  350. * get_ramdisk() is responsible for finding a valid ramdisk image.
  351. * Curently supported are the following ramdisk sources:
  352. * - multicomponent kernel/ramdisk image,
  353. * - commandline provided address of decicated ramdisk image.
  354. *
  355. * returns:
  356. * rd_start and rd_end are set to ramdisk start/end addresses if
  357. * ramdisk image is found and valid
  358. * rd_start and rd_end are set to 0 if no ramdisk exists
  359. * board is reset if ramdisk image is found but corrupted
  360. */
  361. void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  362. image_header_t *hdr, int verify, uint8_t arch,
  363. ulong *rd_start, ulong *rd_end)
  364. {
  365. ulong rd_addr;
  366. ulong rd_data, rd_len;
  367. image_header_t *rd_hdr;
  368. if (argc >= 3) {
  369. /*
  370. * Look for a '-' which indicates to ignore the
  371. * ramdisk argument
  372. */
  373. if (strcmp(argv[2], "-") == 0) {
  374. debug ("## Skipping init Ramdisk\n");
  375. rd_len = rd_data = 0;
  376. } else {
  377. /*
  378. * Check if there is an initrd image at the
  379. * address provided in the second bootm argument
  380. */
  381. rd_addr = simple_strtoul (argv[2], NULL, 16);
  382. printf ("## Loading init Ramdisk Image at %08lx ...\n",
  383. rd_addr);
  384. rd_hdr = image_get_ramdisk (cmdtp, flag, argc, argv,
  385. rd_addr, arch, verify);
  386. rd_data = image_get_data (rd_hdr);
  387. rd_len = image_get_data_size (rd_hdr);
  388. #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
  389. /*
  390. *we need to copy the ramdisk to SRAM to let Linux boot
  391. */
  392. memmove ((void *)image_get_load (rd_hdr),
  393. (uchar *)rd_data, rd_len);
  394. rd_data = image_get_load (rd_hdr);
  395. #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
  396. }
  397. } else if (image_check_type (hdr, IH_TYPE_MULTI)) {
  398. /*
  399. * Now check if we have a multifile image
  400. * Get second entry data start address and len
  401. */
  402. show_boot_progress (13);
  403. printf ("## Loading init Ramdisk from multi component "
  404. "Image at %08lx ...\n", (ulong)hdr);
  405. image_multi_getimg (hdr, 1, &rd_data, &rd_len);
  406. } else {
  407. /*
  408. * no initrd image
  409. */
  410. show_boot_progress (14);
  411. rd_len = rd_data = 0;
  412. }
  413. if (!rd_data) {
  414. debug ("## No init Ramdisk\n");
  415. *rd_start = 0;
  416. *rd_end = 0;
  417. } else {
  418. *rd_start = rd_data;
  419. *rd_end = rd_data + rd_len;
  420. }
  421. debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
  422. *rd_start, *rd_end);
  423. }
  424. #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
  425. /**
  426. * ramdisk_high - relocate init ramdisk
  427. * @rd_data: ramdisk data start address
  428. * @rd_len: ramdisk data length
  429. * @kbd: kernel board info copy (within BOOTMAPSZ boundary)
  430. * @sp_limit: stack pointer limit (including BOOTMAPSZ)
  431. * @sp: current stack pointer
  432. * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
  433. * start address (after possible relocation)
  434. * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
  435. * end address (after possible relocation)
  436. *
  437. * ramdisk_high() takes a relocation hint from "initrd_high" environement
  438. * variable and if requested ramdisk data is moved to a specified location.
  439. *
  440. * returns:
  441. * - initrd_start and initrd_end are set to final (after relocation) ramdisk
  442. * start/end addresses if ramdisk image start and len were provided
  443. * otherwise set initrd_start and initrd_end set to zeros
  444. * - returns new allc_current, next free address below BOOTMAPSZ
  445. */
  446. ulong ramdisk_high (ulong alloc_current, ulong rd_data, ulong rd_len,
  447. bd_t *kbd, ulong sp_limit, ulong sp,
  448. ulong *initrd_start, ulong *initrd_end)
  449. {
  450. char *s;
  451. ulong initrd_high;
  452. int initrd_copy_to_ram = 1;
  453. ulong new_alloc_current = alloc_current;
  454. if ((s = getenv ("initrd_high")) != NULL) {
  455. /* a value of "no" or a similar string will act like 0,
  456. * turning the "load high" feature off. This is intentional.
  457. */
  458. initrd_high = simple_strtoul (s, NULL, 16);
  459. if (initrd_high == ~0)
  460. initrd_copy_to_ram = 0;
  461. } else {
  462. /* not set, no restrictions to load high */
  463. initrd_high = ~0;
  464. }
  465. #ifdef CONFIG_LOGBUFFER
  466. /* Prevent initrd from overwriting logbuffer */
  467. if (initrd_high < (kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD))
  468. initrd_high = kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD;
  469. debug ("## Logbuffer at 0x%08lx ", kbd->bi_memsize - LOGBUFF_LEN);
  470. #endif
  471. debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
  472. initrd_high, initrd_copy_to_ram);
  473. if (rd_data) {
  474. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  475. debug (" in-place initrd\n");
  476. *initrd_start = rd_data;
  477. *initrd_end = rd_data + rd_len;
  478. } else {
  479. new_alloc_current = alloc_current - rd_len;
  480. *initrd_start = new_alloc_current;
  481. *initrd_start &= ~(4096 - 1); /* align on page */
  482. if (initrd_high) {
  483. ulong nsp;
  484. /*
  485. * the inital ramdisk does not need to be within
  486. * CFG_BOOTMAPSZ as it is not accessed until after
  487. * the mm system is initialised.
  488. *
  489. * do the stack bottom calculation again and see if
  490. * the initrd will fit just below the monitor stack
  491. * bottom without overwriting the area allocated
  492. * for command line args and board info.
  493. */
  494. nsp = sp;
  495. nsp -= 2048; /* just to be sure */
  496. nsp &= ~0xF;
  497. if (nsp > initrd_high) /* limit as specified */
  498. nsp = initrd_high;
  499. nsp -= rd_len;
  500. nsp &= ~(4096 - 1); /* align on page */
  501. if (nsp >= sp_limit) {
  502. *initrd_start = nsp;
  503. new_alloc_current = alloc_current;
  504. }
  505. }
  506. show_boot_progress (12);
  507. *initrd_end = *initrd_start + rd_len;
  508. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  509. *initrd_start, *initrd_end);
  510. memmove_wd((void *)*initrd_start,
  511. (void *)rd_data, rd_len, CHUNKSZ);
  512. puts ("OK\n");
  513. }
  514. } else {
  515. *initrd_start = 0;
  516. *initrd_end = 0;
  517. }
  518. debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
  519. *initrd_start, *initrd_end);
  520. return new_alloc_current;
  521. }
  522. /**
  523. * get_boot_sp_limit - calculate stack pointer limit
  524. * @sp: current stack pointer
  525. *
  526. * get_boot_sp_limit() takes current stack pointer adrress and calculates
  527. * stack pointer limit, below which kernel boot data (cmdline, board info,
  528. * etc.) will be allocated.
  529. *
  530. * returns:
  531. * stack pointer limit
  532. */
  533. ulong get_boot_sp_limit(ulong sp)
  534. {
  535. ulong sp_limit = sp;
  536. sp_limit -= 2048; /* just to be sure */
  537. /* make sure sp_limit is within kernel mapped space */
  538. if (sp_limit > CFG_BOOTMAPSZ)
  539. sp_limit = CFG_BOOTMAPSZ;
  540. sp_limit &= ~0xF;
  541. return sp_limit;
  542. }
  543. /**
  544. * get_boot_cmdline - allocate and initialize kernel cmdline
  545. * @alloc_current: current boot allocation address (counting down
  546. * from sp_limit)
  547. * @cmd_start: pointer to a ulong variable, will hold cmdline start
  548. * @cmd_end: pointer to a ulong variable, will hold cmdline end
  549. *
  550. * get_boot_cmdline() allocates space for kernel command line below
  551. * provided alloc_current address. If "bootargs" U-boot environemnt
  552. * variable is present its contents is copied to allocated kernel
  553. * command line.
  554. *
  555. * returns:
  556. * alloc_current after cmdline allocation
  557. */
  558. ulong get_boot_cmdline (ulong alloc_current, ulong *cmd_start, ulong *cmd_end)
  559. {
  560. char *cmdline;
  561. char *s;
  562. cmdline = (char *)((alloc_current - CFG_BARGSIZE) & ~0xF);
  563. if ((s = getenv("bootargs")) == NULL)
  564. s = "";
  565. strcpy(cmdline, s);
  566. *cmd_start = (ulong) & cmdline[0];
  567. *cmd_end = *cmd_start + strlen(cmdline);
  568. debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
  569. return (ulong)cmdline;
  570. }
  571. /**
  572. * get_boot_kbd - allocate and initialize kernel copy of board info
  573. * @alloc_current: current boot allocation address (counting down
  574. * from sp_limit)
  575. * @kbd: double pointer to board info data
  576. *
  577. * get_boot_kbd() - allocates space for kernel copy of board info data.
  578. * Space is allocated below provided alloc_current address and kernel
  579. * board info is initialized with the current u-boot board info data.
  580. *
  581. * returns:
  582. * alloc_current after kbd allocation
  583. */
  584. ulong get_boot_kbd (ulong alloc_current, bd_t **kbd)
  585. {
  586. *kbd = (bd_t *) (((ulong)alloc_current - sizeof(bd_t)) & ~0xF);
  587. **kbd = *(gd->bd);
  588. debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
  589. #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
  590. do_bdinfo(NULL, 0, 0, NULL);
  591. #endif
  592. return (ulong)*kbd;
  593. }
  594. #endif /* CONFIG_PPC || CONFIG_M68K */
  595. #endif /* USE_HOSTCC */