]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
fdt: Sync up with libfdt
authorSimon Glass <sjg@chromium.org>
Wed, 30 Jul 2014 09:59:03 +0000 (03:59 -0600)
committerTom Rini <trini@ti.com>
Sat, 9 Aug 2014 15:17:04 +0000 (11:17 -0400)
This brings in changes up to commit f9e91a48 in the libfdt repo.
Mostly this is whitespace/minor changes. But there are a few new
features:

- fdt_size_cells() and fdt_address_cells()
- fdt_resize()

Signed-off-by: Simon Glass <sjg@chromium.org>
include/libfdt.h
lib/libfdt/Makefile
lib/libfdt/fdt_addresses.c [new file with mode: 0644]
lib/libfdt/fdt_rw.c
lib/libfdt/fdt_sw.c
lib/libfdt/libfdt_internal.h

index 9eefaaf5f87a7de869f78a05c67bed09d56202bd..a1ef1e15df3ddbd8abec45766b9f9038f334bcc1 100644 (file)
         * Should never be returned, if it is, it indicates a bug in
         * libfdt itself. */
 
-#define FDT_ERR_MAX            13
+/* Errors in device tree content */
+#define FDT_ERR_BADNCELLS      14
+       /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
+        * or similar property with a bad format or value */
+
+#define FDT_ERR_MAX            14
 
 /**********************************************************************/
 /* Low-level functions (you probably don't need these)                */
@@ -596,9 +601,9 @@ const char *fdt_get_alias_namelen(const void *fdt,
                                  const char *name, int namelen);
 
 /**
- * fdt_get_alias - retrieve the path referenced by a given alias
+ * fdt_get_alias - retreive the path referenced by a given alias
  * @fdt: pointer to the device tree blob
- * @name: name of the alias to look up
+ * @name: name of the alias th look up
  *
  * fdt_get_alias() retrieves the value of a given alias.  That is, the
  * value of the property named 'name' in the node /aliases.
@@ -731,7 +736,7 @@ int fdt_parent_offset(const void *fdt, int nodeoffset);
  *     offset = fdt_node_offset_by_prop_value(fdt, -1, propname,
  *                                            propval, proplen);
  *     while (offset != -FDT_ERR_NOTFOUND) {
- *             ... other code here ...
+ *             // other code here
  *             offset = fdt_node_offset_by_prop_value(fdt, offset, propname,
  *                                                    propval, proplen);
  *     }
@@ -816,7 +821,7 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,
  * idiom can be used:
  *     offset = fdt_node_offset_by_compatible(fdt, -1, compatible);
  *     while (offset != -FDT_ERR_NOTFOUND) {
- *             ... other code here ...
+ *             // other code here
  *             offset = fdt_node_offset_by_compatible(fdt, offset, compatible);
  *     }
  *
@@ -852,6 +857,63 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
  */
 int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
 
+/**********************************************************************/
+/* Read-only functions (addressing related)                           */
+/**********************************************************************/
+
+/**
+ * FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells
+ *
+ * This is the maximum value for #address-cells, #size-cells and
+ * similar properties that will be processed by libfdt.  IEE1275
+ * requires that OF implementations handle values up to 4.
+ * Implementations may support larger values, but in practice higher
+ * values aren't used.
+ */
+#define FDT_MAX_NCELLS         4
+
+/**
+ * fdt_address_cells - retrieve address size for a bus represented in the tree
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node to find the address size for
+ *
+ * When the node has a valid #address-cells property, returns its value.
+ *
+ * returns:
+ *     0 <= n < FDT_MAX_NCELLS, on success
+ *      2, if the node has no #address-cells property
+ *      -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
+ *             #address-cells property
+ *     -FDT_ERR_BADMAGIC,
+ *     -FDT_ERR_BADVERSION,
+ *     -FDT_ERR_BADSTATE,
+ *     -FDT_ERR_BADSTRUCTURE,
+ *     -FDT_ERR_TRUNCATED, standard meanings
+ */
+int fdt_address_cells(const void *fdt, int nodeoffset);
+
+/**
+ * fdt_size_cells - retrieve address range size for a bus represented in the
+ *                  tree
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node to find the address range size for
+ *
+ * When the node has a valid #size-cells property, returns its value.
+ *
+ * returns:
+ *     0 <= n < FDT_MAX_NCELLS, on success
+ *      2, if the node has no #address-cells property
+ *      -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid
+ *             #size-cells property
+ *     -FDT_ERR_BADMAGIC,
+ *     -FDT_ERR_BADVERSION,
+ *     -FDT_ERR_BADSTATE,
+ *     -FDT_ERR_BADSTRUCTURE,
+ *     -FDT_ERR_TRUNCATED, standard meanings
+ */
+int fdt_size_cells(const void *fdt, int nodeoffset);
+
+
 /**********************************************************************/
 /* Write-in-place functions                                           */
 /**********************************************************************/
@@ -1023,6 +1085,7 @@ int fdt_nop_node(void *fdt, int nodeoffset);
 /**********************************************************************/
 
 int fdt_create(void *buf, int bufsize);
