0001-Add-tool-to-dump-sunxi-images.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From b4e67c5112b8d8ec8f9255af057c3515c5ea71c1 Mon Sep 17 00:00:00 2001
  2. From: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
  3. Date: Sat, 29 May 2021 19:14:22 +0200
  4. Subject: [PATCH] Add tool to dump sunxi images
  5. $./tools/dumpimage -l ~/work/temp/lime1.img
  6. Allwinner eGON image, size: 24576 bytes
  7. SPL header version 0.2
  8. DT name: sun7i-a20-olinuxino-lime2-emmc
  9. $ ./tools/dumpimage -l ~/work/temp/parabola.img
  10. Allwinner eGON image, size: 24576 bytes
  11. SPL header version 0.2
  12. DT name: sun7i-a20-olinuxino-lime2-emmc
  13. TODO:
  14. - why do we have the lime2 dt detected above? is the
  15. env a leftover from the previous image somehow?
  16. - Handle block devices:
  17. $ sudo ./tools/dumpimage -l /dev/sdb
  18. Image Type: MVEBU Boot from (null) Image
  19. Image version:0
  20. Data Size: -4 Bytes = 4194304.00 KiB = 4096.00 MiB
  21. Load Address: 00000000
  22. Entry Point: 00000000
  23. - Make it easily parsable by tools
  24. - Force type to sunxi_egon
  25. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
  26. ---
  27. tools/dumpimage.c | 16 +++++++++++++---
  28. 1 file changed, 13 insertions(+), 3 deletions(-)
  29. diff --git a/tools/dumpimage.c b/tools/dumpimage.c
  30. index e5481435a7..9d0d0c448b 100644
  31. --- a/tools/dumpimage.c
  32. +++ b/tools/dumpimage.c
  33. @@ -71,6 +71,9 @@ int main(int argc, char **argv)
  34. char *ptr;
  35. int retval = EXIT_SUCCESS;
  36. struct image_type_params *tparams = NULL;
  37. + off_t offset = 0;
  38. +
  39. + offset = 8192; /* Allwinner SOCs */
  40. params.cmdname = *argv;
  41. @@ -159,6 +162,14 @@ int main(int argc, char **argv)
  42. exit(EXIT_FAILURE);
  43. }
  44. + /* Handle block devices */
  45. + if (sbuf.st_size == 0) {
  46. + /* 1M should be sufficient as we have the first partition that
  47. + * is typically aligned at 1M for MBR partitioning.
  48. + */
  49. + sbuf.st_size = 1024*1024;
  50. + }
  51. +
  52. if ((uint32_t)sbuf.st_size < tparams->header_size) {
  53. fprintf(stderr, "%s: Bad size: \"%s\" is not valid image\n",
  54. params.cmdname, params.imagefile);
  55. @@ -182,7 +193,7 @@ int main(int argc, char **argv)
  56. * Extract the data files from within the matched
  57. * image type. Returns the error code if not matched
  58. */
  59. - retval = dumpimage_extract_subimage(tparams, ptr, &sbuf);
  60. + retval = dumpimage_extract_subimage(tparams, ptr + offset, &sbuf);
  61. if (retval)
  62. fprintf(stderr, "%s: Can't extract subimage from %s\n",
  63. params.cmdname, params.imagefile);
  64. @@ -191,10 +202,9 @@ int main(int argc, char **argv)
  65. * Print the image information for matched image type
  66. * Returns the error code if not matched
  67. */
  68. - retval = imagetool_verify_print_header(ptr, &sbuf, tparams,
  69. + retval = imagetool_verify_print_header(ptr + offset, &sbuf, tparams,
  70. &params);
  71. }
  72. -
  73. (void)munmap((void *)ptr, sbuf.st_size);
  74. (void)close(ifd);
  75. --
  76. 2.31.1