]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/fdt_support.c
fdt: fixup changes from commit 7a172ae7a3fc
[karo-tx-uboot.git] / common / fdt_support.c
index ea42c63eaafd74300374dd5734726f6a64aaf8e3..8fbe6b5132c0c98c785f32a54f31e1c17fe3ae54 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <common.h>
+#include <inttypes.h>
 #include <stdio_dev.h>
 #include <linux/ctype.h>
 #include <linux/types.h>
@@ -370,22 +371,22 @@ static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size,
                        int n)
 {
        int i;
-       int address_len = fdt_address_cells(fdt, 0);
-       int size_len = fdt_size_cells(fdt, 0);
+       int address_cells = fdt_address_cells(fdt, 0);
+       int size_cells = fdt_size_cells(fdt, 0);
        char *p = buf;
 
        for (i = 0; i < n; i++) {
-               if (address_len == 2)
+               if (address_cells == 2)
                        *(fdt64_t *)p = cpu_to_fdt64(address[i]);
                else
                        *(fdt32_t *)p = cpu_to_fdt32(address[i]);
-               p += address_len;
+               p += 4 * address_cells;
 
-               if (size_len == 2)
+               if (size_cells == 2)
                        *(fdt64_t *)p = cpu_to_fdt64(size[i]);
                else
                        *(fdt32_t *)p = cpu_to_fdt32(size[i]);
-               p += size_len;
+               p += 4 * size_cells;
        }
 
        return p - (char *)buf;
@@ -531,7 +532,8 @@ int fdt_shrink_to_minimum(void *blob)
        ret = fdt_add_mem_rsv(blob, (uintptr_t)blob, actualsize);
        if (ret < 0)
                return ret;
-
+       if (getenv("fdtsize"))
+               setenv_hex("fdtsize", actualsize);
        return actualsize;
 }
 
@@ -701,7 +703,7 @@ struct reg_cell {
        unsigned int r1;
 };
 
-int fdt_del_subnodes(const void *blob, int parent_offset)
+static int fdt_del_subnodes(const void *blob, int parent_offset)
 {
        int off, ndepth;
        int ret;
@@ -709,18 +711,22 @@ int fdt_del_subnodes(const void *blob, int parent_offset)
        for (ndepth = 0, off = fdt_next_node(blob, parent_offset, &ndepth);
             (off >= 0) && (ndepth > 0);
             off = fdt_next_node(blob, off, &ndepth)) {
-               if (ndepth == 1) {
-                       debug("delete %s: offset: %x\n",
-                               fdt_get_name(blob, off, 0), off);
-                       ret = fdt_del_node((void *)blob, off);
-                       if (ret < 0) {
-                               printf("Can't delete node: %s\n",
-                                       fdt_strerror(ret));
-                               return ret;
-                       } else {
-                               ndepth = 0;
-                               off = parent_offset;
-                       }
+               if (ndepth < 0)
+                       break;
+               else if (ndepth != 1)
+                       continue;
+               else if (fdt_getprop(blob, off, "compatible", NULL))
+                       continue;
+               debug("delete %s: offset: %x\n",
+                       fdt_get_name(blob, off, 0), off);
+               ret = fdt_del_node((void *)blob, off);
+               if (ret < 0) {
+                       printf("Can't delete node: %s\n",
+                               fdt_strerror(ret));
+                       return ret;
+               } else {
+                       ndepth = 0;
+                       off = parent_offset;
                }
        }
        return 0;
@@ -730,11 +736,16 @@ int fdt_del_partitions(void *blob, int parent_offset)
 {
        const void *prop;
        int ndepth = 0;
-       int off;
+       int off = parent_offset;
        int ret;
 
-       off = fdt_next_node(blob, parent_offset, &ndepth);
-       if (off > 0 && ndepth == 1) {
+       while ((off = fdt_next_node(blob, off, &ndepth)) > 0) {
+               if (ndepth < 0)
+                       break;
+               else if (ndepth != 1)
+                       continue;
+               else if (fdt_getprop(blob, off, "compatible", NULL))
+                       continue;
                prop = fdt_getprop(blob, off, "label", NULL);
                if (prop == NULL) {
                        /*
@@ -760,7 +771,7 @@ int fdt_node_set_part_info(void *blob, int parent_offset,
        struct list_head *pentry;
        struct part_info *part;
        struct reg_cell cell;
-       int off, ndepth = 0;
+       int off = parent_offset, ndepth = 0;
        int part_num, ret;
        char buf[64];
 
@@ -772,10 +783,16 @@ int fdt_node_set_part_info(void *blob, int parent_offset,
         * Check if it is nand {}; subnode, adjust
         * the offset in this case
         */
-       off = fdt_next_node(blob, parent_offset, &ndepth);
-       if (off > 0 && ndepth == 1)
+       while ((off = fdt_next_node(blob, off, &ndepth)) > 0) {
+               if (ndepth < 0)
+                       break;
+               else if (ndepth != 1)
+                       continue;
+               else if (fdt_getprop(blob, off, "compatible", NULL))
+                       continue;
                parent_offset = off;
-
+               break;
+       }
        part_num = 0;
        list_for_each_prev(pentry, &dev->parts) {
                int newoff;
@@ -914,8 +931,6 @@ void fdt_del_node_and_alias(void *blob, const char *alias)
        fdt_delprop(blob, off, alias);
 }
 
-#define PRu64  "%llx"
-
 /* Max address size we deal with */
 #define OF_MAX_ADDR_CELLS      4
 #define OF_BAD_ADDR    ((u64)-1)
@@ -973,8 +988,8 @@ static u64 of_bus_default_map(fdt32_t *addr, const fdt32_t *range,
        s  = of_read_number(range + na + pna, ns);
        da = of_read_number(addr, na);
 
-       debug("OF: default map, cp="PRu64", s="PRu64", da="PRu64"\n",
-           cp, s, da);
+       debug("OF: default map, cp=%" PRIu64 ", s=%" PRIu64
+             ", da=%" PRIu64 "\n", cp, s, da);
 
        if (da < cp || da >= (cp + s))
                return OF_BAD_ADDR;
@@ -1052,7 +1067,7 @@ static int of_translate_one(void * blob, int parent, struct of_bus *bus,
 
  finish:
        of_dump_addr("OF: parent translation for:", addr, pna);
-       debug("OF: with offset: "PRu64"\n", offset);
+       debug("OF: with offset: %" PRIu64 "\n", offset);
 
        /* Translate it into parent bus space */
        return pbus->translate(addr, offset, pna);
@@ -1086,7 +1101,7 @@ static u64 __of_translate_address(void *blob, int node_offset, const fdt32_t *in
                goto bail;
        bus = &of_busses[0];
 
-       /* Cound address cells & copy address locally */
+       /* Count address cells & copy address locally */
        bus->count_cells(blob, parent, &na, &ns);
        if (!OF_CHECK_COUNTS(na, ns)) {
                printf("%s: Bad cell count for %s\n", __FUNCTION__,
@@ -1381,9 +1396,9 @@ int fdt_verify_alias_address(void *fdt, int anode, const char *alias, u64 addr)
 
        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);
+               printf("Warning: U-Boot configured device %s at address %"
+                      PRIx64 ",\n but the device tree has it address %"
+                      PRIx64 ".\n", alias, addr, dt_addr);
                return 0;
        }