AR# 70176

|

2018.x -- 2019.x Zynq UltraScale+ MPSoC: How to get MAC address from EEPROM on ZCU102 Board using PetaLinux?

Description

How can I get a mac address from serial EEPROM on PetaLinux? 

If a valid MAC address is stored in the EEPROM, this is used as default address if there is NO corresponding address setting in the u-boot environment.

If the corresponding environment (ethaddr) variable is set, this overrides the EEPROM address. This implies that:

  • If the EEPROM has a valid MAC address, and there is no address in the environment, the EEPROM's address is used.
  • If there is no valid address in the EEPROM, and a definition in the environment exists, then the value from the environment variable is used.
  • If both the EEPROM and the environment contain a MAC address, and both addresses are the same, this MAC address is used.
  • If both the EEPROM and the environment contain a MAC address, and the addresses differ, the value from the environment is used and a warning is printed.
 
Thus, to force u-boot to read the MAC address from EEPROM, the user needs to unset the value of the variable 'ethaddr' in the u-boot environment.

Solution

The solution is comprised of two parts:

Part 1: Ensure that the u-boot environment variable 'ethaddr' is undefined.

Part 2: Write the MAC address into the EEPROM

Part 1:

Depending on the flow you are using, choose either of the following methods to ensure that the U-Boot environment variable 'ethaddr' is undefined:

 

a) If you are customizing the PetaLinux project:

Run the below command and then select the following:

$ petalinux-config
---> Subsystem AUTO Hardware Settings --> Ethernet Settings --> Ethernet MAC address

Delete the default value, and keep this empty. Make sure to save the new config prior to exiting the GUI menu.

 

b) If using pre-built PetaLinux images:

Halt at U-Boot, and issue the following commands:

ZynqMP> setenv ethaddr
ZynqMP> saveenv

Part 2:

Use one of the two methods below to program the MAC address to EEPROM:

 

1) ZCU102_SCUI

In previous versions of the SCUI (earlier than 2016.4), it was possible to set the MAC Address in the SCUI GUI.

However, from the 2017.1 release on, that option no longer exists, and you can only get the MAC Address from the board.

However, you can manually take it back by adding the following section to config.json (rdf0382-zcu102-system-controller-es2-2017-2.zip) , saving the config.json, and relaunching the SCUI.

{
      "name": "Set MAC Address",
      "command": "<setmux:1:74:01><writeeeprom:1:54:20:<3>><setmux:1:74:00>",
      "UI": {
          "spacer": 20,
          "label": "Input the board MAC address with no colons (only hex characters):",
          "spacer": 20,
          "input": "^([0-9a-fA-F]{12})$"
      }
}

 

The modified file is attached to this Answer Record.

 

2) Writing EEPROM Using I2C Commands over U-Boot

Before writing, you need to know the address of the EEPROM. 

Below are the files containing the MAC address information of the EEPROM defined in U-Boot for a ZCU102 board.

This information will be passed as arguments to the I2C commands for programming the MAC address into the EEPROM.

For 2018.x PetaLinux:

https://github.com/Xilinx/device-tree-xlnx/blob/xilinx-v2018.3/device_tree/data/kernel_dtsi/2018.3/BOARD/zcu102-rev1.0.dtsi

eeprom: eeprom@54 { /* u23 */
                  compatible = "at,24c08";
                  reg = <0x54>;
};

 

For 2019.1 PetaLinux:

https://github.com/Xilinx/device-tree-xlnx/blob/xilinx-v2019.1/device_tree/data/kernel_dtsi/2019.1/BOARD/zcu102-rev1.0.dtsi

eeprom: eeprom@54 { /* u23 */
                  compatible = "atmel,24c08";
                  reg = <0x54>;
};

 

Note: If using petalinux 2019.1, please refer to https://www.xilinx.com/support/answers/72401.html, for generating the correct device-tree entry for the eeprom node as shown above.

The following line defines the offset for writing the MAC address.

https://github.com/Xilinx/u-boot-xlnx/blob/xilinx-v2019.1/configs/xilinx_zynqmp_zcu102_rev1_0_defconfig

#define CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET 0x20

So the address of the EEPROM device is 0x54, and the MAC address is located at an offset of 0x20.

Use this information to update your desired MAC address to EEPROM with the following I2C commands:

ZynqMP> i2c 
i2c - I2C sub-system

Usage:
i2c bus [muxtype:muxaddr:muxchannel] - show I2C bus info
crc32 chip address[.0, .1, .2] count - compute CRC32 checksum
i2c dev [dev] - show or set current I2C bus
i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device
i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device
i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)
i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)
i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)
i2c probe [address] - test for and show device(s) on the I2C bus
i2c read chip address[.0, .1, .2] length memaddress - read to memory
i2c write memaddress chip address[.0, .1, .2] length [-s] - write memory
          to I2C; the -s option selects bulk write in a single transaction
i2c reset - re-init the I2C Controller
i2c speed [speed] - show or set I2C bus speed

ZynqMP> mm.b 0
00000000: 00 ? 00
00000001: 00 ? 0a
00000002: 00 ? 35
00000003: 00 ? 03
00000004: 00 ? 2c
00000005: 00 ? 5a
00000006: 00 ? q
ZynqMP> i2c dev 5
Current bus is 5
ZynqMP> i2c write 0 54 20 6
ZynqMP> i2c md 54 20 6
0020: 00 0a 35 03 2c 5a  

ZynqMP> reset   

After the reset command above, you should see U-Boot reading the MAC address from the EEPROM, and also the variable 'ethaddr' being updated with this address.

Warning: ethernet@ff0e0000 using MAC address from ROM
eth0: ethernet@ff0e0000
Hit any key to stop autoboot: 0
ZynqMP> printenv ethaddr
ethaddr=00:0a:35:03:2c:5a

Attachments

Associated Attachments

Name File Size File Type
config.zip 4 KB ZIP
AR# 70176
Date 04/26/2021
Status Active
Type General Article
Devices
Tools
Boards & Kits
People Also Viewed