diff mbox series

[v3,3/4] u-boot-tools: fix pylibfdt build with swig 4.5.0

Message ID 20260811111120.17612-4-jaipaul.cheernam@est.tech
State Under Review
Headers show
Series swig: upgrade 4.4.1 -> 4.5.0 | expand

Commit Message

Jaipaul Cheernam Aug. 11, 2026, 11:11 a.m. UTC
SWIG 4.5.0 removed Python 2 compatibility macros (PyInt_*, PyString_*)
from its runtime. Backport the dtc upstream fix to u-boot's bundled
pylibfdt/libfdt.i to replace them with Python 3 equivalents.

Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
---
 ...-removed-SWIG-Python-2-compatibility.patch | 57 +++++++++++++++++++
 .../u-boot/u-boot-tools_2026.07.bb            |  4 +-
 2 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-bsp/u-boot/files/0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch

Comments

Mathieu Dubois-Briand Aug. 11, 2026, 12:58 p.m. UTC | #1
On Tue Aug 11, 2026 at 1:11 PM CEST, Jaipaul Cheernam wrote:
> SWIG 4.5.0 removed Python 2 compatibility macros (PyInt_*, PyString_*)
> from its runtime. Backport the dtc upstream fix to u-boot's bundled
> pylibfdt/libfdt.i to replace them with Python 3 equivalents.
>
> Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
> ---

Hi Jaipaul,

Thanks for your patch.

Can you confirm this is based on today master? The u-boot patch fails to
apply on my side:

