DESK-MP1-L/Deployment/MAC Address programming

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes
2023/08/01 DESK-MP1-L-1.0.0 release


MAC Address programming[edit | edit source]

Every network adapter has a Media Access Control address (usually shortened to MAC address). A MAC address is a six-byte identifying number permanently embedded in the firmware of the adapter, and is readable by the network and the operating system of the device on which the adapter is installed.

The address must follow the standards set by the Institute of Electrical and Electronics Engineers (IEEE), which sets computer networking standards.

The MAC address is a six-pair set of hexadecimal numbers, for example a1-c2-e3-44-5f-6d. Specifically, in Ethernet, the MAC address is known as the Ethernet Address, which is the unique ID serial number of the Ethernet device in one's computer. MAC Addresses are used in a Local Area Network (LAN) by computers to communicate with each other. Every adapter has a unique MAC address.

Platform supported[edit | edit source]

In this Application Note, we will describe how to use the ETRA eFuse for programming and using the MAC address(es) and it applies to the following DAVE ETRA family products:


200px-Emblem-important.svg.png

This Application Note has been validated in the ETRA SOM.

Obtaining a MAC address[edit | edit source]

To obtain a MAC address for your organization, please refer to our Setting the MAC address wiki page with the overall information about this topic.

Permanent storage areas[edit | edit source]

Some SOCs provide programmable OTPs for security, MAC address, boot modes, etc. Usually, some of these are general-purpose registers and can be managed by the user.

In other cases, an external permanent storage device can be used for storing permanent settings like the MAC address: for the ETRA product family, DAVE proposes to use the General Purposes eFuses (OTP blocks) on SoC itself for storing permanently the MAC address(es).

MAC address programming on ETRA family[edit | edit source]

MAC address configuration in u-boot[edit | edit source]

If the MAC address is not already programmed in the OTPs and the ethaddr u-boot variable is not set, u-boot assignes a random value (different at every power on cycle):

Net:
Warning: ethernet@5800a000 (eth0) using random MAC address - d6:39:06:41:0f:b2
eth0: ethernet@5800a000

If the ethaddr is set and saved in the u-boot environment, its value is used as the MAC Address:

u-boot=> setenv ethaddr 00:50:c2:1e:af:a8
u-boot=> saveenv
Saving Environment to MMC... Writing to MMC(0)... OK
u-boot=>

eFuse bank registers[edit | edit source]

ETRA family uses the Bank0 Word 57, Word 58 for storing the MAC address. The MAC values should be properly divided in two registers for correct programming.

The related 57, 58, OTP registers will be used for the purposes illustrated in this AN.


200px-Emblem-important.svg.png

Warning!! eFuse programming is a permanent and non-reversible action. Pay attention to the values and commands used during MAC programming.

eth0 read current value[edit | edit source]

U-boot uses the fuse sense command to read the MAC address value into the eFuse

STM32MP> fuse sense 0 57 2
Sensing bank 0:
Word 0x00000039: 00000000 00000000

If it is all zero there should also be the following print from U-Boot invalid MAC address 0 in OTP 00:00:00:00:00:00.

If the present MAC address is not valid, a random one is generated.

To check if the OTPs have been blocked execute use the fuse sense command, the address to use is calculated as follows:

OTP 57 (decimal) -> 0x39 (Hex) as shown by the output of the previous command (Word 0x00000039: XXXXXXXX YYYYYYYY), add on address this value 0x10000000 -> 0x10000039

STM32MP> fuse sense 0 0x10000039 2
Sensing bank 0:
Word 0x10000039: 00000000 00000000

If the value is 0 in both cells, they have not been locked.

If the value is 40000000 the cell has been locked.

eth0 eFuse programming[edit | edit source]

U-Boot uses the fuse prog command for writing the MAC address into the eFuse. The MAC address should be divided in two parts, for example MAC address AB:CD:12:34:56:78 for eth0 is then divided into :

fuse prog 0 57 0x12cd34ab
fuse prog 0 58 0x00007856

In the following example the MAC address 2A:01:7A:9F:3E:20 is stored in the SOC:

  • (in case of presence) clear the ethaddr u-boot variable
u-boot=> setenv ethaddr
u-boot=> saveenv
Saving Environment to MMC... Writing to MMC(1)... OK
  • program the MAC address in the OPTs with the following commands:
STM32MP> fuse prog 0 57 0x9f7a012a 0x0000203e
Programming bank 0 word 0x00000039 to 0x9f7a012a...
Warning: Programming fuses is an irreversible operation!
         This may brick your system.
         Use this command only if you are sure of what you are doing!

Really perform this fuse programming? <y/N>
y
Programming bank 0 word 0x0000003a to 0x0000203e...
Warning: Programming fuses is an irreversible operation!
         This may brick your system.
         Use this command only if you are sure of what you are doing!

Really perform this fuse programming? <y/N>
y
STM32MP>

If you want to write the eFuse value directly without confirmation, uses the -y parameter with the fuse prog command, as per the previous example:

STM32MP> fuse prog -y 0 57 0x9f7a012a 0x0000203e
Programming bank 0 word 0x00000039 to 0x9f7a012a...
Programming bank 0 word 0x0000003a to 0x0000203e...

At the next boot, the ethaddr value wil be read from the OPTs:

STM32MP> pri ethaddr
ethaddr=2a:01:7a:9f:3e:20
STM32MP>

eFuse locking[edit | edit source]

The OTP eFuse registers should be locked in order to avoid unwanted registers (and then MAC addresses) modifications. OTP lock grants the MAC values cannot be modified anymore.


200px-Emblem-important.svg.png

If not locked yet, OTP bits can be set to '1' but not reversed to '0' value, so some modifications can be applied if the eFuse registers are not locked.

The registers lock can be forced using the following command:

STM32MP> fuse prog 0 0x10000039 0x40000000 0x40000000
STM32MP> fuse sense 0 0x10000039 2
Sensing bank 0:
Word 0x10000039: 40000000 40000000
STM32MP>

eFuse reading[edit | edit source]

The eFuse registers can be read - after programming - for checking the written values:

STM32MP> fuse sense 0 57 2
Sensing bank 0:
Word 0x00000039: 9f7a012a 0000203e
STM32MP>

Linux kernel MAC address[edit | edit source]

The MAC Address configured in u-boot is passed to the kernel which configures the eth0 peripherals with the correct values:

root@desk-mp1:~# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.89  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::2801:7aff:fe9f:3e20  prefixlen 64  scopeid 0x20<link>
        ether 2a:01:7a:9f:3e:20  txqueuelen 1000  (Ethernet)
        RX packets 199  bytes 19957 (19.4 KiB)
        RX errors 0  dropped 5  overruns 0  frame 0
        TX packets 58  bytes 7816 (7.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 44  base 0xa000

root@desk-mp1:~#