Rework EEPROM access in shell scripts
This commit is contained in:
parent
fe9d56c161
commit
e198b3bc91
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue