ce61cb0fb6ccd455e9049f421f1600cfcd9e11a6
[openwrt/staging/hauke.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 @@ -20,6 +20,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 @@ -76,11 +77,12 @@ static void usage(const char *msg)
14 " -l ==> list image header information\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 @@ -143,7 +145,7 @@ static void process_args(int argc, char
28 int opt;
29
30 while ((opt = getopt(argc, argv,
31 - "a:A:b:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qsT:vVx")) != -1) {
32 + "a:A:b:c:C:d:D:e:Ef:Fk:i:K:lM:n:N:p:O:rR:qsT:vVx")) != -1) {
33 switch (opt) {
34 case 'a':
35 params.addr = strtoull(optarg, &ptr, 16);
36 @@ -221,6 +223,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 @@ -116,7 +116,7 @@ static void image_set_header(void *ptr,
54 }
55
56 /* Build new header */
57 - image_set_magic(hdr, IH_MAGIC);
58 + image_set_magic(hdr, params->magic);
59 image_set_time(hdr, time);
60 image_set_size(hdr, imagesize);
61 image_set_load(hdr, addr);
62 --- a/tools/imagetool.h
63 +++ b/tools/imagetool.h
64 @@ -53,6 +53,7 @@ struct image_tool_params {
65 int arch;
66 int type;
67 int comp;
68 + unsigned int magic;
69 char *dtc;
70 unsigned int addr;
71 unsigned int ep;