Skip to contentSkip to conversation

MIPS: add support for vmlinux appended DTB

RFC PATCH Superseded Jonas Gorski 2 participants 3 messages Jul 8, 2014 – Jul 9, 2014 MIPS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 MIPS: add support for vmlinux appended DTB

Add support for populating initial_device_params through a dtb blob appended to vmlinux.

---
Mostly adapted from how ARM is doing it.

Sent as an RFC PATCH because I am not sure if this is the right way to it, and whether storing the pointer in initial_device_params is a good idea, or a new variable should be introduced.

The reasoning for initial_device_params is that there is no common MIPS interface yet, so the next best thing was using that. This also has the advantage of keeping the original fw_args intact.

This patch works for me on bcm63xx, where the bootloade expects an lzma compressed kernel, so I wanted to not double compress using the in-kernel compressed kernel support.

Completely untested on anything except MIPS32 / big endian.

 arch/mips/Kconfig              | 18 ++++++++++++++++++
 arch/mips/kernel/head.S        | 19 +++++++++++++++++++
 arch/mips/kernel/vmlinux.lds.S |  6 ++++++
 3 files changed, 43 insertions(+)
arch/mips/Kconfig +18 -0
index 3f05b56..58527cd 100644
@@ -2476,6 +2476,24 @@ config USE_OF
 	select OF_EARLY_FLATTREE
 	select IRQ_DOMAIN
 
+config MIPS_APPENDED_DTB
+	bool "Use appended device tree blob to vmlinux (EXPERIMENTAL)"
+	depends on OF
+	help
+	  With this option, the boot code will look for a device tree binary
+	  DTB) appended to vmlinux
+	  (e.g. cat vmlinux <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.  Do not leave this option active in a production kernel
+	  if you don't intend to always append a DTB.
+
 endmenu
 
 config LOCKDEP_SUPPORT
arch/mips/kernel/head.S +19 -0
index 95afd66..72c1049 100644
@@ -93,7 +93,22 @@ NESTED(kernel_entry, 16, sp)			# kernel entry point
 	PTR_LA	t0, 0f
 	jr	t0
 0:
+#ifdef CONFIG_MIPS_APPENDED_DTB
+	PTR_LA		t0, __appended_dtb
+	PTR_LI		t3, 0
 
+#ifdef CONFIG_CPU_BIG_ENDIAN
+	PTR_LI		t1, 0xd00dfeed
+#else
+	PTR_LI		t1, 0xedfe0dd0
+#endif
+	LONG_L		t2, (t0)
+	bne		t1, t2, not_found
+
+	PTR_LA		t3, __appended_dtb
+
+not_found:
+#endif
 	PTR_LA		t0, __bss_start		# clear .bss
 	LONG_S		zero, (t0)
 	PTR_LA		t1, __bss_stop - LONGSIZE
@@ -107,6 +122,10 @@ NESTED(kernel_entry, 16, sp)			# kernel entry point
 	LONG_S		a2, fw_arg2
 	LONG_S		a3, fw_arg3
 
+#ifdef CONFIG_MIPS_APPENDED_DTB
+	LONG_S		t3, initial_boot_params
+#endif
+
 	MTC0		zero, CP0_CONTEXT	# clear context register
 	PTR_LA		$28, init_thread_union
 	/* Set the SP after an empty pt_regs.  */
arch/mips/kernel/vmlinux.lds.S +6 -0
index 3b46f7c..8009530 100644
@@ -127,6 +127,12 @@ SECTIONS
 	}
 
 	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
+
+#ifdef CONFIG_MIPS_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 · 1 line
2.0.0
#1 lore raw

Hi Jonas,

Quoted 1 line · Jonas Gorski

Add support for populating initial_device_params through a dtb

initial_boot_params here and above?

Quoted 1 line

blob appended to vmlinux.

should that be vmlinux.bin? Presumably it isn't appended to the ELF file?

Quoted 5 lines

---
Mostly adapted from how ARM is doing it.

