|
| 1 | +# Utilities to create, flash and dump HAT EEPROM images |
| 2 | + |
| 3 | +**Build Instructions** |
| 4 | + |
| 5 | +Install the prerequisites with "sudo apt install cmake" - you need at least version 3.10 of cmake. Run the following commands here, or in the top-level directory to build and install all the utilities: |
| 6 | + |
| 7 | + - *cmake .* |
| 8 | + - *make* |
| 9 | + - *sudo make install* |
| 10 | + |
| 11 | +**Usage** |
| 12 | + |
| 13 | +1. Copy `eeprom_settings.txt` (or `eeprom_v1_settings.txt` for a V1 HAT) to `myhat_eeprom.txt`. |
| 14 | + |
| 15 | +2. Edit `myhat_eeprom.txt` to suit your specific HAT. |
| 16 | + |
| 17 | +3. Run `eepmake myhat_eeprom.txt myhat.eep` (or `eepmake -v1 myhat_eeprom.txt myhat.eep` for a V1 HAT) to create the .eep binary. |
| 18 | + |
| 19 | +4. If `eepmake` has generated a product UUID for you, it is a good idea to patch your myhat_eeprom.txt to include and hence preserve it (or use `eepdump` to regenerate it). |
| 20 | + |
| 21 | +**Flashing the EEPROM image** |
| 22 | +Follow these steps on the Raspberry Pi after installing the tools and building the .eep file: |
| 23 | + |
| 24 | +1. Disable EEPROM write protection |
| 25 | + * Sometimes this requires a jumper on the board |
| 26 | + * Sometimes this is a GPIO |
| 27 | + * Check your schematics |
| 28 | +2. Make sure you can talk to the EEPROM |
| 29 | + * In the HAT specification, the HAT EEPROM is connected to pins that can be driven by I2C0. |
| 30 | + However, this is the same interface as used by the camera and displays, so use of it by the ARMs is discouraged. |
| 31 | + The `eepflash.sh` script gets around this problem by instantiating a software driven I2C interface using those |
| 32 | + pins as GPIOs, calling it `i2c-9`: |
| 33 | + ``` |
| 34 | + sudo dtoverlay i2c-gpio i2c_gpio_sda=0 i2c_gpio_scl=1 bus=9 |
| 35 | + ``` |
| 36 | + * Install i2cdetect `sudo apt install i2c-tools` |
| 37 | + * As explained in the HAT+ specification, HAT EEPROMs can have a variety of (hexadecimal) I2C addresses: |
| 38 | + + 50: standard HAT+ (or legacy HAT) |
| 39 | + + 51: stackable HAT+ (e.g. Raspberry Pi M.2 M Key HAT) |
| 40 | + + 52: stackable Power HAT+ (MODE0) |
| 41 | + + 53: stackable Power HAT+ (MODE1) |
| 42 | + |
| 43 | + The examples below assume a standard HAT+/HAT, so be prepared to substitute the correct address for another type. |
| 44 | + |
| 45 | + * Check with `i2cdetect -y 9` (should be at address 0x50) |
| 46 | + ```bash |
| 47 | + i2cdetect -y 9 0x50 0x50 |
| 48 | + 0 1 2 3 4 5 6 7 8 9 a b c d e f |
| 49 | + 00: |
| 50 | + 10: |
| 51 | + 20: |
| 52 | + 30: |
| 53 | + 40: |
| 54 | + 50: 50 |
| 55 | + 60: |
| 56 | + 70: |
| 57 | + ``` |
| 58 | + Normally, you can skip this step, and assume things are working. |
| 59 | +3. Flash eep file `sudo ./eepflash.sh -w -t=24c32 -a=0x50 -f=eeprom.eep` |
| 60 | +4. Enable EEPROM write protection, by undoing step 1 (putting back jumper, or resetting GPIO) |
| 61 | + |
| 62 | +## String data formatting |
| 63 | + |
| 64 | +The tools support two string representations: |
| 65 | +1. A single, simple string with no CR/NL, no NUL-termination, and no embedded double-quotes. |
| 66 | +2. A multiline string using minimal escaping: |
| 67 | + * String begins with a single `"` followed by CR/NL (carriage return/newline) |
| 68 | + * NULs are escaped as \0, and followed by an extra NL (because they end a string) |
| 69 | + * Backslashes are escaped (`\\`) |
| 70 | + * NLs and TABs are included verbatim |
| 71 | + * CRs are escaped (`\r`) |
| 72 | + * The multiline string is terminated by `\"` |
| 73 | + * Any literal, unescaped CRs found in the string are ignored |
| 74 | + |
| 75 | +`eepmake` attempts to display dt_blob and custom_data blocks as simple strings, falling back to multiline strings, ultimately resorting to hexadecimal data. |
| 76 | + |
| 77 | +If in doubt, put the text in a file, add it using the `-c` option in `eepmake`, and use `eepdump` to see what it looks like. To confirm that blobs data is encoded and preserved correctly, use the `-b <prefix>` option to `eepdump` to save the blob data as separate files. |
| 78 | + |
| 79 | +Examples: |
| 80 | +``` |
| 81 | +dt_blob "rpi-dacpro" |
| 82 | +
|
| 83 | +custom_data " |
| 84 | +This is the start of a long string. |
| 85 | +End this line with a carriage return\r |
| 86 | +NUL-terminated\0 |
| 87 | +\" |
| 88 | +
|
| 89 | +custom_data " |
| 90 | +NL and NUL-terminated |
| 91 | +\0 |
| 92 | +\" |
| 93 | +
|
| 94 | +# This one could have been a simple string |
| 95 | +custom_data " |
| 96 | +End text with no NL\" |
| 97 | +
|
| 98 | +custom_data " |
| 99 | +End text with NL |
| 100 | +\" |
| 101 | +``` |
0 commit comments