54c92eaaf778dedd428a60217f9729387a6ac69e
[openwrt/staging/dangole.git] /
1 From 1c9174cbf57ddc75bb5a25b2563333d974fd1a55 Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Wed, 31 Aug 2022 19:05:22 +0800
4 Subject: [PATCH 29/32] tools: mtk_image: split gfh header verification into a
5 new function
6
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.
9
10 Reviewed-by: Simon Glass <sjg@chromium.org>
11 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
12 ---
13 tools/mtk_image.c | 51 +++++++++++++++++++----------------------------
14 1 file changed, 21 insertions(+), 30 deletions(-)
15
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;
20 }
21
22 +static int mtk_image_verify_gfh(struct gfh_header *gfh, uint32_t type, int print)
23 +{
24 + if (strcmp(gfh->file_info.name, GFH_FILE_INFO_NAME))
25 + return -1;
26 +
27 + if (le32_to_cpu(gfh->file_info.flash_type) != type)
28 + return -1;
29 +
30 + if (print)
31 + printf("Load Address: %08x\n",
32 + le32_to_cpu(gfh->file_info.load_addr) +
33 + le32_to_cpu(gfh->file_info.jump_offset));
34 +
35 + if (print)
36 + printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
37 +
38 + return 0;
39 +}
40 +
41 static int mtk_image_verify_gen_header(const uint8_t *ptr, int print)
42 {
43 union gen_boot_header *gbh = (union gen_boot_header *)ptr;
44 @@ -542,21 +561,7 @@ static int mtk_image_verify_gen_header(c
45
46 gfh = (struct gfh_header *)(ptr + gfh_offset);
47
48 - if (strcmp(gfh->file_info.name, GFH_FILE_INFO_NAME))
49 - return -1;
50 -
51 - if (le32_to_cpu(gfh->file_info.flash_type) != GFH_FLASH_TYPE_GEN)
52 - return -1;
53 -
54 - if (print)
55 - printf("Load Address: %08x\n",
56 - le32_to_cpu(gfh->file_info.load_addr) +
57 - le32_to_cpu(gfh->file_info.jump_offset));
58 -
59 - if (print)
60 - printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
61 -
62 - return 0;
63 + return mtk_image_verify_gfh(gfh, GFH_FLASH_TYPE_GEN, print);
64 }
65
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(
68
69 gfh = (struct gfh_header *)(ptr + 2 * le16_to_cpu(nh->pagesize));
70
71 - if (strcmp(gfh->file_info.name, GFH_FILE_INFO_NAME))
72 - return -1;
73 -
74 - if (le32_to_cpu(gfh->file_info.flash_type) != GFH_FLASH_TYPE_NAND)
75 - return -1;
76 -
77 - if (print)
78 - printf("Load Address: %08x\n",
79 - le32_to_cpu(gfh->file_info.load_addr) +
80 - le32_to_cpu(gfh->file_info.jump_offset));
81 -
82 - if (print)
83 - printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
84 -
85 - return 0;
86 + return mtk_image_verify_gfh(gfh, GFH_FLASH_TYPE_NAND, print);
87 }
88
89 static uint32_t crc32be_cal(const void *data, size_t length)