Skip to contentSkip to conversation

MIPS: add vmlinu{x,z}.bin appended dtb support

RFC PATCH In review Jonas Gorski 2 participants 6 messages Apr 12, 2015 – Apr 18, 2015 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover MIPS: add vmlinu{x,z}.bin appended dtb support

This patch series implements vmlinux.bin and vmlinuz.bin appended dtb support, and adds a user for the vmlinux one.

The first two patches add the appropriate support for vmlinux.bin and vmlinuz.bin. Since enabling it for both does not make sense (and is potentially dangerous) I made it a choice for which variant it should be enabled.

Patches three and four then add BMIPS as a test user for this implementation. vmlinuz.bin was tested by selecting SYS_SUPPORTS_ZBOOT and setting zload-y to 0x81000000 (ramstart + 16 MiB, so the kernel is loaded behind CFE), then wrapping vmlinuz_w_dtb.bin in the CFE expected lzma with appropriate header to unpack there.

For easier testing/using I changed boot/dts/brcm to build all dts files as dtb blobs in case no built in dtb is selected.

Completely untested on anything except MIPS32 / big endian.

Obviously it won't work with an ELF kernel. I did not have a reasonable idea how to do that except by parsing the elf header from head.S, and that seemed a bit insane.

Regards
Jonas

Changes RFC v2 -> v3
* Switched to UHI specs interface instead of manipulating initial_boot_params
* fixed boot on !SMP
* Changed PTR_LW to lw and PTR_LI to li to ensure 32bit loads/ comparisons are done also on 64 bit
* Added vmlinuz.bin support
* Added bmips as a user

Changes RFC v1 -> v2

* changed all occurences of vmlinux to vmlinux.bin
* clarified this applies to the raw vmlinux.bin without decompressor
* s/initial_device_params/initial_boot_params/

Jonas Gorski (4):
MIPS: add support for vmlinux.bin appended dtb
MIPS: add support for vmlinuz.bin appended dtb
MIPS: BMIPS: build all dtbs if no builtin dtb
MIPS: BMIPS: accept UHI interface for passing a dtb

 arch/mips/Kconfig                   |   45 +++++++++++++++++++++++++++++++++++
 arch/mips/bmips/setup.c             |    2 ++
 arch/mips/boot/compressed/head.S    |   16 +++++++++++++
 arch/mips/boot/compressed/ld.script |    6 ++++-
 arch/mips/boot/dts/brcm/Makefile    |   13 ++++++++++
 arch/mips/kernel/head.S             |   16 +++++++++++++
 arch/mips/kernel/vmlinux.lds.S      |    8 ++++++-
 7 files changed, 104 insertions(+), 2 deletions(-)
Signature · 5 lines
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1428834301-12721-1-git-send-email-jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org

#2 lore raw

RFC PATCH v3 1/4 MIPS: add support for vmlinux.bin appended dtb

Add support for detecting a vmlinux.bin appended dtb and overriding the boot arguments to match the UHI interface.

Due to the PERCPU section being empty for !SMP, but still modifying the current address by aligning it to the page size, do not define it for !SMP builds to allow __appended_dtb to still point to the actual end of the data.

---
Changes RFC v2 -> v3

* Switched to UHI interface instead of manipulating initial_boot_params
* fixed boot on !SMP
* Changed PTR_LW to lw and PTR_LI to li to ensure 32bit loads/ comparisons are done on 64 bit

Changes RFC v1 -> v2

* changed all occurences of vmlinux to vmlinux.bin
* clarified this applies to the raw vmlinux.bin without decompressor
* s/initial_device_params/initial_boot_params/

 arch/mips/Kconfig              |   27 +++++++++++++++++++++++++++
 arch/mips/kernel/head.S        |   16 ++++++++++++++++
 arch/mips/kernel/vmlinux.lds.S |    8 +++++++-
 3 files changed, 50 insertions(+), 1 deletion(-)
arch/mips/Kconfig +27 -0
index 779dcae..0986619 100644
@@ -2672,6 +2672,33 @@ config USE_OF
 config BUILTIN_DTB
 	bool
 
