image.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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. #ifndef USE_HOSTCC
  26. #include <common.h>
  27. #include <watchdog.h>
  28. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  29. #include <status_led.h>
  30. #endif
  31. #ifdef CONFIG_HAS_DATAFLASH
  32. #include <dataflash.h>
  33. #endif
  34. #ifdef CONFIG_LOGBUFFER
  35. #include <logbuff.h>
  36. #endif
  37. #include <rtc.h>
  38. #include <environment.h>
  39. #include <image.h>
  40. #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
  41. #include <libfdt.h>
  42. #include <fdt_support.h>
  43. #endif
  44. #include <u-boot/md5.h>
  45. #include <sha1.h>
  46. #include <asm/io.h>
  47. #ifdef CONFIG_CMD_BDI
  48. extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  49. #endif
  50. DECLARE_GLOBAL_DATA_PTR;
  51. static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
  52. int verify);
  53. #else
  54. #include "mkimage.h"
  55. #include <u-boot/md5.h>
  56. #include <time.h>
  57. #include <image.h>
  58. #endif /* !USE_HOSTCC*/
  59. #include <u-boot/crc.h>
  60. #ifndef CONFIG_SYS_BARGSIZE
  61. #define CONFIG_SYS_BARGSIZE 512
  62. #endif
  63. static const table_entry_t uimage_arch[] = {
  64. { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
  65. { IH_ARCH_ALPHA, "alpha", "Alpha", },
  66. { IH_ARCH_ARM, "arm", "ARM", },
  67. { IH_ARCH_I386, "x86", "Intel x86", },
  68. { IH_ARCH_IA64, "ia64", "IA64", },
  69. { IH_ARCH_M68K, "m68k", "M68K", },
  70. { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", },
  71. { IH_ARCH_MIPS, "mips", "MIPS", },
  72. { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", },
  73. { IH_ARCH_NIOS2, "nios2", "NIOS II", },
  74. { IH_ARCH_PPC, "powerpc", "PowerPC", },
  75. { IH_ARCH_PPC, "ppc", "PowerPC", },
  76. { IH_ARCH_S390, "s390", "IBM S390", },
  77. { IH_ARCH_SH, "sh", "SuperH", },
  78. { IH_ARCH_SPARC, "sparc", "SPARC", },
  79. { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", },
  80. { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", },
  81. { IH_ARCH_AVR32, "avr32", "AVR32", },
  82. { IH_ARCH_NDS32, "nds32", "NDS32", },
  83. { IH_ARCH_OPENRISC, "or1k", "OpenRISC 1000",},
  84. { IH_ARCH_SANDBOX, "sandbox", "Sandbox", },
  85. { -1, "", "", },
  86. };
  87. static const table_entry_t uimage_os[] = {
  88. { IH_OS_INVALID, NULL, "Invalid OS", },
  89. { IH_OS_LINUX, "linux", "Linux", },
  90. #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
  91. { IH_OS_LYNXOS, "lynxos", "LynxOS", },
  92. #endif
  93. { IH_OS_NETBSD, "netbsd", "NetBSD", },
  94. { IH_OS_OSE, "ose", "Enea OSE", },
  95. { IH_OS_PLAN9, "plan9", "Plan 9", },
  96. { IH_OS_RTEMS, "rtems", "RTEMS", },
  97. { IH_OS_U_BOOT, "u-boot", "U-Boot", },
  98. #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
  99. { IH_OS_QNX, "qnx", "QNX", },
  100. { IH_OS_VXWORKS, "vxworks", "VxWorks", },
  101. #endif
  102. #if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC)
  103. { IH_OS_INTEGRITY,"integrity", "INTEGRITY", },
  104. #endif
  105. #ifdef USE_HOSTCC
  106. { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
  107. { IH_OS_DELL, "dell", "Dell", },
  108. { IH_OS_ESIX, "esix", "Esix", },
  109. { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
  110. { IH_OS_IRIX, "irix", "Irix", },
  111. { IH_OS_NCR, "ncr", "NCR", },
  112. { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
  113. { IH_OS_PSOS, "psos", "pSOS", },
  114. { IH_OS_SCO, "sco", "SCO", },
  115. { IH_OS_SOLARIS, "solaris", "Solaris", },
  116. { IH_OS_SVR4, "svr4", "SVR4", },
  117. #endif
  118. { -1, "", "", },
  119. };
  120. static const table_entry_t uimage_type[] = {
  121. { IH_TYPE_AISIMAGE, "aisimage", "Davinci AIS image",},
  122. { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
  123. { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
  124. { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
  125. { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
  126. { IH_TYPE_KERNEL_NOLOAD, "kernel_noload", "Kernel Image (no loading done)", },
  127. { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
  128. { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
  129. { IH_TYPE_INVALID, NULL, "Invalid Image", },
  130. { IH_TYPE_MULTI, "multi", "Multi-File Image", },
  131. { IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",},
  132. { IH_TYPE_PBLIMAGE, "pblimage", "Freescale PBL Boot Image",},
  133. { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
  134. { IH_TYPE_SCRIPT, "script", "Script", },
  135. { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
  136. { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",},
  137. { -1, "", "", },
  138. };
  139. static const table_entry_t uimage_comp[] = {
  140. { IH_COMP_NONE, "none", "uncompressed", },
  141. { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
  142. { IH_COMP_GZIP, "gzip", "gzip compressed", },
  143. { IH_COMP_LZMA, "lzma", "lzma compressed", },
  144. { IH_COMP_LZO, "lzo", "lzo compressed", },
  145. { -1, "", "", },
  146. };
  147. /*****************************************************************************/
  148. /* Legacy format routines */
  149. /*****************************************************************************/
  150. int image_check_hcrc(const image_header_t *hdr)
  151. {
  152. ulong hcrc;
  153. ulong len = image_get_header_size();
  154. image_header_t header;
  155. /* Copy header so we can blank CRC field for re-calculation */
  156. memmove(&header, (char *)hdr, image_get_header_size());
  157. image_set_hcrc(&header, 0);
  158. hcrc = crc32(0, (unsigned char *)&header, len);
  159. return (hcrc == image_get_hcrc(hdr));
  160. }
  161. int image_check_dcrc(const image_header_t *hdr)
  162. {
  163. ulong data = image_get_data(hdr);
  164. ulong len = image_get_data_size(hdr);
  165. ulong dcrc = crc32_wd(0, (unsigned char *)data, len, CHUNKSZ_CRC32);
  166. return (dcrc == image_get_dcrc(hdr));
  167. }
  168. /**
  169. * image_multi_count - get component (sub-image) count
  170. * @hdr: pointer to the header of the multi component image
  171. *
  172. * image_multi_count() returns number of components in a multi
  173. * component image.
  174. *
  175. * Note: no checking of the image type is done, caller must pass
  176. * a valid multi component image.
  177. *
  178. * returns:
  179. * number of components
  180. */
  181. ulong image_multi_count(const image_header_t *hdr)
  182. {
  183. ulong i, count = 0;
  184. uint32_t *size;
  185. /* get start of the image payload, which in case of multi
  186. * component images that points to a table of component sizes */
  187. size = (uint32_t *)image_get_data(hdr);
  188. /* count non empty slots */
  189. for (i = 0; size[i]; ++i)
  190. count++;
  191. return count;
  192. }
  193. /**
  194. * image_multi_getimg - get component data address and size
  195. * @hdr: pointer to the header of the multi component image
  196. * @idx: index of the requested component
  197. * @data: pointer to a ulong variable, will hold component data address
  198. * @len: pointer to a ulong variable, will hold component size
  199. *
  200. * image_multi_getimg() returns size and data address for the requested
  201. * component in a multi component image.
  202. *
  203. * Note: no checking of the image type is done, caller must pass
  204. * a valid multi component image.
  205. *
  206. * returns:
  207. * data address and size of the component, if idx is valid
  208. * 0 in data and len, if idx is out of range
  209. */
  210. void image_multi_getimg(const image_header_t *hdr, ulong idx,
  211. ulong *data, ulong *len)
  212. {
  213. int i;
  214. uint32_t *size;
  215. ulong offset, count, img_data;
  216. /* get number of component */
  217. count = image_multi_count(hdr);
  218. /* get start of the image payload, which in case of multi
  219. * component images that points to a table of component sizes */
  220. size = (uint32_t *)image_get_data(hdr);
  221. /* get address of the proper component data start, which means
  222. * skipping sizes table (add 1 for last, null entry) */
  223. img_data = image_get_data(hdr) + (count + 1) * sizeof(uint32_t);
  224. if (idx < count) {
  225. *len = uimage_to_cpu(size[idx]);
  226. offset = 0;
  227. /* go over all indices preceding requested component idx */
  228. for (i = 0; i < idx; i++) {
  229. /* add up i-th component size, rounding up to 4 bytes */
  230. offset += (uimage_to_cpu(size[i]) + 3) & ~3 ;
  231. }
  232. /* calculate idx-th component data address */
  233. *data = img_data + offset;
  234. } else {
  235. *len = 0;
  236. *data = 0;
  237. }
  238. }
  239. static void image_print_type(const image_header_t *hdr)
  240. {
  241. const char *os, *arch, *type, *comp;
  242. os = genimg_get_os_name(image_get_os(hdr));
  243. arch = genimg_get_arch_name(image_get_arch(hdr));
  244. type = genimg_get_type_name(image_get_type(hdr));
  245. comp = genimg_get_comp_name(image_get_comp(hdr));
  246. printf("%s %s %s (%s)\n", arch, os, type, comp);
  247. }
  248. /**
  249. * image_print_contents - prints out the contents of the legacy format image
  250. * @ptr: pointer to the legacy format image header
  251. * @p: pointer to prefix string
  252. *
  253. * image_print_contents() formats a multi line legacy image contents description.
  254. * The routine prints out all header fields followed by the size/offset data
  255. * for MULTI/SCRIPT images.
  256. *
  257. * returns:
  258. * no returned results
  259. */
  260. void image_print_contents(const void *ptr)
  261. {
  262. const image_header_t *hdr = (const image_header_t *)ptr;
  263. const char *p;
  264. p = IMAGE_INDENT_STRING;
  265. printf("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name(hdr));
  266. if (IMAGE_ENABLE_TIMESTAMP) {
  267. printf("%sCreated: ", p);
  268. genimg_print_time((time_t)image_get_time(hdr));
  269. }
  270. printf("%sImage Type: ", p);
  271. image_print_type(hdr);
  272. printf("%sData Size: ", p);
  273. genimg_print_size(image_get_data_size(hdr));
  274. printf("%sLoad Address: %08x\n", p, image_get_load(hdr));
  275. printf("%sEntry Point: %08x\n", p, image_get_ep(hdr));
  276. if (image_check_type(hdr, IH_TYPE_MULTI) ||
  277. image_check_type(hdr, IH_TYPE_SCRIPT)) {
  278. int i;
  279. ulong data, len;
  280. ulong count = image_multi_count(hdr);
  281. printf("%sContents:\n", p);
  282. for (i = 0; i < count; i++) {
  283. image_multi_getimg(hdr, i, &data, &len);
  284. printf("%s Image %d: ", p, i);
  285. genimg_print_size(len);
  286. if (image_check_type(hdr, IH_TYPE_SCRIPT) && i > 0) {
  287. /*
  288. * the user may need to know offsets
  289. * if planning to do something with
  290. * multiple files
  291. */
  292. printf("%s Offset = 0x%08lx\n", p, data);
  293. }
  294. }
  295. }
  296. }
  297. #ifndef USE_HOSTCC
  298. /**
  299. * image_get_ramdisk - get and verify ramdisk image
  300. * @rd_addr: ramdisk image start address
  301. * @arch: expected ramdisk architecture
  302. * @verify: checksum verification flag
  303. *
  304. * image_get_ramdisk() returns a pointer to the verified ramdisk image
  305. * header. Routine receives image start address and expected architecture
  306. * flag. Verification done covers data and header integrity and os/type/arch
  307. * fields checking.
  308. *
  309. * If dataflash support is enabled routine checks for dataflash addresses
  310. * and handles required dataflash reads.
  311. *
  312. * returns:
  313. * pointer to a ramdisk image header, if image was found and valid
  314. * otherwise, return NULL
  315. */
  316. static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
  317. int verify)
  318. {
  319. const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
  320. if (!image_check_magic(rd_hdr)) {
  321. puts("Bad Magic Number\n");
  322. bootstage_error(BOOTSTAGE_ID_RD_MAGIC);
  323. return NULL;
  324. }
  325. if (!image_check_hcrc(rd_hdr)) {
  326. puts("Bad Header Checksum\n");
  327. bootstage_error(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
  328. return NULL;
  329. }
  330. bootstage_mark(BOOTSTAGE_ID_RD_MAGIC);
  331. image_print_contents(rd_hdr);
  332. if (verify) {
  333. puts(" Verifying Checksum ... ");
  334. if (!image_check_dcrc(rd_hdr)) {
  335. puts("Bad Data CRC\n");
  336. bootstage_error(BOOTSTAGE_ID_RD_CHECKSUM);
  337. return NULL;
  338. }
  339. puts("OK\n");
  340. }
  341. bootstage_mark(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
  342. if (!image_check_os(rd_hdr, IH_OS_LINUX) ||
  343. !image_check_arch(rd_hdr, arch) ||
  344. !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) {
  345. printf("No Linux %s Ramdisk Image\n",
  346. genimg_get_arch_name(arch));
  347. bootstage_error(BOOTSTAGE_ID_RAMDISK);
  348. return NULL;
  349. }
  350. return rd_hdr;
  351. }
  352. #endif /* !USE_HOSTCC */
  353. /*****************************************************************************/
  354. /* Shared dual-format routines */
  355. /*****************************************************************************/
  356. #ifndef USE_HOSTCC
  357. ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
  358. ulong save_addr; /* Default Save Address */
  359. ulong save_size; /* Default Save Size (in bytes) */
  360. static int on_loadaddr(const char *name, const char *value, enum env_op op,
  361. int flags)
  362. {
  363. switch (op) {
  364. case env_op_create:
  365. case env_op_overwrite:
  366. load_addr = simple_strtoul(value, NULL, 16);
  367. break;
  368. default:
  369. break;
  370. }
  371. return 0;
  372. }
  373. U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr);
  374. ulong getenv_bootm_low(void)
  375. {
  376. char *s = getenv("bootm_low");
  377. if (s) {
  378. ulong tmp = simple_strtoul(s, NULL, 16);
  379. return tmp;
  380. }
  381. #if defined(CONFIG_SYS_SDRAM_BASE)
  382. return CONFIG_SYS_SDRAM_BASE;
  383. #elif defined(CONFIG_ARM)
  384. return gd->bd->bi_dram[0].start;
  385. #else
  386. return 0;
  387. #endif
  388. }
  389. phys_size_t getenv_bootm_size(void)
  390. {
  391. phys_size_t tmp;
  392. char *s = getenv("bootm_size");
  393. if (s) {
  394. tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
  395. return tmp;
  396. }
  397. s = getenv("bootm_low");
  398. if (s)
  399. tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
  400. else
  401. tmp = 0;
  402. #if defined(CONFIG_ARM)
  403. return gd->bd->bi_dram[0].size - tmp;
  404. #else
  405. return gd->bd->bi_memsize - tmp;
  406. #endif
  407. }
  408. phys_size_t getenv_bootm_mapsize(void)
  409. {
  410. phys_size_t tmp;
  411. char *s = getenv("bootm_mapsize");
  412. if (s) {
  413. tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
  414. return tmp;
  415. }
  416. #if defined(CONFIG_SYS_BOOTMAPSZ)
  417. return CONFIG_SYS_BOOTMAPSZ;
  418. #else
  419. return getenv_bootm_size();
  420. #endif
  421. }
  422. void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
  423. {
  424. if (to == from)
  425. return;
  426. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  427. while (len > 0) {
  428. size_t tail = (len > chunksz) ? chunksz : len;
  429. WATCHDOG_RESET();
  430. memmove(to, from, tail);
  431. to += tail;
  432. from += tail;
  433. len -= tail;
  434. }
  435. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  436. memmove(to, from, len);
  437. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  438. }
  439. #endif /* !USE_HOSTCC */
  440. void genimg_print_size(uint32_t size)
  441. {
  442. #ifndef USE_HOSTCC
  443. printf("%d Bytes = ", size);
  444. print_size(size, "\n");
  445. #else
  446. printf("%d Bytes = %.2f kB = %.2f MB\n",
  447. size, (double)size / 1.024e3,
  448. (double)size / 1.048576e6);
  449. #endif
  450. }
  451. #if IMAGE_ENABLE_TIMESTAMP
  452. void genimg_print_time(time_t timestamp)
  453. {
  454. #ifndef USE_HOSTCC
  455. struct rtc_time tm;
  456. to_tm(timestamp, &tm);
  457. printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
  458. tm.tm_year, tm.tm_mon, tm.tm_mday,
  459. tm.tm_hour, tm.tm_min, tm.tm_sec);
  460. #else
  461. printf("%s", ctime(&timestamp));
  462. #endif
  463. }
  464. #endif
  465. /**
  466. * get_table_entry_name - translate entry id to long name
  467. * @table: pointer to a translation table for entries of a specific type
  468. * @msg: message to be returned when translation fails
  469. * @id: entry id to be translated
  470. *
  471. * get_table_entry_name() will go over translation table trying to find
  472. * entry that matches given id. If matching entry is found, its long
  473. * name is returned to the caller.
  474. *
  475. * returns:
  476. * long entry name if translation succeeds
  477. * msg otherwise
  478. */
  479. char *get_table_entry_name(const table_entry_t *table, char *msg, int id)
  480. {
  481. for (; table->id >= 0; ++table) {
  482. if (table->id == id)
  483. #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
  484. return table->lname;
  485. #else
  486. return table->lname + gd->reloc_off;
  487. #endif
  488. }
  489. return (msg);
  490. }
  491. const char *genimg_get_os_name(uint8_t os)
  492. {
  493. return (get_table_entry_name(uimage_os, "Unknown OS", os));
  494. }
  495. const char *genimg_get_arch_name(uint8_t arch)
  496. {
  497. return (get_table_entry_name(uimage_arch, "Unknown Architecture",
  498. arch));
  499. }
  500. const char *genimg_get_type_name(uint8_t type)
  501. {
  502. return (get_table_entry_name(uimage_type, "Unknown Image", type));
  503. }
  504. const char *genimg_get_comp_name(uint8_t comp)
  505. {
  506. return (get_table_entry_name(uimage_comp, "Unknown Compression",
  507. comp));
  508. }
  509. /**
  510. * get_table_entry_id - translate short entry name to id
  511. * @table: pointer to a translation table for entries of a specific type
  512. * @table_name: to be used in case of error
  513. * @name: entry short name to be translated
  514. *
  515. * get_table_entry_id() will go over translation table trying to find
  516. * entry that matches given short name. If matching entry is found,
  517. * its id returned to the caller.
  518. *
  519. * returns:
  520. * entry id if translation succeeds
  521. * -1 otherwise
  522. */
  523. int get_table_entry_id(const table_entry_t *table,
  524. const char *table_name, const char *name)
  525. {
  526. const table_entry_t *t;
  527. #ifdef USE_HOSTCC
  528. int first = 1;
  529. for (t = table; t->id >= 0; ++t) {
  530. if (t->sname && strcasecmp(t->sname, name) == 0)
  531. return(t->id);
  532. }
  533. fprintf(stderr, "\nInvalid %s Type - valid names are", table_name);
  534. for (t = table; t->id >= 0; ++t) {
  535. if (t->sname == NULL)
  536. continue;
  537. fprintf(stderr, "%c %s", (first) ? ':' : ',', t->sname);
  538. first = 0;
  539. }
  540. fprintf(stderr, "\n");
  541. #else
  542. for (t = table; t->id >= 0; ++t) {
  543. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  544. if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
  545. #else
  546. if (t->sname && strcmp(t->sname, name) == 0)
  547. #endif
  548. return (t->id);
  549. }
  550. debug("Invalid %s Type: %s\n", table_name, name);
  551. #endif /* USE_HOSTCC */
  552. return (-1);
  553. }
  554. int genimg_get_os_id(const char *name)
  555. {
  556. return (get_table_entry_id(uimage_os, "OS", name));
  557. }
  558. int genimg_get_arch_id(const char *name)
  559. {
  560. return (get_table_entry_id(uimage_arch, "CPU", name));
  561. }
  562. int genimg_get_type_id(const char *name)
  563. {
  564. return (get_table_entry_id(uimage_type, "Image", name));
  565. }
  566. int genimg_get_comp_id(const char *name)
  567. {
  568. return (get_table_entry_id(uimage_comp, "Compression", name));
  569. }
  570. #ifndef USE_HOSTCC
  571. /**
  572. * genimg_get_format - get image format type
  573. * @img_addr: image start address
  574. *
  575. * genimg_get_format() checks whether provided address points to a valid
  576. * legacy or FIT image.
  577. *
  578. * New uImage format and FDT blob are based on a libfdt. FDT blob
  579. * may be passed directly or embedded in a FIT image. In both situations
  580. * genimg_get_format() must be able to dectect libfdt header.
  581. *
  582. * returns:
  583. * image format type or IMAGE_FORMAT_INVALID if no image is present
  584. */
  585. int genimg_get_format(const void *img_addr)
  586. {
  587. ulong format = IMAGE_FORMAT_INVALID;
  588. const image_header_t *hdr;
  589. #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
  590. char *fit_hdr;
  591. #endif
  592. hdr = (const image_header_t *)img_addr;
  593. if (image_check_magic(hdr))
  594. format = IMAGE_FORMAT_LEGACY;
  595. #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
  596. else {
  597. fit_hdr = (char *)img_addr;
  598. if (fdt_check_header(fit_hdr) == 0)
  599. format = IMAGE_FORMAT_FIT;
  600. }
  601. #endif
  602. return format;
  603. }
  604. /**
  605. * genimg_get_image - get image from special storage (if necessary)
  606. * @img_addr: image start address
  607. *
  608. * genimg_get_image() checks if provided image start adddress is located
  609. * in a dataflash storage. If so, image is moved to a system RAM memory.
  610. *
  611. * returns:
  612. * image start address after possible relocation from special storage
  613. */
  614. ulong genimg_get_image(ulong img_addr)
  615. {
  616. ulong ram_addr = img_addr;
  617. #ifdef CONFIG_HAS_DATAFLASH
  618. ulong h_size, d_size;
  619. if (addr_dataflash(img_addr)) {
  620. void *buf;
  621. /* ger RAM address */
  622. ram_addr = CONFIG_SYS_LOAD_ADDR;
  623. /* get header size */
  624. h_size = image_get_header_size();
  625. #if defined(CONFIG_FIT)
  626. if (sizeof(struct fdt_header) > h_size)
  627. h_size = sizeof(struct fdt_header);
  628. #endif
  629. /* read in header */
  630. debug(" Reading image header from dataflash address "
  631. "%08lx to RAM address %08lx\n", img_addr, ram_addr);
  632. buf = map_sysmem(ram_addr, 0);
  633. read_dataflash(img_addr, h_size, buf);
  634. /* get data size */
  635. switch (genimg_get_format(buf)) {
  636. case IMAGE_FORMAT_LEGACY:
  637. d_size = image_get_data_size(buf);
  638. debug(" Legacy format image found at 0x%08lx, "
  639. "size 0x%08lx\n",
  640. ram_addr, d_size);
  641. break;
  642. #if defined(CONFIG_FIT)
  643. case IMAGE_FORMAT_FIT:
  644. d_size = fit_get_size(buf) - h_size;
  645. debug(" FIT/FDT format image found at 0x%08lx, "
  646. "size 0x%08lx\n",
  647. ram_addr, d_size);
  648. break;
  649. #endif
  650. default:
  651. printf(" No valid image found at 0x%08lx\n",
  652. img_addr);
  653. return ram_addr;
  654. }
  655. /* read in image data */
  656. debug(" Reading image remaining data from dataflash address "
  657. "%08lx to RAM address %08lx\n", img_addr + h_size,
  658. ram_addr + h_size);
  659. read_dataflash(img_addr + h_size, d_size,
  660. (char *)(buf + h_size));
  661. }
  662. #endif /* CONFIG_HAS_DATAFLASH */
  663. return ram_addr;
  664. }
  665. /**
  666. * fit_has_config - check if there is a valid FIT configuration
  667. * @images: pointer to the bootm command headers structure
  668. *
  669. * fit_has_config() checks if there is a FIT configuration in use
  670. * (if FTI support is present).
  671. *
  672. * returns:
  673. * 0, no FIT support or no configuration found
  674. * 1, configuration found
  675. */
  676. int genimg_has_config(bootm_headers_t *images)
  677. {
  678. #if defined(CONFIG_FIT)
  679. if (images->fit_uname_cfg)
  680. return 1;
  681. #endif
  682. return 0;
  683. }
  684. /**
  685. * boot_get_ramdisk - main ramdisk handling routine
  686. * @argc: command argument count
  687. * @argv: command argument list
  688. * @images: pointer to the bootm images structure
  689. * @arch: expected ramdisk architecture
  690. * @rd_start: pointer to a ulong variable, will hold ramdisk start address
  691. * @rd_end: pointer to a ulong variable, will hold ramdisk end
  692. *
  693. * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
  694. * Curently supported are the following ramdisk sources:
  695. * - multicomponent kernel/ramdisk image,
  696. * - commandline provided address of decicated ramdisk image.
  697. *
  698. * returns:
  699. * 0, if ramdisk image was found and valid, or skiped
  700. * rd_start and rd_end are set to ramdisk start/end addresses if
  701. * ramdisk image is found and valid
  702. *
  703. * 1, if ramdisk image is found but corrupted, or invalid
  704. * rd_start and rd_end are set to 0 if no ramdisk exists
  705. */
  706. int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
  707. uint8_t arch, ulong *rd_start, ulong *rd_end)
  708. {
  709. ulong rd_addr, rd_load;
  710. ulong rd_data, rd_len;
  711. const image_header_t *rd_hdr;
  712. void *buf;
  713. #ifdef CONFIG_SUPPORT_RAW_INITRD
  714. char *end;
  715. #endif
  716. #if defined(CONFIG_FIT)
  717. void *fit_hdr;
  718. const char *fit_uname_config = NULL;
  719. const char *fit_uname_ramdisk = NULL;
  720. ulong default_addr;
  721. int rd_noffset;
  722. int cfg_noffset;
  723. const void *data;
  724. size_t size;
  725. #endif
  726. *rd_start = 0;
  727. *rd_end = 0;
  728. /*
  729. * Look for a '-' which indicates to ignore the
  730. * ramdisk argument
  731. */
  732. if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
  733. debug("## Skipping init Ramdisk\n");
  734. rd_len = rd_data = 0;
  735. } else if (argc >= 3 || genimg_has_config(images)) {
  736. #if defined(CONFIG_FIT)
  737. if (argc >= 3) {
  738. /*
  739. * If the init ramdisk comes from the FIT image and
  740. * the FIT image address is omitted in the command
  741. * line argument, try to use os FIT image address or
  742. * default load address.
  743. */
  744. if (images->fit_uname_os)
  745. default_addr = (ulong)images->fit_hdr_os;
  746. else
  747. default_addr = load_addr;
  748. if (fit_parse_conf(argv[2], default_addr,
  749. &rd_addr, &fit_uname_config)) {
  750. debug("* ramdisk: config '%s' from image at "
  751. "0x%08lx\n",
  752. fit_uname_config, rd_addr);
  753. } else if (fit_parse_subimage(argv[2], default_addr,
  754. &rd_addr, &fit_uname_ramdisk)) {
  755. debug("* ramdisk: subimage '%s' from image at "
  756. "0x%08lx\n",
  757. fit_uname_ramdisk, rd_addr);
  758. } else
  759. #endif
  760. {
  761. rd_addr = simple_strtoul(argv[2], NULL, 16);
  762. debug("* ramdisk: cmdline image address = "
  763. "0x%08lx\n",
  764. rd_addr);
  765. }
  766. #if defined(CONFIG_FIT)
  767. } else {
  768. /* use FIT configuration provided in first bootm
  769. * command argument
  770. */
  771. rd_addr = map_to_sysmem(images->fit_hdr_os);
  772. fit_uname_config = images->fit_uname_cfg;
  773. debug("* ramdisk: using config '%s' from image "
  774. "at 0x%08lx\n",
  775. fit_uname_config, rd_addr);
  776. /*
  777. * Check whether configuration has ramdisk defined,
  778. * if not, don't try to use it, quit silently.
  779. */
  780. fit_hdr = images->fit_hdr_os;
  781. cfg_noffset = fit_conf_get_node(fit_hdr,
  782. fit_uname_config);
  783. if (cfg_noffset < 0) {
  784. debug("* ramdisk: no such config\n");
  785. return 1;
  786. }
  787. rd_noffset = fit_conf_get_ramdisk_node(fit_hdr,
  788. cfg_noffset);
  789. if (rd_noffset < 0) {
  790. debug("* ramdisk: no ramdisk in config\n");
  791. return 0;
  792. }
  793. }
  794. #endif
  795. /* copy from dataflash if needed */
  796. rd_addr = genimg_get_image(rd_addr);
  797. /*
  798. * Check if there is an initrd image at the
  799. * address provided in the second bootm argument
  800. * check image type, for FIT images get FIT node.
  801. */
  802. buf = map_sysmem(rd_addr, 0);
  803. switch (genimg_get_format(buf)) {
  804. case IMAGE_FORMAT_LEGACY:
  805. printf("## Loading init Ramdisk from Legacy "
  806. "Image at %08lx ...\n", rd_addr);
  807. bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK);
  808. rd_hdr = image_get_ramdisk(rd_addr, arch,
  809. images->verify);
  810. if (rd_hdr == NULL)
  811. return 1;
  812. rd_data = image_get_data(rd_hdr);
  813. rd_len = image_get_data_size(rd_hdr);
  814. rd_load = image_get_load(rd_hdr);
  815. break;
  816. #if defined(CONFIG_FIT)
  817. case IMAGE_FORMAT_FIT:
  818. fit_hdr = buf;
  819. printf("## Loading init Ramdisk from FIT "
  820. "Image at %08lx ...\n", rd_addr);
  821. bootstage_mark(BOOTSTAGE_ID_FIT_RD_FORMAT);
  822. if (!fit_check_format(fit_hdr)) {
  823. puts("Bad FIT ramdisk image format!\n");
  824. bootstage_error(
  825. BOOTSTAGE_ID_FIT_RD_FORMAT);
  826. return 1;
  827. }
  828. bootstage_mark(BOOTSTAGE_ID_FIT_RD_FORMAT_OK);
  829. if (!fit_uname_ramdisk) {
  830. /*
  831. * no ramdisk image node unit name, try to get config
  832. * node first. If config unit node name is NULL
  833. * fit_conf_get_node() will try to find default config node
  834. */
  835. bootstage_mark(
  836. BOOTSTAGE_ID_FIT_RD_NO_UNIT_NAME);
  837. cfg_noffset = fit_conf_get_node(fit_hdr,
  838. fit_uname_config);
  839. if (cfg_noffset < 0) {
  840. puts("Could not find configuration "
  841. "node\n");
  842. bootstage_error(
  843. BOOTSTAGE_ID_FIT_RD_NO_UNIT_NAME);
  844. return 1;
  845. }
  846. fit_uname_config = fdt_get_name(fit_hdr,
  847. cfg_noffset, NULL);
  848. printf(" Using '%s' configuration\n",
  849. fit_uname_config);
  850. rd_noffset = fit_conf_get_ramdisk_node(fit_hdr,
  851. cfg_noffset);
  852. fit_uname_ramdisk = fit_get_name(fit_hdr,
  853. rd_noffset, NULL);
  854. } else {
  855. /* get ramdisk component image node offset */
  856. bootstage_mark(
  857. BOOTSTAGE_ID_FIT_RD_UNIT_NAME);
  858. rd_noffset = fit_image_get_node(fit_hdr,
  859. fit_uname_ramdisk);
  860. }
  861. if (rd_noffset < 0) {
  862. puts("Could not find subimage node\n");
  863. bootstage_error(BOOTSTAGE_ID_FIT_RD_SUBNODE);
  864. return 1;
  865. }
  866. printf(" Trying '%s' ramdisk subimage\n",
  867. fit_uname_ramdisk);
  868. bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK);
  869. if (!fit_check_ramdisk(fit_hdr, rd_noffset, arch,
  870. images->verify))
  871. return 1;
  872. /* get ramdisk image data address and length */
  873. if (fit_image_get_data(fit_hdr, rd_noffset, &data,
  874. &size)) {
  875. puts("Could not find ramdisk subimage data!\n");
  876. bootstage_error(BOOTSTAGE_ID_FIT_RD_GET_DATA);
  877. return 1;
  878. }
  879. bootstage_mark(BOOTSTAGE_ID_FIT_RD_GET_DATA_OK);
  880. rd_data = (ulong)data;
  881. rd_len = size;
  882. if (fit_image_get_load(fit_hdr, rd_noffset, &rd_load)) {
  883. puts("Can't get ramdisk subimage load "
  884. "address!\n");
  885. bootstage_error(BOOTSTAGE_ID_FIT_RD_LOAD);
  886. return 1;
  887. }
  888. bootstage_mark(BOOTSTAGE_ID_FIT_RD_LOAD);
  889. images->fit_hdr_rd = fit_hdr;
  890. images->fit_uname_rd = fit_uname_ramdisk;
  891. images->fit_noffset_rd = rd_noffset;
  892. break;
  893. #endif
  894. default:
  895. #ifdef CONFIG_SUPPORT_RAW_INITRD
  896. if (argc >= 3 && (end = strchr(argv[2], ':'))) {
  897. rd_len = simple_strtoul(++end, NULL, 16);
  898. rd_data = rd_addr;
  899. } else
  900. #endif
  901. {
  902. puts("Wrong Ramdisk Image Format\n");
  903. rd_data = rd_len = rd_load = 0;
  904. return 1;
  905. }
  906. }
  907. } else if (images->legacy_hdr_valid &&
  908. image_check_type(&images->legacy_hdr_os_copy,
  909. IH_TYPE_MULTI)) {
  910. /*
  911. * Now check if we have a legacy mult-component image,
  912. * get second entry data start address and len.
  913. */
  914. bootstage_mark(BOOTSTAGE_ID_RAMDISK);
  915. printf("## Loading init Ramdisk from multi component "
  916. "Legacy Image at %08lx ...\n",
  917. (ulong)images->legacy_hdr_os);
  918. image_multi_getimg(images->legacy_hdr_os, 1, &rd_data, &rd_len);
  919. } else {
  920. /*
  921. * no initrd image
  922. */
  923. bootstage_mark(BOOTSTAGE_ID_NO_RAMDISK);
  924. rd_len = rd_data = 0;
  925. }
  926. if (!rd_data) {
  927. debug("## No init Ramdisk\n");
  928. } else {
  929. *rd_start = rd_data;
  930. *rd_end = rd_data + rd_len;
  931. }
  932. debug(" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
  933. *rd_start, *rd_end);
  934. return 0;
  935. }
  936. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  937. /**
  938. * boot_ramdisk_high - relocate init ramdisk
  939. * @lmb: pointer to lmb handle, will be used for memory mgmt
  940. * @rd_data: ramdisk data start address
  941. * @rd_len: ramdisk data length
  942. * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
  943. * start address (after possible relocation)
  944. * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
  945. * end address (after possible relocation)
  946. *
  947. * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
  948. * variable and if requested ramdisk data is moved to a specified location.
  949. *
  950. * Initrd_start and initrd_end are set to final (after relocation) ramdisk
  951. * start/end addresses if ramdisk image start and len were provided,
  952. * otherwise set initrd_start and initrd_end set to zeros.
  953. *
  954. * returns:
  955. * 0 - success
  956. * -1 - failure
  957. */
  958. int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
  959. ulong *initrd_start, ulong *initrd_end)
  960. {
  961. char *s;
  962. ulong initrd_high;
  963. int initrd_copy_to_ram = 1;
  964. if ((s = getenv("initrd_high")) != NULL) {
  965. /* a value of "no" or a similar string will act like 0,
  966. * turning the "load high" feature off. This is intentional.
  967. */
  968. initrd_high = simple_strtoul(s, NULL, 16);
  969. if (initrd_high == ~0)
  970. initrd_copy_to_ram = 0;
  971. } else {
  972. /* not set, no restrictions to load high */
  973. initrd_high = ~0;
  974. }
  975. #ifdef CONFIG_LOGBUFFER
  976. /* Prevent initrd from overwriting logbuffer */
  977. lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
  978. #endif
  979. debug("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
  980. initrd_high, initrd_copy_to_ram);
  981. if (rd_data) {
  982. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  983. debug(" in-place initrd\n");
  984. *initrd_start = rd_data;
  985. *initrd_end = rd_data + rd_len;
  986. lmb_reserve(lmb, rd_data, rd_len);
  987. } else {
  988. if (initrd_high)
  989. *initrd_start = (ulong)lmb_alloc_base(lmb,
  990. rd_len, 0x1000, initrd_high);
  991. else
  992. *initrd_start = (ulong)lmb_alloc(lmb, rd_len,
  993. 0x1000);
  994. if (*initrd_start == 0) {
  995. puts("ramdisk - allocation error\n");
  996. goto error;
  997. }
  998. bootstage_mark(BOOTSTAGE_ID_COPY_RAMDISK);
  999. *initrd_end = *initrd_start + rd_len;
  1000. printf(" Loading Ramdisk to %08lx, end %08lx ... ",
  1001. *initrd_start, *initrd_end);
  1002. memmove_wd((void *)*initrd_start,
  1003. (void *)rd_data, rd_len, CHUNKSZ);
  1004. #ifdef CONFIG_MP
  1005. /*
  1006. * Ensure the image is flushed to memory to handle
  1007. * AMP boot scenarios in which we might not be
  1008. * HW cache coherent
  1009. */
  1010. flush_cache((unsigned long)*initrd_start, rd_len);
  1011. #endif
  1012. puts("OK\n");
  1013. }
  1014. } else {
  1015. *initrd_start = 0;
  1016. *initrd_end = 0;
  1017. }
  1018. debug(" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
  1019. *initrd_start, *initrd_end);
  1020. return 0;
  1021. error:
  1022. return -1;
  1023. }
  1024. #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
  1025. #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
  1026. /**
  1027. * boot_get_cmdline - allocate and initialize kernel cmdline
  1028. * @lmb: pointer to lmb handle, will be used for memory mgmt
  1029. * @cmd_start: pointer to a ulong variable, will hold cmdline start
  1030. * @cmd_end: pointer to a ulong variable, will hold cmdline end
  1031. *
  1032. * boot_get_cmdline() allocates space for kernel command line below
  1033. * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt
  1034. * variable is present its contents is copied to allocated kernel
  1035. * command line.
  1036. *
  1037. * returns:
  1038. * 0 - success
  1039. * -1 - failure
  1040. */
  1041. int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
  1042. {
  1043. char *cmdline;
  1044. char *s;
  1045. cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
  1046. getenv_bootm_mapsize() + getenv_bootm_low());
  1047. if (cmdline == NULL)
  1048. return -1;
  1049. if ((s = getenv("bootargs")) == NULL)
  1050. s = "";
  1051. strcpy(cmdline, s);
  1052. *cmd_start = (ulong) & cmdline[0];
  1053. *cmd_end = *cmd_start + strlen(cmdline);
  1054. debug("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
  1055. return 0;
  1056. }
  1057. #endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
  1058. #ifdef CONFIG_SYS_BOOT_GET_KBD
  1059. /**
  1060. * boot_get_kbd - allocate and initialize kernel copy of board info
  1061. * @lmb: pointer to lmb handle, will be used for memory mgmt
  1062. * @kbd: double pointer to board info data
  1063. *
  1064. * boot_get_kbd() allocates space for kernel copy of board info data below
  1065. * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized
  1066. * with the current u-boot board info data.
  1067. *
  1068. * returns:
  1069. * 0 - success
  1070. * -1 - failure
  1071. */
  1072. int boot_get_kbd(struct lmb *lmb, bd_t **kbd)
  1073. {
  1074. *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
  1075. getenv_bootm_mapsize() + getenv_bootm_low());
  1076. if (*kbd == NULL)
  1077. return -1;
  1078. **kbd = *(gd->bd);
  1079. debug("## kernel board info at 0x%08lx\n", (ulong)*kbd);
  1080. #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
  1081. do_bdinfo(NULL, 0, 0, NULL);
  1082. #endif
  1083. return 0;
  1084. }
  1085. #endif /* CONFIG_SYS_BOOT_GET_KBD */
  1086. #ifdef CONFIG_LMB
  1087. int image_setup_linux(bootm_headers_t *images)
  1088. {
  1089. ulong of_size = images->ft_len;
  1090. char **of_flat_tree = &images->ft_addr;
  1091. ulong *initrd_start = &images->initrd_start;
  1092. ulong *initrd_end = &images->initrd_end;
  1093. struct lmb *lmb = &images->lmb;
  1094. ulong rd_len;
  1095. int ret;
  1096. if (IMAGE_ENABLE_OF_LIBFDT)
  1097. boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
  1098. if (IMAGE_BOOT_GET_CMDLINE) {
  1099. ret = boot_get_cmdline(lmb, &images->cmdline_start,
  1100. &images->cmdline_end);
  1101. if (ret) {
  1102. puts("ERROR with allocation of cmdline\n");
  1103. return ret;
  1104. }
  1105. }
  1106. if (IMAGE_ENABLE_RAMDISK_HIGH) {
  1107. rd_len = images->rd_end - images->rd_start;
  1108. ret = boot_ramdisk_high(lmb, images->rd_start, rd_len,
  1109. initrd_start, initrd_end);
  1110. if (ret)
  1111. return ret;
  1112. }
  1113. if (IMAGE_ENABLE_OF_LIBFDT) {
  1114. ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
  1115. if (ret)
  1116. return ret;
  1117. }
  1118. if (IMAGE_ENABLE_OF_LIBFDT && of_size) {
  1119. ret = image_setup_libfdt(images, *of_flat_tree, of_size, lmb);
  1120. if (ret)
  1121. return ret;
  1122. }
  1123. return 0;
  1124. }
  1125. #endif /* CONFIG_LMB */
  1126. #endif /* !USE_HOSTCC */