]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
board: amlogic: vim3: fix setup ethernet mac from efuse
authorArtem Lapkin <email2tema@gmail.com>
Tue, 12 Jan 2021 11:42:12 +0000 (19:42 +0800)
committerNeil Armstrong <narmstrong@baylibre.com>
Tue, 12 Jan 2021 13:25:55 +0000 (14:25 +0100)
Fix reading built-in ethernet MAC address from efuse

NOTE: MAC is stored in ASCII format, 1bytes = 2characters by 0 offset

if mac from efuse not valid we use meson_generate_serial_ethaddr

NOTE: remake odroid-n2.c from Neil Armstrong <narmstrong@baylibre.com>

Signed-off-by: Artem Lapkin <art@khadas.com>
[narmstrong: remove MAC print & spurious new endline]
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
board/amlogic/vim3/vim3.c

index 824fff826271439d63efb71b60889979a21b3bc7..7145dbe18ecb2d0295a3ed9726026372ceb55c9c 100644 (file)
@@ -139,25 +139,37 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
 }
 
 #define EFUSE_MAC_OFFSET       0
-#define EFUSE_MAC_SIZE         6
+#define EFUSE_MAC_SIZE         12
+#define MAC_ADDR_LEN           6
 
 int misc_init_r(void)
 {
-       uint8_t mac_addr[EFUSE_MAC_SIZE];
+       u8 mac_addr[MAC_ADDR_LEN];
+       char efuse_mac_addr[EFUSE_MAC_SIZE], tmp[3];
        ssize_t len;
 
        meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
 
        if (!eth_env_get_enetaddr("ethaddr", mac_addr)) {
                len = meson_sm_read_efuse(EFUSE_MAC_OFFSET,
-                                         mac_addr, EFUSE_MAC_SIZE);
+                                         efuse_mac_addr, EFUSE_MAC_SIZE);
                if (len != EFUSE_MAC_SIZE)
                        return 0;
 
+               /* MAC is stored in ASCII format, 1bytes = 2characters */
+               for (int i = 0; i < 6; i++) {
+                       tmp[0] = efuse_mac_addr[i * 2];
+                       tmp[1] = efuse_mac_addr[i * 2 + 1];
+                       tmp[2] = '\0';
+                       mac_addr[i] = simple_strtoul(tmp, NULL, 16);
+               }
+
                if (is_valid_ethaddr(mac_addr))
                        eth_env_set_enetaddr("ethaddr", mac_addr);
                else
                        meson_generate_serial_ethaddr();
+
+               eth_env_get_enetaddr("ethaddr", mac_addr);
        }
 
        return 0;