tools/mkimage: update to 2023.10
[openwrt/staging/stintel.git] / tools / mkimage / patches / 030-allow-to-use-different-magic.patch
1 This patch makes it possible to set a custom image magic.
2
3 --- a/tools/mkimage.c
4 +++ b/tools/mkimage.c
5 @@ -26,6 +26,7 @@ static struct image_tool_params params =
6 .arch = IH_ARCH_PPC,
7 .type = IH_TYPE_KERNEL,
8 .comp = IH_COMP_GZIP,
9 + .magic = IH_MAGIC,
10 .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS,
11 .imagename = "",
12 .imagename2 = "",
13 @@ -89,11 +90,12 @@ static void usage(const char *msg)
14 " -q ==> quiet\n",
15 params.cmdname);
16 fprintf(stderr,
17 - " %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image\n"
18 + " %s [-x] -A arch -O os -T type -C comp -M magic -a addr -e ep -n name -d data_file[:data_file...] image\n"
19 " -A ==> set architecture to 'arch'\n"
20 " -O ==> set operating system to 'os'\n"
21 " -T ==> set image type to 'type'\n"
22 " -C ==> set compression type 'comp'\n"
23 + " -M ==> set image magic to 'magic'\n"
24 " -a ==> set load address to 'addr' (hex)\n"
25 " -e ==> set entry point to 'ep' (hex)\n"
26 " -n ==> set image name to 'name'\n"
27 @@ -159,7 +161,7 @@ static int add_content(int type, const c
28 }
29
30 static const char optstring[] =
31 - "a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:ln:N:o:O:p:qrR:stT:vVx";
32 + "a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:lM:n:N:o:O:p:qrR:stT:vVx";
33
34 static const struct option longopts[] = {
35 { "load-address", required_argument, NULL, 'a' },
36 @@ -302,6 +304,14 @@ static void process_args(int argc, char
37 case 'l':
38 params.lflag = 1;
39 break;
40 + case 'M':
41 + params.magic = strtoull(optarg, &ptr, 16);
42 + if (*ptr) {
43 + fprintf(stderr, "%s: invalid magic %s\n",
44 + params.cmdname, optarg);
45 + exit(EXIT_FAILURE);
46 + }
47 + break;
48 case 'n':
49 params.imagename = optarg;
50 break;
51 --- a/tools/default_image.c
52 +++ b/tools/default_image.c
53 @@ -68,7 +68,7 @@ static int image_verify_header(unsigned
54 */
55 memcpy(hdr, ptr, sizeof(struct legacy_img_hdr));
56
57 - if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) {
58 + if (be32_to_cpu(hdr->ih_magic) != params->magic) {
59 debug("%s: Bad Magic Number: \"%s\" is no valid image\n",
60 params->cmdname, params->imagefile);
61 return -FDT_ERR_BADMAGIC;
62 @@ -147,7 +147,7 @@ static void image_set_header(void *ptr,
63 }
64
65 /* Build new header */
66 - image_set_magic(hdr, IH_MAGIC);
67 + image_set_magic(hdr, params->magic);
68 image_set_time(hdr, time);
69 image_set_size(hdr, imagesize);
70 image_set_load(hdr, addr);
71 --- a/tools/imagetool.h
72 +++ b/tools/imagetool.h
73 @@ -67,6 +67,7 @@ struct image_tool_params {
74 int arch;
75 int type;
76 int comp;
77 + unsigned int magic;
78 char *dtc;
79 unsigned int addr;
80 unsigned int ep;