Skip to content

Commit cb96f2b

Browse files
committed
stm32mp1: use device tree to determine board_id OTP
This OTP is filled only for STMicroelectronics boards, therefore the BSEC device tree node for this should be moved to boards DTS files. The function that displays this information is also reworked to use this device tree information and macros. A potential bug is also corrected to avoid non-null terminated string. Change-Id: Ie4f268a4afff8cc3d63eb7ea31b4f44c8f488267 Signed-off-by: Yann Gautier <yann.gautier@st.com> Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/tf-a/+/133034 Reviewed-by: CITOOLS <smet-aci-reviews@lists.codex.cro.st.com> Reviewed-by: CIBUILD <smet-aci-builds@lists.codex.cro.st.com> Reviewed-by: Lionel DEBIEVE <lionel.debieve@st.com>
1 parent ddd5be1 commit cb96f2b

5 files changed

+71
-15
lines changed

fdts/stm32mp157a-dk1.dts

+8
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@
306306
};
307307

308308
/* Security specific */
309+
&bsec {
310+
board_id: board_id@ec {
311+
reg = <0xec 0x4>;
312+
status = "okay";
313+
secure-status = "okay";
314+
};
315+
};
316+
309317
&etzpc {
310318
st,decprot = <
311319
DECPROT(STM32MP1_ETZPC_USART1_ID, DECPROT_NS_RW, DECPROT_UNLOCK)

fdts/stm32mp157c-ed1.dts

+8
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@
311311
};
312312

313313
/* Security specific */
314+
&bsec {
315+
board_id: board_id@ec {
316+
reg = <0xec 0x4>;
317+
status = "okay";
318+
secure-status = "okay";
319+
};
320+
};
321+
314322
&etzpc {
315323
st,decprot = <
316324
DECPROT(STM32MP1_ETZPC_USART1_ID, DECPROT_NS_RW, DECPROT_UNLOCK)

fdts/stm32mp157c-security.dtsi

-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
spare_ns_ea: spare_ns_ea@ea {
4242
reg = <0xea 0x2>;
4343
};
44-
board_id: board_id@ec {
45-
reg = <0xec 0x4>;
46-
};
4744
};
4845

4946
&iwdg2 {

plat/st/stm32mp1/stm32mp1_def.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ enum ddr_type {
374374
#define UID2_OTP U(15)
375375
#define PACKAGE_OTP U(16)
376376
#define HW2_OTP U(18) /* HW watchdog OTP */
377-
#define BOARD_OTP U(59)
378377

379378
/* OTP mask */
380379
/* DATA0 */
@@ -531,6 +530,7 @@ static inline uint32_t tamp_bkpr(uint32_t idx)
531530
/*******************************************************************************
532531
* Device Tree defines
533532
******************************************************************************/
533+
#define DT_BSEC_COMPAT "st,stm32mp15-bsec"
534534
#define DT_PWR_COMPAT "st,stm32mp1-pwr"
535535
#define DT_RCC_CLK_COMPAT "st,stm32mp1-rcc"
536536
#define DT_SYSCFG_COMPAT "st,stm32mp157-syscfg"

plat/st/stm32mp1/stm32mp1_private.c

+54-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
2+
* Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
@@ -17,6 +17,23 @@
1717
#include <stm32mp_dt.h>
1818
#include <xlat_tables_v2.h>
1919

20+
/* Internal layout of the 32bit OTP word board_id */
21+
#define BOARD_ID_BOARD_NB_MASK GENMASK(31, 16)
22+
#define BOARD_ID_BOARD_NB_SHIFT 16
23+
#define BOARD_ID_VARIANT_MASK GENMASK(15, 12)
24+
#define BOARD_ID_VARIANT_SHIFT 12
25+
#define BOARD_ID_REVISION_MASK GENMASK(11, 8)
26+
#define BOARD_ID_REVISION_SHIFT 8
27+
#define BOARD_ID_BOM_MASK GENMASK(3, 0)
28+
29+
#define BOARD_ID2NB(_id) (((_id) & BOARD_ID_BOARD_NB_MASK) >> \
30+
BOARD_ID_BOARD_NB_SHIFT)
31+
#define BOARD_ID2VAR(_id) (((_id) & BOARD_ID_VARIANT_MASK) >> \
32+
BOARD_ID_VARIANT_SHIFT)
33+
#define BOARD_ID2REV(_id) (((_id) & BOARD_ID_REVISION_MASK) >> \
34+
BOARD_ID_REVISION_SHIFT)
35+
#define BOARD_ID2BOM(_id) ((_id) & BOARD_ID_BOM_MASK)
36+
2037
#define MAP_ROM MAP_REGION_FLAT(STM32MP_ROM_BASE, \
2138
STM32MP_ROM_SIZE, \
2239
MT_MEMORY | \
@@ -237,23 +254,49 @@ void stm32mp_print_cpuinfo(void)
237254

238255
void stm32mp_print_boardinfo(void)
239256
{
240-
uint32_t board;
241-
int res = 0;
257+
uint32_t board_id = 0;
258+
uint32_t board_otp;
259+
int bsec_node, bsec_board_id_node;
260+
void *fdt;
261+
const fdt32_t *cuint;
262+
263+
if (fdt_get_address(&fdt) == 0) {
264+
panic();
265+
}
266+
267+
bsec_node = fdt_node_offset_by_compatible(fdt, -1, DT_BSEC_COMPAT);
268+
if (bsec_node < 0) {
269+
return;
270+
}
271+
272+
bsec_board_id_node = fdt_subnode_offset(fdt, bsec_node, "board_id");
273+
if (bsec_board_id_node <= 0) {
274+
return;
275+
}
276+
277+
cuint = fdt_getprop(fdt, bsec_board_id_node, "reg", NULL);
278+
if (cuint == NULL) {
279+
ERROR("board_id node without reg property\n");
280+
panic();
281+
}
282+
283+
board_otp = fdt32_to_cpu(*cuint) / sizeof(uint32_t);
242284

243-
if (bsec_shadow_read_otp(&board, BOARD_OTP) != BSEC_OK) {
285+
if (bsec_shadow_read_otp(&board_id, board_otp) != BSEC_OK) {
244286
ERROR("BSEC: PART_NUMBER_OTP Error\n");
245-
res = -1;
287+
return;
246288
}
247289

248-
if ((res == 0) && (board != 0U)) {
249-
char rev[1];
290+
if (board_id != 0U) {
291+
char rev[2];
250292

251-
*rev = ((board >> 8) & 0xF) - 1 + 'A';
293+
rev[0] = BOARD_ID2REV(board_id) - 1 + 'A';
294+
rev[1] = '\0';
252295
NOTICE("Board: MB%04x Var%d Rev.%s-%02d\n",
253-
board >> 16,
254-
(board >> 12) & 0xF,
296+
BOARD_ID2NB(board_id),
297+
BOARD_ID2VAR(board_id),
255298
rev,
256-
board & 0xF);
299+
BOARD_ID2BOM(board_id));
257300
}
258301
}
259302

0 commit comments

Comments
 (0)