tools/mkimage: update to version 2018.03
[oweals/openwrt.git] / tools / mkimage / patches / 030-allow-to-use-different-magic.patch
1 --- a/tools/mkimage.c
2 +++ b/tools/mkimage.c
3 @@ -21,6 +21,7 @@ static struct image_tool_params params =
4         .arch = IH_ARCH_PPC,
5         .type = IH_TYPE_KERNEL,
6         .comp = IH_COMP_GZIP,
7 +       .magic = IH_MAGIC,
8         .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS,
9         .imagename = "",
10         .imagename2 = "",
11 @@ -77,11 +78,12 @@ static void usage(const char *msg)
12                          "          -l ==> list image header information\n",
13                 params.cmdname);
14         fprintf(stderr,
15 -               "       %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image\n"
16 +               "       %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"
17                 "          -A ==> set architecture to 'arch'\n"
18                 "          -O ==> set operating system to 'os'\n"
19                 "          -T ==> set image type to 'type'\n"
20                 "          -C ==> set compression type 'comp'\n"
21 +               "          -M ==> set image magic to 'magic'\n"
22                 "          -a ==> set load address to 'addr' (hex)\n"
23                 "          -e ==> set entry point to 'ep' (hex)\n"
24                 "          -n ==> set image name to 'name'\n"
25 @@ -144,7 +146,7 @@ static void process_args(int argc, char
26         int opt;
27  
28         while ((opt = getopt(argc, argv,
29 -                            "a:A:b:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qsT:vVx")) != -1) {
30 +                            "a:A:b:c:C:d:D:e:Ef:Fk:i:K:lM:n:N:p:O:rR:qsT:vVx")) != -1) {
31                 switch (opt) {
32                 case 'a':
33                         params.addr = strtoull(optarg, &ptr, 16);
34 @@ -222,6 +224,14 @@ static void process_args(int argc, char
35                 case 'l':
36                         params.lflag = 1;
37                         break;
38 +               case 'M':
39 +                       params.magic = strtoull(optarg, &ptr, 16);
40 +                       if (*ptr) {
41 +                               fprintf(stderr, "%s: invalid magic %s\n",
42 +                                       params.cmdname, optarg);
43 +                               exit(EXIT_FAILURE);
44 +                       }
45 +                       break;
46                 case 'n':
47                         params.imagename = optarg;
48                         break;
49 --- a/tools/default_image.c
50 +++ b/tools/default_image.c
51 @@ -106,7 +106,7 @@ static void image_set_header(void *ptr,
52                 imagesize = sbuf->st_size - sizeof(image_header_t);
53  
54         /* Build new header */
55 -       image_set_magic(hdr, IH_MAGIC);
56 +       image_set_magic(hdr, params->magic);
57         image_set_time(hdr, time);
58         image_set_size(hdr, imagesize);
59         image_set_load(hdr, params->addr);
60 --- a/tools/imagetool.h
61 +++ b/tools/imagetool.h
62 @@ -54,6 +54,7 @@ struct image_tool_params {
63         int arch;
64         int type;
65         int comp;
66 +       unsigned int magic;
67         char *dtc;
68         unsigned int addr;
69         unsigned int ep;