Skip to content

Commit 20b07e3

Browse files
Avinash95francois-berder
authored andcommitted
Set ethernet mac address read from OTP
ethernet MAC address is stored in the OTP, read it and write it into dtb, so kernel can use updated MAC address Signed-off-by: Avinash Tahakik <[email protected]> Signed-off-by: Francois Berder <[email protected]>
1 parent 3be46f0 commit 20b07e3

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

board/imgtec/pistachio_bub/pistachio.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#include <asm-generic/sections.h>
2222
#include <watchdog.h>
2323
#include <tpm.h>
24-
24+
#include <winbond-otp.h>
2525
#include "mfio.h"
2626

27+
#define ETH_MAC_ADDRESS_OFFSET 0x1015 /* Ethernet MAC address offset */
28+
2729
DECLARE_GLOBAL_DATA_PTR;
28-
const char *enet_dtb_macaddr = 0;
2930

3031
int reloc_tlb_fixup(void)
3132
{
@@ -109,22 +110,42 @@ static const char *get_dtb_macaddr(u32 ifno)
109110
if (mac && is_valid_ethaddr((u8 *)mac))
110111
return mac;
111112

112-
return NULL;
113+
return NULL;
113114
}
114115
#endif
115116

116117
int board_eth_init(bd_t *bs)
117118
{
119+
u_char mac_addr[MAC_ADDR_LEN];
120+
118121
mfio_setup_ethernet();
119122

120-
/* try to get a valid macaddr from dtb */
123+
/* Order of precedence:
124+
* 1. Check for existing ethaddr environment variable
125+
* 2. Read from OTP
126+
* 3. Fallback on dtb
127+
*/
128+
memset(mac_addr, 0, MAC_ADDR_LEN);
129+
eth_getenv_enetaddr("ethaddr", mac_addr);
130+
131+
#ifdef CONFIG_WINBOND_OTP
132+
if (!is_valid_ethaddr(mac_addr)) {
133+
if (!read_otp_data(ETH_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
134+
(char *)mac_addr)
135+
&& is_valid_ethaddr(mac_addr))
136+
eth_setenv_enetaddr("ethaddr", (u8 *)mac_addr);
137+
else
138+
printf("Could not read MAC address from OTP\n");
139+
}
140+
#endif
121141
#ifdef CONFIG_OF_CONTROL
122-
enet_dtb_macaddr = get_dtb_macaddr(0);
123-
124-
if (enet_dtb_macaddr)
125-
eth_setenv_enetaddr("ethaddr", (u8 *)enet_dtb_macaddr);
126-
else
127-
printf("No valid Mac-addr found from dtb\n");
142+
if (!is_valid_ethaddr(mac_addr)) {
143+
const char *enet_dtb_macaddr = get_dtb_macaddr(0);
144+
if (enet_dtb_macaddr)
145+
eth_setenv_enetaddr("ethaddr", (u8 *)enet_dtb_macaddr);
146+
else
147+
printf("No valid Mac-addr found from dtb\n");
148+
}
128149
#endif
129150

130151
#ifndef CONFIG_DM_ETH

include/configs/pistachio_bub.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#define PISTACHIO_BOARD_NAME CONFIG_SYS_CONFIG_NAME
2323
#define CONFIG_BOARD_EARLY_INIT_F
2424
#define CONFIG_DISPLAY_BOARDINFO
25-
25+
#define CONFIG_WINBOND_OTP
2626
#define CONFIG_OF_LIBFDT
27+
2728
/*
2829
* CPU Configuration
2930
*/

0 commit comments

Comments
 (0)