diff mbox series

[2/7] devtool: ide-sdk: add real hardware NFS export helper

Message ID 20260917183832.998361-3-adrian.freihofer@siemens.com
State New
Headers show
Series oe-selftest: devtool ide-sdk: make slirp tests port collision proof | expand

Commit Message

AdrianF Sept. 17, 2026, 6:37 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Generate a helper for NFS-enabled IDE SDK images that exports the rootfs
with runqemu-export-rootfs and serves the deploy directory over HTTP. This
allows real hardware targets to boot the generated rootfs and retrieve the
kernel from the deploy directory over HTTP.

For some use cases like u-boot with wget command built-in this helper
is expected to cover the typical scenario. For other use cases the
generated script at least provides a starting point and can be adapted
as needed for other scenarios.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 scripts/lib/devtool/ide_sdk.py | 35 ++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
diff mbox series

Patch

diff --git a/scripts/lib/devtool/ide_sdk.py b/scripts/lib/devtool/ide_sdk.py
index 20b03b2d40..a2b15ce440 100755
--- a/scripts/lib/devtool/ide_sdk.py
+++ b/scripts/lib/devtool/ide_sdk.py
@@ -360,6 +360,33 @@  class RecipeImage:
         os.chmod(helper, os.stat(helper).st_mode | stat.S_IEXEC)
         return helper
 
+    def nfs_hw_helper(self, nfs_export_base_dir, nfs):
+        """Create a helper that exports the selected rootfs and the kernel to a target.
+
+        The rootfs is exported over NFS with runqemu-export-rootfs
+        The deploy directory (fitImage/kernel) is served over plain
+        HTTP, e.g. for a U-Boot 'wget' in recovery/netboot mode.
+        """
+        export_dir = os.path.join(nfs_export_base_dir, self.pn)
+        rootfs_dir = self.nfs_rootfs_dir(nfs_export_base_dir, nfs)
+
+        helper = os.path.join(export_dir, 'export-hw-' + nfs)
+        with open(helper, 'w') as helper_file:
+            helper_file.write('#!/bin/sh\n')
+            helper_file.write('set -e\n')
+            helper_file.write(
+                'runqemu-export-rootfs start %s\n' % shlex.quote(rootfs_dir))
+            helper_file.write(
+                'trap \'runqemu-export-rootfs stop %s\' EXIT INT TERM\n' %
+                shlex.quote(rootfs_dir))
+            helper_file.write('cd %s\n' % shlex.quote(self.deploy_dir_image))
+            helper_file.write(
+                'echo "Serving %s over HTTP on port ${PORT:-8080}"\n' %
+                self.deploy_dir_image)
+            helper_file.write('python3 -m http.server "${PORT:-8080}"\n')
+        os.chmod(helper, os.stat(helper).st_mode | stat.S_IEXEC)
+        return helper
+
     def update_image_bbappend(self, recipes_modified, nfs=None):
         """Write debug settings for modified-mode recipes into the image bbappend.
 
@@ -489,6 +516,14 @@  class RecipeImage:
                 'Pass any additional runqemu options to this helper.',
                 helper, opts)
 
+        hw_helper = self.nfs_hw_helper(nfs_export_base_dir, nfs)
+        logger.info(
+            'With the build environment sourced, export the rootfs (NFS) and '
+            'the kernel (HTTP) for a real hardware target instead of QEMU:\n'
+            '  %s\n'
+            'Set PORT to override the HTTP port (default: 8080).',
+            hw_helper)
+
     def update_qb_slirp_opt(self):
         """Update QB_SLIRP_OPT in the image bbappend