public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] target-bootstrapper-service: add runtime serial tty drop-in generation
@ 2026-06-19 10:39 'Gourav Singh' via isar-users
  2026-07-01  9:04 ` Zhihang Wei
  0 siblings, 1 reply; 2+ messages in thread
From: 'Gourav Singh' via isar-users @ 2026-06-19 10:39 UTC (permalink / raw)
  To: isar-users; +Cc: Gourav Singh

Extend the recipe to support dynamically detected serial consoles without
taking over every getty instance.

The existing loop still installs overrides for statically configured
TARGET_BOOTSTRAPPER_TTY_SERVICES. In addition, a runtime oneshot service
and helper script are installed to detect the first available serial tty
(ttyACM*/ttyUSB*/ttyAMA*/ttyGS*) and create one matching
serial-getty@<tty>.service.d override from a stored template.

This keeps installer behavior on configured ttys, adds support for
runtime-discovered serial devices, and preserves other consoles for
normal login/debug access.

Signed-off-by: Gourav Singh <gouravsingh@siemens.com>
---
 .../generate-target-bootstrapper-dropin.sh    | 47 +++++++++++++++++++
 .../files/postinst.tmpl                       |  3 ++
 ...arget-bootstrapper-generate-dropin.service | 12 +++++
 .../target-bootstrapper-service.bb            | 14 +++++-
 4 files changed, 74 insertions(+), 2 deletions(-)
 create mode 100644 meta-isar/recipes-installer/target-bootstrapper-service/files/generate-target-bootstrapper-dropin.sh
 create mode 100644 meta-isar/recipes-installer/target-bootstrapper-service/files/target-bootstrapper-generate-dropin.service

diff --git a/meta-isar/recipes-installer/target-bootstrapper-service/files/generate-target-bootstrapper-dropin.sh b/meta-isar/recipes-installer/target-bootstrapper-service/files/generate-target-bootstrapper-dropin.sh
new file mode 100644
index 00000000..50c3ba40
--- /dev/null
+++ b/meta-isar/recipes-installer/target-bootstrapper-service/files/generate-target-bootstrapper-dropin.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# This software is a part of Isar.
+# Copyright (C) Siemens AG, 2026
+#
+# SPDX-License-Identifier: MIT
+
+set -e
+
+OVERRIDE_DIR="/usr/lib/systemd/system"
+DROP_IN_SUFFIX="d/10-target-bootstrapper.override.conf"
+
+# Check if override template exists
+if [ ! -f "/usr/lib/target-bootstrapper.override.conf" ]; then
+    exit 0
+fi
+
+# Detect first available serial device (ttyACM*, ttyUSB*, ttyAMA*, etc.)
+detect_first_serial_device() {
+    for pattern in ttyACM ttyUSB ttyAMA ttyGS; do
+        for dev in /dev/${pattern}*; do
+            if [ -c "$dev" ]; then
+                basename "$dev"
+                return 0
+            fi
+        done
+    done
+}
+
+DETECTED_TTY=$(detect_first_serial_device 2>/dev/null)
+
+if [ -z "$DETECTED_TTY" ]; then
+    exit 0
+fi
+
+# Map device name to getty service instance
+# e.g. ttyACM0 -> serial-getty@ttyACM0.service
+TTY_SERVICE="serial-getty@${DETECTED_TTY}.service"
+DROP_IN_DIR="${OVERRIDE_DIR}/${TTY_SERVICE}.d"
+
+# Create drop-in directory and install override
+mkdir -p "$DROP_IN_DIR"
+cp "/usr/lib/target-bootstrapper.override.conf" "$DROP_IN_DIR/${DROP_IN_SUFFIX##*/}"
+
+# Reload systemd to pick up new drop-ins
+systemctl daemon-reload || true
+
+exit 0
diff --git a/meta-isar/recipes-installer/target-bootstrapper-service/files/postinst.tmpl b/meta-isar/recipes-installer/target-bootstrapper-service/files/postinst.tmpl
index 7c24af17..57851956 100644
--- a/meta-isar/recipes-installer/target-bootstrapper-service/files/postinst.tmpl
+++ b/meta-isar/recipes-installer/target-bootstrapper-service/files/postinst.tmpl
@@ -5,3 +5,6 @@ set -e
 for tty_service in ${TARGET_BOOTSTRAPPER_TTY_SERVICES}; do
     deb-systemd-helper enable ${tty_service} || true
 done
+
+# Enable the runtime detection service
+deb-systemd-helper enable target-bootstrapper-generate-dropin.service || true
diff --git a/meta-isar/recipes-installer/target-bootstrapper-service/files/target-bootstrapper-generate-dropin.service b/meta-isar/recipes-installer/target-bootstrapper-service/files/target-bootstrapper-generate-dropin.service
new file mode 100644
index 00000000..38457c8d
--- /dev/null
+++ b/meta-isar/recipes-installer/target-bootstrapper-service/files/target-bootstrapper-generate-dropin.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Generate target-bootstrapper drop-in for detected serial devices
+Before=serial-getty@.service getty@.service
+After=dev-*.device
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/target-bootstrapper-service/generate-target-bootstrapper-dropin.sh
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-isar/recipes-installer/target-bootstrapper-service/target-bootstrapper-service.bb b/meta-isar/recipes-installer/target-bootstrapper-service/target-bootstrapper-service.bb
index e7a8b2a1..572cddcd 100644
--- a/meta-isar/recipes-installer/target-bootstrapper-service/target-bootstrapper-service.bb
+++ b/meta-isar/recipes-installer/target-bootstrapper-service/target-bootstrapper-service.bb
@@ -25,6 +25,8 @@ inherit dpkg-raw
 SRC_URI = "\
     file://postinst.tmpl \
     file://target-bootstrapper.override.conf \
+    file://generate-target-bootstrapper-dropin.sh \
+    file://target-bootstrapper-generate-dropin.service \
     "
 
 TEMPLATE_FILES = "postinst.tmpl"
@@ -33,11 +35,19 @@ TEMPLATE_VARS = "TARGET_BOOTSTRAPPER_TTY_SERVICES"
 DEPENDS += " target-bootstrapper"
 DEBIAN_DEPENDS = "target-bootstrapper"
 
-do_install[cleandirs] = "${D}/usr/lib/systemd/system/"
+do_install[cleandirs] = "${D}/usr/lib/systemd/system/ ${D}/usr/libexec"
 do_install() {
     for svc_name in ${TARGET_BOOTSTRAPPER_TTY_SERVICES}
     do
-        mkdir -p ${D}/usr/lib/systemd/system/${svc_name}.service.d/
+        install -d -m 0755 ${D}/usr/lib/systemd/system/${svc_name}.service.d/
         install -m 0644 ${WORKDIR}/target-bootstrapper.override.conf ${D}/usr/lib/systemd/system/${svc_name}.service.d/10-target-bootstrapper.override.conf
     done
+
+    # Install script and service for runtime detection of serial devices
+    install -d -m 0755 ${D}/usr/libexec/${PN}/
+    install -m 0755 ${WORKDIR}/generate-target-bootstrapper-dropin.sh ${D}/usr/libexec/${PN}/
+    install -m 0644 ${WORKDIR}/target-bootstrapper-generate-dropin.service ${D}/usr/lib/systemd/system/
+
+    # Install override template for runtime use by the detection script
+    install -m 0644 ${WORKDIR}/target-bootstrapper.override.conf ${D}/usr/lib/target-bootstrapper.override.conf
 }
-- 
2.39.5

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20260619103944.1303513-1-gouravsingh%40siemens.com.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] target-bootstrapper-service: add runtime serial tty drop-in generation
  2026-06-19 10:39 [PATCH] target-bootstrapper-service: add runtime serial tty drop-in generation 'Gourav Singh' via isar-users
@ 2026-07-01  9:04 ` Zhihang Wei
  0 siblings, 0 replies; 2+ messages in thread
