image.c 31.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * (C) Copyright 2008 Semihalf
 *
 * (C) Copyright 2000-2006
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */
25

26
#ifndef USE_HOSTCC
27 28 29 30 31 32 33 34 35 36 37
#include <common.h>
#include <watchdog.h>

#ifdef CONFIG_SHOW_BOOT_PROGRESS
#include <status_led.h>
#endif

#ifdef CONFIG_HAS_DATAFLASH
#include <dataflash.h>
#endif

38 39 40 41
#ifdef CONFIG_LOGBUFFER
#include <logbuff.h>
#endif

42 43
#include <rtc.h>

J
Joe Hershberger 已提交
44
#include <environment.h>
45 46
#include <image.h>

S
Stephen Warren 已提交
47
#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
48 49
#include <libfdt.h>
#include <fdt_support.h>
50 51
#endif

52
#include <u-boot/md5.h>
53
#include <sha1.h>
54
#include <asm/errno.h>
55
#include <asm/io.h>
56

57
#ifdef CONFIG_CMD_BDI
58
extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
59 60 61
#endif

DECLARE_GLOBAL_DATA_PTR;
62

S
Stephen Warren 已提交
63
static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
64
						int verify);
65
#else
66
#include "mkimage.h"
67
#include <u-boot/md5.h>
68
#include <time.h>
69
#include <image.h>
70
#endif /* !USE_HOSTCC*/
71

72 73
#include <u-boot/crc.h>

74 75 76 77
#ifndef CONFIG_SYS_BARGSIZE
#define CONFIG_SYS_BARGSIZE 512
#endif

M
Mike Frysinger 已提交
78
static const table_entry_t uimage_arch[] = {
79 80 81 82 83 84 85 86 87 88
	{	IH_ARCH_INVALID,	NULL,		"Invalid ARCH",	},
	{	IH_ARCH_ALPHA,		"alpha",	"Alpha",	},
	{	IH_ARCH_ARM,		"arm",		"ARM",		},
	{	IH_ARCH_I386,		"x86",		"Intel x86",	},
	{	IH_ARCH_IA64,		"ia64",		"IA64",		},
	{	IH_ARCH_M68K,		"m68k",		"M68K",		},
	{	IH_ARCH_MICROBLAZE,	"microblaze",	"MicroBlaze",	},
	{	IH_ARCH_MIPS,		"mips",		"MIPS",		},
	{	IH_ARCH_MIPS64,		"mips64",	"MIPS 64 Bit",	},
	{	IH_ARCH_NIOS2,		"nios2",	"NIOS II",	},
89
	{	IH_ARCH_PPC,		"powerpc",	"PowerPC",	},
90 91 92 93 94 95 96
	{	IH_ARCH_PPC,		"ppc",		"PowerPC",	},
	{	IH_ARCH_S390,		"s390",		"IBM S390",	},
	{	IH_ARCH_SH,		"sh",		"SuperH",	},
	{	IH_ARCH_SPARC,		"sparc",	"SPARC",	},
	{	IH_ARCH_SPARC64,	"sparc64",	"SPARC 64 Bit",	},
	{	IH_ARCH_BLACKFIN,	"blackfin",	"Blackfin",	},
	{	IH_ARCH_AVR32,		"avr32",	"AVR32",	},
97
	{	IH_ARCH_NDS32,		"nds32",	"NDS32",	},
98
	{	IH_ARCH_OPENRISC,	"or1k",		"OpenRISC 1000",},
99
	{	IH_ARCH_SANDBOX,	"sandbox",	"Sandbox",	},
100 101 102
	{	-1,			"",		"",		},
};

M
Mike Frysinger 已提交
103
static const table_entry_t uimage_os[] = {
104 105 106 107 108 109
	{	IH_OS_INVALID,	NULL,		"Invalid OS",		},
	{	IH_OS_LINUX,	"linux",	"Linux",		},
#if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
	{	IH_OS_LYNXOS,	"lynxos",	"LynxOS",		},
#endif
	{	IH_OS_NETBSD,	"netbsd",	"NetBSD",		},
110
	{	IH_OS_OSE,	"ose",		"Enea OSE",		},
S
Steven Stallion 已提交
111
	{	IH_OS_PLAN9,	"plan9",	"Plan 9",		},
112 113 114 115 116 117
	{	IH_OS_RTEMS,	"rtems",	"RTEMS",		},
	{	IH_OS_U_BOOT,	"u-boot",	"U-Boot",		},
#if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
	{	IH_OS_QNX,	"qnx",		"QNX",			},
	{	IH_OS_VXWORKS,	"vxworks",	"VxWorks",		},
#endif
118 119 120
#if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC)
	{	IH_OS_INTEGRITY,"integrity",	"INTEGRITY",		},
#endif
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
#ifdef USE_HOSTCC
	{	IH_OS_4_4BSD,	"4_4bsd",	"4_4BSD",		},
	{	IH_OS_DELL,	"dell",		"Dell",			},
	{	IH_OS_ESIX,	"esix",		"Esix",			},
	{	IH_OS_FREEBSD,	"freebsd",	"FreeBSD",		},
	{	IH_OS_IRIX,	"irix",		"Irix",			},
	{	IH_OS_NCR,	"ncr",		"NCR",			},
	{	IH_OS_OPENBSD,	"openbsd",	"OpenBSD",		},
	{	IH_OS_PSOS,	"psos",		"pSOS",			},
	{	IH_OS_SCO,	"sco",		"SCO",			},
	{	IH_OS_SOLARIS,	"solaris",	"Solaris",		},
	{	IH_OS_SVR4,	"svr4",		"SVR4",			},
#endif
	{	-1,		"",		"",			},
};

