with open(image_file, "wb") as image_obj: image_obj.write(image_data) ui.print_message("Storing FLASH image in {}".format(image_file)) def parse_args(): parser = ScriptArgumentsParser() parser.add_argument('bin_file', type=str, help='path to app binary') parser.add_argument('--image', metavar='image_file', dest='image_file', type=str, help='output file with FLASH image') parser.add_argument('--sw_version', metavar='sw_version_file', dest='sw_version_file', type=str, help='version file used for binary') parser.add_config_args() args = parser.parse_args() return args.bin_file, args.image_file, args.sw_version_file, args.header_config, \ args.flash_config if __name__ == '__main__': ui.print_header('PREPARE FLASH IMAGE') run_script(prepare_flash_image, parse_args) ui.print_footer('FINISHED')
cli_programmer, serial) else: report[STEP_CS_WRITE] = [ STATUS_NOT_RUN, 'Feature not enabled in configuration' ] __print_report(report) def parse_args(): parser = ScriptArgumentsParser() parser.add_interface_args() parser.add_argument('--secure_cfg', metavar='<file_path>', dest='secure_cfg_file', help='path to DA1469x-00 secure configuration file') parser.add_argument('--keys', metavar='<file_path>', dest='keys_file', help='path to DA1469x-00 keys file') args = parser.parse_args() cli, serial = parser.get_interface_from_args(args) return args.secure_cfg_file, args.keys_file, cli, serial if __name__ == '__main__': ui.print_header('PROGRAM PRODUCT KEYS AND CS (OTP)') run_script(secure_keys_prog, parse_args) ui.print_footer('FINISHED')
"Parameters available only for {}".format(args.prod_id)) group.add_argument('--sym_key_idx', help='index of symmetric key used in image encryption') group.add_argument('--nonce', help='nonce used in image encryption (AES CTR mode)') group.add_argument('--cs_sec_boot', choices=['enable', 'disable'], help='secure boot in CS') else: raise RuntimeError('No valid Product ID selected. Execution aborted.') def parse_args(): parser = ScriptArgumentsParser() parser.add_argument('-cfg', metavar='<configuration_file>', dest='configuration_file', help='configuration file') parser.add_argument('--product_keys', help='product keys file') parser.add_argument('--pub_key_idx', help='index of public key used in image signature ' 'verification') parser.add_argument('--key_revocations', nargs='+', help='indexes of keys to revoke') add_device_args(parser) args = parser.parse_args() return args.configuration_file, args.product_keys, args.prod_id, args.pub_key_idx, \ getattr(args, 'elliptic_curve', None), getattr(args, 'hash_method', None), \ args.key_revocations, getattr(args, 'min_version', None), \ getattr(args, 'sym_key_idx', None), getattr(args, 'nonce', None), \ getattr(args, 'cs_sec_boot', None) if __name__ == '__main__': ui.print_header('SECURE IMAGE CONFIGURATOR') run_script(secure_keys_cfg, parse_args) ui.print_footer('FINISHED')
SYMMETRIC_FW_DEC_KEYS_NUM[product_id], SYMMETRIC_FW_DEC_KEYS_LEN[product_id]): product_keys.add_symmetric_fw_dec_key(key=key) if not product_keys.is_valid(product_id): raise RuntimeError('Generated keys are invalid - cannot save file.') product_keys.save() def parse_args(): parser = ScriptArgumentsParser() parser.add_revision_args() parser.add_argument('-o', metavar='<file>', dest='output_file', help='output file') parser.add_argument('-ec', '--elliptic_curve', dest='elliptic_curve', help='elliptic curve (omitted for DA1469x devices)', choices=[e.value for e in ALLOWED_ELLIPTIC_CURVES]) args = parser.parse_args() return args.output_file, args.elliptic_curve, args.prod_id if __name__ == '__main__': ui.print_header('GENERATING PRODUCT KEYS') run_script(generate_keys, parse_args) ui.print_footer('FINISHED')
program_product_header(qspi_config, cli_programmer, serial) def parse_args(): parser = ScriptArgumentsParser() parser.add_interface_args() parser.add_argument('image_file', type=str, nargs='?', help='path to image') parser.add_argument('--secure_cfg', metavar='<file_path>', dest='secure_cfg_file', help='path to DA1469x-00 secure configuration file') parser.add_argument('--keys', metavar='<file_path>', dest='keys_file', help='path to DA1469x-00 keys file') parser.add_config_args() args = parser.parse_args() cli, serial = parser.get_interface_from_args(args) return args.image_file, args.secure_cfg_file, args.keys_file, cli, serial, args.header_config, \ args.flash_config if __name__ == '__main__': ui.print_header('PROGRAM SECURE IMAGE (QSPI)') run_script(secure_img_prog, parse_args) ui.print_footer('FINISHED')
ui.print_message("Product header can be programmed only on DA1469x-00 boards. Skipped.") if image_file is not None: ui.print_title("Programming image") cli_programmer.write_qspi_exec(image_file=image_file, serial_port=serial, silent=False) else: raise RuntimeError("No supported device selected ({})".format(qspi_config.product_id)) if image_file is None and prog_prod_header is False: ui.print_message("No image, no header selected. Nothing to do.") def parse_args(): parser = ScriptArgumentsParser() parser.add_interface_args() parser.add_argument('--prod_header', '-ph', action='store_true', help='program product header (DA1469x-00 only)') parser.add_argument('image_file', type=str, nargs='?', help='path to image') parser.add_config_args() args = parser.parse_args() cli, serial = parser.get_interface_from_args(args) return args.image_file, cli, serial, args.prod_header, args.header_config, args.flash_config if __name__ == '__main__': ui.print_header('PROGRAM QSPI') run_script(program_qspi, parse_args) ui.print_footer('FINISHED')
metavar='<jlink_path>', type=str, help='path to jlink') security_group = parser.add_argument_group('security options') security_group.add_argument('--secure_config', metavar='<security_cfg_path>', dest='secure_config', help='path to secure config') security_group.add_argument( '--keys', metavar='<keys_path>', dest='keys', help='path to keys to be written to OTP. This file is required ' 'also for secure image generation.') parser.add_argument('binary', metavar='<app_binary>', type=str, help='path to binary to flash') parser.add_revision_args() args = parser.parse_args() return args.binary, args.bootloader, args.nobootloader, args.cfg, args.device_id, \ args.jlink_path, args.secure_config, args.keys, args.prod_id if __name__ == '__main__': ui.print_header('INITIAL FLASH') run_script(initial_flash, parse_args) ui.print_footer("FINISHED")
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) sys.path.append(PROJECT_ROOT) from api import ui from api.script_base import run_script, ScriptArgumentsParser, prepare_cli_programmer_ini, ProductId def prepare_local_ini_file(cfg=None, prod_id=None, device_id=None, port=None, log=None, target_reset_cmd=None, jlink_path=None): prepare_cli_programmer_ini(cfg=cfg, prod_id=prod_id, device_id=device_id, port=port, log=log, target_reset_cmd=target_reset_cmd, jlink_path=jlink_path) def parse_args(): parser = ScriptArgumentsParser() parser.add_argument('--cfg', type=str, help='config path') parser.add_argument('--id', type=str, help='device serial number') parser.add_revision_args() parser.add_argument('--port', type=int, help='GDB port') parser.add_argument('--log', type=str, help='JLink log') parser.add_argument('--trc', type=str, help='target reset command') parser.add_argument('--jlink_path', type=str, help='JLink path') args = parser.parse_args() return args.cfg, args.prod_id, args.id, args.port, args.log, args.trc, args.jlink_path if __name__ == '__main__': run_script(prepare_local_ini_file, parse_args)
min_ver=True if secure_cfg.adm_minimal_version else False, ver=secure_cfg.adm_minimal_version) else: return Mkimage().single(binary_file, version_file, image_file) else: raise RuntimeError('No supported revision selected ().'.format(prod_id)) def parse_args(): parser = ScriptArgumentsParser() parser.add_argument('binary', metavar='bin_file', type=str, help='file with application binary') parser.add_argument('image', metavar='image_file', type=str, nargs='?', help='output file with image for SUOTA') parser.add_revision_args() parser.add_argument('--sw_version', metavar='sw_version_file', dest='sw_version_file', type=str, help='version file used for binary') parser.add_argument('-s', '--sec_cfg', metavar='security_config', dest='security_config_file', type=str, help='configuration file for secure image (forces secure image)') parser.add_argument('--prod_keys', metavar='product_keys', dest='keys_file', type=str, help='keys file for secure image') args = parser.parse_args() return args.binary, args.image, args.prod_id, args.sw_version_file, args.security_config_file, \ args.keys_file if __name__ == '__main__': run_script(mkimage, parse_args, suppress_errors=True)
'Insert Active FW image address (hex)') ui.print_title('Update FW Image Address\n') config.update_image_address = \ _setup_address(ProgramQspiConfig.UPDATE_FW_IMAGE_ADDRESS_TAG, 'Insert Update FW image address (hex)') config.save() def parse_args(): parser = ScriptArgumentsParser() parser.add_revision_args() parser.add_config_args() parser.add_argument('-sf', '--select_flash', type=str, help='preselect Flash type') parser.add_argument( '--default_img_addr', action='store_true', help='use default active and update fw image addresses') args = parser.parse_args() return args.prod_id, args.flash_config, args.header_config, args.select_flash, \ args.default_img_addr if __name__ == '__main__': ui.print_header('PROGRAM QSPI CONFIGURATOR') run_script(program_qspi_config, parse_args) ui.print_footer('FINISHED')
cli_programmer = CliProgrammer(cfg_path=cfg, prod_id=config.product_id, jlink_id=device_id) if not cfg: prepare_local_ini_file(cfg=cli_programmer.get_cfg(), device_id=device_id) project_path = os.path.join(project_output_path, '..') create_nvparam(project_output_path, [project_path + "/config", SDK_ROOT + "/sdk/middleware/adapters/include"], arm_gcc_path) nvparam_bin = os.path.join(project_output_path, 'nvparam.bin') cli_programmer.write_qspi(nvparam_address, nvparam_bin) def parse_args(): parser = ScriptArgumentsParser() parser.add_argument('--cfg', metavar='<cfg_path>', type=str, help='config path') parser.add_argument('--id', metavar='<serial_number>', type=str, help='device serial number') parser.add_argument('--arm_gcc_path', metavar='<arm_gcc_path>', type=str, help='path to cross compiler') parser.add_argument('path', metavar='<project_output_path>', type=str, help='folder which contains the binary you want to program') args = parser.parse_args() return args.path, args.cfg, args.id, args.arm_gcc_path if __name__ == '__main__': ui.print_header('PROGRAM QSPI NVPARAM') run_script(program_qspi_nvparam, parse_args) ui.print_footer('FINISHED')
raise RuntimeError("Unknown product id: " + str(prod_id)) try: script = tempfile.mktemp() make_reboot_script_file(script) jlink_exe.run(args=[ '-if', 'SWD', '-device', device, '-speed', 'adaptive', '-SelectEmuBySN', jlink_number, '-CommandFile', script ], silent=True) finally: os.remove(script) def parse_args(): parser = ScriptArgumentsParser() parser.add_revision_args() parser.add_argument('jlink_number', nargs='?', type=str, help='JLink number') parser.add_argument('--jlink_path', type=str, help='path to JLink') args = parser.parse_args() return args.prod_id, args.jlink_number, args.jlink_path if __name__ == '__main__': run_script(reboot_device, parse_args)
import os import sys PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) sys.path.append(PROJECT_ROOT) from api import ui from api.script_base import run_script, ScriptArgumentsParser, ExecutionCanceled, ProductId def erase_qspi_jtag(cli_programmer=None, serial=None): if ui.ask(text='Are you sure you want to completely erase QSPI?') is False: raise ExecutionCanceled() cli_programmer.chip_erase_qspi(serial_port=serial, silent=False) def parse_args(): parser = ScriptArgumentsParser() parser.add_interface_args() args = parser.parse_args() cli, serial = parser.get_interface_from_args(args) return cli, serial if __name__ == '__main__': ui.print_header('ERASE QSPI') run_script(erase_qspi_jtag, parse_args) ui.print_footer('FINISHED')