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