M
Mike Frysinger 已提交
137
static const table_entry_t uimage_type[] = {
138
	{	IH_TYPE_AISIMAGE,   "aisimage",   "Davinci AIS image",},
139 140
	{	IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image",	},
	{	IH_TYPE_FIRMWARE,   "firmware",	  "Firmware",		},
141
	{	IH_TYPE_FLATDT,     "flat_dt",    "Flat Device Tree",	},
142
	{	IH_TYPE_KERNEL,	    "kernel",	  "Kernel Image",	},
143
	{	IH_TYPE_KERNEL_NOLOAD, "kernel_noload",  "Kernel Image (no loading done)", },
144 145 146
	{	IH_TYPE_KWBIMAGE,   "kwbimage",   "Kirkwood Boot Image",},
	{	IH_TYPE_IMXIMAGE,   "imximage",   "Freescale i.MX Boot Image",},
	{	IH_TYPE_INVALID,    NULL,	  "Invalid Image",	},
147
	{	IH_TYPE_MULTI,	    "multi",	  "Multi-File Image",	},
148
	{	IH_TYPE_OMAPIMAGE,  "omapimage",  "TI OMAP SPL With GP CH",},
149
	{	IH_TYPE_PBLIMAGE,   "pblimage",   "Freescale PBL Boot Image",},
150 151 152
	{	IH_TYPE_RAMDISK,    "ramdisk",	  "RAMDisk Image",	},
	{	IH_TYPE_SCRIPT,     "script",	  "Script",		},
	{	IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
153
	{	IH_TYPE_UBLIMAGE,   "ublimage",   "Davinci UBL image",},
154 155 156
	{	-1,		    "",		  "",			},
};

M
Mike Frysinger 已提交
157
static const table_entry_t uimage_comp[] = {
158 159 160
	{	IH_COMP_NONE,	"none",		"uncompressed",		},
	{	IH_COMP_BZIP2,	"bzip2",	"bzip2 compressed",	},
	{	IH_COMP_GZIP,	"gzip",		"gzip compressed",	},
161
	{	IH_COMP_LZMA,	"lzma",		"lzma compressed",	},
P
Peter Korsgaard 已提交
162
	{	IH_COMP_LZO,	"lzo",		"lzo compressed",	},
163 164 165
	{	-1,		"",		"",			},
};

166 167 168
/*****************************************************************************/
/* Legacy format routines */
/*****************************************************************************/
S
Stephen Warren 已提交
169
int image_check_hcrc(const image_header_t *hdr)
170 171
{
	ulong hcrc;
S
Stephen Warren 已提交
172
	ulong len = image_get_header_size();
173 174 175
	image_header_t header;

	/* Copy header so we can blank CRC field for re-calculation */
S
Stephen Warren 已提交
176 177
	memmove(&header, (char *)hdr, image_get_header_size());
	image_set_hcrc(&header, 0);
178

S
Stephen Warren 已提交
179
	hcrc = crc32(0, (unsigned char *)&header, len);
180

S
Stephen Warren 已提交
181
	return (hcrc == image_get_hcrc(hdr));
182 183
}

S
Stephen Warren 已提交
184
int image_check_dcrc(const image_header_t *hdr)
185
{
S
Stephen Warren 已提交
186 187 188
	ulong data = image_get_data(hdr);
	ulong len = image_get_data_size(hdr);
	ulong dcrc = crc32_wd(0, (unsigned char *)data, len, CHUNKSZ_CRC32);
189

S
Stephen Warren 已提交
190
	return (dcrc == image_get_dcrc(hdr));
191 192
}

193 194 195 196 197 198 199 200 201 202 203 204 205
/**
 * image_multi_count - get component (sub-image) count
 * @hdr: pointer to the header of the multi component image
 *
 * image_multi_count() returns number of components in a multi
 * component image.
 *
 * Note: no checking of the image type is done, caller must pass
 * a valid multi component image.
 *
 * returns:
 *     number of components
 */
S
Stephen Warren 已提交
206
ulong image_multi_count(const image_header_t *hdr)
207 208
{
	ulong i, count = 0;
209
	uint32_t *size;
210 211 212

	/* get start of the image payload, which in case of multi
	 * component images that points to a table of component sizes */
S
Stephen Warren 已提交
213
	size = (uint32_t *)image_get_data(hdr);
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238

	/* count non empty slots */
	for (i = 0; size[i]; ++i)
		count++;

	return count;
}

/**
 * image_multi_getimg - get component data address and size
 * @hdr: pointer to the header of the multi component image
 * @idx: index of the requested component
 * @data: pointer to a ulong variable, will hold component data address
 * @len: pointer to a ulong variable, will hold component size
 *
 * image_multi_getimg() returns size and data address for the requested
 * component in a multi component image.
 *
 * Note: no checking of the image type is done, caller must pass
 * a valid multi component image.
 *
 * returns:
 *     data address and size of the component, if idx is valid
 *     0 in data and len, if idx is out of range
 */
S
Stephen Warren 已提交
239
void image_multi_getimg(const image_header_t *hdr, ulong idx,
240 241 242
			ulong *data, ulong *len)
{
	int i;
243
	uint32_t *size;
244
	ulong offset, count, img_data;
245 246

	/* get number of component */
S
Stephen Warren 已提交
247
	count = image_multi_count(hdr);
248 249 250

	/* get start of the image payload, which in case of multi
	 * component images that points to a table of component sizes */
S
Stephen Warren 已提交
251
	size = (uint32_t *)image_get_data(hdr);
252 253 254

	/* get address of the proper component data start, which means
	 * skipping sizes table (add 1 for last, null entry) */
S
Stephen Warren 已提交
255
	img_data = image_get_data(hdr) + (count + 1) * sizeof(uint32_t);
256 257

	if (idx < count) {
S
Stephen Warren 已提交
258
		*len = uimage_to_cpu(size[idx]);
259 260 261 262
		offset = 0;

		/* go over all indices preceding requested component idx */
		for (i = 0; i < idx; i++) {
263
			/* add up i-th component size, rounding up to 4 bytes */
S
Stephen Warren 已提交
264
			offset += (uimage_to_cpu(size[i]) + 3) & ~3 ;
265 266 267
		}

		/* calculate idx-th component data address */
268
		*data = img_data + offset;
269 270 271 272 273
	} else {
		*len = 0;
		*data = 0;
	}
}
274

S
Stephen Warren 已提交
275
static void image_print_type(const image_header_t *hdr)
276 277 278
{
	const char *os, *arch, *type, *comp;

S
Stephen Warren 已提交
279 280 281 282
	os = genimg_get_os_name(image_get_os(hdr));
	arch = genimg_get_arch_name(image_get_arch(hdr));
	type = genimg_get_type_name(image_get_type(hdr));
	comp = genimg_get_comp_name(image_get_comp(hdr));
283

S
Stephen Warren 已提交
284
	printf("%s %s %s (%s)\n", arch, os, type, comp);
285 286
}

287
/**
288
 * image_print_contents - prints out the contents of the legacy format image
289
 * @ptr: pointer to the legacy format image header
290 291
 * @p: pointer to prefix string
 *
292
 * image_print_contents() formats a multi line legacy image contents description.
293 294 295 296 297 298
 * The routine prints out all header fields followed by the size/offset data
 * for MULTI/SCRIPT images.
 *
 * returns:
 *     no returned results
 */
S
Stephen Warren 已提交
299
void image_print_contents(const void *ptr)
300
{
301
	const image_header_t *hdr = (const image_header_t *)ptr;
302 303
	const char *p;

304
	p = IMAGE_INDENT_STRING;
S
Stephen Warren 已提交
305
	printf("%sImage Name:   %.*s\n", p, IH_NMLEN, image_get_name(hdr));
306 307 308 309
	if (IMAGE_ENABLE_TIMESTAMP) {
		printf("%sCreated:      ", p);
		genimg_print_time((time_t)image_get_time(hdr));
	}
S
Stephen Warren 已提交
310 311 312 313 314 315 316 317 318
	printf("%sImage Type:   ", p);
	image_print_type(hdr);
	printf("%sData Size:    ", p);
	genimg_print_size(image_get_data_size(hdr));
	printf("%sLoad Address: %08x\n", p, image_get_load(hdr));
	printf("%sEntry Point:  %08x\n", p, image_get_ep(hdr));

	if (image_check_type(hdr, IH_TYPE_MULTI) ||
			image_check_type(hdr, IH_TYPE_SCRIPT)) {
319 320
		int i;
		ulong data, len;
S
Stephen Warren 已提交
321
		ulong count = image_multi_count(hdr);
322

S
Stephen Warren 已提交
323
		printf("%sContents:\n", p);
324
		for (i = 0; i < count; i++) {
S
Stephen Warren 已提交
325
			image_multi_getimg(hdr, i, &data, &len);
326

S
Stephen Warren 已提交
327 328
			printf("%s   Image %d: ", p, i);
			genimg_print_size(len);
329

S
Stephen Warren 已提交
330
			if (image_check_type(hdr, IH_TYPE_SCRIPT) && i > 0) {
331 332 333 334 335
				/*
				 * the user may need to know offsets
				 * if planning to do something with
				 * multiple files
				 */
S
Stephen Warren 已提交
336
				printf("%s    Offset = 0x%08lx\n", p, data);
337
			}
338 339 340 341
		}
	}
}

342 343

#ifndef USE_HOSTCC
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
/**
 * image_get_ramdisk - get and verify ramdisk image
 * @rd_addr: ramdisk image start address
 * @arch: expected ramdisk architecture
 * @verify: checksum verification flag
 *
 * image_get_ramdisk() returns a pointer to the verified ramdisk image
 * header. Routine receives image start address and expected architecture
 * flag. Verification done covers data and header integrity and os/type/arch
 * fields checking.
 *
 * If dataflash support is enabled routine checks for dataflash addresses
 * and handles required dataflash reads.
 *
 * returns:
 *     pointer to a ramdisk image header, if image was found and valid
 *     otherwise, return NULL
 */
S
Stephen Warren 已提交
362
static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
363
						int verify)
364
{
365
	const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
366

S
Stephen Warren 已提交
367 368
	if (!image_check_magic(rd_hdr)) {
		puts("Bad Magic Number\n");
369
		bootstage_error(BOOTSTAGE_ID_RD_MAGIC);
370 371 372
		return NULL;
	}

S
Stephen Warren 已提交
373 374
	if (!image_check_hcrc(rd_hdr)) {
		puts("Bad Header Checksum\n");
375
		bootstage_error(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
376 377 378
		return NULL;
	}

379
	bootstage_mark(BOOTSTAGE_ID_RD_MAGIC);
S
Stephen Warren 已提交
380
	image_print_contents(rd_hdr);
381 382 383

	if (verify) {
		puts("   Verifying Checksum ... ");
S
Stephen Warren 已提交
384 385
		if (!image_check_dcrc(rd_hdr)) {
			puts("Bad Data CRC\n");
386
			bootstage_error(BOOTSTAGE_ID_RD_CHECKSUM);
387 388 389 390 391
			return NULL;
		}
		puts("OK\n");
	}

392
	bootstage_mark(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
393

S
Stephen Warren 已提交
394 395 396 397
	if (!image_check_os(rd_hdr, IH_OS_LINUX) ||
	    !image_check_arch(rd_hdr, arch) ||
	    !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) {
		printf("No Linux %s Ramdisk Image\n",
398
				genimg_get_arch_name(arch));
399
		bootstage_error(BOOTSTAGE_ID_RAMDISK);
400 401 402 403 404
		return NULL;
	}

	return rd_hdr;
}
405
#endif /* !USE_HOSTCC */
406 407 408 409

/*****************************************************************************/
/* Shared dual-format routines */
/*****************************************************************************/
410
#ifndef USE_HOSTCC
J
Joe Hershberger 已提交
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
ulong load_addr = CONFIG_SYS_LOAD_ADDR;	/* Default Load Address */
ulong save_addr;			/* Default Save Address */
ulong save_size;			/* Default Save Size (in bytes) */

static int on_loadaddr(const char *name, const char *value, enum env_op op,
	int flags)
{
	switch (op) {
	case env_op_create:
	case env_op_overwrite:
		load_addr = simple_strtoul(value, NULL, 16);
		break;
	default:
		break;
	}

	return 0;
}
U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr);

431 432
ulong getenv_bootm_low(void)
{
S
Stephen Warren 已提交
433
	char *s = getenv("bootm_low");
434
	if (s) {
S
Stephen Warren 已提交
435
		ulong tmp = simple_strtoul(s, NULL, 16);
436 437 438
		return tmp;
	}

439 440
#if defined(CONFIG_SYS_SDRAM_BASE)
	return CONFIG_SYS_SDRAM_BASE;
441 442
#elif defined(CONFIG_ARM)
	return gd->bd->bi_dram[0].start;
443 444 445 446 447
#else
	return 0;
#endif
}

448
phys_size_t getenv_bootm_size(void)
449
{
450
	phys_size_t tmp;
S
Stephen Warren 已提交
451
	char *s = getenv("bootm_size");
452
	if (s) {
S
Stephen Warren 已提交
453
		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
454 455
		return tmp;
	}
456 457
	s = getenv("bootm_low");
	if (s)
S
Stephen Warren 已提交
458
		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
459 460 461
	else
		tmp = 0;

462

463
#if defined(CONFIG_ARM)
464
	return gd->bd->bi_dram[0].size - tmp;
465
#else
466
	return gd->bd->bi_memsize - tmp;
467
#endif
468 469
}

470 471 472
phys_size_t getenv_bootm_mapsize(void)
{
	phys_size_t tmp;
S
Stephen Warren 已提交
473
	char *s = getenv("bootm_mapsize");
474
	if (s) {
S
Stephen Warren 已提交
475
		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
476 477 478 479 480 481 482 483 484 485
		return tmp;
	}

#if defined(CONFIG_SYS_BOOTMAPSZ)
	return CONFIG_SYS_BOOTMAPSZ;
#else
	return getenv_bootm_size();
#endif
}

S
Stephen Warren 已提交
486
void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
487
{
488 489 490
	if (to == from)
		return;

491 492 493
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
	while (len > 0) {
		size_t tail = (len > chunksz) ? chunksz : len;
S
Stephen Warren 已提交
494 495
		WATCHDOG_RESET();
		memmove(to, from, tail);
496 497 498 499 500
		to += tail;
		from += tail;
		len -= tail;
	}
#else	/* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
S
Stephen Warren 已提交
501
	memmove(to, from, len);
502 503
#endif	/* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
}
504
#endif /* !USE_HOSTCC */
505

S
Stephen Warren 已提交
506
void genimg_print_size(uint32_t size)
507
{
508
#ifndef USE_HOSTCC
S
Stephen Warren 已提交
509 510
	printf("%d Bytes = ", size);
	print_size(size, "\n");
511
#else
S
Stephen Warren 已提交
512
	printf("%d Bytes = %.2f kB = %.2f MB\n",
513 514
			size, (double)size / 1.024e3,
			(double)size / 1.048576e6);
515
#endif
516 517
}

518 519
#if IMAGE_ENABLE_TIMESTAMP
void genimg_print_time(time_t timestamp)
520 521 522 523
{
#ifndef USE_HOSTCC
	struct rtc_time tm;

S
Stephen Warren 已提交
524 525
	to_tm(timestamp, &tm);
	printf("%4d-%02d-%02d  %2d:%02d:%02d UTC\n",
526 527 528
			tm.tm_year, tm.tm_mon, tm.tm_mday,
			tm.tm_hour, tm.tm_min, tm.tm_sec);
#else
S
Stephen Warren 已提交
529
	printf("%s", ctime(&timestamp));
530
#endif
531
}
532
#endif
533

534 535 536 537 538 539 540 541 542 543 544 545 546 547
/**
 * get_table_entry_name - translate entry id to long name
 * @table: pointer to a translation table for entries of a specific type
 * @msg: message to be returned when translation fails
 * @id: entry id to be translated
 *
 * get_table_entry_name() will go over translation table trying to find
 * entry that matches given id. If matching entry is found, its long
 * name is returned to the caller.
 *
 * returns:
 *     long entry name if translation succeeds
 *     msg otherwise
 */
M
Mike Frysinger 已提交
548
char *get_table_entry_name(const table_entry_t *table, char *msg, int id)
549 550 551
{
	for (; table->id >= 0; ++table) {
		if (table->id == id)
552
#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
553 554 555 556
			return table->lname;
#else
			return table->lname + gd->reloc_off;
#endif
557
	}
558 559
	return (msg);
}
560

S
Stephen Warren 已提交
561
const char *genimg_get_os_name(uint8_t os)
562
{
S
Stephen Warren 已提交
563
	return (get_table_entry_name(uimage_os, "Unknown OS", os));
564 565
}

S
Stephen Warren 已提交
566
const char *genimg_get_arch_name(uint8_t arch)
567
{
S
Stephen Warren 已提交
568 569
	return (get_table_entry_name(uimage_arch, "Unknown Architecture",
					arch));
570
}
571

S
Stephen Warren 已提交
572
const char *genimg_get_type_name(uint8_t type)
573
{
S
Stephen Warren 已提交
574
	return (get_table_entry_name(uimage_type, "Unknown Image", type));
575
}
576

S
Stephen Warren 已提交
577
const char *genimg_get_comp_name(uint8_t comp)
578
{
S
Stephen Warren 已提交
579 580
	return (get_table_entry_name(uimage_comp, "Unknown Compression",
					comp));
581 582
}

583 584 585 586 587 588 589 590 591 592 593 594 595 596
/**
 * get_table_entry_id - translate short entry name to id
 * @table: pointer to a translation table for entries of a specific type
 * @table_name: to be used in case of error
 * @name: entry short name to be translated
 *
 * get_table_entry_id() will go over translation table trying to find
 * entry that matches given short name. If matching entry is found,
 * its id returned to the caller.
 *
 * returns:
 *     entry id if translation succeeds
 *     -1 otherwise
 */
M
Mike Frysinger 已提交
597
int get_table_entry_id(const table_entry_t *table,
598
		const char *table_name, const char *name)
599
{
M
Mike Frysinger 已提交
600
	const table_entry_t *t;
601 602
#ifdef USE_HOSTCC
	int first = 1;
603

604 605
	for (t = table; t->id >= 0; ++t) {
		if (t->sname && strcasecmp(t->sname, name) == 0)
S
Stephen Warren 已提交
606
			return(t->id);
607 608
	}

S
Stephen Warren 已提交
609
	fprintf(stderr, "\nInvalid %s Type - valid names are", table_name);
610 611 612
	for (t = table; t->id >= 0; ++t) {
		if (t->sname == NULL)
			continue;
S
Stephen Warren 已提交
613
		fprintf(stderr, "%c %s", (first) ? ':' : ',', t->sname);
614 615
		first = 0;
	}
S
Stephen Warren 已提交
616
	fprintf(stderr, "\n");
617 618
#else
	for (t = table; t->id >= 0; ++t) {
619
#ifdef CONFIG_NEEDS_MANUAL_RELOC
620
		if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
621 622
#else
		if (t->sname && strcmp(t->sname, name) == 0)
623
#endif
624 625
			return (t->id);
	}
S
Stephen Warren 已提交
626
	debug("Invalid %s Type: %s\n", table_name, name);
627 628 629 630
#endif /* USE_HOSTCC */
	return (-1);
}

S
Stephen Warren 已提交
631
int genimg_get_os_id(const char *name)
632
{
S
Stephen Warren 已提交
633
	return (get_table_entry_id(uimage_os, "OS", name));
634 635
}

S
Stephen Warren 已提交
636
int genimg_get_arch_id(const char *name)
637
{
S
Stephen Warren 已提交
638
	return (get_table_entry_id(uimage_arch, "CPU", name));
639
}
640

S
Stephen Warren 已提交
641
int genimg_get_type_id(const char *name)
642
{
S
Stephen Warren 已提交
643
	return (get_table_entry_id(uimage_type, "Image", name));
644 645
}

S
Stephen Warren 已提交
646
int genimg_get_comp_id(const char *name)
647
{
S
Stephen Warren 已提交
648
	return (get_table_entry_id(uimage_comp, "Compression", name));
649 650 651
}

#ifndef USE_HOSTCC
652
/**
653
 * genimg_get_format - get image format type
654 655
 * @img_addr: image start address
 *
656
 * genimg_get_format() checks whether provided address points to a valid
657 658
 * legacy or FIT image.
 *
659 660
 * New uImage format and FDT blob are based on a libfdt. FDT blob
 * may be passed directly or embedded in a FIT image. In both situations
661
 * genimg_get_format() must be able to dectect libfdt header.
662
 *
663 664 665
 * returns:
 *     image format type or IMAGE_FORMAT_INVALID if no image is present
 */
666
int genimg_get_format(const void *img_addr)
667
{
668 669
	ulong format = IMAGE_FORMAT_INVALID;
	const image_header_t *hdr;
670
#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
671
	char *fit_hdr;
672 673
#endif

674
	hdr = (const image_header_t *)img_addr;
675 676
	if (image_check_magic(hdr))
		format = IMAGE_FORMAT_LEGACY;
677
#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
678 679
	else {
		fit_hdr = (char *)img_addr;
S
Stephen Warren 已提交
680
		if (fdt_check_header(fit_hdr) == 0)
681 682 683 684 685 686 687 688
			format = IMAGE_FORMAT_FIT;
	}
#endif

	return format;
}

/**
689
 * genimg_get_image - get image from special storage (if necessary)
690 691
 * @img_addr: image start address
 *
692
 * genimg_get_image() checks if provided image start adddress is located
693 694 695 696 697
 * in a dataflash storage. If so, image is moved to a system RAM memory.
 *
 * returns:
 *     image start address after possible relocation from special storage
 */
S
Stephen Warren 已提交
698
ulong genimg_get_image(ulong img_addr)
699
{
700
	ulong ram_addr = img_addr;
701 702

#ifdef CONFIG_HAS_DATAFLASH
703 704
	ulong h_size, d_size;

S
Stephen Warren 已提交
705
	if (addr_dataflash(img_addr)) {
706 707
		void *buf;

708
		/* ger RAM address */
709
		ram_addr = CONFIG_SYS_LOAD_ADDR;
710 711

		/* get header size */
S
Stephen Warren 已提交
712
		h_size = image_get_header_size();
713 714 715 716 717 718
#if defined(CONFIG_FIT)
		if (sizeof(struct fdt_header) > h_size)
			h_size = sizeof(struct fdt_header);
#endif

		/* read in header */
S
Stephen Warren 已提交
719
		debug("   Reading image header from dataflash address "
720 721
			"%08lx to RAM address %08lx\n", img_addr, ram_addr);

722 723
		buf = map_sysmem(ram_addr, 0);
		read_dataflash(img_addr, h_size, buf);
724

725
		/* get data size */
726
		switch (genimg_get_format(buf)) {
727
		case IMAGE_FORMAT_LEGACY:
728
			d_size = image_get_data_size(buf);
S
Stephen Warren 已提交
729 730
			debug("   Legacy format image found at 0x%08lx, "
					"size 0x%08lx\n",
731 732
					ram_addr, d_size);
			break;
733
#if defined(CONFIG_FIT)
734
		case IMAGE_FORMAT_FIT:
735
			d_size = fit_get_size(buf) - h_size;
S
Stephen Warren 已提交
736 737
			debug("   FIT/FDT format image found at 0x%08lx, "
					"size 0x%08lx\n",
738 739
					ram_addr, d_size);
			break;
740
#endif
741
		default:
S
Stephen Warren 已提交
742 743
			printf("   No valid image found at 0x%08lx\n",
				img_addr);
744 745
			return ram_addr;
		}
746

747
		/* read in image data */
S
Stephen Warren 已提交
748
		debug("   Reading image remaining data from dataflash address "
749 750 751
			"%08lx to RAM address %08lx\n", img_addr + h_size,
			ram_addr + h_size);

S
Stephen Warren 已提交
752
		read_dataflash(img_addr + h_size, d_size,
753
				(char *)(buf + h_size));
754

755
	}
756
#endif /* CONFIG_HAS_DATAFLASH */
757 758 759 760

	return ram_addr;
}

761 762 763 764 765 766 767 768 769 770 771
/**
 * fit_has_config - check if there is a valid FIT configuration
 * @images: pointer to the bootm command headers structure
 *
 * fit_has_config() checks if there is a FIT configuration in use
 * (if FTI support is present).
 *
 * returns:
 *     0, no FIT support or no configuration found
 *     1, configuration found
 */
S
Stephen Warren 已提交
772
int genimg_has_config(bootm_headers_t *images)
773 774 775 776 777 778 779 780
{
#if defined(CONFIG_FIT)
	if (images->fit_uname_cfg)
		return 1;
#endif
	return 0;
}

781
/**
782
 * boot_get_ramdisk - main ramdisk handling routine
783 784
 * @argc: command argument count
 * @argv: command argument list
785
 * @images: pointer to the bootm images structure
786 787 788 789
 * @arch: expected ramdisk architecture
 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
 * @rd_end: pointer to a ulong variable, will hold ramdisk end
 *
790
 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
791 792 793 794 795
 * Curently supported are the following ramdisk sources:
 *      - multicomponent kernel/ramdisk image,
 *      - commandline provided address of decicated ramdisk image.
 *
 * returns:
796
 *     0, if ramdisk image was found and valid, or skiped
797 798
 *     rd_start and rd_end are set to ramdisk start/end addresses if
 *     ramdisk image is found and valid
799
 *
800
 *     1, if ramdisk image is found but corrupted, or invalid
801 802
 *     rd_start and rd_end are set to 0 if no ramdisk exists
 */
S
Stephen Warren 已提交
803
int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
804
		uint8_t arch, ulong *rd_start, ulong *rd_end)
805
{
806
	ulong rd_addr, rd_load;
807
	ulong rd_data, rd_len;
808
	const image_header_t *rd_hdr;
809
	void *buf;
810
#ifdef CONFIG_SUPPORT_RAW_INITRD
811
	char *end;
812
#endif
813 814 815 816
#if defined(CONFIG_FIT)
	const char	*fit_uname_config = NULL;
	const char	*fit_uname_ramdisk = NULL;
	ulong		default_addr;
817
	int		rd_noffset;
818
#endif
S
Simon Glass 已提交
819
	const char *select = NULL;
820

821 822 823
	*rd_start = 0;
	*rd_end = 0;

S
Simon Glass 已提交
824 825
	if (argc >= 2)
		select = argv[1];
826 827 828 829
	/*
	 * Look for a '-' which indicates to ignore the
	 * ramdisk argument
	 */
S
Simon Glass 已提交
830
	if (select && strcmp(select, "-") ==  0) {
S
Stephen Warren 已提交
831
		debug("## Skipping init Ramdisk\n");
832
		rd_len = rd_data = 0;
S
Simon Glass 已提交
833
	} else if (select || genimg_has_config(images)) {
834
#if defined(CONFIG_FIT)
S
Simon Glass 已提交
835
		if (select) {
836 837 838 839 840 841 842 843 844 845 846
			/*
			 * If the init ramdisk comes from the FIT image and
			 * the FIT image address is omitted in the command
			 * line argument, try to use os FIT image address or
			 * default load address.
			 */
			if (images->fit_uname_os)
				default_addr = (ulong)images->fit_hdr_os;
			else
				default_addr = load_addr;

S
Simon Glass 已提交
847 848
			if (fit_parse_conf(select, default_addr,
					   &rd_addr, &fit_uname_config)) {
S
Stephen Warren 已提交
849 850
				debug("*  ramdisk: config '%s' from image at "
						"0x%08lx\n",
851
						fit_uname_config, rd_addr);
S
Simon Glass 已提交
852
			} else if (fit_parse_subimage(select, default_addr,
853
						&rd_addr, &fit_uname_ramdisk)) {
S
Stephen Warren 已提交
854 855
				debug("*  ramdisk: subimage '%s' from image at "
						"0x%08lx\n",
856 857
						fit_uname_ramdisk, rd_addr);
			} else
858
#endif
859
			{
S
Simon Glass 已提交
860
				rd_addr = simple_strtoul(select, NULL, 16);
S
Stephen Warren 已提交
861 862
				debug("*  ramdisk: cmdline image address = "
						"0x%08lx\n",
863 864 865 866 867
						rd_addr);
			}
#if defined(CONFIG_FIT)
		} else {
			/* use FIT configuration provided in first bootm
868 869
			 * command argument. If the property is not defined,
			 * quit silently.
870
			 */
871
			rd_addr = map_to_sysmem(images->fit_hdr_os);
872 873 874
			rd_noffset = fit_get_node_from_config(images,
					FIT_RAMDISK_PROP, rd_addr);
			if (rd_noffset == -ENOLINK)
875
				return 0;
876 877
			else if (rd_noffset < 0)
				return 1;
878
		}
879
#endif
880 881

		/* copy from dataflash if needed */
S
Stephen Warren 已提交
882
		rd_addr = genimg_get_image(rd_addr);
883 884 885 886 887 888

		/*
		 * Check if there is an initrd image at the
		 * address provided in the second bootm argument
		 * check image type, for FIT images get FIT node.
		 */
889 890
		buf = map_sysmem(rd_addr, 0);
		switch (genimg_get_format(buf)) {
891
		case IMAGE_FORMAT_LEGACY:
S
Stephen Warren 已提交
892
			printf("## Loading init Ramdisk from Legacy "
893
					"Image at %08lx ...\n", rd_addr);
894

895
			bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK);
S
Stephen Warren 已提交
896
			rd_hdr = image_get_ramdisk(rd_addr, arch,
897
							images->verify);
898

899
			if (rd_hdr == NULL)
900 901
				return 1;

S
Stephen Warren 已提交
902 903 904
			rd_data = image_get_data(rd_hdr);
			rd_len = image_get_data_size(rd_hdr);
			rd_load = image_get_load(rd_hdr);
905 906 907
			break;
#if defined(CONFIG_FIT)
		case IMAGE_FORMAT_FIT:
908 909 910 911 912 913 914
			rd_noffset = fit_image_load(images, FIT_RAMDISK_PROP,
					rd_addr, &fit_uname_ramdisk,
					fit_uname_config, arch,
					IH_TYPE_RAMDISK,
					BOOTSTAGE_ID_FIT_RD_START,
					FIT_LOAD_REQUIRED, &rd_data, &rd_len);
			if (rd_noffset < 0)
915
				return 1;
916

917
			images->fit_hdr_rd = map_sysmem(rd_addr, 0);
918
			images->fit_uname_rd = fit_uname_ramdisk;
919
			images->fit_noffset_rd = rd_noffset;
920
			break;
921 922
#endif
		default:
923
#ifdef CONFIG_SUPPORT_RAW_INITRD
S
Simon Glass 已提交
924 925 926 927
			end = NULL;
			if (select)
				end = strchr(select, ':');
			if (end) {
928 929 930 931 932 933 934 935 936
				rd_len = simple_strtoul(++end, NULL, 16);
				rd_data = rd_addr;
			} else
#endif
			{
				puts("Wrong Ramdisk Image Format\n");
				rd_data = rd_len = rd_load = 0;
				return 1;
			}
937 938
		}
	} else if (images->legacy_hdr_valid &&
S
Stephen Warren 已提交
939 940 941
			image_check_type(&images->legacy_hdr_os_copy,
						IH_TYPE_MULTI)) {

942
		/*
943 944
		 * Now check if we have a legacy mult-component image,
		 * get second entry data start address and len.
945
		 */
946
		bootstage_mark(BOOTSTAGE_ID_RAMDISK);
S
Stephen Warren 已提交
947
		printf("## Loading init Ramdisk from multi component "
948
				"Legacy Image at %08lx ...\n",
949 950
				(ulong)images->legacy_hdr_os);

S
Stephen Warren 已提交
951
		image_multi_getimg(images->legacy_hdr_os, 1, &rd_data, &rd_len);
952 953 954 955
	} else {
		/*
		 * no initrd image
		 */
956
		bootstage_mark(BOOTSTAGE_ID_NO_RAMDISK);
957 958 959 960
		rd_len = rd_data = 0;
	}

	if (!rd_data) {
S
Stephen Warren 已提交
961
		debug("## No init Ramdisk\n");
962 963 964 965
	} else {
		*rd_start = rd_data;
		*rd_end = rd_data + rd_len;
	}
S
Stephen Warren 已提交
966
	debug("   ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
967
			*rd_start, *rd_end);
968 969

	return 0;
970
}
971