+choice
+	prompt "Kernel appended dtb support" if OF
+	default MIPS_NO_APPENDED_DTB
+
+	config MIPS_NO_APPENDED_DTB
+		bool "None"
+		help
+		  Do not enable appended dtb support.
+
+	config MIPS_RAW_APPENDED_DTB
+		bool "vmlinux.bin"
+		help
+		  With this option, the boot code will look for a device tree binary
+		  DTB) appended to raw vmlinux.bin (without decompressor).
+		  (e.g. cat vmlinux.bin <filename>.dtb > vmlinux_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 vmlinux.bin.  Do not leave this option active in a production kernel
+		  if you don't intend to always append a DTB.
+endchoice
+
 endmenu
 
 config LOCKDEP_SUPPORT
arch/mips/kernel/head.S +16 -0
index 95afd66..4e4cc5b 100644
@@ -94,6 +94,22 @@ NESTED(kernel_entry, 16, sp)			# kernel entry point
 	jr	t0
 0:
 
+#ifdef CONFIG_MIPS_RAW_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		a1, t0
+	PTR_LI		a0, -2
+not_found:
+#endif
 	PTR_LA		t0, __bss_start		# clear .bss
 	LONG_S		zero, (t0)
 	PTR_LA		t1, __bss_stop - LONGSIZE
arch/mips/kernel/vmlinux.lds.S +7 -1
index 3b46f7c..07d32a4 100644
@@ -125,8 +125,14 @@ SECTIONS
 	.exit.data : {
 		EXIT_DATA
 	}
-
+#ifdef CONFIG_SMP
 	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
+#endif
+#ifdef CONFIG_MIPS_RAW_APPENDED_DTB
+	__appended_dtb = .;
+	/* leave space for appended DTB */
+	. += 0x100000;
+#endif
 	/*
 	 * Align to 64K in attempt to eliminate holes before the
 	 * .bss..swapper_pg_dir section at the start of .bss.  This
Signature · 5 lines
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

RFC PATCH v3 2/4 MIPS: add support for vmlinuz.bin appended dtb

In reply to a message not in the archive

Add support for detecting a vmlinuz.bin appended dtb and overriding the boot arguments to match the UHI interface.

To ensure _edata / __apendend_dtb points to the actual end of the binary, align the data section to 16 bytes instead of the address cursor.

Due to ld.script not going through the preprocessor, we can't check for MIPS_ZBOOT_APPENDED_DTB being enabled, so always reserve space for it. It should have no consequences for booting without it enabled except 1 MiB more ram usage during the uncompressing stage.

---
 arch/mips/Kconfig                   |   18 ++++++++++++++++++
 arch/mips/boot/compressed/head.S    |   16 ++++++++++++++++
 arch/mips/boot/compressed/ld.script |    6 +++++-
 3 files changed, 39 insertions(+), 1 deletion(-)
arch/mips/Kconfig +18 -0
index 0986619..8aef377 100644
@@ -2697,6 +2697,24 @@ 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
 
 endmenu
arch/mips/boot/compressed/head.S +16 -0
index 409cb48..c580e85 100644
@@ -25,6 +25,22 @@ 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
arch/mips/boot/compressed/ld.script +5 -1
index 5a33409..2ed08fb 100644
@@ -29,8 +29,12 @@ SECTIONS
 		*(.image)
 		__image_end = .;
 		CONSTRUCTORS
+		. = ALIGN(16);
 	}
-	. = ALIGN(16);
+	__appended_dtb = .;
+	/* leave space for appended DTB */
+	. += 0x100000;
+
 	_edata = .;
 	/* End of data section */
 
Signature · 5 lines
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

RFC PATCH v3 3/4 MIPS: BMIPS: build all dtbs if no builtin dtb

In reply to a message not in the archive

Build all available dtbs to allow them to be appended to the resulting kernel in case there is no builtin dtb.

---
 arch/mips/boot/dts/brcm/Makefile |   13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/mips/boot/dts/brcm/Makefile +13 -0
index 1c8353b..c641216 100644
@@ -10,6 +10,19 @@ dtb-$(CONFIG_DT_BCM97362SVMB)		+= bcm97362svmb.dtb
 dtb-$(CONFIG_DT_BCM97420C)		+= bcm97420c.dtb
 dtb-$(CONFIG_DT_BCM97425SVMB)		+= bcm97425svmb.dtb
 
+dtb-$(CONFIG_DT_NONE)			+= \
+						bcm93384wvg.dtb		\
+						bcm93384wvg_viper.dtb	\
+						bcm96368mvwg.dtb	\
+						bcm9ejtagprb.dtb	\
+						bcm97125cbmb.dtb	\
+						bcm97346dbsmb.dtb	\
+						bcm97358svmb.dtb	\
+						bcm97360svmb.dtb	\
+						bcm97362svmb.dtb	\
+						bcm97420c.dtb		\
+						bcm97425svmb.dtb
+
 obj-y				+= $(patsubst %.dtb, %.dtb.o, $(dtb-y))
 
 # Force kbuild to make empty built-in.o if necessary
Signature · 5 lines
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

RFC PATCH v3 4/4 MIPS: BMIPS: accept UHI interface for passing a dtb

In reply to a message not in the archive

Detect and use passed dtb address using the UHI interface. This allows for booting with a vmlinux.bin appended dtb instead of using a built-in one.

---
 arch/mips/bmips/setup.c |    2 ++
 1 file changed, 2 insertions(+)
arch/mips/bmips/setup.c +2 -0
index fae800e..526ec27 100644
@@ -149,6 +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 (__dtb_start != __dtb_end)
 		dtb = (void *)__dtb_start;
 	else
Signature · 5 lines
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1428834301-12721-5-git-send-email-jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org

#7 lore raw

Re: [PATCH RFC v3 4/4] MIPS: BMIPS: accept UHI interface for passing a dtb

Quoted 2 lines · Jonas Gorski

Detect and use passed dtb address using the UHI interface. This allows for booting with a vmlinux.bin appended dtb instead of using a built-in one.

No particular objections to this change, current platforms support by this change fall under 3 categories:

- BCM7xxx using a CFE providing a firmware interface you call into using code from arch/mips/fw/cfe/
- BCM63xx CFE
- BCM33xx using Aeolus [1]

The first two are likely not going to be changed since these are currently deployed products/systems, however the latter could be changed to match UHI as Kevin proposed a while ago.

Quoted 12 lines
---
 arch/mips/bmips/setup.c |    2 ++
 1 file changed, 2 insertions(+)
arch/mips/bmips/setup.c +0 -0
index fae800e..526ec27 100644

arch/mips/bmips/setup.c void __init plat_mem_setup(void) · line 156

Quoted 8 lines
arch/mips/bmips/setup.c +2 -0
@@ -149,6 +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 (__dtb_start != __dtb_end)
 		dtb = (void *)__dtb_start;
 	else

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html