The Pi4 has 512Kb of EEPROM which hold the bootloader.
Does anyone know if it is possible to write to spi memory to be used in programs in the user space without corrupting the bootloader?
Is there any small space available?
Thanks.
The Pi4 has 512Kb of EEPROM which hold the bootloader.
Does anyone know if it is possible to write to spi memory to be used in programs in the user space without corrupting the bootloader?
Is there any small space available?
Thanks.
Yes the EEPROM can be written to. You can install the rpi-eeprom
package and check the rpi-eeprom-update
script to see how it is done. Apparently, you'll have to get the EEPROM image file from /lib/firmware/raspberrypi/bootloader/critical/
, add whatever data you wanted, and then write it to the EEPROM using rpi-eeprom-update
or flashrom
command.
Writing procedure is detailed in applyUpdate
function of rpi-eeprom-update
. Here's a shortened version:
eeprom_image="$1" # must be configured with rpi-eeprom-config
[ "$(id -u)" = "0" ] || die "* Must be run as root - try 'sudo rpi-eeprom-update'"
# Bootloader EEPROM chip-select is muxed with audio pin so disable audio
# LDO first to avoid sending noise to analog audio.
/opt/vc/bin/vcmailbox 0x00030056 4 4 0 > /dev/null || true
dtparam audio=off
# Switch the SPI pins to boot EEPROM
dtoverlay spi-gpio40-45
modprobe spidev
modprobe spi-bcm2835
flashrom -p "linux_spi:dev=/dev/spidev0.0,spispeed=16000" -w "${eeprom_image}" || die "flashrom EEPROM update failed"
dtparam -R spi-gpio40-45
dtparam audio=on
/opt/vc/bin/vcmailbox 0x00030056 4 4 1 > /dev/null || true
At the time of writing, about 60% of space at the end of the bootloader image is filled with 0xFF bytes, which is a strong hint that they are unused. I'd say that the last 256KB of the bootloader image should be safe to write to. This can obviously change as new versions are released, especially once the network boot and USB boot will be implemented.
See this Raspberry Pi documentation page for more details.
If you brick the bootloader, a recovery image is available on the download page.