972
#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
973
/**
974
 * boot_ramdisk_high - relocate init ramdisk
975
 * @lmb: pointer to lmb handle, will be used for memory mgmt
976 977 978 979 980 981 982
 * @rd_data: ramdisk data start address
 * @rd_len: ramdisk data length
 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
 *      start address (after possible relocation)
 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
 *      end address (after possible relocation)
 *
983
 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
984 985
 * variable and if requested ramdisk data is moved to a specified location.
 *
986 987 988 989
 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
 * start/end addresses if ramdisk image start and len were provided,
 * otherwise set initrd_start and initrd_end set to zeros.
 *
990
 * returns:
991 992
 *      0 - success
 *     -1 - failure
993
 */
S
Stephen Warren 已提交
994
int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
995
		  ulong *initrd_start, ulong *initrd_end)
996 997 998 999 1000
{
	char	*s;
	ulong	initrd_high;
	int	initrd_copy_to_ram = 1;

S
Stephen Warren 已提交
1001
	if ((s = getenv("initrd_high")) != NULL) {
1002 1003 1004
		/* a value of "no" or a similar string will act like 0,
		 * turning the "load high" feature off. This is intentional.
		 */
S
Stephen Warren 已提交
1005
		initrd_high = simple_strtoul(s, NULL, 16);
1006 1007 1008 1009 1010 1011 1012
		if (initrd_high == ~0)
			initrd_copy_to_ram = 0;
	} else {
		/* not set, no restrictions to load high */
		initrd_high = ~0;
	}

1013 1014 1015 1016 1017 1018

#ifdef CONFIG_LOGBUFFER
	/* Prevent initrd from overwriting logbuffer */
	lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
#endif

S
Stephen Warren 已提交
1019
	debug("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1020 1021 1022 1023
			initrd_high, initrd_copy_to_ram);

	if (rd_data) {
		if (!initrd_copy_to_ram) {	/* zero-copy ramdisk support */
S
Stephen Warren 已提交
1024
			debug("   in-place initrd\n");
1025 1026
			*initrd_start = rd_data;
			*initrd_end = rd_data + rd_len;
1027
			lmb_reserve(lmb, rd_data, rd_len);
1028
		} else {
1029
			if (initrd_high)
S
Stephen Warren 已提交
1030 1031
				*initrd_start = (ulong)lmb_alloc_base(lmb,
						rd_len, 0x1000, initrd_high);
1032
			else
S
Stephen Warren 已提交
1033 1034
				*initrd_start = (ulong)lmb_alloc(lmb, rd_len,
								 0x1000);
1035 1036

			if (*initrd_start == 0) {
S
Stephen Warren 已提交
1037
				puts("ramdisk - allocation error\n");
1038
				goto error;
1039
			}
1040
			bootstage_mark(BOOTSTAGE_ID_COPY_RAMDISK);
1041 1042

			*initrd_end = *initrd_start + rd_len;
S
Stephen Warren 已提交
1043
			printf("   Loading Ramdisk to %08lx, end %08lx ... ",
1044 1045
					*initrd_start, *initrd_end);

S
Stephen Warren 已提交
1046
			memmove_wd((void *)*initrd_start,
1047 1048
					(void *)rd_data, rd_len, CHUNKSZ);

1049 1050 1051 1052 1053 1054 1055 1056
#ifdef CONFIG_MP
			/*
			 * Ensure the image is flushed to memory to handle
			 * AMP boot scenarios in which we might not be
			 * HW cache coherent
			 */
			flush_cache((unsigned long)*initrd_start, rd_len);
#endif
S
Stephen Warren 已提交
1057
			puts("OK\n");
1058 1059 1060 1061 1062
		}
	} else {
		*initrd_start = 0;
		*initrd_end = 0;
	}
S
Stephen Warren 已提交
1063
	debug("   ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1064
			*initrd_start, *initrd_end);
1065

1066
	return 0;
1067

1068 1069
error:
	return -1;
1070
}
1071
#endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
1072

