Module 14 · Lesson 57 of 92

Reading and writing identity

Read a board's hardware identity, derive stable product identifiers, and verify that U-Boot and Linux use the same provisioned values.

  • Beginner to advanced
  • 9 min read
  • 12 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM for offline practice, the device-tree-compiler package, and a Raspberry Pi 4 or 5 booted with a device tree for live inspection

Your place in the module
By the end you can 4 objectives
  • Distinguish a firmware-supplied serial from raw bytes exported by an nvmem provider.
  • Specify a reproducible mapping from a factory ID to a serial and a locally administered MAC.
  • Write and read back identity properties in a copy of a DTB.
  • Trace an identity mismatch from persistent storage through U-Boot to the Linux network interface.
Video coming soonReading and writing identity
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from MAC addresses and key provisioning
  • An IEEE assignment reserves address space, and the factory must allocate each interface address only once.
  • A fresh challenge proves that the device can use the private key corresponding to its certificate.
  • The boot signing key signs release artifacts, while the device key authenticates an individual unit.
01

Find out where Linux got the ID

4 min read

Keys and MACs exist, but software must read them the same way every boot. This lesson answers reading the factory-unique ID through nvmem and writing identity so U-Boot and the kernel agree on it.

Linux's device-tree usage guide describes a real boot-time operation. Firmware or a bootloader can change a device tree before giving it to Linux. Consequently, a generic DTB on disk and the live device tree on a running board can contain different values. When you investigate a serial or an Ethernet address, the file on the boot medium tells you what went into the boot process. The live tree tells you what Linux received. Linux and the Devicetree

Keep three values distinct in your notes. The factory ID identifies the SoC and comes from a hardware-defined field. The product serial is the string your product reports, which you might derive from that field. The MAC address identifies a network interface, so a board with multiple interfaces needs a separate mapping for each one. A replacement SoC changes an identity derived directly from its factory ID. If your service records require the same product serial after a board replacement, you need a persisted assignment and an explicit replacement procedure.

On a Raspberry Pi 4 or 5 booted with a device tree, inspect the root serial-number property when the firmware supplies it. The property is a device-tree string with a terminating zero byte. The command removes that terminator for display. Record it as a firmware-supplied value. To use it as input to a derivation, first establish that its format and relationship to the hardware ID are defined for your boot flow.

bash
serial_property=/sys/firmware/devicetree/base/serial-number
if [ -r "$serial_property" ]; then
    tr -d '\000' < "$serial_property" && printf '\n'
fi
Going deeperExplore the mechanism

Linux's gives Linux another way to obtain an identifier. A provider driver accesses a device such as an EEPROM or an OTP controller. With the appropriate provider and sysfs support enabled, Linux can expose a binary nvmem attribute under /sys/bus/nvmem/devices/. On a running board, look for exports with ls /sys/bus/nvmem/devices/*/nvmem. An Ubuntu VM or WSL2 session ordinarily lacks the target SoC's provider. On hardware, an absent export can mean the driver or sysfs support is missing, or that firmware owns access to the field. The BSP and the board's device tree identify the intended provider.

Before reading bytes, establish the provider, byte offset, length, and encoding for the documented ID field. If the provider permits that read, od -An -tx1 -v -j "$offset" -N "$length" "$provider_file" displays the selected bytes. Set those variables from the board documentation and the actual sysfs entry. Check that you obtained the full field. The display is for inspection. A derivation that takes binary input should use the field bytes, since the spaces and newlines printed by od change the input. Kernel consumers can use named cells to request specific fields. NVMEM Subsystem

Where the bytes come fromFirmwarehandoffHardware readSourceFirmware orbootloaderOTP or EEPROMLinux interfaceLive devicetreenvmemproviderExample dataSerial stringRaw fieldbytes
Two routes by which Linux can obtain identity information

