2019-07-05 15:20:16 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019, STMicroelectronics - All Rights Reserved
|
2020-03-24 08:05:00 +00:00
|
|
|
*
|
2023-01-06 12:20:18 +00:00
|
|
|
* the command stboard supports the STMicroelectronics board identification
|
|
|
|
* saved in OTP_BOARD.
|
2020-03-24 08:05:00 +00:00
|
|
|
*
|
|
|
|
* The ST product codification have several element
|
|
|
|
* - "Commercial Product Name" (CPN): type of product board (DKX, EVX)
|
|
|
|
* associated to the board ID "MBxxxx"
|
|
|
|
* - "Finished Good" or "Finish Good" (FG):
|
|
|
|
* effective content of the product without chip STM32MP1xx (LCD, Wifi,…)
|
|
|
|
* - BOM: cost variant for same FG (for example, several provider of the same
|
|
|
|
* component)
|
|
|
|
*
|
|
|
|
* For example
|
|
|
|
* - commercial product = STM32MP157C-EV1 for board MB1263
|
|
|
|
* - Finished Good = EVA32MP157A1$AU1
|
|
|
|
*
|
|
|
|
* Both information are written on board and these information are also saved
|
2023-01-06 12:20:18 +00:00
|
|
|
* in OTP_BOARD (59 for STM32MP15x or 60 for STM32MP13x), with:
|
2020-03-24 08:05:00 +00:00
|
|
|
* bit [31:16] (hex) => Board id, MBxxxx
|
|
|
|
* bit [15:12] (dec) => Variant CPN (1....15)
|
|
|
|
* bit [11:8] (dec) => Revision board (index with A = 1, Z = 26)
|
|
|
|
* bit [7:4] (dec) => Variant FG : finished good index
|
|
|
|
* bit [3:0] (dec) => BOM (01, .... 255)
|
|
|
|
*
|
|
|
|
* and displayed with the format:
|
|
|
|
* Board: MB<Board> Var<VarCPN>.<VarFG> Rev.<Revision>-<BOM>
|
2019-07-05 15:20:16 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-13 14:17:40 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
2019-07-05 15:20:16 +00:00
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2019-07-05 15:20:16 +00:00
|
|
|
#include <console.h>
|
|
|
|
#include <misc.h>
|
2023-01-06 12:20:15 +00:00
|
|
|
#include <asm/arch/bsec.h>
|
2019-07-05 15:20:16 +00:00
|
|
|
#include <dm/device.h>
|
|
|
|
#include <dm/uclass.h>
|
|
|
|
|
|
|
|
static bool check_stboard(u16 board)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2020-03-24 08:05:00 +00:00
|
|
|
/* list of supported ST boards */
|
2019-07-05 15:20:16 +00:00
|
|
|
const u16 st_board_id[] = {
|
|
|
|
0x1272,
|
|
|
|
0x1263,
|
|
|
|
0x1264,
|
|
|
|
0x1298,
|
|
|
|
0x1341,
|
|
|
|
0x1497,
|
2023-01-06 12:20:18 +00:00
|
|
|
0x1635,
|
2019-07-05 15:20:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(st_board_id); i++)
|
|
|
|
if (board == st_board_id[i])
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_stboard(u32 otp)
|
|
|
|
{
|
2020-03-24 08:05:00 +00:00
|
|
|
/* display board indentification with OPT coding */
|
|
|
|
printf("Board: MB%04x Var%d.%d Rev.%c-%02d\n",
|
2019-07-05 15:20:16 +00:00
|
|
|
otp >> 16,
|
|
|
|
(otp >> 12) & 0xF,
|
2020-03-24 08:05:00 +00:00
|
|
|
(otp >> 4) & 0xF,
|
2019-07-05 15:20:16 +00:00
|
|
|
((otp >> 8) & 0xF) - 1 + 'A',
|
|
|
|
otp & 0xF);
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_stboard(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2019-07-05 15:20:16 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2020-02-12 18:37:39 +00:00
|
|
|
u32 otp, lock;
|
2019-07-05 15:20:16 +00:00
|
|
|
u8 revision;
|
2020-03-24 08:05:00 +00:00
|
|
|
unsigned long board, var_cpn, var_fg, bom;
|
2019-07-05 15:20:16 +00:00
|
|
|
struct udevice *dev;
|
2020-03-24 08:05:00 +00:00
|
|
|
int confirmed = argc == 7 && !strcmp(argv[1], "-y");
|
2019-07-05 15:20:16 +00:00
|
|
|
|
|
|
|
argc -= 1 + confirmed;
|
|
|
|
argv += 1 + confirmed;
|
|
|
|
|
2020-03-24 08:05:00 +00:00
|
|
|
if (argc != 0 && argc != 5)
|
2019-07-05 15:20:16 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_MISC,
|
2020-12-29 03:34:56 +00:00
|
|
|
DM_DRIVER_GET(stm32mp_bsec),
|
2019-07-05 15:20:16 +00:00
|
|
|
&dev);
|
|
|
|
|
2020-02-12 18:37:36 +00:00
|
|
|
ret = misc_read(dev, STM32_BSEC_OTP(BSEC_OTP_BOARD),
|
2019-07-05 15:20:16 +00:00
|
|
|
&otp, sizeof(otp));
|
|
|
|
|
2022-02-01 13:37:19 +00:00
|
|
|
if (ret != sizeof(otp)) {
|
2022-04-15 09:46:50 +00:00
|
|
|
puts("OTP read error\n");
|
2019-07-05 15:20:16 +00:00
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-02-12 18:37:39 +00:00
|
|
|
ret = misc_read(dev, STM32_BSEC_LOCK(BSEC_OTP_BOARD),
|
|
|
|
&lock, sizeof(lock));
|
2022-02-01 13:37:19 +00:00
|
|
|
if (ret != sizeof(lock)) {
|
2022-04-15 09:46:50 +00:00
|
|
|
puts("LOCK read error\n");
|
2020-02-12 18:37:39 +00:00
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-07-05 15:20:16 +00:00
|
|
|
if (argc == 0) {
|
|
|
|
if (!otp)
|
|
|
|
puts("Board : OTP board FREE\n");
|
|
|
|
else
|
|
|
|
display_stboard(otp);
|
2020-02-12 18:37:39 +00:00
|
|
|
printf(" OTP %d %s locked !\n", BSEC_OTP_BOARD,
|
2023-01-06 12:20:15 +00:00
|
|
|
lock & BSEC_LOCK_PERM ? "" : "NOT");
|
2019-07-05 15:20:16 +00:00
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (otp) {
|
|
|
|
display_stboard(otp);
|
|
|
|
printf("ERROR: OTP board not FREE\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strict_strtoul(argv[0], 16, &board) < 0 ||
|
|
|
|
board == 0 || board > 0xFFFF) {
|
|
|
|
printf("argument %d invalid: %s\n", 1, argv[0]);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
2020-03-24 08:05:00 +00:00
|
|
|
if (strict_strtoul(argv[1], 10, &var_cpn) < 0 ||
|
|
|
|
var_cpn == 0 || var_cpn > 15) {
|
2019-07-05 15:20:16 +00:00
|
|
|
printf("argument %d invalid: %s\n", 2, argv[1]);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
revision = argv[2][0] - 'A' + 1;
|
|
|
|
if (strlen(argv[2]) > 1 || revision == 0 || revision > 15) {
|
|
|
|
printf("argument %d invalid: %s\n", 3, argv[2]);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
2020-03-24 08:05:00 +00:00
|
|
|
if (strict_strtoul(argv[3], 10, &var_fg) < 0 ||
|
|
|
|
var_fg > 15) {
|
|
|
|
printf("argument %d invalid: %s\n", 4, argv[3]);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strict_strtoul(argv[4], 10, &bom) < 0 ||
|
2019-07-05 15:20:16 +00:00
|
|
|
bom == 0 || bom > 15) {
|
|
|
|
printf("argument %d invalid: %s\n", 4, argv[3]);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
2020-03-24 08:05:00 +00:00
|
|
|
/* st board indentification value */
|
|
|
|
otp = (board << 16) | (var_cpn << 12) | (revision << 8) |
|
|
|
|
(var_fg << 4) | bom;
|
2019-07-05 15:20:16 +00:00
|
|
|
display_stboard(otp);
|
|
|
|
printf("=> OTP[%d] = %08X\n", BSEC_OTP_BOARD, otp);
|
|
|
|
|
|
|
|
if (!check_stboard((u16)board)) {
|
|
|
|
printf("Unknown board MB%04x\n", (u16)board);
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
if (!confirmed) {
|
|
|
|
printf("Warning: Programming BOARD in OTP is irreversible!\n");
|
|
|
|
printf("Really perform this OTP programming? <y/N>\n");
|
|
|
|
|
|
|
|
if (!confirm_yesno()) {
|
|
|
|
puts("BOARD programming aborted\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = misc_write(dev, STM32_BSEC_OTP(BSEC_OTP_BOARD),
|
|
|
|
&otp, sizeof(otp));
|
|
|
|
|
2022-02-01 13:37:19 +00:00
|
|
|
if (ret != sizeof(otp)) {
|
2019-07-05 15:20:16 +00:00
|
|
|
puts("BOARD programming error\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
2020-02-12 18:37:39 +00:00
|
|
|
|
|
|
|
/* write persistent lock */
|
2023-01-06 12:20:15 +00:00
|
|
|
otp = BSEC_LOCK_PERM;
|
2020-02-12 18:37:39 +00:00
|
|
|
ret = misc_write(dev, STM32_BSEC_LOCK(BSEC_OTP_BOARD),
|
|
|
|
&otp, sizeof(otp));
|
2022-02-01 13:37:19 +00:00
|
|
|
if (ret != sizeof(otp)) {
|
2020-02-12 18:37:39 +00:00
|
|
|
puts("BOARD lock error\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-07-05 15:20:16 +00:00
|
|
|
puts("BOARD programming done\n");
|
|
|
|
|
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-03-24 08:05:00 +00:00
|
|
|
U_BOOT_CMD(stboard, 7, 0, do_stboard,
|
2019-07-05 15:20:16 +00:00
|
|
|
"read/write board reference in OTP",
|
|
|
|
"\n"
|
|
|
|
" Print current board information\n"
|
2020-03-24 08:05:00 +00:00
|
|
|
"stboard [-y] <Board> <VarCPN> <Revision> <VarFG> <BOM>\n"
|
2019-07-05 15:20:16 +00:00
|
|
|
" Write board information\n"
|
|
|
|
" - Board: xxxx, example 1264 for MB1264\n"
|
2020-03-24 08:05:00 +00:00
|
|
|
" - VarCPN: 1...15\n"
|
2019-07-05 15:20:16 +00:00
|
|
|
" - Revision: A...O\n"
|
2020-03-24 08:05:00 +00:00
|
|
|
" - VarFG: 0...15\n"
|
2019-07-05 15:20:16 +00:00
|
|
|
" - BOM: 1...15\n");
|
2020-01-13 14:17:40 +00:00
|
|
|
|
|
|
|
#endif
|