otp.c (a219f6de7376d4001dcf72d318c34a2f6a516b5a) | otp.c (e14b073c2abd86bd2233fac84e6cb9aee2e20425) |
---|---|
1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * Copyright 2021 Aspeed Technology Inc. 4 */ 5#include <stdlib.h> 6#include <common.h> 7#include <console.h> 8#include <bootretry.h> --- 1936 unchanged lines hidden (view full) --- 1945 otp_print_strap_info(view); 1946 } else { 1947 return CMD_RET_USAGE; 1948 } 1949 1950 return CMD_RET_SUCCESS; 1951} 1952 | 1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * Copyright 2021 Aspeed Technology Inc. 4 */ 5#include <stdlib.h> 6#include <common.h> 7#include <console.h> 8#include <bootretry.h> --- 1936 unchanged lines hidden (view full) --- 1945 otp_print_strap_info(view); 1946 } else { 1947 return CMD_RET_USAGE; 1948 } 1949 1950 return CMD_RET_SUCCESS; 1951} 1952 |
1953static int do_otpprotect(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | 1953static int _do_otpprotect(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[], int preg) |
1954{ 1955 int input; 1956 int bit_offset; | 1954{ 1955 int input; 1956 int bit_offset; |
1957 int prog_address; | 1957 u32 prog_address; |
1958 int ret; | 1958 int ret; |
1959 char info[10]; |
|
1959 | 1960 |
1961 if (preg) { 1962 sprintf(info, "register "); 1963 prog_address = 0xe08; 1964 } else { 1965 info[0] = 0; 1966 prog_address = 0xe0c; 1967 } 1968 |
|
1960 if (argc != 3 && argc != 2) 1961 return CMD_RET_USAGE; 1962 | 1969 if (argc != 3 && argc != 2) 1970 return CMD_RET_USAGE; 1971 |
1963 if (!strcmp(argv[0], "o")) { | 1972 if (!strcmp(argv[1], "o")) { |
1964 input = simple_strtoul(argv[2], NULL, 16); 1965 } else { 1966 input = simple_strtoul(argv[1], NULL, 16); | 1973 input = simple_strtoul(argv[2], NULL, 16); 1974 } else { 1975 input = simple_strtoul(argv[1], NULL, 16); |
1967 printf("OTPSTRAP[%d] will be protected\n", input); | 1976 printf("OTPSTRAP[%d] %swill be protected\n", input, info); |
1968 printf("type \"YES\" (no quotes) to continue:\n"); 1969 if (!confirm_yesno()) { 1970 printf(" Aborting\n"); 1971 return CMD_RET_FAILURE; 1972 } 1973 } 1974 | 1977 printf("type \"YES\" (no quotes) to continue:\n"); 1978 if (!confirm_yesno()) { 1979 printf(" Aborting\n"); 1980 return CMD_RET_FAILURE; 1981 } 1982 } 1983 |
1975 prog_address = 0x800; | |
1976 if (input < 32) { 1977 bit_offset = input; | 1984 if (input < 32) { 1985 bit_offset = input; |
1978 prog_address |= 0x60c; | |
1979 } else if (input < 64) { 1980 bit_offset = input - 32; | 1986 } else if (input < 64) { 1987 bit_offset = input - 32; |
1981 prog_address |= 0x60e; | 1988 prog_address += 2; |
1982 } else { 1983 return CMD_RET_USAGE; 1984 } 1985 | 1989 } else { 1990 return CMD_RET_USAGE; 1991 } 1992 |
1986 if (verify_bit(prog_address, bit_offset, 1) == 0) 1987 printf("OTPSTRAP[%d] already protected\n", input); | 1993 writel(OTP_PASSWD, OTP_PROTECT_KEY); //password 1994 if (verify_bit(prog_address, bit_offset, 1) == 0) { 1995 printf("OTPSTRAP[%d] %salready protected\n", input, info); 1996 return CMD_RET_SUCCESS; 1997 } |
1988 1989 ret = otp_prog_bit(1, prog_address, bit_offset); 1990 otp_soak(0); 1991 1992 if (ret) { | 1998 1999 ret = otp_prog_bit(1, prog_address, bit_offset); 2000 otp_soak(0); 2001 2002 if (ret) { |
1993 printf("OTPSTRAP[%d] is protected\n", input); | 2003 printf("OTPSTRAP[%d] %sis protected\n", input, info); |
1994 return CMD_RET_SUCCESS; 1995 } 1996 | 2004 return CMD_RET_SUCCESS; 2005 } 2006 |
1997 printf("Protect OTPSTRAP[%d] fail\n", input); | 2007 printf("Protect OTPSTRAP[%d] %sfail\n", input, info); |
1998 return CMD_RET_FAILURE; 1999} 2000 | 2008 return CMD_RET_FAILURE; 2009} 2010 |
2011static int do_otpprotect(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) 2012{ 2013 return _do_otpprotect(cmdtp, flag, argc, argv, 0); 2014} 2015 2016static int do_otprprotect(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) 2017{ 2018 return _do_otpprotect(cmdtp, flag, argc, argv, 1); 2019} 2020 |
|
2001static int do_otpver(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) 2002{ 2003 printf("OTP tool version: %s\n", OTP_VER); 2004 printf("OTP info version: %s\n", OTP_INFO_VER); 2005 2006 return CMD_RET_SUCCESS; 2007} 2008 2009static cmd_tbl_t cmd_otp[] = { 2010 U_BOOT_CMD_MKENT(version, 1, 0, do_otpver, "", ""), 2011 U_BOOT_CMD_MKENT(read, 4, 0, do_otpread, "", ""), 2012 U_BOOT_CMD_MKENT(info, 3, 0, do_otpinfo, "", ""), 2013 U_BOOT_CMD_MKENT(prog, 3, 0, do_otpprog, "", ""), 2014 U_BOOT_CMD_MKENT(pb, 6, 0, do_otppb, "", ""), 2015 U_BOOT_CMD_MKENT(protect, 3, 0, do_otpprotect, "", ""), | 2021static int do_otpver(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) 2022{ 2023 printf("OTP tool version: %s\n", OTP_VER); 2024 printf("OTP info version: %s\n", OTP_INFO_VER); 2025 2026 return CMD_RET_SUCCESS; 2027} 2028 2029static cmd_tbl_t cmd_otp[] = { 2030 U_BOOT_CMD_MKENT(version, 1, 0, do_otpver, "", ""), 2031 U_BOOT_CMD_MKENT(read, 4, 0, do_otpread, "", ""), 2032 U_BOOT_CMD_MKENT(info, 3, 0, do_otpinfo, "", ""), 2033 U_BOOT_CMD_MKENT(prog, 3, 0, do_otpprog, "", ""), 2034 U_BOOT_CMD_MKENT(pb, 6, 0, do_otppb, "", ""), 2035 U_BOOT_CMD_MKENT(protect, 3, 0, do_otpprotect, "", ""), |
2036 U_BOOT_CMD_MKENT(rprotect, 3, 0, do_otprprotect, "", ""), |
|
2016 U_BOOT_CMD_MKENT(cmp, 3, 0, do_otpcmp, "", ""), 2017}; 2018 2019static int do_ast_otp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) 2020{ 2021 cmd_tbl_t *cp; 2022 u32 ver; | 2037 U_BOOT_CMD_MKENT(cmp, 3, 0, do_otpcmp, "", ""), 2038}; 2039 2040static int do_ast_otp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) 2041{ 2042 cmd_tbl_t *cp; 2043 u32 ver; |
2044 int ret; |
|
2023 2024 cp = find_cmd_tbl(argv[1], cmd_otp, ARRAY_SIZE(cmd_otp)); 2025 2026 /* Drop the otp command */ 2027 argc--; 2028 argv++; 2029 2030 if (!cp || argc > cp->maxargs) --- 39 unchanged lines hidden (view full) --- 2070 info_cb.key_info = a3_key_type; 2071 info_cb.key_info_len = ARRAY_SIZE(a3_key_type); 2072 break; 2073 default: 2074 printf("SOC is not supported\n"); 2075 return CMD_RET_FAILURE; 2076 } 2077 | 2045 2046 cp = find_cmd_tbl(argv[1], cmd_otp, ARRAY_SIZE(cmd_otp)); 2047 2048 /* Drop the otp command */ 2049 argc--; 2050 argv++; 2051 2052 if (!cp || argc > cp->maxargs) --- 39 unchanged lines hidden (view full) --- 2092 info_cb.key_info = a3_key_type; 2093 info_cb.key_info_len = ARRAY_SIZE(a3_key_type); 2094 break; 2095 default: 2096 printf("SOC is not supported\n"); 2097 return CMD_RET_FAILURE; 2098 } 2099 |
2078 return cp->cmd(cmdtp, flag, argc, argv); | 2100 ret = cp->cmd(cmdtp, flag, argc, argv); 2101 writel(1, OTP_PROTECT_KEY); //password 2102 2103 return ret; |
2079} 2080 2081U_BOOT_CMD(otp, 7, 0, do_ast_otp, 2082 "ASPEED One-Time-Programmable sub-system", 2083 "version\n" 2084 "otp read conf|data <otp_dw_offset> <dw_count>\n" 2085 "otp read strap <strap_bit_offset> <bit_count>\n" 2086 "otp info strap [v]\n" 2087 "otp info conf [otp_dw_offset]\n" 2088 "otp prog [o] <addr>\n" 2089 "otp pb conf|data [o] <otp_dw_offset> <bit_offset> <value>\n" 2090 "otp pb strap [o] <bit_offset> <value>\n" 2091 "otp protect [o] <bit_offset>\n" | 2104} 2105 2106U_BOOT_CMD(otp, 7, 0, do_ast_otp, 2107 "ASPEED One-Time-Programmable sub-system", 2108 "version\n" 2109 "otp read conf|data <otp_dw_offset> <dw_count>\n" 2110 "otp read strap <strap_bit_offset> <bit_count>\n" 2111 "otp info strap [v]\n" 2112 "otp info conf [otp_dw_offset]\n" 2113 "otp prog [o] <addr>\n" 2114 "otp pb conf|data [o] <otp_dw_offset> <bit_offset> <value>\n" 2115 "otp pb strap [o] <bit_offset> <value>\n" 2116 "otp protect [o] <bit_offset>\n" |
2117 "otp rprotect [o] <bit_offset>\n" |
|
2092 "otp cmp <addr> <otp_dw_offset>\n" 2093 ); | 2118 "otp cmp <addr> <otp_dw_offset>\n" 2119 ); |