image.c 33 KB

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