image.c 34 KB

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