Skip to content

Commit 77f2eb1

Browse files
Check version register of the OTP
The version of register 0 and 1 must be equal to 1, otherwise do not attempt to read any data from the OTP. Signed-off-by: Francois Berder <[email protected]>
1 parent f75db81 commit 77f2eb1

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

board/imgtec/pistachio_bub/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ obj-y += cmd_scratchpad.o
2121
endif
2222
ifdef CONFIG_WINBOND_OTP
2323
obj-y += fdt.o
24+
obj-y += otp.o
2425
endif

board/imgtec/pistachio_bub/fdt.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
1111

1212
#include <winbond-otp.h>
13-
14-
#define WIFI_STA_MAC_ADDRESS_OFFSET 0x1003
15-
#define WIFI_AP_MAC_ADDRESS_OFFSET 0x1009
16-
#define DCXO_OFFSET 0x2003
13+
#include "otp.h"
1714

1815
DECLARE_GLOBAL_DATA_PTR;
1916

@@ -24,6 +21,10 @@ static void fixup_wifi(void *blob)
2421
char dcxo;
2522
char *rf_params_prop;
2623

24+
if (check_otp_version(VERSION_REG0_OFFSET)
25+
|| check_otp_version(VERSION_REG1_OFFSET))
26+
return;
27+
2728
node = fdt_path_offset(blob, "/uccp@18480000");
2829
if (node < 0) {
2930
printf("WARNING: no /uccp@18480000 path\n");

board/imgtec/pistachio_bub/otp.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2016 Imagination Technologies
3+
* Author: Francois Berder <[email protected]>
4+
*
5+
* SPDX-License-Identifier: GPL-2.0+
6+
*/
7+
8+
#include <common.h>
9+
#include <winbond-otp.h>
10+
#include "otp.h"
11+
12+
int check_otp_version(loff_t offset)
13+
{
14+
u_char version;
15+
16+
if (read_otp_data(offset, sizeof(version), (char *)&version)) {
17+
printf("WARNING: Could not read register version from OTP.\n");
18+
return -1;
19+
}
20+
21+
if (version != 1) {
22+
printf("WARNING: Unknown version in OTP.\n");
23+
return -1;
24+
}
25+
26+
return 0;
27+
}

board/imgtec/pistachio_bub/otp.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2016 Imagination Technologies
3+
* Author: Francois Berder <[email protected]>
4+
*
5+
* SPDX-License-Identifier: GPL-2.0+
6+
*/
7+
8+
#ifndef _OTP_H
9+
#define _OTP_H
10+
11+
#ifdef CONFIG_WINBOND_OTP
12+
13+
#include <linux/types.h>
14+
15+
#define VERSION_REG0_OFFSET 0x1002
16+
#define VERSION_REG1_OFFSET 0x2002
17+
#define WIFI_STA_MAC_ADDRESS_OFFSET 0x1003
18+
#define WIFI_AP_MAC_ADDRESS_OFFSET 0x1009
19+
#define ETH_MAC_ADDRESS_OFFSET 0x1015
20+
#define DCXO_OFFSET 0x2003
21+
22+
/*
23+
* check_otp_version: Check version register from OTP
24+
* @offset: Offset of the register in the OTP.
25+
*
26+
* returns:
27+
* 0 if the version is equal to 1
28+
* -1 otherwise
29+
*/
30+
int check_otp_version(loff_t offset);
31+
32+
#endif
33+
34+
#endif

board/imgtec/pistachio_bub/pistachio.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <tpm.h>
2424
#include <winbond-otp.h>
2525
#include "mfio.h"
26+
#include "otp.h"
2627

27-
#define ETH_MAC_ADDRESS_OFFSET 0x1015 /* Ethernet MAC address offset */
2828

2929
DECLARE_GLOBAL_DATA_PTR;
3030

@@ -129,7 +129,8 @@ int board_eth_init(bd_t *bs)
129129
eth_getenv_enetaddr("ethaddr", mac_addr);
130130

131131
#ifdef CONFIG_WINBOND_OTP
132-
if (!is_valid_ethaddr(mac_addr)) {
132+
if (!is_valid_ethaddr(mac_addr)
133+
&& !check_otp_version(VERSION_REG0_OFFSET)) {
133134
if (!read_otp_data(ETH_MAC_ADDRESS_OFFSET, MAC_ADDR_LEN,
134135
(char *)mac_addr)
135136
&& is_valid_ethaddr(mac_addr))

0 commit comments

Comments
 (0)