2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-01-08 17:14:09 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2008 Semihalf
|
|
|
|
*
|
|
|
|
* (C) Copyright 2000-2006
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
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>
|
2020-05-10 17:40:00 +00:00
|
|
|
#include <bootstage.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2019-08-01 15:46:52 +00:00
|
|
|
#include <env.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <lmb.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2019-11-14 19:57:16 +00:00
|
|
|
#include <u-boot/crc.h>
|
2008-01-31 12:55:39 +00:00
|
|
|
#include <watchdog.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_SHOW_BOOT_PROGRESS
|
|
|
|
#include <status_led.h>
|
|
|
|
#endif
|
|
|
|
|
2008-02-21 16:27:41 +00:00
|
|
|
#include <rtc.h>
|
|
|
|
|
2019-08-01 15:46:36 +00:00
|
|
|
#include <gzip.h>
|
2008-02-29 20:24:06 +00:00
|
|
|
#include <image.h>
|
2019-11-14 19:57:25 +00:00
|
|
|
#include <lz4.h>
|
2015-03-22 22:08:59 +00:00
|
|
|
#include <mapmem.h>
|
2008-02-29 20:24:06 +00:00
|
|
|
|
2016-02-23 05:55:45 +00:00
|
|
|
#if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2008-02-21 16:20:19 +00:00
|
|
|
#include <fdt_support.h>
|
2016-05-17 12:03:50 +00:00
|
|
|
#include <fpga.h>
|
|
|
|
#include <xilinx.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>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2013-05-07 06:12:03 +00:00
|
|
|
#include <asm/io.h>
|
2008-03-12 09:12:37 +00:00
|
|
|
|
2019-07-25 02:37:54 +00:00
|
|
|
#include <bzlib.h>
|
|
|
|
#include <linux/lzo.h>
|
|
|
|
#include <lzma/LzmaTypes.h>
|
|
|
|
#include <lzma/LzmaDec.h>
|
|
|
|
#include <lzma/LzmaTools.h>
|
2020-04-25 17:37:21 +00:00
|
|
|
#include <linux/zstd.h>
|
2019-07-25 02:37:54 +00:00
|
|
|
|
2008-01-31 12:58:13 +00:00
|
|
|
#ifdef CONFIG_CMD_BDI
|
2020-05-10 17:40:03 +00:00
|
|
|
extern int do_bdinfo(struct cmd_tbl *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
|
|
|
|
2019-05-23 11:14:07 +00:00
|
|
|
#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
|
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>
|
2019-09-23 18:39:47 +00:00
|
|
|
#include <imximage.h>
|
2013-02-24 17:33:25 +00:00
|
|
|
|
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[] = {
|
2016-06-30 16:52:15 +00:00
|
|
|
{ IH_ARCH_INVALID, "invalid", "Invalid ARCH", },
|
2008-02-29 14:59:59 +00:00
|
|
|
{ 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", },
|
2016-08-10 15:36:43 +00:00
|
|
|
{ IH_ARCH_XTENSA, "xtensa", "Xtensa", },
|
2018-03-13 05:37:29 +00:00
|
|
|
{ IH_ARCH_RISCV, "riscv", "RISC-V", },
|
2008-02-29 14:59:59 +00:00
|
|
|
{ -1, "", "", },
|
|
|
|
};
|
|
|
|
|
2010-10-20 11:17:39 +00:00
|
|
|
static const table_entry_t uimage_os[] = {
|
2016-06-30 16:52:15 +00:00
|
|
|
{ IH_OS_INVALID, "invalid", "Invalid OS", },
|
2017-09-13 19:29:29 +00:00
|
|
|
{ IH_OS_ARM_TRUSTED_FIRMWARE, "arm-trusted-firmware", "ARM Trusted Firmware" },
|
2008-02-29 14:59:59 +00:00
|
|
|
{ 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", },
|
2018-03-13 16:50:35 +00:00
|
|
|
{ IH_OS_TEE, "tee", "Trusted Execution Environment" },
|
2008-02-29 14:59:59 +00:00
|
|
|
{ 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
|
2019-08-21 19:14:44 +00:00
|
|
|
{ IH_OS_OPENSBI, "opensbi", "RISC-V OpenSBI", },
|
2019-12-24 16:05:38 +00:00
|
|
|
{ IH_OS_EFI, "efi", "EFI Firmware" },
|
2014-12-16 13:07:21 +00:00
|
|
|
|
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",},
|
2018-10-16 04:50:30 +00:00
|
|
|
{ IH_TYPE_IMX8IMAGE, "imx8image", "NXP i.MX8 Boot Image",},
|
2018-11-20 10:19:36 +00:00
|
|
|
{ IH_TYPE_IMX8MIMAGE, "imx8mimage", "NXP i.MX8M Boot Image",},
|
2016-06-30 16:52:15 +00:00
|
|
|
{ IH_TYPE_INVALID, "invalid", "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", },
|
2018-04-15 11:15:33 +00:00
|
|
|
{ IH_TYPE_SOCFPGAIMAGE, "socfpgaimage", "Altera SoCFPGA CV/AV preloader",},
|
|
|
|
{ IH_TYPE_SOCFPGAIMAGE_V1, "socfpgaimage_v1", "Altera SoCFPGA A10 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" },
|
2016-09-26 07:08:06 +00:00
|
|
|
{ IH_TYPE_VYBRIDIMAGE, "vybridimage", "Vybrid Boot Image", },
|
2015-11-17 12:56:56 +00:00
|
|
|
{ IH_TYPE_ZYNQIMAGE, "zynqimage", "Xilinx Zynq Boot Image" },
|
2016-04-27 12:03:29 +00:00
|
|
|
{ IH_TYPE_ZYNQMPIMAGE, "zynqmpimage", "Xilinx ZynqMP Boot Image" },
|
2018-04-13 12:18:52 +00:00
|
|
|
{ IH_TYPE_ZYNQMPBIF, "zynqmpbif", "Xilinx ZynqMP Boot Image (bif)" },
|
2016-05-17 11:58:44 +00:00
|
|
|
{ IH_TYPE_FPGA, "fpga", "FPGA Image" },
|
2016-11-29 22:33:21 +00:00
|
|
|
{ IH_TYPE_TEE, "tee", "Trusted Execution Environment Image",},
|
2016-11-06 15:37:56 +00:00
|
|
|
{ IH_TYPE_FIRMWARE_IVT, "firmware_ivt", "Firmware with HABv4 IVT" },
|
2017-07-31 15:58:20 +00:00
|
|
|
{ IH_TYPE_PMMC, "pmmc", "TI Power Management Micro-Controller Firmware",},
|
2018-03-12 09:46:04 +00:00
|
|
|
{ IH_TYPE_STM32IMAGE, "stm32image", "STMicroelectronics STM32 Image" },
|
2018-11-15 02:07:49 +00:00
|
|
|
{ IH_TYPE_MTKIMAGE, "mtk_image", "MediaTek BootROM loadable Image" },
|
2019-08-02 13:07:19 +00:00
|
|
|
{ IH_TYPE_COPRO, "copro", "Coprocessor 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", },
|
2015-10-07 03:03:53 +00:00
|
|
|
{ IH_COMP_LZ4, "lz4", "lz4 compressed", },
|
2020-04-25 17:37:21 +00:00
|
|
|
{ IH_COMP_ZSTD, "zstd", "zstd compressed", },
|
2008-02-29 14:59:59 +00:00
|
|
|
{ -1, "", "", },
|
|
|
|
};
|
|
|
|
|
2016-06-30 16:52:14 +00:00
|
|
|
struct table_info {
|
|
|
|
const char *desc;
|
|
|
|
int count;
|
|
|
|
const table_entry_t *table;
|
|
|
|
};
|
|
|
|
|
2020-03-06 00:24:22 +00:00
|
|
|
static const struct comp_magic_map image_comp[] = {
|
|
|
|
{ IH_COMP_BZIP2, "bzip2", {0x42, 0x5a},},
|
|
|
|
{ IH_COMP_GZIP, "gzip", {0x1f, 0x8b},},
|
|
|
|
{ IH_COMP_LZMA, "lzma", {0x5d, 0x00},},
|
|
|
|
{ IH_COMP_LZO, "lzo", {0x89, 0x4c},},
|
|
|
|
{ IH_COMP_NONE, "none", {}, },
|
|
|
|
};
|
|
|
|
|
2016-06-30 16:52:14 +00:00
|
|
|
static const struct table_info table_info[IH_COUNT] = {
|
|
|
|
{ "architecture", IH_ARCH_COUNT, uimage_arch },
|
|
|
|
{ "compression", IH_COMP_COUNT, uimage_comp },
|
|
|
|
{ "operating system", IH_OS_COUNT, uimage_os },
|
|
|
|
{ "image type", IH_TYPE_COUNT, uimage_type },
|
|
|
|
};
|
|
|
|
|
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
|
|
|
}
|
2016-11-06 15:37:56 +00:00
|
|
|
} else if (image_check_type(hdr, IH_TYPE_FIRMWARE_IVT)) {
|
|
|
|
printf("HAB Blocks: 0x%08x 0x0000 0x%08x\n",
|
2019-09-23 18:39:47 +00:00
|
|
|
image_get_load(hdr) - image_get_header_size(),
|
|
|
|
(int)(image_get_size(hdr) + image_get_header_size()
|
|
|
|
+ sizeof(flash_header_v2_t) - 0x2060));
|
2008-02-29 13:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 02:37:54 +00:00
|
|
|
/**
|
|
|
|
* print_decomp_msg() - Print a suitable decompression/loading message
|
|
|
|
*
|
|
|
|
* @type: OS type (IH_OS_...)
|
|
|
|
* @comp_type: Compression type being used (IH_COMP_...)
|
|
|
|
* @is_xip: true if the load address matches the image start
|
|
|
|
*/
|
|
|
|
static void print_decomp_msg(int comp_type, int type, bool is_xip)
|
|
|
|
{
|
|
|
|
const char *name = genimg_get_type_name(type);
|
|
|
|
|
|
|
|
if (comp_type == IH_COMP_NONE)
|
|
|
|
printf(" %s %s\n", is_xip ? "XIP" : "Loading", name);
|
|
|
|
else
|
|
|
|
printf(" Uncompressing %s\n", name);
|
|
|
|
}
|
|
|
|
|
2020-03-06 00:24:22 +00:00
|
|
|
int image_decomp_type(const unsigned char *buf, ulong len)
|
|
|
|
{
|
|
|
|
const struct comp_magic_map *cmagic = image_comp;
|
|
|
|
|
|
|
|
if (len < 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (; cmagic->comp_id > 0; cmagic++) {
|
|
|
|
if (!memcmp(buf, cmagic->magic, 2))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmagic->comp_id;
|
|
|
|
}
|
|
|
|
|
2019-07-25 02:37:54 +00:00
|
|
|
int image_decomp(int comp, ulong load, ulong image_start, int type,
|
|
|
|
void *load_buf, void *image_buf, ulong image_len,
|
|
|
|
uint unc_len, ulong *load_end)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
*load_end = load;
|
|
|
|
print_decomp_msg(comp, type, load == image_start);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the image to the right place, decompressing if needed. After
|
|
|
|
* this, image_len will be set to the number of uncompressed bytes
|
|
|
|
* loaded, ret will be non-zero on error.
|
|
|
|
*/
|
|
|
|
switch (comp) {
|
|
|
|
case IH_COMP_NONE:
|
|
|
|
if (load == image_start)
|
|
|
|
break;
|
|
|
|
if (image_len <= unc_len)
|
|
|
|
memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
|
|
|
|
else
|
|
|
|
ret = -ENOSPC;
|
|
|
|
break;
|
|
|
|
#ifdef CONFIG_GZIP
|
|
|
|
case IH_COMP_GZIP: {
|
|
|
|
ret = gunzip(load_buf, unc_len, image_buf, &image_len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_GZIP */
|
|
|
|
#ifdef CONFIG_BZIP2
|
|
|
|
case IH_COMP_BZIP2: {
|
|
|
|
uint size = unc_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we've got less than 4 MB of malloc() space,
|
|
|
|
* use slower decompression algorithm which requires
|
|
|
|
* at most 2300 KB of memory.
|
|
|
|
*/
|
|
|
|
ret = BZ2_bzBuffToBuffDecompress(load_buf, &size,
|
|
|
|
image_buf, image_len,
|
|
|
|
CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
|
|
|
|
image_len = size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_BZIP2 */
|
|
|
|
#ifdef CONFIG_LZMA
|
|
|
|
case IH_COMP_LZMA: {
|
|
|
|
SizeT lzma_len = unc_len;
|
|
|
|
|
|
|
|
ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
|
|
|
|
image_buf, image_len);
|
|
|
|
image_len = lzma_len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_LZMA */
|
|
|
|
#ifdef CONFIG_LZO
|
|
|
|
case IH_COMP_LZO: {
|
|
|
|
size_t size = unc_len;
|
|
|
|
|
|
|
|
ret = lzop_decompress(image_buf, image_len, load_buf, &size);
|
|
|
|
image_len = size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_LZO */
|
|
|
|
#ifdef CONFIG_LZ4
|
|
|
|
case IH_COMP_LZ4: {
|
|
|
|
size_t size = unc_len;
|
|
|
|
|
|
|
|
ret = ulz4fn(image_buf, image_len, load_buf, &size);
|
|
|
|
image_len = size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_LZ4 */
|
2020-04-25 17:37:21 +00:00
|
|
|
#ifdef CONFIG_ZSTD
|
|
|
|
case IH_COMP_ZSTD: {
|
|
|
|
size_t size = unc_len;
|
|
|
|
ZSTD_DStream *dstream;
|
|
|
|
ZSTD_inBuffer in_buf;
|
|
|
|
ZSTD_outBuffer out_buf;
|
|
|
|
void *workspace;
|
|
|
|
size_t wsize;
|
|
|
|
|
|
|
|
wsize = ZSTD_DStreamWorkspaceBound(image_len);
|
|
|
|
workspace = malloc(wsize);
|
|
|
|
if (!workspace) {
|
|
|
|
debug("%s: cannot allocate workspace of size %zu\n", __func__,
|
|
|
|
wsize);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dstream = ZSTD_initDStream(image_len, workspace, wsize);
|
|
|
|
if (!dstream) {
|
|
|
|
printf("%s: ZSTD_initDStream failed\n", __func__);
|
|
|
|
return ZSTD_getErrorCode(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
in_buf.src = image_buf;
|
|
|
|
in_buf.pos = 0;
|
|
|
|
in_buf.size = image_len;
|
|
|
|
|
|
|
|
out_buf.dst = load_buf;
|
|
|
|
out_buf.pos = 0;
|
|
|
|
out_buf.size = size;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
size_t ret;
|
|
|
|
|
|
|
|
ret = ZSTD_decompressStream(dstream, &out_buf, &in_buf);
|
|
|
|
if (ZSTD_isError(ret)) {
|
|
|
|
printf("%s: ZSTD_decompressStream error %d\n", __func__,
|
|
|
|
ZSTD_getErrorCode(ret));
|
|
|
|
return ZSTD_getErrorCode(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_buf.pos >= image_len || !ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
image_len = out_buf.pos;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ZSTD */
|
2019-07-25 02:37:54 +00:00
|
|
|
default:
|
|
|
|
printf("Unimplemented compression type %d\n", comp);
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
*load_end = load + image_len;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-02-29 14:59:59 +00:00
|
|
|
|
|
|
|
#ifndef USE_HOSTCC
|
2019-05-23 11:14:07 +00:00
|
|
|
#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
|
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.
|
|
|
|
*
|
|
|
|
* 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
|
2019-12-28 17:45:02 +00:00
|
|
|
ulong image_load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
|
|
|
|
ulong image_save_addr; /* Default Save Address */
|
|
|
|
ulong image_save_size; /* Default Save Size (in bytes) */
|
2012-12-12 04:16:28 +00:00
|
|
|
|
|
|
|
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:
|
2019-12-28 17:45:02 +00:00
|
|
|
image_load_addr = simple_strtoul(value, NULL, 16);
|
2012-12-12 04:16:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
U_BOOT_ENV_CALLBACK(loadaddr, on_loadaddr);
|
|
|
|
|
2017-08-03 18:22:15 +00:00
|
|
|
ulong env_get_bootm_low(void)
|
2008-02-29 13:58:34 +00:00
|
|
|
{
|
2017-08-03 18:22:12 +00:00
|
|
|
char *s = env_get("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;
|
2019-09-25 07:11:48 +00:00
|
|
|
#elif defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE)
|
2008-03-12 11:14:15 +00:00
|
|
|
return gd->bd->bi_dram[0].start;
|
2008-02-29 13:58:34 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:22:15 +00:00
|
|
|
phys_size_t env_get_bootm_size(void)
|
2008-02-29 13:58:34 +00:00
|
|
|
{
|
2016-02-05 07:12:50 +00:00
|
|
|
phys_size_t tmp, size;
|
|
|
|
phys_addr_t start;
|
2017-08-03 18:22:12 +00:00
|
|
|
char *s = env_get("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;
|
|
|
|
}
|
2016-02-05 07:12:50 +00:00
|
|
|
|
2020-08-12 10:57:18 +00:00
|
|
|
start = gd->ram_base;
|
|
|
|
size = gd->ram_size;
|
2016-02-05 07:12:50 +00:00
|
|
|
|
2020-08-24 17:14:05 +00:00
|
|
|
if (start + size > gd->ram_top)
|
|
|
|
size = gd->ram_top - start;
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
s = env_get("bootm_low");
|
2010-07-08 15:11:08 +00:00
|
|
|
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
|
2016-02-05 07:12:50 +00:00
|
|
|
tmp = start;
|
2008-02-29 13:58:34 +00:00
|
|
|
|
2016-02-05 07:12:50 +00:00
|
|
|
return size - (tmp - start);
|
2008-02-29 13:58:34 +00:00
|
|
|
}
|
|
|
|
|
2017-08-03 18:22:15 +00:00
|
|
|
phys_size_t env_get_bootm_mapsize(void)
|
2011-03-28 09:58:43 +00:00
|
|
|
{
|
|
|
|
phys_size_t tmp;
|
2017-08-03 18:22:12 +00:00
|
|
|
char *s = env_get("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
|
2017-08-03 18:22:15 +00:00
|
|
|
return env_get_bootm_size();
|
2011-03-28 09:58:43 +00:00
|
|
|
#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 */
|
|
|
|
}
|
2019-07-25 02:37:54 +00:00
|
|
|
#else /* USE_HOSTCC */
|
|
|
|
void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
|
|
|
|
{
|
|
|
|
memmove(to, from, len);
|
|
|
|
}
|
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
|
2017-01-04 13:04:44 +00:00
|
|
|
printf("%d Bytes = %.2f KiB = %.2f MiB\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;
|
|
|
|
}
|
|
|
|
|
2016-06-30 16:52:16 +00:00
|
|
|
static const char *unknown_msg(enum ih_category category)
|
|
|
|
{
|
2016-10-31 16:21:09 +00:00
|
|
|
static const char unknown_str[] = "Unknown ";
|
2016-06-30 16:52:16 +00:00
|
|
|
static char msg[30];
|
|
|
|
|
2016-10-31 16:21:09 +00:00
|
|
|
strcpy(msg, unknown_str);
|
|
|
|
strncat(msg, table_info[category].desc,
|
|
|
|
sizeof(msg) - sizeof(unknown_str));
|
2016-06-30 16:52:16 +00:00
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-07 02:22:24 +00:00
|
|
|
* genimg_get_cat_name - translate entry id to long name
|
2016-06-30 16:52:16 +00:00
|
|
|
* @category: category to look up (enum ih_category)
|
|
|
|
* @id: entry id to be translated
|
|
|
|
*
|
|
|
|
* This will scan the translation table trying to find the entry that matches
|
|
|
|
* the given id.
|
|
|
|
*
|
2020-10-07 02:22:24 +00:00
|
|
|
* @return long entry name if translation succeeds; error string on failure
|
2016-06-30 16:52:16 +00:00
|
|
|
*/
|
|
|
|
const char *genimg_get_cat_name(enum ih_category category, uint id)
|
|
|
|
{
|
|
|
|
const table_entry_t *entry;
|
|
|
|
|
|
|
|
entry = get_table_entry(table_info[category].table, id);
|
|
|
|
if (!entry)
|
|
|
|
return unknown_msg(category);
|
|
|
|
#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
|
|
|
|
return entry->lname;
|
|
|
|
#else
|
|
|
|
return entry->lname + gd->reloc_off;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-07 02:22:24 +00:00
|
|
|
* genimg_get_cat_short_name - translate entry id to short name
|
2016-06-30 16:52:16 +00:00
|
|
|
* @category: category to look up (enum ih_category)
|
|
|
|
* @id: entry id to be translated
|
|
|
|
*
|
|
|
|
* This will scan the translation table trying to find the entry that matches
|
|
|
|
* the given id.
|
|
|
|
*
|
2020-10-07 02:22:24 +00:00
|
|
|
* @return short entry name if translation succeeds; error string on failure
|
2016-06-30 16:52:16 +00:00
|
|
|
*/
|
|
|
|
const char *genimg_get_cat_short_name(enum ih_category category, uint id)
|
|
|
|
{
|
|
|
|
const table_entry_t *entry;
|
|
|
|
|
|
|
|
entry = get_table_entry(table_info[category].table, id);
|
|
|
|
if (!entry)
|
|
|
|
return unknown_msg(category);
|
|
|
|
#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
|
|
|
|
return entry->sname;
|
|
|
|
#else
|
|
|
|
return entry->sname + gd->reloc_off;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int genimg_get_cat_count(enum ih_category category)
|
|
|
|
{
|
|
|
|
return table_info[category].count;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *genimg_get_cat_desc(enum ih_category category)
|
|
|
|
{
|
|
|
|
return table_info[category].desc;
|
|
|
|
}
|
|
|
|
|
2020-10-07 02:21:25 +00:00
|
|
|
/**
|
|
|
|
* genimg_cat_has_id - check whether category has entry id
|
|
|
|
* @category: category to look up (enum ih_category)
|
|
|
|
* @id: entry id to be checked
|
|
|
|
*
|
|
|
|
* This will scan the translation table trying to find the entry that matches
|
|
|
|
* the given id.
|
|
|
|
*
|
|
|
|
* @return true if category has entry id; false if not
|
|
|
|
*/
|
|
|
|
bool genimg_cat_has_id(enum ih_category category, uint id)
|
|
|
|
{
|
|
|
|
if (get_table_entry(table_info[category].table, id))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-10-07 02:22:24 +00:00
|
|
|
const char *genimg_get_comp_name(uint8_t comp)
|
|
|
|
{
|
|
|
|
return (get_table_entry_name(uimage_comp, "Unknown Compression",
|
|
|
|
comp));
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:55:50 +00:00
|
|
|
static const char *genimg_get_short_name(const table_entry_t *table, int val)
|
2015-06-23 21:38:25 +00:00
|
|
|
{
|
2016-02-23 05:55:50 +00:00
|
|
|
table = get_table_entry(table, val);
|
2015-06-23 21:38:25 +00:00
|
|
|
if (!table)
|
|
|
|
return "unknown";
|
|
|
|
#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
|
|
|
|
return table->sname;
|
|
|
|
#else
|
|
|
|
return table->sname + gd->reloc_off;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:55:50 +00:00
|
|
|
const char *genimg_get_type_short_name(uint8_t type)
|
|
|
|
{
|
|
|
|
return genimg_get_short_name(uimage_type, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *genimg_get_comp_short_name(uint8_t comp)
|
|
|
|
{
|
|
|
|
return genimg_get_short_name(uimage_comp, comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *genimg_get_os_short_name(uint8_t os)
|
|
|
|
{
|
|
|
|
return genimg_get_short_name(uimage_os, os);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *genimg_get_arch_short_name(uint8_t arch)
|
|
|
|
{
|
|
|
|
return genimg_get_short_name(uimage_arch, arch);
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-12-28 17:45:02 +00:00
|
|
|
kernel_addr = image_load_addr;
|
2014-08-01 00:39:58 +00:00
|
|
|
debug("* kernel: default image load address = 0x%08lx\n",
|
2019-12-28 17:45:02 +00:00
|
|
|
image_load_addr);
|
2016-02-23 05:55:43 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FIT)
|
2019-12-28 17:45:02 +00:00
|
|
|
} else if (fit_parse_conf(img_addr, image_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);
|
2019-12-28 17:45:02 +00:00
|
|
|
} else if (fit_parse_subimage(img_addr, image_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
|
|
|
{
|
2019-05-23 11:14:07 +00:00
|
|
|
#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
|
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
|
2016-02-23 05:55:45 +00:00
|
|
|
#if IMAGE_ENABLE_FIT || IMAGE_ENABLE_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-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
|
|
|
{
|
2016-02-23 05:55:43 +00:00
|
|
|
#if IMAGE_ENABLE_FIT
|
2008-03-12 09:35:46 +00:00
|
|
|
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
|
|
|
|
*/
|
2020-05-10 17:40:03 +00:00
|
|
|
int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
|
|
|
|
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;
|
2019-05-23 11:14:07 +00:00
|
|
|
#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
|
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
|
2016-02-23 05:55:43 +00:00
|
|
|
#if IMAGE_ENABLE_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;
|
|
|
|
|
2015-08-27 19:42:41 +00:00
|
|
|
#ifdef CONFIG_ANDROID_BOOT_IMAGE
|
|
|
|
/*
|
|
|
|
* Look for an Android boot image.
|
|
|
|
*/
|
|
|
|
buf = map_sysmem(images->os.start, 0);
|
2015-10-27 23:04:40 +00:00
|
|
|
if (buf && genimg_get_format(buf) == IMAGE_FORMAT_ANDROID)
|
2019-02-22 08:28:06 +00:00
|
|
|
select = (argc == 0) ? env_get("loadaddr") : argv[0];
|
2015-08-27 19:42:41 +00:00
|
|
|
#endif
|
|
|
|
|
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)) {
|
2016-02-23 05:55:43 +00:00
|
|
|
#if IMAGE_ENABLE_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
|
2019-12-28 17:45:02 +00:00
|
|
|
default_addr = image_load_addr;
|
2008-03-12 09:35:46 +00:00
|
|
|
|
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);
|
|
|
|
}
|
2016-02-23 05:55:43 +00:00
|
|
|
#if IMAGE_ENABLE_FIT
|
2008-03-12 09:35:46 +00:00
|
|
|
} 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);
|
2016-09-20 17:17:12 +00:00
|
|
|
if (rd_noffset == -ENOENT)
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)) {
|
2019-05-23 11:14:07 +00:00
|
|
|
#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
|
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
|
2016-02-23 05:55:43 +00:00
|
|
|
#if IMAGE_ENABLE_FIT
|
2008-02-04 07:28:09 +00:00
|
|
|
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;
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
s = env_get("initrd_high");
|
|
|
|
if (s) {
|
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 {
|
2017-08-03 18:22:15 +00:00
|
|
|
initrd_high = env_get_bootm_mapsize() + env_get_bootm_low();
|
2008-01-31 12:57:17 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 13:53:29 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2017-12-14 10:19:22 +00:00
|
|
|
flush_cache((unsigned long)*initrd_start,
|
|
|
|
ALIGN(rd_len, ARCH_DMA_MINALIGN));
|
2011-12-07 04:42:58 +00:00
|
|
|
#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)
|
|
|
|
{
|
2016-02-23 05:55:43 +00:00
|
|
|
#if IMAGE_ENABLE_FIT
|
2014-10-20 03:11:24 +00:00
|
|
|
return boot_get_setup_fit(images, arch, setup_start, setup_len);
|
|
|
|
#else
|
|
|
|
return -ENOENT;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-02-23 05:55:43 +00:00
|
|
|
#if IMAGE_ENABLE_FIT
|
2017-11-10 14:17:41 +00:00
|
|
|
#if defined(CONFIG_FPGA)
|
2020-05-10 17:40:03 +00:00
|
|
|
int boot_get_fpga(int argc, char *const argv[], bootm_headers_t *images,
|
2016-05-17 12:03:50 +00:00
|
|
|
uint8_t arch, const ulong *ld_start, ulong * const ld_len)
|
|
|
|
{
|
|
|
|
ulong tmp_img_addr, img_data, img_len;
|
|
|
|
void *buf;
|
|
|
|
int conf_noffset;
|
|
|
|
int fit_img_result;
|
2016-10-02 23:59:28 +00:00
|
|
|
const char *uname, *name;
|
2016-05-17 12:03:50 +00:00
|
|
|
int err;
|
|
|
|
int devnum = 0; /* TODO support multi fpga platforms */
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
tmp_img_addr = map_to_sysmem(images->fit_hdr_os);
|
|
|
|
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);
|
|
|
|
|
2016-10-02 23:59:28 +00:00
|
|
|
uname = fdt_stringlist_get(buf, conf_noffset, FIT_FPGA_PROP, 0,
|
|
|
|
NULL);
|
|
|
|
if (!uname) {
|
2016-05-17 12:03:50 +00:00
|
|
|
debug("## FPGA image is not specified\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fit_img_result = fit_image_load(images,
|
|
|
|
tmp_img_addr,
|
|
|
|
(const char **)&uname,
|
|
|
|
&(images->fit_uname_cfg),
|
|
|
|
arch,
|
|
|
|
IH_TYPE_FPGA,
|
|
|
|
BOOTSTAGE_ID_FPGA_INIT,
|
|
|
|
FIT_LOAD_OPTIONAL_NON_ZERO,
|
|
|
|
&img_data, &img_len);
|
|
|
|
|
|
|
|
debug("FPGA image (%s) loaded to 0x%lx/size 0x%lx\n",
|
|
|
|
uname, img_data, img_len);
|
|
|
|
|
|
|
|
if (fit_img_result < 0) {
|
|
|
|
/* Something went wrong! */
|
|
|
|
return fit_img_result;
|
|
|
|
}
|
|
|
|
|
2017-11-10 14:17:41 +00:00
|
|
|
if (!fpga_is_partial_data(devnum, img_len)) {
|
2016-05-17 12:03:50 +00:00
|
|
|
name = "full";
|
|
|
|
err = fpga_loadbitstream(devnum, (char *)img_data,
|
|
|
|
img_len, BIT_FULL);
|
|
|
|
if (err)
|
|
|
|
err = fpga_load(devnum, (const void *)img_data,
|
|
|
|
img_len, BIT_FULL);
|
|
|
|
} else {
|
|
|
|
name = "partial";
|
|
|
|
err = fpga_loadbitstream(devnum, (char *)img_data,
|
|
|
|
img_len, BIT_PARTIAL);
|
|
|
|
if (err)
|
|
|
|
err = fpga_load(devnum, (const void *)img_data,
|
|
|
|
img_len, BIT_PARTIAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err)
|
2016-12-16 09:35:40 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
printf(" Programming %s bitstream... OK\n", name);
|
2016-05-17 12:03:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("The given image format is not supported (corrupt?)\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-29 22:33:20 +00:00
|
|
|
static void fit_loadable_process(uint8_t img_type,
|
|
|
|
ulong img_data,
|
|
|
|
ulong img_len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const unsigned int count =
|
|
|
|
ll_entry_count(struct fit_loadable_tbl, fit_loadable);
|
|
|
|
struct fit_loadable_tbl *fit_loadable_handler =
|
|
|
|
ll_entry_start(struct fit_loadable_tbl, fit_loadable);
|
|
|
|
/* For each loadable handler */
|
|
|
|
for (i = 0; i < count; i++, fit_loadable_handler++)
|
|
|
|
/* matching this type */
|
|
|
|
if (fit_loadable_handler->type == img_type)
|
|
|
|
/* call that handler with this image data */
|
|
|
|
fit_loadable_handler->handler(img_data, img_len);
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images,
|
|
|
|
uint8_t arch, const ulong *ld_start, ulong * const ld_len)
|
2015-05-21 13:52:48 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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;
|
2016-10-02 23:59:28 +00:00
|
|
|
const char *uname;
|
2016-11-29 22:33:20 +00:00
|
|
|
uint8_t img_type;
|
2015-05-21 13:52:48 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
tmp_img_addr = map_to_sysmem(images->fit_hdr_os);
|
|
|
|
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;
|
2016-10-02 23:59:28 +00:00
|
|
|
uname = fdt_stringlist_get(buf, conf_noffset,
|
|
|
|
FIT_LOADABLE_PROP, loadables_index,
|
|
|
|
NULL), uname;
|
2015-05-21 13:52:48 +00:00
|
|
|
loadables_index++)
|
|
|
|
{
|
|
|
|
fit_img_result = fit_image_load(images,
|
|
|
|
tmp_img_addr,
|
2016-10-02 23:59:28 +00:00
|
|
|
&uname,
|
2015-05-21 13:52:48 +00:00
|
|
|
&(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;
|
|
|
|
}
|
2016-11-29 22:33:20 +00:00
|
|
|
|
|
|
|
fit_img_result = fit_image_get_node(buf, uname);
|
|
|
|
if (fit_img_result < 0) {
|
|
|
|
/* Something went wrong! */
|
|
|
|
return fit_img_result;
|
|
|
|
}
|
|
|
|
fit_img_result = fit_image_get_type(buf,
|
|
|
|
fit_img_result,
|
|
|
|
&img_type);
|
|
|
|
if (fit_img_result < 0) {
|
|
|
|
/* Something went wrong! */
|
|
|
|
return fit_img_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
fit_loadable_process(img_type, img_data, img_len);
|
2015-05-21 13:52:48 +00:00
|
|
|
}
|
|
|
|
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
|
2018-06-07 14:17:19 +00:00
|
|
|
* BOOTMAPSZ + env_get_bootm_low() address. If "bootargs" U-Boot environment
|
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,
|
2017-08-03 18:22:15 +00:00
|
|
|
env_get_bootm_mapsize() + env_get_bootm_low());
|
2008-02-28 03:51:49 +00:00
|
|
|
|
|
|
|
if (cmdline == NULL)
|
|
|
|
return -1;
|
2008-01-31 12:58:13 +00:00
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
s = env_get("bootargs");
|
|
|
|
if (!s)
|
2008-01-31 12:58:13 +00:00
|
|
|
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
|
2017-08-03 18:22:15 +00:00
|
|
|
* BOOTMAPSZ + env_get_bootm_low() address and kernel board info is initialized
|
2011-03-28 09:58:34 +00:00
|
|
|
* 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
|
|
|
*/
|
2020-06-26 06:13:33 +00:00
|
|
|
int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd)
|
2008-01-31 12:58:13 +00:00
|
|
|
{
|
2020-06-26 06:13:33 +00:00
|
|
|
*kbd = (struct bd_info *)(ulong)lmb_alloc_base(lmb,
|
|
|
|
sizeof(struct bd_info),
|
|
|
|
0xf,
|
|
|
|
env_get_bootm_mapsize() + env_get_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;
|
|
|
|
struct lmb *lmb = &images->lmb;
|
|
|
|
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_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 */
|