image.c 34 KB

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