From 044e6bbb7316457a28886c6d0906481b9ab94373 Mon Sep 17 00:00:00 2001 From: shripad621git Date: Wed, 1 Nov 2023 12:43:47 +0530 Subject: [PATCH] made outdir user governed --- .../tools/generate_esp32_chip_factory_bin.py | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/scripts/tools/generate_esp32_chip_factory_bin.py b/scripts/tools/generate_esp32_chip_factory_bin.py index 12e00f395ef9f4..18282834ddcade 100755 --- a/scripts/tools/generate_esp32_chip_factory_bin.py +++ b/scripts/tools/generate_esp32_chip_factory_bin.py @@ -52,6 +52,7 @@ FACTORY_PARTITION_CSV = 'nvs_partition.csv' FACTORY_PARTITION_BIN = 'factory_partition.bin' NVS_KEY_PARTITION_BIN = 'nvs_key_partition.bin' +ESP_SECURE_CERT_PARTITION_BIN = 'esp_secure_cert_partititon.bin' FACTORY_DATA = { # CommissionableDataProvider @@ -165,11 +166,6 @@ # in the respective functions. } -OUT_DIR = { - 'top': None, - 'chip': None, -} - class CalendarTypes(enum.Enum): Buddhist = 0 @@ -330,8 +326,7 @@ def populate_factory_data(args, spake2p_params): FACTORY_DATA['dac-key']['value'] = os.path.abspath('dac_raw_privkey.bin') FACTORY_DATA['dac-pub-key']['value'] = os.path.abspath('dac_raw_pubkey.bin') else: - file_name = "esp_secure_cert_partititon.bin" - secure_cert_partition_file_path = os.path.join(OUT_DIR['top'], file_name) + secure_cert_partition_file_path = os.path.join(args.output_dir, ESP_SECURE_CERT_PARTITION_BIN) if args.ds_peripheral: if args.target != "esp32h2": logging.error("DS peripheral is only supported for esp32h2 target") @@ -341,7 +336,7 @@ def populate_factory_data(args, spake2p_params): exit(1) priv_key = tlv_priv_key_t(key_type=tlv_priv_key_type_t.ESP_SECURE_CERT_ECDSA_PERIPHERAL_KEY, key_path=args.dac_key, key_pass=None) - priv_key.priv_key_len = 256 + priv_key.priv_key_len = 256 // bits priv_key.efuse_key_id = args.efuse_key_id generate_partition_ds(priv_key=priv_key, device_cert=args.dac_cert, ca_cert=args.pai_cert, idf_target=args.target, @@ -515,9 +510,9 @@ def generate_nvs_csv(out_csv_filename): logging.info('Generated the factory partition csv file : {}'.format(os.path.abspath(out_csv_filename))) -def generate_nvs_bin(encrypt, size, csv_filename, bin_filename): +def generate_nvs_bin(encrypt, size, csv_filename, bin_filename, output_dir): nvs_args = SimpleNamespace(version=2, - outdir=OUT_DIR['top'], + outdir=output_dir, input=csv_filename, output=bin_filename, size=hex(size)) @@ -565,7 +560,7 @@ def any_base_int(s): return int(s, 0) parser.add_argument('--cd', help='The path to the certificate declaration der format') # Options for esp_secure_cert_partition - parser.add_argument('--dac-in-secure-cert', action="store_true", required=False, + parser.add_argument('--dac-in-secure-cert', action="store_true", help='Store DAC in secure cert partition. By default, DAC is stored in nvs factory partition.') parser.add_argument('-ds', '--ds-peripheral', action="store_true", help='Use DS Peripheral in generating secure cert partition.') @@ -603,6 +598,8 @@ def any_base_int(s): return int(s, 0) help='Encrypt the factory parititon NVS binary') parser.add_argument('--no-bin', action='store_false', dest='generate_bin', help='Do not generate the factory partition binary') + parser.add_argument('--output_dir', type=str, default='bin', help='Created image output file path') + parser.set_defaults(generate_bin=True) return parser.parse_args() @@ -620,21 +617,18 @@ def set_up_factory_data(args): if args.dac_key and not args.dac_in_secure_cert: gen_raw_ec_keypair_from_der(args.dac_key, FACTORY_DATA['dac-pub-key']['value'], FACTORY_DATA['dac-key']['value']) - if args.dac_key: - gen_raw_ec_keypair_from_der(args.dac_key, os.path.abspath('dac_raw_pubkey.bin'), os.path.abspath('dac_raw_privkey.bin')) def generate_factory_partiton_binary(args): generate_nvs_csv(FACTORY_PARTITION_CSV) if args.generate_bin: - generate_nvs_bin(args.encrypt, args.size, FACTORY_PARTITION_CSV, FACTORY_PARTITION_BIN) + generate_nvs_bin(args.encrypt, args.size, FACTORY_PARTITION_CSV, FACTORY_PARTITION_BIN, args.output_dir) print_flashing_help(args.encrypt, FACTORY_PARTITION_BIN) clean_up() def set_up_out_dirs(args): - OUT_DIR['top'] = os.sep.join(['out', 'bin']) - os.makedirs(OUT_DIR['top'], exist_ok=True) + os.makedirs(args.output_dir, exist_ok=True) def main():