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.

MAC Address Assignment from NAND Flash?

Other Parts Discussed in Thread: AM1808

Can anyone tell me if it is possible to be able to assign a MAC Address when booting from NAND flash where no SPI Flash exists (i.e. custom board).
Regardless of setting the ethaddr variable in u-boot, whenever linux boots, a random Mac Address is assigned.  I have found discussions on the fact that when booting Linux, the Mac Address is attempted to be retrieved from SPI Flash...and if it is not found, it will assign a random Mac Address regardless of what u-boot ethaddr variable is set to. I also see there is some patch that is required from here: https://patchwork.kernel.org/patch/861732/  in order to have the Mac Address correctly assigned.  In addition, I have found the documentation on how to restore the MAC Address on SPI Flash if it was erased or needs to be changed from here: http://processors.wiki.ti.com/index.php/GSG:_OMAP-L138_DVEVM_Additional_Procedures#Restoring_MAC_address_on_SPI_Flash.  My big problem is that nobody is talking about the situation when no SPI Flash is available. Can the MAC Address assignment be done from NAND flash?  If so how?  If not..does this mean I need to put SPI Flash on my custom board for the sole purpose of assigning a static MAC Address? I can't ship production boards with MAC Addresses that change everytime a board is booted.  BTW - I have an AM1808 processor.
Thanks for any help you can provide!

  • OK - since my post I have found the following post also talking about the problem:

    http://answerpot.com/showthread.php?2018845-DaVinci+EMAC+driver+uses+random+MAC+addresses

    I have also found that I can force a new MAC after Linux starts by performing the following:
    ifconfig eth0 down
    ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX
    ifconfig eth0 up

    Alternatively, we can install SPI Flash on our board in order to follow T.I.'s instructions on how to flash the right part of SPI Flash for the MAC Address..but I was hoping someone had a way that the u-boot arg "ethaddr" could be used to force the right MAC address without having to install an SPI Flash on our custom board.

  • My L137 EVM gets its MAC address from a I2C EEPROM that won't be on the production board. I'm pondering possible solutions as well.

    1) U-Boot initializes the MAC register in the Ethernet controller. Linux just picks its up taking care not to reset the register. I've seen on some non-TI processors with a separate controller. Not sure how easy it would be to do this on a TI chip.

    2) Linux reads out the MAC address from the same place that U-Boot stores it in NAND, or in my case SPI Flash. If the flash code is already in place and you can figure out where the MAC is stored, this approach would seem the most elegant.

    3) Write your own bootarg hack. Some possible untested and uncompiled code below.

    File: arch/arm/mach-davinci/common.c

    #include <linux/init.h>

    static int __init set_mac_addr(char *str)
    {
      unsigned int m[6];
      char *mac = davinci_soc_info.emac_pdata->mac_addr;

      if(sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
                 &m[0],&m[1],&m[2],&m[3],&m[4],&m[5]) != 6)
        return(0);

      mac[0] = (char)m[0];
      mac[1] = (char)m[1];
      mac[2] = (char)m[2];
      mac[3] = (char)m[3];
      mac[4] = (char)m[4];
      mac[5] = (char)m[5];

      pr_info("Read MAC addr from cmdline: %pM\n", mac);
      return 1;
    }
    __setup("mac=", set_mac_addr);

    I am assuming that in mass production, for each board, the U-Boot parameters with a unique MAC is programmed directly into NAND. For low volume, you'd manually type it in and saveenv'ing it.

     

  • Hi Norman,
    Well..you just happen to find all of my posts huh?  :-)  Thanks for your insight. I am currently trying to access my custom u-boot variable from within the davinci_emac.c file, but it is not yet working as anticipated.  I have added some code at the top of the file such as:

    static char *mac_address = "XX.XX.XX.XX.XX.XX";
    module_param(mac_address, charp, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
    MODULE_PARAM_DESC(mac_address, "DaVinci EMAC Assigned MAC Address");

    Then in the function: __devinit_davinci_emac_probe(struct platform_device *pdev), I try to print out the mac_address variable using:
    printk(KERN_INFO "mac_address = %s\n", mac_address);

    Unfortunately, I never get the value that I set from u-boot.  Here are my u-boot args:

    setenv bootargs mem=64M console=ttyS2,115200n8 root=/dev/ram0 rw initrd=0xc1180000,18M ip=10.0.1.123 mac_address=${ethaddr}
    setenv nandbootargs 'setenv bootargs mem=64M console=ttyS2,115200n8 root=/dev/ram0 rw initrd=0xc1180000,18M ip=10.0.1.123 mac_address=${ethaddr}'
    setenv nandboot 'run nandbootargs; mw 6800001c 84122115; mw 01c14138 00000081; mw 01c1413c 00111111; mw 01c14140 11111111; mw 01c14144 11111111; mw 01c14148 11111111; mw 01c1414c 11111111; mw 01c14150 11111111; nand read.e 0xc1180000 0x600000 0x700000; nboot.e 0xc0700000 0 0x200000; bootm'
    setenv bootcmd run nandboot

    I have also tried changing the mac_address assignment to "davinci_emac_driver.mac_address" as I have seen some posts suggesting to use the module name prior to the variable. So far..no luck.  I will report back when I figure it out.

  • I'm looking at the 3.21.00.04 version of "drivers/net/davinci_emac.c". The module name is "davinci_emac". No "_driver".

     

     

  • Ah - maybe that is the reason!  I was just assuming the help that pops up when investigating what drivers to include in the kernel (kernel config) was correct. Looking at the help they say the module name is with "_driver"  - I will give this a shot in the AM as I have to run.  I will let you know if that did it.

    Thanks!

  • Thanks Norman - I am now able to see the value I set in u-boot.  Much appreciated.