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