image.c 34 KB

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