This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM3352: Change MAC address

Part Number: AM3352

Tool/software: Linux

Hi

I want to set a default mac address on both eth0 and eth1 port.

Could I write it in /etc/systemd/network/10-eth.network?

My code as below, static ip is work, but mac address fail.

[Match]
Name=eth1

[Network]

Address=192.168.66.88

Broadcast=192.168.66.255
Netmask=255.255.255.0
Gateway=192.168.66.1

HWAddress=00:11:22:33:44:55

Thanks.

  • Hi,

    Mac address is setup in the u-boot. In general the MAC address is programmed in the EFUSE registers during SoC production and u-boot code reads this address (unique for each device) and sets it as eth_addr.

    If you wish to override this you have two options:
    1. Program the mac address in external EEPROM and read from there.
    2. Set the MAC addres in a static structure (or array) in u-boot and use it as mac address.

    The code that deals with setting up the MAC is located in u-boot/board/ti/am335x/board.c:

    #if !defined(CONFIG_SPL_BUILD)
    /* try reading mac address from efuse */
    mac_lo = readl(&cdev->macid0l);
    mac_hi = readl(&cdev->macid0h);
    mac_addr[0] = mac_hi & 0xFF;
    mac_addr[1] = (mac_hi & 0xFF00) >> 8;
    mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
    mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
    mac_addr[4] = mac_lo & 0xFF;
    mac_addr[5] = (mac_lo & 0xFF00) >> 8;

    if (!env_get("ethaddr")) {
    printf("<ethaddr> not set. Validating first E-fuse MAC\n");

    if (is_valid_ethaddr(mac_addr))
    eth_env_set_enetaddr("ethaddr", mac_addr);
    }

    mac_lo = readl(&cdev->macid1l);
    mac_hi = readl(&cdev->macid1h);
    mac_addr[0] = mac_hi & 0xFF;
    mac_addr[1] = (mac_hi & 0xFF00) >> 8;
    mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
    mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
    mac_addr[4] = mac_lo & 0xFF;
    mac_addr[5] = (mac_lo & 0xFF00) >> 8;

    if (!env_get("eth1addr")) {
    if (is_valid_ethaddr(mac_addr))
    eth_env_set_enetaddr("eth1addr", mac_addr);
    }

    env_set("ice_mii", prueth_is_mii ? "mii" : "rmii");
    #endif

    Best Regards,
    Yordan

  • Hi Yordan
    We don't have EEPROM on board, it is only EMMC on board.
    Because of we don't have serial port on board, so we can't use setenv and saveenv in u-boot.
    Are that any way changing MAC address in driver or system command or external tool?
    I tried ifconfig and ip command, it is work, but MAC address would return to default after reboot.

    thanks.
  • Hi,

    I mentioned that you can fix it in u-boot and the fixed MAC address would be used instead of the EFUSE one.

    Best Regards,
    Yordan
  • Hi Yordan

    I see mac_addr define in both ti_am_eeprom and ti_common_eeprom in board_detect.h

    We put EEPROM back to board, and write data as below picture

    Could you teach me how to read it in board_eth_init and board_late_init?

  • Hi,

    You should use I2C or SPI reads, depending on how you connect your EEPROM to the AM3352.

    Best Regards,
    Yordan
  • hi Yordan

    I add code in board.c as below

    but I can get correct data, could you help me check the code?

    Our i2c bus is 0, eeprom address is 0x50

    my eeprom data

    Data read by my code

    thanks.

  • Hi,

    In your board.c file, do you have the enable_i2c0_pin_mux() and i2c_init() functions.

    I would suggest to use the same approach as with the board detect (which reads a magic number from the EEPROM). Use the above functions to initialize the i2c interface, then use ti_i2c_eeprom_am_get() to init eeprom chip and then use ti_i2c_eeprom_read() to get data from eeprom.

    Best Regards,
    Yordan