#ifndef USE_HOSTCC
#include <common.h>
+#include <bootstage.h>
+#include <cpu_func.h>
#include <env.h>
+#include <lmb.h>
+#include <log.h>
+#include <malloc.h>
+#include <asm/cache.h>
+#include <u-boot/crc.h>
#include <watchdog.h>
#ifdef CONFIG_SHOW_BOOT_PROGRESS
#include <gzip.h>
#include <image.h>
+#include <lz4.h>
#include <mapmem.h>
#if IMAGE_ENABLE_FIT || IMAGE_ENABLE_OF_LIBFDT
#include <xilinx.h>
#endif
+#include <asm/global_data.h>
#include <u-boot/md5.h>
#include <u-boot/sha1.h>
#include <linux/errno.h>
#include <lzma/LzmaTypes.h>
#include <lzma/LzmaDec.h>
#include <lzma/LzmaTools.h>
+#include <linux/zstd.h>
#ifdef CONFIG_CMD_BDI
-extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+extern int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[]);
#endif
DECLARE_GLOBAL_DATA_PTR;
#endif /* !USE_HOSTCC*/
#include <u-boot/crc.h>
+#include <imximage.h>
#ifndef CONFIG_SYS_BARGSIZE
#define CONFIG_SYS_BARGSIZE 512
{ IH_OS_OPENRTOS, "openrtos", "OpenRTOS", },
#endif
{ IH_OS_OPENSBI, "opensbi", "RISC-V OpenSBI", },
+ { IH_OS_EFI, "efi", "EFI Firmware" },
{ -1, "", "", },
};
{ IH_TYPE_STM32IMAGE, "stm32image", "STMicroelectronics STM32 Image" },
{ IH_TYPE_MTKIMAGE, "mtk_image", "MediaTek BootROM loadable Image" },
{ IH_TYPE_COPRO, "copro", "Coprocessor Image"},
+ { IH_TYPE_SUNXI_EGON, "sunxi_egon", "Allwinner eGON Boot Image" },
{ -1, "", "", },
};
{ IH_COMP_LZMA, "lzma", "lzma compressed", },
{ IH_COMP_LZO, "lzo", "lzo compressed", },
{ IH_COMP_LZ4, "lz4", "lz4 compressed", },
+ { IH_COMP_ZSTD, "zstd", "zstd compressed", },
{ -1, "", "", },
};
const table_entry_t *table;
};
+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", {}, },
+};
+
static const struct table_info table_info[IH_COUNT] = {
{ "architecture", IH_ARCH_COUNT, uimage_arch },
{ "compression", IH_COMP_COUNT, uimage_comp },
}
} else if (image_check_type(hdr, IH_TYPE_FIRMWARE_IVT)) {
printf("HAB Blocks: 0x%08x 0x0000 0x%08x\n",
- image_get_load(hdr) - image_get_header_size(),
- image_get_size(hdr) + image_get_header_size()
- - 0x1FE0);
+ image_get_load(hdr) - image_get_header_size(),
+ (int)(image_get_size(hdr) + image_get_header_size()
+ + sizeof(flash_header_v2_t) - 0x2060));
}
}
printf(" Uncompressing %s\n", name);
}
+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;
+}
+
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)
break;
}
#endif /* CONFIG_LZ4 */
+#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 */
default:
printf("Unimplemented compression type %d\n", comp);
return -ENOSYS;
/* Shared dual-format routines */
/*****************************************************************************/
#ifndef USE_HOSTCC
-ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
-ulong save_addr; /* Default Save Address */
-ulong save_size; /* Default Save Size (in bytes) */
+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) */
static int on_loadaddr(const char *name, const char *value, enum env_op op,
int flags)
switch (op) {
case env_op_create:
case env_op_overwrite:
- load_addr = simple_strtoul(value, NULL, 16);
+ image_load_addr = simple_strtoul(value, NULL, 16);
break;
default:
break;
#if defined(CONFIG_SYS_SDRAM_BASE)
return CONFIG_SYS_SDRAM_BASE;
-#elif defined(CONFIG_ARM)
+#elif defined(CONFIG_ARM) || defined(CONFIG_MICROBLAZE)
return gd->bd->bi_dram[0].start;
#else
return 0;
return tmp;
}
-#if defined(CONFIG_ARM) && defined(CONFIG_NR_DRAM_BANKS)
- start = gd->bd->bi_dram[0].start;
- size = gd->bd->bi_dram[0].size;
-#else
- start = gd->bd->bi_memstart;
- size = gd->bd->bi_memsize;
-#endif
+ start = gd->ram_base;
+ size = gd->ram_size;
+
+ if (start + size > gd->ram_top)
+ size = gd->ram_top - start;
s = env_get("bootm_low");
if (s)
}
/**
- * get_cat_table_entry_name - translate entry id to long name
+ * genimg_get_cat_name - translate entry id to long name
* @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.
*
- * @retur long entry name if translation succeeds; error string on failure
+ * @return long entry name if translation succeeds; error string on failure
*/
const char *genimg_get_cat_name(enum ih_category category, uint id)
{
}
/**
- * get_cat_table_entry_short_name - translate entry id to short name
+ * genimg_get_cat_short_name - translate entry id to short name
* @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.
*
- * @retur short entry name if translation succeeds; error string on failure
+ * @return short entry name if translation succeeds; error string on failure
*/
const char *genimg_get_cat_short_name(enum ih_category category, uint id)
{
return table_info[category].desc;
}
+/**
+ * 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;
+}
+
/**
* get_table_entry_name - translate entry id to long name
* @table: pointer to a translation table for entries of a specific type
return (get_table_entry_name(uimage_type, "Unknown Image", type));
}
+const char *genimg_get_comp_name(uint8_t comp)
+{
+ return (get_table_entry_name(uimage_comp, "Unknown Compression",
+ comp));
+}
+
static const char *genimg_get_short_name(const table_entry_t *table, int val)
{
table = get_table_entry(table, val);
return genimg_get_short_name(uimage_type, type);
}
-const char *genimg_get_comp_name(uint8_t comp)
-{
- return (get_table_entry_name(uimage_comp, "Unknown Compression",
- comp));
-}
-
const char *genimg_get_comp_short_name(uint8_t comp)
{
return genimg_get_short_name(uimage_comp, comp);
/* find out kernel image address */
if (!img_addr) {
- kernel_addr = load_addr;
+ kernel_addr = image_load_addr;
debug("* kernel: default image load address = 0x%08lx\n",
- load_addr);
+ image_load_addr);
#if CONFIG_IS_ENABLED(FIT)
- } else if (fit_parse_conf(img_addr, load_addr, &kernel_addr,
+ } else if (fit_parse_conf(img_addr, image_load_addr, &kernel_addr,
fit_uname_config)) {
debug("* kernel: config '%s' from image at 0x%08lx\n",
*fit_uname_config, kernel_addr);
- } else if (fit_parse_subimage(img_addr, load_addr, &kernel_addr,
+ } else if (fit_parse_subimage(img_addr, image_load_addr, &kernel_addr,
fit_uname_kernel)) {
debug("* kernel: subimage '%s' from image at 0x%08lx\n",
*fit_uname_kernel, kernel_addr);
* 1, if ramdisk image is found but corrupted, or invalid
* rd_start and rd_end are set to 0 if no ramdisk exists
*/
-int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
- uint8_t arch, ulong *rd_start, ulong *rd_end)
+int boot_get_ramdisk(int argc, char *const argv[], bootm_headers_t *images,
+ uint8_t arch, ulong *rd_start, ulong *rd_end)
{
ulong rd_addr, rd_load;
ulong rd_data, rd_len;
if (images->fit_uname_os)
default_addr = (ulong)images->fit_hdr_os;
else
- default_addr = load_addr;
+ default_addr = image_load_addr;
if (fit_parse_conf(select, default_addr,
&rd_addr, &fit_uname_config)) {
#if IMAGE_ENABLE_FIT
#if defined(CONFIG_FPGA)
-int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images,
+int boot_get_fpga(int argc, char *const argv[], bootm_headers_t *images,
uint8_t arch, const ulong *ld_start, ulong * const ld_len)
{
ulong tmp_img_addr, img_data, img_len;
fit_loadable_handler->handler(img_data, img_len);
}
-int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
- uint8_t arch, const ulong *ld_start, ulong * const ld_len)
+int boot_get_loadable(int argc, char *const argv[], bootm_headers_t *images,
+ uint8_t arch, const ulong *ld_start, ulong * const ld_len)
{
/*
* These variables are used to hold the current image location
* 0 - success
* -1 - failure
*/
-int boot_get_kbd(struct lmb *lmb, bd_t **kbd)
+int boot_get_kbd(struct lmb *lmb, struct bd_info **kbd)
{
- *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
- env_get_bootm_mapsize() + env_get_bootm_low());
+ *kbd = (struct bd_info *)(ulong)lmb_alloc_base(lmb,
+ sizeof(struct bd_info),
+ 0xf,
+ env_get_bootm_mapsize() + env_get_bootm_low());
if (*kbd == NULL)
return -1;