We have succesfully added the second ethernet for the iMX8.
We plan to have our own range of MAC addresses for the second ethernet, and was thinking that maybe we can reuse the Toradex way of thinking by setting the first three bytes to our OUI and the last three bytes to represent the serial number.
I can manually hardcode it in U-boot by
setenv eth1addr 02:AB:CD:EF:12:34
savenev
This takes effect.
How do I best do the next step so that it is automated as possible?
By next step I mean automate it so that it is scripted to set eth1addr to our OUI and then the next three bytes representing the serial number.
I can hardcode it through u_boot_env, but was hoping on copying how the MAC is set for eth0 and doing it in our custom build of TorizonCore.
Could you direct me to where it is done in the Yocto build?
Also, I forgot to mention in the question that if there is a way to use a Toradex MAC for eth1 that would be our first choice, but as I understand from other posts there is not?
For other modules I think I read that the second ethernet got the same MAC as eth0, but offset 0x100000 or something?
I have gotten so far that I can set a fixed MAC by manipulating the u-boot-toradex recipe, by adding this in u-boot-toradex_%.bbappend:
do_configure:append() {
# Insert eth1 MAC address
# This line inserts the hardcoded address at the right place. It should be available in u-boot now.
sed -i '/^\t"panel.*"/ s/\(\t"panel.*" \)\\$/&\n\t"eth1addr=02:AB:CD:EF:12:34\\0" \\/' ${S}/include/configs/apalis-imx8.h
# For next step we want to get address 02:AB:CD followed by the last three bytes for serial number, converted to hex
# It could also be copied from ethaddr last three bytes, or characters 10-17 in ethaddr
}
I am now trying to retrieve the last three bytes of ethaddr in u-boot, so i can concatenate my OUI in first three bytes + serial in hex for last three bytes of eth1addr.
I can find serial# in u-boot, but it is decimal so I cannot use it straight of.
From where is serial# is u-boot calculated?
How do you guys calculate the last three bytes of ethaddr from serial number?
Hello @jugge ,
You can have a look at the function get_mac_from_serial (u32 tdx_serial, struct toradex_eth_addr *eth_addr) in board/toradex/common/tdx-cfg-block.c
Nothing implemented yet, but based on your input we are thinking about copying the method in this define and implementing our own, and possibly also put it under its own define and add it to apalis-imx8.
I am thinking it will look something like this, but I have not tested it yet:
Current method in board/toradex/tdx-common.c:
#ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR
if (!eth_env_get_enetaddr("eth1addr", ethaddr)) {
/*
* Secondary MAC address is allocated from block
* 0x100000 higher then the first MAC address
*/
memcpy(ethaddr, &tdx_eth_addr, 6);
ethaddr[3] += 0x10;
eth_env_set_enetaddr("eth1addr", ethaddr);
}
#endif
What I am thinking about testing, when time allows:
#ifdef CONFIG_CUSTOM_CFG_BLOCK_2ND_ETHADDR
if (!eth_env_get_enetaddr("eth1addr", ethaddr)) {
/*
* Secondary MAC address is copied from first MAC
* address and then replacing the first three bytes to
* a hardcoded OUI 02:AA:BB
*/
memcpy(ethaddr, &tdx_eth_addr, 6);
ethaddr[0] = 0x02;
ethaddr[1] = 0xAA;
ethaddr[2] = 0xBB;
eth_env_set_enetaddr("eth1addr", ethaddr);
}
#endif
If the custom define CONFIG_CUSTOM_CFG_BLOCK_2ND_ETHADDR is used I am guessing I need to define it in apalis-imx8., something like this:
do_configure:append() {
CONFIG_CUSTOM_CFG_BLOCK_2ND_ETHADDR to u-boot config
# Add the config after line /* Networking */ in apalis-imx8.h
sed -i '/\/\* Networking \*\//a #define CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR' ${S}/include/configs/apalis-imx8.h
}