]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/fdt_support.c
fdt: introduce fdt_verify_alias_address() and fdt_get_base_address()
[karo-tx-uboot.git] / common / fdt_support.c
index 90e909795b04d77bcdbbf181d5b3944551f5d635..150a3c5a591dadacf72e8daafc77b199a43c47d7 100644 (file)
@@ -183,7 +183,7 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
                }
        }
 
-       err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start + 1);
+       err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start);
        if (err < 0) {
                printf("fdt_initrd: %s\n", fdt_strerror(err));
                return err;
@@ -394,9 +394,8 @@ int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
 {
        int err, nodeoffset;
        int addr_cell_len, size_cell_len, len;
-       u8 tmp[banks * 8];
+       u8 tmp[banks * 16]; /* Up to 64-bit address + 64-bit size */
        int bank;
-       const u32 *addrcell, *sizecell;
 
        err = fdt_check_header(blob);
        if (err < 0) {
@@ -955,7 +954,7 @@ static void of_bus_default_count_cells(void *blob, int parentoffset,
        if (addrc) {
                prop = fdt_getprop(blob, parentoffset, "#address-cells", NULL);
                if (prop)
-                       *addrc = be32_to_cpup(prop);
+                       *addrc = be32_to_cpup((u32 *)prop);
                else
                        *addrc = 2;
        }
@@ -963,7 +962,7 @@ static void of_bus_default_count_cells(void *blob, int parentoffset,
        if (sizec) {
                prop = fdt_getprop(blob, parentoffset, "#size-cells", NULL);
                if (prop)
-                       *sizec = be32_to_cpup(prop);
+                       *sizec = be32_to_cpup((u32 *)prop);
                else
                        *sizec = 1;
        }
@@ -1224,3 +1223,70 @@ err_size:
        return ret;
 }
 #endif
+
+/*
+ * Verify the physical address of device tree node for a given alias
+ *
+ * This function locates the device tree node of a given alias, and then
+ * verifies that the physical address of that device matches the given
+ * parameter.  It displays a message if there is a mismatch.
+ *
+ * Returns 1 on success, 0 on failure
+ */
+int fdt_verify_alias_address(void *fdt, int anode, const char *alias, u64 addr)
+{
+       const char *path;
+       const u32 *reg;
+       int node, len;
+       u64 dt_addr;
+
+       path = fdt_getprop(fdt, anode, alias, NULL);
+       if (!path) {
+               /* If there's no such alias, then it's not a failure */
+               return 1;
+       }
+
+       node = fdt_path_offset(fdt, path);
+       if (node < 0) {
+               printf("Warning: device tree alias '%s' points to invalid "
+                      "node %s.\n", alias, path);
+               return 0;
+       }
+
+       reg = fdt_getprop(fdt, node, "reg", &len);
+       if (!reg) {
+               printf("Warning: device tree node '%s' has no address.\n",
+                      path);
+               return 0;
+       }
+
+       dt_addr = fdt_translate_address(fdt, node, reg);
+       if (addr != dt_addr) {
+               printf("Warning: U-Boot configured device %s at address %llx,\n"
+                      " but the device tree has it address %llx.\n",
+                      alias, addr, dt_addr);
+               return 0;
+       }
+
+       return 1;
+}
+
+/*
+ * Returns the base address of an SOC or PCI node
+ */
+u64 fdt_get_base_address(void *fdt, int node)
+{
+       int size;
+       u32 naddr;
+       const u32 *prop;
+
+       prop = fdt_getprop(fdt, node, "#address-cells", &size);
+       if (prop && size == 4)
+               naddr = *prop;
+       else
+               naddr = 2;
+
+       prop = fdt_getprop(fdt, node, "ranges", &size);
+
+       return prop ? fdt_translate_address(fdt, node, prop + naddr) : 0;
+}