aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2023-03-16 10:01:45 -0500
committerRob Herring <robh@kernel.org>2023-03-16 10:06:35 -0500
commit68a49c5715f287fc344c6a21acd2bf1b6738f2f5 (patch)
treea6ad9f8c3f8fc551b279a800bce80e246858ecb5
parenteb6330deb46cf67ff77913b56710052eba0dc9f9 (diff)
downloadlibfdt -68a49c5715f287fc344c6a21acd2bf1b6738f2f5.zip
libfdt -68a49c5715f287fc344c6a21acd2bf1b6738f2f5.tar.gz
libfdt -68a49c5715f287fc344c6a21acd2bf1b6738f2f5.tar.bz2
Sync libfdt.i from upstream dtc
Missed copying pylibfdt/libfdt.i from upstream dtc. Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r--libfdt/libfdt.i63
1 files changed, 59 insertions, 4 deletions
diff --git a/libfdt/libfdt.i b/libfdt/libfdt.i
index 51ee801..2361e22 100644
--- a/libfdt/libfdt.i
+++ b/libfdt/libfdt.i
@@ -443,6 +443,29 @@ class FdtRo(object):
"""
return fdt_get_alias(self._fdt, name)
+ def get_path(self, nodeoffset, size_hint=1024, quiet=()):
+ """Get the full path of a node
+
+ Args:
+ nodeoffset: Node offset to check
+ size_hint: Hint for size of returned string
+
+ Returns:
+ Full path to the node
+
+ Raises:
+ FdtException if an error occurs
+ """
+ while True:
+ ret, path = fdt_get_path(self._fdt, nodeoffset, size_hint)
+ if ret == -NOSPACE:
+ size_hint *= 2
+ continue
+ err = check_err(ret, quiet)
+ if err:
+ return err
+ return path
+
def parent_offset(self, nodeoffset, quiet=()):
"""Get the offset of a node's parent
@@ -716,6 +739,21 @@ class Property(bytearray):
def as_int64(self):
return self.as_cell('q')
+ def as_list(self, fmt):
+ return list(map(lambda x: x[0], struct.iter_unpack('>' + fmt, self)))
+
+ def as_uint32_list(self):
+ return self.as_list('L')
+
+ def as_int32_list(self):
+ return self.as_list('l')
+
+ def as_uint64_list(self):
+ return self.as_list('Q')
+
+ def as_int64_list(self):
+ return self.as_list('q')
+
def as_str(self):
"""Unicode is supported by decoding from UTF-8"""
if self[-1] != 0:
@@ -724,6 +762,13 @@ class Property(bytearray):
raise ValueError('Property contains embedded nul characters')
return self[:-1].decode('utf-8')
+ def as_stringlist(self):
+ """Unicode is supported by decoding from UTF-8"""
+ if self[-1] != 0:
+ raise ValueError('Property lacks nul termination')
+ parts = self[:-1].split(b'\x00')
+ return list(map(lambda x: x.decode('utf-8'), parts))
+
class FdtSw(FdtRo):
"""Software interface to create a device tree from scratch
@@ -991,6 +1036,9 @@ class NodeAdder():
%rename(fdt_property) fdt_property_func;
+%immutable fdt_property::data;
+%immutable fdt_node_header::name;
+
/*
* fdt32_t is a big-endian 32-bit value defined to uint32_t in libfdt_env.h
* so use the same type here.
@@ -1040,14 +1088,16 @@ typedef uint32_t fdt32_t;
/* typemap used for fdt_getprop() */
%typemap(out) (const void *) {
- if (!$1)
+ if (!$1) {
$result = Py_None;
- else
+ Py_INCREF($result);
+ } else {
%#if PY_VERSION_HEX >= 0x03000000
- $result = Py_BuildValue("y#", $1, *arg4);
+ $result = Py_BuildValue("y#", $1, (Py_ssize_t)*arg4);
%#else
- $result = Py_BuildValue("s#", $1, *arg4);
+ $result = Py_BuildValue("s#", $1, (Py_ssize_t)*arg4);
%#endif
+ }
}
/* typemap used for fdt_setprop() */
@@ -1091,6 +1141,11 @@ typedef uint32_t fdt32_t;
}
}
+%include "cstring.i"
+
+%cstring_output_maxsize(char *buf, int buflen);
+int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen);
+
/* We have both struct fdt_property and a function fdt_property() */
%warnfilter(302) fdt_property;