Skip to content

Commit 9a332d4

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

File tree

6 files changed

+75
-9
lines changed

6 files changed

+75
-9
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: 8 additions & 5 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

@@ -69,7 +66,13 @@ static void fixup_wifi_calibration(void *blob, int node)
6966

7067
int ft_board_setup(void *blob, bd_t *bd)
7168
{
72-
int node = fdt_path_offset(blob, "wifi0");
69+
int node;
70+
71+
if (check_otp_version(VERSION_REG0_OFFSET)
72+
|| check_otp_version(VERSION_REG1_OFFSET))
73+
return -1;
74+
75+
node = fdt_path_offset(blob, "wifi0");
7376
if (node < 0) {
7477
printf("WARNING: can't find wifi0 alias\n");
7578
return -1;

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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#define MAC_ADDR_LEN 6
12+
13+
#ifdef CONFIG_WINBOND_OTP
14+
15+
#include <linux/types.h>
16+
17+
#define VERSION_REG0_OFFSET 0x1002
18+
#define VERSION_REG1_OFFSET 0x2002
19+
#define WIFI_STA_MAC_ADDRESS_OFFSET 0x1003
20+
#define WIFI_AP_MAC_ADDRESS_OFFSET 0x1009
21+
#define ETH_MAC_ADDRESS_OFFSET 0x1015
22+
#define DCXO_OFFSET 0x2003
23+
24+
/*
25+
* check_otp_version: Check version register from OTP
26+
* @offset: Offset of the register in the OTP.
27+
*
28+
* returns:
29+
* 0 if the version is equal to 1
30+
* -1 otherwise
31+
*/
32+
int check_otp_version(loff_t offset);
33+
34+
#endif
35+
36+
#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))

include/winbond-otp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#ifndef WINBOND_OTP_H
99
#define WINBOND_OTP_H
1010

11-
#define MAC_ADDR_LEN 6
12-
1311
int read_otp_data(loff_t from, size_t len, char *data);
1412

1513
#endif

0 commit comments

Comments
 (0)