]> git.ipfire.org Git - thirdparty/u-boot.git/blobdiff - cmd/abootimg.c
arm: Check FEAT_CCIDX when parsing ccsidr_el1 register
[thirdparty/u-boot.git] / cmd / abootimg.c
index 15e727f4a2d69682ed4102cc0eec11fe426fcdc2..2653b555b10a07d89192536f300524072213b8f4 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <android_image.h>
 #include <common.h>
+#include <command.h>
 #include <image.h>
 #include <mapmem.h>
 
 
 /* Please use abootimg_addr() macro to obtain the boot image address */
 static ulong _abootimg_addr = -1;
+static ulong _avendor_bootimg_addr = -1;
 
-static int abootimg_get_ver(int argc, char * const argv[])
+ulong get_abootimg_addr(void)
 {
-       const struct andr_img_hdr *hdr;
+       return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr);
+}
+
+ulong get_avendor_bootimg_addr(void)
+{
+       return _avendor_bootimg_addr;
+}
+
+static int abootimg_get_ver(int argc, char *const argv[])
+{
+       const struct andr_boot_img_hdr_v0 *hdr;
        int res = CMD_RET_SUCCESS;
 
        if (argc > 1)
                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;
@@ -40,7 +52,7 @@ exit:
        return res;
 }
 
-static int abootimg_get_recovery_dtbo(int argc, char * const argv[])
+static int abootimg_get_recovery_dtbo(int argc, char *const argv[])
 {
        ulong addr;
        u32 size;
@@ -62,38 +74,48 @@ static int abootimg_get_recovery_dtbo(int argc, char * const argv[])
        return CMD_RET_SUCCESS;
 }
 
