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