summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2026-08-24 17:13:06 +0400
committerTom Rini <trini@konsulko.com>2026-08-31 17:06:20 -0600
commit3bf9e7e72ab545d08d9ae30bcb45027ad24609bb (patch)
treee2e988cdc59e0489f553bb9a097bf44d0d3630c8
parent69c95e9e4f576b811e640d1bf0ee95cf070dd542 (diff)
downloadu-boot-3bf9e7e72ab545d08d9ae30bcb45027ad24609bb.tar.gz
u-boot-3bf9e7e72ab545d08d9ae30bcb45027ad24609bb.zip
pylibfdt: Support boolean properties
Boolean properties are unusual in that their presense or absence indicates the value of the property. This makes them a little painful to support using the existing getprop() support. Add new methods to deal with booleans specifically. This is a backport of dtc commit 52157f13ef3d ("pylibfdt: Support boolean properties"), without the dtc-side tests, which have no counterpart in U-Boot's test suite. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au> [adapt to U-Boot] Signed-off-by: Alexey Charkov <alchark@flipper.net>
-rw-r--r--scripts/dtc/pylibfdt/libfdt.i_shipped55
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/dtc/pylibfdt/libfdt.i_shipped b/scripts/dtc/pylibfdt/libfdt.i_shipped
index 6a900265459..dd568fc7493 100644
--- a/scripts/dtc/pylibfdt/libfdt.i_shipped
+++ b/scripts/dtc/pylibfdt/libfdt.i_shipped
@@ -423,6 +423,35 @@ class FdtRo(object):
return pdata
return Property(prop_name, bytearray(pdata[0]))
+ def hasprop(self, nodeoffset, prop_name, quiet=()):
+ """Check if a node has a property
+
+ This can be used to check boolean properties
+
+ Args:
+ nodeoffset: Node offset containing property to check
+ prop_name: Name of property to check
+ quiet: Errors to ignore (empty to raise on all errors). Note that
+ NOTFOUND is added internally by this function so need not be
+ provided
+
+ Returns:
+ True if the property exists in the node, else False. If an error
+ other than -NOTFOUND is returned by fdt_getprop() then the error
+ is return (-ve integer)
+
+ Raises:
+ FdtError if any error occurs other than NOTFOUND (e.g. the
+ nodeoffset is invalid)
+ """
+ pdata = check_err_null(fdt_getprop(self._fdt, nodeoffset, prop_name),
+ quiet + (NOTFOUND,))
+ if isinstance(pdata, (int)):
+ if pdata == -NOTFOUND:
+ return False
+ return pdata
+ return True
+
def get_phandle(self, nodeoffset):
"""Get the phandle of a node
@@ -609,6 +638,32 @@ class Fdt(FdtRo):
return check_err(fdt_setprop(self._fdt, nodeoffset, prop_name, val,
len(val)), quiet)
+ def setprop_bool(self, nodeoffset, prop_name, val, quiet=()):
+ """Set the boolean value of a property
+
+ Either:
+ adds the property if not already present; or
+ deletes the property if present
+
+ Args:
+ nodeoffset: Node offset containing the property to create/delete
+ prop_name: Name of property
+ val: Boolean value to write (i.e. True or False)
+ quiet: Errors to ignore (empty to raise on all errors)
+
+ Returns:
+ Error code, or 0 if OK
+
+ Raises:
+ FdtException if no parent found or other error occurs
+ """
+ exists = self.hasprop(nodeoffset, prop_name, quiet)
+ if val != exists:
+ if val:
+ return self.setprop(nodeoffset, prop_name, b'', quiet=quiet)
+ else:
+ return self.delprop(nodeoffset, prop_name, quiet=quiet)
+
def setprop_u32(self, nodeoffset, prop_name, val, quiet=()):
"""Set the value of a property