[PATCH v3 03/19] android: boot: replace android_image_check_header
Safae Ouajih
souajih at baylibre.com
Mon Feb 6 00:50:05 CET 2023
With the new vendor boot image introduced in versions 3 and 4
of boot image header, the header check must be done for both boot
image and vendor boot image. Thus, replace android_image_check_header()
by is_android_boot_image_header() to only refer to boot image header check.
Signed-off-by: Safae Ouajih <souajih at baylibre.com>
Reviewed-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek at baylibre.com>
---
boot/image-android.c | 17 ++++-------------
boot/image-board.c | 2 +-
cmd/abootimg.c | 4 ++--
drivers/fastboot/fb_mmc.c | 3 +--
include/image.h | 22 +++++++++++-----------
5 files changed, 19 insertions(+), 29 deletions(-)
diff --git a/boot/image-android.c b/boot/image-android.c
index b070974791..ac7cb479c1 100644
--- a/boot/image-android.c
+++ b/boot/image-android.c
@@ -122,18 +122,9 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify,
return 0;
}
-/**
- * android_image_check_header() - Check the magic of boot image
- *
- * This checks the header of Android boot image and verifies the
- * magic is "ANDROID!"
- *
- * @hdr: Pointer to boot image
- * Return: 0 if the magic is correct, non-zero if there is a magic mismatch
- */
-int android_image_check_header(const struct andr_boot_img_hdr_v0 *hdr)
+bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr)
{
- return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
+ return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE);
}
ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr)
@@ -240,7 +231,7 @@ bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size)
bool ret = true;
hdr = map_sysmem(hdr_addr, sizeof(*hdr));
- if (android_image_check_header(hdr)) {
+ if (!is_android_boot_image_header(hdr)) {
printf("Error: Boot Image header is incorrect\n");
ret = false;
goto exit;
@@ -289,7 +280,7 @@ static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr)
bool ret = true;
hdr = map_sysmem(hdr_addr, sizeof(*hdr));
- if (android_image_check_header(hdr)) {
+ if (!is_android_boot_image_header(hdr)) {
printf("Error: Boot Image header is incorrect\n");
ret = false;
goto exit;
diff --git a/boot/image-board.c b/boot/image-board.c
index e5d71a3d54..9295b6d0c8 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -284,7 +284,7 @@ int genimg_get_format(const void *img_addr)
return IMAGE_FORMAT_FIT;
}
if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE) &&
- !android_image_check_header(img_addr))
+ is_android_boot_image_header(img_addr))
return IMAGE_FORMAT_ANDROID;
return IMAGE_FORMAT_INVALID;
diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index 026c03f91c..b5cfb141ef 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -26,7 +26,7 @@ static int abootimg_get_ver(int argc, char *const argv[])
return CMD_RET_USAGE;
hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
- if (android_image_check_header(hdr)) {
+ if (!is_android_boot_image_header(hdr)) {
printf("Error: Boot Image header is incorrect\n");
res = CMD_RET_FAILURE;
goto exit;
@@ -73,7 +73,7 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
return CMD_RET_USAGE;
hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
- if (android_image_check_header(hdr)) {
+ if (!is_android_boot_image_header(hdr)) {
printf("Error: Boot Image header is incorrect\n");
res = CMD_RET_FAILURE;
goto exit;
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 6d0112fdf4..086e5f7843 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -313,8 +313,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
}
/* Check boot header magic string */
- res = android_image_check_header(hdr);
- if (res != 0) {
+ if (!is_android_boot_image_header(hdr)) {
pr_err("bad boot image magic\n");
fastboot_fail("boot partition not initialized", response);
return 0;
diff --git a/include/image.h b/include/image.h
index 735484117d..6e67cf4817 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1736,17 +1736,6 @@ struct cipher_algo *image_get_cipher_algo(const char *full_name);
struct andr_boot_img_hdr_v0;
-/**
- * android_image_check_header() - Check the magic of boot image
- *
- * This checks the header of Android boot image and verifies the
- * magic is "ANDROID!"
- *
- * @hdr: Pointer to image header
- * Return: 0 if the magic is correct, non-zero if there is a magic mismatch
- */
-int android_image_check_header(const struct andr_boot_img_hdr_v0 *hdr);
-
/**
* android_image_get_kernel() - Processes kernel part of Android boot images
*
@@ -1838,6 +1827,17 @@ ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr);
void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr);
bool android_image_print_dtb_contents(ulong hdr_addr);
+/**
+ * is_android_boot_image_header() - Check the magic of boot image
+ *
+ * This checks the header of Android boot image and verifies the
+ * magic is "ANDROID!"
+ *
+ * @hdr: Pointer to boot image
+ * Return: non-zero if the magic is correct, zero otherwise
+ */
+bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr);
+
/**
* board_fit_config_name_match() - Check for a matching board name
*
--
2.34.1
More information about the U-Boot
mailing list