2008-01-09 01:14:09 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2008 Semihalf
|
|
|
|
*
|
|
|
|
* (C) Copyright 2000-2006
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2008-01-09 01:14:09 +08:00
|
|
|
*/
|
2008-01-31 20:57:17 +08:00
|
|
|
|
2008-01-09 01:14:09 +08:00
|
|
|
#ifndef USE_HOSTCC
|
2008-01-31 20:55:39 +08:00
|
|
|
#include <common.h>
|
|
|
|
#include <watchdog.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_SHOW_BOOT_PROGRESS
|
|
|
|
#include <status_led.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_HAS_DATAFLASH
|
|
|
|
#include <dataflash.h>
|
|
|
|
#endif
|
|
|
|
|
2008-05-13 21:53:29 +08:00
|
|
|
#ifdef CONFIG_LOGBUFFER
|
|
|
|
#include <logbuff.h>
|
|
|
|
#endif
|
|
|
|
|
2008-02-22 00:27:41 +08:00
|
|
|
#include <rtc.h>
|
|
|
|
|
2012-12-12 12:16:28 +08:00
|
|
|
#include <environment.h>
|
2008-03-01 04:24:06 +08:00
|
|
|
#include <image.h>
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
|
2008-02-22 00:20:19 +08:00
|
|
|
#include <libfdt.h>
|
|
|
|
#include <fdt_support.h>
|
2008-03-12 17:12:37 +08:00
|
|
|
#endif
|
|
|
|
|
2008-04-03 05:19:07 +08:00
|
|
|
#include <u-boot/md5.h>
|
2008-03-01 04:24:06 +08:00
|
|
|
#include <sha1.h>
|
2013-05-16 21:53:22 +08:00
|
|
|
#include <asm/errno.h>
|
2013-05-07 14:12:03 +08:00
|
|
|
#include <asm/io.h>
|
2008-03-12 17:12:37 +08:00
|
|
|
|
2008-01-31 20:58:13 +08:00
|
|
|
#ifdef CONFIG_CMD_BDI
|
2010-06-29 04:00:46 +08:00
|
|
|
extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
2008-01-31 20:58:13 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2008-02-27 18:01:04 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
|
2008-03-12 17:14:38 +08:00
|
|
|
int verify);
|
2008-01-09 01:14:09 +08:00
|
|
|
#else
|
2008-01-31 20:55:39 +08:00
|
|
|
#include "mkimage.h"
|
2008-04-03 05:19:07 +08:00
|
|
|
#include <u-boot/md5.h>
|
2008-03-01 04:24:06 +08:00
|
|
|
#include <time.h>
|
2008-01-09 01:14:09 +08:00
|
|
|
#include <image.h>
|
2008-03-01 04:24:06 +08:00
|
|
|
#endif /* !USE_HOSTCC*/
|
2008-01-09 01:14:09 +08:00
|
|
|
|
2013-02-25 01:33:25 +08:00
|
|
|
#include <u-boot/crc.h>
|
|
|
|
|
2013-05-08 16:06:01 +08:00
|
|
|
#ifndef CONFIG_SYS_BARGSIZE
|
|
|
|
#define CONFIG_SYS_BARGSIZE 512
|
|
|
|
#endif
|
|
|
|
|
2010-10-20 19:17:39 +08:00
|
|
|
static const table_entry_t uimage_arch[] = {
|
2008-02-29 22:59:59 +08:00
|
|
|
{ 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", },
|
2008-05-05 07:45:01 +08:00
|
|
|
{ IH_ARCH_PPC, "powerpc", "PowerPC", },
|
2008-02-29 22:59:59 +08:00
|
|
|
{ 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", },
|
2011-10-20 04:41:09 +08:00
|
|
|
{ IH_ARCH_NDS32, "nds32", "NDS32", },
|
2011-11-27 03:04:50 +08:00
|
|
|
{ IH_ARCH_OPENRISC, "or1k", "OpenRISC 1000",},
|
2013-05-07 14:12:03 +08:00
|
|
|
{ IH_ARCH_SANDBOX, "sandbox", "Sandbox", },
|
2013-12-14 11:47:35 +08:00
|
|
|
{ IH_ARCH_ARM64, "arm64", "AArch64", },
|
2008-02-29 22:59:59 +08:00
|
|
|
{ -1, "", "", },
|
|
|
|
};
|
|
|
|
|
2010-10-20 19:17:39 +08:00
|
|
|
static const table_entry_t uimage_os[] = {
|
2008-02-29 22:59:59 +08:00
|
|
|
{ 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", },
|
2010-09-28 17:05:36 +08:00
|
|
|
{ IH_OS_OSE, "ose", "Enea OSE", },
|
2013-03-20 14:31:35 +08:00
|
|
|
{ IH_OS_PLAN9, "plan9", "Plan 9", },
|
2008-02-29 22:59:59 +08:00
|
|
|
{ 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
|
2008-09-09 03:56:49 +08:00
|
|
|
#if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC)
|
|
|
|
{ IH_OS_INTEGRITY,"integrity", "INTEGRITY", },
|
|
|
|
#endif
|
2008-02-29 22:59:59 +08:00
|
|
|
#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, "", "", },
|
|
|
|
};
|
|
|
|
|
2010-10-20 19:17:39 +08:00
|
|
|
static const table_entry_t uimage_type[] = {
|
2011-10-17 08:07:43 +08:00
|
|
|
{ IH_TYPE_AISIMAGE, "aisimage", "Davinci AIS image",},
|
2008-02-29 22:59:59 +08:00
|
|
|
{ IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
|
|
|
|
{ IH_TYPE_FIRMWARE, "firmware", "Firmware", },
|
2011-07-21 21:10:30 +08:00
|
|
|
{ IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
|
2008-02-29 22:59:59 +08:00
|
|
|
{ IH_TYPE_KERNEL, "kernel", "Kernel Image", },
|
2011-11-11 04:17:53 +08:00
|
|
|
{ IH_TYPE_KERNEL_NOLOAD, "kernel_noload", "Kernel Image (no loading done)", },
|
2011-10-17 08:07:43 +08:00
|
|
|
{ IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
|
|
|
|
{ IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
|
|
|
|
{ IH_TYPE_INVALID, NULL, "Invalid Image", },
|
2008-02-29 22:59:59 +08:00
|
|
|
{ IH_TYPE_MULTI, "multi", "Multi-File Image", },
|
2011-10-17 08:07:43 +08:00
|
|
|
{ IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",},
|
2012-08-10 10:49:35 +08:00
|
|
|
{ IH_TYPE_PBLIMAGE, "pblimage", "Freescale PBL Boot Image",},
|
2008-02-29 22:59:59 +08:00
|
|
|
{ IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
|
|
|
|
{ IH_TYPE_SCRIPT, "script", "Script", },
|
|
|
|
{ IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
|
2011-07-16 08:06:42 +08:00
|
|
|
{ IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",},
|
2013-08-27 02:43:33 +08:00
|
|
|
{ IH_TYPE_MXSIMAGE, "mxsimage", "Freescale MXS Boot Image",},
|
2008-02-29 22:59:59 +08:00
|
|
|
{ -1, "", "", },
|
|
|
|
};
|
|
|
|
|
2010-10-20 19:17:39 +08:00
|
|
|
static const table_entry_t uimage_comp[] = {
|
2008-02-29 22:59:59 +08:00
|
|
|
{ IH_COMP_NONE, "none", "uncompressed", },
|
|
|
|
{ IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
|
|
|
|
{ IH_COMP_GZIP, "gzip", "gzip compressed", },
|
2008-09-08 08:46:13 +08:00
|
|
|
{ IH_COMP_LZMA, "lzma", "lzma compressed", },
|
2009-11-19 18:37:51 +08:00
|
|
|
{ IH_COMP_LZO, "lzo", "lzo compressed", },
|
2008-02-29 22:59:59 +08:00
|
|
|
{ -1, "", "", },
|
|
|
|
};
|
|
|
|
|
2008-02-29 21:58:34 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Legacy format routines */
|
|
|
|
/*****************************************************************************/
|
2011-10-18 19:11:49 +08:00
|
|
|
int image_check_hcrc(const image_header_t *hdr)
|
2008-01-09 01:14:09 +08:00
|
|
|
{
|
|
|
|
ulong hcrc;
|
2011-10-18 19:11:49 +08:00
|
|
|
ulong len = image_get_header_size();
|
2008-01-09 01:14:09 +08:00
|
|
|
image_header_t header;
|
|
|
|
|
|
|
|
/* Copy header so we can blank CRC field for re-calculation */
|
2011-10-18 19:11:49 +08:00
|
|
|
memmove(&header, (char *)hdr, image_get_header_size());
|
|
|
|
image_set_hcrc(&header, 0);
|
2008-01-09 01:14:09 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
hcrc = crc32(0, (unsigned char *)&header, len);
|
2008-01-09 01:14:09 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
return (hcrc == image_get_hcrc(hdr));
|
2008-01-09 01:14:09 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
int image_check_dcrc(const image_header_t *hdr)
|
2008-01-09 01:14:09 +08:00
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
ulong data = image_get_data(hdr);
|
|
|
|
ulong len = image_get_data_size(hdr);
|
|
|
|
ulong dcrc = crc32_wd(0, (unsigned char *)data, len, CHUNKSZ_CRC32);
|
2008-01-09 01:14:09 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
return (dcrc == image_get_dcrc(hdr));
|
2008-01-09 01:14:09 +08:00
|
|
|
}
|
|
|
|
|
2008-01-09 01:12:17 +08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
ulong image_multi_count(const image_header_t *hdr)
|
2008-01-09 01:12:17 +08:00
|
|
|
{
|
|
|
|
ulong i, count = 0;
|
2008-02-29 23:00:06 +08:00
|
|
|
uint32_t *size;
|
2008-01-09 01:12:17 +08:00
|
|
|
|
|
|
|
/* get start of the image payload, which in case of multi
|
|
|
|
* component images that points to a table of component sizes */
|
2011-10-18 19:11:49 +08:00
|
|
|
size = (uint32_t *)image_get_data(hdr);
|
2008-01-09 01:12:17 +08:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
void image_multi_getimg(const image_header_t *hdr, ulong idx,
|
2008-01-09 01:12:17 +08:00
|
|
|
ulong *data, ulong *len)
|
|
|
|
{
|
|
|
|
int i;
|
2008-02-29 23:00:06 +08:00
|
|
|
uint32_t *size;
|
2008-05-11 05:02:04 +08:00
|
|
|
ulong offset, count, img_data;
|
2008-01-09 01:12:17 +08:00
|
|
|
|
|
|
|
/* get number of component */
|
2011-10-18 19:11:49 +08:00
|
|
|
count = image_multi_count(hdr);
|
2008-01-09 01:12:17 +08:00
|
|
|
|
|
|
|
/* get start of the image payload, which in case of multi
|
|
|
|
* component images that points to a table of component sizes */
|
2011-10-18 19:11:49 +08:00
|
|
|
size = (uint32_t *)image_get_data(hdr);
|
2008-01-09 01:12:17 +08:00
|
|
|
|
|
|
|
/* get address of the proper component data start, which means
|
|
|
|
* skipping sizes table (add 1 for last, null entry) */
|
2011-10-18 19:11:49 +08:00
|
|
|
img_data = image_get_data(hdr) + (count + 1) * sizeof(uint32_t);
|
2008-01-09 01:12:17 +08:00
|
|
|
|
|
|
|
if (idx < count) {
|
2011-10-18 19:11:49 +08:00
|
|
|
*len = uimage_to_cpu(size[idx]);
|
2008-01-09 01:12:17 +08:00
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
/* go over all indices preceding requested component idx */
|
|
|
|
for (i = 0; i < idx; i++) {
|
2008-05-11 05:02:04 +08:00
|
|
|
/* add up i-th component size, rounding up to 4 bytes */
|
2011-10-18 19:11:49 +08:00
|
|
|
offset += (uimage_to_cpu(size[i]) + 3) & ~3 ;
|
2008-01-09 01:12:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate idx-th component data address */
|
2008-05-11 05:02:04 +08:00
|
|
|
*data = img_data + offset;
|
2008-01-09 01:12:17 +08:00
|
|
|
} else {
|
|
|
|
*len = 0;
|
|
|
|
*data = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-01-31 20:20:07 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
static void image_print_type(const image_header_t *hdr)
|
2008-02-29 21:58:34 +08:00
|
|
|
{
|
|
|
|
const char *os, *arch, *type, *comp;
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
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));
|
2008-02-29 21:58:34 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("%s %s %s (%s)\n", arch, os, type, comp);
|
2008-02-29 21:58:34 +08:00
|
|
|
}
|
|
|
|
|
2008-03-01 04:24:06 +08:00
|
|
|
/**
|
2008-04-18 18:39:23 +08:00
|
|
|
* image_print_contents - prints out the contents of the legacy format image
|
2009-08-19 17:42:56 +08:00
|
|
|
* @ptr: pointer to the legacy format image header
|
2008-03-01 04:24:06 +08:00
|
|
|
* @p: pointer to prefix string
|
|
|
|
*
|
2008-04-18 18:39:23 +08:00
|
|
|
* image_print_contents() formats a multi line legacy image contents description.
|
2008-03-01 04:24:06 +08:00
|
|
|
* The routine prints out all header fields followed by the size/offset data
|
|
|
|
* for MULTI/SCRIPT images.
|
|
|
|
*
|
|
|
|
* returns:
|
|
|
|
* no returned results
|
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
void image_print_contents(const void *ptr)
|
2008-02-29 21:58:34 +08:00
|
|
|
{
|
2009-08-19 17:42:56 +08:00
|
|
|
const image_header_t *hdr = (const image_header_t *)ptr;
|
2008-04-18 18:39:23 +08:00
|
|
|
const char *p;
|
|
|
|
|
2013-05-08 16:05:58 +08:00
|
|
|
p = IMAGE_INDENT_STRING;
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name(hdr));
|
2013-05-07 14:11:51 +08:00
|
|
|
if (IMAGE_ENABLE_TIMESTAMP) {
|
|
|
|
printf("%sCreated: ", p);
|
|
|
|
genimg_print_time((time_t)image_get_time(hdr));
|
|
|
|
}
|
2011-10-18 19:11:49 +08:00
|
|
|
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)) {
|
2008-02-29 21:58:34 +08:00
|
|
|
int i;
|
|
|
|
ulong data, len;
|
2011-10-18 19:11:49 +08:00
|
|
|
ulong count = image_multi_count(hdr);
|
2008-02-29 21:58:34 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("%sContents:\n", p);
|
2008-02-29 21:58:34 +08:00
|
|
|
for (i = 0; i < count; i++) {
|
2011-10-18 19:11:49 +08:00
|
|
|
image_multi_getimg(hdr, i, &data, &len);
|
2008-02-29 22:59:59 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("%s Image %d: ", p, i);
|
|
|
|
genimg_print_size(len);
|
2008-02-29 22:59:59 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
if (image_check_type(hdr, IH_TYPE_SCRIPT) && i > 0) {
|
2008-02-29 22:59:59 +08:00
|
|
|
/*
|
|
|
|
* the user may need to know offsets
|
|
|
|
* if planning to do something with
|
|
|
|
* multiple files
|
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("%s Offset = 0x%08lx\n", p, data);
|
2008-02-29 22:59:59 +08:00
|
|
|
}
|
2008-02-29 21:58:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-29 22:59:59 +08:00
|
|
|
|
|
|
|
#ifndef USE_HOSTCC
|
2008-02-29 21:58:34 +08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
|
2008-03-12 17:14:38 +08:00
|
|
|
int verify)
|
2008-02-29 21:58:34 +08:00
|
|
|
{
|
2009-08-19 17:42:56 +08:00
|
|
|
const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
|
2008-02-29 21:58:34 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
if (!image_check_magic(rd_hdr)) {
|
|
|
|
puts("Bad Magic Number\n");
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_error(BOOTSTAGE_ID_RD_MAGIC);
|
2008-02-29 21:58:34 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
if (!image_check_hcrc(rd_hdr)) {
|
|
|
|
puts("Bad Header Checksum\n");
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_error(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
|
2008-02-29 21:58:34 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_mark(BOOTSTAGE_ID_RD_MAGIC);
|
2011-10-18 19:11:49 +08:00
|
|
|
image_print_contents(rd_hdr);
|
2008-02-29 21:58:34 +08:00
|
|
|
|
|
|
|
if (verify) {
|
|
|
|
puts(" Verifying Checksum ... ");
|
2011-10-18 19:11:49 +08:00
|
|
|
if (!image_check_dcrc(rd_hdr)) {
|
|
|
|
puts("Bad Data CRC\n");
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_error(BOOTSTAGE_ID_RD_CHECKSUM);
|
2008-02-29 21:58:34 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
puts("OK\n");
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_mark(BOOTSTAGE_ID_RD_HDR_CHECKSUM);
|
2008-02-29 21:58:34 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
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",
|
2008-02-29 21:58:34 +08:00
|
|
|
genimg_get_arch_name(arch));
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_error(BOOTSTAGE_ID_RAMDISK);
|
2008-02-29 21:58:34 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rd_hdr;
|
|
|
|
}
|
2008-02-29 22:59:59 +08:00
|
|
|
#endif /* !USE_HOSTCC */
|
2008-02-29 21:58:34 +08:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Shared dual-format routines */
|
|
|
|
/*****************************************************************************/
|
2008-02-29 22:59:59 +08:00
|
|
|
#ifndef USE_HOSTCC
|
2012-12-12 12:16:28 +08:00
|
|
|
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);
|
|
|
|
|
2008-02-29 21:58:34 +08:00
|
|
|
ulong getenv_bootm_low(void)
|
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
char *s = getenv("bootm_low");
|
2008-02-29 21:58:34 +08:00
|
|
|
if (s) {
|
2011-10-18 19:11:49 +08:00
|
|
|
ulong tmp = simple_strtoul(s, NULL, 16);
|
2008-02-29 21:58:34 +08:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
#if defined(CONFIG_SYS_SDRAM_BASE)
|
|
|
|
return CONFIG_SYS_SDRAM_BASE;
|
2008-03-12 19:14:15 +08:00
|
|
|
#elif defined(CONFIG_ARM)
|
|
|
|
return gd->bd->bi_dram[0].start;
|
2008-02-29 21:58:34 +08:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-06-10 09:37:18 +08:00
|
|
|
phys_size_t getenv_bootm_size(void)
|
2008-02-29 21:58:34 +08:00
|
|
|
{
|
2010-07-08 23:11:08 +08:00
|
|
|
phys_size_t tmp;
|
2011-10-18 19:11:49 +08:00
|
|
|
char *s = getenv("bootm_size");
|
2008-02-29 21:58:34 +08:00
|
|
|
if (s) {
|
2011-10-18 19:11:49 +08:00
|
|
|
tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
|
2008-02-29 21:58:34 +08:00
|
|
|
return tmp;
|
|
|
|
}
|
2010-07-08 23:11:08 +08:00
|
|
|
s = getenv("bootm_low");
|
|
|
|
if (s)
|
2011-10-18 19:11:49 +08:00
|
|
|
tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
|
2010-07-08 23:11:08 +08:00
|
|
|
else
|
|
|
|
tmp = 0;
|
|
|
|
|
2008-02-29 21:58:34 +08:00
|
|
|
|
2008-03-12 19:14:15 +08:00
|
|
|
#if defined(CONFIG_ARM)
|
2010-07-08 23:11:08 +08:00
|
|
|
return gd->bd->bi_dram[0].size - tmp;
|
2008-03-12 19:14:15 +08:00
|
|
|
#else
|
2010-07-08 23:11:08 +08:00
|
|
|
return gd->bd->bi_memsize - tmp;
|
2008-03-12 19:14:15 +08:00
|
|
|
#endif
|
2008-02-29 21:58:34 +08:00
|
|
|
}
|
|
|
|
|
2011-03-28 17:58:43 +08:00
|
|
|
phys_size_t getenv_bootm_mapsize(void)
|
|
|
|
{
|
|
|
|
phys_size_t tmp;
|
2011-10-18 19:11:49 +08:00
|
|
|
char *s = getenv("bootm_mapsize");
|
2011-03-28 17:58:43 +08:00
|
|
|
if (s) {
|
2011-10-18 19:11:49 +08:00
|
|
|
tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
|
2011-03-28 17:58:43 +08:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_SYS_BOOTMAPSZ)
|
|
|
|
return CONFIG_SYS_BOOTMAPSZ;
|
|
|
|
#else
|
|
|
|
return getenv_bootm_size();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
|
2008-02-29 21:58:34 +08:00
|
|
|
{
|
2010-04-20 20:09:43 +08:00
|
|
|
if (to == from)
|
|
|
|
return;
|
|
|
|
|
2008-02-29 21:58:34 +08:00
|
|
|
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
|
|
|
|
while (len > 0) {
|
|
|
|
size_t tail = (len > chunksz) ? chunksz : len;
|
2011-10-18 19:11:49 +08:00
|
|
|
WATCHDOG_RESET();
|
|
|
|
memmove(to, from, tail);
|
2008-02-29 21:58:34 +08:00
|
|
|
to += tail;
|
|
|
|
from += tail;
|
|
|
|
len -= tail;
|
|
|
|
}
|
|
|
|
#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
|
2011-10-18 19:11:49 +08:00
|
|
|
memmove(to, from, len);
|
2008-02-29 21:58:34 +08:00
|
|
|
#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
|
|
|
|
}
|
2008-02-29 22:59:59 +08:00
|
|
|
#endif /* !USE_HOSTCC */
|
2008-02-29 21:58:34 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
void genimg_print_size(uint32_t size)
|
2008-01-31 20:20:07 +08:00
|
|
|
{
|
2008-02-29 22:59:59 +08:00
|
|
|
#ifndef USE_HOSTCC
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("%d Bytes = ", size);
|
|
|
|
print_size(size, "\n");
|
2008-02-29 22:59:59 +08:00
|
|
|
#else
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("%d Bytes = %.2f kB = %.2f MB\n",
|
2008-02-29 22:59:59 +08:00
|
|
|
size, (double)size / 1.024e3,
|
|
|
|
(double)size / 1.048576e6);
|
2008-01-31 20:20:07 +08:00
|
|
|
#endif
|
2008-02-29 22:59:59 +08:00
|
|
|
}
|
|
|
|
|
2013-05-07 14:11:51 +08:00
|
|
|
#if IMAGE_ENABLE_TIMESTAMP
|
|
|
|
void genimg_print_time(time_t timestamp)
|
2008-02-29 22:59:59 +08:00
|
|
|
{
|
|
|
|
#ifndef USE_HOSTCC
|
|
|
|
struct rtc_time tm;
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
to_tm(timestamp, &tm);
|
|
|
|
printf("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
|
2008-02-29 22:59:59 +08:00
|
|
|
tm.tm_year, tm.tm_mon, tm.tm_mday,
|
|
|
|
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
|
|
#else
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("%s", ctime(×tamp));
|
2008-01-31 20:20:07 +08:00
|
|
|
#endif
|
2008-02-29 22:59:59 +08:00
|
|
|
}
|
2013-05-07 14:11:51 +08:00
|
|
|
#endif
|
2008-01-31 20:20:07 +08:00
|
|
|
|
2008-02-29 22:59:59 +08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2010-10-20 19:17:39 +08:00
|
|
|
char *get_table_entry_name(const table_entry_t *table, char *msg, int id)
|
2008-02-29 22:59:59 +08:00
|
|
|
{
|
|
|
|
for (; table->id >= 0; ++table) {
|
|
|
|
if (table->id == id)
|
2010-10-29 02:00:11 +08:00
|
|
|
#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
|
2009-04-03 05:15:10 +08:00
|
|
|
return table->lname;
|
|
|
|
#else
|
|
|
|
return table->lname + gd->reloc_off;
|
|
|
|
#endif
|
2008-01-31 20:20:07 +08:00
|
|
|
}
|
2008-02-29 22:59:59 +08:00
|
|
|
return (msg);
|
|
|
|
}
|
2008-01-31 20:20:07 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
const char *genimg_get_os_name(uint8_t os)
|
2008-02-29 22:59:59 +08:00
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
return (get_table_entry_name(uimage_os, "Unknown OS", os));
|
2008-01-31 20:20:07 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
const char *genimg_get_arch_name(uint8_t arch)
|
2008-01-31 20:20:07 +08:00
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
return (get_table_entry_name(uimage_arch, "Unknown Architecture",
|
|
|
|
arch));
|
2008-02-29 22:59:59 +08:00
|
|
|
}
|
2008-01-31 20:20:07 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
const char *genimg_get_type_name(uint8_t type)
|
2008-02-29 22:59:59 +08:00
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
return (get_table_entry_name(uimage_type, "Unknown Image", type));
|
2008-02-29 22:59:59 +08:00
|
|
|
}
|
2008-01-31 20:20:07 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
const char *genimg_get_comp_name(uint8_t comp)
|
2008-02-29 22:59:59 +08:00
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
return (get_table_entry_name(uimage_comp, "Unknown Compression",
|
|
|
|
comp));
|
2008-01-31 20:20:07 +08:00
|
|
|
}
|
|
|
|
|
2008-02-29 22:59:59 +08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2010-10-20 19:17:39 +08:00
|
|
|
int get_table_entry_id(const table_entry_t *table,
|
2008-02-29 22:59:59 +08:00
|
|
|
const char *table_name, const char *name)
|
2008-01-31 20:20:07 +08:00
|
|
|
{
|
2010-10-20 19:17:39 +08:00
|
|
|
const table_entry_t *t;
|
2008-02-29 22:59:59 +08:00
|
|
|
#ifdef USE_HOSTCC
|
|
|
|
int first = 1;
|
2008-01-31 20:20:07 +08:00
|
|
|
|
2008-02-29 22:59:59 +08:00
|
|
|
for (t = table; t->id >= 0; ++t) {
|
|
|
|
if (t->sname && strcasecmp(t->sname, name) == 0)
|
2011-10-18 19:11:49 +08:00
|
|
|
return(t->id);
|
2008-01-31 20:20:07 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
fprintf(stderr, "\nInvalid %s Type - valid names are", table_name);
|
2008-02-29 22:59:59 +08:00
|
|
|
for (t = table; t->id >= 0; ++t) {
|
|
|
|
if (t->sname == NULL)
|
|
|
|
continue;
|
2011-10-18 19:11:49 +08:00
|
|
|
fprintf(stderr, "%c %s", (first) ? ':' : ',', t->sname);
|
2008-02-29 22:59:59 +08:00
|
|
|
first = 0;
|
|
|
|
}
|
2011-10-18 19:11:49 +08:00
|
|
|
fprintf(stderr, "\n");
|
2008-02-29 22:59:59 +08:00
|
|
|
#else
|
|
|
|
for (t = table; t->id >= 0; ++t) {
|
2010-10-29 02:00:11 +08:00
|
|
|
#ifdef CONFIG_NEEDS_MANUAL_RELOC
|
2009-04-03 05:15:10 +08:00
|
|
|
if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
|
2010-10-29 02:00:11 +08:00
|
|
|
#else
|
|
|
|
if (t->sname && strcmp(t->sname, name) == 0)
|
2009-09-22 00:20:36 +08:00
|
|
|
#endif
|
2008-02-29 22:59:59 +08:00
|
|
|
return (t->id);
|
|
|
|
}
|
2011-10-18 19:11:49 +08:00
|
|
|
debug("Invalid %s Type: %s\n", table_name, name);
|
2008-02-29 22:59:59 +08:00
|
|
|
#endif /* USE_HOSTCC */
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
int genimg_get_os_id(const char *name)
|
2008-02-29 22:59:59 +08:00
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
return (get_table_entry_id(uimage_os, "OS", name));
|
2008-02-29 22:59:59 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
int genimg_get_arch_id(const char *name)
|
2008-02-29 22:59:59 +08:00
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
return (get_table_entry_id(uimage_arch, "CPU", name));
|
2008-01-31 20:20:07 +08:00
|
|
|
}
|
2008-01-31 20:55:39 +08:00
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
int genimg_get_type_id(const char *name)
|
2008-02-29 22:59:59 +08:00
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
return (get_table_entry_id(uimage_type, "Image", name));
|
2008-02-29 22:59:59 +08:00
|
|
|
}
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
int genimg_get_comp_id(const char *name)
|
2008-02-29 22:59:59 +08:00
|
|
|
{
|
2011-10-18 19:11:49 +08:00
|
|
|
return (get_table_entry_id(uimage_comp, "Compression", name));
|
2008-02-29 22:59:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef USE_HOSTCC
|
2008-02-22 00:20:19 +08:00
|
|
|
/**
|
2008-02-29 21:58:34 +08:00
|
|
|
* genimg_get_format - get image format type
|
2008-02-22 00:20:19 +08:00
|
|
|
* @img_addr: image start address
|
|
|
|
*
|
2008-02-29 21:58:34 +08:00
|
|
|
* genimg_get_format() checks whether provided address points to a valid
|
2008-02-22 00:20:19 +08:00
|
|
|
* legacy or FIT image.
|
|
|
|
*
|
2008-02-27 18:02:26 +08:00
|
|
|
* 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
|
2008-02-29 21:58:34 +08:00
|
|
|
* genimg_get_format() must be able to dectect libfdt header.
|
2008-02-27 18:02:26 +08:00
|
|
|
*
|
2008-02-22 00:20:19 +08:00
|
|
|
* returns:
|
|
|
|
* image format type or IMAGE_FORMAT_INVALID if no image is present
|
|
|
|
*/
|
2013-05-07 14:12:03 +08:00
|
|
|
int genimg_get_format(const void *img_addr)
|
2008-02-22 00:20:19 +08:00
|
|
|
{
|
2009-08-19 17:42:56 +08:00
|
|
|
ulong format = IMAGE_FORMAT_INVALID;
|
|
|
|
const image_header_t *hdr;
|
2008-02-22 00:20:19 +08:00
|
|
|
|
2009-08-19 17:42:56 +08:00
|
|
|
hdr = (const image_header_t *)img_addr;
|
2008-02-22 00:20:19 +08:00
|
|
|
if (image_check_magic(hdr))
|
|
|
|
format = IMAGE_FORMAT_LEGACY;
|
2008-02-27 18:02:26 +08:00
|
|
|
#if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
|
2008-02-22 00:20:19 +08:00
|
|
|
else {
|
2013-09-19 11:10:18 +08:00
|
|
|
if (fdt_check_header(img_addr) == 0)
|
2008-02-22 00:20:19 +08:00
|
|
|
format = IMAGE_FORMAT_FIT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-29 21:58:34 +08:00
|
|
|
* genimg_get_image - get image from special storage (if necessary)
|
2008-02-22 00:20:19 +08:00
|
|
|
* @img_addr: image start address
|
|
|
|
*
|
2008-02-29 21:58:34 +08:00
|
|
|
* genimg_get_image() checks if provided image start adddress is located
|
2008-02-22 00:20:19 +08:00
|
|
|
* in a dataflash storage. If so, image is moved to a system RAM memory.
|
|
|
|
*
|
|
|
|
* returns:
|
|
|
|
* image start address after possible relocation from special storage
|
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
ulong genimg_get_image(ulong img_addr)
|
2008-02-22 00:20:19 +08:00
|
|
|
{
|
2008-02-27 18:00:47 +08:00
|
|
|
ulong ram_addr = img_addr;
|
2008-02-22 00:20:19 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_HAS_DATAFLASH
|
2008-02-27 18:00:47 +08:00
|
|
|
ulong h_size, d_size;
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
if (addr_dataflash(img_addr)) {
|
2013-05-07 14:12:03 +08:00
|
|
|
void *buf;
|
|
|
|
|
2008-02-27 18:00:47 +08:00
|
|
|
/* ger RAM address */
|
2008-10-16 21:01:15 +08:00
|
|
|
ram_addr = CONFIG_SYS_LOAD_ADDR;
|
2008-02-27 18:00:47 +08:00
|
|
|
|
|
|
|
/* get header size */
|
2011-10-18 19:11:49 +08:00
|
|
|
h_size = image_get_header_size();
|
2008-02-27 18:00:47 +08:00
|
|
|
#if defined(CONFIG_FIT)
|
|
|
|
if (sizeof(struct fdt_header) > h_size)
|
|
|
|
h_size = sizeof(struct fdt_header);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* read in header */
|
2011-10-18 19:11:49 +08:00
|
|
|
debug(" Reading image header from dataflash address "
|
2008-02-22 00:20:19 +08:00
|
|
|
"%08lx to RAM address %08lx\n", img_addr, ram_addr);
|
|
|
|
|
2013-05-07 14:12:03 +08:00
|
|
|
buf = map_sysmem(ram_addr, 0);
|
|
|
|
read_dataflash(img_addr, h_size, buf);
|
2008-02-22 00:20:19 +08:00
|
|
|
|
2008-02-27 18:00:47 +08:00
|
|
|
/* get data size */
|
2013-05-07 14:12:03 +08:00
|
|
|
switch (genimg_get_format(buf)) {
|
2008-02-27 18:00:47 +08:00
|
|
|
case IMAGE_FORMAT_LEGACY:
|
2013-05-07 14:12:03 +08:00
|
|
|
d_size = image_get_data_size(buf);
|
2011-10-18 19:11:49 +08:00
|
|
|
debug(" Legacy format image found at 0x%08lx, "
|
|
|
|
"size 0x%08lx\n",
|
2008-02-27 18:00:47 +08:00
|
|
|
ram_addr, d_size);
|
|
|
|
break;
|
2008-02-22 00:20:19 +08:00
|
|
|
#if defined(CONFIG_FIT)
|
2008-02-27 18:00:47 +08:00
|
|
|
case IMAGE_FORMAT_FIT:
|
2013-05-07 14:12:03 +08:00
|
|
|
d_size = fit_get_size(buf) - h_size;
|
2011-10-18 19:11:49 +08:00
|
|
|
debug(" FIT/FDT format image found at 0x%08lx, "
|
|
|
|
"size 0x%08lx\n",
|
2008-02-27 18:00:47 +08:00
|
|
|
ram_addr, d_size);
|
|
|
|
break;
|
2008-02-22 00:20:19 +08:00
|
|
|
#endif
|
2008-02-27 18:00:47 +08:00
|
|
|
default:
|
2011-10-18 19:11:49 +08:00
|
|
|
printf(" No valid image found at 0x%08lx\n",
|
|
|
|
img_addr);
|
2008-02-27 18:00:47 +08:00
|
|
|
return ram_addr;
|
|
|
|
}
|
2008-02-22 00:20:19 +08:00
|
|
|
|
2008-02-27 18:00:47 +08:00
|
|
|
/* read in image data */
|
2011-10-18 19:11:49 +08:00
|
|
|
debug(" Reading image remaining data from dataflash address "
|
2008-02-22 00:20:19 +08:00
|
|
|
"%08lx to RAM address %08lx\n", img_addr + h_size,
|
|
|
|
ram_addr + h_size);
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
read_dataflash(img_addr + h_size, d_size,
|
2013-05-07 14:12:03 +08:00
|
|
|
(char *)(buf + h_size));
|
2008-02-27 18:00:47 +08:00
|
|
|
|
2008-02-22 00:20:19 +08:00
|
|
|
}
|
2008-02-27 18:00:47 +08:00
|
|
|
#endif /* CONFIG_HAS_DATAFLASH */
|
2008-02-22 00:20:19 +08:00
|
|
|
|
|
|
|
return ram_addr;
|
|
|
|
}
|
|
|
|
|
2008-03-12 17:35:46 +08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
int genimg_has_config(bootm_headers_t *images)
|
2008-03-12 17:35:46 +08:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_FIT)
|
|
|
|
if (images->fit_uname_cfg)
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-31 20:55:39 +08:00
|
|
|
/**
|
2008-02-29 21:58:34 +08:00
|
|
|
* boot_get_ramdisk - main ramdisk handling routine
|
2008-01-31 20:55:39 +08:00
|
|
|
* @argc: command argument count
|
|
|
|
* @argv: command argument list
|
2008-02-27 18:01:04 +08:00
|
|
|
* @images: pointer to the bootm images structure
|
2008-01-31 20:55:39 +08:00
|
|
|
* @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
|
|
|
|
*
|
2008-02-29 21:58:34 +08:00
|
|
|
* boot_get_ramdisk() is responsible for finding a valid ramdisk image.
|
2008-01-31 20:55:39 +08:00
|
|
|
* Curently supported are the following ramdisk sources:
|
|
|
|
* - multicomponent kernel/ramdisk image,
|
|
|
|
* - commandline provided address of decicated ramdisk image.
|
|
|
|
*
|
|
|
|
* returns:
|
2008-03-12 17:14:38 +08:00
|
|
|
* 0, if ramdisk image was found and valid, or skiped
|
2008-01-31 20:55:39 +08:00
|
|
|
* rd_start and rd_end are set to ramdisk start/end addresses if
|
|
|
|
* ramdisk image is found and valid
|
2008-03-12 17:14:38 +08:00
|
|
|
*
|
2008-08-30 08:08:29 +08:00
|
|
|
* 1, if ramdisk image is found but corrupted, or invalid
|
2008-01-31 20:55:39 +08:00
|
|
|
* rd_start and rd_end are set to 0 if no ramdisk exists
|
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
|
2008-03-12 17:14:38 +08:00
|
|
|
uint8_t arch, ulong *rd_start, ulong *rd_end)
|
2008-01-31 20:55:39 +08:00
|
|
|
{
|
2008-02-04 15:28:09 +08:00
|
|
|
ulong rd_addr, rd_load;
|
2008-01-31 20:55:39 +08:00
|
|
|
ulong rd_data, rd_len;
|
2009-08-19 17:42:56 +08:00
|
|
|
const image_header_t *rd_hdr;
|
2013-05-07 14:12:03 +08:00
|
|
|
void *buf;
|
2012-03-31 05:19:10 +08:00
|
|
|
#ifdef CONFIG_SUPPORT_RAW_INITRD
|
2012-03-18 19:47:58 +08:00
|
|
|
char *end;
|
2012-03-31 05:19:10 +08:00
|
|
|
#endif
|
2008-02-04 15:28:09 +08:00
|
|
|
#if defined(CONFIG_FIT)
|
2013-07-11 14:08:10 +08:00
|
|
|
const char *fit_uname_config = images->fit_uname_cfg;
|
2008-02-04 15:28:09 +08:00
|
|
|
const char *fit_uname_ramdisk = NULL;
|
|
|
|
ulong default_addr;
|
2008-03-12 17:12:37 +08:00
|
|
|
int rd_noffset;
|
2008-02-04 15:28:09 +08:00
|
|
|
#endif
|
2013-06-12 02:14:46 +08:00
|
|
|
const char *select = NULL;
|
2008-01-31 20:55:39 +08:00
|
|
|
|
2008-03-12 17:12:37 +08:00
|
|
|
*rd_start = 0;
|
|
|
|
*rd_end = 0;
|
|
|
|
|
2013-06-12 02:14:46 +08:00
|
|
|
if (argc >= 2)
|
|
|
|
select = argv[1];
|
2008-02-04 15:28:09 +08:00
|
|
|
/*
|
|
|
|
* Look for a '-' which indicates to ignore the
|
|
|
|
* ramdisk argument
|
|
|
|
*/
|
2013-06-12 02:14:46 +08:00
|
|
|
if (select && strcmp(select, "-") == 0) {
|
2011-10-18 19:11:49 +08:00
|
|
|
debug("## Skipping init Ramdisk\n");
|
2008-02-04 15:28:09 +08:00
|
|
|
rd_len = rd_data = 0;
|
2013-06-12 02:14:46 +08:00
|
|
|
} else if (select || genimg_has_config(images)) {
|
2008-02-04 15:28:09 +08:00
|
|
|
#if defined(CONFIG_FIT)
|
2013-06-12 02:14:46 +08:00
|
|
|
if (select) {
|
2008-03-12 17:35:46 +08:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2013-06-12 02:14:46 +08:00
|
|
|
if (fit_parse_conf(select, default_addr,
|
|
|
|
&rd_addr, &fit_uname_config)) {
|
2011-10-18 19:11:49 +08:00
|
|
|
debug("* ramdisk: config '%s' from image at "
|
|
|
|
"0x%08lx\n",
|
2008-03-12 17:35:46 +08:00
|
|
|
fit_uname_config, rd_addr);
|
2013-06-12 02:14:46 +08:00
|
|
|
} else if (fit_parse_subimage(select, default_addr,
|
2008-03-12 17:35:46 +08:00
|
|
|
&rd_addr, &fit_uname_ramdisk)) {
|
2011-10-18 19:11:49 +08:00
|
|
|
debug("* ramdisk: subimage '%s' from image at "
|
|
|
|
"0x%08lx\n",
|
2008-03-12 17:35:46 +08:00
|
|
|
fit_uname_ramdisk, rd_addr);
|
|
|
|
} else
|
2008-02-04 15:28:09 +08:00
|
|
|
#endif
|
2008-03-12 17:35:46 +08:00
|
|
|
{
|
2013-06-12 02:14:46 +08:00
|
|
|
rd_addr = simple_strtoul(select, NULL, 16);
|
2011-10-18 19:11:49 +08:00
|
|
|
debug("* ramdisk: cmdline image address = "
|
|
|
|
"0x%08lx\n",
|
2008-03-12 17:35:46 +08:00
|
|
|
rd_addr);
|
|
|
|
}
|
|
|
|
#if defined(CONFIG_FIT)
|
|
|
|
} else {
|
|
|
|
/* use FIT configuration provided in first bootm
|
2013-05-16 21:53:22 +08:00
|
|
|
* command argument. If the property is not defined,
|
|
|
|
* quit silently.
|
2008-03-12 17:35:46 +08:00
|
|
|
*/
|
2013-05-07 14:12:03 +08:00
|
|
|
rd_addr = map_to_sysmem(images->fit_hdr_os);
|
2013-05-16 21:53:22 +08:00
|
|
|
rd_noffset = fit_get_node_from_config(images,
|
|
|
|
FIT_RAMDISK_PROP, rd_addr);
|
|
|
|
if (rd_noffset == -ENOLINK)
|
2008-08-05 23:51:57 +08:00
|
|
|
return 0;
|
2013-05-16 21:53:22 +08:00
|
|
|
else if (rd_noffset < 0)
|
|
|
|
return 1;
|
2008-02-04 15:28:09 +08:00
|
|
|
}
|
2008-03-12 17:35:46 +08:00
|
|
|
#endif
|
2008-02-04 15:28:09 +08:00
|
|
|
|
|
|
|
/* copy from dataflash if needed */
|
2011-10-18 19:11:49 +08:00
|
|
|
rd_addr = genimg_get_image(rd_addr);
|
2008-02-04 15:28:09 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-05-07 14:12:03 +08:00
|
|
|
buf = map_sysmem(rd_addr, 0);
|
|
|
|
switch (genimg_get_format(buf)) {
|
2008-02-04 15:28:09 +08:00
|
|
|
case IMAGE_FORMAT_LEGACY:
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("## Loading init Ramdisk from Legacy "
|
2008-03-12 17:12:37 +08:00
|
|
|
"Image at %08lx ...\n", rd_addr);
|
2008-01-31 20:55:39 +08:00
|
|
|
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_mark(BOOTSTAGE_ID_CHECK_RAMDISK);
|
2011-10-18 19:11:49 +08:00
|
|
|
rd_hdr = image_get_ramdisk(rd_addr, arch,
|
2008-03-12 17:14:38 +08:00
|
|
|
images->verify);
|
2008-01-31 20:55:39 +08:00
|
|
|
|
2008-03-12 17:12:37 +08:00
|
|
|
if (rd_hdr == NULL)
|
2008-02-28 11:51:46 +08:00
|
|
|
return 1;
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
rd_data = image_get_data(rd_hdr);
|
|
|
|
rd_len = image_get_data_size(rd_hdr);
|
|
|
|
rd_load = image_get_load(rd_hdr);
|
2008-02-04 15:28:09 +08:00
|
|
|
break;
|
|
|
|
#if defined(CONFIG_FIT)
|
|
|
|
case IMAGE_FORMAT_FIT:
|
2013-05-16 21:53:22 +08:00
|
|
|
rd_noffset = fit_image_load(images, FIT_RAMDISK_PROP,
|
|
|
|
rd_addr, &fit_uname_ramdisk,
|
2013-07-11 14:08:10 +08:00
|
|
|
&fit_uname_config, arch,
|
2013-05-16 21:53:22 +08:00
|
|
|
IH_TYPE_RAMDISK,
|
|
|
|
BOOTSTAGE_ID_FIT_RD_START,
|
2013-07-12 21:09:23 +08:00
|
|
|
FIT_LOAD_IGNORED, &rd_data, &rd_len);
|
2013-05-16 21:53:22 +08:00
|
|
|
if (rd_noffset < 0)
|
2008-07-11 16:43:13 +08:00
|
|
|
return 1;
|
2008-03-12 17:12:37 +08:00
|
|
|
|
2013-05-16 21:53:22 +08:00
|
|
|
images->fit_hdr_rd = map_sysmem(rd_addr, 0);
|
2008-03-12 17:12:37 +08:00
|
|
|
images->fit_uname_rd = fit_uname_ramdisk;
|
2008-03-12 17:32:59 +08:00
|
|
|
images->fit_noffset_rd = rd_noffset;
|
2008-03-12 17:12:37 +08:00
|
|
|
break;
|
2008-02-04 15:28:09 +08:00
|
|
|
#endif
|
|
|
|
default:
|
2012-03-18 19:47:58 +08:00
|
|
|
#ifdef CONFIG_SUPPORT_RAW_INITRD
|
2013-06-12 02:14:46 +08:00
|
|
|
end = NULL;
|
|
|
|
if (select)
|
|
|
|
end = strchr(select, ':');
|
|
|
|
if (end) {
|
2012-03-18 19:47:58 +08:00
|
|
|
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;
|
|
|
|
}
|
2008-02-04 15:28:09 +08:00
|
|
|
}
|
|
|
|
} else if (images->legacy_hdr_valid &&
|
2011-10-18 19:11:49 +08:00
|
|
|
image_check_type(&images->legacy_hdr_os_copy,
|
|
|
|
IH_TYPE_MULTI)) {
|
|
|
|
|
2008-01-31 20:55:39 +08:00
|
|
|
/*
|
2008-02-04 15:28:09 +08:00
|
|
|
* Now check if we have a legacy mult-component image,
|
|
|
|
* get second entry data start address and len.
|
2008-01-31 20:55:39 +08:00
|
|
|
*/
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_mark(BOOTSTAGE_ID_RAMDISK);
|
2011-10-18 19:11:49 +08:00
|
|
|
printf("## Loading init Ramdisk from multi component "
|
2008-03-12 17:12:37 +08:00
|
|
|
"Legacy Image at %08lx ...\n",
|
2008-02-04 15:28:09 +08:00
|
|
|
(ulong)images->legacy_hdr_os);
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
image_multi_getimg(images->legacy_hdr_os, 1, &rd_data, &rd_len);
|
2008-01-31 20:55:39 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* no initrd image
|
|
|
|
*/
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_mark(BOOTSTAGE_ID_NO_RAMDISK);
|
2008-01-31 20:55:39 +08:00
|
|
|
rd_len = rd_data = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rd_data) {
|
2011-10-18 19:11:49 +08:00
|
|
|
debug("## No init Ramdisk\n");
|
2008-01-31 20:55:39 +08:00
|
|
|
} else {
|
|
|
|
*rd_start = rd_data;
|
|
|
|
*rd_end = rd_data + rd_len;
|
|
|
|
}
|
2011-10-18 19:11:49 +08:00
|
|
|
debug(" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
|
2008-01-31 20:55:39 +08:00
|
|
|
*rd_start, *rd_end);
|
2008-02-28 11:51:46 +08:00
|
|
|
|
|
|
|
return 0;
|
2008-01-31 20:55:39 +08:00
|
|
|
}
|
2008-01-31 20:57:17 +08:00
|
|
|
|
2010-10-14 03:57:35 +08:00
|
|
|
#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
|
2008-01-31 20:57:17 +08:00
|
|
|
/**
|
2008-02-29 21:58:34 +08:00
|
|
|
* boot_ramdisk_high - relocate init ramdisk
|
2008-02-28 11:51:49 +08:00
|
|
|
* @lmb: pointer to lmb handle, will be used for memory mgmt
|
2008-01-31 20:57:17 +08:00
|
|
|
* @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)
|
|
|
|
*
|
2013-09-16 19:15:45 +08:00
|
|
|
* boot_ramdisk_high() takes a relocation hint from "initrd_high" environment
|
2008-01-31 20:57:17 +08:00
|
|
|
* variable and if requested ramdisk data is moved to a specified location.
|
|
|
|
*
|
2008-02-29 21:58:34 +08:00
|
|
|
* 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.
|
|
|
|
*
|
2008-01-31 20:57:17 +08:00
|
|
|
* returns:
|
2008-02-29 21:58:34 +08:00
|
|
|
* 0 - success
|
|
|
|
* -1 - failure
|
2008-01-31 20:57:17 +08:00
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
int boot_ramdisk_high(struct lmb *lmb, ulong rd_data, ulong rd_len,
|
2008-02-28 11:51:49 +08:00
|
|
|
ulong *initrd_start, ulong *initrd_end)
|
2008-01-31 20:57:17 +08:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
ulong initrd_high;
|
|
|
|
int initrd_copy_to_ram = 1;
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
if ((s = getenv("initrd_high")) != NULL) {
|
2008-01-31 20:57:17 +08:00
|
|
|
/* a value of "no" or a similar string will act like 0,
|
|
|
|
* turning the "load high" feature off. This is intentional.
|
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
initrd_high = simple_strtoul(s, NULL, 16);
|
2008-01-31 20:57:17 +08:00
|
|
|
if (initrd_high == ~0)
|
|
|
|
initrd_copy_to_ram = 0;
|
|
|
|
} else {
|
|
|
|
/* not set, no restrictions to load high */
|
|
|
|
initrd_high = ~0;
|
|
|
|
}
|
|
|
|
|
2008-05-13 21:53:29 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_LOGBUFFER
|
|
|
|
/* Prevent initrd from overwriting logbuffer */
|
|
|
|
lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
|
|
|
|
#endif
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
debug("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
|
2008-01-31 20:57:17 +08:00
|
|
|
initrd_high, initrd_copy_to_ram);
|
|
|
|
|
|
|
|
if (rd_data) {
|
|
|
|
if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
|
2011-10-18 19:11:49 +08:00
|
|
|
debug(" in-place initrd\n");
|
2008-01-31 20:57:17 +08:00
|
|
|
*initrd_start = rd_data;
|
|
|
|
*initrd_end = rd_data + rd_len;
|
2008-02-28 11:51:49 +08:00
|
|
|
lmb_reserve(lmb, rd_data, rd_len);
|
2008-01-31 20:57:17 +08:00
|
|
|
} else {
|
2008-02-28 11:51:49 +08:00
|
|
|
if (initrd_high)
|
2011-10-18 19:11:49 +08:00
|
|
|
*initrd_start = (ulong)lmb_alloc_base(lmb,
|
|
|
|
rd_len, 0x1000, initrd_high);
|
2008-02-28 11:51:49 +08:00
|
|
|
else
|
2011-10-18 19:11:49 +08:00
|
|
|
*initrd_start = (ulong)lmb_alloc(lmb, rd_len,
|
|
|
|
0x1000);
|
2008-02-28 11:51:49 +08:00
|
|
|
|
|
|
|
if (*initrd_start == 0) {
|
2011-10-18 19:11:49 +08:00
|
|
|
puts("ramdisk - allocation error\n");
|
2008-02-28 11:51:49 +08:00
|
|
|
goto error;
|
2008-01-31 20:57:17 +08:00
|
|
|
}
|
2012-02-13 21:51:18 +08:00
|
|
|
bootstage_mark(BOOTSTAGE_ID_COPY_RAMDISK);
|
2008-01-31 20:57:17 +08:00
|
|
|
|
|
|
|
*initrd_end = *initrd_start + rd_len;
|
2011-10-18 19:11:49 +08:00
|
|
|
printf(" Loading Ramdisk to %08lx, end %08lx ... ",
|
2008-01-31 20:57:17 +08:00
|
|
|
*initrd_start, *initrd_end);
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
memmove_wd((void *)*initrd_start,
|
2008-01-31 20:57:17 +08:00
|
|
|
(void *)rd_data, rd_len, CHUNKSZ);
|
|
|
|
|
2011-12-07 12:42:58 +08:00
|
|
|
#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
|
2011-10-18 19:11:49 +08:00
|
|
|
puts("OK\n");
|
2008-01-31 20:57:17 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*initrd_start = 0;
|
|
|
|
*initrd_end = 0;
|
|
|
|
}
|
2011-10-18 19:11:49 +08:00
|
|
|
debug(" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
|
2008-01-31 20:57:17 +08:00
|
|
|
*initrd_start, *initrd_end);
|
2008-02-29 21:58:34 +08:00
|
|
|
|
2008-02-28 11:51:49 +08:00
|
|
|
return 0;
|
2008-01-31 20:58:13 +08:00
|
|
|
|
2008-02-28 11:51:49 +08:00
|
|
|
error:
|
|
|
|
return -1;
|
2008-01-31 20:58:13 +08:00
|
|
|
}
|
2010-10-14 03:57:35 +08:00
|
|
|
#endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
|
2008-01-31 20:58:13 +08:00
|
|
|
|
2010-10-14 03:57:35 +08:00
|
|
|
#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
|
2008-01-31 20:58:13 +08:00
|
|
|
/**
|
2008-02-29 21:58:34 +08:00
|
|
|
* boot_get_cmdline - allocate and initialize kernel cmdline
|
2008-02-28 11:51:49 +08:00
|
|
|
* @lmb: pointer to lmb handle, will be used for memory mgmt
|
2008-01-31 20:58:13 +08:00
|
|
|
* @cmd_start: pointer to a ulong variable, will hold cmdline start
|
|
|
|
* @cmd_end: pointer to a ulong variable, will hold cmdline end
|
|
|
|
*
|
2008-02-29 21:58:34 +08:00
|
|
|
* boot_get_cmdline() allocates space for kernel command line below
|
2011-03-28 17:58:34 +08:00
|
|
|
* BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt
|
2008-01-31 20:58:13 +08:00
|
|
|
* variable is present its contents is copied to allocated kernel
|
|
|
|
* command line.
|
|
|
|
*
|
|
|
|
* returns:
|
2008-02-28 11:51:49 +08:00
|
|
|
* 0 - success
|
|
|
|
* -1 - failure
|
2008-01-31 20:58:13 +08:00
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
int boot_get_cmdline(struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
|
2008-01-31 20:58:13 +08:00
|
|
|
{
|
|
|
|
char *cmdline;
|
|
|
|
char *s;
|
|
|
|
|
2008-10-16 21:01:15 +08:00
|
|
|
cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
|
2011-03-28 17:58:43 +08:00
|
|
|
getenv_bootm_mapsize() + getenv_bootm_low());
|
2008-02-28 11:51:49 +08:00
|
|
|
|
|
|
|
if (cmdline == NULL)
|
|
|
|
return -1;
|
2008-01-31 20:58:13 +08:00
|
|
|
|
|
|
|
if ((s = getenv("bootargs")) == NULL)
|
|
|
|
s = "";
|
|
|
|
|
|
|
|
strcpy(cmdline, s);
|
|
|
|
|
|
|
|
*cmd_start = (ulong) & cmdline[0];
|
|
|
|
*cmd_end = *cmd_start + strlen(cmdline);
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
debug("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
|
2008-01-31 20:58:13 +08:00
|
|
|
|
2008-02-28 11:51:49 +08:00
|
|
|
return 0;
|
2008-01-31 20:58:13 +08:00
|
|
|
}
|
2010-10-14 03:57:35 +08:00
|
|
|
#endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
|
2008-01-31 20:58:13 +08:00
|
|
|
|
2010-10-14 03:57:35 +08:00
|
|
|
#ifdef CONFIG_SYS_BOOT_GET_KBD
|
2008-01-31 20:58:13 +08:00
|
|
|
/**
|
2008-02-29 21:58:34 +08:00
|
|
|
* boot_get_kbd - allocate and initialize kernel copy of board info
|
2008-02-28 11:51:49 +08:00
|
|
|
* @lmb: pointer to lmb handle, will be used for memory mgmt
|
2008-01-31 20:58:13 +08:00
|
|
|
* @kbd: double pointer to board info data
|
|
|
|
*
|
2008-02-29 21:58:34 +08:00
|
|
|
* boot_get_kbd() allocates space for kernel copy of board info data below
|
2011-03-28 17:58:34 +08:00
|
|
|
* BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized
|
|
|
|
* with the current u-boot board info data.
|
2008-01-31 20:58:13 +08:00
|
|
|
*
|
|
|
|
* returns:
|
2008-02-28 11:51:49 +08:00
|
|
|
* 0 - success
|
|
|
|
* -1 - failure
|
2008-01-31 20:58:13 +08:00
|
|
|
*/
|
2011-10-18 19:11:49 +08:00
|
|
|
int boot_get_kbd(struct lmb *lmb, bd_t **kbd)
|
2008-01-31 20:58:13 +08:00
|
|
|
{
|
2008-06-10 09:37:18 +08:00
|
|
|
*kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
|
2011-03-28 17:58:43 +08:00
|
|
|
getenv_bootm_mapsize() + getenv_bootm_low());
|
2008-02-28 11:51:49 +08:00
|
|
|
if (*kbd == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2008-01-31 20:58:13 +08:00
|
|
|
**kbd = *(gd->bd);
|
|
|
|
|
2011-10-18 19:11:49 +08:00
|
|
|
debug("## kernel board info at 0x%08lx\n", (ulong)*kbd);
|
2008-01-31 20:58:13 +08:00
|
|
|
|
|
|
|
#if defined(DEBUG) && defined(CONFIG_CMD_BDI)
|
|
|
|
do_bdinfo(NULL, 0, 0, NULL);
|
|
|
|
#endif
|
|
|
|
|
2008-02-28 11:51:49 +08:00
|
|
|
return 0;
|
2008-01-31 20:57:17 +08:00
|
|
|
}
|
2010-10-14 03:57:35 +08:00
|
|
|
#endif /* CONFIG_SYS_BOOT_GET_KBD */
|
2013-05-08 16:06:01 +08:00
|
|
|
|
|
|
|
#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 */
|
2008-03-01 04:24:06 +08:00
|
|
|
#endif /* !USE_HOSTCC */
|