Skip to content. | Skip to navigation

Sections
You are here: Home Support Knowledge Base Setting per-board ethernet MAC addresses

Setting per-board ethernet MAC addresses

I am manufacturing a device the runs PetaLinux, and I need to each one to have a different network MAC address. How can I change the MAC address per-board without building a different PetaLinux image for each board?

Problem Description

By default, the ethernet MAC address for both u-boot and the kernel are set during compilation, based on the "Ethernet MAC address" option in the "System Settings" configuration menu.

When preparing devices for manufacturing, it is not practical to create a new PetaLinux system image for each board, to provide a unique MAC address.

This Knowledge Base article describes a manufacturing-friendly procedure the allows easy customisation of the board MAC address.

Background

The system MAC address is used in both u-boot and the kernel. In case of u-boot, it uses the environment variable "ethaddr" as the MAC address. In case of the Linux kernel, it gets the MAC address from the device tree (DTB/DTS file).

To update the MAC address on a per-board basis, we need to update both the "ethaddr" u-boot variable and the MAC address in the device tree.

This is achieved by creating a new flash memory partition to hold the per-board DTB, which will override the default DTB built into the PetaLinux system image

Resolution

This solution is for PetaLinux SDK version 1.3 and later.  The following procedure is used to set a per-board ethernet address.  It is intended that this procedure would be integrated with a manufacturing process, which might involve a bar-code scanner or similar to automatically inject the sequence of commands to the u-boot console, including the unique MAC address.

 1. Create a flash partition "dtb" to contain the DTB file with the minimum partition size as 16KByte (0x4000) with menuconfig.  Be sure to observe any flash device rules about minimum sector size:

    $ petalinux-config-app
      "System Settings" --->
          |-"Flash Partition Table" --->
             (dtb) name
             (0x4000) size

 2. Rebuild PetaLinux:

    $ cd ${PETALINUX}/software/petalinux-dist
    $ make clean
    $ make

The resulting u-boot (u-boot-s.bin) and kernel (image.ub) images will be programmed into the flash memory of all boards to be manufactured.

The following steps will then be performed per-board:

 3. After programing the board with the FPGA bitstream, download the latest built u-boot image:

    $ petalinux-jtag-boot -u

  Alternatively, boot the board directly into u-boot via fs-boot.

 4. When u-boot starts, download the DTB file to the DTB flash partition:

    u-boot> run update_dtb

    This command will download the DTB file to the DTB flash partition.  Ensure that the serverip variable 

 

 5. update the u-boot MAC address:

    u-boot> set ethaddr AA BB CC DD EE FF

 6. Save the u-boot environment variables to save the u-boot MAC address:

    u-boot> saveenv

 

 7. Load the DTB file from the DTB flash partition to the memory:

    u-boot> run get_dtb

 8. Set the MAC address in DTB:

    u-boot> fdt set <PATH TO local-mac-address PROPERTY OF THE ETHERNET CORE> local-mac-address "[AA BB CC DD EE FF]"

   e.g. Change the MAC address of Ethernet lite:

   u-boot> fdt set /plb@0/ethernet@81000000 local-mac-address "[AA BB CC DD EE FF]"

   e.g. Change the MAC address of ll_temac:

   u-boot> fdt set /plb@0/xps-ll-temac@82780000/ethernet@82780000 local-mac-address "[AA BB CC DD EE FF]" 

You can use the u-boot command 'fdt print' to display the device tree, and find the DTB path to the ethernet device

 9. Copy the changed DTB file back to flash:

    u-boot> run install_dtb

 10. Update the kernel image in flash (if necessary):

    u-boot> run update_kernel

 11. Update the u-boot image in Flash (if necessary):

    u-boot-> run update_uboot

Next time when you reboot the board, it will boot the kernel with the updated DTB from the flash from u-boot.

Document Actions
Quick Contact
Customer stories

Petalogix helped us stay on our target schedule and provided valuable insight.

Read more PetaLogix customer stories

 
Site by:
Personal tools