Lines Matching +full:otp +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0+
19 #include <u-boot/sha256.h>
20 #include <u-boot/sha512.h>
21 #include <u-boot/rsa.h>
22 #include <u-boot/rsa-mod-exp.h>
33 #define OTP_REGION_CONF BIT(1)
36 #define OTP_USAGE -1
37 #define OTP_FAILURE -2
40 #define OTP_PROG_SKIP 1
42 #define OTP_KEY_TYPE_RSA_PUB 1
49 #define OTP_BIG_END 1
77 #define OTP_A1 1
105 #define SOC_AST2600A1 1
214 …{0, OTP_KEY_TYPE_AES, OTP_LIT_END, 0, "AES-256 as OEM platform key for image encryption/decr…
215 {1, OTP_KEY_TYPE_VAULT, OTP_LIT_END, 0, "AES-256 as secret vault key"},
216 {4, OTP_KEY_TYPE_HMAC, OTP_LIT_END, 1, "HMAC as encrypted OEM HMAC keys in Mode 1"},
217 {8, OTP_KEY_TYPE_RSA_PUB, OTP_LIT_END, 1, "RSA-public as OEM DSS public keys in Mode 2"},
218 {9, OTP_KEY_TYPE_RSA_PUB, OTP_LIT_END, 0, "RSA-public as SOC public key"},
219 {10, OTP_KEY_TYPE_RSA_PUB, OTP_LIT_END, 0, "RSA-public as AES key decryption key"},
220 {13, OTP_KEY_TYPE_RSA_PRIV, OTP_LIT_END, 0, "RSA-private as SOC private key"},
221 {14, OTP_KEY_TYPE_RSA_PRIV, OTP_LIT_END, 0, "RSA-private as AES key decryption key"},
225 {1, OTP_KEY_TYPE_VAULT, OTP_LIT_END, 0, "AES-256 as secret vault key"},
226 …TP_KEY_TYPE_AES, OTP_LIT_END, 1, "AES-256 as OEM platform key for image encryption/decryptio…
227 {8, OTP_KEY_TYPE_RSA_PUB, OTP_LIT_END, 1, "RSA-public as OEM DSS public keys in Mode 2"},
228 {10, OTP_KEY_TYPE_RSA_PUB, OTP_LIT_END, 0, "RSA-public as AES key decryption key"},
229 {14, OTP_KEY_TYPE_RSA_PRIV, OTP_LIT_END, 0, "RSA-private as AES key decryption key"},
233 {1, OTP_KEY_TYPE_VAULT, OTP_LIT_END, 0, "AES-256 as secret vault key"},
234 …TP_KEY_TYPE_AES, OTP_LIT_END, 1, "AES-256 as OEM platform key for image encryption/decryptio…
235 {8, OTP_KEY_TYPE_RSA_PUB, OTP_LIT_END, 1, "RSA-public as OEM DSS public keys in Mode 2"},
236 {10, OTP_KEY_TYPE_RSA_PUB, OTP_LIT_END, 0, "RSA-public as AES key decryption key"},
237 {14, OTP_KEY_TYPE_RSA_PRIV, OTP_LIT_END, 0, "RSA-private as AES key decryption key"},
241 {1, OTP_KEY_TYPE_VAULT, OTP_LIT_END, 0, "AES-256 as secret vault key"},
242 …TP_KEY_TYPE_AES, OTP_LIT_END, 1, "AES-256 as OEM platform key for image encryption/decryptio…
243 {8, OTP_KEY_TYPE_RSA_PUB, OTP_LIT_END, 1, "RSA-public as OEM DSS public keys in Mode 2"},
244 …{9, OTP_KEY_TYPE_RSA_PUB, OTP_BIG_END, 1, "RSA-public as OEM DSS public keys in Mode 2(big endia…
245 {10, OTP_KEY_TYPE_RSA_PUB, OTP_LIT_END, 0, "RSA-public as AES key decryption key"},
246 {11, OTP_KEY_TYPE_RSA_PUB, OTP_BIG_END, 0, "RSA-public as AES key decryption key(big endian)"},
247 {12, OTP_KEY_TYPE_RSA_PRIV, OTP_LIT_END, 0, "RSA-private as AES key decryption key"},
248 {13, OTP_KEY_TYPE_RSA_PRIV, OTP_BIG_END, 0, "RSA-private as AES key decryption key(big endian)"},
260 if ((i + 1) % 16 == 0) in buf_print()
275 i = 1; in get_dw_bit()
276 bit_offset = offset - 32; in get_dw_bit()
279 return 1; in get_dw_bit()
294 fz = 1; in get_rid_num()
316 /* AST2600-A0 */ in chip_version()
319 /* AST2600-A1 */ in chip_version()
322 /* AST2600-A2 */ in chip_version()
325 /* AST2600-A3 */ in chip_version()
328 /* AST2620-A1 */ in chip_version()
331 /* AST2620-A2 */ in chip_version()
334 /* AST2620-A3 */ in chip_version()
337 /* AST2605-A2 */ in chip_version()
340 /* AST2605-A3 */ in chip_version()
343 /* AST2605-A3 */ in chip_version()
354 udelay(1); in wait_complete()
379 case 1: //normal program in otp_soak()
399 case 1: //normal program in otp_soak()
423 data[1] = readl(OTP_COMPARE_2); in otp_read_data()
447 printf("%08X\n", buf[1]); in otp_compare()
451 writel(~buf[0], OTP_COMPARE_1); //Compare data 1 in otp_compare()
452 writel(~buf[1], OTP_COMPARE_2); //Compare data 2 in otp_compare()
471 writel(otp_addr - 1, OTP_ADDR); //Read address in verify_bit()
476 ret[1] = readl(OTP_COMPARE_2); in verify_bit()
479 if (((ret[0] >> bit_offset) & 1) == value) in verify_bit()
484 if (((ret[1] >> bit_offset) & 1) == value) in verify_bit()
495 otp_addr &= ~(1 << 15); in verify_dw()
500 writel(otp_addr - 1, OTP_ADDR); //Read address in verify_dw()
504 ret[1] = readl(OTP_COMPARE_2); in verify_dw()
505 if (size == 1) { in verify_dw()
516 // printf("check %x : %x = %x\n", otp_addr, ret[1], value[0]); in verify_dw()
517 if ((value[0] & ~ignore[0]) == (ret[1] & ~ignore[0])) { in verify_dw()
521 compare[0] = ~(value[0] ^ ret[1]); in verify_dw()
526 …alue[0] & ~ignore[0]) == (ret[0] & ~ignore[0]) && (value[1] & ~ignore[1]) == (ret[1] & ~ignore[1])… in verify_dw()
528 // printf("check[1] %x : %x = %x\n", otp_addr, ret[1], value[1]); in verify_dw()
530 compare[1] = ~0; in verify_dw()
534 // printf("check[1] %x : %x = %x\n", otp_addr, ret[1], value[1]); in verify_dw()
536 compare[1] = ~(value[1] ^ ret[1]); in verify_dw()
564 prog_address |= 1 << 15; in _otp_prog_bit()
579 otp_soak(1); in otp_prog_dc_b()
592 otp_soak(1); in otp_prog_dc_b()
594 pass = 1; in otp_prog_dc_b()
598 pass = 1; in otp_prog_dc_b()
624 prog_address |= 1 << 15; in otp_prog_dw()
650 data1_masked = data[1] & ~ignore_mask[1]; in otp_prog_verify_2dw()
651 buf1_masked = buf[1] & ~ignore_mask[1]; in otp_prog_verify_2dw()
656 if (((data0_masked >> i) & 0x1) == 1 && ((buf0_masked >> i) & 0x1) == 0) in otp_prog_verify_2dw()
658 if (((data1_masked >> i) & 0x1) == 0 && ((buf1_masked >> i) & 0x1) == 1) in otp_prog_verify_2dw()
662 otp_soak(1); in otp_prog_verify_2dw()
670 ret = otp_prog_dw(buf[1], ignore_mask[1], prog_address + 1); in otp_prog_verify_2dw()
684 if (compare[1] != ~0) { in otp_prog_verify_2dw()
685 ret = otp_prog_dw(compare[1], ignore_mask[1], prog_address + 1); in otp_prog_verify_2dw()
690 otp_soak(1); in otp_prog_verify_2dw()
692 pass = 1; in otp_prog_verify_2dw()
696 pass = 1; in otp_prog_verify_2dw()
718 otpstrap[j].writeable_option = -1; in otp_strap_status()
726 otpstrap[j].writeable_option = -1; in otp_strap_status()
734 int option = (i - 16) / 2; in otp_strap_status()
737 otp_read_conf(i + 1, &OTPSTRAP_RAW[1]); in otp_strap_status()
741 if (bit_value == 0 && otpstrap[j].writeable_option == -1) in otp_strap_status()
743 if (bit_value == 1) in otp_strap_status()
744 otpstrap[j].remain_times--; in otp_strap_status()
749 char bit_value = ((OTPSTRAP_RAW[1] >> (j - 32)) & 0x1); in otp_strap_status()
751 if (bit_value == 0 && otpstrap[j].writeable_option == -1) in otp_strap_status()
753 if (bit_value == 1) in otp_strap_status()
754 otpstrap[j].remain_times--; in otp_strap_status()
761 otp_read_conf(31, &OTPSTRAP_RAW[1]); in otp_strap_status()
763 if (((OTPSTRAP_RAW[0] >> j) & 0x1) == 1) in otp_strap_status()
764 otpstrap[j].protected = 1; in otp_strap_status()
767 if (((OTPSTRAP_RAW[1] >> (j - 32)) & 0x1) == 1) in otp_strap_status()
768 otpstrap[j].protected = 1; in otp_strap_status()
777 if (ibit == 1) in otp_strap_bit_confirm()
781 if (bit == otpstrap->value) { in otp_strap_bit_confirm()
788 prog_flag = 1; in otp_strap_bit_confirm()
790 if (otpstrap->protected == 1 && prog_flag) { in otp_strap_bit_confirm()
794 if (otpstrap->remain_times == 0 && prog_flag) { in otp_strap_bit_confirm()
798 if (pbit == 1) in otp_strap_bit_confirm()
799 printf(" This bit will be protected and become non-writable.\n"); in otp_strap_bit_confirm()
801 …1 to OTPSTRAP[0x%X] OPTION[0x%X], that value becomes from 0x%X to 0x%X.\n", offset, otpstrap->writ… in otp_strap_bit_confirm()
827 offset = (bit_offset - 32); in otp_prog_strap_b()
832 return otp_prog_dc_b(1, prog_address, offset); in otp_prog_strap_b()
838 u32 ret[1]; in otp_print_conf()
862 printf("%03X: %08X %08X ", i * 4, ret[0], ret[1]); in otp_print_data()
864 printf("%08X %08X\n", ret[0], ret[1]); in otp_print_data()
892 printf("0x%-8X", i); in otp_print_strap()
893 printf("%-7d", otpstrap[i].value); in otp_print_strap()
897 if (otpstrap[i].protected == 1) { in otp_print_strap()
917 printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); in otp_print_revid()
924 j = 1; in otp_print_revid()
925 bit_offset = i - 32; in otp_print_revid()
930 if ((i + 1) % 16 == 0) in otp_print_revid()
938 u32 *OTPSCU = (u32 *)image_layout->scu_pro; in otp_print_scu_image()
939 u32 *OTPSCU_IGNORE = (u32 *)image_layout->scu_pro_ignore; in otp_print_scu_image()
951 mask = BIT(scu_info[i].length) - 1; in otp_print_scu_image()
955 dw_offset = 1; in otp_print_scu_image()
956 bit_offset = scu_info[i].bit_offset - 32; in otp_print_scu_image()
974 printf("0x%-6X", scu_offset); in otp_print_scu_image()
975 if (scu_info[i].length == 1) in otp_print_scu_image()
976 printf("0x%-11X", bit_offset); in otp_print_scu_image()
978 printf("0x%-2X:0x%-6x", bit_offset, bit_offset + scu_info[i].length - 1); in otp_print_scu_image()
979 printf("0x%-14X", otp_value); in otp_print_scu_image()
997 otp_read_conf(29, &OTPCFG[1]); in otp_print_scu_info()
1009 bit_offset = scu_info[i].bit_offset + j - 32; in otp_print_scu_info()
1010 reg_p = (OTPCFG[1] >> bit_offset) & 0x1; in otp_print_scu_info()
1012 printf("0x%-6X", scu_offset); in otp_print_scu_info()
1013 printf("0x%-4X", bit_offset); in otp_print_scu_info()
1014 printf("0x%-13X", reg_p); in otp_print_scu_info()
1015 if (length == 1) { in otp_print_scu_info()
1022 else if (j == length - 1) in otp_print_scu_info()
1033 u32 *OTPCFG = (u32 *)image_layout->conf; in otp_print_conf_image()
1034 u32 *OTPCFG_IGNORE = (u32 *)image_layout->conf_ignore; in otp_print_conf_image()
1054 mask = BIT(conf_info[i].length) - 1; in otp_print_conf_image()
1060 fail = 1; in otp_print_conf_image()
1061 mask_err = 1; in otp_print_conf_image()
1067 fail = 1; in otp_print_conf_image()
1068 mask_err = 1; in otp_print_conf_image()
1077 printf("0x%-4X", dw_offset); in otp_print_conf_image()
1079 if (conf_info[i].length == 1) { in otp_print_conf_image()
1080 printf("0x%-9X", conf_info[i].bit_offset); in otp_print_conf_image()
1082 printf("0x%-2X:0x%-4X", in otp_print_conf_image()
1083 conf_info[i].bit_offset + conf_info[i].length - 1, in otp_print_conf_image()
1086 printf("0x%-10x", otp_value); in otp_print_conf_image()
1100 if (otp_value & (1 << j)) in otp_print_conf_image()
1101 valid_bit[j * 2] = '1'; in otp_print_conf_image()
1104 valid_bit[j * 2 + 1] = ' '; in otp_print_conf_image()
1119 printf("OTP revision ID is invalid.\n"); in otp_print_conf_image()
1120 fail = 1; in otp_print_conf_image()
1126 fz = 1; in otp_print_conf_image()
1130 printf("OTP revision ID is invalid.\n"); in otp_print_conf_image()
1131 fail = 1; in otp_print_conf_image()
1138 printf("OTP revision ID\n"); in otp_print_conf_image()
1140 printf("OTP revision ID: 0x%x\n", rid_num); in otp_print_conf_image()
1169 if (input_offset != -1 && input_offset != conf_info[i].dw_offset) in otp_print_conf_info()
1173 mask = BIT(conf_info[i].length) - 1; in otp_print_conf_info()
1181 printf("0x%-4X", dw_offset); in otp_print_conf_info()
1183 if (conf_info[i].length == 1) { in otp_print_conf_info()
1184 printf("0x%-9X", conf_info[i].bit_offset); in otp_print_conf_info()
1186 printf("0x%-2X:0x%-4X", in otp_print_conf_info()
1187 conf_info[i].bit_offset + conf_info[i].length - 1, in otp_print_conf_info()
1190 printf("0x%-10x", otp_value); in otp_print_conf_info()
1200 if (otp_value & (1 << j)) in otp_print_conf_info()
1201 valid_bit[j * 2] = '1'; in otp_print_conf_info()
1204 valid_bit[j * 2 + 1] = ' '; in otp_print_conf_info()
1234 OTPSTRAP = (u32 *)image_layout->strap; in otp_print_strap_image()
1235 OTPSTRAP_PRO = (u32 *)image_layout->strap_pro; in otp_print_strap_image()
1236 OTPSTRAP_IGNORE = (u32 *)image_layout->strap_ignore; in otp_print_strap_image()
1244 dw_offset = 1; in otp_print_strap_image()
1245 bit_offset = strap_info[i].bit_offset - 32; in otp_print_strap_image()
1251 mask = BIT(strap_info[i].length) - 1; in otp_print_strap_image()
1259 fail = 1; in otp_print_strap_image()
1265 if (strap_info[i].length == 1) { in otp_print_strap_image()
1266 printf("0x%-9X", strap_info[i].bit_offset); in otp_print_strap_image()
1268 printf("0x%-2X:0x%-4X", in otp_print_strap_image()
1269 strap_info[i].bit_offset + strap_info[i].length - 1, in otp_print_strap_image()
1272 printf("0x%-10x", otp_value); in otp_print_strap_image()
1273 printf("0x%-10x", otp_protect); in otp_print_strap_image()
1324 printf("0x%-7X", strap_info[i].bit_offset + j); in otp_print_strap_info()
1325 printf("0x%-5X", strap_status[bit_offset + j].value); in otp_print_strap_info()
1326 printf("%-9d", strap_status[bit_offset + j].remain_times); in otp_print_strap_info()
1327 printf("0x%-7X", strap_status[bit_offset + j].protected); in otp_print_strap_info()
1332 if (length == 1) { in otp_print_strap_info()
1339 else if (j == length - 1) in otp_print_strap_info()
1345 if (length == 1) { in otp_print_strap_info()
1346 printf("0x%-9X", strap_info[i].bit_offset); in otp_print_strap_info()
1348 printf("0x%-2X:0x%-4X", in otp_print_strap_info()
1349 bit_offset + length - 1, bit_offset); in otp_print_strap_info()
1352 printf("0x%-10X", otp_value); in otp_print_strap_info()
1370 struct otpkey_type key_info = { .value = -1 }; in _otp_print_key()
1390 if (key_info.value == -1) in _otp_print_key()
1402 case 1: in _otp_print_key()
1420 case 1: in _otp_print_key()
1457 printf("AES Key 1:\n"); in _otp_print_key()
1484 empty = 1; in otp_print_key()
1495 printf("OTP data header is empty\n"); in otp_print_key()
1500 last = (data[i] >> 13) & 1; in otp_print_key()
1511 buf = (u32 *)image_layout->data; in otp_print_data_image()
1535 buf = (u32 *)image_layout->data; in otp_prog_data()
1536 buf_ignore = (u32 *)image_layout->data_ignore; in otp_prog_data()
1544 i, data[i], data[i + 1], buf[i], buf[i + 1], buf_ignore[i], buf_ignore[i + 1]); in otp_prog_data()
1553 i, data[i], data[i + 1], buf[i], buf[i + 1], buf_ignore[i], buf_ignore[i + 1]); in otp_prog_data()
1573 strap = (u32 *)image_layout->strap; in otp_prog_strap()
1574 strap_pro = (u32 *)image_layout->strap_pro; in otp_prog_strap()
1575 strap_ignore = (u32 *)image_layout->strap_ignore; in otp_prog_strap()
1588 offset = (i - 32); in otp_prog_strap()
1589 bit = (strap[1] >> offset) & 0x1; in otp_prog_strap()
1590 ibit = (strap_ignore[1] >> offset) & 0x1; in otp_prog_strap()
1591 pbit = (strap_pro[1] >> offset) & 0x1; in otp_prog_strap()
1596 if (ibit == 1) in otp_prog_strap()
1601 prog_flag = 1; in otp_prog_strap()
1603 if (otpstrap[i].protected == 1 && prog_flag) { in otp_prog_strap()
1604 fail = 1; in otp_prog_strap()
1608 fail = 1; in otp_prog_strap()
1613 ret = otp_prog_dc_b(1, prog_address, offset); in otp_prog_strap()
1625 ret = otp_prog_dc_b(1, prog_address, offset); in otp_prog_strap()
1631 if (fail == 1) in otp_prog_strap()
1642 u32 *conf = (u32 *)image_layout->conf; in otp_prog_conf()
1643 u32 *conf_ignore = (u32 *)image_layout->conf_ignore; in otp_prog_conf()
1657 pass = 1; in otp_prog_conf()
1661 otp_soak(1); in otp_prog_conf()
1668 if (verify_dw(prog_address, &conf[i], &conf_ignore[i], compare, 1) != 0) { in otp_prog_conf()
1673 if (verify_dw(prog_address, &conf[i], &conf_ignore[i], compare, 1) != 0) { in otp_prog_conf()
1674 otp_soak(1); in otp_prog_conf()
1676 pass = 1; in otp_prog_conf()
1680 pass = 1; in otp_prog_conf()
1704 u32 *OTPSCU = (u32 *)image_layout->scu_pro; in otp_prog_scu_protect()
1705 u32 *OTPSCU_IGNORE = (u32 *)image_layout->scu_pro_ignore; in otp_prog_scu_protect()
1717 pass = 1; in otp_prog_scu_protect()
1721 otp_soak(1); in otp_prog_scu_protect()
1727 if (verify_dw(prog_address, &OTPSCU[i], &OTPSCU_IGNORE[i], compare, 1) != 0) { in otp_prog_scu_protect()
1732 if (verify_dw(prog_address, &OTPSCU[i], &OTPSCU_IGNORE[i], compare, 1) != 0) { in otp_prog_scu_protect()
1733 otp_soak(1); in otp_prog_scu_protect()
1735 pass = 1; in otp_prog_scu_protect()
1739 pass = 1; in otp_prog_scu_protect()
1762 u32 *buf = (u32 *)image_layout->data; in otp_check_data_image()
1763 u32 *buf_ignore = (u32 *)image_layout->data_ignore; in otp_check_data_image()
1766 data_dw = image_layout->data_length / 4; in otp_check_data_image()
1767 // ignore last two dw, the last two dw is used for slt otp write check. in otp_check_data_image()
1768 for (i = 0; i < data_dw - 2; i++) { in otp_check_data_image()
1777 printf("Input image can't program into OTP, please check.\n"); in otp_check_data_image()
1787 printf("Input image can't program into OTP, please check.\n"); in otp_check_data_image()
1808 strap = (u32 *)image_layout->strap; in otp_check_strap_image()
1809 strap_pro = (u32 *)image_layout->strap_pro; in otp_check_strap_image()
1810 strap_ignore = (u32 *)image_layout->strap_ignore; in otp_check_strap_image()
1818 bit = (strap[1] >> (i - 32)) & 0x1; in otp_check_strap_image()
1819 ibit = (strap_ignore[1] >> (i - 32)) & 0x1; in otp_check_strap_image()
1820 pbit = (strap_pro[1] >> (i - 32)) & 0x1; in otp_check_strap_image()
1826 fail = 1; in otp_check_strap_image()
1828 if (fail == 1) { in otp_check_strap_image()
1829 printf("Input image can't program into OTP, please check.\n"); in otp_check_strap_image()
1837 u32 *conf = (u32 *)image_layout->conf; in otp_check_conf_image()
1838 u32 *conf_ignore = (u32 *)image_layout->conf_ignore; in otp_check_conf_image()
1851 printf("Input image can't program into OTP, please check.\n"); in otp_check_conf_image()
1863 u32 *OTPSCU = (u32 *)image_layout->scu_pro; in otp_check_scu_image()
1864 u32 *OTPSCU_IGNORE = (u32 *)image_layout->scu_pro_ignore; in otp_check_scu_image()
1877 printf("Input image can't program into OTP, please check.\n"); in otp_check_scu_image()
1896 algo->hash_func_ws(data, data_len, value, algo->chunk_size); in do_hash()
1905 case 1: in otp_verify_image()
1943 image_size = OTP_IMAGE_SIZE(otp_header->image_info); in otp_prog_image()
1953 checksum = buf + otp_header->checksum_offset; in otp_prog_image()
1955 if (strcmp(OTP_MAGIC, (char *)otp_header->otp_magic) != 0) { in otp_prog_image()
1960 image_layout.data_length = (int)(OTP_REGION_SIZE(otp_header->data_info) / 2); in otp_prog_image()
1961 image_layout.data = buf + OTP_REGION_OFFSET(otp_header->data_info); in otp_prog_image()
1964 image_layout.conf_length = (int)(OTP_REGION_SIZE(otp_header->config_info) / 2); in otp_prog_image()
1965 image_layout.conf = buf + OTP_REGION_OFFSET(otp_header->config_info); in otp_prog_image()
1968 image_layout.strap = buf + OTP_REGION_OFFSET(otp_header->strap_info); in otp_prog_image()
1969 image_layout.strap_length = (int)(OTP_REGION_SIZE(otp_header->strap_info) / 3); in otp_prog_image()
1973 image_layout.scu_pro = buf + OTP_REGION_OFFSET(otp_header->scu_protect_info); in otp_prog_image()
1974 image_layout.scu_pro_length = (int)(OTP_REGION_SIZE(otp_header->scu_protect_info) / 2); in otp_prog_image()
1977 if (otp_header->soc_ver == SOC_AST2600A0) { in otp_prog_image()
1979 } else if (otp_header->soc_ver == SOC_AST2600A1) { in otp_prog_image()
1981 } else if (otp_header->soc_ver == SOC_AST2600A2) { in otp_prog_image()
1983 } else if (otp_header->soc_ver == SOC_AST2600A3) { in otp_prog_image()
1995 switch (OTPTOOL_VERSION_MAJOR(otp_header->otptool_ver)) { in otp_prog_image()
1996 case 1: in otp_prog_image()
1997 printf("WARNING: OTP image is not generated by otptool v2.x.x\n"); in otp_prog_image()
1998 printf("Please use the latest version of otptool to generate OTP image\n"); in otp_prog_image()
1999 ret = otp_verify_image(buf, image_size, checksum, 1); in otp_prog_image()
2005 printf("OTP image version is not supported\n"); in otp_prog_image()
2015 printf("OTP memory is locked\n"); in otp_prog_image()
2019 if (otp_header->image_info & OTP_INC_DATA) { in otp_prog_image()
2021 printf("OTP data region is protected\n"); in otp_prog_image()
2022 ret = -1; in otp_prog_image()
2025 printf("OTP secure region is protected\n"); in otp_prog_image()
2026 ret = -1; in otp_prog_image()
2028 printf("Read OTP Data Region:\n"); in otp_prog_image()
2034 ret = -1; in otp_prog_image()
2036 if (otp_header->image_info & OTP_INC_CONFIG) { in otp_prog_image()
2038 printf("OTP config region is protected\n"); in otp_prog_image()
2039 ret = -1; in otp_prog_image()
2041 printf("Read OTP Config Region:\n"); in otp_prog_image()
2047 ret = -1; in otp_prog_image()
2049 if (otp_header->image_info & OTP_INC_STRAP) { in otp_prog_image()
2051 printf("OTP strap region is protected\n"); in otp_prog_image()
2052 ret = -1; in otp_prog_image()
2054 printf("Read OTP Strap Region:\n"); in otp_prog_image()
2059 ret = -1; in otp_prog_image()
2061 if (otp_header->image_info & OTP_INC_SCU_PRO) { in otp_prog_image()
2063 printf("OTP strap region is protected\n"); in otp_prog_image()
2064 ret = -1; in otp_prog_image()
2068 otp_read_conf(29, &scu_pro[1]); in otp_prog_image()
2072 ret = -1; in otp_prog_image()
2074 if (ret == -1) in otp_prog_image()
2078 if (otp_header->image_info & OTP_INC_DATA) { in otp_prog_image()
2081 printf("OTP data error, please check.\n"); in otp_prog_image()
2085 if (otp_header->image_info & OTP_INC_CONFIG) { in otp_prog_image()
2088 printf("OTP config error, please check.\n"); in otp_prog_image()
2092 if (otp_header->image_info & OTP_INC_STRAP) { in otp_prog_image()
2095 printf("OTP strap error, please check.\n"); in otp_prog_image()
2099 if (otp_header->image_info & OTP_INC_SCU_PRO) { in otp_prog_image()
2102 printf("OTP scu protect error, please check.\n"); in otp_prog_image()
2114 if (otp_header->image_info & OTP_INC_DATA) { in otp_prog_image()
2123 if (otp_header->image_info & OTP_INC_STRAP) { in otp_prog_image()
2132 if (otp_header->image_info & OTP_INC_SCU_PRO) { in otp_prog_image()
2141 if (otp_header->image_info & OTP_INC_CONFIG) { in otp_prog_image()
2175 if (otp_bit == 1 && value == 0) { in otp_prog_bit()
2176 printf("OTPCFG0x%X[0x%X] = 1\n", otp_dw_offset, bit_offset); in otp_prog_bit()
2177 printf("OTP is programmed, which can't be clean\n"); in otp_prog_bit()
2180 printf("Program OTPCFG0x%X[0x%X] to 1\n", otp_dw_offset, bit_offset); in otp_prog_bit()
2189 if (otp_bit == 1 && value == 0) { in otp_prog_bit()
2190 printf("OTPDATA0x%X[0x%X] = 1\n", otp_dw_offset, bit_offset); in otp_prog_bit()
2191 printf("OTP is programmed, which can't be cleared\n"); in otp_prog_bit()
2195 otp_read_data(otp_dw_offset - 1, read); in otp_prog_bit()
2196 otp_bit = (read[1] >> bit_offset) & 0x1; in otp_prog_bit()
2198 if (otp_bit == 0 && value == 1) { in otp_prog_bit()
2199 printf("OTPDATA0x%X[0x%X] = 1\n", otp_dw_offset, bit_offset); in otp_prog_bit()
2200 printf("OTP is programmed, which can't be written\n"); in otp_prog_bit()
2214 otp_print_strap(bit_offset, 1); in otp_prog_bit()
2243 printf("OTP cannot be programmed\n"); in otp_prog_bit()
2264 otp_read_conf(11, &otp_rid[1]); in otp_update_rid()
2267 sw_rid[1] = readl(SW_REV_ID1); in otp_update_rid()
2284 printf("Current OTP revision ID cannot handle by this command,\n" in otp_update_rid()
2285 "please use 'otp pb' command to update it manually\n"); in otp_update_rid()
2290 printf("current OTP revision ID: 0x%x\n", rid_num); in otp_update_rid()
2295 printf("OTP rev_id is bigger than 0x%X\n", update_num); in otp_update_rid()
2299 printf("OTP rev_id is same as input\n"); in otp_update_rid()
2310 bit_offset = i - 32; in otp_update_rid()
2313 if (i + 1 != update_num) in otp_update_rid()
2333 bit_offset = i - 32; in otp_update_rid()
2335 if (otp_prog_dc_b(1, dw_offset, bit_offset)) { in otp_update_rid()
2343 otp_read_conf(11, &otp_rid[1]); in otp_update_rid()
2346 printf("OTP revision ID: 0x%x\n", rid_num); in otp_update_rid()
2348 printf("OTP revision ID\n"); in otp_update_rid()
2385 if (krb_or & (1 << retire_id)) { in otp_retire_key()
2399 if (otp_prog_dc_b(1, 0x808, retire_id) == OTP_FAILURE) { in otp_retire_key()
2402 if (otp_prog_dc_b(1, 0x808, retire_id + 16) == OTP_FAILURE) in otp_retire_key()
2411 if (krb_or & (1 << retire_id)) { in otp_retire_key()
2433 si->enc_flag = (cfg0 >> 27) & 0x1; in parse_config()
2437 si->secure_region = 1; in parse_config()
2439 si->secure_region = 0; in parse_config()
2441 si->header_offset = cfg3 & 0xffff; in parse_config()
2442 if (si->header_offset == 0) in parse_config()
2443 si->header_offset = 0x20; in parse_config()
2447 si->retire_list[i] = 1; in parse_config()
2449 si->retire_list[i] = 0; in parse_config()
2457 if (si->enc_flag) in parse_config()
2466 si->rsa_algo = 1024; in parse_config()
2468 } else if (rsa_len == 1) { in parse_config()
2469 si->rsa_algo = 2048; in parse_config()
2472 si->rsa_algo = 3072; in parse_config()
2475 si->rsa_algo = 4096; in parse_config()
2479 si->sha_algo = 224; in parse_config()
2480 si->digest_len = 28; in parse_config()
2482 } else if (sha_len == 1) { in parse_config()
2483 si->sha_algo = 256; in parse_config()
2484 si->digest_len = 32; in parse_config()
2487 si->sha_algo = 384; in parse_config()
2488 si->digest_len = 48; in parse_config()
2491 si->sha_algo = 512; in parse_config()
2492 si->digest_len = 64; in parse_config()
2516 if (si->retire_list[id] == 1) in parse_data()
2517 kl[*key_num].retire = 1; in parse_data()
2524 if ((data[i] >> 13) & 1) in parse_data()
2531 switch (si->sha_algo) { in sb_sha()
2533 printf("otp verify does not support SHA224\n"); in sb_sha()
2562 u32 rsa_len = si->rsa_algo / 8; in mode2_verify()
2572 rsa_m_rev[i] = rsa_m[rsa_len - 1 - i]; in mode2_verify()
2573 signature_rev[i] = signature[rsa_len - 1 - i]; in mode2_verify()
2576 prop.num_bits = si->rsa_algo; in mode2_verify()
2582 prop.num_bits = si->rsa_algo; in mode2_verify()
2596 sign_ret[i] = sign_ret[rsa_len - 1 - i]; in mode2_verify()
2597 sign_ret[rsa_len - 1 - i] = tmp; in mode2_verify()
2599 ret = memcmp(digest, sign_ret, si->digest_len); in mode2_verify()
2601 ret = memcmp(digest, sign_ret + (rsa_len - si->digest_len), si->digest_len); in mode2_verify()
2641 otp_read_conf(11, &otp_rid[1]); in otp_verify_boot_image()
2645 signature = sec_image + sh->signature_offset; in otp_verify_boot_image()
2650 if (sh->sign_image_size % 512) { in otp_verify_boot_image()
2657 sw_rid[0] = sh->revision_low; in otp_verify_boot_image()
2658 sw_rid[1] = sh->revision_high; in otp_verify_boot_image()
2662 printf("Header revision_low: %x\n", sh->revision_low); in otp_verify_boot_image()
2663 printf("Header revision_high: %x\n", sh->revision_high); in otp_verify_boot_image()
2664 printf("OTP revision_low: %x\n", otp_rid[0]); in otp_verify_boot_image()
2665 printf("OTP revision_high: %x\n", otp_rid[1]); in otp_verify_boot_image()
2671 if (((sh->aes_data_offset + sh->enc_offset + sh->sign_image_size + in otp_verify_boot_image()
2672 sh->signature_offset + sh->revision_high + sh->revision_low + in otp_verify_boot_image()
2673 sh->reserved + sh->bl1_header_checksum) & 0xffffffff) != 0) { in otp_verify_boot_image()
2675 printf("aes_data_offset: %x\n", sh->aes_data_offset); in otp_verify_boot_image()
2676 printf("enc_offset: %x\n", sh->enc_offset); in otp_verify_boot_image()
2677 printf("sign_image_size: %x\n", sh->sign_image_size); in otp_verify_boot_image()
2678 printf("signature_offset: %x\n", sh->signature_offset); in otp_verify_boot_image()
2679 printf("revision_high: %x\n", sh->revision_high); in otp_verify_boot_image()
2680 printf("revision_low: %x\n", sh->revision_low); in otp_verify_boot_image()
2681 printf("reserved: %x\n", sh->reserved); in otp_verify_boot_image()
2682 printf("bl1_header_checksum: %x\n", sh->bl1_header_checksum); in otp_verify_boot_image()
2687 ret = sb_sha(&si, sec_image, sh->sign_image_size, digest); in otp_verify_boot_image()
2693 if (kl[i].key_info->key_type != OTP_KEY_TYPE_RSA_PUB) in otp_verify_boot_image()
2701 if (!mode2_verify(sec_image, sh->sign_image_size, in otp_verify_boot_image()
2702 signature, key, kl[i].key_info->order, digest, in otp_verify_boot_image()
2704 pass = 1; in otp_verify_boot_image()
2711 if (kl[i].key_info->order == OTP_BIG_END) in otp_verify_boot_image()
2753 prog_val = 1; in otp_invalid_key()
2776 count = 1; in do_otpread()
2781 if (!strcmp(argv[1], "conf")) in do_otpread()
2783 else if (!strcmp(argv[1], "data")) in do_otpread()
2785 else if (!strcmp(argv[1], "strap")) in do_otpread()
2801 if (strcmp(argv[1], "o")) in do_otpprog()
2804 ret = otp_prog_image(addr, 1); in do_otpprog()
2806 addr = simple_strtoul(argv[1], NULL, 16); in do_otpprog()
2834 argc--; in do_otppb()
2847 argc--; in do_otppb()
2851 nconfirm = 1; in do_otppb()
2853 argc--; in do_otppb()
2859 value = simple_strtoul(argv[1], NULL, 16); in do_otppb()
2860 if (bit_offset >= 64 || (value != 0 && value != 1)) in do_otppb()
2864 bit_offset = simple_strtoul(argv[1], NULL, 16); in do_otppb()
2866 if (bit_offset >= 32 || (value != 0 && value != 1)) in do_otppb()
2876 if (value != 0 && value != 1) in do_otppb()
2881 printf("OTP memory is locked\n"); in do_otppb()
2887 printf("OTP data region is protected\n"); in do_otppb()
2888 ret = -1; in do_otppb()
2891 printf("OTP secure region is not readable, skip it to prevent unpredictable result\n"); in do_otppb()
2892 ret = -1; in do_otppb()
2896 printf("OTP secure region is protected\n"); in do_otppb()
2897 ret = -1; in do_otppb()
2900 printf("OTP data region is protected\n"); in do_otppb()
2901 ret = -1; in do_otppb()
2906 printf("OTP config region is protected\n"); in do_otppb()
2907 ret = -1; in do_otppb()
2916 otp_read_conf(11, &otp_rid[1]); in do_otppb()
2918 sw_rid[1] = readl(SW_REV_ID1); in do_otppb()
2921 otp_rid[0] |= 1 << bit_offset; in do_otppb()
2923 otp_rid[1] |= 1 << bit_offset; in do_otppb()
2927 ret = -1; in do_otppb()
2932 ret = -1; in do_otppb()
2941 retire = bit_offset - 16; in do_otppb()
2946 ret = -1; in do_otppb()
2952 printf("OTP strap region is protected\n"); in do_otppb()
2953 ret = -1; in do_otppb()
2962 ret = -1; in do_otppb()
2969 printf("OTP strap region is protected\n"); in do_otppb()
2970 ret = -1; in do_otppb()
2974 if (ret == -1) in do_otppb()
2996 addr = simple_strtoul(argv[1], NULL, 16); in do_otpcmp()
3015 if (!strcmp(argv[1], "conf")) { in do_otpinfo()
3020 otp_print_conf_info(-1); in do_otpinfo()
3022 } else if (!strcmp(argv[1], "strap")) { in do_otpinfo()
3024 view = 1; in do_otpinfo()
3026 argc--; in do_otpinfo()
3030 } else if (!strcmp(argv[1], "scu")) { in do_otpinfo()
3032 } else if (!strcmp(argv[1], "key")) { in do_otpinfo()
3052 if (!strcmp(argv[1], "o")) { in do_otpprotect()
3054 force = 1; in do_otpprotect()
3056 input = simple_strtoul(argv[1], NULL, 16); in do_otpprotect()
3064 bit_offset = input - 32; in do_otpprotect()
3071 printf("OTP strap region is protected\n"); in do_otpprotect()
3084 if (verify_bit(prog_address, bit_offset, 1) == 0) { in do_otpprotect()
3089 ret = otp_prog_dc_b(1, prog_address, bit_offset); in do_otpprotect()
3113 if (!strcmp(argv[1], "o")) { in do_otp_scuprotect()
3116 force = 1; in do_otp_scuprotect()
3118 scu_offset = simple_strtoul(argv[1], NULL, 16); in do_otp_scuprotect()
3134 printf("OTP strap region is protected\n"); in do_otp_scuprotect()
3147 if (verify_bit(prog_address, bit_offset, 1) == 0) { in do_otp_scuprotect()
3152 ret = otp_prog_dc_b(1, prog_address, bit_offset); in do_otp_scuprotect()
3166 printf("SOC OTP version: %s\n", info_cb.ver_name); in do_otpver()
3167 printf("OTP tool version: %s\n", OTP_VER); in do_otpver()
3168 printf("OTP info version: %s\n", OTP_INFO_VER); in do_otpver()
3180 if (strcmp(argv[1], "o")) in do_otpupdate()
3182 force = 1; in do_otpupdate()
3185 update_num = simple_strtoul(argv[1], NULL, 16); in do_otpupdate()
3207 if (argc != 1) in do_otprid()
3211 otp_read_conf(11, &otp_rid[1]); in do_otprid()
3214 sw_rid[1] = readl(SW_REV_ID1); in do_otprid()
3222 printf("SEC6C:0x%x\n", sw_rid[1]); in do_otprid()
3227 printf("current OTP revision ID: 0x%x\n", rid_num); in do_otprid()
3230 printf("Current OTP revision ID cannot handle by 'otp update',\n" in do_otprid()
3231 "please use 'otp pb' command to update it manually\n" in do_otprid()
3232 "current OTP revision ID\n"); in do_otprid()
3247 if (strcmp(argv[1], "o")) in do_otpretire()
3249 force = 1; in do_otpretire()
3252 retire_id = simple_strtoul(argv[1], NULL, 16); in do_otpretire()
3272 addr = simple_strtoul(argv[1], NULL, 16); in do_otpverify()
3293 if (strcmp(argv[1], "o")) in do_otpinvalid()
3295 force = 1; in do_otpinvalid()
3298 header_offset = simple_strtoul(argv[1], NULL, 16); in do_otpinvalid()
3313 U_BOOT_CMD_MKENT(version, 1, 0, do_otpver, "", ""),
3322 U_BOOT_CMD_MKENT(rid, 1, 0, do_otprid, "", ""),
3336 cp = find_cmd_tbl(argv[1], cmd_otp, ARRAY_SIZE(cmd_otp)); in do_ast_otp()
3338 /* Drop the otp command */ in do_ast_otp()
3339 argc--; in do_ast_otp()
3342 if (!cp || argc > cp->maxargs) in do_ast_otp()
3404 pro_sts->mem_lock = (otp_conf0 >> 31) & 0x1; in do_ast_otp()
3405 pro_sts->pro_key_ret = (otp_conf0 >> 29) & 0x1; in do_ast_otp()
3406 pro_sts->pro_strap = (otp_conf0 >> 25) & 0x1; in do_ast_otp()
3407 pro_sts->pro_conf = (otp_conf0 >> 24) & 0x1; in do_ast_otp()
3408 pro_sts->pro_data = (otp_conf0 >> 23) & 0x1; in do_ast_otp()
3409 pro_sts->pro_sec = (otp_conf0 >> 22) & 0x1; in do_ast_otp()
3410 pro_sts->sec_size = ((otp_conf0 >> 16) & 0x3f) << 5; in do_ast_otp()
3412 ret = cp->cmd(cmdtp, flag, argc, argv); in do_ast_otp()
3413 writel(1, OTP_PROTECT_KEY); //protect otp controller in do_ast_otp()
3418 U_BOOT_CMD(otp, 7, 0, do_ast_otp,
3419 "ASPEED One-Time-Programmable sub-system",
3421 "otp read conf|data <otp_dw_offset> <dw_count>\n"
3422 "otp read strap <strap_bit_offset> <bit_count>\n"
3423 "otp info strap [v]\n"
3424 "otp info conf [otp_dw_offset]\n"
3425 "otp info scu\n"
3426 "otp info key\n"
3427 "otp prog [o] <addr>\n"
3428 "otp pb conf|data [o] <otp_dw_offset> <bit_offset> <value>\n"
3429 "otp pb strap [o] <bit_offset> <value>\n"
3430 "otp protect [o] <bit_offset>\n"
3431 "otp scuprotect [o] <scu_offset> <bit_offset>\n"
3432 "otp update [o] <revision_id>\n"
3433 "otp rid\n"
3434 "otp retire [o] <key_id>\n"
3435 "otp verify <addr>\n"
3436 "otp invalid [o] <header_offset>\n"