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
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.
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>
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(-)
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.
33 config MIPS_RAW_APPENDED_DTB
35 + bool "vmlinux.bin or vmlinuz.bin"
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).
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.
48 - config MIPS_ZBOOT_APPENDED_DTB
50 - depends on SYS_SUPPORTS_ZBOOT
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).
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.
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.
68 --- a/arch/mips/boot/compressed/decompress.c
69 +++ b/arch/mips/boot/compressed/decompress.c
71 #include <linux/types.h>
72 #include <linux/kernel.h>
73 #include <linux/string.h>
74 +#include <linux/libfdt.h>
76 #include <asm/addrspace.h>
78 @@ -36,6 +37,8 @@ extern void puthex(unsigned long long va
79 #define puthex(val) do {} while (0)
82 +extern char __appended_dtb[];
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);
91 + if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) &&
92 + fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) {
93 + unsigned int image_size, dtb_size;
95 + dtb_size = fdt_totalsize((void *)&__appended_dtb);
97 + /* last four bytes is always image size in little endian */
98 + image_size = le32_to_cpup((void *)&__image_end - 4);
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);
105 /* FIXME: should we flush cache here? */
106 puts("Now, booting the kernel...\n");
108 --- a/arch/mips/boot/compressed/head.S
109 +++ b/arch/mips/boot/compressed/head.S
110 @@ -25,22 +25,6 @@ start:
114 -#ifdef CONFIG_MIPS_ZBOOT_APPENDED_DTB
115 - PTR_LA t0, __appended_dtb
116 -#ifdef CONFIG_CPU_BIG_ENDIAN
122 - bne t1, t2, not_found