Skip to content

Commit

Permalink
MIPS: ZBOOT: copy appended dtb to the end of the kernel
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Kevin Cernekee <[email protected]>
Cc: Florian Fainelli <[email protected]>
Cc: John Crispin <[email protected]>
Cc: Paul Burton <[email protected]>
Cc: James Hogan <[email protected]>
Cc: Alban Bedel <[email protected]>
Cc: Daniel Gimpelevich <[email protected]>
Cc: Antony Pavlov <[email protected]>
Cc: [email protected]
Patchwork: https://patchwork.linux-mips.org/patch/13698/
Signed-off-by: Ralf Baechle <[email protected]>
  • Loading branch information
KanjiMonster authored and ralfbaechle committed Aug 2, 2016
1 parent 7997789 commit b8f54f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
22 changes: 2 additions & 20 deletions arch/mips/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2884,10 +2884,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
Expand All @@ -2899,24 +2899,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
Expand Down
17 changes: 17 additions & 0 deletions arch/mips/boot/compressed/decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/libfdt.h>

#include <asm/addrspace.h>

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

extern char __appended_dtb[];

void error(char *x)
{
puts("\n\n");
Expand Down Expand Up @@ -114,6 +117,20 @@ void decompress_kernel(unsigned long boot_heap_start)
__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");
}
16 changes: 0 additions & 16 deletions arch/mips/boot/compressed/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8f54f2

Please sign in to comment.