diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/firmware/critical/pieeprom-2019-09-10.bin b/firmware/critical/pieeprom-2019-09-10.bin new file mode 100644 index 0000000..df5ead0 Binary files /dev/null and b/firmware/critical/pieeprom-2019-09-10.bin differ diff --git a/firmware/recovery.bin b/firmware/recovery.bin index 218375c..50717cd 100644 Binary files a/firmware/recovery.bin and b/firmware/recovery.bin differ diff --git a/firmware/release-notes.md b/firmware/release-notes.md index f0695e2..217e33b 100644 --- a/firmware/release-notes.md +++ b/firmware/release-notes.md @@ -1,6 +1,6 @@ # Raspberry Pi4 bootloader EEPROM release notes -## 2019-09-10 - Git f626c772 - (BETA) +## 2019-09-10 - Git f626c772 * Configure ethernet RGMII pins at power on. This is a minor change which which may improve reliability of ethernet for some users. diff --git a/rpi-eeprom-config b/rpi-eeprom-config index 32cbd80..ee39da2 100755 --- a/rpi-eeprom-config +++ b/rpi-eeprom-config @@ -15,7 +15,8 @@ IMAGE_SIZE = 512 * 1024 # The number, order and size of the sections depends on the bootloader version # but the following mask can be used to test for section headers and skip # unknown data. -MAGIC_MASK = 0x55aaf00f +MAGIC = 0x55aaf00f +MAGIC_MASK = 0xfffff00f FILE_MAGIC = 0x55aaf11f # id for modifiable file, currently only bootconf.txt FILE_HDR_LEN = 20 FILENAME_LEN = 12 @@ -37,7 +38,7 @@ class BootloaderImage(object): magic = 0 while offset < IMAGE_SIZE: magic, length = struct.unpack_from('>LL', self._bytes, offset) - if (magic & MAGIC_MASK) != MAGIC_MASK: + if (magic & MAGIC_MASK) != MAGIC: raise Exception('EEPROM is corrupted') if magic == FILE_MAGIC: # Found a file diff --git a/rpi-eeprom-update b/rpi-eeprom-update index 1c3dc09..76a261f 100755 --- a/rpi-eeprom-update +++ b/rpi-eeprom-update @@ -167,16 +167,16 @@ getCurrentVersion() { fi } -# Set to the latest critical firmware version -CRITICAL_UPDATE_IMAGE="" -CRITICAL_UPDATE_VERSION=0 -getLatestCriticalUpdate() { - CRITICAL_UPDATE_VERSION=0 +# Find latest applicable update version +UPDATE_IMAGE="" +UPDATE_VERSION=0 +getUpdateVersion() { + UPDATE_VERSION=0 match=".*/pieeprom-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].bin" latest="$(find "${FIRMWARE_IMAGE_DIR}" -maxdepth 1 -type f -size "${EEPROM_SIZE}c" -regex "${match}" | sort -r | head -n1)" if [ -f "${latest}" ]; then - CRITICAL_UPDATE_VERSION=$(strings "${latest}" | grep BUILD_TIMESTAMP | sed 's/.*=//g') - CRITICAL_UPDATE_IMAGE="${latest}" + UPDATE_VERSION=$(strings "${latest}" | grep BUILD_TIMESTAMP | sed 's/.*=//g') + UPDATE_IMAGE="${latest}" fi } @@ -189,11 +189,11 @@ checkDependencies() { fi if [ ! -d "${FIRMWARE_IMAGE_DIR}" ]; then - die "Bootloader critical updates directory ${FIRMWARE_IMAGE_DIR} not found." + die "Bootloader updates directory ${FIRMWARE_IMAGE_DIR} not found." fi if vcgencmd bootloader_config | grep -qi "Command not registered"; then - die "vcgencmd: bootloader_config. not supported. Please update VC firmware" + die "vcgencmd: 'bootloader_config' command not supported. Please update VC firmware" fi if ! flashrom --version > /dev/null 2>&1; then @@ -201,14 +201,14 @@ checkDependencies() { fi if [ "${USE_FLASHROM}" = 0 ]; then - [ -f "${RECOVERY_BIN}" ] || die "${RECOVERY_BIN} not found" + [ -f "${RECOVERY_BIN}" ] || die "${RECOVERY_BIN} not found." fi } usage() { cat <&2 + exit 1 +} + +TMP_CONFIG="" +TMP_EEPROM="" +cleanup() { + rm -f "${TMP_CONFIG}" -f "${TMP_EEPROM}" + TMP_CONFIG="" + TMP_EEPROM="" +} +trap cleanup EXIT + +check_loopback() +{ + echo "check_update $1 $2" + + image="${script_dir}/$1" + conf="${script_dir}/$2" + + # Check that the production config file can be read correctly + expected_md5="$(md5sum "${conf}" | awk '{print $1}')" + actual_md5="$("${script_dir}/../rpi-eeprom-config" "${image}" | md5sum | awk '{print $1}')" + [ "${actual_md5}" = "${expected_md5}" ] || die "Config-read: checksum mismatch" + + # Check that overwriting the config section produces an identical binary + TMP_EEPROM=$(mktemp) + "${script_dir}/../rpi-eeprom-config" \ + "${image}" \ + --config "${conf}" \ + --out "${TMP_EEPROM}" + + expected_md5="$(md5sum "${image}" | awk '{print $1}')" + actual_md5="$(md5sum "${TMP_EEPROM}" | awk '{print $1}')" + [ "${actual_md5}" = "${expected_md5}" ] || die "EEPROM loopback: checksum mismatch" +} + +# Update the EEPROM with a new config and check the expected image is produced +check_update() +{ + echo "check_update $1 $2 $3" + + image="${script_dir}/$1" + ref_image="${script_dir}/$2" + conf="${script_dir}/$3" + + expected_md5="$(md5sum "${ref_image}" | awk '{print $1}')" + + TMP_EEPROM="$(mktemp)" + "${script_dir}/../rpi-eeprom-config" \ + "${image}" \ + --config "${conf}" \ + --out "${TMP_EEPROM}" + + actual_md5="$(md5sum "${TMP_EEPROM}" | awk '{print $1}')" + if [ "${actual_md5}" != "${expected_md5}" ]; then + hexdump -C "${TMP_EEPROM}" > "tmp.hex" + die "EEPROM update: checksum mismatch" + fi +} + +check_loopback "../firmware/critical/pieeprom-2019-05-10.bin" "bootconf-2019-05-10.txt" +cleanup + +check_loopback "../firmware/critical/pieeprom-2019-07-15.bin" "bootconf-2019-07-15.txt" +cleanup + +check_update "../firmware/critical/pieeprom-2019-07-15.bin" "pieeprom-2019-07-15-freeze.bin" "bootconf-2019-07-15-freeze.txt" +cleanup