...
Table of Contents
Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
where to get
https://github.com/SolidRun/PyTLVWriter
Anchor | ||||
---|---|---|---|---|
|
This script writes TLV (TagType-Length-Value) structured data into an I2C EEPROM. It supports a variety of system-specific keys that define metadata for the device.
...
Builds TLV-formatted payloads.
Writes the data into an EEPROM via I2C.
Supports custom-defined keys.
Calculates and appends a CRC checksum to ensure data integrity.
...
Anchor | ||||
---|---|---|---|---|
|
To ensure all required dependencies are installed, run:
Code Block |
---|
sudo apt update
sudo apt install python3 python3-smbus |
this will:
Install Python 3 if it is not already installed.
Install smbus for I2C communication.
...
Anchor | ||||
---|---|---|---|---|
|
Code Block |
---|
python3 TLV_write.py <i2c_bus> <eeprom_address> [--yes] [-b] <key> <value> <key> <value> ... |
Arguments
Argument | Description |
---|---|
i2c_bus | The I2C bus number. |
eeprom_address | The EEPROM address (hex or decimal). |
--yes | Automatically confirms the operation (skips user confirmation). |
-b | Writes the TLV data to a binary file ( |
<key> <value> | One or more key-value pairs to write to EEPROM. |
Anchor | ||||
---|---|---|---|---|
|
For example if we want the following data to appear in DMI:
Code Block |
---|
Handle 0xXXXX, DMI type 1, XX bytes
System Information
Manufacturer: XXXXX
Product Name: MySystem
Version: 1.0
Serial Number: XXXXXX
UUID: XXXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Wake-up Type: XXXXXXXXXXXX
SKU Number: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Family: XXXXXXXXXXXXXXXXXXXXXXX |
We want to run the following command (Note that bus 3 address 0X50 is used in this example):
Code Block |
---|
python3 TLVwriter.py 3 0x50 TLV_CODE_SYS_NAME "MySystem" TLV_CODE_SYS_VERSION "1.0" |
Panel | ||
---|---|---|
| ||
eeprom example for this :
00: 54 6c 76 49 6e 66 6f 00 01 65 0030 0e 45 6d 62 TlvInfo.?e.0?Emb header version Total Payload Length (little endian) Type Length Value crc checksum TLV |
Anchor | ||||
---|---|---|---|---|
|
Info | ||
---|---|---|
Finding the I2C Bus NumberTo determine the correct I2C bus number, run the following command:
If no EEPROM device is found, repeat the command with different bus numbers (e.g. |
...
, 3, 4, 5 etc.) until you detect an address 0x50 or 0x56. Once found, use the corresponding bus number in the script. Example:
If the output shows:
Then bus |
...
3 and address 0x50 should be used in the script. |
Arguments
Argument | Description |
---|---|
i2c_bus | The I2C bus number. |
eeprom_address | The EEPROM address (hex or decimal). |
--yes (optional) | Automatically confirms the operation (skips user confirmation). |
<key> <value> | One or more key-value pairs to write to EEPROM. |
Example Usage
Code Block |
---|
python3 TLV_write.py 2 0x50 TLV_CODE_SYS_NAME "MySystem" TLV_CODE_SYS_VERSION "1.0" |
This writes:
...
System Name: "MySystem"
...
Note |
---|
Bus 2 or 5 usually has the memory SPD on addresses 0x50 & 0x51, do not write to them! |
...
Anchor | ||||
---|---|---|---|---|
|
Each TLV Key has a Hex Code, Max Length, and belongs to a DMIDecode Type.
System Information (
...
SMBIOS Type 1)
TLV KeyHex Code | Max Length (bytes) | BIOS path | |
TLV_CODE_FAMILY | 0x202020 | - | |
TLV_CODE_MANUF_DATE | 0x231010 | - | |
TLV_CODE_PLATFORM_NAME | 0x242020 | - | |
TLV_CODE_MANUF_NAME | 0x252020 | - | |
TLV_CODE_VENDOR_NAME | 0x272020 | - | |
TLV_CODE_SYS_NAME | 0x30 | 2020 | Main → Detailed Configuration Information → Model |
TLV_CODE_SYS_SKU | 0x312020 | Main screen | |
TLV_CODE_SYS_SERIAL_NUMBER | 0x322424 | Main screen | |
TLV_CODE_SYS_VERSION | 0x3355 | - |
NIO Information (
...
SMBIOS Type
...
2)
TLV KeyHex Code | Max Length (bytes) | |
TLV_CODE_NIO_NAME | 0x40 | 20 |
TLV_CODE_NIO_SERIAL_NUMBER | 0x41 | 24 |
TLV_CODE_NIO_VERSION | 0x42 | 5 |
Chassis Information (
...
SMBIOS Type
...
3)
TLV Key | Hex Code | Max Length (bytes) | |
TLV_CODE_CHS_SERIAL_NUMBER0x50 | 24 | ||
TLV_CODE_CHS_VERSION | 0x51 | 5 | 5 |
TLV Key | Max Length (bytes) | BIOS path |
TLV_CODE_CONFIG_CODE |
...
200 | Main → Detailed Configuration Information → Configuration String |
...
Anchor | ||||
---|---|---|---|---|
|
If invalid input is provided, the script will:
Print an error message.
Exit without modifying EEPROM contents.
...
Possible Errors
Error Message | Cause |
| Provided TLV key is not in the supported list. |
| Input exceeds the maximum allowed length. |
| Incorrect MAC format. |
| I2C communication issue during EEPROM write. |
| Data is too large for EEPROM storage. |
Dependencies
This script requires:
Python 3
smbus
(I2C communication)struct
andbinascii
(binary manipulation)
To install missing dependencies:
...
...