From: Zhihang Wei @ 2026-07-01  9:04 UTC (permalink / raw)
  To: Gourav Singh, isar-users

Applied to next, thanks.

Zhihang

On 6/19/26 12:39, 'Gourav Singh' via isar-users wrote:
> Extend the recipe to support dynamically detected serial consoles without
> taking over every getty instance.
>
> The existing loop still installs overrides for statically configured
> TARGET_BOOTSTRAPPER_TTY_SERVICES. In addition, a runtime oneshot service
> and helper script are installed to detect the first available serial tty
> (ttyACM*/ttyUSB*/ttyAMA*/ttyGS*) and create one matching
> serial-getty@<tty>.service.d override from a stored template.
>
> This keeps installer behavior on configured ttys, adds support for
> runtime-discovered serial devices, and preserves other consoles for
> normal login/debug access.
>
> Signed-off-by: Gourav Singh <gouravsingh@siemens.com>
> ---
>   .../generate-target-bootstrapper-dropin.sh    | 47 +++++++++++++++++++
>   .../files/postinst.tmpl                       |  3 ++
>   ...arget-bootstrapper-generate-dropin.service | 12 +++++
>   .../target-bootstrapper-service.bb            | 14 +++++-
>   4 files changed, 74 insertions(+), 2 deletions(-)
>   create mode 100644 meta-isar/recipes-installer/target-bootstrapper-service/files/generate-target-bootstrapper-dropin.sh
>   create mode 100644 meta-isar/recipes-installer/target-bootstrapper-service/files/target-bootstrapper-generate-dropin.service
>
> diff --git a/meta-isar/recipes-installer/target-bootstrapper-service/files/generate-target-bootstrapper-dropin.sh b/meta-isar/recipes-installer/target-bootstrapper-service/files/generate-target-bootstrapper-dropin.sh
> new file mode 100644
> index 00000000..50c3ba40
> --- /dev/null
> +++ b/meta-isar/recipes-installer/target-bootstrapper-service/files/generate-target-bootstrapper-dropin.sh
> @@ -0,0 +1,47 @@
> +#!/bin/sh
> +# This software is a part of Isar.
> +# Copyright (C) Siemens AG, 2026
> +#
> +# SPDX-License-Identifier: MIT
> +
> +set -e
> +
> +OVERRIDE_DIR="/usr/lib/systemd/system"
> +DROP_IN_SUFFIX="d/10-target-bootstrapper.override.conf"
> +
> +# Check if override template exists
> +if [ ! -f "/usr/lib/target-bootstrapper.override.conf" ]; then
> +    exit 0
> +fi
> +
> +# Detect first available serial device (ttyACM*, ttyUSB*, ttyAMA*, etc.)
> +detect_first_serial_device() {
> +    for pattern in ttyACM ttyUSB ttyAMA ttyGS; do
> +        for dev in /dev/${pattern}*; do
> +            if [ -c "$dev" ]; then
> +                basename "$dev"
> +                return 0
> +            fi
> +        done
> +    done
> +}
> +
> +DETECTED_TTY=$(detect_first_serial_device 2>/dev/null)
> +
> +if [ -z "$DETECTED_TTY" ]; then
> +    exit 0
> +fi
> +
> +# Map device name to getty service instance
> +# e.g. ttyACM0 -> serial-getty@ttyACM0.service
> +TTY_SERVICE="serial-getty@${DETECTED_TTY}.service"
> +DROP_IN_DIR="${OVERRIDE_DIR}/${TTY_SERVICE}.d"
> +
> +# Create drop-in directory and install override
> +mkdir -p "$DROP_IN_DIR"
> +cp "/usr/lib/target-bootstrapper.override.conf" "$DROP_IN_DIR/${DROP_IN_SUFFIX##*/}"
> +
> +# Reload systemd to pick up new drop-ins
> +systemctl daemon-reload || true
> +
> +exit 0
> diff --git a/meta-isar/recipes-installer/target-bootstrapper-service/files/postinst.tmpl b/meta-isar/recipes-installer/target-bootstrapper-service/files/postinst.tmpl
> index 7c24af17..57851956 100644
> --- a/meta-isar/recipes-installer/target-bootstrapper-service/files/postinst.tmpl
> +++ b/meta-isar/recipes-installer/target-bootstrapper-service/files/postinst.tmpl
> @@ -5,3 +5,6 @@ set -e
>   for tty_service in ${TARGET_BOOTSTRAPPER_TTY_SERVICES}; do
>       deb-systemd-helper enable ${tty_service} || true
>   done
> +
> +# Enable the runtime detection service
> +deb-systemd-helper enable target-bootstrapper-generate-dropin.service || true
> diff --git a/meta-isar/recipes-installer/target-bootstrapper-service/files/target-bootstrapper-generate-dropin.service b/meta-isar/recipes-installer/target-bootstrapper-service/files/target-bootstrapper-generate-dropin.service
> new file mode 100644
> index 00000000..38457c8d
> --- /dev/null
> +++ b/meta-isar/recipes-installer/target-bootstrapper-service/files/target-bootstrapper-generate-dropin.service
> @@ -0,0 +1,12 @@
> +[Unit]
> +Description=Generate target-bootstrapper drop-in for detected serial devices
> +Before=serial-getty@.service getty@.service
> +After=dev-*.device
> +
> +[Service]
> +Type=oneshot
> +ExecStart=/usr/libexec/target-bootstrapper-service/generate-target-bootstrapper-dropin.sh
> +RemainAfterExit=yes
> +
> +[Install]
> +WantedBy=multi-user.target
> diff --git a/meta-isar/recipes-installer/target-bootstrapper-service/target-bootstrapper-service.bb b/meta-isar/recipes-installer/target-bootstrapper-service/target-bootstrapper-service.bb
> index e7a8b2a1..572cddcd 100644
> --- a/meta-isar/recipes-installer/target-bootstrapper-service/target-bootstrapper-service.bb
> +++ b/meta-isar/recipes-installer/target-bootstrapper-service/target-bootstrapper-service.bb
> @@ -25,6 +25,8 @@ inherit dpkg-raw
>   SRC_URI = "\
>       file://postinst.tmpl \
>       file://target-bootstrapper.override.conf \
> +    file://generate-target-bootstrapper-dropin.sh \
> +    file://target-bootstrapper-generate-dropin.service \
>       "
>   
>   TEMPLATE_FILES = "postinst.tmpl"
> @@ -33,11 +35,19 @@ TEMPLATE_VARS = "TARGET_BOOTSTRAPPER_TTY_SERVICES"
>   DEPENDS += " target-bootstrapper"
>   DEBIAN_DEPENDS = "target-bootstrapper"
>   
> -do_install[cleandirs] = "${D}/usr/lib/systemd/system/"
> +do_install[cleandirs] = "${D}/usr/lib/systemd/system/ ${D}/usr/libexec"
>   do_install() {
>       for svc_name in ${TARGET_BOOTSTRAPPER_TTY_SERVICES}
>       do
> -        mkdir -p ${D}/usr/lib/systemd/system/${svc_name}.service.d/
> +        install -d -m 0755 ${D}/usr/lib/systemd/system/${svc_name}.service.d/
>           install -m 0644 ${WORKDIR}/target-bootstrapper.override.conf ${D}/usr/lib/systemd/system/${svc_name}.service.d/10-target-bootstrapper.override.conf
>       done
> +
> +    # Install script and service for runtime detection of serial devices
> +    install -d -m 0755 ${D}/usr/libexec/${PN}/
> +    install -m 0755 ${WORKDIR}/generate-target-bootstrapper-dropin.sh ${D}/usr/libexec/${PN}/
> +    install -m 0644 ${WORKDIR}/target-bootstrapper-generate-dropin.service ${D}/usr/lib/systemd/system/
> +
> +    # Install override template for runtime use by the detection script
> +    install -m 0644 ${WORKDIR}/target-bootstrapper.override.conf ${D}/usr/lib/target-bootstrapper.override.conf
>   }

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/b0db2afd-d5eb-491b-80cc-07e467323ef9%40ilbers.de.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-01  9:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-19 10:39 [PATCH] target-bootstrapper-service: add runtime serial tty drop-in generation 'Gourav Singh' via isar-users
2026-07-01  9:04 ` Zhihang Wei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox