From: Patrick Delaunay Date: Mon, 13 Jan 2020 14:17:40 +0000 (+0100) Subject: stm32mp1: move stboard command in board/st/common directory X-Git-Tag: v2020.04-rc1~14^2~4 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ba2c20ce7aba106d0101e04910be64fe3f855096;p=oweals%2Fu-boot.git stm32mp1: move stboard command in board/st/common directory Move the ST command in board/st/common, as this command is only used by ST board. Prepare the support in U-Boot of boards with STM32MP15x SOC but not STMicroelectronics. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- diff --git a/board/st/common/Kconfig b/board/st/common/Kconfig new file mode 100644 index 0000000000..1824087afc --- /dev/null +++ b/board/st/common/Kconfig @@ -0,0 +1,6 @@ +config CMD_STBOARD + bool "stboard - command for OTP board information" + default y + help + This compile the stboard command to + read and write the board in the OTP. diff --git a/board/st/common/MAINTAINERS b/board/st/common/MAINTAINERS new file mode 100644 index 0000000000..3b02f4ab98 --- /dev/null +++ b/board/st/common/MAINTAINERS @@ -0,0 +1,6 @@ +ST BOARDS +M: Patrick Delaunay +L: uboot-stm32@st-md-mailman.stormreply.com (moderated for non-subscribers) +T: git https://gitlab.denx.de/u-boot/custodians/u-boot-stm.git +S: Maintained +F: board/st/common/ diff --git a/board/st/common/Makefile b/board/st/common/Makefile new file mode 100644 index 0000000000..8553606b90 --- /dev/null +++ b/board/st/common/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +# +# Copyright (C) 2020, STMicroelectronics - All Rights Reserved +# + +obj-$(CONFIG_CMD_STBOARD) += cmd_stboard.o diff --git a/board/st/common/cmd_stboard.c b/board/st/common/cmd_stboard.c new file mode 100644 index 0000000000..e994a88e71 --- /dev/null +++ b/board/st/common/cmd_stboard.c @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +/* + * Copyright (C) 2019, STMicroelectronics - All Rights Reserved + */ + +#ifndef CONFIG_SPL_BUILD +#include +#include +#include +#include +#include + +static bool check_stboard(u16 board) +{ + unsigned int i; + const u16 st_board_id[] = { + 0x1272, + 0x1263, + 0x1264, + 0x1298, + 0x1341, + 0x1497, + }; + + 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) +{ + printf("Board: MB%04x Var%d Rev.%c-%02d\n", + otp >> 16, + (otp >> 12) & 0xF, + ((otp >> 8) & 0xF) - 1 + 'A', + otp & 0xF); +} + +static int do_stboard(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + int ret; + u32 otp; + u8 revision; + unsigned long board, variant, bom; + struct udevice *dev; + int confirmed = argc == 6 && !strcmp(argv[1], "-y"); + + argc -= 1 + confirmed; + argv += 1 + confirmed; + + if (argc != 0 && argc != 4) + return CMD_RET_USAGE; + + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_GET_DRIVER(stm32mp_bsec), + &dev); + + ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD), + &otp, sizeof(otp)); + + if (ret < 0) { + puts("OTP read error"); + return CMD_RET_FAILURE; + } + + if (argc == 0) { + if (!otp) + puts("Board : OTP board FREE\n"); + else + display_stboard(otp); + 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; + } + + if (strict_strtoul(argv[1], 10, &variant) < 0 || + variant == 0 || variant > 15) { + 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; + } + + if (strict_strtoul(argv[3], 10, &bom) < 0 || + bom == 0 || bom > 15) { + printf("argument %d invalid: %s\n", 4, argv[3]); + return CMD_RET_USAGE; + } + + otp = (board << 16) | (variant << 12) | (revision << 8) | bom; + 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? \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)); + + if (ret) { + puts("BOARD programming error\n"); + return CMD_RET_FAILURE; + } + puts("BOARD programming done\n"); + + return CMD_RET_SUCCESS; +} + +U_BOOT_CMD(stboard, 6, 0, do_stboard, + "read/write board reference in OTP", + "\n" + " Print current board information\n" + "stboard [-y] \n" + " Write board information\n" + " - Board: xxxx, example 1264 for MB1264\n" + " - Variant: 1 ... 15\n" + " - Revision: A...O\n" + " - BOM: 1...15\n"); + +#endif diff --git a/board/st/stm32mp1/Kconfig b/board/st/stm32mp1/Kconfig index 4fa2360b4f..9f985e5775 100644 --- a/board/st/stm32mp1/Kconfig +++ b/board/st/stm32mp1/Kconfig @@ -15,15 +15,10 @@ config ENV_SECT_SIZE config ENV_OFFSET default 0x280000 if ENV_IS_IN_SPI_FLASH -config CMD_STBOARD - bool "stboard - command for OTP board information" - default y - help - This compile the stboard command to - read and write the board in the OTP. - config TARGET_STM32MP157C_DK2 bool "support of STMicroelectronics STM32MP157C-DK2 Discovery Board" default y +source "board/st/common/Kconfig" + endif diff --git a/board/st/stm32mp1/Makefile b/board/st/stm32mp1/Makefile index 3c6c035b11..8188075b1a 100644 --- a/board/st/stm32mp1/Makefile +++ b/board/st/stm32mp1/Makefile @@ -7,7 +7,6 @@ ifdef CONFIG_SPL_BUILD obj-y += spl.o else obj-y += stm32mp1.o -obj-$(CONFIG_CMD_STBOARD) += cmd_stboard.o endif obj-y += board.o diff --git a/board/st/stm32mp1/cmd_stboard.c b/board/st/stm32mp1/cmd_stboard.c deleted file mode 100644 index 04352ae8ed..0000000000 --- a/board/st/stm32mp1/cmd_stboard.c +++ /dev/null @@ -1,145 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause -/* - * Copyright (C) 2019, STMicroelectronics - All Rights Reserved - */ - -#include -#include -#include -#include -#include - -static bool check_stboard(u16 board) -{ - unsigned int i; - const u16 st_board_id[] = { - 0x1272, - 0x1263, - 0x1264, - 0x1298, - 0x1341, - 0x1497, - }; - - 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) -{ - printf("Board: MB%04x Var%d Rev.%c-%02d\n", - otp >> 16, - (otp >> 12) & 0xF, - ((otp >> 8) & 0xF) - 1 + 'A', - otp & 0xF); -} - -static int do_stboard(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) -{ - int ret; - u32 otp; - u8 revision; - unsigned long board, variant, bom; - struct udevice *dev; - int confirmed = argc == 6 && !strcmp(argv[1], "-y"); - - argc -= 1 + confirmed; - argv += 1 + confirmed; - - if (argc != 0 && argc != 4) - return CMD_RET_USAGE; - - ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), - &dev); - - ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD), - &otp, sizeof(otp)); - - if (ret < 0) { - puts("OTP read error"); - return CMD_RET_FAILURE; - } - - if (argc == 0) { - if (!otp) - puts("Board : OTP board FREE\n"); - else - display_stboard(otp); - 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; - } - - if (strict_strtoul(argv[1], 10, &variant) < 0 || - variant == 0 || variant > 15) { - 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; - } - - if (strict_strtoul(argv[3], 10, &bom) < 0 || - bom == 0 || bom > 15) { - printf("argument %d invalid: %s\n", 4, argv[3]); - return CMD_RET_USAGE; - } - - otp = (board << 16) | (variant << 12) | (revision << 8) | bom; - 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? \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)); - - if (ret) { - puts("BOARD programming error\n"); - return CMD_RET_FAILURE; - } - puts("BOARD programming done\n"); - - return CMD_RET_SUCCESS; -} - -U_BOOT_CMD(stboard, 6, 0, do_stboard, - "read/write board reference in OTP", - "\n" - " Print current board information\n" - "stboard [-y] \n" - " Write board information\n" - " - Board: xxxx, example 1264 for MB1264\n" - " - Variant: 1 ... 15\n" - " - Revision: A...O\n" - " - BOM: 1...15\n");