366-MIPS-add-support-for-vmlinux.bin-appended-DTB.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. From 318c1fce4aeef298cbb6153416c499c94ad7cda0 Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <jogo@openwrt.org>
  3. Date: Tue, 24 Jun 2014 10:53:15 +0200
  4. Subject: [PATCH RFC v3] MIPS: add support for vmlinux.bin appended DTB
  5. Add support for populating initial_boot_params through a dtb
  6. blob appended to raw vmlinux.bin.
  7. Signed-off-by: Jonas Gorski <jogo@openwrt.org>
  8. ---
  9. Changes RFC v2 -> v3
  10. * fixed !smp kernels (TODO: move it to its own patch
  11. Changes RFC v1 -> v2
  12. * changed all occurences of vmlinux to vmlinux.bin
  13. * clarified this applies to the raw vmlinux.bin without decompressor
  14. * s/initial_device_params/initial_boot_params/
  15. Initial comments by me still valid:
  16. Mostly adapted from how ARM is doing it.
  17. Sent as an RFC PATCH because I am not sure if this is the right way to
  18. it, and whether storing the pointer in initial_boot_params is a good
  19. idea, or a new variable should be introduced.
  20. The reasoning for initial_boot_params is that there is no common
  21. MIPS interface yet, so the next best thing was using that. This also
  22. has the advantage of keeping the original fw_args intact.
  23. This patch works for me on bcm63xx, where the bootloader expects
  24. an lzma compressed kernel, so I didn't want to double compress using
  25. the in-kernel compressed kernel support.
  26. Completely untested on anything except MIPS32 / big endian.
  27. arch/mips/Kconfig | 18 ++++++++++++++++++
  28. arch/mips/kernel/head.S | 19 +++++++++++++++++++
  29. arch/mips/kernel/vmlinux.lds.S | 7 +++++++
  30. 3 files changed, 43 insertions(+)
  31. --- a/arch/mips/Kconfig
  32. +++ b/arch/mips/Kconfig
  33. @@ -2655,6 +2655,24 @@ config RAPIDIO
  34. source "drivers/rapidio/Kconfig"
  35. +config MIPS_APPENDED_DTB
  36. + bool "Use appended device tree blob to vmlinux.bin (EXPERIMENTAL)"
  37. + depends on OF
  38. + help
  39. + With this option, the boot code will look for a device tree binary
  40. + DTB) appended to raw vmlinux.bin (without decompressor).
  41. + (e.g. cat vmlinux.bin <filename>.dtb > vmlinux_w_dtb).
  42. +
  43. + This is meant as a backward compatibility convenience for those
  44. + systems with a bootloader that can't be upgraded to accommodate
  45. + the documented boot protocol using a device tree.
  46. +
  47. + Beware that there is very little in terms of protection against
  48. + this option being confused by leftover garbage in memory that might
  49. + look like a DTB header after a reboot if no actual DTB is appended
  50. + to vmlinux.bin. Do not leave this option active in a production kernel
  51. + if you don't intend to always append a DTB.
  52. +
  53. endmenu
  54. menu "Executable file formats"
  55. --- a/arch/mips/kernel/head.S
  56. +++ b/arch/mips/kernel/head.S
  57. @@ -100,6 +100,22 @@ NESTED(kernel_entry, 16, sp) # kernel
  58. jr t0
  59. 0:
  60. +#ifdef CONFIG_MIPS_APPENDED_DTB
  61. + PTR_LA t0, __appended_dtb
  62. + PTR_LI t3, 0
  63. +
  64. +#ifdef CONFIG_CPU_BIG_ENDIAN
  65. + PTR_LI t1, 0xd00dfeed
  66. +#else
  67. + PTR_LI t1, 0xedfe0dd0
  68. +#endif
  69. + LONG_L t2, (t0)
  70. + bne t1, t2, not_found
  71. +
  72. + PTR_LA t3, __appended_dtb
  73. +
  74. +not_found:
  75. +#endif
  76. PTR_LA t0, __bss_start # clear .bss
  77. LONG_S zero, (t0)
  78. PTR_LA t1, __bss_stop - LONGSIZE
  79. @@ -113,6 +129,10 @@ NESTED(kernel_entry, 16, sp) # kernel
  80. LONG_S a2, fw_arg2
  81. LONG_S a3, fw_arg3
  82. +#ifdef CONFIG_MIPS_APPENDED_DTB
  83. + LONG_S t3, initial_boot_params
  84. +#endif
  85. +
  86. MTC0 zero, CP0_CONTEXT # clear context register
  87. PTR_LA $28, init_thread_union
  88. /* Set the SP after an empty pt_regs. */
  89. --- a/arch/mips/kernel/vmlinux.lds.S
  90. +++ b/arch/mips/kernel/vmlinux.lds.S
  91. @@ -125,8 +125,14 @@ SECTIONS
  92. .exit.data : {
  93. EXIT_DATA
  94. }
  95. -
  96. +#ifdef CONFIG_SMP
  97. PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
  98. +#endif
  99. +#ifdef CONFIG_MIPS_APPENDED_DTB
  100. + __appended_dtb = .;
  101. + /* leave space for appended DTB */
  102. + . = . + 0x100000;
  103. +#endif
  104. /*
  105. * Align to 64K in attempt to eliminate holes before the
  106. * .bss..swapper_pg_dir section at the start of .bss. This