From f882f8a89711d51f4597b99445d7c1ffd000a9a8 Mon Sep 17 00:00:00 2001
From: Jip Galema <jipgalema@hotmail.com>
Date: Mon, 30 Dec 2024 10:09:59 +0100
Subject: [PATCH] [SEM-442] Check bom number to change display type when
 upgrading

---
 initramfs/init.sh | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/initramfs/init.sh b/initramfs/init.sh
index 35cd128..b19870d 100644
--- a/initramfs/init.sh
+++ b/initramfs/init.sh
@@ -25,10 +25,6 @@ BOOT_PARTITION="${EMMC_DEV}p1"
 SYSTEM_UPDATE_ENTRYPOINT="start_update.sh"
 UPDATE_DEVICES="/dev/mmcblk[0-9]p[0-9]"
 
-#uc2 : UltiController 2 (UM3,UM3E) This UltiController is not considered here anymore
-#uc3 : UltiController 3 (S5,S5r2,S3)
-#uc4 : UltiController 4 (Colorado)
-DISPLAY_TYPE="uc4"
 UM_SPLASH="umsplash.fb"
 FB_DEVICE="/dev/fb0"
 
@@ -346,9 +342,24 @@ find_and_run_update()
             echo "Warning: unable to unmount '${UPDATE_IMG_MOUNT}'."
         fi
 
-        echo "Got '${SYSTEM_UPDATE_ENTRYPOINT}' script, trying to execute."
-        if ! "${update_tmpfs_mount}/${SYSTEM_UPDATE_ENTRYPOINT}" "${update_tmpfs_mount}/${UPDATE_IMAGE}" "${EMMC_DEV}" "${DISPLAY_TYPE}" "${SOFTWARE_INSTALL_MODE}"; then
-            echo "Error, update failed: executing '${update_tmpfs_mount}/${SYSTEM_UPDATE_ENTRYPOINT} ${update_tmpfs_mount}/${UPDATE_IMAGE} ${EMMC_DEV} ${DISPLAY_TYPE} ${SOFTWARE_INSTALL_MODE}'."
+
+        # Read the article number from the I2C device
+        art_num=$(i2ctransfer -y 1 w2@0x57 0x01 0x00 r4)
+        echo "---> Article number read from EEPROM: >${art_num}<"
+
+        # Convert the hexadecimal article number to a single decimal number
+        # Assuming art_num is in the format "0x00 0x03 0x78 0x34"
+        art_num_hex=""
+        for hex in $art_num; do
+            art_num_hex="${art_num_hex}${hex#0x}"  # Remove the "0x" prefix
+        done
+        art_num_dec=$(printf "%d\n" "0x$art_num_hex")
+
+        echo "---> Article number in decimal: >${art_num_dec}<"
+
+        echo "Got '${SYSTEM_UPDATE_ENTRYPOINT}' script, trying to execute, with art_num_dec=${art_num_dec}."
+        if ! "${update_tmpfs_mount}/${SYSTEM_UPDATE_ENTRYPOINT}" "${update_tmpfs_mount}/${UPDATE_IMAGE}" "${EMMC_DEV}" "${art_num_dec}" "${SOFTWARE_INSTALL_MODE}"; then
+            echo "Error, update failed: executing '${update_tmpfs_mount}/${SYSTEM_UPDATE_ENTRYPOINT} ${update_tmpfs_mount}/${UPDATE_IMAGE} ${EMMC_DEV} ${art_num_dec} ${SOFTWARE_INSTALL_MODE}'."
             critical_error
             break
         fi