-static int abootimg_get_dtb_load_addr(int argc, char * const argv[])
+static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
 {
-       const struct andr_img_hdr *hdr;
-       int res = CMD_RET_SUCCESS;
-
        if (argc > 1)
                return CMD_RET_USAGE;
+       struct andr_image_data img_data = {0};
+       const struct andr_boot_img_hdr_v0 *hdr;
+       const struct andr_vnd_boot_img_hdr *vhdr;
 
        hdr = map_sysmem(abootimg_addr(), sizeof(*hdr));
-       if (android_image_check_header(hdr)) {
-               printf("Error: Boot Image header is incorrect\n");
-               res = CMD_RET_FAILURE;
-               goto exit;
+       if (get_avendor_bootimg_addr() != -1)
+               vhdr = map_sysmem(get_avendor_bootimg_addr(), sizeof(*vhdr));
+
+       if (!android_image_get_data(hdr, vhdr, &img_data)) {
+               if (get_avendor_bootimg_addr() != -1)
+                       unmap_sysmem(vhdr);
+               unmap_sysmem(hdr);
+               return CMD_RET_FAILURE;
        }
 
-       if (hdr->header_version < 2) {
+       if (get_avendor_bootimg_addr() != -1)
+               unmap_sysmem(vhdr);
+       unmap_sysmem(hdr);
+
+       if (img_data.header_version < 2) {
                printf("Error: header_version must be >= 2 for this\n");
-               res = CMD_RET_FAILURE;
-               goto exit;
+               return CMD_RET_FAILURE;
+       }
+
+       if (!img_data.dtb_load_addr) {
+               printf("Error: failed to read dtb_load_addr\n");
+               return CMD_RET_FAILURE;
        }
 
        if (argc == 0)
-               printf("%lx\n", (ulong)hdr->dtb_addr);
+               printf("%lx\n", (ulong)img_data.dtb_load_addr);
        else
-               env_set_hex(argv[0], (ulong)hdr->dtb_addr);
+               env_set_hex(argv[0], (ulong)img_data.dtb_load_addr);
 
-exit:
-       unmap_sysmem(hdr);
-       return res;
+       return CMD_RET_SUCCESS;
 }
 
-static int abootimg_get_dtb_by_index(int argc, char * const argv[])
+static int abootimg_get_dtb_by_index(int argc, char *const argv[])
 {
        const char *index_str;
        u32 num;
@@ -116,7 +138,8 @@ static int abootimg_get_dtb_by_index(int argc, char * const argv[])
                return CMD_RET_FAILURE;
        }
 
-       if (!android_image_get_dtb_by_index(abootimg_addr(), num,
+       if (!android_image_get_dtb_by_index(abootimg_addr(),
+                                           get_avendor_bootimg_addr(), num,
                                            &addr, &size)) {
                return CMD_RET_FAILURE;
        }
@@ -140,7 +163,7 @@ static int abootimg_get_dtb_by_index(int argc, char * const argv[])
        return CMD_RET_SUCCESS;
 }
 
-static int abootimg_get_dtb(int argc, char * const argv[])
+static int abootimg_get_dtb(int argc, char *const argv[])
 {
        if (argc < 1)
                return CMD_RET_USAGE;
@@ -151,27 +174,38 @@ static int abootimg_get_dtb(int argc, char * const argv[])
        return CMD_RET_USAGE;
 }
 
-static int do_abootimg_addr(cmd_tbl_t *cmdtp, int flag, int argc,
-                           char * const argv[])
+static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc,
+                           char *const argv[])
 {
        char *endp;
        ulong img_addr;
 
-       if (argc != 2)
+       if (argc < 2 || argc > 3)
                return CMD_RET_USAGE;
 
-       img_addr = simple_strtoul(argv[1], &endp, 16);
+       img_addr = hextoul(argv[1], &endp);
        if (*endp != '\0') {
                printf("Error: Wrong image address\n");
                return CMD_RET_FAILURE;
        }
 
        _abootimg_addr = img_addr;
+
+       if (argc == 3) {
+               img_addr = simple_strtoul(argv[2], &endp, 16);
+               if (*endp != '\0') {
+                       printf("Error: Wrong vendor image address\n");
+                       return CMD_RET_FAILURE;
+               }
+
+               _avendor_bootimg_addr = img_addr;
+       }
+
        return CMD_RET_SUCCESS;
 }
 
-static int do_abootimg_get(cmd_tbl_t *cmdtp, int flag, int argc,
-                          char * const argv[])
+static int do_abootimg_get(struct cmd_tbl *cmdtp, int flag, int argc,
+                          char *const argv[])
 {
        const char *param;
 
@@ -193,8 +227,8 @@ static int do_abootimg_get(cmd_tbl_t *cmdtp, int flag, int argc,
        return CMD_RET_USAGE;
 }
 
-static int do_abootimg_dump(cmd_tbl_t *cmdtp, int flag, int argc,
-                           char * const argv[])
+static int do_abootimg_dump(struct cmd_tbl *cmdtp, int flag, int argc,
+                           char *const argv[])
 {
        if (argc != 2)
                return CMD_RET_USAGE;
@@ -209,16 +243,16 @@ static int do_abootimg_dump(cmd_tbl_t *cmdtp, int flag, int argc,
        return CMD_RET_SUCCESS;
 }
 
-static cmd_tbl_t cmd_abootimg_sub[] = {
-       U_BOOT_CMD_MKENT(addr, 2, 1, do_abootimg_addr, "", ""),
+static struct cmd_tbl cmd_abootimg_sub[] = {
+       U_BOOT_CMD_MKENT(addr, 3, 1, do_abootimg_addr, "", ""),
        U_BOOT_CMD_MKENT(dump, 2, 1, do_abootimg_dump, "", ""),
        U_BOOT_CMD_MKENT(get, 5, 1, do_abootimg_get, "", ""),
 };
 
-static int do_abootimg(cmd_tbl_t *cmdtp, int flag, int argc,
-                      char * const argv[])
+static int do_abootimg(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
 {
-       cmd_tbl_t *cp;
+       struct cmd_tbl *cp;
 
        cp = find_cmd_tbl(argv[1], cmd_abootimg_sub,
                          ARRAY_SIZE(cmd_abootimg_sub));
@@ -238,7 +272,7 @@ static int do_abootimg(cmd_tbl_t *cmdtp, int flag, int argc,
 U_BOOT_CMD(
        abootimg, CONFIG_SYS_MAXARGS, 0, do_abootimg,
        "manipulate Android Boot Image",
-       "addr <addr>\n"
+       "addr <boot_img_addr> [<vendor_boot_img_addr>]>\n"
        "    - set the address in RAM where boot image is located\n"
        "      ($loadaddr is used by default)\n"
        "abootimg dump dtb\n"