image.c 34 KB

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