umbim: add missing json_close_object call
[openwrt/openwrt.git] / tools / mkimage / patches / 080-mtk_image-add-support-for-booting-ARM64-images.patch
1 From 44165e4c676d266f73fda2e6ba82b4bf3262daf2 Mon Sep 17 00:00:00 2001
2 From: Fabien Parent <fparent@baylibre.com>
3 Date: Fri, 16 Oct 2020 19:52:37 +0200
4 Subject: [PATCH] tools: mtk_image: add support for booting ARM64 images
5
6 mkimage is only able to package aarch32 binaries. Add support for
7 AArch64 images.
8
9 One can create a ARM64 image using the following command line:
10 mkimage -T mtk_image -a 0x201000 -e 0x201000 -n "media=emmc;arm64=1"
11 -d bl2.bin bl2.img
12
13 Signed-off-by: Fabien Parent <fparent@baylibre.com>
14 ---
15 tools/mtk_image.c | 28 ++++++++++++++++++++++++----
16 tools/mtk_image.h | 6 +++++-
17 2 files changed, 29 insertions(+), 5 deletions(-)
18
19 diff --git a/tools/mtk_image.c b/tools/mtk_image.c
20 index 2ca519483d..bde1e5da4b 100644
21 --- a/tools/mtk_image.c
22 +++ b/tools/mtk_image.c
23 @@ -246,6 +246,7 @@ static const struct brom_img_type {
24 /* Image type selected by user */
25 static enum brlyt_img_type hdr_media;
26 static int use_lk_hdr;
27 +static bool is_arm64_image;
28
29 /* LK image name */
30 static char lk_name[32] = "U-Boot";
31 @@ -276,6 +277,7 @@ static int mtk_brom_parse_imagename(const char *imagename)
32 static const char *media = "";
33 static const char *nandinfo = "";
34 static const char *lk = "";
35 + static const char *arm64_param = "";
36
37 key = buf;
38 while (key) {
39 @@ -323,6 +325,9 @@ static int mtk_brom_parse_imagename(const char *imagename)
40
41 if (!strcmp(key, "lkname"))
42 snprintf(lk_name, sizeof(lk_name), "%s", val);
43 +
44 + if (!strcmp(key, "arm64"))
45 + arm64_param = val;
46 }
47
48 if (next)
49 @@ -354,6 +359,9 @@ static int mtk_brom_parse_imagename(const char *imagename)
50 }
51 }
52
53 + if (arm64_param && arm64_param[0] == '1')
54 + is_arm64_image = true;
55 +
56 free(buf);
57
58 if (hdr_media == BRLYT_TYPE_INVALID) {
59 @@ -458,6 +466,9 @@ static int mtk_image_verify_gen_header(const uint8_t *ptr, int print)
60 le32_to_cpu(gfh->file_info.load_addr) +
61 le32_to_cpu(gfh->file_info.jump_offset));
62
63 + if (print)
64 + printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
65 +
66 return 0;
67 }
68
69 @@ -523,6 +534,9 @@ static int mtk_image_verify_nand_header(const uint8_t *ptr, int print)
70 le32_to_cpu(gfh->file_info.load_addr) +
71 le32_to_cpu(gfh->file_info.jump_offset));
72
73 + if (print)
74 + printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
75 +
76 return 0;
77 }
78
79 @@ -581,6 +595,8 @@ static void put_ghf_common_header(struct gfh_common_header *gfh, int size,
80 static void put_ghf_header(struct gfh_header *gfh, int file_size,
81 int dev_hdr_size, int load_addr, int flash_type)
82 {
83 + uint32_t cfg_bits;
84 +
85 memset(gfh, 0, sizeof(struct gfh_header));
86
87 /* GFH_FILE_INFO header */
88 @@ -608,11 +624,15 @@ static void put_ghf_header(struct gfh_header *gfh, int file_size,
89 /* GFH_BROM_CFG header */
90 put_ghf_common_header(&gfh->brom_cfg.gfh, sizeof(gfh->brom_cfg),
91 GFH_TYPE_BROM_CFG, 3);
92 - gfh->brom_cfg.cfg_bits = cpu_to_le32(
93 - GFH_BROM_CFG_USBDL_AUTO_DETECT_DIS |
94 - GFH_BROM_CFG_USBDL_BY_KCOL0_TIMEOUT_EN |
95 - GFH_BROM_CFG_USBDL_BY_FLAG_TIMEOUT_EN);
96 + cfg_bits = GFH_BROM_CFG_USBDL_AUTO_DETECT_DIS |
97 + GFH_BROM_CFG_USBDL_BY_KCOL0_TIMEOUT_EN |
98 + GFH_BROM_CFG_USBDL_BY_FLAG_TIMEOUT_EN;
99 gfh->brom_cfg.usbdl_by_kcol0_timeout_ms = cpu_to_le32(5000);
100 + if (is_arm64_image) {
101 + gfh->brom_cfg.jump_bl_arm64 = GFH_BROM_CFG_JUMP_BL_ARM64;
102 + cfg_bits |= GFH_BROM_CFG_JUMP_BL_ARM64_EN;
103 + }
104 + gfh->brom_cfg.cfg_bits = cpu_to_le32(cfg_bits);
105
106 /* GFH_BL_SEC_KEY header */
107 put_ghf_common_header(&gfh->bl_sec_key.gfh, sizeof(gfh->bl_sec_key),
108 diff --git a/tools/mtk_image.h b/tools/mtk_image.h
109 index 4e78b3d0ff..7dda71ce88 100644
110 --- a/tools/mtk_image.h
111 +++ b/tools/mtk_image.h
112 @@ -136,7 +136,9 @@ struct gfh_brom_cfg {
113 struct gfh_common_header gfh;
114 uint32_t cfg_bits;
115 uint32_t usbdl_by_auto_detect_timeout_ms;
116 - uint8_t unused[0x48];
117 + uint8_t unused[0x45];
118 + uint8_t jump_bl_arm64;
119 + uint8_t unused2[2];
120 uint32_t usbdl_by_kcol0_timeout_ms;
121 uint32_t usbdl_by_flag_timeout_ms;
122 uint32_t pad;
123 @@ -146,6 +148,8 @@ struct gfh_brom_cfg {
124 #define GFH_BROM_CFG_USBDL_AUTO_DETECT_DIS 0x10
125 #define GFH_BROM_CFG_USBDL_BY_KCOL0_TIMEOUT_EN 0x80
126 #define GFH_BROM_CFG_USBDL_BY_FLAG_TIMEOUT_EN 0x100
127 +#define GFH_BROM_CFG_JUMP_BL_ARM64_EN 0x1000
128 +#define GFH_BROM_CFG_JUMP_BL_ARM64 0x64
129
130 struct gfh_bl_sec_key {
131 struct gfh_common_header gfh;
132 --
133 2.30.1
134