Skip to content

Commit

Permalink
telink update mfg_tool and merge_factorydata_dac
Browse files Browse the repository at this point in the history
to fix code style issues.

Signed-off-by: Damien Ji <[email protected]>
  • Loading branch information
damien0x0023 committed Jan 10, 2025
1 parent 8ca9ce4 commit 9bac534
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
23 changes: 16 additions & 7 deletions scripts/tools/telink/merge_factorydata_dac.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

import argparse

def merge_factorydata_dac(factory_data_ext_path, dac_cert_key_path, dac_cert_start_address, output_path):

def merge_factorydata_dac(factory_data_ext_path, dac_cert_key_path,
dac_cert_start_address, output_path):
# Read the content of the factory_data_ext.bin
with open(factory_data_ext_path, 'rb') as f:
factory_data_ext = f.read()
Expand All @@ -59,19 +61,26 @@ def merge_factorydata_dac(factory_data_ext_path, dac_cert_key_path, dac_cert_sta

print(f"Firmware merged successfully into {output_path}")


def main():
# Setup argument parser
parser = argparse.ArgumentParser(description='Merge firmware files.')
parser.add_argument('factory_data_ext_path', type=str, help='Path to the factory_data_ext.bin file')
parser.add_argument('dac_cert_key_path', type=str, help='Path to the dac_cert_key.bin file')
parser.add_argument('dac_cert_start_address', type=lambda x: int(x, 0), help='Start address for dac_cert_key.bin (e.g., 0x800)')
parser.add_argument('output_path', default="merged_factorydata_dac.bin", type=str, help='Path to the output merged firmware file')
parser.add_argument('factory_data_ext_path', type=str,
help='Path to the factory_data_ext.bin file')
parser.add_argument('dac_cert_key_path', type=str,
help='Path to the dac_cert_key.bin file')
parser.add_argument('dac_cert_start_address', type=lambda x: int(x, 0),
help='Start address for dac_cert_key.bin (e.g., 0x800)')
parser.add_argument('output_path', default="merged_factorydata_dac.bin",
type=str, help='Path to the output merged firmware file')

# Parse the arguments
args = parser.parse_args()

# Call the merge function with the provided arguments
merge_factorydata_dac(args.factory_data_ext_path, args.dac_cert_key_path, args.dac_cert_start_address, args.output_path)
merge_factorydata_dac(args.factory_data_ext_path, args.dac_cert_key_path,
args.dac_cert_start_address, args.output_path)


if __name__ == '__main__':
main()
main()
10 changes: 5 additions & 5 deletions scripts/tools/telink/mfg_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import cryptography.hazmat.backends
import cryptography.x509
import pyqrcode
from intelhex import IntelHex
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from intelhex import IntelHex

TOOLS = {
'spake2p': None,
Expand Down Expand Up @@ -457,7 +457,7 @@ def write_device_unique_data(args, out_dirs, pai_cert):
dacs = use_dac_cert_from_args(args, out_dirs)
else:
dacs = generate_dac_cert(int(row['Index']), args, out_dirs, int(row['Discriminator']),
int(row['PIN Code']), pai_cert['key_pem'], pai_cert['cert_pem'])
int(row['PIN Code']), pai_cert['key_pem'], pai_cert['cert_pem'])
dac_cert_storage = read_der_file(dacs[0])
dac_key_storage = read_key_bin_file(dacs[1])
if not args.secure_programming_verification:
Expand Down Expand Up @@ -744,10 +744,10 @@ def base64_str(s): return base64.b64decode(s)

secure_args = parser.add_argument_group('Secure programming verification options')
secure_args.add_argument("--secure-programming-verification", action="store_true",
help="Enable secure programming mode. When set, the script will perform additional steps for secure programming verification.")
help="Enable secure programming mode. When set, the script will perform additional steps for secure programming verification.")
secure_args.add_argument("--chip-id", required=False, type=str, help="Chip ID in hex format (32 hex characters).")
secure_args.add_argument("--disable_serial_num_storage", action="store_true",
help="Disable storage of serial-num in factorydata.")
help="Disable storage of serial-num in factorydata.")

args = parser.parse_args()

Expand Down

0 comments on commit 9bac534

Please sign in to comment.