[MIPS] Ranchu platform Appended DTB support
authorMiodrag Dinic <miodrag.dinic@imgtec.com>
Tue, 25 Nov 2014 17:31:30 +0000 (18:31 +0100)
committerRaghu Gandham <raghu.gandham@imgtec.com>
Tue, 2 Dec 2014 23:30:20 +0000 (15:30 -0800)
With CONFIG_MIPS_APPENDED_DTB=y option enabled, the boot code
will look for a device tree binary (dtb) appended to raw
vmlinux.bin (without decompressor).
(e.g. cat vmlinux.bin <filename>.dtb > vmlinux_w_dtb).

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.bin.

Change-Id: Ia1d7e0e4fe3848385b84cb06b04ea480897946f9
Reviewed-on: https://mipsia.review.mips.com/2860
Reviewed-by: Raghu Gandham <raghu.gandham@imgtec.com>
Tested-by: Raghu Gandham <raghu.gandham@imgtec.com>
arch/mips/Kconfig
arch/mips/goldfish/Makefile
arch/mips/goldfish/goldfish-platform.c
arch/mips/include/asm/mips-boards/generic.h
arch/mips/kernel/head.S
arch/mips/kernel/prom.c
arch/mips/kernel/vmlinux.lds.S

index 79ca0e2a699b22952098f1af85f06451e71d63b2..897591216a876f8a30e3205b4c77f9a2b1879e02 100644 (file)
@@ -2499,6 +2499,20 @@ config USE_OF
        select OF_EARLY_FLATTREE
        select IRQ_DOMAIN
 
+config MIPS_APPENDED_DTB
+       bool "Use appended device tree blob to vmlinux.bin (EXPERIMENTAL)"
+       depends on OF && MIPS_RANCHU
+       help
+         With this option, the boot code will look for a device tree binary
+         DTB) appended to raw vmlinux.bin (without decompressor).
+         (e.g. cat vmlinux.bin <filename>.dtb > vmlinux_w_dtb).
+
+         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.bin. Do not leave this option active in a production kernel
+         if you don't intend to always append a DTB.
+
 endmenu
 
 config LOCKDEP_SUPPORT
index e48f32ccad4c8005b145b78759395250c8660c51..4d8535f50c2eac502b2c62f0b5b9cfc92f8d39fb 100644 (file)
@@ -10,7 +10,9 @@ obj-$(CONFIG_GOLDFISH)        += goldfish-time.o
 obj-$(CONFIG_GOLDFISH) += switch.o
 obj-$(CONFIG_GOLDFISH) += pm.o
 
-obj-$(CONFIG_MIPS_RANCHU)      += ranchu.dtb.o
+ifneq ($(CONFIG_MIPS_APPENDED_DTB), y)
+obj-$(CONFIG_MIPS_RANCHU)        += ranchu.dtb.o
 
 $(obj)/%.dtb: $(obj)/%.dts
        $(call if_changed,dtc)
+endif
index 63139f204cca483615b96a2f05146dc94b4155e8..286b0e305a58a282055cc849e377134bec38c60b 100644 (file)
@@ -58,10 +58,17 @@ const char *get_system_type(void)
 void __init plat_mem_setup(void)
 {
        /*
-        * Load the builtin devicetree. This causes the chosen node to be
+        * Load the builtin or appended devicetree.
+        * This causes the chosen node to be
         * parsed resulting in our memory appearing
         */
+#ifdef CONFIG_MIPS_APPENDED_DTB
+       pr_info("Try setup using Appended DTB\n");
+       __dt_setup_arch(&__appended_dtb);
+#else
+       pr_info("Try setup using Built-in DTB\n");
        __dt_setup_arch(&__dtb_start);
+#endif
 }
 
 void __init device_tree_init(void)
index 48616816bcbc9073b3184e83a6276dad687d6feb..dc7cfbcc5643780fae45e6589750b32d05449315 100644 (file)
@@ -69,6 +69,9 @@ extern int mips_revision_sconid;
 
 #ifdef CONFIG_OF
 extern struct boot_param_header __dtb_start;
+#ifdef CONFIG_MIPS_APPENDED_DTB
+extern struct boot_param_header __appended_dtb;
+#endif
 #endif
 
 #ifdef CONFIG_PCI
index 4a4c4f174143b96dacb71a26ee3a9773c14ed329..aa98896fbb27668ccae2cfe2f22a1ba07eaef9d1 100644 (file)
@@ -179,6 +179,23 @@ NESTED(kernel_entry, 16, sp)                       # kernel entry point
        mtc0    t0, CP0_STATUS
 #endif /* CONFIG_MIPS_MT_SMTC */
 
+#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
@@ -192,6 +209,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.  */
index 32b87882ac87795fd1e2bc2baed7f98f408e39f9..3b0bf5d4f988b9a1e98a22da9c2f1af8086fd91a 100644 (file)
@@ -101,7 +101,11 @@ void __init early_init_devtree(void *params)
 void __init __dt_setup_arch(struct boot_param_header *bph)
 {
        if (be32_to_cpu(bph->magic) != OF_DT_HEADER) {
+#ifdef CONFIG_MIPS_APPENDED_DTB
+               pr_err("DTB has bad magic, ignoring appended OF DTB\n");
+#else
                pr_err("DTB has bad magic, ignoring builtin OF DTB\n");
+#endif
 
                return;
        }
index 05826d20a7923a47d06a7affb196f6388c6f1d70..7ed2fe5dd3775c6cd4f5a6b6c2ee0c1b162d4596 100644 (file)
@@ -145,6 +145,12 @@ SECTIONS
 
        _end = . ;
 
+#ifdef CONFIG_MIPS_APPENDED_DTB
+       __appended_dtb = .;
+       /* leave space for appended DTB */
+       . = . + 0x100000;
+#endif
+
        /* These mark the ABI of the kernel for debuggers.  */
        .mdebug.abi32 : {
                KEEP(*(.mdebug.abi32))