1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
10 #include <dm/device.h>
11 #include <dm/uclass.h>
13 #define STM32_OTP_HASH_KEY_START 24
14 #define STM32_OTP_HASH_KEY_SIZE 8
16 static void read_hash_value(u32 addr)
20 for (i = 0; i < STM32_OTP_HASH_KEY_SIZE; i++) {
21 printf("OTP value %i: %x\n", STM32_OTP_HASH_KEY_START + i,
22 __be32_to_cpu(*(u32 *)addr));
27 static void fuse_hash_value(u32 addr, bool print)
33 ret = uclass_get_device_by_driver(UCLASS_MISC,
34 DM_GET_DRIVER(stm32mp_bsec),
37 pr_err("Can't find stm32mp_bsec driver\n");
41 for (i = 0; i < STM32_OTP_HASH_KEY_SIZE; i++) {
43 printf("Fuse OTP %i : %x\n",
44 STM32_OTP_HASH_KEY_START + i,
45 __be32_to_cpu(*(u32 *)addr));
47 word = STM32_OTP_HASH_KEY_START + i;
48 val = __be32_to_cpu(*(u32 *)addr);
49 misc_write(dev, STM32_BSEC_OTP(word), &val, 4);
55 static int confirm_prog(void)
57 puts("Warning: Programming fuses is an irreversible operation!\n"
58 " This may brick your system.\n"
59 " Use this command only if you are sure of what you are doing!\n"
60 "\nReally perform this fuse programming? <y/N>\n");
65 puts("Fuse programming aborted\n");
69 static int do_stm32key(cmd_tbl_t *cmdtp, int flag, int argc,
73 const char *op = argc >= 2 ? argv[1] : NULL;
74 int confirmed = argc > 3 && !strcmp(argv[2], "-y");
76 argc -= 2 + confirmed;
77 argv += 2 + confirmed;
82 addr = simple_strtoul(argv[0], NULL, 16);
86 if (!strcmp(op, "read"))
87 read_hash_value(addr);
89 if (!strcmp(op, "fuse")) {
90 if (!confirmed && !confirm_prog())
91 return CMD_RET_FAILURE;
92 fuse_hash_value(addr, !confirmed);
95 return CMD_RET_SUCCESS;
98 U_BOOT_CMD(stm32key, 4, 1, do_stm32key,
100 "read <addr>: Read the hash store at addr in memory\n"
101 "stm32key fuse [-y] <addr> : Fuse hash store at addr in otp\n");