Burning MAC In Uboot


1. Open The MAC Burning Function In Uboot

Take spinand board as an example:

$ cd boot
$ make pioneer3_spinand_defconfig
$ make menuconfig

Set the following options to true:

->Device Drivers
->MStar drivers
    ->MSTAR MAC BURN    #Enable burning mac
    ->MSTAR SDMMC       #Enable SD drive
$ make clean;make

Recompile uboot, and copy boot/u-boot_spinand.xz.img.bin to project/board/p3/boot/spinand/uboot, uboot.bin will be updated when images are packaged in project.

uboot patch:P3-boot-support-batch-mac-address-burning.patch


2. Make MAC Burning File

If the MAC address is continuous, you can use the script to automatically generate the flash file, copy the mac_split.sh to the SD card (SD card needs to be formatted as fat32), and run the script as follows to generate the MAC flash file in batches in linux .

$ sh mac_split.sh –h ab:cd:ef:hi:jk –s 0 –e 99

Parameter description:

-h : MAC address header

-s : MAC address start value

-e : MAC address end value

Generate MAC_INDEX to record the number of the mac file currently to be burned, up to 9999, such as: 0001 means 1, and the corresponding mac file is MAC_1.

MAC_0~MAC_99 save the actual address of the mac to be burned, such as: MAC_0 is ab:cd:ef:hi:jk:00, MAC_99 is ab:cd:ef:hi:jk: 63.

Manually make the burning file, according to the above, create a new MAX_INDEX and MAC_0~MAC_99, and modify the content according to the actual situation.


3. Principle of Burning MAC

Power on the demo board, after uboot runs, first check whether the SD card is inserted, and then read MAC_INDEX from it to get the current MAC file number to be burned, and then read the specified MAC file according to the number to get the actual mac address value; Write the mac address to the environment variable ethaddr through setenv and save it. Finally, add 1 to the current MAC file number and rewrite it to MAC_INDEX, and find the new MAC programming file through MAC_INDEX during the next burning.

The environment variable ethaddr is written to the flash, it will not be lost after power failure, and the user can read the mac address through getenv.

...