[PATCH 02/10] board: samsung: e850-96: Set ethaddr

Sam Protsenko semen.protsenko at linaro.org
Thu Aug 7 00:27:02 CEST 2025


Set the environment variable for Ethernet MAC address (ethaddr). Use the
SoC ID to make sure it's unique. It'll be formatted in a way that
follows the consecutive style of the serial number ("serial#" variable),
i.e.:

    OTP_CHIPID0   = 0xf51c8113
    OTP_CHIPID1   = 0x236
    get_chip_id() = 0x236f51c8113
    serial#       = 00000236f51c8113
    ethaddr       = 02:36:f5:1c:81:13

where corresponding bytes of the MAC address are:

    mac_addr[0]   = 0x02   // OTP_CHIPID1[15:8]
    mac_addr[1]   = 0x36   // OTP_CHIPID1[7:0]
    mac_addr[2]   = 0xf5   // OTP_CHIPID0[31:24]
    mac_addr[3]   = 0x1c   // OTP_CHIPID0[23:16]
    mac_addr[4]   = 0x81   // OTP_CHIPID0[15:8]
    mac_addr[5]   = 0x13   // OTP_CHIPID0[7:0]

because OTP_CHIPID1 has only 16 significant bits (with actual ID
values), and all 32 bits of OTP_CHIPID0 are significant.

Signed-off-by: Sam Protsenko <semen.protsenko at linaro.org>
---
 board/samsung/e850-96/e850-96.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/board/samsung/e850-96/e850-96.c b/board/samsung/e850-96/e850-96.c
index a6c264d12481..d489716bfdf2 100644
--- a/board/samsung/e850-96/e850-96.c
+++ b/board/samsung/e850-96/e850-96.c
@@ -8,6 +8,7 @@
 #include <env.h>
 #include <init.h>
 #include <mapmem.h>
+#include <net.h>
 #include <asm/io.h>
 #include "fw.h"
 
@@ -92,11 +93,35 @@ static void setup_serial(void)
 	env_set("serial#", serial_str);
 }
 
+static void setup_ethaddr(void)
+{
+	u64 serial_num;
+	u32 mac_hi, mac_lo;
+	u8 mac_addr[6];
+
+	if (env_get("ethaddr"))
+		return;
+
+	serial_num = get_chip_id();
+	mac_lo = (u32)serial_num;		/* OTP_CHIPID0 */
+	mac_hi = (u32)(serial_num >> 32UL);	/* OTP_CHIPID1 */
+	mac_addr[0] = (mac_hi >> 8) & 0xff;
+	mac_addr[1] = mac_hi & 0xff;
+	mac_addr[2] = (mac_lo >> 24) & 0xff;
+	mac_addr[3] = (mac_lo >> 16) & 0xff;
+	mac_addr[4] = (mac_lo >> 8) & 0xff;
+	mac_addr[5] = mac_lo & 0xff;
+	mac_addr[0] &= ~0x1; /* make sure it's not a multicast address */
+	if (is_valid_ethaddr(mac_addr))
+		eth_env_set_enetaddr("ethaddr", mac_addr);
+}
+
 int board_late_init(void)
 {
 	int err;
 
 	setup_serial();
+	setup_ethaddr();
 
 	/*
 	 * Do this in board_late_init() to make sure MMC is not probed before
-- 
2.39.5



More information about the U-Boot mailing list