080-mtk_image-add-support-for-booting-ARM64-images.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. From 44165e4c676d266f73fda2e6ba82b4bf3262daf2 Mon Sep 17 00:00:00 2001
  2. From: Fabien Parent <[email protected]>
  3. Date: Fri, 16 Oct 2020 19:52:37 +0200
  4. Subject: [PATCH] tools: mtk_image: add support for booting ARM64 images
  5. mkimage is only able to package aarch32 binaries. Add support for
  6. AArch64 images.
  7. One can create a ARM64 image using the following command line:
  8. mkimage -T mtk_image -a 0x201000 -e 0x201000 -n "media=emmc;arm64=1"
  9. -d bl2.bin bl2.img
  10. Signed-off-by: Fabien Parent <[email protected]>
  11. ---
  12. tools/mtk_image.c | 28 ++++++++++++++++++++++++----
  13. tools/mtk_image.h | 6 +++++-
  14. 2 files changed, 29 insertions(+), 5 deletions(-)
  15. diff --git a/tools/mtk_image.c b/tools/mtk_image.c
  16. index 2ca519483d..bde1e5da4b 100644
  17. --- a/tools/mtk_image.c
  18. +++ b/tools/mtk_image.c
  19. @@ -246,6 +246,7 @@ static const struct brom_img_type {
  20. /* Image type selected by user */
  21. static enum brlyt_img_type hdr_media;
  22. static int use_lk_hdr;
  23. +static bool is_arm64_image;
  24. /* LK image name */
  25. static char lk_name[32] = "U-Boot";
  26. @@ -276,6 +277,7 @@ static int mtk_brom_parse_imagename(const char *imagename)
  27. static const char *media = "";
  28. static const char *nandinfo = "";
  29. static const char *lk = "";
  30. + static const char *arm64_param = "";
  31. key = buf;
  32. while (key) {
  33. @@ -323,6 +325,9 @@ static int mtk_brom_parse_imagename(const char *imagename)
  34. if (!strcmp(key, "lkname"))
  35. snprintf(lk_name, sizeof(lk_name), "%s", val);
  36. +
  37. + if (!strcmp(key, "arm64"))
  38. + arm64_param = val;
  39. }
  40. if (next)
  41. @@ -354,6 +359,9 @@ static int mtk_brom_parse_imagename(const char *imagename)
  42. }
  43. }
  44. + if (arm64_param && arm64_param[0] == '1')
  45. + is_arm64_image = true;
  46. +
  47. free(buf);
  48. if (hdr_media == BRLYT_TYPE_INVALID) {
  49. @@ -458,6 +466,9 @@ static int mtk_image_verify_gen_header(const uint8_t *ptr, int print)
  50. le32_to_cpu(gfh->file_info.load_addr) +
  51. le32_to_cpu(gfh->file_info.jump_offset));
  52. + if (print)
  53. + printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
  54. +
  55. return 0;
  56. }
  57. @@ -523,6 +534,9 @@ static int mtk_image_verify_nand_header(const uint8_t *ptr, int print)
  58. le32_to_cpu(gfh->file_info.load_addr) +
  59. le32_to_cpu(gfh->file_info.jump_offset));
  60. + if (print)
  61. + printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
  62. +
  63. return 0;
  64. }
  65. @@ -581,6 +595,8 @@ static void put_ghf_common_header(struct gfh_common_header *gfh, int size,
  66. static void put_ghf_header(struct gfh_header *gfh, int file_size,
  67. int dev_hdr_size, int load_addr, int flash_type)
  68. {
  69. + uint32_t cfg_bits;
  70. +
  71. memset(gfh, 0, sizeof(struct gfh_header));
  72. /* GFH_FILE_INFO header */
  73. @@ -608,11 +624,15 @@ static void put_ghf_header(struct gfh_header *gfh, int file_size,
  74. /* GFH_BROM_CFG header */
  75. put_ghf_common_header(&gfh->brom_cfg.gfh, sizeof(gfh->brom_cfg),
  76. GFH_TYPE_BROM_CFG, 3);
  77. - gfh->brom_cfg.cfg_bits = cpu_to_le32(
  78. - GFH_BROM_CFG_USBDL_AUTO_DETECT_DIS |
  79. - GFH_BROM_CFG_USBDL_BY_KCOL0_TIMEOUT_EN |
  80. - GFH_BROM_CFG_USBDL_BY_FLAG_TIMEOUT_EN);
  81. + cfg_bits = GFH_BROM_CFG_USBDL_AUTO_DETECT_DIS |
  82. + GFH_BROM_CFG_USBDL_BY_KCOL0_TIMEOUT_EN |
  83. + GFH_BROM_CFG_USBDL_BY_FLAG_TIMEOUT_EN;
  84. gfh->brom_cfg.usbdl_by_kcol0_timeout_ms = cpu_to_le32(5000);
  85. + if (is_arm64_image) {
  86. + gfh->brom_cfg.jump_bl_arm64 = GFH_BROM_CFG_JUMP_BL_ARM64;
  87. + cfg_bits |= GFH_BROM_CFG_JUMP_BL_ARM64_EN;
  88. + }
  89. + gfh->brom_cfg.cfg_bits = cpu_to_le32(cfg_bits);
  90. /* GFH_BL_SEC_KEY header */
  91. put_ghf_common_header(&gfh->bl_sec_key.gfh, sizeof(gfh->bl_sec_key),
  92. diff --git a/tools/mtk_image.h b/tools/mtk_image.h
  93. index 4e78b3d0ff..7dda71ce88 100644
  94. --- a/tools/mtk_image.h
  95. +++ b/tools/mtk_image.h
  96. @@ -136,7 +136,9 @@ struct gfh_brom_cfg {
  97. struct gfh_common_header gfh;
  98. uint32_t cfg_bits;
  99. uint32_t usbdl_by_auto_detect_timeout_ms;
  100. - uint8_t unused[0x48];
  101. + uint8_t unused[0x45];
  102. + uint8_t jump_bl_arm64;
  103. + uint8_t unused2[2];
  104. uint32_t usbdl_by_kcol0_timeout_ms;
  105. uint32_t usbdl_by_flag_timeout_ms;
  106. uint32_t pad;
  107. @@ -146,6 +148,8 @@ struct gfh_brom_cfg {
  108. #define GFH_BROM_CFG_USBDL_AUTO_DETECT_DIS 0x10
  109. #define GFH_BROM_CFG_USBDL_BY_KCOL0_TIMEOUT_EN 0x80
  110. #define GFH_BROM_CFG_USBDL_BY_FLAG_TIMEOUT_EN 0x100
  111. +#define GFH_BROM_CFG_JUMP_BL_ARM64_EN 0x1000
  112. +#define GFH_BROM_CFG_JUMP_BL_ARM64 0x64
  113. struct gfh_bl_sec_key {
  114. struct gfh_common_header gfh;
  115. --
  116. 2.30.1