image.c 34 KB

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