metag: copy devicetree to non-init memory
authorJames Hogan <james.hogan@imgtec.com>
Wed, 20 Feb 2013 13:59:13 +0000 (13:59 +0000)
committerJames Hogan <james.hogan@imgtec.com>
Sat, 2 Mar 2013 20:11:17 +0000 (20:11 +0000)
Make a copy of the device tree blob in non-init memory. It is required
when using built-in device tree files that the platform code copies the
blob to non-init memory prior to calling unflatten_device_tree(),
otherwise the strings that the device tree refer to will get poisoned
and potentially reused, breaking later reading of the device tree
post-init (such as compatible matching in modules, debugfs, and the
procfs interface).

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Reviewed-by: Vineet Gupta <vgupta@synopsys.com>
arch/metag/include/asm/prom.h
arch/metag/kernel/devtree.c
arch/metag/kernel/setup.c

index d881396c392c1a781eef9acac7e3339698ea2752..ccac97e865d0d7a95eb1fe9368ebe81fcefa1999 100644 (file)
@@ -18,6 +18,7 @@
 #define HAVE_ARCH_DEVTREE_FIXUPS
 
 extern struct machine_desc *setup_machine_fdt(void *dt);
+extern void copy_fdt(void);
 extern void metag_dt_memblock_reserve(void);
 
 #endif /* __ASM_METAG_PROM_H */
index 5b6b1d8554928d058b81d48d95396ac61cacebcc..7cd02529636e955bdc2db86f24d993892b6463ee 100644 (file)
@@ -95,3 +95,20 @@ struct machine_desc * __init setup_machine_fdt(void *dt)
 
        return mdesc_best;
 }
+
+/**
+ * copy_fdt - Copy device tree into non-init memory.
+ *
+ * We must copy the flattened device tree blob into non-init memory because the
+ * unflattened device tree will reference the strings in it directly.
+ */
+void __init copy_fdt(void)
+{
+       void *alloc = early_init_dt_alloc_memory_arch(
+                       be32_to_cpu(initial_boot_params->totalsize), 0x40);
+       if (alloc) {
+               memcpy(alloc, initial_boot_params,
+                      be32_to_cpu(initial_boot_params->totalsize));
+               initial_boot_params = alloc;
+       }
+}
index dd6c5ad739171ae26425264f5d5563f22bc85353..879246170aecb7443123f734bed77c050b88eba5 100644 (file)
@@ -406,6 +406,8 @@ void __init setup_arch(char **cmdline_p)
        cpu_2_hwthread_id[smp_processor_id()] = hard_processor_id();
        hwthread_id_2_cpu[hard_processor_id()] = smp_processor_id();
 
+       /* Copy device tree blob into non-init memory before unflattening */
+       copy_fdt();
        unflatten_device_tree();
 
 #ifdef CONFIG_SMP
This page took 0.026848 seconds and 5 git commands to generate.