mirror of
https://github.com/raspberrypi/rpi-eeprom.git
synced 2026-01-21 14:53:32 +08:00
Merge pull request #66 from timg236/eeprom_config_hook
Eeprom config hook
This commit is contained in:
@@ -57,6 +57,9 @@ cleanup() {
|
|||||||
if [ -f "${TMP_EEPROM_CONFIG}" ]; then
|
if [ -f "${TMP_EEPROM_CONFIG}" ]; then
|
||||||
rm -f "${TMP_EEPROM_CONFIG}"
|
rm -f "${TMP_EEPROM_CONFIG}"
|
||||||
fi
|
fi
|
||||||
|
if [ -f "${NEW_EEPROM_CONFIG}" ]; then
|
||||||
|
rm -f "${NEW_EEPROM_CONFIG}"
|
||||||
|
fi
|
||||||
if [ -d "${TMP_BOOTFS_MNT}" ]; then
|
if [ -d "${TMP_BOOTFS_MNT}" ]; then
|
||||||
umount "${TMP_BOOTFS_MNT}"
|
umount "${TMP_BOOTFS_MNT}"
|
||||||
rmdir "${TMP_BOOTFS_MNT}"
|
rmdir "${TMP_BOOTFS_MNT}"
|
||||||
@@ -64,6 +67,7 @@ cleanup() {
|
|||||||
TMP_BOOTFS_MNT=
|
TMP_BOOTFS_MNT=
|
||||||
TMP_EEPROM_IMAGE=
|
TMP_EEPROM_IMAGE=
|
||||||
TMP_EEPROM_CONFIG=
|
TMP_EEPROM_CONFIG=
|
||||||
|
NEW_EEPROM_CONFIG=
|
||||||
}
|
}
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
@@ -77,6 +81,7 @@ prepareImage()
|
|||||||
[ -f "${BOOTLOADER_UPDATE_IMAGE}" ] || die "EEPROM image \'${BOOTLOADER_UPDATE_IMAGE}\' not found"
|
[ -f "${BOOTLOADER_UPDATE_IMAGE}" ] || die "EEPROM image \'${BOOTLOADER_UPDATE_IMAGE}\' not found"
|
||||||
TMP_EEPROM_IMAGE="$(mktemp)"
|
TMP_EEPROM_IMAGE="$(mktemp)"
|
||||||
TMP_EEPROM_CONFIG="$(mktemp)"
|
TMP_EEPROM_CONFIG="$(mktemp)"
|
||||||
|
NEW_EEPROM_CONFIG="$(mktemp)"
|
||||||
|
|
||||||
mkdir -p "${FIRMWARE_BACKUP_DIR}"
|
mkdir -p "${FIRMWARE_BACKUP_DIR}"
|
||||||
|
|
||||||
@@ -85,7 +90,17 @@ prepareImage()
|
|||||||
backup="${FIRMWARE_BACKUP_DIR}/pieeprom-backup-$(date +%Y%m%d-%H%M%S).conf"
|
backup="${FIRMWARE_BACKUP_DIR}/pieeprom-backup-$(date +%Y%m%d-%H%M%S).conf"
|
||||||
cp -f "${TMP_EEPROM_CONFIG}" "${backup}"
|
cp -f "${TMP_EEPROM_CONFIG}" "${backup}"
|
||||||
|
|
||||||
if [ "$(wc -l "${TMP_EEPROM_CONFIG}" | awk '{print $1}')" -lt 3 ]; then
|
if [ -x "${EEPROM_CONFIG_HOOK}" ]; then
|
||||||
|
echo "Running EEPROM config hook ${EEPROM_CONFIG_HOOK}"
|
||||||
|
if ! "${EEPROM_CONFIG_HOOK}" -u "${BOOTLOADER_UPDATE_IMAGE}" < "${TMP_EEPROM_CONFIG}" > "${NEW_EEPROM_CONFIG}"; then
|
||||||
|
echo "EEPROM config hook \"${EEPROM_CONFIG_HOOK}\" failed. Using original configuration"
|
||||||
|
cp -f "${TMP_EEPROM_CONFIG}" "${NEW_EEPROM_CONFIG}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
cp -f "${TMP_EEPROM_CONFIG}" "${NEW_EEPROM_CONFIG}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$(wc -l "${NEW_EEPROM_CONFIG}" | awk '{print $1}')" -lt 3 ]; then
|
||||||
# Don't propagate empty EEPROM config files and also prevent the initial
|
# Don't propagate empty EEPROM config files and also prevent the initial
|
||||||
# bootloader config with WAKE_ON_GPIO=0 propgating to newer versions by
|
# bootloader config with WAKE_ON_GPIO=0 propgating to newer versions by
|
||||||
# accident.
|
# accident.
|
||||||
@@ -97,7 +112,7 @@ prepareImage()
|
|||||||
if [ "${OVERWRITE_CONFIG}" = 0 ]; then
|
if [ "${OVERWRITE_CONFIG}" = 0 ]; then
|
||||||
"${script_dir}/rpi-eeprom-config" \
|
"${script_dir}/rpi-eeprom-config" \
|
||||||
--out "${TMP_EEPROM_IMAGE}" \
|
--out "${TMP_EEPROM_IMAGE}" \
|
||||||
--config "${TMP_EEPROM_CONFIG}" "${BOOTLOADER_UPDATE_IMAGE}"
|
--config "${NEW_EEPROM_CONFIG}" "${BOOTLOADER_UPDATE_IMAGE}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,6 +291,7 @@ checkDependencies() {
|
|||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
rpi-eeprom-update [options]... [FILE]
|
rpi-eeprom-update [options]... [FILE]
|
||||||
|
|
||||||
Checks whether the Raspberry Pi bootloader and the VL805 USB controller
|
Checks whether the Raspberry Pi bootloader and the VL805 USB controller
|
||||||
EEPROMs are up-to-date and optionally updates the EEPROMs at the next reboot.
|
EEPROMs are up-to-date and optionally updates the EEPROMs at the next reboot.
|
||||||
|
|
||||||
@@ -295,15 +311,10 @@ rpi-eeprom-update [options]... [FILE]
|
|||||||
is not a NOOBS system then the mount point for BOOTFS should be defined
|
is not a NOOBS system then the mount point for BOOTFS should be defined
|
||||||
in /etc/default/rpi-eeprom-update by defining the BOOTFS variable.
|
in /etc/default/rpi-eeprom-update by defining the BOOTFS variable.
|
||||||
|
|
||||||
For reference, the flashrom update mechanism may be enabled by defining
|
|
||||||
USE_FLASHROM=1 in /etc/default/rpi-eeprom-update. This not recommended
|
|
||||||
because the SPI pins are muxed with audio and other device drivers may
|
|
||||||
be using SPI (e.g. HATs). This is also not safe in the event of a power
|
|
||||||
failure during the update of the EEPROM.
|
|
||||||
|
|
||||||
A backup of the current EEPROM config file is written to ${FIRMWARE_BACKUP_DIR}
|
A backup of the current EEPROM config file is written to ${FIRMWARE_BACKUP_DIR}
|
||||||
before applying the update.
|
before applying the update.
|
||||||
|
|
||||||
|
Options:
|
||||||
-a Automatically install bootloader and USB (VLI) EEPROM updates.
|
-a Automatically install bootloader and USB (VLI) EEPROM updates.
|
||||||
-A Specify which type of EEPROM to automatically update (vl805 or bootloader)
|
-A Specify which type of EEPROM to automatically update (vl805 or bootloader)
|
||||||
-d Use the default bootloader config instead of migrating the current settings
|
-d Use the default bootloader config instead of migrating the current settings
|
||||||
@@ -319,6 +330,29 @@ rpi-eeprom-update [options]... [FILE]
|
|||||||
-r Removes temporary EEPROM update files from the boot partition.
|
-r Removes temporary EEPROM update files from the boot partition.
|
||||||
-u Install the specified VL805 (USB EEPROM) image file.
|
-u Install the specified VL805 (USB EEPROM) image file.
|
||||||
|
|
||||||
|
Environment:
|
||||||
|
Environment variables should be defined in /etc/default/rpi-eeprom-update
|
||||||
|
|
||||||
|
EEPROM_CONFIG_HOOK
|
||||||
|
|
||||||
|
Specifies the path of an optional script which post-processes the
|
||||||
|
configuration file before it is applied to the new image. The modified
|
||||||
|
output must contain at least 3 lines and should contain WAKE_ON_GPIO
|
||||||
|
and POWER_OFF_ON_HALT settings.
|
||||||
|
|
||||||
|
USE_FLASHROM
|
||||||
|
|
||||||
|
The flashrom update mechanism may be enabled by setting USE_FLASHROM=1. This
|
||||||
|
also selects the vl805 tool instead of using recovery.bin to perform the
|
||||||
|
update. This may be desirable if an immediate update is required or if an
|
||||||
|
sd-card is not present.
|
||||||
|
However, this not recommended because the SPI pins are muxed with audio and other
|
||||||
|
device drivers may be using SPI (e.g. HATs). This is also not safe in the
|
||||||
|
event of a power failure during the update of the EEPROM.
|
||||||
|
Changing the VL805 firmware whilst USB devices are attached may also cause
|
||||||
|
those devices to stop working until after the system is reboot.
|
||||||
|
|
||||||
|
Examples:
|
||||||
To extract the configuration file from an EEPROM image:
|
To extract the configuration file from an EEPROM image:
|
||||||
rpi-eeprom-config pieeprom.bin --out bootconf.txt
|
rpi-eeprom-config pieeprom.bin --out bootconf.txt
|
||||||
|
|
||||||
@@ -328,8 +362,7 @@ rpi-eeprom-update [options]... [FILE]
|
|||||||
To flash the new image:
|
To flash the new image:
|
||||||
sudo rpi-eeprom-update -d -f ./pieeprom-new.bin
|
sudo rpi-eeprom-update -d -f ./pieeprom-new.bin
|
||||||
|
|
||||||
The syntax is the same as config.txt but section filters etc are not supported. See
|
The syntax is the same as config.txt See online documentation for the list of parameters.
|
||||||
online documentation for the list of parameters.
|
|
||||||
|
|
||||||
The official documentation for the Raspberry Pi bootloader EEPROM is available at
|
The official documentation for the Raspberry Pi bootloader EEPROM is available at
|
||||||
https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md
|
https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ FIRMWARE_IMAGE_DIR="${FIRMWARE_ROOT}/${FIRMWARE_RELEASE_STATUS}"
|
|||||||
FIRMWARE_BACKUP_DIR="/var/lib/raspberrypi/bootloader/backup"
|
FIRMWARE_BACKUP_DIR="/var/lib/raspberrypi/bootloader/backup"
|
||||||
BOOTFS=/boot
|
BOOTFS=/boot
|
||||||
USE_FLASHROM=0
|
USE_FLASHROM=0
|
||||||
|
EEPROM_CONFIG_HOOK=
|
||||||
|
|||||||
Reference in New Issue
Block a user