Rework EEPROM access in shell scripts

This commit is contained in:
Joris van Rantwijk 2024-10-04 19:36:04 +02:00
parent fe9d56c161
commit e198b3bc91
2 changed files with 25 additions and 12 deletions

View File

@ -61,3 +61,23 @@ sync_config() {
sync
}
# Read settings from EEPROM.
# Defines variables $eeprom_ethaddr and $eeprom_hw_rev.
read_eeprom() {
tmpfile=$(mktemp -t eeprom.XXXXXX)
dd if=/sys/bus/i2c/devices/0-0050/eeprom bs=1k skip=6 count=1 status=none | tr '\000' '\n' > $tmpfile
while read -r eeprom_item eeprom_rest ; do
if [ "${eeprom_item}" != "${eeprom_item#ethaddr=}" ]; then
eeprom_ethaddr="${eeprom_item#ethaddr=}"
fi
if [ "${eeprom_item}" != "${eeprom_item#hw_rev=}" ]; then
eeprom_hw_rev="${eeprom_item#hw_rev=}"
fi
done < $tmpfile
rm -f $tmpfile
}

View File

@ -3,24 +3,17 @@
# Script to run the remote control server.
#
. /opt/puzzlefw/lib/functions.sh
PIDFILE=/var/run/puzzlefw_remotectl.pid
# Redirect output to console.
exec &> /dev/console
# Read model and serial number from EEPROM.
model=unknown
serialnr=0
dd if=/sys/bus/i2c/devices/0-0050/eeprom bs=1k skip=6 count=1 status=none | tr '\000' '\n' > /tmp/run_remotectl_eeprom
while read -r cfgitem cfgrest ; do
if [ "$cfgitem" != "${cfgitem#hw_rev=}" ]; then
model="${cfgitem#hw_rev=}"
fi
if [ "$cfgitem" != "${cfgitem#ethaddr=}" ]; then
serialnr="${cfgitem#ethaddr=}"
fi
done < /tmp/run_remotectl_eeprom
read_eeprom
model="${eeprom_hw_rev:-unknown}"
serialnr="${eeprom_ethaddr:-0}"
echo "model=$model"
echo "serialnr=$serialnr"