Linux-MIPS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] mips: boot compressed: preprocess linker script
@ 2020-10-15 20:10 John Thomson
  2020-10-15 20:11 ` [PATCH 2/2] mips: boot compressed: add support for vlinuz ELF DTB John Thomson
  0 siblings, 1 reply; 3+ messages in thread
From: John Thomson @ 2020-10-15 20:10 UTC (permalink / raw)
  To: linux-mips; +Cc: Thomas Bogendoerfer, linux-kernel, John Thomson

Preprocess vmlinuz (self-decompressing kernel ELF) linker script
to avoid using ld -Ttext $(address)
https://lkml.kernel.org/lkml/20200413153453.zi4jvu3c4ul23e23@google.com/

Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
---
 arch/mips/boot/compressed/.gitignore                   | 1 +
 arch/mips/boot/compressed/Makefile                     | 8 ++++++--
 arch/mips/boot/compressed/{ld.script => vmlinuz.lds.S} | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)
 rename arch/mips/boot/compressed/{ld.script => vmlinuz.lds.S} (96%)

diff --git a/arch/mips/boot/compressed/.gitignore b/arch/mips/boot/compressed/.gitignore
index d358395614c..1c367a2efb9 100644
--- a/arch/mips/boot/compressed/.gitignore
+++ b/arch/mips/boot/compressed/.gitignore
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 ashldi3.c
 bswapsi.c
+vmlinuz.lds
diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
index 6e56caef69f..49d1adceade 100644
--- a/arch/mips/boot/compressed/Makefile
+++ b/arch/mips/boot/compressed/Makefile
@@ -96,11 +96,15 @@ UIMAGE_LOADADDR = $(VMLINUZ_LOAD_ADDRESS)
 
 vmlinuzobjs-y += $(obj)/piggy.o
 
+targets += vmlinuz.lds
+$(obj)/vmlinuz.lds: $(obj)/calc_vmlinuz_load_addr $(obj)/vmlinux.bin
+CPPFLAGS_vmlinuz.lds = -DVMLINUZ_LOAD_ADDRESS="$(VMLINUZ_LOAD_ADDRESS)"
+
 quiet_cmd_zld = LD      $@
-      cmd_zld = $(LD) $(KBUILD_LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@
+      cmd_zld = $(LD) $(KBUILD_LDFLAGS) -T $< $(vmlinuzobjs-y) -o $@
 quiet_cmd_strip = STRIP	  $@
       cmd_strip = $(STRIP) -s $@
-vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr
+vmlinuz: $(obj)/vmlinuz.lds $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr
 	$(call cmd,zld)
 	$(call cmd,strip)
 
diff --git a/arch/mips/boot/compressed/ld.script b/arch/mips/boot/compressed/vmlinuz.lds.S
similarity index 96%
rename from arch/mips/boot/compressed/ld.script
rename to arch/mips/boot/compressed/vmlinuz.lds.S
index 2ed08fbef8e..890c31c55c1 100644
--- a/arch/mips/boot/compressed/ld.script
+++ b/arch/mips/boot/compressed/vmlinuz.lds.S
@@ -14,7 +14,7 @@ PHDRS {
 SECTIONS
 {
 	/* Text and read-only data */
-	/* . = VMLINUZ_LOAD_ADDRESS; */
+	. = VMLINUZ_LOAD_ADDRESS;
 	.text : {
 		*(.text)
 		*(.rodata)
-- 
2.28.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] mips: boot compressed: add support for vlinuz ELF DTB
  2020-10-15 20:10 [PATCH 1/2] mips: boot compressed: preprocess linker script John Thomson
@ 2020-10-15 20:11 ` John Thomson
  2020-10-17 22:13   ` John Thomson
  0 siblings, 1 reply; 3+ messages in thread
From: John Thomson @ 2020-10-15 20:11 UTC (permalink / raw)
  To: linux-mips; +Cc: Thomas Bogendoerfer, linux-kernel, John Thomson

For legacy bootloader devices that do not support DTB,
and only support booting ELF, or have issues booting large ELF files.

vmlinux (objcopy to bytecode then compressed for vmlinuz)
requires MIPS_RAW_APPENDED_DTB, then
vmlinuz may use MIPS_ELF_APPENDED_DTB_VMLINUZ, and insert the DTB into
the ELF:

objcopy --update-section .appended_dtb=<filename>.dtb vmlinuz

Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
---
 arch/mips/Kconfig                       | 21 +++++++++++++++++++++
 arch/mips/boot/compressed/decompress.c  |  4 ++++
 arch/mips/boot/compressed/vmlinuz.lds.S |  9 +++++++++
 3 files changed, 34 insertions(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 8f328298f8c..2749d46be9e 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -3098,6 +3098,27 @@ choice
 		  if you don't intend to always append a DTB.
 endchoice
 
+config MIPS_ELF_APPENDED_DTB_VMLINUZ
+	bool "vmlinuz (ELF self-decompressing kernel) appended DTB support"
+	depends on MIPS_RAW_APPENDED_DTB && SYS_SUPPORTS_ZBOOT
+	help
+	  With this option, the vmlinuz (self-decompressing kernel ELF binary)
+	  boot code will look for a device tree binary (DTB|FDT) included in
+	  the vmlinux ELF section .appended_dtb. By default it is empty and
+	  the DTB can be appended using binutils command
+	  objcopy:
+
+	    objcopy --update-section .appended_dtb=<filename>.dtb vmlinuz
+
+	  This is meant as a backward compatiblity convenience for those
+	  systems with a bootloader that can't be upgraded to accommodate
+	  the documented boot protocol using a device tree.
+
+	  vmlinuz uses the compressed vmlinux.bin, thus vmlinux must use
+	  MIPS_RAW_APPENDED_DTB to expect a DTB at the end-of-uncompressed
+	  kernel location. vmlinuz copies the DTB to this location after kernel
+	  decompression.
+
 choice
 	prompt "Kernel command line type" if !CMDLINE_OVERRIDE
 	default MIPS_CMDLINE_FROM_DTB if USE_OF && !ATH79 && !MACH_INGENIC && \
diff --git a/arch/mips/boot/compressed/decompress.c b/arch/mips/boot/compressed/decompress.c
index 88f5d637b1c..cd1a47c69e3 100644
--- a/arch/mips/boot/compressed/decompress.c
+++ b/arch/mips/boot/compressed/decompress.c
@@ -33,7 +33,11 @@ extern void puthex(unsigned long long val);
 #define puthex(val) do {} while (0)
 #endif
 
+#ifdef CONFIG_MIPS_ELF_APPENDED_DTB_VMLINUZ
+unsigned char __section(.appended_dtb) __appended_dtb[0x100000];
+#else
 extern char __appended_dtb[];
+#endif
 
 void error(char *x)
 {
diff --git a/arch/mips/boot/compressed/vmlinuz.lds.S b/arch/mips/boot/compressed/vmlinuz.lds.S
index 890c31c55c1..f5a35b60059 100644
--- a/arch/mips/boot/compressed/vmlinuz.lds.S
+++ b/arch/mips/boot/compressed/vmlinuz.lds.S
@@ -31,9 +31,18 @@ SECTIONS
 		CONSTRUCTORS
 		. = ALIGN(16);
 	}
+
+#ifdef CONFIG_MIPS_ELF_APPENDED_DTB_VMLINUZ
+	/* keep the empty unreferenced ELF DTB section */
+	.appended_dtb : {
+		*(.appended_dtb)
+		KEEP(*(.appended_dtb))
+	}
+#else
 	__appended_dtb = .;
 	/* leave space for appended DTB */
 	. += 0x100000;
+#endif /* _APPENDED_DTB */
 
 	_edata = .;
 	/* End of data section */
-- 
2.28.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] mips: boot compressed: add support for vlinuz ELF DTB
  2020-10-15 20:11 ` [PATCH 2/2] mips: boot compressed: add support for vlinuz ELF DTB John Thomson
@ 2020-10-17 22:13   ` John Thomson
  0 siblings, 0 replies; 3+ messages in thread
From: John Thomson @ 2020-10-17 22:13 UTC (permalink / raw)
  To: linux-mips; +Cc: Thomas Bogendoerfer, linux-kernel

I think it would be safer to make these changes by adding a different boot/compressed target: vmlinuz.elf?
So that this would not break kernel build cases where both a normal RAW_APPENDED_DTB zImage is wanted, and additionally an ELF boot vmlinuz.elf.

-- 
  John Thomson

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 20:10 [PATCH 1/2] mips: boot compressed: preprocess linker script John Thomson
2020-10-15 20:11 ` [PATCH 2/2] mips: boot compressed: add support for vlinuz ELF DTB John Thomson
2020-10-17 22:13   ` John Thomson

Linux-MIPS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mips/0 linux-mips/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mips linux-mips/ https://lore.kernel.org/linux-mips \
		linux-mips@vger.kernel.org
	public-inbox-index linux-mips

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-mips


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git