netutils/netinit: Support the NETINIT_MACADDR

Support getting MAC address from boardctl(BOARDIOC_MACADDR) via NETINIT_MACADDR.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
liqinhui 2025-06-06 10:07:25 +08:00 committed by Xiang Xiao
parent 42e3566147
commit b80d67c628
3 changed files with 18 additions and 6 deletions

View file

@ -488,6 +488,13 @@ config NETINIT_SWMAC
With this choice, you can assign a fixed MAC address determined by
a NuttX configuration option.
config NETINIT_MACADDR
bool "Device MAC address"
depends on BOARDCTL_MACADDR
---help---
With this choice, you can assign a fixed MAC address in the file
device.info (DEVICE_INFO_PATH) defined by user.
endchoice # MAC address selection
config NETINIT_MACADDR_1

View file

@ -286,7 +286,9 @@ static const uint16_t g_ipv6_netmask[8] =
defined(HAVE_MAC)
static void netinit_set_macaddr(void)
{
#if defined(CONFIG_NETINIT_UIDMAC)
#if defined(CONFIG_NETINIT_MACADDR)
struct boardioc_macaddr_s req;
#elif defined(CONFIG_NETINIT_UIDMAC)
uint8_t uid[CONFIG_BOARDCTL_UNIQUEID_SIZE];
#elif defined(CONFIG_NET_ETHERNET)
uint8_t mac[IFHWADDRLEN];
@ -296,7 +298,14 @@ static void netinit_set_macaddr(void)
/* Many embedded network interfaces must have a software assigned MAC */
#if defined(CONFIG_NETINIT_UIDMAC)
#if defined(CONFIG_NETINIT_MACADDR)
strlcpy(req.ifname, NET_DEVNAME, IFNAMSIZ);
if (boardctl(BOARDIOC_MACADDR, (uintptr_t)&req) == 0)
{
netlib_setmacaddr(NET_DEVNAME, req.macaddr);
}
#elif defined(CONFIG_NETINIT_UIDMAC)
boardctl(BOARDIOC_UNIQUEID, (uintptr_t)&uid);
uid[0] = (uid[0] & 0b11110000) | 2; /* Locally Administered MAC */
netlib_setmacaddr(NET_DEVNAME, uid);