From 3b84b29d25b957d6f78cfbd0ec2dca9ffcd6de64 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20H=C3=B6ppner?= <jonas.hoeppner@garz-fricke.com>
Date: Thu, 4 Aug 2022 15:44:08 +0200
Subject: [PATCH] fng-install/prepare-image: Make output of prepare scripts
 visible

Also cleanup the output a little.
Make sure that the prepare_rtc script only affects Tanaro devices
---
 .../fnginstall-postinstallation                  |  2 +-
 .../fng-install/fng-install/fng-install.sh       |  4 +++-
 .../prepare-image/gf-prepare-bootpartition.sh    |  8 ++++----
 .../fng-install/prepare-image/gf-prepare-rtc.sh  | 16 ++++++++++++----
 4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/recipes-bsp/fng-install/fng-install-postinstallation/fnginstall-postinstallation b/recipes-bsp/fng-install/fng-install-postinstallation/fnginstall-postinstallation
index d5bfede7..11bacf71 100644
--- a/recipes-bsp/fng-install/fng-install-postinstallation/fnginstall-postinstallation
+++ b/recipes-bsp/fng-install/fng-install-postinstallation/fnginstall-postinstallation
@@ -19,7 +19,7 @@ IFS='|'
 for script in $scripts;
 do
 
-    [ "$VERBOSE" -gt 0 ] && echo "Running $script ..."
+    echo "Running $script ..."
 
     "./$script" --fngpostinstall
     r=$?
diff --git a/recipes-bsp/fng-install/fng-install/fng-install.sh b/recipes-bsp/fng-install/fng-install/fng-install.sh
index 59c4d83b..eca758b0 100644
--- a/recipes-bsp/fng-install/fng-install/fng-install.sh
+++ b/recipes-bsp/fng-install/fng-install/fng-install.sh
@@ -503,7 +503,7 @@ target_os_postinstall()
                 DEVICETREEOV='$DEVICETREEOV' \
                 ROOTPARTITION='$TARGET_PARTITION_ROOT' \
                 BOOTPARTITION='$TARGET_PARTITION_BOOT' \
-                $TARGET_POSTINSTALL_SCRIPT"
+                $TARGET_POSTINSTALL_SCRIPT" 2>&1 | tee -a "$LOGFILE" >&5
         then
             milestone "Executing postinstall step done."
         else
@@ -1140,6 +1140,7 @@ do_update()
         # Needs to go inside the subshell, otherwise the AB_PARTITIONING_TARGET
         # variable is not accessable
 
+        {
         if $AB_PARTITIONING_FOUND;then
             echo "Installed as '$AB_PARTITIONING_TARGET' installation, use"
             if [ $AB_PARTITIONING_TARGET = 'B' ];then
@@ -1149,6 +1150,7 @@ do_update()
             fi
             echo "to boot the newly installed image."
         fi
+        }>&5
     )
     return $?
 }
diff --git a/recipes-bsp/fng-install/prepare-image/gf-prepare-bootpartition.sh b/recipes-bsp/fng-install/prepare-image/gf-prepare-bootpartition.sh
index 99c473b0..f7bd5926 100644
--- a/recipes-bsp/fng-install/prepare-image/gf-prepare-bootpartition.sh
+++ b/recipes-bsp/fng-install/prepare-image/gf-prepare-bootpartition.sh
@@ -66,13 +66,13 @@ do
     get_partition_label label "$part"
     # Check
     if [ "$label" = "$PARTITION_LABEL" ];then
-        warn_msg "Warning: found duplicated label for bootpartition"
+        warn_msg "Found duplicated label for bootpartition"
         if command -v fatlabel 1>/dev/null;then
-            warn_msg "Warning: change label of $part to ${label}BAK"
+            warn_msg "Changing label of $part to ${label}BAK"
             fatlabel "$part" "${label}BAK"
         else
-            warn_msg "Warning: Deleting filesystem on $part"
-            dd if=/dev/zero of="$part" bs=1M count=1
+            warn_msg "Deleting filesystem on $part"
+            dd if=/dev/zero of="$part" bs=1M count=1 2>/dev/null
         fi
     fi
 done
diff --git a/recipes-bsp/fng-install/prepare-image/gf-prepare-rtc.sh b/recipes-bsp/fng-install/prepare-image/gf-prepare-rtc.sh
index 4202794d..ab89dafd 100644
--- a/recipes-bsp/fng-install/prepare-image/gf-prepare-rtc.sh
+++ b/recipes-bsp/fng-install/prepare-image/gf-prepare-rtc.sh
@@ -10,15 +10,21 @@ if ! . /usr/sbin/gf-prepare-common.sh; then
 fi
 
 poll_rtc() {
-    if i2cget -y 2 "$1" 0x00 2>&1 | grep -E '.*0x.*|.*Device or resource busy.*'; then
-        echo "Device found at address $1"
+    # Check if there is an i2c device at the know bus and address
+    # if the tool returns 'Device or resource busy' we assume a
+    # driver has grapped the existing rtc device
+    if i2cget -y 2 "$1" 0x00 2>&1 | grep -q -E '.*0x.*|.*Device or resource busy.*'; then
         return 0
     else
-        echo "No device found at address $1"
         return 1
     fi
 }
 
+# These overlays currently only apply to Tanaro
+if ! grep -q -i Tanaro /sys/devices/soc0/machine;then
+    echo "Device is not a 'Tanaro', skipping rtc detection."
+fi
+
 # Get the directory containing the bootfiles
 mount_bootpartition BOOTFILES_DIR
 
@@ -27,13 +33,15 @@ cd "$BOOTFILES_DIR" || exit 1
 
 # RX8803
 if poll_rtc 0x32; then
+    echo "Selecting overlay 'rx8803-overlay.dtbo'"
     append_overlay "rx8803-overlay.dtbo"
 else
     # PCF8563
     if poll_rtc 0x51; then
+        echo "Selecting overlay 'pcf8563-overlay.dtbo'"
         append_overlay "pcf8563-overlay.dtbo"
     else
-        echo "Error: Unable to find any valid device"
+        echo "Error: Unable to find any valid rtc device, not applying any overlay."
         exit 1
     fi
 fi
-- 
GitLab