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>
|
2019-08-01 15:46:52 +00:00
|
|
|
#include <env.h>
|
2022-07-31 18:28:48 +00:00
|
|
|
#include <display_options.h>
|
2021-11-08 18:03:38 +00:00
|
|
|
#include <init.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>
|
2019-11-14 19:57:16 +00:00
|
|
|
#include <u-boot/crc.h>
|
2008-01-31 12:55:39 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SHOW_BOOT_PROGRESS
|
|
|
|
#include <status_led.h>
|
|
|
|
#endif
|
|
|
|
|
2021-09-26 01:43:21 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FIT) || CONFIG_IS_ENABLED(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>
|
2008-03-12 09:12:37 +00:00
|
|
|
#endif
|
|
|
|
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
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
|
|
|
|
2008-01-31 12:58:13 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2008-02-27 10:01:04 +00:00
|
|
|
|
2021-09-25 13:03:14 +00:00
|
|
|
/* Set this if we have less than 4 MB of malloc() space */
|
|
|
|
#if CONFIG_SYS_MALLOC_LEN < (4096 * 1024)
|
|
|
|
#define CONSERVE_MEMORY true
|
2008-01-08 17:14:09 +00:00
|
|
|
#else
|
2021-09-25 13:03:14 +00:00
|
|
|
#define CONSERVE_MEMORY false
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* USE_HOSTCC */
|
2008-01-31 12:55:39 +00:00
|
|
|
#include "mkimage.h"
|
2023-12-14 12:16:54 +00:00
|
|
|
#include <linux/kconfig.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>
|
2015-06-29 07:10:46 +00:00
|
|
|
|
|
|
|
#ifndef __maybe_unused
|
|
|
|
# define __maybe_unused /* unimplemented */
|
|
|
|
#endif
|
2021-09-25 13:03:14 +00:00
|
|
|
|
|
|
|
#define CONSERVE_MEMORY false
|
|
|
|
|
2008-02-29 20:24:06 +00:00
|
|
|
#endif /* !USE_HOSTCC*/
|
2008-01-08 17:14:09 +00:00
|
|
|
|
2021-09-25 13:03:14 +00:00
|
|
|
#include <abuf.h>
|
|
|
|
#include <bzlib.h>
|
2021-09-25 13:03:17 +00:00
|
|
|
#include <display_options.h>
|
2021-09-25 13:03:14 +00:00
|
|
|
#include <gzip.h>
|
2021-09-25 13:03:15 +00:00
|
|
|
#include <image.h>
|
2019-09-23 18:39:47 +00:00
|
|
|
#include <imximage.h>
|
2021-09-25 13:03:18 +00:00
|
|
|
#include <relocate.h>
|
2021-09-25 13:03:14 +00:00
|
|
|
#include <linux/lzo.h>
|
|
|
|
#include <linux/zstd.h>
|
|
|
|
#include <lzma/LzmaTypes.h>
|
|
|
|
#include <lzma/LzmaDec.h>
|
|
|
|
#include <lzma/LzmaTools.h>
|
|
|
|
#include <u-boot/crc.h>
|
2021-10-09 15:28:21 +00:00
|
|
|
#include <u-boot/lz4.h>
|
2013-02-24 17:33:25 +00:00
|
|
|
|
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", },
|
|
|
|
{ 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"},
|
2018-12-20 01:15:18 +00:00
|
|
|
{ IH_TYPE_SUNXI_EGON, "sunxi_egon", "Allwinner eGON Boot Image" },
|
2022-03-18 05:00:43 +00:00
|
|
|
{ IH_TYPE_SUNXI_TOC0, "sunxi_toc0", "Allwinner TOC0 Boot Image" },
|
2022-11-23 11:55:33 +00:00
|
|
|
{ IH_TYPE_FDT_LEGACY, "fdt_legacy", "legacy Image with Flat Device Tree ", },
|
2023-05-13 01:36:57 +00:00
|
|
|
{ IH_TYPE_RENESAS_SPKG, "spkgimage", "Renesas SPKG Image" },
|
2023-09-17 11:47:30 +00:00
|
|
|
{ IH_TYPE_STARFIVE_SPL, "sfspl", "StarFive SPL 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, "", "", },
|
|
|
|
};
|
|
|
|
|
2022-10-21 00:23:03 +00:00
|
|
|
static const table_entry_t uimage_phase[] = {
|
|
|
|
{ IH_PHASE_NONE, "none", "any", },
|
|
|
|
{ IH_PHASE_U_BOOT, "u-boot", "U-Boot phase", },
|
|
|
|
{ IH_PHASE_SPL, "spl", "SPL Phase", },
|
|
|
|
{ -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},},
|
2021-08-31 10:22:18 +00:00
|
|
|
{ IH_COMP_LZ4, "lz4", {0x04, 0x22},},
|
|
|
|
{ IH_COMP_ZSTD, "zstd", {0x28, 0xb5},},
|
2020-03-06 00:24:22 +00:00
|
|
|
{ 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 },
|
2022-10-21 00:23:03 +00:00
|
|
|
{ "phase", IH_PHASE_COUNT, uimage_phase },
|
2016-06-30 16:52:14 +00:00
|
|
|
};
|
|
|
|
|
2008-02-29 13:58:34 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Legacy format routines */
|
|
|
|
/*****************************************************************************/
|
2022-09-07 02:26:52 +00:00
|
|
|
int image_check_hcrc(const struct legacy_img_hdr *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();
|
2022-09-07 02:26:52 +00:00
|
|
|
struct legacy_img_hdr header;
|
2008-01-08 17:14:09 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2022-09-07 02:26:52 +00:00
|
|
|
int image_check_dcrc(const struct legacy_img_hdr *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
|
|
|
|
*/
|
2022-09-07 02:26:52 +00:00
|
|
|
ulong image_multi_count(const struct legacy_img_hdr *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
|
|
|
|
*/
|
2022-09-07 02:26:52 +00:00
|
|
|
void image_multi_getimg(const struct legacy_img_hdr *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
|
|
|
|
2022-09-07 02:26:52 +00:00
|
|
|
static void image_print_type(const struct legacy_img_hdr *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
|
|
|
{
|
2022-09-07 02:26:52 +00:00
|
|
|
const struct legacy_img_hdr *hdr = (const struct legacy_img_hdr *)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
|
2023-11-19 14:43:32 +00:00
|
|
|
* @load: Load address for printing
|
2019-07-25 02:37:54 +00:00
|
|
|
*/
|
2023-11-19 14:43:32 +00:00
|
|
|
static void print_decomp_msg(int comp_type, int type, bool is_xip,
|
|
|
|
ulong load)
|
2019-07-25 02:37:54 +00:00
|
|
|
{
|
|
|
|
const char *name = genimg_get_type_name(type);
|
|
|
|
|
2023-11-19 14:43:32 +00:00
|
|
|
/* Shows "Loading Kernel Image" for example */
|
2019-07-25 02:37:54 +00:00
|
|
|
if (comp_type == IH_COMP_NONE)
|
2023-11-19 14:43:32 +00:00
|
|
|
printf(" %s %s", is_xip ? "XIP" : "Loading", name);
|
2019-07-25 02:37:54 +00:00
|
|
|
else
|
2023-11-19 14:43:32 +00:00
|
|
|
printf(" Uncompressing %s", name);
|
|
|
|
|
|
|
|
printf(" to %lx\n", load);
|
2019-07-25 02:37:54 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2021-09-25 13:03:11 +00:00
|
|
|
int ret = -ENOSYS;
|
2019-07-25 02:37:54 +00:00
|
|
|
|
|
|
|
*load_end = load;
|
2023-11-19 14:43:32 +00:00
|
|
|
print_decomp_msg(comp, type, load == image_start, load);
|
2019-07-25 02:37:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:
|
2021-09-25 13:03:11 +00:00
|
|
|
ret = 0;
|
2019-07-25 02:37:54 +00:00
|
|
|
if (load == image_start)
|
|
|
|
break;
|
|
|
|
if (image_len <= unc_len)
|
|
|
|
memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
|
|
|
|
else
|
|
|
|
ret = -ENOSPC;
|
|
|
|
break;
|
2021-09-25 13:03:14 +00:00
|
|
|
case IH_COMP_GZIP:
|
2021-09-26 01:43:14 +00:00
|
|
|
if (!tools_build() && CONFIG_IS_ENABLED(GZIP))
|
2021-09-25 13:03:14 +00:00
|
|
|
ret = gunzip(load_buf, unc_len, image_buf, &image_len);
|
2019-07-25 02:37:54 +00:00
|
|
|
break;
|
2021-09-25 13:03:14 +00:00
|
|
|
case IH_COMP_BZIP2:
|
2021-09-26 01:43:14 +00:00
|
|
|
if (!tools_build() && CONFIG_IS_ENABLED(BZIP2)) {
|
2021-09-25 13:03:14 +00:00
|
|
|
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, CONSERVE_MEMORY, 0);
|
|
|
|
image_len = size;
|
|
|
|
}
|
2019-07-25 02:37:54 +00:00
|
|
|
break;
|
2021-09-25 13:03:14 +00:00
|
|
|
case IH_COMP_LZMA:
|
2021-09-26 01:43:14 +00:00
|
|
|
if (!tools_build() && CONFIG_IS_ENABLED(LZMA)) {
|
2021-09-25 13:03:14 +00:00
|
|
|
SizeT lzma_len = unc_len;
|
2019-07-25 02:37:54 +00:00
|
|
|
|
2021-09-25 13:03:14 +00:00
|
|
|
ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
|
|
|
|
image_buf, image_len);
|
|
|
|
image_len = lzma_len;
|
|
|
|
}
|
2019-07-25 02:37:54 +00:00
|
|
|
break;
|
2021-09-25 13:03:14 +00:00
|
|
|
case IH_COMP_LZO:
|
2021-09-26 01:43:14 +00:00
|
|
|
if (!tools_build() && CONFIG_IS_ENABLED(LZO)) {
|
2021-09-25 13:03:14 +00:00
|
|
|
size_t size = unc_len;
|
2019-07-25 02:37:54 +00:00
|
|
|
|
2021-09-25 13:03:14 +00:00
|
|
|
ret = lzop_decompress(image_buf, image_len, load_buf, &size);
|
|
|
|
image_len = size;
|
|
|
|
}
|
2019-07-25 02:37:54 +00:00
|
|
|
break;
|
2021-09-25 13:03:14 +00:00
|
|
|
case IH_COMP_LZ4:
|
2021-09-26 01:43:14 +00:00
|
|
|
if (!tools_build() && CONFIG_IS_ENABLED(LZ4)) {
|
2021-09-25 13:03:14 +00:00
|
|
|
size_t size = unc_len;
|
2019-07-25 02:37:54 +00:00
|
|
|
|
2021-09-25 13:03:14 +00:00
|
|
|
ret = ulz4fn(image_buf, image_len, load_buf, &size);
|
|
|
|
image_len = size;
|
|
|
|
}
|
2019-07-25 02:37:54 +00:00
|
|
|
break;
|
2021-09-25 13:03:14 +00:00
|
|
|
case IH_COMP_ZSTD:
|
2021-09-26 01:43:14 +00:00
|
|
|
if (!tools_build() && CONFIG_IS_ENABLED(ZSTD)) {
|
2021-09-25 13:03:14 +00:00
|
|
|
struct abuf in, out;
|
|
|
|
|
|
|
|
abuf_init_set(&in, image_buf, image_len);
|
2022-03-16 19:35:36 +00:00
|
|
|
abuf_init_set(&out, load_buf, unc_len);
|
2021-09-25 13:03:14 +00:00
|
|
|
ret = zstd_decompress(&in, &out);
|
|
|
|
if (ret >= 0) {
|
|
|
|
image_len = ret;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2020-04-25 17:37:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-09-25 13:03:11 +00:00
|
|
|
if (ret == -ENOSYS) {
|
2019-07-25 02:37:54 +00:00
|
|
|
printf("Unimplemented compression type %d\n", comp);
|
2021-09-25 13:03:11 +00:00
|
|
|
return ret;
|
2019-07-25 02:37:54 +00:00
|
|
|
}
|
2021-09-25 13:03:11 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-07-25 02:37:54 +00:00
|
|
|
|
|
|
|
*load_end = load + image_len;
|
|
|
|
|
2021-09-25 13:03:11 +00:00
|
|
|
return 0;
|
2019-07-25 02:37:54 +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.
|
|
|
|
*
|
2022-01-19 17:05:50 +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);
|
2023-09-06 21:29:59 +00:00
|
|
|
return entry->lname;
|
2016-06-30 16:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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.
|
|
|
|
*
|
2022-01-19 17:05:50 +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);
|
2023-09-06 21:29:59 +00:00
|
|
|
return entry->sname;
|
2016-06-30 16:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: true if category has entry id; false if not
|
2020-10-07 02:21:25 +00:00
|
|
|
*/
|
|
|
|
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;
|
2023-09-06 21:29:59 +00:00
|
|
|
return table->lname;
|
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));
|
|
|
|
}
|
|
|
|
|
2022-10-21 00:23:03 +00:00
|
|
|
const char *genimg_get_phase_name(enum image_phase_t phase)
|
|
|
|
{
|
|
|
|
return get_table_entry_name(uimage_phase, "Unknown Phase", phase);
|
|
|
|
}
|
|
|
|
|
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";
|
2023-09-06 21:29:59 +00:00
|
|
|
return table->sname;
|
2015-06-23 21:38:25 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2023-09-06 21:29:59 +00:00
|
|
|
if (t->sname && !strcasecmp(t->sname, name))
|
2021-09-25 13:03:18 +00:00
|
|
|
return t->id;
|
2008-02-29 14:59:59 +00:00
|
|
|
}
|
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
|
|
|
}
|
2022-10-21 00:23:03 +00:00
|
|
|
|
|
|
|
int genimg_get_phase_id(const char *name)
|
|
|
|
{
|
|
|
|
return get_table_entry_id(uimage_phase, "Phase", name);
|
|
|
|
}
|