002-0028-tools-mtk_image-split-gfh-header-verification-into-a.patch 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. From b6bb61fd3818f4a3025fedbe4d15dbeeaef6ee82 Mon Sep 17 00:00:00 2001
  2. From: Weijie Gao <[email protected]>
  3. Date: Tue, 2 Aug 2022 17:21:34 +0800
  4. Subject: [PATCH 28/31] tools: mtk_image: split gfh header verification into a
  5. new function
  6. The verification code of gfh header for NAND and non-NAND are identical.
  7. It's better to define a individual function to reduce redundancy.
  8. Reviewed-by: Simon Glass <[email protected]>
  9. Signed-off-by: Weijie Gao <[email protected]>
  10. ---
  11. tools/mtk_image.c | 51 +++++++++++++++++++----------------------------
  12. 1 file changed, 21 insertions(+), 30 deletions(-)
  13. --- a/tools/mtk_image.c
  14. +++ b/tools/mtk_image.c
  15. @@ -480,6 +480,25 @@ static int mtk_image_vrec_header(struct
  16. return SHA256_SUM_LEN;
  17. }
  18. +static int mtk_image_verify_gfh(struct gfh_header *gfh, uint32_t type, int print)
  19. +{
  20. + if (strcmp(gfh->file_info.name, GFH_FILE_INFO_NAME))
  21. + return -1;
  22. +
  23. + if (le32_to_cpu(gfh->file_info.flash_type) != type)
  24. + return -1;
  25. +
  26. + if (print)
  27. + printf("Load Address: %08x\n",
  28. + le32_to_cpu(gfh->file_info.load_addr) +
  29. + le32_to_cpu(gfh->file_info.jump_offset));
  30. +
  31. + if (print)
  32. + printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
  33. +
  34. + return 0;
  35. +}
  36. +
  37. static int mtk_image_verify_gen_header(const uint8_t *ptr, int print)
  38. {
  39. union gen_boot_header *gbh = (union gen_boot_header *)ptr;
  40. @@ -542,21 +561,7 @@ static int mtk_image_verify_gen_header(c
  41. gfh = (struct gfh_header *)(ptr + gfh_offset);
  42. - if (strcmp(gfh->file_info.name, GFH_FILE_INFO_NAME))
  43. - return -1;
  44. -
  45. - if (le32_to_cpu(gfh->file_info.flash_type) != GFH_FLASH_TYPE_GEN)
  46. - return -1;
  47. -
  48. - if (print)
  49. - printf("Load Address: %08x\n",
  50. - le32_to_cpu(gfh->file_info.load_addr) +
  51. - le32_to_cpu(gfh->file_info.jump_offset));
  52. -
  53. - if (print)
  54. - printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
  55. -
  56. - return 0;
  57. + return mtk_image_verify_gfh(gfh, GFH_FLASH_TYPE_GEN, print);
  58. }
  59. static int mtk_image_verify_nand_header(const uint8_t *ptr, int print)
  60. @@ -610,21 +615,7 @@ static int mtk_image_verify_nand_header(
  61. gfh = (struct gfh_header *)(ptr + 2 * le16_to_cpu(nh->pagesize));
  62. - if (strcmp(gfh->file_info.name, GFH_FILE_INFO_NAME))
  63. - return -1;
  64. -
  65. - if (le32_to_cpu(gfh->file_info.flash_type) != GFH_FLASH_TYPE_NAND)
  66. - return -1;
  67. -
  68. - if (print)
  69. - printf("Load Address: %08x\n",
  70. - le32_to_cpu(gfh->file_info.load_addr) +
  71. - le32_to_cpu(gfh->file_info.jump_offset));
  72. -
  73. - if (print)
  74. - printf("Architecture: %s\n", is_arm64_image ? "ARM64" : "ARM");
  75. -
  76. - return 0;
  77. + return mtk_image_verify_gfh(gfh, GFH_FLASH_TYPE_NAND, print);
  78. }
  79. static uint32_t crc32be_cal(const void *data, size_t length)