1 From b6bb61fd3818f4a3025fedbe4d15dbeeaef6ee82 Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Tue, 2 Aug 2022 17:21:34 +0800
4 Subject: [PATCH 28/31] tools: mtk_image: split gfh header verification into a
7 The verification code of gfh header for NAND and non-NAND are identical.
8 It's better to define a individual function to reduce redundancy.
10 Reviewed-by: Simon Glass <sjg@chromium.org>
11 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
13 tools/mtk_image.c | 51 +++++++++++++++++++----------------------------
14 1 file changed, 21 insertions(+), 30 deletions(-)
16 --- a/tools/mtk_image.c
17 +++ b/tools/mtk_image.c
18 @@ -480,6 +480,25 @@ static int mtk_image_vrec_header(struct
19 return SHA256_SUM_LEN;
22 +static int mtk_image_verify_gfh(struct gfh_header *gfh, uint32_t type, int print)
24 + if (strcmp(gfh->file_info.name, GFH_FILE_INFO_NAME))
27 + if (le32_to_cpu(gfh->file_info.flash_type) != type)
31 + printf("Load Address: %08x\n",
32 + le32_to_cpu(gfh->file_info.load_addr) +
33 + le32_to_cpu(gfh->file_info.jump_offset));
36 + printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
41 static int mtk_image_verify_gen_header(const uint8_t *ptr, int print)
43 union gen_boot_header *gbh = (union gen_boot_header *)ptr;
44 @@ -542,21 +561,7 @@ static int mtk_image_verify_gen_header(c
46 gfh = (struct gfh_header *)(ptr + gfh_offset);
48 - if (strcmp(gfh->file_info.name, GFH_FILE_INFO_NAME))
51 - if (le32_to_cpu(gfh->file_info.flash_type) != GFH_FLASH_TYPE_GEN)
55 - printf("Load Address: %08x\n",
56 - le32_to_cpu(gfh->file_info.load_addr) +
57 - le32_to_cpu(gfh->file_info.jump_offset));
60 - printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
63 + return mtk_image_verify_gfh(gfh, GFH_FLASH_TYPE_GEN, print);
66 static int mtk_image_verify_nand_header(const uint8_t *ptr, int print)
67 @@ -610,21 +615,7 @@ static int mtk_image_verify_nand_header(
69 gfh = (struct gfh_header *)(ptr + 2 * le16_to_cpu(nh->pagesize));
71 - if (strcmp(gfh->file_info.name, GFH_FILE_INFO_NAME))
74 - if (le32_to_cpu(gfh->file_info.flash_type) != GFH_FLASH_TYPE_NAND)
78 - printf("Load Address: %08x\n",
79 - le32_to_cpu(gfh->file_info.load_addr) +
80 - le32_to_cpu(gfh->file_info.jump_offset));
83 - printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
86 + return mtk_image_verify_gfh(gfh, GFH_FLASH_TYPE_NAND, print);
89 static uint32_t crc32be_cal(const void *data, size_t length)