Simplify hwrev configuration
authorHugo Villeneuve <hugo@hugovil.com>
Sat, 13 Dec 2025 16:38:47 +0000 (11:38 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Fri, 23 Jan 2026 16:44:47 +0000 (11:44 -0500)
Uses new hwrev class in meta-dimonoff to simplify hwrev configuration
for swupdate and scripts.

The following variables are now automatically set by hwrev class:

    HWREV_LATEST
    HWREV_LATEST_NUM
    HWREV_PREFIX ?= "rev"

Signed-off-by: Hugo Villeneuve <hugo@hugovil.com>
raspberrypi/conf/machine/raspberrypi-extra.conf
recipes-support/swupdate/swupdate/97-hwrevision-hardcoded.sh.in
recipes-support/swupdate/swupdate_%.bbappend
wandboard/conf/machine/wandboard-extra.conf

index 26f7c68..1c544b0 100644 (file)
@@ -20,10 +20,8 @@ VIDEO_CAMERA = "0"
 
 WKS_FILE = "hvmpd-raspberrypi.wks.in"
 
-# List of hardware versions supported by our swupdate setup. Each revision must
-# be enclosed within double-quotes, and separated with a comma.
-# Exemple: SWUPDATE_HWREV = ""revA", "revB""
-SWUPDATE_HWREV = ""revA""
+# List of hardware versions supported by our swupdate setup.
+HWREV_LIST = "A"
 
 RPI_KERNEL_DEVICETREE_OVERLAYS += " \
     overlays/hvmpd.dtbo \
index 44bdf5d..8672113 100644 (file)
@@ -1,12 +1,26 @@
 #!/bin/sh
 
-# TODO: the revision should be read at bootup from an EEPROM or other means.
-# For now, it is simply hardcoded.
-HWREV="revA"
+. /usr/bin/dimonoff.sh
 
+# Note: this script is sourced by swupdate. In case of success, we must not use
+# the exit statement, but return. Exit is ok in case of error.
+
+# Write infos under /var/run so that it works for read-only rootfs
 DESTDIR="/var/run/swupdate"
 DESTFILE="${DESTDIR}/hwrevision"
 
+EEPROM_I2C_DEVNUM="@EEPROM_I2C_DEVNUM@"
+
+devpath="/sys/bus/i2c/devices/${EEPROM_I2C_DEVNUM}/eeprom"
+
+# Define default hardware revision.
+# If the EEPROM is present, when we exit, the next script executed by
+# swupdate (98-hwrevision-tlv-eeprom.sh) will handle the actual hardware
+# revision stored in the TLV EEPROM.
+
 mkdir -p ${DESTDIR}
+echo "@MACHINE@ @HWREV_LATEST@" > ${DESTFILE}
 
-echo "@MACHINE@ ${HWREV}" > ${DESTFILE}
+if [ ! -f ${devpath} ]; then
+    log_warn "EEPROM not found, using hardcoded hardware revision (@HWREV_LATEST@)"
+fi
index a475262..350bd51 100644 (file)
@@ -4,9 +4,16 @@ SRC_URI:append:hvmpd = " \
     file://97-hwrevision-hardcoded.sh.in \
 "
 
+inherit hwrev
+
 do_install:append:hvmpd() {
-    sed -e s/@MACHINE@/${MACHINE}/ \
-        ${WORKDIR}/97-hwrevision-hardcoded.sh.in > ${WORKDIR}/97-hwrevision-hardcoded.sh
+    cp ${WORKDIR}/97-hwrevision-hardcoded.sh.in ${WORKDIR}/97-hwrevision-hardcoded.sh
+
+    sed -e "s!@MACHINE@!${MACHINE}!g" \
+        -e "s!@EEPROM_I2C_DEVNUM@!${EEPROM_I2C_DEVNUM}!g" \
+        -e "s!@HWREV_LATEST@!${HWREV_LATEST}!g" \
+        -i ${WORKDIR}/97-hwrevision-hardcoded.sh
+
     install -d ${D}${libdir}/swupdate/conf.d/
     install -m 644 ${WORKDIR}/97-hwrevision-hardcoded.sh ${D}${libdir}/swupdate/conf.d/
 }
index 95c8fb5..290d664 100644 (file)
@@ -15,7 +15,5 @@ IMAGE_FSTYPES = "tar.xz wic.gz wic.bmap"
 
 WKS_FILE = "hvmpd-wandboard.wks.in"
 
-# List of hardware versions supported by our swupdate setup. Each revision must
-# be enclosed within double-quotes, and separated with a comma.
-# Exemple: SWUPDATE_HWREV = ""revA", "revB""
-SWUPDATE_HWREV = ""revA""
+# List of hardware versions supported by our swupdate setup.
+HWREV_LIST = "A"