boot: arm: riscv: sandbox: Add a format for the booti file

Arm invented a new format for arm64 and something similar is also used
with RISC-V. Add this to the list of supported formats and provide a way
for the format to be detected on both architectures.

Update the genimg_get_format() function to support this.

Fix up switch() statements which don't currently mention this format.
Booti does not support a ramdisk, so this can be ignored.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-03-05 17:25:09 -07:00
committed by Tom Rini
parent 3c7b13b075
commit 098407e673
5 changed files with 35 additions and 2 deletions

View File

@@ -28,6 +28,13 @@ struct Image_header {
uint32_t res5;
};
bool booti_is_valid(const void *img)
{
const struct Image_header *ih = img;
return ih->magic == le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC);
}
int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
bool force_reloc)
{
@@ -39,7 +46,7 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
ih = (struct Image_header *)map_sysmem(image, 0);
if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) {
if (!booti_is_valid(ih)) {
puts("Bad Linux ARM64 Image magic!\n");
return 1;
}

View File

@@ -32,6 +32,13 @@ struct linux_image_h {
uint32_t res4; /* reserved */
};
bool booti_is_valid(const void *img)
{
const struct linux_image_h *lhdr = img;
return lhdr->magic == LINUX_RISCV_IMAGE_MAGIC;
}
int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
bool force_reloc)
{
@@ -39,7 +46,7 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
lhdr = (struct linux_image_h *)map_sysmem(image, 0);
if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) {
if (!booti_is_valid(lhdr)) {
puts("Bad Linux RISCV Image magic!\n");
return -EINVAL;
}

View File

@@ -89,3 +89,8 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
return 1;
}
bool booti_is_valid(const void *img)
{
return false;
}

View File

@@ -250,6 +250,9 @@ enum image_fmt_t genimg_get_format(const void *img_addr)
if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE) &&
is_android_boot_image_header(img_addr))
return IMAGE_FORMAT_ANDROID;
if (IS_ENABLED(CONFIG_CMD_BOOTI) &&
booti_is_valid(img_addr))
return IMAGE_FORMAT_BOOTI;
return IMAGE_FORMAT_INVALID;
}
@@ -420,6 +423,8 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a
done = true;
}
break;
case IMAGE_FORMAT_BOOTI:
break;
case IMAGE_FORMAT_INVALID:
break;
}

View File

@@ -603,6 +603,7 @@ enum image_fmt_t {
IMAGE_FORMAT_LEGACY, /* legacy image_header based format */
IMAGE_FORMAT_FIT, /* new, libfdt based format */
IMAGE_FORMAT_ANDROID, /* Android boot image */
IMAGE_FORMAT_BOOTI, /* Arm64/RISC-V boot image */
};
/**
@@ -649,6 +650,14 @@ enum image_fmt_t genimg_get_format(const void *img_addr);
int genimg_has_config(struct bootm_headers *images);
/**
* booti_is_valid() - Check if an image appears to be an Arm64 image
*
* @img: Pointer to image
* Return: true if the image has the Arm64 magic
*/
bool booti_is_valid(const void *img);
/**
* boot_get_fpga() - Locate the FPGA image
*