From: Alexey Charkov <alchark@flipper.net>
To: u-boot@lists.u-boot-project.org
Cc: Tom Rini <trini@konsulko.com>,
David Gibson <david@gibson.dropbear.id.au>,
Luca Weiss <luca@z3ntu.xyz>,
Brandon Maier <brandon.maier@gmail.com>,
Francesco Valla <francesco@valla.it>,
Simon Glass <sjg@chromium.org>, Rob Herring <robh@kernel.org>,
Jaipaul Cheernam <jaipaul.cheernam@est.tech>,
Alexey Charkov <alchark@flipper.net>
Subject: [PATCH 09/17] pylibfdt: Support boolean properties
Date: Mon, 24 Aug 2026 17:13:06 +0400 [thread overview]
Message-ID: <20260824-pylibfdt-sync-v1-9-a42be6fa4872@flipper.net> (raw)
In-Reply-To: <20260824-pylibfdt-sync-v1-0-a42be6fa4872@flipper.net>
From: Simon Glass <sjg@chromium.org>
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>
---
scripts/dtc/pylibfdt/libfdt.i_shipped | 55 +++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/scripts/dtc/pylibfdt/libfdt.i_shipped b/scripts/dtc/pylibfdt/libfdt.i_shipped
index 6a900265459d..dd568fc74935 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
--
2.54.0
next prev parent reply other threads:[~2026-08-24 13:13 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 13:12 [PATCH 00/17] pylibfdt: Update the U-Boot version with changes from upstream dtc Alexey Charkov
2026-08-24 13:12 ` [PATCH 01/17] pylibfdt: Cast property length to Py_ssize_t Alexey Charkov
2026-08-24 13:12 ` [PATCH 02/17] pylibfdt: Restore the upstream bytearray() in getprop() Alexey Charkov
2026-08-24 13:13 ` [PATCH 03/17] pylibfdt: Fix Python crash on getprop deallocation Alexey Charkov
2026-08-24 13:13 ` [PATCH 04/17] pylibfdt: Add Property.as_stringlist() Alexey Charkov
2026-08-24 13:13 ` [PATCH 05/17] pylibfdt: Add Property.as_*int*_array() Alexey Charkov
2026-08-24 13:13 ` [PATCH 06/17] pylibfdt: Add FdtRo.get_path() Alexey Charkov
2026-08-24 13:13 ` [PATCH 07/17] pylibfdt: Work-around SWIG limitations with flexible arrays Alexey Charkov
2026-08-24 13:13 ` [PATCH 08/17] pylibfdt: Add size_hint parameter for get_path Alexey Charkov
2026-08-24 13:13 ` Alexey Charkov [this message]
2026-08-24 13:13 ` [PATCH 10/17] pylibfdt: Fix get_mem_rsv for newer Python versions Alexey Charkov
2026-08-24 13:13 ` [PATCH 11/17] pylibfdt: Fix backwards compatibility of return values Alexey Charkov
2026-08-24 13:13 ` [PATCH 12/17] pylibfdt: Fix a typo in the next_node() docstring Alexey Charkov
2026-08-24 13:13 ` [PATCH 13/17] pylibfdt: Grow the FdtSw buffer geometrically Alexey Charkov
2026-08-24 13:13 ` [PATCH 14/17] pylibfdt: Add address_cells() and size_cells() Alexey Charkov
2026-08-24 13:13 ` [PATCH 15/17] pylibfdt: Add add_mem_rsv() and del_mem_rsv() Alexey Charkov
2026-08-24 13:13 ` [PATCH 16/17] pylibfdt: Document that FdtSw.property() takes bytes Alexey Charkov
2026-08-24 13:13 ` [PATCH 17/17] dtoc: Add tests for the pylibfdt bindings dtoc does not use Alexey Charkov
2026-08-24 18:16 ` [PATCH 00/17] pylibfdt: Update the U-Boot version with changes from upstream dtc Tom Rini
2026-09-01 2:13 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260824-pylibfdt-sync-v1-9-a42be6fa4872@flipper.net \
--to=alchark@flipper.net \
--cc=brandon.maier@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=francesco@valla.it \
--cc=jaipaul.cheernam@est.tech \
--cc=luca@z3ntu.xyz \
--cc=robh@kernel.org \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.