From 705ea75cd6403a5f77fe8c272736cd596dd64006 Mon Sep 17 00:00:00 2001
From: Tobias Kahlki <tobias.kahlki@seco.com>
Date: Thu, 7 Nov 2024 15:21:47 +0100
Subject: [PATCH] helper: Add script to enable/disable the standard output on
 the terminal

This is required by some tests that exchange data on the default tty.

MODV-98
---
 helper/config_debug_serial.sh | 45 +++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 helper/config_debug_serial.sh

diff --git a/helper/config_debug_serial.sh b/helper/config_debug_serial.sh
new file mode 100644
index 0000000..4fd3cfd
--- /dev/null
+++ b/helper/config_debug_serial.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+# @TODO: What about USB serial? Will it still work?
+
+print_help() {
+    echo "Usage: config_debug_serial.sh {enable|disable|help}"
+}
+
+if [ ! $# -eq 1 ]; then
+    print_help
+    exit 1
+fi
+
+# @TODO: Check for /boot
+
+# Backup default config before changing it
+if [ ! -e /boot/boot.cfg.bak ]; then
+    cp /boot/boot.cfg /boot/boot.cfg.bak
+fi
+
+if [ "$1" = "enable" ]; then
+    # Enable Kernel output
+    sed -i -e 's/ quiet//' -e 's/console=\S*/console=ttymxc0,115200/' /boot/boot.cfg
+
+    # Enable auto spawning of getty
+    systemctl unmask serial-getty@.service
+elif [ "$1" = "disable" ]; then
+    # Disable Kernel output
+    #
+    # Note: Always try to remove the quiet
+    # argument, because it might be added
+    # twice when calling 'disable' more than
+    # one time.
+    sed -i -e 's/ quiet//' -e 's/console=\S*/console=ttynull quiet/' /boot/boot.cfg
+
+    # Disable auto spawning of getty
+    systemctl mask serial-getty@.service
+else
+    print_help
+    exit 1
+fi
+
+echo "INFO: Please reboot the device for the change to take effect"
+
+exit 0
-- 
GitLab