Once you have the factory ID, define exactly how to turn it into product identifiers. A simple serial policy renders every byte of the documented ID in a fixed order as two uppercase hexadecimal digits. That keeps leading zeros and makes the serial easy to compare with a factory record. If your source exposes words, specify how to serialize each word into bytes. If you support more than one SoC family, include a product or family prefix where the ID's uniqueness is scoped to that family.

For a product that uses derived locally administered MACs, one policy is to hash a fixed product-and-version prefix, a stable interface label, and the canonical ID bytes using SHA-256. For example, define the prefix and interface label as ASCII, each followed by a zero byte, then append the ID bytes. Take the first six digest bytes. In the first byte, clear bit 0 and set bit 1 to select unicast and local administration. Use a label defined by the board design, such as lan0 for a particular connector. Linux interface names can change with operating-system policy.

Write down the exact input encoding and retain a test vector. Changing the label, the byte order, or the prefix can change deployed addresses even if the SoC stays the same. Truncating a digest can also produce a collision. Check assignments for collisions before accepting them, and persist any approved replacement address so each boot stage uses the same result. If the product already has assigned MACs, use those recorded values in the steps that follow.

02

Persist the identity and pass it to Linux

3 min read

Choose one authoritative source for each field. In an EEPROM-based design, for example, the factory process writes the product serial and MACs into a documented record. U-Boot validates that record and uses it to configure its network interfaces and update the DTB for Linux. Linux then takes the serial from the root property and the MAC from the relevant Ethernet node, provided the driver supports that property. Every copy can be traced to a single assignment.

Passing a provisioned identityFactorywriterEEPROMrecordU-BootReads andusesidentityWorking DTBSerial andMACpropertiesLinuxReadssuppliedpropertiesFactorywriterEEPROMrecordU-BootReads andusesidentityWorking DTBSerial andMACpropertiesLinuxReadssuppliedproperties
A provisioned record supplies both U-Boot and the Linux device tree

The place where you write the identity determines who has to read it.

  • DTB. Write serial-number as a string on the root node and local-mac-address as six raw bytes on the intended Ethernet node. A per-device DTB must survive image updates. For U-Boot itself to use values stored only in that DTB, its board code or boot flow must read them before it needs them. U-Boot can have its own control tree, separate from the working tree passed to Linux. If the boot flow sets mac-address as well, keep both MAC properties consistent. Linux drivers using the standard device-tree MAC lookup check a valid mac-address first.
  • U-Boot environment. On a build with a writable persistent environment, use setenv to set serial# and ethaddr, then saveenv to commit the environment. Read back with printenv after a restart to check the persistent copy. Some builds protect these variables against overwriting. Verify which Ethernet device U-Boot maps to ethaddr and any indexed variables. Linux receives these values when the boot flow writes the corresponding device-tree properties. Confirm that the serial fixup and Ethernet fixups apply to the working tree used for the actual boot.
  • EEPROM. Write the record using the factory writer for the board's EEPROM layout. Define field lengths, serial encoding, interface order, and how a reader detects an invalid or incomplete record. Read back and decode the stored bytes before accepting the write. At boot, U-Boot needs code that understands that layout. It can then pass identity in the DTB. A Linux driver or product service can also read the EEPROM directly when it has its own reader for the same layout. Give both readers the same format definition.

On Ubuntu, fdtput and fdtget from device-tree-compiler let you check the DTB representation in an offline copy. Start with board.dtb, a copy of your board's device tree. The first command sequence writes an example serial. The second resolves the existing ethernet0 alias to a node path and writes an example locally administered MAC. If the DTB lacks that alias, identify the actual Ethernet node path before setting a MAC. Both values here are for the offline copy.

bash
cp board.dtb identity.dtb &&
    fdtput -t s identity.dtb / serial-number EXAMPLE-A &&
    fdtget -t s identity.dtb / serial-number
