Search code examples
linuxnetworkingembeddedethernetconnman

How to set ethernet interface MAC address with connman


I have an embedded system that requires me to pull a MAC address out of flash and pass it to the Ethernet interface at the time it is brought up. Traditionally I have modified the call to ifconfig in an init script to just pass the MAC pulled out of flash as the hw ether parameter.

The system I am working on uses connman to handle the network connection. The embedded system will always have a single Ethernet connection with a single matching MAC address in a custom format in flash. connman is used as when the interface is available changes, so having a dynamic system for handling bringing the interface up and down and configuring it is helpful.

Is it possible to pass the MAC to connman to use in a similar way to what I have done before with ifconfig and, if so, how?

Alternatively is it possible to pass the MAC as a boot parameter to the kernel so that connman never has to know about this? I can pull the MAC out of flash in U-Boot but the Ethernet device is not available to U-Boot.


Solution

  • Alternatively is it possible to pass the MAC as a boot parameter to the kernel so that connman never has to know about this?

    Yes, you can use U-Boot's ethaddr environment variable to do exactly that.

    Check out U-Boot Environment Variables for documentation on the variable.

    Relevant documentation snippet:

    ethaddr: Ethernet MAC address for first/only ethernet interface (= eth0 in Linux). This variable can be set only once (usually during manufacturing of the board). U-Boot refuses to delete or overwrite this variable once it has been set.

    It may be as simple as running the following commands to set the environment variable and save it (substituting your MAC address of course):

    setenv ethaddr 11:22:33:44:55:66
    saveenv
    

    If ethaddr isn't already used in your U-Boot boot line then you'll need to do more than just the above. For an example of how to configure this on a system, check out How to set a fixed MAC address in a LeopardBoard DM36x.

    Here's the boot command utilizing ethaddr that the above site ends up with:

    setenv bootcmd 'setenv bootargs \${bootargs} davinci_emac.ethaddr=\${ethaddr}; nboot 0x82000000 0 \${kerneloffset}'