Merge tag 'video-for-2021.01-rc1' of https://gitlab.denx.de/u-boot/custodians/u-boot...
[platform/kernel/u-boot.git] / common / fdt_support.c
index 86de5b8..a565b47 100644 (file)
@@ -7,7 +7,10 @@
  */
 
 #include <common.h>
+#include <env.h>
+#include <log.h>
 #include <mapmem.h>
+#include <net.h>
 #include <stdio_dev.h>
 #include <linux/ctype.h>
 #include <linux/types.h>
@@ -466,6 +469,41 @@ int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
        }
        return 0;
 }
+
+int fdt_set_usable_memory(void *blob, u64 start[], u64 size[], int areas)
+{
+       int err, nodeoffset;
+       int len;
+       u8 tmp[8 * 16]; /* Up to 64-bit address + 64-bit size */
+
+       if (areas > 8) {
+               printf("%s: num areas %d exceeds hardcoded limit %d\n",
+                      __func__, areas, 8);
+               return -1;
+       }
+
+       err = fdt_check_header(blob);
+       if (err < 0) {
+               printf("%s: %s\n", __func__, fdt_strerror(err));
+               return err;
+       }
+
+       /* find or create "/memory" node. */
+       nodeoffset = fdt_find_or_add_subnode(blob, 0, "memory");
+       if (nodeoffset < 0)
+               return nodeoffset;
+
+       len = fdt_pack_reg(blob, tmp, start, size, areas);
+
+       err = fdt_setprop(blob, nodeoffset, "linux,usable-memory", tmp, len);
+       if (err < 0) {
+               printf("WARNING: could not set %s %s.\n",
+                      "reg", fdt_strerror(err));
+               return err;
+       }
+
+       return 0;
+}
 #endif
 
 int fdt_fixup_memory(void *blob, u64 start, u64 size)
@@ -778,8 +816,8 @@ static int fdt_del_partitions(void *blob, int parent_offset)
        return 0;
 }
 
-int fdt_node_set_part_info(void *blob, int parent_offset,
-                          struct mtd_device *dev)
+static int fdt_node_set_part_info(void *blob, int parent_offset,
+                                 struct mtd_device *dev)
 {
        struct list_head *pentry;
        struct part_info *part;
@@ -913,27 +951,35 @@ void fdt_fixup_mtdparts(void *blob, const struct node_info *node_info,
        struct mtd_device *dev;
        int i, idx;
        int noff;
-
-       if (mtdparts_init() != 0)
-               return;
+       bool inited = false;
 
        for (i = 0; i < node_info_size; i++) {
                idx = 0;
-               noff = fdt_node_offset_by_compatible(blob, -1,
-                                                    node_info[i].compat);
-               while (noff != -FDT_ERR_NOTFOUND) {
+               noff = -1;
+
+               while ((noff = fdt_node_offset_by_compatible(blob, noff,
+                                               node_info[i].compat)) >= 0) {
+                       const char *prop;
+
+                       prop = fdt_getprop(blob, noff, "status", NULL);
+                       if (prop && !strcmp(prop, "disabled"))
+                               continue;
+
                        debug("%s: %s, mtd dev type %d\n",
                                fdt_get_name(blob, noff, 0),
                                node_info[i].compat, node_info[i].type);
+
+                       if (!inited) {
+                               if (mtdparts_init() != 0)
+                                       return;
+                               inited = true;
+                       }
+
                        dev = device_find(node_info[i].type, idx++);
                        if (dev) {
                                if (fdt_node_set_part_info(blob, noff, dev))
                                        return; /* return on error */
                        }
-
-                       /* Jump to next flash node */
-                       noff = fdt_node_offset_by_compatible(blob, noff,
-                                                            node_info[i].compat);
                }
        }
 }
@@ -1565,7 +1611,7 @@ static int fdt_read_prop(const fdt32_t *prop, int prop_len, int cell_off,
                         uint64_t *val, int cells)
 {
        const fdt32_t *prop32 = &prop[cell_off];
-       const fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off];
+       const unaligned_fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off];
 
        if ((cell_off + cells) > prop_len)
                return -FDT_ERR_NOSPACE;