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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. This patch makes it possible to set a custom image magic.
  2. --- a/tools/mkimage.c
  3. +++ b/tools/mkimage.c
  4. @@ -26,6 +26,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. @@ -89,11 +90,12 @@ static void usage(const char *msg)
  13. " -q ==> quiet\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. @@ -159,7 +161,7 @@ static int add_content(int type, const c
  27. }
  28. static const char optstring[] =
  29. - "a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:ln:N:o:O:p:qrR:stT:vVx";
  30. + "a:A:b:B:c:C:d:D:e:Ef:Fg:G:i:k:K:lM:n:N:o:O:p:qrR:stT:vVx";
  31. static const struct option longopts[] = {
  32. { "load-address", required_argument, NULL, 'a' },
  33. @@ -302,6 +304,14 @@ static void process_args(int argc, char
  34. case 'l':
  35. params.lflag = 1;
  36. break;
  37. + case 'M':
  38. + params.magic = strtoull(optarg, &ptr, 16);
  39. + if (*ptr) {
  40. + fprintf(stderr, "%s: invalid magic %s\n",
  41. + params.cmdname, optarg);
  42. + exit(EXIT_FAILURE);
  43. + }
  44. + break;
  45. case 'n':
  46. params.imagename = optarg;
  47. break;
  48. --- a/tools/default_image.c
  49. +++ b/tools/default_image.c
  50. @@ -63,7 +63,7 @@ static int image_verify_header(unsigned
  51. */
  52. memcpy(hdr, ptr, sizeof(struct legacy_img_hdr));
  53. - if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) {
  54. + if (be32_to_cpu(hdr->ih_magic) != params->magic) {
  55. debug("%s: Bad Magic Number: \"%s\" is no valid image\n",
  56. params->cmdname, params->imagefile);
  57. return -FDT_ERR_BADMAGIC;
  58. @@ -142,7 +142,7 @@ static void image_set_header(void *ptr,
  59. }
  60. /* Build new header */
  61. - image_set_magic(hdr, IH_MAGIC);
  62. + image_set_magic(hdr, params->magic);
  63. image_set_time(hdr, time);
  64. image_set_size(hdr, imagesize);
  65. image_set_load(hdr, addr);
  66. --- a/tools/imagetool.h
  67. +++ b/tools/imagetool.h
  68. @@ -67,6 +67,7 @@ struct image_tool_params {
  69. int arch;
  70. int type;
  71. int comp;
  72. + unsigned int magic;
  73. char *dtc;
  74. unsigned int addr;
  75. unsigned int ep;