030-allow-to-use-different-magic.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. This patch makes it possible to set a custom image magic.
  2. --- a/tools/mkimage.c
  3. +++ b/tools/mkimage.c
  4. @@ -20,6 +20,7 @@ static struct image_tool_params params =
  5. .arch = IH_ARCH_PPC,
  6. .type = IH_TYPE_KERNEL,
  7. .comp = IH_COMP_GZIP,
  8. + .magic = IH_MAGIC,
  9. .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS,
  10. .imagename = "",
  11. .imagename2 = "",
  12. @@ -76,11 +77,12 @@ static void usage(const char *msg)
  13. " -l ==> list image header information\n",
  14. params.cmdname);
  15. fprintf(stderr,
  16. - " %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image\n"
  17. + " %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"
  18. " -A ==> set architecture to 'arch'\n"
  19. " -O ==> set operating system to 'os'\n"
  20. " -T ==> set image type to 'type'\n"
  21. " -C ==> set compression type 'comp'\n"
  22. + " -M ==> set image magic to 'magic'\n"
  23. " -a ==> set load address to 'addr' (hex)\n"
  24. " -e ==> set entry point to 'ep' (hex)\n"
  25. " -n ==> set image name to 'name'\n"
  26. @@ -143,7 +145,7 @@ static void process_args(int argc, char
  27. int opt;
  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. @@ -221,6 +223,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. @@ -116,7 +116,7 @@ static void image_set_header(void *ptr,
  52. }
  53. /* Build new header */
  54. - image_set_magic(hdr, IH_MAGIC);
  55. + image_set_magic(hdr, params->magic);
  56. image_set_time(hdr, time);
  57. image_set_size(hdr, imagesize);
  58. image_set_load(hdr, addr);
  59. --- a/tools/imagetool.h
  60. +++ b/tools/imagetool.h
  61. @@ -53,6 +53,7 @@ struct image_tool_params {
  62. int arch;
  63. int type;
  64. int comp;
  65. + unsigned int magic;
  66. char *dtc;
  67. unsigned int addr;
  68. unsigned int ep;