[PATCH 2/2] uboot: build in-tree pylibfdt against Python 3
Vladimir Savelev
anykey196 at gmail.com
Fri Oct 2 00:15:30 PDT 2026
The SWIG interface shipped for pylibfdt uses Python 2 APIs outside the
PY_VERSION_HEX guards: PyString_FromString() in the fdt_property typemap
and PyInt_AsLong() in the int *depth typemap. The neighbouring typemaps
are already guarded, so guard these two the same way.
On a host with Python 3.12+ and GCC 14+ this fails to build pylibfdt
with "implicit declaration of function 'PyInt_AsLong'" and
-Wint-conversion errors, since Python 3 removed both names.
This has been reported upstream: https://github.com/u-boot/u-boot/pull/1053
This patch was prepared with the assistance of AI tools.
Signed-off-by: Vladimir Savelev <anykey196 at gmail.com>
---
...s-dtc-pylibfdt-build-against-python3.patch | 41 +++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 package/boot/uboot/patches/910-scripts-dtc-pylibfdt-build-against-python3.patch
diff --git a/package/boot/uboot/patches/910-scripts-dtc-pylibfdt-build-against-python3.patch b/package/boot/uboot/patches/910-scripts-dtc-pylibfdt-build-against-python3.patch
new file mode 100644
index 000000000..b3431798a
--- /dev/null
+++ b/package/boot/uboot/patches/910-scripts-dtc-pylibfdt-build-against-python3.patch
@@ -0,0 +1,41 @@
+scripts: dtc: build pylibfdt against Python 3
+
+The SWIG interface shipped for pylibfdt uses Python 2 APIs outside the
+PY_VERSION_HEX guards: PyString_FromString() in the fdt_property typemap
+and PyInt_AsLong() in the int *depth typemap. The neighbouring typemaps
+are already guarded, so guard these two the same way.
+
+On a host with Python 3.12+ and GCC 14+ this fails to build pylibfdt
+with "implicit declaration of function 'PyInt_AsLong'" and
+-Wint-conversion errors, since Python 3 removed both names.
+
+This has been reported upstream: https://github.com/u-boot/u-boot/pull/1053
+
+--- a/scripts/dtc/pylibfdt/libfdt.i_shipped
++++ b/scripts/dtc/pylibfdt/libfdt.i_shipped
+@@ -1033,8 +1033,13 @@
+ PyObject *buff;
+
+ if ($1) {
++ %#if PY_VERSION_HEX >= 0x03000000
++ resultobj = PyUnicode_FromString(
++ fdt_string(fdt1, fdt32_to_cpu($1->nameoff)));
++ %#else
+ resultobj = PyString_FromString(
+ fdt_string(fdt1, fdt32_to_cpu($1->nameoff)));
++ %#endif
+ buff = PyByteArray_FromStringAndSize(
+ (const char *)($1 + 1), fdt32_to_cpu($1->len));
+ resultobj = SWIG_AppendOutput(resultobj, buff);
+@@ -1070,7 +1075,11 @@
+
+ /* typemaps used for fdt_next_node() */
+ %typemap(in, numinputs=1) int *depth (int depth) {
++ %#if PY_VERSION_HEX >= 0x03000000
++ depth = (int) PyLong_AsLong($input);
++ %#else
+ depth = (int) PyInt_AsLong($input);
++ %#endif
+ $1 = &depth;
+ }
+
More information about the openwrt-devel
mailing list