]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
arm: imx: Add function to validate i.MX8 containers
authorSean Anderson <seanga2@gmail.com>
Sat, 14 Oct 2023 20:47:43 +0000 (16:47 -0400)
committerTom Rini <trini@konsulko.com>
Wed, 18 Oct 2023 00:50:52 +0000 (20:50 -0400)
Add a function to abstract the common task of validating i.MX8 container
image headers.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
arch/arm/include/asm/mach-imx/image.h
arch/arm/mach-imx/ele_ahab.c
arch/arm/mach-imx/image-container.c
arch/arm/mach-imx/imx8/ahab.c
arch/arm/mach-imx/parse-container.c
arch/arm/mach-imx/spl_imx_romapi.c

index ee67ca96f4c272ada71dca21e19a9808bf1db146..54cd684e35d52b231fbd1312b8b96a7220193834 100644 (file)
@@ -18,6 +18,9 @@
 #define CONTAINER_HDR_QSPI_OFFSET SZ_4K
 #define CONTAINER_HDR_NAND_OFFSET SZ_128M
 
+#define CONTAINER_HDR_TAG 0x87
+#define CONTAINER_HDR_VERSION 0
+
 struct container_hdr {
        u8 version;
        u8 length_lsb;
@@ -66,4 +69,10 @@ struct generate_key_blob_hdr {
 } __packed;
 
 int get_container_size(ulong addr, u16 *header_length);
+
+static inline bool valid_container_hdr(struct container_hdr *container)
+{
+       return container->tag == CONTAINER_HDR_TAG &&
+              container->version == CONTAINER_HDR_VERSION;
+}
 #endif
index 785b0d6ec3cf4b8637511b198873cf3caab75b5c..6a1ad198f89c1fa2dab4ab4b9aeeaaa74e4c55ee 100644 (file)
@@ -343,7 +343,7 @@ int authenticate_os_container(ulong addr)
        }
 
        phdr = (struct container_hdr *)addr;
-       if (phdr->tag != 0x87 || phdr->version != 0x0) {
+       if (!valid_container_hdr(phdr)) {
                printf("Error: Wrong container header\n");
                return -EFAULT;
        }
index 5f188ab32d18fc54f27a90c3dc2fb80163806307..eff9e0c4597a51a9b06a58afaa49acf6aeb61606 100644 (file)
@@ -50,7 +50,7 @@ int get_container_size(ulong addr, u16 *header_length)
        u32 max_offset = 0, img_end;
 
        phdr = (struct container_hdr *)addr;
-       if (phdr->tag != 0x87 || phdr->version != 0x0) {
+       if (!valid_container_hdr(phdr)) {
                debug("Wrong container header\n");
                return -EFAULT;
        }
index b58b14ca9b4d5488984b736edced3c211ef1ac70..44ea63584aa650dc98120d25c90a5fea6e4459e2 100644 (file)
@@ -146,7 +146,7 @@ int authenticate_os_container(ulong addr)
        }
 
        phdr = (struct container_hdr *)addr;
-       if (phdr->tag != 0x87 && phdr->version != 0x0) {
+       if (!valid_container_hdr(phdr)) {
                printf("Error: Wrong container header\n");
                return -EFAULT;
        }
index 48cffb3ab4d57f4337327dca2f0a92c0e43cdbff..d57f25df6dc5766fe8eca93f4969d435f70125eb 100644 (file)
@@ -85,7 +85,7 @@ static int read_auth_container(struct spl_image_info *spl_image,
                goto end;
        }
 
-       if (container->tag != 0x87 && container->version != 0x0) {
+       if (!valid_container_hdr(container)) {
                log_err("Wrong container header\n");
                ret = -ENOENT;
                goto end;
index c4a4185eed1fb5c5cdad17494c7504e68b2a7171..80909aec3ea7d753ecc31ca4882ced668cd95b64 100644 (file)
@@ -202,7 +202,8 @@ static u8 *search_container_header(u8 *p, int size)
 
        for (i = 0; i < size; i += 4) {
                hdr = p + i;
-               if (*(hdr + 3) == 0x87 && *hdr == 0 && (*(hdr + 1) != 0 || *(hdr + 2) != 0))
+               if (valid_container_hdr((void *)hdr) &&
+                   (*(hdr + 1) != 0 || *(hdr + 2) != 0))
                        return p + i;
        }