ARM: stm32: Add MAC address readout from fuses on DH STM32MP1 DHSOM
authorMarek Vasut <marek.vasut@mailbox.org>
Thu, 23 Oct 2025 21:48:26 +0000 (23:48 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 17 Nov 2025 16:45:11 +0000 (10:45 -0600)
Add support for reading out the MAC address from SoC fuses on DH STM32MP1 DHSOM.
The DH STM32MP1 DHSOM may contain external ethernet MACs, which benefit from the
MAC address stored in SoC fuses as well, handle those consistently. This however
means the architecture setup_mac_address() cannot be used and instead a simpler
local fuse read out is implemented in the board file.

Signed-off-by: Marek Vasut <marek.vasut@mailbox.org>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
board/dhelectronics/dh_stm32mp1/board.c

index 065d2f3..c18f191 100644 (file)
@@ -119,6 +119,29 @@ static bool dh_stm32_mac_is_in_ks8851(void)
        return false;
 }
 
+static int dh_stm32_get_mac_from_fuse(unsigned char *enetaddr, int index)
+{
+       struct udevice *dev;
+       u8 otp[12];
+       int ret;
+
+       ret = uclass_get_device_by_driver(UCLASS_MISC,
+                                         DM_DRIVER_GET(stm32mp_bsec),
+                                         &dev);
+       if (ret)
+               return ret;
+
+       ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_MAC), otp, sizeof(otp));
+       if (ret < 0)
+               return ret;
+
+       memcpy(enetaddr, otp + ARP_HLEN * index, ARP_HLEN);
+       if (!is_valid_ethaddr(enetaddr))
+               return -EINVAL;
+
+       return 0;
+}
+
 static int dh_stm32_setup_ethaddr(struct eeprom_id_page *eip)
 {
        unsigned char enetaddr[6];
@@ -129,6 +152,9 @@ static int dh_stm32_setup_ethaddr(struct eeprom_id_page *eip)
        if (dh_get_mac_is_enabled("ethernet0"))
                return 0;
 
+       if (!dh_stm32_get_mac_from_fuse(enetaddr, 0))
+               goto out;
+
        if (!dh_get_value_from_eeprom_buffer(DH_MAC0, enetaddr, sizeof(enetaddr), eip))
                goto out;
 
@@ -154,6 +180,9 @@ static int dh_stm32_setup_eth1addr(struct eeprom_id_page *eip)
        if (dh_stm32_mac_is_in_ks8851())
                return 0;
 
+       if (!dh_stm32_get_mac_from_fuse(enetaddr, 1))
+               goto out;
+
        if (!dh_get_value_from_eeprom_buffer(DH_MAC1, enetaddr, sizeof(enetaddr), eip))
                goto out;