Skip to content

Commit b8f54f2

Browse files
KanjiMonsterralfbaechle
authored andcommitted
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@openwrt.org> Cc: Kevin Cernekee <cernekee@gmail.com> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: John Crispin <john@phrozen.org> Cc: Paul Burton <paul.burton@imgtec.com> Cc: James Hogan <james.hogan@imgtec.com> Cc: Alban Bedel <albeu@free.fr> Cc: Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us> Cc: Antony Pavlov <antonynpavlov@gmail.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/13698/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 7997789 commit b8f54f2

3 files changed

Lines changed: 19 additions & 36 deletions

File tree

‎arch/mips/Kconfig‎

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,10 +2884,10 @@ choice
28842884
the documented boot protocol using a device tree.
28852885

28862886
config MIPS_RAW_APPENDED_DTB
2887-
bool "vmlinux.bin"
2887+
bool "vmlinux.bin or vmlinuz.bin"
28882888
help
28892889
With this option, the boot code will look for a device tree binary
2890-
DTB) appended to raw vmlinux.bin (without decompressor).
2890+
DTB) appended to raw vmlinux.bin or vmlinuz.bin.
28912891
(e.g. cat vmlinux.bin <filename>.dtb > vmlinux_w_dtb).
28922892

28932893
This is meant as a backward compatibility convenience for those
@@ -2899,24 +2899,6 @@ choice
28992899
look like a DTB header after a reboot if no actual DTB is appended
29002900
to vmlinux.bin. Do not leave this option active in a production kernel
29012901
if you don't intend to always append a DTB.
2902-
2903-
config MIPS_ZBOOT_APPENDED_DTB
2904-
bool "vmlinuz.bin"
2905-
depends on SYS_SUPPORTS_ZBOOT
2906-
help
2907-
With this option, the boot code will look for a device tree binary
2908-
DTB) appended to raw vmlinuz.bin (with decompressor).
2909-
(e.g. cat vmlinuz.bin <filename>.dtb > vmlinuz_w_dtb).
2910-
2911-
This is meant as a backward compatibility convenience for those
2912-
systems with a bootloader that can't be upgraded to accommodate
2913-
the documented boot protocol using a device tree.
2914-
2915-
Beware that there is very little in terms of protection against
2916-
this option being confused by leftover garbage in memory that might
2917-
look like a DTB header after a reboot if no actual DTB is appended
2918-
to vmlinuz.bin. Do not leave this option active in a production kernel
2919-
if you don't intend to always append a DTB.
29202902
endchoice
29212903

29222904
choice

‎arch/mips/boot/compressed/decompress.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/types.h>
1515
#include <linux/kernel.h>
1616
#include <linux/string.h>
17+
#include <linux/libfdt.h>
1718

1819
#include <asm/addrspace.h>
1920

@@ -36,6 +37,8 @@ extern void puthex(unsigned long long val);
3637
#define puthex(val) do {} while (0)
3738
#endif
3839

40+
extern char __appended_dtb[];
41+
3942
void error(char *x)
4043
{
4144
puts("\n\n");
@@ -114,6 +117,20 @@ void decompress_kernel(unsigned long boot_heap_start)
114117
__decompress((char *)zimage_start, zimage_size, 0, 0,
115118
(void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error);
116119

120+
if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) &&
121+
fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) {
122+
unsigned int image_size, dtb_size;
123+
124+
dtb_size = fdt_totalsize((void *)&__appended_dtb);
125+
126+
/* last four bytes is always image size in little endian */
127+
image_size = le32_to_cpup((void *)&__image_end - 4);
128+
129+
/* copy dtb to where the booted kernel will expect it */
130+
memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size,
131+
__appended_dtb, dtb_size);
132+
}
133+
117134
/* FIXME: should we flush cache here? */
118135
puts("Now, booting the kernel...\n");
119136
}

‎arch/mips/boot/compressed/head.S‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ start:
2525
move s2, a2
2626
move s3, a3
2727

28-
#ifdef CONFIG_MIPS_ZBOOT_APPENDED_DTB
29-
PTR_LA t0, __appended_dtb
30-
#ifdef CONFIG_CPU_BIG_ENDIAN
31-
li t1, 0xd00dfeed
32-
#else
33-
li t1, 0xedfe0dd0
34-
#endif
35-
lw t2, (t0)
36-
bne t1, t2, not_found
37-
nop
38-
39-
move s1, t0
40-
PTR_LI s0, -2
41-
not_found:
42-
#endif
43-
4428
/* Clear BSS */
4529
PTR_LA a0, _edata
4630
PTR_LA a2, _end

0 commit comments

Comments
 (0)