Cananka, the Raspberry Pi HAT: EEPROM

[This post is part six in the series.]

What makes HAT a HAT is its EEPROM. While official instructions are lacking in details there are some forum posts and tutorials dealing with that issue.

In order to follow steps later in this post, we first have to install some packages:

# sudo apt-get install git i2c-tools

For HAT EEPROM access we have to tell system to allow use of, usually inaccessible, I2C bus 0:

# sudo bash -c 'echo "dtparam=i2c_vc=on" >> /boot/config.txt'
# sudo reboot

Easiest way to see if we have set it up correctly is to probe I2C bus 0 for EEPROM at address 0x50 and see what we have there. We are searching device with ID of 0x50:

# i2cdetect 0
# i2cdump 0 0x50

To manipulate it any further we need to install EEPROM utilities from the Rasbperry repository:

# git clone https://github.com/raspberrypi/hats.git
# cd hats/eepromutils/
# make clean ; make

Before anything else is done, it is a good idea to clean out EEPROM:

# dd if=/dev/zero ibs=1k count=4 of=blank.eep
# sudo ./eepflash.sh -w -f=blank.eep -t=24c32

Now we are finally ready to actually create .eep file from our text config and upload it to EEPROM:

# ./eepmake eeprom_settings.txt hat.eep
# sudo ./eepflash.sh -w -f=hat.eep -t=24c32
# sudo reboot

If everything is ok, you should have directory /proc/device-tree/hat with product, vendor, and other files:

# more /proc/device-tree/hat/product

But this is not where we want to stop - we want also device tree so that our CAN bus can get some auto-configuration magic. And frankly that whole concept is such a mess that creating it from scratch takes unholy amount of time. However, since CAN over SPI is one of the already existing overlays, we don't have to do anything other than include it and flash our EEPROM again:

# ./eepmake eeprom_settings.txt hat.eep /boot/overlays/mcp2515-can0.dtbo
# sudo ./eepflash.sh -w -f=blank.eep -t=24c32
# sudo ./eepflash.sh -w -f=hat.eep -t=24c32
# sudo reboot

Even if our CAN bus implementation didn't match existing overlay completely (e.g. using different frequency), we could still use it as a template for our modifications. We would first dump it:

# dtc -I dtb -O dts /boot/overlays/mcp2515-can0.dtbo > hat.dts

Once we have it in (semi) human readable format, we can change what is needed (e.g. clock-frequency) and then use the same flash procedure as before:

# ./eepmake eeprom_settings.txt hat.eep hat.dts
# sudo ./eepflash.sh -w -f=blank.eep -t=24c32
# sudo ./eepflash.sh -w -f=hat.eep -t=24c32
# sudo reboot

Now you can remove all modifications done to /boot/config.txt and our interface will still appear:

# ip -d link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
link/can promiscuity 0
...

With that, we have Cananka project completed and the only post remaining is to reminiscence over development problems.

One thought to “Cananka, the Raspberry Pi HAT: EEPROM”

Leave a Reply

Your email address will not be published. Required fields are marked *