Quoted 7 lines

Sent as an RFC PATCH because I am not sure if this is the right way to it, and whether storing the pointer in initial_device_params is a good idea, or a new variable should be introduced.

The reasoning for initial_device_params is that there is no common MIPS interface yet, so the next best thing was using that. This also has the advantage of keeping the original fw_args intact.

Does it matter that this will be ignored if the bootloader does provide a DT (initial_boot_params overwritten by early_init_dt_scan() call), and that if no DT is provided by the bootloader the of_scan_flat_dt() calls at the bottom of early_init_dt_scan will never happen?

Quoted 2 lines

This patch works for me on bcm63xx, where the bootloade expects

s/bootloade/bootloader/

Quoted 15 lines

an lzma compressed kernel, so I wanted to not double compress using the in-kernel compressed kernel support.

Completely untested on anything except MIPS32 / big endian.

 arch/mips/Kconfig              | 18 ++++++++++++++++++
 arch/mips/kernel/head.S        | 19 +++++++++++++++++++
 arch/mips/kernel/vmlinux.lds.S |  6 ++++++
 3 files changed, 43 insertions(+)
arch/mips/Kconfig +0 -0
index 3f05b56..58527cd 100644

arch/mips/Kconfig config USE_OF · line 2484

Quoted 9 lines
arch/mips/Kconfig +6 -0
@@ -2476,6 +2476,24 @@ config USE_OF
 	select OF_EARLY_FLATTREE
 	select IRQ_DOMAIN
 
+config MIPS_APPENDED_DTB
+	bool "Use appended device tree blob to vmlinux (EXPERIMENTAL)"
+	depends on OF
+	help
+	  With this option, the boot code will look for a device tree binary
+	  DTB) appended to vmlinux

s/DTB)/(DTB)/

vmlinux.bin again?

arch/mips/Kconfig config USE_OF · line 2485

Quoted 1 line
arch/mips/Kconfig +1 -0
+	  (e.g. cat vmlinux <filename>.dtb > vmlinux_w_dtb).

here too I think.

arch/mips/Kconfig config USE_OF · line 2494

Quoted 9 lines
arch/mips/Kconfig +9 -0
+
+	  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.  Do not leave this option active in a production kernel

maybe same here too.

Can't fault the rest though.

Cheers
James

Quoted 61 lines
arch/mips/Kconfig +2 -0
+	  if you don't intend to always append a DTB.
+
 endmenu
 
 config LOCKDEP_SUPPORT
arch/mips/kernel/head.S +19 -0
index 95afd66..72c1049 100644
@@ -93,7 +93,22 @@ NESTED(kernel_entry, 16, sp)			# kernel entry point
 	PTR_LA	t0, 0f
 	jr	t0
 0:
+#ifdef CONFIG_MIPS_APPENDED_DTB
+	PTR_LA		t0, __appended_dtb
+	PTR_LI		t3, 0
 
+#ifdef CONFIG_CPU_BIG_ENDIAN
+	PTR_LI		t1, 0xd00dfeed
+#else
+	PTR_LI		t1, 0xedfe0dd0
+#endif
+	LONG_L		t2, (t0)
+	bne		t1, t2, not_found
+
+	PTR_LA		t3, __appended_dtb
+
+not_found:
+#endif
 	PTR_LA		t0, __bss_start		# clear .bss
 	LONG_S		zero, (t0)
 	PTR_LA		t1, __bss_stop - LONGSIZE
@@ -107,6 +122,10 @@ NESTED(kernel_entry, 16, sp)			# kernel entry point
 	LONG_S		a2, fw_arg2
 	LONG_S		a3, fw_arg3
 
+#ifdef CONFIG_MIPS_APPENDED_DTB
+	LONG_S		t3, initial_boot_params
+#endif
+
 	MTC0		zero, CP0_CONTEXT	# clear context register
 	PTR_LA		$28, init_thread_union
 	/* Set the SP after an empty pt_regs.  */
