As it is hard to find good quality information EEPROM for HATs, and after some struggling, I decided to write this post to clarify the process. I have made a tgz archive with all example files explained below, including ready to use EEPROM binary: As a preliminary step, you need to activate videocore I2C. This is done by adding a line at the beginning of your /boot/config.txt file :
Add:
Code: Select all
dtparam=i2c_vc=on
First of all, you need to get EEPROM utils (to make EEPROM content and flash it) and device-tree compiler (dtc).
For the device tree, I followed advice from Adafruit : https://learn.adafruit.com/introduction ... an-overlay
Code: Select all
git clone https://github.com/raspberrypi/hats.git
wget -c https://raw.githubusercontent.com/RobertCNelson/tools/master/pkgs/dtc.sh
chmod +x dtc.sh
./dtc.sh
Code: Select all
cd hat/eepromutils
Code: Select all
########################################################################
# EEPROM settings text file
#
# Edit this file for your particular board and run through eepmake tool,
# then use eepflash tool to write to attached HAT ID EEPROM
#
# Tools available:
# eepmake Parses EEPROM text file and creates binary .eep file
# eepdump Dumps a binary .eep file as human readable text (for debug)
# eepflash Write or read .eep binary image to/from HAT EEPROM
#
########################################################################
########################################################################
# Vendor info
# 128 bit UUID. If left at zero eepmake tool will auto-generate
# RFC 4122 compliant UUID
product_uuid 00000000-0000-0000-0000-000000000000
# 16 bit product id
product_id 0x0001
# 16 bit product version
product_ver 0x0002
# ASCII vendor string (max 255 characters)
vendor "Martinlbb"
# ASCII product string (max 255 characters)
product "Brilliant board"
########################################################################
# GPIO bank settings, set to nonzero to change from the default.
# NOTE these setting can only be set per BANK, uncommenting any of
# these will force the bank to use the custom setting.
# drive strength, 0=default, 1-8=2,4,6,8,10,12,14,16mA, 9-15=reserved
gpio_drive 0
# 0=default, 1=slew rate limiting, 2=no slew limiting, 3=reserved
gpio_slew 0
# 0=default, 1=hysteresis disabled, 2=hysteresis enabled, 3=reserved
gpio_hysteresis 0
# If board back-powers Pi via 5V GPIO header pins:
# 0 = board does not back-power
# 1 = board back-powers and can supply the Pi with a minimum of 1.3A
# 2 = board back-powers and can supply the Pi with a minimum of 2A
# 3 = reserved
# If back_power=2 then USB high current mode will be automatically
# enabled on the Pi
back_power 0
########################################################################
# GPIO pins, uncomment for GPIOs used on board
# Options for FUNCTION: INPUT, OUTPUT, ALT0-ALT5
# Options for PULL: DEFAULT, UP, DOWN, NONE
# NB GPIO0 and GPIO1 are reserved for ID EEPROM so cannot be set
# GPIO FUNCTION PULL
# ---- -------- ----
#setgpio 2 INPUT DEFAULT
#setgpio 3 INPUT DEFAULT
#setgpio 4 INPUT DEFAULT
#setgpio 5 INPUT DEFAULT
#setgpio 6 INPUT DEFAULT
#setgpio 7 INPUT DEFAULT
#setgpio 8 INPUT DEFAULT
#setgpio 9 INPUT DEFAULT
#setgpio 10 INPUT DEFAULT
#setgpio 11 INPUT DEFAULT
#setgpio 12 INPUT DEFAULT
#setgpio 13 INPUT DEFAULT
#setgpio 14 INPUT DEFAULT
#setgpio 15 INPUT DEFAULT
#setgpio 16 INPUT DEFAULT
#setgpio 17 INTPUT DEFAULT
setgpio 18 OUTPUT DEFAULT
#setgpio 19 INPUT DEFAULT
#setgpio 20 INPUT DEFAULT
#setgpio 21 INPUT DEFAULT
#setgpio 22 INPUT DEFAULT
#setgpio 23 INPUT DEFAULT
#setgpio 24 INPUT DEFAULT
#setgpio 25 INPUT DEFAULT
#setgpio 26 INPUT DEFAULT
#setgpio 27 INPUT DEFAULT
Code: Select all
./eepmake eeprom_settings.txt myhat.eep
You can now write it on EEPROM. If you have followed the design guide, you have a 24c32 memory (4k). But your myhat.eep file is smaller. As you don't know the state of your EEPROM, you may have conflict, as your myhat.eep could be misread. To avoid that, we shall start by cleaning EEPROM.
Use this dd command to generate a 4k file, padded with zero (an excellent choice, zeros are my favorites!). If you have another EEPROM size, just change count value according to your real EEPROM size.
Code: Select all
dd if=/dev/zero ibs=1k count=4 of=blank.eep
Code: Select all
hexdump blank.eep
Code: Select all
sudo ./eepflash -w -f=blank.eep -t=24c32
To verify if everything went well, you can use this command to check EEPROM content. Caution: it will only work after you use the eepflash command, which does some modprobes.
Code: Select all
sudo hexdump /sys/class/i2c-adapter/i2c-0/0-0050/eeprom
Then, you can upload your own myhat.eep.
Code: Select all
sudo ./eepflash -w -f=myhat.eep -t=24c32
Code: Select all
sudo hexdump /sys/class/i2c-adapter/i2c-0/0-0050/eeprom
To check if your HAT is recognized, just go to /proc/device-tree/. If you see a hat directory, you are a winner:)
Code: Select all
cd /proc/device-tree/hat/
more vendor
more product
Code: Select all
sudo sh -c 'echo "18" > /sys/class/gpio/export'
sudo sh -c 'echo "out" > /sys/class/gpio/gpio18/direction'
sudo sh -c 'echo "1" > /sys/class/gpio/gpio18/value'
Code: Select all
sudo sh -c 'echo "0" > /sys/class/gpio/gpio18/value'
Now we can dive in the device-tree world. Open a file, called myled.dts, and paste this code (heavily copied from fividi post viewtopic.php?f=29&t=97875):
Code: Select all
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2708";
fragment@0 {
target = <&leds>;
__overlay__ {
my_led: myled {
label = "MYLED";
gpios = <&gpio 18 0>;
linux,default-trigger = "heartbeat";
};
};
};
};
Code: Select all
sudo dtc -@ -I dts -O dtb -o myled.dtb myled.dts ; sudo chown pi:pi myled.dtb
Now, we can generate a eep file containing both board definition (eeprom_config.txt) and device-tree (for kernel auto configuration).
Code: Select all
./eepmake eeprom_settings.txt myhat-with-dt.eep myled.dtb
Code: Select all
sudo ./eepflash -w -f=blank.eep -t=24c32
sudo ./eepflash -w -f=myhat-with-dt.eep -t=24c32
Code: Select all
hexdump myhat-with-dt.eep
sudo hexdump /sys/class/i2c-adapter/i2c-0/0-0050/eeprom
Final reminder: When you start playing with adding long device tree, keep in mind you have a limited memory (4096 bytes for a 24c32 memory). When creating an eep file with eepmake, this tool will give you final size of your eep. Just verifiy if you have exceed your EEPROM size.
Note: With an incorrect DT, even your eeprom_settings are not recognized by kernel. And a bootable device-tree overlay is sometimes not sufficient for "eeprom boot"
To allow auto configuration after kernel boot (ie: modprobe some modules, TFT calibration, etc...), I use a custom parameter file, based on JSON, that could be parsed after. I choose JSON as it is small, human-readable, and easy to parse.
To add a custom file to your eep, just do this:
Code: Select all
./eepmake eeprom_settings.txt myhat-with-dt.eep myled.dtb -c myparams.json