901-01-ARM-decompressor-support-memory-start-validation-.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 2f86b9b71a11f86e3d850214ab781ebb17d7260e Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Fri, 19 Jan 2024 19:48:30 +0100
  4. Subject: [PATCH v2 1/2] ARM: decompressor: support memory start validation for
  5. appended DTB
  6. There is currently a problem with a very specific sets of kernel config
  7. and AUTO_ZRELADDR.
  8. For the most common case AUTO_ZRELADDR check the PC register and
  9. calculate the start of the physical memory. Then fdt_check_mem_start is
  10. called to make sure the detected value makes sense by comparing it with
  11. what is present in DTB in the memory nodes and if additional fixup are
  12. required with the use of linux,usable-memory-range in the chosen node to
  13. hardcode usable memory range in case some reserved space needs to be
  14. addressed. With the help of this function the right address is
  15. calculated and the kernel correctly decompress and loads.
  16. Things starts to become problematic when in the mix,
  17. CONFIG_ARM_APPENDED_DTB is used. This is a particular kernel config is
  18. used when legacy systems doesn't support passing a DTB directly and a
  19. DTB is appended at the end of the image.
  20. In such case, fdt_check_mem_start is skipped in AUTO_ZRELADDR iteration
  21. as the appended DTB can be augumented later with ATAGS passed from the
  22. bootloader (if CONFIG_ARM_ATAG_DTB_COMPAT is enabled).
  23. The main problem and what this patch address is the fact that
  24. fdt_check_mem_start is never called later when the appended DTB is
  25. augumented, hence any fixup and validation is not done making AUTO_ZRELADDR
  26. detection inconsistent and most of the time wrong.
  27. Add support in head.S for this by checking if AUTO_ZRELADDR is enabled
  28. and calling fdt_check_mem_start with the appended DTB and the augumented
  29. values permitting legacy device to provide info in DTB instead of
  30. disabling AUTO_ZRELADDR and hardcoding the physical address offsets.
  31. Signed-off-by: Christian Marangi <[email protected]>
  32. Reviewed-by: Geert Uytterhoeven <[email protected]>
  33. Reviewed-by: Linus Walleij <[email protected]>
  34. ---
  35. arch/arm/boot/compressed/head.S | 22 ++++++++++++++++++++++
  36. 1 file changed, 22 insertions(+)
  37. --- a/arch/arm/boot/compressed/head.S
  38. +++ b/arch/arm/boot/compressed/head.S
  39. @@ -443,6 +443,28 @@ restart: adr r0, LC1
  40. add r6, r6, r5
  41. add r10, r10, r5
  42. add sp, sp, r5
  43. +
  44. +#ifdef CONFIG_AUTO_ZRELADDR
  45. + /*
  46. + * Validate calculated start of physical memory with appended DTB.
  47. + * In the first iteration for physical memory start calculation,
  48. + * we skipped validating it as it could have been augumented by
  49. + * ATAGS stored at an offset from the same start of physical memory.
  50. + *
  51. + * We now have parsed them and augumented the appended DTB if asked
  52. + * so we can finally validate the start of physical memory.
  53. + *
  54. + * This is needed to apply additional fixup with
  55. + * linux,usable-memory-range or to make sure AUTO_ZRELADDR detected
  56. + * the correct value.
  57. + */
  58. + sub r0, r4, #TEXT_OFFSET @ revert to base address
  59. + mov r1, r8 @ use appended DTB
  60. + bl fdt_check_mem_start
  61. +
  62. + /* Determine final kernel image address. */
  63. + add r4, r0, #TEXT_OFFSET
  64. +#endif
  65. dtb_check_done:
  66. #endif