arch/mips/kernel/vmlinux.lds.S +6 -0
index 3b46f7c..8009530 100644
@@ -127,6 +127,12 @@ SECTIONS
 	}
 
 	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
+
+#ifdef CONFIG_MIPS_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
#2 lore raw
Quoted 6 lines · James Hogan

Hi Jonas,

Quoted 1 line · Jonas Gorski

Add support for populating initial_device_params through a dtb

initial_boot_params here and above?

Yes, that's what I meant. I must have been distracted by the thunderstorm outside.

Quoted 4 lines
Quoted 2 lines

blob appended to vmlinux.

should that be vmlinux.bin? Presumably it isn't appended to the ELF file?

Hmmm, you are right, indeed it should. I was always taking the OpenWrt names for granted, so I never looked at how the kernel itself named them. OpenWrt uses "vmlinux" for binary only, and "vmlinux.elf" for the unstripped elf one.

As far as I can tell, there is no simple vmlinux.bin target without the decompressor wrapper included, but for the description I will change the name and clarify that I am talking about a binary kernel without the decompressing wrapper.

Quoted 10 lines
Quoted 10 lines

---
Mostly adapted from how ARM is doing it.

Sent as an RFC PATCH because I am not sure if this is the right way to it, and whether storing the pointer in initial_device_params is a good idea, or a new variable should be introduced.

Quoted 8 lines
Quoted 3 lines

The reasoning for initial_device_params is that there is no common MIPS interface yet, so the next best thing was using that. This also has the advantage of keeping the original fw_args intact.

Does it matter that this will be ignored if the bootloader does provide a DT (initial_boot_params overwritten by early_init_dt_scan() call), and that if no DT is provided by the bootloader the of_scan_flat_dt() calls at the bottom of early_init_dt_scan will never happen?

Since (AFAIK) there is no common interface on mips for a bootloader to pass a dtb to the kernel, it is currently up to the individual targets to do something with an appended dtb, and decide which one has a higher priority. They already need to manually "extract" the passed dtb from the bootloader and pass it to the kernel, so all this patch does is provide another source for one.

Quoted 32 lines
Quoted 2 lines

This patch works for me on bcm63xx, where the bootloade expects

s/bootloade/bootloader/

Quoted 15 lines

an lzma compressed kernel, so I wanted to not double compress using the in-kernel compressed kernel support.

Completely untested on anything except MIPS32 / big endian.

 arch/mips/Kconfig              | 18 ++++++++++++++++++
 arch/mips/kernel/head.S        | 19 +++++++++++++++++++
 arch/mips/kernel/vmlinux.lds.S |  6 ++++++
 3 files changed, 43 insertions(+)
arch/mips/Kconfig +0 -0
index 3f05b56..58527cd 100644

arch/mips/Kconfig config USE_OF · line 2484

Quoted 9 lines
arch/mips/Kconfig +6 -0
@@ -2476,6 +2476,24 @@ config USE_OF
      select OF_EARLY_FLATTREE
      select IRQ_DOMAIN
 
+config MIPS_APPENDED_DTB
+     bool "Use appended device tree blob to vmlinux (EXPERIMENTAL)"
+     depends on OF
+     help
+       With this option, the boot code will look for a device tree binary
+       DTB) appended to vmlinux

s/DTB)/(DTB)/

Quoted 1 line

vmlinux.bin again?

Right.

Quoted 3 lines

arch/mips/Kconfig config USE_OF · line 2485

Quoted 1 line
arch/mips/Kconfig +1 -0
+       (e.g. cat vmlinux <filename>.dtb > vmlinux_w_dtb).

here too I think.

Right again.

Quoted 11 lines

arch/mips/Kconfig config USE_OF · line 2494

Quoted 9 lines
arch/mips/Kconfig +9 -0
+
+       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.  Do not leave this option active in a production kernel

maybe same here too.

Will fix that, too.

Quoted 5 lines

Can't fault the rest though.

Cheers
James

Thanks for the review!

Jonas