1073
#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
1074
/**
1075
 * boot_get_cmdline - allocate and initialize kernel cmdline
1076
 * @lmb: pointer to lmb handle, will be used for memory mgmt
1077 1078 1079
 * @cmd_start: pointer to a ulong variable, will hold cmdline start
 * @cmd_end: pointer to a ulong variable, will hold cmdline end
 *
1080
 * boot_get_cmdline() allocates space for kernel command line below
1081
 * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt
1082 1083 1084 1085
 * variable is present its contents is copied to allocated kernel
 * command line.
 *
 * returns:
1086 1087
 *      0 - success
 *     -1 - failure
1088
 */
S
Stephen Warren 已提交
1089
int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
1090 1091 1092 1093
{
	char *cmdline;
	char *s;

1094
	cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
1095
				getenv_bootm_mapsize() + getenv_bootm_low());
1096 1097 1098

	if (cmdline == NULL)
		return -1;
1099 1100 1101 1102 1103 1104 1105 1106 1107

	if ((s = getenv("bootargs")) == NULL)
		s = "";

	strcpy(cmdline, s);

	*cmd_start = (ulong) & cmdline[0];
	*cmd_end = *cmd_start + strlen(cmdline);

S
Stephen Warren 已提交
1108
	debug("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1109

1110
	return 0;
1111
}
1112
#endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
1113

