Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jonas Gorski and committed by
Ralf Baechle
b8f54f2c 79977894

+19 -36
+2 -20
arch/mips/Kconfig
··· 2884 2884 the documented boot protocol using a device tree. 2885 2885 2886 2886 config MIPS_RAW_APPENDED_DTB 2887 - bool "vmlinux.bin" 2887 + bool "vmlinux.bin or vmlinuz.bin" 2888 2888 help 2889 2889 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. 2891 2891 (e.g. cat vmlinux.bin <filename>.dtb > vmlinux_w_dtb). 2892 2892 2893 2893 This is meant as a backward compatibility convenience for those ··· 2898 2898 this option being confused by leftover garbage in memory that might 2899 2899 look like a DTB header after a reboot if no actual DTB is appended 2900 2900 to vmlinux.bin. Do not leave this option active in a production kernel 2901 - 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 2901 if you don't intend to always append a DTB. 2920 2902 endchoice 2921 2903
+17
arch/mips/boot/compressed/decompress.c
··· 14 14 #include <linux/types.h> 15 15 #include <linux/kernel.h> 16 16 #include <linux/string.h> 17 + #include <linux/libfdt.h> 17 18 18 19 #include <asm/addrspace.h> 19 20 ··· 36 35 #define puts(s) do {} while (0) 37 36 #define puthex(val) do {} while (0) 38 37 #endif 38 + 39 + extern char __appended_dtb[]; 39 40 40 41 void error(char *x) 41 42 { ··· 116 113 /* Decompress the kernel with according algorithm */ 117 114 __decompress((char *)zimage_start, zimage_size, 0, 0, 118 115 (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error); 116 + 117 + if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) && 118 + fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) { 119 + unsigned int image_size, dtb_size; 120 + 121 + dtb_size = fdt_totalsize((void *)&__appended_dtb); 122 + 123 + /* last four bytes is always image size in little endian */ 124 + image_size = le32_to_cpup((void *)&__image_end - 4); 125 + 126 + /* copy dtb to where the booted kernel will expect it */ 127 + memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size, 128 + __appended_dtb, dtb_size); 129 + } 119 130 120 131 /* FIXME: should we flush cache here? */ 121 132 puts("Now, booting the kernel...\n");
-16
arch/mips/boot/compressed/head.S
··· 25 25 move s2, a2 26 26 move s3, a3 27 27 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 - 44 28 /* Clear BSS */ 45 29 PTR_LA a0, _edata 46 30 PTR_LA a2, _end