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. @@ -25,6 +25,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. @@ -88,11 +89,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. @@ -163,7 +165,7 @@ static void process_args(int argc, char
  27. int opt;
  28. while ((opt = getopt(argc, argv,
  29. - "a:A:b:B:c:C:d:D:e:Ef:FG:k:i:K:ln:N:p:o:O:rR:qstT:vVx")) != -1) {
  30. + "a:A:b:B:c:C:d:D:e:Ef:FG:k:i:K:lM:n:N:p:o:O:rR:qstT:vVx")) != -1) {
  31. switch (opt) {
  32. case 'a':
  33. params.addr = strtoull(optarg, &ptr, 16);
  34. @@ -254,6 +256,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. @@ -56,7 +56,7 @@ static int image_verify_header(unsigned
  52. */
  53. memcpy(hdr, ptr, sizeof(image_header_t));
  54. - if (be32_to_cpu(hdr->ih_magic) != IH_MAGIC) {
  55. + if (be32_to_cpu(hdr->ih_magic) != params->magic) {
  56. debug("%s: Bad Magic Number: \"%s\" is no valid image\n",
  57. params->cmdname, params->imagefile);
  58. return -FDT_ERR_BADMAGIC;
  59. @@ -120,7 +120,7 @@ static void image_set_header(void *ptr,
  60. }
  61. /* Build new header */
  62. - image_set_magic(hdr, IH_MAGIC);
  63. + image_set_magic(hdr, params->magic);
  64. image_set_time(hdr, time);
  65. image_set_size(hdr, imagesize);
  66. image_set_load(hdr, addr);
  67. --- a/tools/imagetool.h
  68. +++ b/tools/imagetool.h
  69. @@ -59,6 +59,7 @@ struct image_tool_params {
  70. int arch;
  71. int type;
  72. int comp;
  73. + unsigned int magic;
  74. char *dtc;
  75. unsigned int addr;
  76. unsigned int ep;