092-MIPS-ZBOOT-copy-appended-dtb-to-the-end-of-the-kerne.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. From b8f54f2cde788623f41d11327688c75aed34092f Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <jogo@openwrt.org>
  3. Date: Mon, 20 Jun 2016 11:27:36 +0200
  4. Subject: [PATCH 1/2] MIPS: ZBOOT: copy appended dtb to the end of the kernel
  5. Instead of rewriting the arguments, just move the appended dtb to where
  6. the decompressed kernel expects it. This eliminates the need for special
  7. casing vmlinuz.bin appended dtb files.
  8. Signed-off-by: Jonas Gorski <jogo@openwrt.org>
  9. Cc: Kevin Cernekee <cernekee@gmail.com>
  10. Cc: Florian Fainelli <f.fainelli@gmail.com>
  11. Cc: John Crispin <john@phrozen.org>
  12. Cc: Paul Burton <paul.burton@imgtec.com>
  13. Cc: James Hogan <james.hogan@imgtec.com>
  14. Cc: Alban Bedel <albeu@free.fr>
  15. Cc: Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
  16. Cc: Antony Pavlov <antonynpavlov@gmail.com>
  17. Cc: linux-mips@linux-mips.org
  18. Patchwork: https://patchwork.linux-mips.org/patch/13698/
  19. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  20. ---
  21. arch/mips/Kconfig | 22 ++--------------------
  22. arch/mips/boot/compressed/decompress.c | 17 +++++++++++++++++
  23. arch/mips/boot/compressed/head.S | 16 ----------------
  24. 3 files changed, 19 insertions(+), 36 deletions(-)
  25. --- a/arch/mips/Kconfig
  26. +++ b/arch/mips/Kconfig
  27. @@ -2754,10 +2754,10 @@ choice
  28. the documented boot protocol using a device tree.
  29. config MIPS_RAW_APPENDED_DTB
  30. - bool "vmlinux.bin"
  31. + bool "vmlinux.bin or vmlinuz.bin"
  32. help
  33. With this option, the boot code will look for a device tree binary
  34. - DTB) appended to raw vmlinux.bin (without decompressor).
  35. + DTB) appended to raw vmlinux.bin or vmlinuz.bin.
  36. (e.g. cat vmlinux.bin <filename>.dtb > vmlinux_w_dtb).
  37. This is meant as a backward compatibility convenience for those
  38. @@ -2769,24 +2769,6 @@ choice
  39. look like a DTB header after a reboot if no actual DTB is appended
  40. to vmlinux.bin. Do not leave this option active in a production kernel
  41. if you don't intend to always append a DTB.
  42. -
  43. - config MIPS_ZBOOT_APPENDED_DTB
  44. - bool "vmlinuz.bin"
  45. - depends on SYS_SUPPORTS_ZBOOT
  46. - help
  47. - With this option, the boot code will look for a device tree binary
  48. - DTB) appended to raw vmlinuz.bin (with decompressor).
  49. - (e.g. cat vmlinuz.bin <filename>.dtb > vmlinuz_w_dtb).
  50. -
  51. - This is meant as a backward compatibility convenience for those
  52. - systems with a bootloader that can't be upgraded to accommodate
  53. - the documented boot protocol using a device tree.
  54. -
  55. - Beware that there is very little in terms of protection against
  56. - this option being confused by leftover garbage in memory that might
  57. - look like a DTB header after a reboot if no actual DTB is appended
  58. - to vmlinuz.bin. Do not leave this option active in a production kernel
  59. - if you don't intend to always append a DTB.
  60. endchoice
  61. choice
  62. --- a/arch/mips/boot/compressed/decompress.c
  63. +++ b/arch/mips/boot/compressed/decompress.c
  64. @@ -14,6 +14,7 @@
  65. #include <linux/types.h>
  66. #include <linux/kernel.h>
  67. #include <linux/string.h>
  68. +#include <linux/libfdt.h>
  69. #include <asm/addrspace.h>
  70. @@ -36,6 +37,8 @@ extern void puthex(unsigned long long va
  71. #define puthex(val) do {} while (0)
  72. #endif
  73. +extern char __appended_dtb[];
  74. +
  75. void error(char *x)
  76. {
  77. puts("\n\n");
  78. @@ -114,6 +117,20 @@ void decompress_kernel(unsigned long boo
  79. __decompress((char *)zimage_start, zimage_size, 0, 0,
  80. (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error);
  81. + if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) &&
  82. + fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) {
  83. + unsigned int image_size, dtb_size;
  84. +
  85. + dtb_size = fdt_totalsize((void *)&__appended_dtb);
  86. +
  87. + /* last four bytes is always image size in little endian */
  88. + image_size = le32_to_cpup((void *)&__image_end - 4);
  89. +
  90. + /* copy dtb to where the booted kernel will expect it */
  91. + memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size,
  92. + __appended_dtb, dtb_size);
  93. + }
  94. +
  95. /* FIXME: should we flush cache here? */
  96. puts("Now, booting the kernel...\n");
  97. }
  98. --- a/arch/mips/boot/compressed/head.S
  99. +++ b/arch/mips/boot/compressed/head.S
  100. @@ -25,22 +25,6 @@ start:
  101. move s2, a2
  102. move s3, a3
  103. -#ifdef CONFIG_MIPS_ZBOOT_APPENDED_DTB
  104. - PTR_LA t0, __appended_dtb
  105. -#ifdef CONFIG_CPU_BIG_ENDIAN
  106. - li t1, 0xd00dfeed
  107. -#else
  108. - li t1, 0xedfe0dd0
  109. -#endif
  110. - lw t2, (t0)
  111. - bne t1, t2, not_found
  112. - nop
  113. -
  114. - move s1, t0
  115. - PTR_LI s0, -2
  116. -not_found:
  117. -#endif
  118. -
  119. /* Clear BSS */
  120. PTR_LA a0, _edata
  121. PTR_LA a2, _end