]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
powerpc/85xx: verify the device tree before booting Linux
authorTimur Tabi <timur@freescale.com>
Tue, 3 May 2011 18:24:08 +0000 (13:24 -0500)
committerKumar Gala <galak@kernel.crashing.org>
Fri, 29 Jul 2011 13:53:39 +0000 (08:53 -0500)
Introduce ft_verify_fdt(), a function that is called after the device tree
has been fixed up, that displays warning messages if there is a mismatch
between the physical addresses of some devices that U-Boot has configured
with what the device tree says the addresses are.

This is a particular problem when booting a 36-bit device tree from a
32-bit U-Boot (or vice versa), because the physical address of CCSR is
wrong in the device tree.  When the operating system boots, no messages are
displayed, so the user generally has no idea what's wrong.

Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
arch/powerpc/cpu/mpc85xx/fdt.c
arch/powerpc/lib/bootm.c

index c62b12fb1d1124750fbd263f69cbefe34f22ac5c..8f13cd8ebf6dae0ebe39397c85bc8b63d2ece234 100644 (file)
@@ -639,3 +639,75 @@ void ft_cpu_setup(void *blob, bd_t *bd)
        do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
                        "clock_freq", gd->bus_clk, 1);
 }
+
+/*
+ * For some CCSR devices, we only have the virtual address, not the physical
+ * address.  This is because we map CCSR as a whole, so we typically don't need
+ * a macro for the physical address of any device within CCSR.  In this case,
+ * we calculate the physical address of that device using it's the difference
+ * between the virtual address of the device and the virtual address of the
+ * beginning of CCSR.
+ */
+#define CCSR_VIRT_TO_PHYS(x) \
+       (CONFIG_SYS_CCSRBAR_PHYS + ((x) - CONFIG_SYS_CCSRBAR))
+
+/*
+ * Verify the device tree
+ *
+ * This function compares several CONFIG_xxx macros that contain physical
+ * addresses with the corresponding nodes in the device tree, to see if
+ * the physical addresses are all correct.  For example, if
+ * CONFIG_SYS_NS16550_COM1 is defined, then it contains the virtual address
+ * of the first UART.  We convert this to a physical address and compare
+ * that with the physical address of the first ns16550-compatible node
+ * in the device tree.  If they don't match, then we display a warning.
+ *
+ * Returns 1 on success, 0 on failure
+ */
+int ft_verify_fdt(void *fdt)
+{
+       uint64_t ccsr = 0;
+       int aliases;
+       int off;
+
+       /* First check the CCSR base address */
+       off = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "soc", 4);
+       if (off > 0)
+               ccsr = fdt_get_base_address(fdt, off);
+
+       if (!ccsr) {
+               printf("Warning: could not determine base CCSR address in "
+                      "device tree\n");
+               /* No point in checking anything else */
+               return 0;
+       }
+
+       if (ccsr != CONFIG_SYS_CCSRBAR_PHYS) {
+               printf("Warning: U-Boot configured CCSR at address %llx,\n"
+                      "but the device tree has it at %llx\n",
+                      (uint64_t) CONFIG_SYS_CCSRBAR_PHYS, ccsr);
+               /* No point in checking anything else */
+               return 0;
+       }
+
+       /*
+        * Get the 'aliases' node.  If there isn't one, then there's nothing
+        * left to do.
+        */
+       aliases = fdt_path_offset(fdt, "/aliases");
+       if (aliases > 0) {
+#ifdef CONFIG_SYS_NS16550_COM1
+               if (!fdt_verify_alias_address(fdt, aliases, "serial0",
+                       CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM1)))
+                       return 0;
+#endif
+
+#ifdef CONFIG_SYS_NS16550_COM2
+               if (!fdt_verify_alias_address(fdt, aliases, "serial1",
+                       CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM2)))
+                       return 0;
+#endif
+       }
+
+       return 1;
+}
index 05adadabb7e38183e030a7777a352d39b461501c..137547451b342a192424477a45faae802146f8d4 100644 (file)
@@ -226,6 +226,24 @@ static int boot_bd_t_linux(bootm_headers_t *images)
        return ret;
 }
 
+/*
+ * Verify the device tree.
+ *
+ * This function is called after all device tree fix-ups have been enacted,
+ * so that the final device tree can be verified.  The definition of "verified"
+ * is up to the specific implementation.  However, it generally means that the
+ * addresses of some of the devices in the device tree are compared with the
+ * actual addresses at which U-Boot has placed them.
+ *
+ * Returns 1 on success, 0 on failure.  If 0 is returned, U-boot will halt the
+ * boot process.
+ */
+static int __ft_verify_fdt(void *fdt)
+{
+       return 1;
+}
+__attribute__((weak, alias("__ft_verify_fdt"))) int ft_verify_fdt(void *fdt);
+
 static int boot_body_linux(bootm_headers_t *images)
 {
        ulong rd_len;
@@ -298,6 +316,9 @@ static int boot_body_linux(bootm_headers_t *images)
                /* fixup the initrd now that we know where it should be */
                if (*initrd_start && *initrd_end)
                        fdt_initrd(*of_flat_tree, *initrd_start, *initrd_end, 1);
+
+               if (!ft_verify_fdt(*of_flat_tree))
+                       return -1;
        }
 #endif /* CONFIG_OF_LIBFDT */
        return 0;