mirror of
https://github.com/raspberrypi/rpi-eeprom.git
synced 2026-01-20 21:13:36 +08:00
Merge pull request #29 from timg236/rpi_eeprom_config_2K
Rpi eeprom config 2 k
This commit is contained in:
@@ -10,6 +10,8 @@ import sys
|
||||
|
||||
IMAGE_SIZE = 512 * 1024
|
||||
|
||||
MAX_BOOTCONF_SIZE = 2024
|
||||
|
||||
# Each section starts with a magic number followed by a 32 bit offset to the
|
||||
# next section (big-endian).
|
||||
# The number, order and size of the sections depends on the bootloader version
|
||||
@@ -55,8 +57,9 @@ class BootloaderImage(object):
|
||||
hdr_offset, length = self.find_config()
|
||||
new_config_bytes = open(new_config, 'rb').read()
|
||||
new_len = len(new_config_bytes) + FILENAME_LEN + 4
|
||||
if new_len > length and new_len > 1024:
|
||||
raise Exception('Config is too large')
|
||||
if len(new_config_bytes) > MAX_BOOTCONF_SIZE:
|
||||
raise Exception("Config is too large (%d bytes). The maximum size is %d bytes."
|
||||
% (len(new_config_bytes), MAX_BOOTCONF_SIZE))
|
||||
if hdr_offset + len(new_config_bytes) + FILE_HDR_LEN > IMAGE_SIZE:
|
||||
raise Exception('EEPROM image size exceeded')
|
||||
|
||||
|
||||
@@ -276,7 +276,6 @@ findBootFS()
|
||||
# If ${BOOTFS} is not writable OR is not on /dev/mmcblk0 then error because the ROM
|
||||
# can only load recovery.bin from the on-board SD-CARD slot or the EEPROM.
|
||||
|
||||
# To skip installing the safe mode recovery.bin use the -s option
|
||||
if blkid | grep -qE "/dev/mmcblk0p1.*LABEL_FATBOOT.*RECOVERY.*TYPE.*vfat"; then
|
||||
TMP_BOOTFS_MNT="$(mktemp -d)"
|
||||
mount /dev/mmcblk0p1 "${TMP_BOOTFS_MNT}"
|
||||
@@ -284,8 +283,7 @@ findBootFS()
|
||||
fi
|
||||
|
||||
# If BOOTFS is not a directory or doesn't contain any .elf files then
|
||||
# it's probably not the boot partition so assume that it cannot be used for a
|
||||
# safe mode recovery
|
||||
# it's probably not the boot partition.
|
||||
[ -d "${BOOTFS}" ] || die "BOOTFS: \"${BOOTFS}\" is not a directory"
|
||||
[ "$(find "${BOOTFS}/" -name "*.elf" | wc -l)" -gt 0 ] || die "BOOTFS: \"${BOOTFS}\" contains no .elf files"
|
||||
}
|
||||
|
||||
28
test/bootconf-2024.txt
Normal file
28
test/bootconf-2024.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
[all]
|
||||
BOOT_UART=0
|
||||
WAKE_ON_GPIO=1
|
||||
POWER_OFF_ON_HALT=0
|
||||
[none]
|
||||
userdata0=0x12345789
|
||||
userdata1=0x12345789
|
||||
userdata2=0x12345789
|
||||
userdata3=0x12345789
|
||||
userdata4=0x12345789
|
||||
userdata5=0x12345789
|
||||
userdata6=0x12345789
|
||||
userdata7=0x12345789
|
||||
userdata8=0x12345789
|
||||
userdata9=0x12345789
|
||||
usercert=ZZZZZZZZZZZZlhEAAAADAQABAAABAQDg2l41l7troIKOA0hk3p9y4KuITWBL/aaTMORoqmXfyqEONNULSMElaLWch/b8ScHmcS+kxkS5DtLmKFo1JI14IaQNL5fr4C6Dp23CyMGIgjp3ZFg9tXs/qWpw36Ge0MCxjabbFeKVcMXD10voMT0AHfJtQb2YfOl37ffzC4bR3phUnp0Ceqpl0Loe6hxUP/r4Jen1OKskdfjsldfjalAjn9ASdkjnkjbaAKjnLKJbaKJHDRDkllDAlciaIKSPX2b0uk2MJRJhfarMHDnmxZtEzqMgwLdLol9XVjiSu/7EUzR9Qtvs8xhf6XuUJPRD6OtJCb49L+bb/pXAej/GOk0f
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# ++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
28
test/bootconf-2025.txt
Normal file
28
test/bootconf-2025.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
[all]
|
||||
BOOT_UART=0
|
||||
WAKE_ON_GPIO=1
|
||||
POWER_OFF_ON_HALT=0
|
||||
[none]
|
||||
userdata0=0x12345789
|
||||
userdata1=0x12345789
|
||||
userdata2=0x12345789
|
||||
userdata3=0x12345789
|
||||
userdata4=0x12345789
|
||||
userdata5=0x12345789
|
||||
userdata6=0x12345789
|
||||
userdata7=0x12345789
|
||||
userdata8=0x12345789
|
||||
userdata9=0x12345789
|
||||
usercert=ZZZZZZZZZZZZlhEAAAADAQABAAABAQDg2l41l7troIKOA0hk3p9y4KuITWBL/aaTMORoqmXfyqEONNULSMElaLWch/b8ScHmcS+kxkS5DtLmKFo1JI14IaQNL5fr4C6Dp23CyMGIgjp3ZFg9tXs/qWpw36Ge0MCxjabbFeKVcMXD10voMT0AHfJtQb2YfOl37ffzC4bR3phUnp0Ceqpl0Loe6hxUP/r4Jen1OKskdfjsldfjalAjn9ASdkjnkjbaAKjnLKJbaKJHDRDkllDAlciaIKSPX2b0uk2MJRJhfarMHDnmxZtEzqMgwLdLol9XVjiSu/7EUzR9Qtvs8xhf6XuUJPRD6OtJCb49L+bb/pXAej/GOk0f
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
|
||||
# ++++++++++++++++++++++++++++++++++++++++++++++++!
|
||||
@@ -107,6 +107,40 @@ check_update()
|
||||
fi
|
||||
}
|
||||
|
||||
# Verify that rpi-eeprom-config will apply and 2024 byte configuration file correctly.
|
||||
check_conf_size_large()
|
||||
{
|
||||
echo "check maximum config file size"
|
||||
image="${script_dir}/$1"
|
||||
conf="bootconf-2024.txt"
|
||||
|
||||
expected_md5="$(md5sum "${conf}" | awk '{print $1}')"
|
||||
|
||||
TMP_EEPROM="$(mktemp)"
|
||||
"${script_dir}/../rpi-eeprom-config" \
|
||||
"${image}" \
|
||||
--config "${conf}" \
|
||||
--out "${TMP_EEPROM}"
|
||||
|
||||
actual_md5="$("${script_dir}/../rpi-eeprom-config" "${TMP_EEPROM}" | md5sum | awk '{print $1}')"
|
||||
[ "${actual_md5}" = "${expected_md5}" ] || die "EEPROM check large config: checksum mismatch"
|
||||
}
|
||||
|
||||
# Verify that rpi-eeprom-config will reject files exceeding 2024 bytes
|
||||
check_conf_size_too_large()
|
||||
{
|
||||
echo "check config file which exceeds the maximum size"
|
||||
image="${script_dir}/$1"
|
||||
conf="bootconf-2025.txt"
|
||||
|
||||
expected_md5="$(md5sum "${conf}" | awk '{print $1}')"
|
||||
|
||||
TMP_EEPROM="$(mktemp)"
|
||||
if "${script_dir}/../rpi-eeprom-config" "${image}" --config "${conf}" --out "${TMP_EEPROM}" > /dev/null 2>&1; then
|
||||
die "$config should have been rejected"
|
||||
fi
|
||||
}
|
||||
|
||||
check_loopback "../firmware/critical/pieeprom-2019-05-10.bin" "bootconf-2019-05-10.txt"
|
||||
cleanup
|
||||
|
||||
@@ -118,3 +152,9 @@ cleanup
|
||||
|
||||
check_reduce_size "../firmware/critical/pieeprom-2019-05-10.bin" "bootconf-2019-05-10.txt"
|
||||
cleanup
|
||||
|
||||
check_conf_size_large "../firmware/critical/pieeprom-2019-05-10.bin"
|
||||
cleanup
|
||||
|
||||
check_conf_size_too_large "../firmware/critical/pieeprom-2019-05-10.bin"
|
||||
cleanup
|
||||
|
||||
Reference in New Issue
Block a user