1114
#ifdef CONFIG_SYS_BOOT_GET_KBD
1115
/**
1116
 * boot_get_kbd - allocate and initialize kernel copy of board info
1117
 * @lmb: pointer to lmb handle, will be used for memory mgmt
1118 1119
 * @kbd: double pointer to board info data
 *
1120
 * boot_get_kbd() allocates space for kernel copy of board info data below
1121 1122
 * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized
 * with the current u-boot board info data.
1123 1124
 *
 * returns:
1125 1126
 *      0 - success
 *     -1 - failure
1127
 */
S
Stephen Warren 已提交
1128
int boot_get_kbd(struct lmb *lmb, bd_t **kbd)
1129
{
1130
	*kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1131
				getenv_bootm_mapsize() + getenv_bootm_low());
1132 1133 1134
	if (*kbd == NULL)
		return -1;

1135 1136
	**kbd = *(gd->bd);

S
Stephen Warren 已提交
1137
	debug("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1138 1139 1140 1141 1142

#if defined(DEBUG) && defined(CONFIG_CMD_BDI)
	do_bdinfo(NULL, 0, 0, NULL);
#endif

1143
	return 0;
1144
}
1145
#endif /* CONFIG_SYS_BOOT_GET_KBD */
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191

#ifdef CONFIG_LMB
int image_setup_linux(bootm_headers_t *images)
{
	ulong of_size = images->ft_len;
	char **of_flat_tree = &images->ft_addr;
	ulong *initrd_start = &images->initrd_start;
	ulong *initrd_end = &images->initrd_end;
	struct lmb *lmb = &images->lmb;
	ulong rd_len;
	int ret;

	if (IMAGE_ENABLE_OF_LIBFDT)
		boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);

	if (IMAGE_BOOT_GET_CMDLINE) {
		ret = boot_get_cmdline(lmb, &images->cmdline_start,
				&images->cmdline_end);
		if (ret) {
			puts("ERROR with allocation of cmdline\n");
			return ret;
		}
	}
	if (IMAGE_ENABLE_RAMDISK_HIGH) {
		rd_len = images->rd_end - images->rd_start;
		ret = boot_ramdisk_high(lmb, images->rd_start, rd_len,
				initrd_start, initrd_end);
		if (ret)
			return ret;
	}

	if (IMAGE_ENABLE_OF_LIBFDT) {
		ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
		if (ret)
			return ret;
	}

	if (IMAGE_ENABLE_OF_LIBFDT && of_size) {
		ret = image_setup_libfdt(images, *of_flat_tree, of_size, lmb);
		if (ret)
			return ret;
	}

	return 0;
}
#endif /* CONFIG_LMB */
1192
#endif /* !USE_HOSTCC */