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