[LEDE-DEV] [PATCH] kernel: preserve bootargs when using appended dtb

Hauke Mehrtens hauke at hauke-m.de
Thu Aug 25 14:20:16 PDT 2016


backport a patch from upstream Linux kernel which stores the appended
dtb not in the same resisters as defined in the UHI specification, use
a separate variable on MIPS.

Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>
---
 ...copy-appended-dtb-to-the-end-of-the-kerne.patch | 132 +++++++++++++++++++++
 ...re-the-appended-dtb-address-in-a-variable.patch | 121 +++++++++++++++++++
 .../patches-4.4/300-mips_expose_boot_raw.patch     |   2 +-
 ...re-the-appended-dtb-address-in-a-variable.patch |  49 ++++++++
 4 files changed, 303 insertions(+), 1 deletion(-)
 create mode 100644 target/linux/generic/patches-4.4/092-MIPS-ZBOOT-copy-appended-dtb-to-the-end-of-the-kerne.patch
 create mode 100644 target/linux/generic/patches-4.4/093-MIPS-store-the-appended-dtb-address-in-a-variable.patch
 create mode 100644 target/linux/lantiq/patches-4.4/122-MIPS-store-the-appended-dtb-address-in-a-variable.patch

diff --git a/target/linux/generic/patches-4.4/092-MIPS-ZBOOT-copy-appended-dtb-to-the-end-of-the-kerne.patch b/target/linux/generic/patches-4.4/092-MIPS-ZBOOT-copy-appended-dtb-to-the-end-of-the-kerne.patch
new file mode 100644
index 0000000..71df429
--- /dev/null
+++ b/target/linux/generic/patches-4.4/092-MIPS-ZBOOT-copy-appended-dtb-to-the-end-of-the-kerne.patch
@@ -0,0 +1,132 @@
+From b8f54f2cde788623f41d11327688c75aed34092f Mon Sep 17 00:00:00 2001
+From: Jonas Gorski <jogo at openwrt.org>
+Date: Mon, 20 Jun 2016 11:27:36 +0200
+Subject: [PATCH 1/2] MIPS: ZBOOT: copy appended dtb to the end of the kernel
+
+Instead of rewriting the arguments, just move the appended dtb to where
+the decompressed kernel expects it. This eliminates the need for special
+casing vmlinuz.bin appended dtb files.
+
+Signed-off-by: Jonas Gorski <jogo at openwrt.org>
+Cc: Kevin Cernekee <cernekee at gmail.com>
+Cc: Florian Fainelli <f.fainelli at gmail.com>
+Cc: John Crispin <john at phrozen.org>
+Cc: Paul Burton <paul.burton at imgtec.com>
+Cc: James Hogan <james.hogan at imgtec.com>
+Cc: Alban Bedel <albeu at free.fr>
+Cc: Daniel Gimpelevich <daniel at gimpelevich.san-francisco.ca.us>
+Cc: Antony Pavlov <antonynpavlov at gmail.com>
+Cc: linux-mips at linux-mips.org
+Patchwork: https://patchwork.linux-mips.org/patch/13698/
+Signed-off-by: Ralf Baechle <ralf at linux-mips.org>
+---
+ arch/mips/Kconfig                      | 22 ++--------------------
+ arch/mips/boot/compressed/decompress.c | 17 +++++++++++++++++
+ arch/mips/boot/compressed/head.S       | 16 ----------------
+ 3 files changed, 19 insertions(+), 36 deletions(-)
+
+--- a/arch/mips/Kconfig
++++ b/arch/mips/Kconfig
+@@ -2752,10 +2752,10 @@ choice
+ 		  the documented boot protocol using a device tree.
+ 
+ 	config MIPS_RAW_APPENDED_DTB
+-		bool "vmlinux.bin"
++		bool "vmlinux.bin or vmlinuz.bin"
+ 		help
+ 		  With this option, the boot code will look for a device tree binary
+-		  DTB) appended to raw vmlinux.bin (without decompressor).
++		  DTB) appended to raw vmlinux.bin or vmlinuz.bin.
+ 		  (e.g. cat vmlinux.bin <filename>.dtb > vmlinux_w_dtb).
+ 
+ 		  This is meant as a backward compatibility convenience for those
+@@ -2767,24 +2767,6 @@ choice
+ 		  look like a DTB header after a reboot if no actual DTB is appended
+ 		  to vmlinux.bin.  Do not leave this option active in a production kernel
+ 		  if you don't intend to always append a DTB.
+-
+-	config MIPS_ZBOOT_APPENDED_DTB
+-		bool "vmlinuz.bin"
+-		depends on SYS_SUPPORTS_ZBOOT
+-		help
+-		  With this option, the boot code will look for a device tree binary
+-		  DTB) appended to raw vmlinuz.bin (with decompressor).
+-		  (e.g. cat vmlinuz.bin <filename>.dtb > vmlinuz_w_dtb).
+-
+-		  This is meant as a backward compatibility convenience for those
+-		  systems with a bootloader that can't be upgraded to accommodate
+-		  the documented boot protocol using a device tree.
+-
+-		  Beware that there is very little in terms of protection against
+-		  this option being confused by leftover garbage in memory that might
+-		  look like a DTB header after a reboot if no actual DTB is appended
+-		  to vmlinuz.bin.  Do not leave this option active in a production kernel
+-		  if you don't intend to always append a DTB.
+ endchoice
+ 
+ choice
+--- a/arch/mips/boot/compressed/decompress.c
++++ b/arch/mips/boot/compressed/decompress.c
+@@ -14,6 +14,7 @@
+ #include <linux/types.h>
+ #include <linux/kernel.h>
+ #include <linux/string.h>
++#include <linux/libfdt.h>
+ 
+ #include <asm/addrspace.h>
+ 
+@@ -36,6 +37,8 @@ extern void puthex(unsigned long long va
+ #define puthex(val) do {} while (0)
+ #endif
+ 
++extern char __appended_dtb[];
++
+ void error(char *x)
+ {
+ 	puts("\n\n");
+@@ -114,6 +117,20 @@ void decompress_kernel(unsigned long boo
+ 	__decompress((char *)zimage_start, zimage_size, 0, 0,
+ 		   (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error);
+ 
++	if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) &&
++	    fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) {
++		unsigned int image_size, dtb_size;
++
++		dtb_size = fdt_totalsize((void *)&__appended_dtb);
++
++		/* last four bytes is always image size in little endian */
++		image_size = le32_to_cpup((void *)&__image_end - 4);
++
++		/* copy dtb to where the booted kernel will expect it */
++		memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size,
++		       __appended_dtb, dtb_size);
++	}
++
+ 	/* FIXME: should we flush cache here? */
+ 	puts("Now, booting the kernel...\n");
+ }
+--- a/arch/mips/boot/compressed/head.S
++++ b/arch/mips/boot/compressed/head.S
+@@ -25,22 +25,6 @@ start:
+ 	move	s2, a2
+ 	move	s3, a3
+ 
+-#ifdef CONFIG_MIPS_ZBOOT_APPENDED_DTB
+-	PTR_LA	t0, __appended_dtb
+-#ifdef CONFIG_CPU_BIG_ENDIAN
+-	li	t1, 0xd00dfeed
+-#else
+-	li	t1, 0xedfe0dd0
+-#endif
+-	lw	t2, (t0)
+-	bne	t1, t2, not_found
+-	 nop
+-
+-	move	s1, t0
+-	PTR_LI	s0, -2
+-not_found:
+-#endif
+-
+ 	/* Clear BSS */
+ 	PTR_LA	a0, _edata
+ 	PTR_LA	a2, _end
diff --git a/target/linux/generic/patches-4.4/093-MIPS-store-the-appended-dtb-address-in-a-variable.patch b/target/linux/generic/patches-4.4/093-MIPS-store-the-appended-dtb-address-in-a-variable.patch
new file mode 100644
index 0000000..643e473
--- /dev/null
+++ b/target/linux/generic/patches-4.4/093-MIPS-store-the-appended-dtb-address-in-a-variable.patch
@@ -0,0 +1,121 @@
+From 15f37e1588920e010f20b53f04af94e91b8ee714 Mon Sep 17 00:00:00 2001
+From: Jonas Gorski <jogo at openwrt.org>
+Date: Mon, 20 Jun 2016 11:27:37 +0200
+Subject: [PATCH] MIPS: store the appended dtb address in a variable
+
+Instead of rewriting the arguments to match the UHI spec, store the
+address of a appended or UHI supplied dtb in fw_supplied_dtb.
+
+That way the original bootloader arugments are kept intact while still
+making the use of an appended dtb invisible for mach code.
+
+Mach code can still find out if it is an appended dtb by comparing
+fw_arg1 with fw_supplied_dtb.
+
+Signed-off-by: Jonas Gorski <jogo at openwrt.org>
+Cc: Kevin Cernekee <cernekee at gmail.com>
+Cc: Florian Fainelli <f.fainelli at gmail.com>
+Cc: John Crispin <john at phrozen.org>
+Cc: Paul Burton <paul.burton at imgtec.com>
+Cc: James Hogan <james.hogan at imgtec.com>
+Cc: Alban Bedel <albeu at free.fr>
+Cc: Daniel Gimpelevich <daniel at gimpelevich.san-francisco.ca.us>
+Cc: Antony Pavlov <antonynpavlov at gmail.com>
+Cc: linux-mips at linux-mips.org
+Patchwork: https://patchwork.linux-mips.org/patch/13699/
+Signed-off-by: Ralf Baechle <ralf at linux-mips.org>
+---
+ arch/mips/ath79/setup.c          |  4 ++--
+ arch/mips/bmips/setup.c          |  4 ++--
+ arch/mips/include/asm/bootinfo.h |  4 ++++
+ arch/mips/kernel/head.S          | 21 ++++++++++++++-------
+ arch/mips/kernel/setup.c         |  4 ++++
+ arch/mips/lantiq/prom.c          |  4 ++--
+ arch/mips/pic32/pic32mzda/init.c |  4 ++--
+ 7 files changed, 30 insertions(+), 15 deletions(-)
+
+--- a/arch/mips/bmips/setup.c
++++ b/arch/mips/bmips/setup.c
+@@ -149,8 +149,8 @@ void __init plat_mem_setup(void)
+ 	/* intended to somewhat resemble ARM; see Documentation/arm/Booting */
+ 	if (fw_arg0 == 0 && fw_arg1 == 0xffffffff)
+ 		dtb = phys_to_virt(fw_arg2);
+-	else if (fw_arg0 == -2) /* UHI interface */
+-		dtb = (void *)fw_arg1;
++	else if (fw_passed_dtb) /* UHI interface */
++		dtb = (void *)fw_passed_dtb;
+ 	else if (__dtb_start != __dtb_end)
+ 		dtb = (void *)__dtb_start;
+ 	else
+--- a/arch/mips/include/asm/bootinfo.h
++++ b/arch/mips/include/asm/bootinfo.h
+@@ -127,6 +127,10 @@ extern char arcs_cmdline[COMMAND_LINE_SI
+  */
+ extern unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
+ 
++#ifdef CONFIG_USE_OF
++extern unsigned long fw_passed_dtb;
++#endif
++
+ /*
+  * Platform memory detection hook called by setup_arch
+  */
+--- a/arch/mips/kernel/head.S
++++ b/arch/mips/kernel/head.S
+@@ -94,21 +94,24 @@ NESTED(kernel_entry, 16, sp)			# kernel
+ 	jr	t0
+ 0:
+ 
++#ifdef CONFIG_USE_OF
+ #ifdef CONFIG_MIPS_RAW_APPENDED_DTB
+-	PTR_LA		t0, __appended_dtb
++	PTR_LA		t2, __appended_dtb
+ 
+ #ifdef CONFIG_CPU_BIG_ENDIAN
+ 	li		t1, 0xd00dfeed
+ #else
+ 	li		t1, 0xedfe0dd0
+ #endif
+-	lw		t2, (t0)
+-	bne		t1, t2, not_found
+-	 nop
+-
+-	move		a1, t0
+-	PTR_LI		a0, -2
+-not_found:
++	lw		t0, (t2)
++	beq		t0, t1, dtb_found
++#endif
++	li		t1, -2
++	beq		a0, t1, dtb_found
++	move		t2, a1
++
++	li		t2, 0
++dtb_found:
+ #endif
+ 	PTR_LA		t0, __bss_start		# clear .bss
+ 	LONG_S		zero, (t0)
+@@ -123,6 +126,10 @@ not_found:
+ 	LONG_S		a2, fw_arg2
+ 	LONG_S		a3, fw_arg3
+ 
++#ifdef CONFIG_USE_OF
++	LONG_S		t2, fw_passed_dtb
++#endif
++
+ 	MTC0		zero, CP0_CONTEXT	# clear context register
+ 	PTR_LA		$28, init_thread_union
+ 	/* Set the SP after an empty pt_regs.  */
+--- a/arch/mips/kernel/setup.c
++++ b/arch/mips/kernel/setup.c
+@@ -814,6 +814,10 @@ void __init setup_arch(char **cmdline_p)
+ unsigned long kernelsp[NR_CPUS];
+ unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
+ 
++#ifdef CONFIG_USE_OF
++unsigned long fw_passed_dtb;
++#endif
++
+ #ifdef CONFIG_DEBUG_FS
+ struct dentry *mips_debugfs_dir;
+ static int __init debugfs_mips(void)
diff --git a/target/linux/generic/patches-4.4/300-mips_expose_boot_raw.patch b/target/linux/generic/patches-4.4/300-mips_expose_boot_raw.patch
index cd7d28a..76c7078 100644
--- a/target/linux/generic/patches-4.4/300-mips_expose_boot_raw.patch
+++ b/target/linux/generic/patches-4.4/300-mips_expose_boot_raw.patch
@@ -18,7 +18,7 @@ Acked-by: Rob Landley <rob at landley.net>
  config CEVT_BCM1480
  	bool
  
-@@ -2810,6 +2807,18 @@ choice
+@@ -2792,6 +2789,18 @@ choice
  		bool "Bootloader kernel arguments if available"
  endchoice
  
diff --git a/target/linux/lantiq/patches-4.4/122-MIPS-store-the-appended-dtb-address-in-a-variable.patch b/target/linux/lantiq/patches-4.4/122-MIPS-store-the-appended-dtb-address-in-a-variable.patch
new file mode 100644
index 0000000..a6641bf
--- /dev/null
+++ b/target/linux/lantiq/patches-4.4/122-MIPS-store-the-appended-dtb-address-in-a-variable.patch
@@ -0,0 +1,49 @@
+From 15f37e1588920e010f20b53f04af94e91b8ee714 Mon Sep 17 00:00:00 2001
+From: Jonas Gorski <jogo at openwrt.org>
+Date: Mon, 20 Jun 2016 11:27:37 +0200
+Subject: [PATCH] MIPS: store the appended dtb address in a variable
+
+Instead of rewriting the arguments to match the UHI spec, store the
+address of a appended or UHI supplied dtb in fw_supplied_dtb.
+
+That way the original bootloader arugments are kept intact while still
+making the use of an appended dtb invisible for mach code.
+
+Mach code can still find out if it is an appended dtb by comparing
+fw_arg1 with fw_supplied_dtb.
+
+Signed-off-by: Jonas Gorski <jogo at openwrt.org>
+Cc: Kevin Cernekee <cernekee at gmail.com>
+Cc: Florian Fainelli <f.fainelli at gmail.com>
+Cc: John Crispin <john at phrozen.org>
+Cc: Paul Burton <paul.burton at imgtec.com>
+Cc: James Hogan <james.hogan at imgtec.com>
+Cc: Alban Bedel <albeu at free.fr>
+Cc: Daniel Gimpelevich <daniel at gimpelevich.san-francisco.ca.us>
+Cc: Antony Pavlov <antonynpavlov at gmail.com>
+Cc: linux-mips at linux-mips.org
+Patchwork: https://patchwork.linux-mips.org/patch/13699/
+Signed-off-by: Ralf Baechle <ralf at linux-mips.org>
+---
+ arch/mips/ath79/setup.c          |  4 ++--
+ arch/mips/bmips/setup.c          |  4 ++--
+ arch/mips/include/asm/bootinfo.h |  4 ++++
+ arch/mips/kernel/head.S          | 21 ++++++++++++++-------
+ arch/mips/kernel/setup.c         |  4 ++++
+ arch/mips/lantiq/prom.c          |  4 ++--
+ arch/mips/pic32/pic32mzda/init.c |  4 ++--
+ 7 files changed, 30 insertions(+), 15 deletions(-)
+
+--- a/arch/mips/lantiq/prom.c
++++ b/arch/mips/lantiq/prom.c
+@@ -74,8 +74,8 @@ void __init plat_mem_setup(void)
+ 
+ 	set_io_port_base((unsigned long) KSEG1);
+ 
+-	if (fw_arg0 == -2) /* UHI interface */
+-		dtb = (void *)fw_arg1;
++	if (fw_passed_dtb) /* UHI interface */
++		dtb = (void *)fw_passed_dtb;
+ 	else if (__dtb_start != __dtb_end)
+ 		dtb = (void *)__dtb_start;
+ 	else
-- 
2.9.3




More information about the Lede-dev mailing list