ERROR: u-boot-tools-1_2026.07-r0 do_patch: Applying patch '/srv/pokybuild/yocto-worker/musl-qemux86-64/build/layers/openembedded-core/meta/recipes-bsp/u-boot/files/0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch' on target directory '/srv/pokybuild/yocto-worker/musl-qemux86-64/build/build/tmp/work/x86-64-v3-poky-linux-musl/u-boot-tools/2026.07/sources/u-boot-tools-2026.07'
CmdError('quilt --quiltrc /srv/pokybuild/yocto-worker/musl-qemux86-64/build/build/tmp/work/x86-64-v3-poky-linux-musl/u-boot-tools/2026.07/recipe-sysroot-native/etc/quiltrc push', 1, "stdout: Applying patch 0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch
can't find file to patch at input line 33
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|From 32378d7b4383a79d13da9005035600d8f0c8c29d Mon Sep 17 00:00:00 2001
|From: Jitka Plesnikova <jplesnik@redhat.com>
|Date: Tue, 29 Jul 2026 05:55:56 +0000
|Subject: [PATCH] pylibfdt: Replace removed SWIG Python 2 compatibility macros
|
|SWIG 4.5.0 removed Python 2 compatibility macros (PyInt_*, PyString_*)
|from its runtime header pyhead.swg (see commit 79f7a2b7cb7d). Replace
|them with their Python 3 C API equivalents:
|
|- PyString_FromString -> PyUnicode_FromString
|- PyString_AsString -> PyBytes_AsString
|- PyInt_AsLong -> PyLong_AsLong
|
|The replacements are safe since the macros were already aliased to
|these exact functions in SWIG's Python 3 code path.
|
|Signed-off-by: Jitka Plesnikova <jplesnik@redhat.com>
|Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
|Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
|(cherry picked from commit 5008d1d6a356b8d0a78060da2e1021507d529cff)
|
|Upstream-Status: Backport [https://github.com/dgibson/dtc/commit/5008d1d6a356b8d0a78060da2e1021507d529cff]
|
|Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
|---
| scripts/dtc/pylibfdt/libfdt.i | 6 +++---
| 1 file changed, 3 insertions(+), 3 deletions(-)
|
|diff --git a/scripts/dtc/pylibfdt/libfdt.i b/scripts/dtc/pylibfdt/libfdt.i
|index 1f9c0471..b1cb9873 100644
|--- a/scripts/dtc/pylibfdt/libfdt.i
|+++ b/scripts/dtc/pylibfdt/libfdt.i
--------------------------
No file to patch.  Skipping patch.
2 out of 2 hunks ignored
Patch 0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch does not apply (enforce with -f)

https://autobuilder.yoctoproject.org/valkyrie/#/builders/17/builds/4216
https://autobuilder.yoctoproject.org/valkyrie/#/builders/3/builds/4423

Thanks,
Mathieu
Quentin Schulz Aug. 11, 2026, 1:38 p.m. UTC | #2
Hi Jaipaul,

On 8/11/26 1:11 PM, Jaipaul Cheernam via lists.openembedded.org wrote:
> SWIG 4.5.0 removed Python 2 compatibility macros (PyInt_*, PyString_*)
> from its runtime. Backport the dtc upstream fix to u-boot's bundled
> pylibfdt/libfdt.i to replace them with Python 3 equivalents.
> 
> Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
> ---
>   ...-removed-SWIG-Python-2-compatibility.patch | 57 +++++++++++++++++++
>   .../u-boot/u-boot-tools_2026.07.bb            |  4 +-
>   2 files changed, 60 insertions(+), 1 deletion(-)
>   create mode 100644 meta/recipes-bsp/u-boot/files/0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch
> 
> diff --git a/meta/recipes-bsp/u-boot/files/0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch b/meta/recipes-bsp/u-boot/files/0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch
> new file mode 100644
> index 0000000000..5fdccf5e9d
> --- /dev/null
> +++ b/meta/recipes-bsp/u-boot/files/0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch
> @@ -0,0 +1,57 @@
> +From 32378d7b4383a79d13da9005035600d8f0c8c29d Mon Sep 17 00:00:00 2001
> +From: Jitka Plesnikova <jplesnik@redhat.com>
> +Date: Tue, 29 Jul 2026 05:55:56 +0000
> +Subject: [PATCH] pylibfdt: Replace removed SWIG Python 2 compatibility macros
> +
> +SWIG 4.5.0 removed Python 2 compatibility macros (PyInt_*, PyString_*)
> +from its runtime header pyhead.swg (see commit 79f7a2b7cb7d). Replace
> +them with their Python 3 C API equivalents:
> +
> +- PyString_FromString -> PyUnicode_FromString
> +- PyString_AsString -> PyBytes_AsString
> +- PyInt_AsLong -> PyLong_AsLong
> +
> +The replacements are safe since the macros were already aliased to
> +these exact functions in SWIG's Python 3 code path.
> +
> +Signed-off-by: Jitka Plesnikova <jplesnik@redhat.com>
> +Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
> +Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> +(cherry picked from commit 5008d1d6a356b8d0a78060da2e1021507d529cff)
> +
> +Upstream-Status: Backport [https://github.com/dgibson/dtc/commit/5008d1d6a356b8d0a78060da2e1021507d529cff]
> +

Not a backport. This commit doesn't exist in U-Boot. Please work with 
upstream U-Boot on fixing this so that other build systems/distros don't 
need to duplicate the work and we don't have to carry this patch forever 
in Yocto.

Cheers,
Quentin
diff mbox series

Patch

diff --git a/meta/recipes-bsp/u-boot/files/0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch b/meta/recipes-bsp/u-boot/files/0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch
new file mode 100644
index 0000000000..5fdccf5e9d
--- /dev/null
+++ b/meta/recipes-bsp/u-boot/files/0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch
@@ -0,0 +1,57 @@ 
+From 32378d7b4383a79d13da9005035600d8f0c8c29d Mon Sep 17 00:00:00 2001
+From: Jitka Plesnikova <jplesnik@redhat.com>
+Date: Tue, 29 Jul 2026 05:55:56 +0000
+Subject: [PATCH] pylibfdt: Replace removed SWIG Python 2 compatibility macros
+
+SWIG 4.5.0 removed Python 2 compatibility macros (PyInt_*, PyString_*)
+from its runtime header pyhead.swg (see commit 79f7a2b7cb7d). Replace
+them with their Python 3 C API equivalents:
+
+- PyString_FromString -> PyUnicode_FromString
+- PyString_AsString -> PyBytes_AsString
+- PyInt_AsLong -> PyLong_AsLong
+
+The replacements are safe since the macros were already aliased to
+these exact functions in SWIG's Python 3 code path.
+
+Signed-off-by: Jitka Plesnikova <jplesnik@redhat.com>
+Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
+Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
+(cherry picked from commit 5008d1d6a356b8d0a78060da2e1021507d529cff)
+
+Upstream-Status: Backport [https://github.com/dgibson/dtc/commit/5008d1d6a356b8d0a78060da2e1021507d529cff]
+
+Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
+---
+ scripts/dtc/pylibfdt/libfdt.i | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/scripts/dtc/pylibfdt/libfdt.i b/scripts/dtc/pylibfdt/libfdt.i
+index 1f9c0471..b1cb9873 100644
+--- a/scripts/dtc/pylibfdt/libfdt.i
++++ b/scripts/dtc/pylibfdt/libfdt.i
+@@ -1136,7 +1136,7 @@ typedef uint32_t fdt32_t;
+ 	PyObject *buff;
+ 
+ 	if ($1) {
+-		resultobj = PyString_FromString(
++		resultobj = PyUnicode_FromString(
+ 			fdt_string(fdt1, fdt32_to_cpu($1->nameoff)));
+ 		buff = PyByteArray_FromStringAndSize(
+ 			(const char *)($1 + 1), fdt32_to_cpu($1->len));
+@@ -1169,13 +1169,13 @@ typedef uint32_t fdt32_t;
+         }
+         $1 = PyBytes_AsString($input);
+     %#else
+-        $1 = PyString_AsString($input);   /* char *str */
++        $1 = PyBytes_AsString($input);   /* char *str */
+     %#endif
+ }
+ 
+ /* typemaps used for fdt_next_node() */
+ %typemap(in, numinputs=1) int *depth (int depth) {
+-   depth = (int) PyInt_AsLong($input);
++   depth = (int) PyLong_AsLong($input);
+    $1 = &depth;
+ }
+ 
diff --git a/meta/recipes-bsp/u-boot/u-boot-tools_2026.07.bb b/meta/recipes-bsp/u-boot/u-boot-tools_2026.07.bb
index 9e7a178310..ea90b726c5 100644
--- a/meta/recipes-bsp/u-boot/u-boot-tools_2026.07.bb
+++ b/meta/recipes-bsp/u-boot/u-boot-tools_2026.07.bb
@@ -1,4 +1,6 @@ 
 require u-boot-common.inc
 require u-boot-tools.inc
 
-SRC_URI += "file://0001-tools-mkeficapsule-Detect-GnuTLS-PKCS-11-support.patch"
+SRC_URI += "file://0001-tools-mkeficapsule-Detect-GnuTLS-PKCS-11-support.patch \
+            file://0001-pylibfdt-Replace-removed-SWIG-Python-2-compatibility.patch \
+            "