Raspberry Pi EEPROM management tool for reading, writing, and managing EEPROM content on RPi HAT devices
Project description
rpi-eeprom
Raspberry Pi EEPROM management tool for reading, writing, and managing EEPROM content on RPi HAT devices. Supports JSON and YAML custom data formats with multi-section storage.
Installation
pip install rpi-eeprom
On a Raspberry Pi with GPIO hardware access:
pip install rpi-eeprom[gpio]
Prerequisites
EEPROM hardware operations require eepmake, eepdump, and eepflash.sh from the Raspberry Pi utils eeptools. Pre-compiled ARM64 binaries are bundled in release builds. If using a source install, compile them manually:
git clone https://github.com/raspberrypi/utils
cd utils/eeptools
cmake .
make
sudo make install
The I2C bus overlay must be loaded before use:
sudo dtoverlay i2c-gpio i2c_gpio_sda=0 i2c_gpio_scl=1 bus=9
Note: Most EEPROM operations require
sudofor hardware access.
Python Library
from rpi_eeprom import EEPROM, EEPROMConfig
# Use default configuration (bus=9, address=0x50, model=24c32)
with EEPROM() as eeprom:
# Read EEPROM content
content = eeprom.read()
print(content.product_uuid)
print(content.vendor)
print(content.serial_number) # From first custom data section
print(content.custom_data) # All custom data sections
# Write new content (resets EEPROM first)
eeprom.write(custom_data=[{"serial_number": "ABC123XYZ"}])
# Update custom data while preserving UUID and settings
eeprom.update(custom_data=[{"serial_number": "NEW456"}])
# Append a new custom data section
eeprom.update(custom_data=[{"extra": "data"}], append=True)
# Replace a specific section by index
eeprom.update(custom_data=[{"replaced": True}], index=1)
# Reset to blank
eeprom.reset()
Custom configuration
config = EEPROMConfig(
model="24c64",
size_kbytes=8,
i2c_bus=1,
i2c_address=0x51,
write_protect_pin=17,
settings_template="/path/to/custom_settings.txt",
)
with EEPROM(config) as eeprom:
content = eeprom.read()
Reading from device tree
with EEPROM() as eeprom:
# Read how Linux currently sees the EEPROM via /proc/device-tree/
# (reflects state at boot, not live changes)
data = eeprom.read_device_tree(index=0)
print(data["serial_number"])
Writing custom data from files
from pathlib import Path
with EEPROM() as eeprom:
# Write from JSON/YAML files
eeprom.write(custom_data=[
Path("config.json"),
Path("metadata.yaml"),
])
# Mix files and dicts
eeprom.write(custom_data=[
Path("config.json"),
{"serial_number": "ABC123"},
])
Error handling
All operations raise typed exceptions instead of returning booleans:
from rpi_eeprom import (
EEPROM,
EEPROMNotFoundError,
EEPROMReadError,
EEPROMWriteError,
EEPROMConfigError,
)
try:
with EEPROM() as eeprom:
content = eeprom.read()
except EEPROMNotFoundError:
print("No EEPROM device detected on I2C bus")
except EEPROMReadError:
print("Failed to read EEPROM content")
except EEPROMWriteError:
print("Failed to write to EEPROM")
except EEPROMConfigError:
print("Invalid configuration")
CLI
The rpi-eeprom command provides three subcommands: read, write, and reset.
Read EEPROM content
# Read and display as JSON (default)
rpi-eeprom read
# Read as YAML
rpi-eeprom read --format yaml
# Save to a file (format auto-detected from extension)
rpi-eeprom read --output eeprom_data.yaml
# Read a specific custom data section
rpi-eeprom read --index 1
# Read from device tree instead of hardware
rpi-eeprom read --device-tree
rpi-eeprom read --device-tree --index 1
Write to EEPROM
# Write custom data from a JSON file
rpi-eeprom write --data config.json
# Write multiple custom data sections
rpi-eeprom write --data section1.json --data section2.yaml
# Append new sections while preserving existing ones
rpi-eeprom write --data new_section.json --append
# Replace a specific section by index
rpi-eeprom write --data replacement.json --index 1
# Update the serial number
rpi-eeprom write --serial ABC123XYZ
# Auto-detect and handle existing content
rpi-eeprom write
rpi-eeprom write --force # Force overwrite corrupt content
Reset EEPROM
# Reset EEPROM to blank state (all zeros)
rpi-eeprom reset
Configuration file
Use --config to specify EEPROM hardware settings (JSON or YAML):
rpi-eeprom --config my_config.yaml read
Example config.yaml:
model: 24c64
size_kbytes: 8
i2c_bus: 1
i2c_address: 0x51
write_protect_pin: 17
Verbose output
rpi-eeprom -v read
EEPROM Content
A valid EEPROM contains a product UUID, vendor/product info, and one or more custom data sections. Each custom data section can be JSON or YAML.
product_uuid 12345678-1234-5678-1234-567812345678
product_id 0x0105
product_ver 0x0001
vendor "Ubo Technology Company"
product "Ubo HAT+"
custom_data "
{"serial_number": "ZF64JA81VPPZ", "eeprom": {"model": "24c32"}}
\"
A valid EEPROM must have a non-zero product_uuid and a serial_number in its first custom data section. Blank or zero-UUID EEPROMs are automatically re-initialized when using the CLI write command.
Development
# Install in development mode with all dev tools
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Run with coverage
pytest tests/ -v --cov=rpi_eeprom
# Lint
ruff check src/ tests/
# Type check
mypy src/rpi_eeprom/
License
Apache License 2.0 - see LICENSE for details.
Pre-compiled eeptools binaries (eepmake, eepdump, eepflash.sh) are from raspberrypi/utils under the BSD 3-Clause License - see THIRD_PARTY_NOTICES.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rpi_eeprom-1.0.0.tar.gz.
File metadata
- Download URL: rpi_eeprom-1.0.0.tar.gz
- Upload date:
- Size: 46.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb9d8ade42e1ecf945f2a8bf3c3e749ed9f85679a07bea428c49ab84a59b90f5
|
|
| MD5 |
eacb99c1afea49d2a03b70e73f764d4d
|
|
| BLAKE2b-256 |
b55bb4720ffc172ab276dbe40124ea95fa0b03b9e6f8bbd36cf6b7481565a049
|
Provenance
The following attestation bundles were made for rpi_eeprom-1.0.0.tar.gz:
Publisher:
release.yml on ubopod/rpi-eeprom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rpi_eeprom-1.0.0.tar.gz -
Subject digest:
cb9d8ade42e1ecf945f2a8bf3c3e749ed9f85679a07bea428c49ab84a59b90f5 - Sigstore transparency entry: 927228167
- Sigstore integration time:
-
Permalink:
ubopod/rpi-eeprom@2dad9cb2f0ea9d47eabe9d855e24d7f485a49dac -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ubopod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2dad9cb2f0ea9d47eabe9d855e24d7f485a49dac -
Trigger Event:
push
-
Statement type:
File details
Details for the file rpi_eeprom-1.0.0-py3-none-any.whl.
File metadata
- Download URL: rpi_eeprom-1.0.0-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9feb821b1d9605b11a46033962bc7de11d8664c5d095965f8987f425b8fcc592
|
|
| MD5 |
377236d7a268d139f9a83dd5e240d539
|
|
| BLAKE2b-256 |
c7d35eb6e308c5389e48cc74f2563b7521b331e8eb956a2b0232a83b09fd2bc7
|
Provenance
The following attestation bundles were made for rpi_eeprom-1.0.0-py3-none-any.whl:
Publisher:
release.yml on ubopod/rpi-eeprom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rpi_eeprom-1.0.0-py3-none-any.whl -
Subject digest:
9feb821b1d9605b11a46033962bc7de11d8664c5d095965f8987f425b8fcc592 - Sigstore transparency entry: 927228168
- Sigstore integration time:
-
Permalink:
ubopod/rpi-eeprom@2dad9cb2f0ea9d47eabe9d855e24d7f485a49dac -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ubopod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2dad9cb2f0ea9d47eabe9d855e24d7f485a49dac -
Trigger Event:
push
-
Statement type: