]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
ARM: stm32: Read values from M24256 write-lockable page on STM32MP13xx DHCOR
authorMarek Vasut <marek.vasut@mailbox.org>
Thu, 23 Oct 2025 21:48:25 +0000 (23:48 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 17 Nov 2025 16:45:11 +0000 (10:45 -0600)
The STM32MP13xx DHCOR SoM is populated with M24256 EEPROM that contains
an additional write-lockable page called ID page, which is populated with
a structure containing ethernet MAC addresses, DH item number and DH serial
number.

Read out the MAC address from the WL page between higher priority SoC fuses
and lower priority plain EEPROM storage area. Read out the DH item and serial
numbers and set environment variables accordingly.

Signed-off-by: Marek Vasut <marek.vasut@mailbox.org>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
arch/arm/dts/stm32mp13xx-dhcor-u-boot.dtsi
board/dhelectronics/dh_stm32mp1/board.c

index 5ca0258e3ff6ff5c44bd6e7a68b1cbf389673049..bedb7c600d5d6a87a9bcdfc400ab8ddd8b851caa 100644 (file)
@@ -10,6 +10,7 @@
 / {
        aliases {
                eeprom0 = &eeprom0;
+               eeprom0wl = &eeprom0wl;
        };
 
        config {
index a9b1a0f2c348a5bb019dc86b0479dfed594356ce..065d2f338c2d22698ec88065feb472cfa688af1e 100644 (file)
@@ -119,7 +119,7 @@ static bool dh_stm32_mac_is_in_ks8851(void)
        return false;
 }
 
-static int dh_stm32_setup_ethaddr(void)
+static int dh_stm32_setup_ethaddr(struct eeprom_id_page *eip)
 {
        unsigned char enetaddr[6];
 
@@ -129,13 +129,19 @@ static int dh_stm32_setup_ethaddr(void)
        if (dh_get_mac_is_enabled("ethernet0"))
                return 0;
 
+       if (!dh_get_value_from_eeprom_buffer(DH_MAC0, enetaddr, sizeof(enetaddr), eip))
+               goto out;
+
        if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
-               return eth_env_set_enetaddr("ethaddr", enetaddr);
+               goto out;
 
        return -ENXIO;
+
+out:
+       return eth_env_set_enetaddr("ethaddr", enetaddr);
 }
 
-static int dh_stm32_setup_eth1addr(void)
+static int dh_stm32_setup_eth1addr(struct eeprom_id_page *eip)
 {
        unsigned char enetaddr[6];
 
@@ -148,20 +154,47 @@ static int dh_stm32_setup_eth1addr(void)
        if (dh_stm32_mac_is_in_ks8851())
                return 0;
 
-       if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) {
-               enetaddr[5]++;
-               return eth_env_set_enetaddr("eth1addr", enetaddr);
-       }
+       if (!dh_get_value_from_eeprom_buffer(DH_MAC1, enetaddr, sizeof(enetaddr), eip))
+               goto out;
+
+       if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
+               goto increment_out;
 
        return -ENXIO;
+
+increment_out:
+       enetaddr[5]++;
+
+out:
+       return eth_env_set_enetaddr("eth1addr", enetaddr);
 }
 
 int setup_mac_address(void)
 {
-       if (dh_stm32_setup_ethaddr())
+       u8 eeprom_buffer[DH_EEPROM_ID_PAGE_MAX_SIZE] = { 0 };
+       struct eeprom_id_page *eip = (struct eeprom_id_page *)eeprom_buffer;
+       int ret;
+
+       ret = dh_read_eeprom_id_page(eeprom_buffer, "eeprom0wl");
+       if (ret) {
+               /*
+                * The EEPROM ID page is available on SoM rev. 200 and greater.
+                * For SoM rev. 100 the return value will be -ENODEV. Suppress
+                * the error message for that, because the absence cannot be
+                * treated as an error.
+                */
+               if (ret != -ENODEV)
+                       printf("%s: Cannot read valid data from EEPROM ID page! ret = %d\n",
+                              __func__, ret);
+               eip = NULL;
+       } else {
+               dh_add_item_number_and_serial_to_env(eip);
+       }
+
+       if (dh_stm32_setup_ethaddr(eip))
                log_err("%s: Unable to setup ethaddr!\n", __func__);
 
-       if (dh_stm32_setup_eth1addr())
+       if (dh_stm32_setup_eth1addr(eip))
                log_err("%s: Unable to setup eth1addr!\n", __func__);
 
        return 0;