+int fdt_resize(void *fdt, void *buf, int bufsize);
 int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
 int fdt_finish_reservemap(void *fdt);
 int fdt_begin_node(void *fdt, const char *name);
index a02c9b02add2d360e5aa5d0d53a2d620e98e9fda..6fe79e0b06e9c422b6bfcfffd8fdd968872960dc 100644 (file)
@@ -5,7 +5,8 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
-COBJS-libfdt += fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_sw.o fdt_wip.o fdt_empty_tree.o
+COBJS-libfdt += fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_sw.o fdt_wip.o \
+       fdt_empty_tree.o fdt_addresses.o
 
 obj-$(CONFIG_OF_LIBFDT) += $(COBJS-libfdt)
 obj-$(CONFIG_FIT) += $(COBJS-libfdt)
diff --git a/lib/libfdt/fdt_addresses.c b/lib/libfdt/fdt_addresses.c
new file mode 100644 (file)
index 0000000..76054d9
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * libfdt - Flat Device Tree manipulation
+ * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
+ * SPDX-License-Identifier:    GPL-2.0+ BSD-2-Clause
+ */
+#include "libfdt_env.h"
+
+#ifndef USE_HOSTCC
+#include <fdt.h>
+#include <libfdt.h>
+#else
+#include "fdt_host.h"
+#endif
+
+#include "libfdt_internal.h"
+
+int fdt_address_cells(const void *fdt, int nodeoffset)
+{
+       const fdt32_t *ac;
+       int val;
+       int len;
+
+       ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len);
+       if (!ac)
+               return 2;
+
+       if (len != sizeof(*ac))
+               return -FDT_ERR_BADNCELLS;
+
+       val = fdt32_to_cpu(*ac);
+       if ((val <= 0) || (val > FDT_MAX_NCELLS))
+               return -FDT_ERR_BADNCELLS;
+
+       return val;
+}
+
+int fdt_size_cells(const void *fdt, int nodeoffset)
+{
+       const fdt32_t *sc;
+       int val;
+       int len;
+
+       sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len);
+       if (!sc)
+               return 2;
+
+       if (len != sizeof(*sc))
+               return -FDT_ERR_BADNCELLS;
+
+       val = fdt32_to_cpu(*sc);
+       if ((val < 0) || (val > FDT_MAX_NCELLS))
+               return -FDT_ERR_BADNCELLS;
+
+       return val;
+}
index 6fa4f13073d28fd76c886b1154e254ca1c6e1fd0..bec8b8ad891846e5240c476cf3b15e34eb3f66e8 100644 (file)
@@ -43,9 +43,9 @@ static int _fdt_rw_check_header(void *fdt)
 
 #define FDT_RW_CHECK_HEADER(fdt) \
        { \
-               int err; \
-               if ((err = _fdt_rw_check_header(fdt)) != 0) \
-                       return err; \
+               int __err; \
+               if ((__err = _fdt_rw_check_header(fdt)) != 0) \
+                       return __err; \
        }
 
 static inline int _fdt_data_size(void *fdt)
index 580b57024ffc96843d718ed3ea7dd962acd52327..320a914991ad76f94fedc67de6ad8fc072e78413 100644 (file)
@@ -62,6 +62,38 @@ int fdt_create(void *buf, int bufsize)
        return 0;
 }
 
+int fdt_resize(void *fdt, void *buf, int bufsize)
+{
+       size_t headsize, tailsize;
+       char *oldtail, *newtail;
+
+       FDT_SW_CHECK_HEADER(fdt);
+
+       headsize = fdt_off_dt_struct(fdt);
+       tailsize = fdt_size_dt_strings(fdt);
+
+       if ((headsize + tailsize) > bufsize)
+               return -FDT_ERR_NOSPACE;
+
+       oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize;
+       newtail = (char *)buf + bufsize - tailsize;
+
+       /* Two cases to avoid clobbering data if the old and new
+        * buffers partially overlap */
+       if (buf <= fdt) {
+               memmove(buf, fdt, headsize);
+               memmove(newtail, oldtail, tailsize);
+       } else {
+               memmove(newtail, oldtail, tailsize);
+               memmove(buf, fdt, headsize);
+       }
+
+       fdt_set_off_dt_strings(buf, bufsize);
+       fdt_set_totalsize(buf, bufsize);
+
+       return 0;
+}
+
 int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
 {
        struct fdt_reserve_entry *re;
index 13cbc9af2ab9259ea1cb76c37cb489be6907ab57..9a79fe85ddaf092904cb1c1a421a98fee1dcf696 100644 (file)
@@ -12,9 +12,9 @@
 
 #define FDT_CHECK_HEADER(fdt) \
        { \
-               int err; \
-               if ((err = fdt_check_header(fdt)) != 0) \
-                       return err; \
+               int __err; \
+               if ((__err = fdt_check_header(fdt)) != 0) \
+                       return __err; \
        }
 
 int _fdt_check_node_offset(const void *fdt, int offset);