Lines Matching +full:2021 +full:- +full:07 +full:- +full:25
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2021 Aspeed Technology Inc.
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>
36 #define OTP_USAGE -1
37 #define OTP_FAILURE -2
71 #define OTP_INC_SCU_PRO BIT(25)
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"},
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 …EY_TYPE_AES, OTP_LIT_END, 1, "AES-256 as OEM platform key for image encryption/decryption in…
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 …EY_TYPE_AES, OTP_LIT_END, 1, "AES-256 as OEM platform key for image encryption/decryption in…
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 …EY_TYPE_AES, OTP_LIT_END, 1, "AES-256 as OEM platform key for image encryption/decryption in…
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)"},
255 printf(" 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n"); in buf_print()
276 bit_offset = offset - 32; in get_dw_bit()
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()
471 writel(otp_addr - 1, OTP_ADDR); //Read address in verify_bit()
500 writel(otp_addr - 1, OTP_ADDR); //Read address in verify_dw()
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()
741 if (bit_value == 0 && otpstrap[j].writeable_option == -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()
754 otpstrap[j].remain_times--; in otp_strap_status()
767 if (((OTPSTRAP_RAW[1] >> (j - 32)) & 0x1) == 1) in otp_strap_status()
781 if (bit == otpstrap->value) { 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()
799 printf(" This bit will be protected and become non-writable.\n"); in otp_strap_bit_confirm()
801 …lue becomes from 0x%X to 0x%X.\n", offset, otpstrap->writeable_option + 1, otpstrap->value, otpstr… in otp_strap_bit_confirm()
827 offset = (bit_offset - 32); in otp_prog_strap_b()
892 printf("0x%-8X", i); in otp_print_strap()
893 printf("%-7d", otpstrap[i].value); in otp_print_strap()
925 bit_offset = i - 32; 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()
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()
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()
1009 bit_offset = scu_info[i].bit_offset + j - 32; 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()
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()
1077 printf("0x%-4X", dw_offset); 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()
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()
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()
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()
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()
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()
1339 else if (j == 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()
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()
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()
1642 u32 *conf = (u32 *)image_layout->conf; in otp_prog_conf()
1643 u32 *conf_ignore = (u32 *)image_layout->conf_ignore; 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()
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()
1768 for (i = 0; i < data_dw - 2; i++) { 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()
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()
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()
1896 algo->hash_func_ws(data, data_len, value, algo->chunk_size); in do_hash()
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()
2019 if (otp_header->image_info & OTP_INC_DATA) { in otp_prog_image()
2022 ret = -1; in otp_prog_image()
2026 ret = -1; in otp_prog_image()
2034 ret = -1; in otp_prog_image()
2036 if (otp_header->image_info & OTP_INC_CONFIG) { in otp_prog_image()
2039 ret = -1; in otp_prog_image()
2047 ret = -1; in otp_prog_image()
2049 if (otp_header->image_info & OTP_INC_STRAP) { in otp_prog_image()
2052 ret = -1; 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()
2064 ret = -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()
2085 if (otp_header->image_info & OTP_INC_CONFIG) { in otp_prog_image()
2092 if (otp_header->image_info & OTP_INC_STRAP) { in otp_prog_image()
2099 if (otp_header->image_info & OTP_INC_SCU_PRO) { 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()
2195 otp_read_data(otp_dw_offset - 1, read); in otp_prog_bit()
2310 bit_offset = i - 32; in otp_update_rid()
2333 bit_offset = i - 32; in otp_update_rid()
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()
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()
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()
2531 switch (si->sha_algo) { 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()
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()
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()
2711 if (kl[i].key_info->order == OTP_BIG_END) in otp_verify_boot_image()
2834 argc--; in do_otppb()
2847 argc--; in do_otppb()
2853 argc--; in do_otppb()
2888 ret = -1; in do_otppb()
2892 ret = -1; in do_otppb()
2897 ret = -1; in do_otppb()
2901 ret = -1; in do_otppb()
2907 ret = -1; 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()
2953 ret = -1; in do_otppb()
2962 ret = -1; in do_otppb()
2970 ret = -1; in do_otppb()
2974 if (ret == -1) in do_otppb()
3020 otp_print_conf_info(-1); in do_otpinfo()
3026 argc--; in do_otpinfo()
3064 bit_offset = input - 32; in do_otpprotect()
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()
3419 "ASPEED One-Time-Programmable sub-system",