bash
eth_node=$(fdtget -t s identity.dtb /aliases ethernet0) &&
    fdtput -t bx identity.dtb "$eth_node" local-mac-address 02 00 00 00 00 01 &&
    fdtget -t bx identity.dtb "$eth_node" local-mac-address

The first readback should match the string supplied to fdtput. Compare the second byte by byte. Hex display may omit leading zeros, so compare 2 and 02 as the same byte value. If a DTB already has mac-address, inspect it too before using a comparable change in a boot image. The commands above demonstrate file contents. A bootloader can still modify those contents after loading the file.

03

Read back the value that each stage uses

3 min read

Verify identity in the order it moves through the system. Start with the persisted value, or the factory ID if the design derives everything at boot. Then inspect U-Boot's effective identity after a cold start and the working DTB after identity has been applied, if your boot flow exposes that point for inspection. Finally, compare the live Linux device tree and the running interface. A match between the provisioning tool and the DTB on disk confirms the write to that file. A match on the running board also confirms that the selected boot path supplied the intended value.

Resolve the live Ethernet node through /sys/firmware/devicetree/base/aliases/ethernet0 if that alias exists and points to the interface you are checking. Read the applicable mac-address and local-mac-address properties as binary bytes with od -An -tx1 -v. Use ip link show to identify the Linux interface, then read /sys/class/net/<interface>/address, replacing <interface> with its name. Compare the same physical connector at both stages. If the live tree has the expected address and the interface shows a different one, inspect how the driver obtains its address and whether Linux network configuration changed it after probe.

Read identity after bootPersistentsourceU-BootvaluesLive devicetreeInterfaceaddressPersistentsourceU-BootvaluesLive devicetreeInterfaceaddress
Read back the effective identity at each stage of boot

A stale environment can explain why a correctly programmed EEPROM yields the wrong address in Linux. For example, if board code populates ethaddr only when it is empty, a saved value can survive EEPROM replacement and drive a later DTB fixup. Define the intended precedence in the board code. When the EEPROM is authoritative, load its validated value before the identity fixups and handle a disagreement explicitly. Verify the behavior after the same reflash or update that a production unit will receive.

Going deeperExplore the mechanism

A fuse-backed design can skip stored serial and MAC copies in the environment and EEPROM. If the OTP contains an assigned MAC, declare its field as an nvmem cell using the SoC provider's binding. A Linux Ethernet driver using the standard device-tree MAC lookup can obtain it from a cell referenced by nvmem-cells and named mac-address in nvmem-cell-names. A valid MAC property in the tree takes precedence in that lookup, so remove stale explicit addresses from a configuration intended to use the cell. For a fused serial or raw factory ID, use a board-specific kernel consumer or a product service reading the documented field. Declaring a serial cell alone does not populate the root serial-number property. If the fuses contain only the raw ID, product code must perform any required derivation.

U-Boot needs its own supported access to the same fuse field when it uses the identity before Linux starts. Both readers must agree on offsets, byte order, and decoding or derivation. Another option is to have U-Boot read the fuses once per boot and publish the resulting values in the working DTB. In that design Linux consumes the published values, and the product can carry the same generic DTB on every unit. Reading a fuse field at boot requires no fuse write.

When two readings disagree, identify the first stage where the value changes. That tells you whether to inspect the factory write, source selection in U-Boot, the DTB handoff, or Linux interface configuration. The next lesson, Production test and data security, uses these readback points to decide what the factory verifies and what it records.

Key takeaways

  • A device-tree serial is supplied by firmware or a bootloader, while nvmem can expose bytes read by a storage provider.
  • Stable derivation requires a fixed byte order, input format, and mapping version.
  • U-Boot must explicitly pass environment or EEPROM values to Linux unless Linux has its own reader for the chosen source.
  • Checking the stored record, live device tree, and interface address tests three distinct stages.
Reflect
  1. Explain to a colleague, in two sentences: distinguish a firmware-supplied serial from raw bytes exported by an nvmem provider.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close