Write data to EEPROM
In order to be able to read data from the EEPROM we first need to write data to the EEPROM. To this end the Pika Spark closely emulates the approach taken by Raspberry Pi for its own HATs via eeptools. An implementation tailored to Arduino Portenta X8 specific needs can be found at pika-spark/portenta-x8-eeprom-utils. We start by preparing a Dockerfile that is cloning and building the required EEPROM tools.
FROM alpine:3.18
RUN apk add git g++ make cmake linux-headers
RUN cd /tmp && \
git clone https://github.com/pika-spark/portenta-x8-eeprom-utils && \
cd portenta-x8-eeprom-utils && \
mkdir build && \
cd build && \
cmake .. && \
make install
COPY eeprom_settings.txt /
RUN eepmake eeprom_settings.txt eeprom_settings.eep
COPY start.sh /
RUN chmod ugo+x /start.sh
ENTRYPOINT ['/start.sh']
We further need to provide a eeprom_settings.txt
file that contains the various mandatory data to be written to the EEPROM as well as a section for user defined data.
product_uuid 00000000-0000-0000-0000-000000000000
product_id 0x0000
product_ver 0x0000
vendor 'ACME Technology Company'
product 'Special Sensor Board'
custom_data
deadbeef c00 1c0d e
end
We also need to define a start script start.sh
which defines the actions to be taken on container startup - flashing the EEPROM in our case.
#!/bin/sh
export PATH='$PATH:/tmp/portenta-x8-eeprom-utils'
eepflash.sh --write --device=1 --address=50 -t=24c256 -f eeprom_settings.eep
After building the Docker image from the Dockerfile via docker build
docker build --pull --no-cache --tag pika_spark_eeprom_flash .
we need to ensure that the at24 kernel driver module is loaded
modprobe at24
and that write protection for the EEPROM (by setting the EEPROM_WP
line low) is disabled
echo 88 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio88/direction
echo 0 > /sys/class/gpio/gpio88/value
. By running the running the prepared container image we can now write the content from the eeprom_settings.txt
file to the Pika Spark's onboard 24LC256 EEPROM.
docker run -it -u 0 --privileged \
-v /sys/class/i2c-dev:/sys/class/i2c-dev pika_spark_eeprom_flash