Ejemplo n.º 1
0
        ctx.obj = {
            'protocol': protocol,
            'debug_mailbox':
                DebugMailbox(
                    debug_probe=debug_probe, reset=reset, moredelay=timing
                ) if '--help' not in click.get_os_args() else None,
        }

    except DebugProbeError as exc:
        logger.error(str(exc))

    return 0


@main.command()
@click.option('-b', '--beacon', type=INT(), help='Authentication beacon')
@click.option('-c', '--certificate', help='Path to Debug Credentials.')
@click.option('-k', '--key', help='Path to DCK private key.')
@click.option('-f', '--force', is_flag=True, default=True)
@click.pass_obj
def auth(pass_obj: dict, beacon: int, certificate: str, key: str, force: bool) -> None:
    """Perform the Debug Authentication."""
    try:
        logger.info("Starting Debug Authentication")
        mail_box = pass_obj['debug_mailbox']
        with open(certificate, 'rb') as f:
            debug_cred_data = f.read()
        debug_cred = DebugCredential.parse(debug_cred_data)
        dac_data = dm_commands.DebugAuthenticationStart(dm=mail_box).run()
        # convert List[int] to bytes
        dac_data_bytes = struct.pack(f'<{len(dac_data)}I', *dac_data)
Ejemplo n.º 2
0
    }
    return 0


@main.command()
@click.pass_context
def error_status(ctx: click.Context) -> None:
    """Get error code of last operation."""
    with SDP(ctx.obj['interface']) as sdp:
        response = sdp.read_status()
    display_output([response], sdp.response_value, ctx.obj['use_json'],
                   f"Response status = {decode_status_code(response)}.")


@main.command()
@click.argument('address', type=INT(), required=True)
@click.pass_context
def jump_address(ctx: click.Context, address: int) -> None:
    """Jump to entry point of image with IVT at specified address.

    \b
    ADDRESS - starting address of the image
    """
    with SDP(ctx.obj['interface']) as sdp:
        sdp.jump_and_run(address)
    display_output([], sdp.response_value)


@main.command()
@click.argument('address', type=INT(), required=True)
@click.argument('bin_file',
Ejemplo n.º 3
0
            interface=selected_probe.interface,
            hardware_id=selected_probe.hardware_id)
        debug_probe.open()

        ctx.obj = {'debug_probe': debug_probe}

    except:
        logger.error("Test of SPSDK debug probes failed")
        return -1
    return 0


@main.command()
@click.option('-a',
              '--address',
              type=INT(),
              help='Testing address',
              default="0x20000000")
@click.option('-s',
              '--size',
              type=INT(),
              help='Testing block size',
              default="1")
@click.pass_obj
def regs(pass_obj: dict, address: int, size: int) -> None:
    """Test Shadow registers."""
    if size == 0:
        logger.error("Invalid test vector size")
        return
    error_cnt = 0
Ejemplo n.º 4
0
    metavar='VERSION',
    default='1.0',
    help=f'Set the protocol version. Default is 1.0 (RSA). '
    f'Available options are: {", ".join(PROTOCOL_VERSIONS)}',
    type=click.Choice(PROTOCOL_VERSIONS),
)
@click.option('-d',
              '--debug',
              'log_level',
              metavar='LEVEL',
              default='debug',
              help=f'Set the level of system logging output. '
              f'Available options are: {", ".join(LOG_LEVEL_NAMES)}',
              type=click.Choice(LOG_LEVEL_NAMES))
@click.option('-t', '--timing', type=float, default=0.0)
@click.option('-s', '--serial-no', type=INT())
@click.option('-ip', '--ip', 'ip_addr')
@click.option('--pemicroid', 'hardware_id')
@click.option('-n', '--no-reset', 'reset', is_flag=True, default=True)
@click.version_option(spsdk_version, '-v', '--version')
@click.help_option('--help')
@click.pass_context
def main(ctx: click.Context, interface: str, protocol: str, log_level: str,
         timing: float, serial_no: int, ip_addr: str, hardware_id: str,
         reset: bool) -> int:
    """NXP Debug Mailbox Tool."""
    logging.basicConfig(level=log_level.upper())
    logger.setLevel(level=log_level.upper())

    ctx.obj = {
        'protocol':
Ejemplo n.º 5
0
                click.echo(ctx.command.commands['get-property'].help)   # type: ignore
                ctx.exit(0)

    # if --help is provided anywhere on commandline, skip interface lookup and display help message
    if not '--help' in click.get_os_args():
        ctx.obj = {
            'interface': get_interface(
                module='mboot', port=port, usb=usb, timeout=timeout
            ),
            'use_json': use_json
        }
    return 0


@main.command()
@click.argument('address', type=INT(), required=True)
@click.argument('argument', type=INT(), required=True)
@click.pass_context
def call(ctx: click.Context, address: int, argument: int) -> None:
    """Invoke code that the ADDRESS, passing single ARGUMENT to it.

    \b
    ADDRESS     - function code address
    ARGUMENT    - argument for the function
    """
    with McuBoot(ctx.obj['interface']) as mboot:
        mboot.call(address, argument)
        display_output([], mboot.status_code, ctx.obj['use_json'])


@main.command()
Ejemplo n.º 6
0
    ctx.obj = {
        "protocol": protocol,
        "interface": interface,
        "serial_no": serial_no,
        "debug_probe_params": probe_user_params,
        "timing": timing,
        "reset": reset,
        "operation_timeout": operation_timeout,
    }

    return 0


@main.command()
@click.option("-b", "--beacon", type=INT(), help="Authentication beacon")
@click.option("-c", "--certificate", help="Path to Debug Credentials.")
@click.option("-k", "--key", help="Path to DCK private key.")
@click.option(
    "-n",
    "--no-exit",
    is_flag=True,
    help="When used, exit debug mailbox command is not executed after debug authentication.",
)
@click.pass_obj
def auth(pass_obj: dict, beacon: int, certificate: str, key: str, no_exit: bool) -> None:
    """Perform the Debug Authentication."""
    try:
        logger.info("Starting Debug Authentication")
        with _open_debugmbox(pass_obj) as mail_box:
            with open(certificate, "rb") as f:
Ejemplo n.º 7
0
    """Utility for communication with bootloader on target."""
    logging.basicConfig(level=log_level or logging.WARNING)
    # if --help is provided anywhere on commandline, skip interface lookup and display help message
    if '--help' in sys.argv:
        port, usb = None, None  # type: ignore
    ctx.obj = {
        'interface': get_interface(
            module='mboot', port=port, usb=usb, timeout=timeout
        ) if port or usb else None,
        'use_json': use_json
    }
    return 0


@main.command()
@click.argument('memory_id', type=INT(), required=True)
@click.argument('address', type=INT(), required=True)
@click.pass_context
def configure_memory(ctx: click.Context, address: int, memory_id: int) -> None:
    """Apply configuration block at internal memory address <ADDRESS> to memory with ID <MEMORY_ID>.

    \b
    MEMORY_ID   - id of memory
    ADDRESS     - starting address
    """
    with McuBoot(ctx.obj['interface']) as mboot:
        mboot.configure_memory(address, memory_id)  # type: ignore
        display_output([], mboot.status_code, ctx.obj['use_json'])


@main.command()
Ejemplo n.º 8
0
@main.command()
@click.pass_context
def error_status(ctx: click.Context) -> None:
    """Reads the error code from the device."""
    with SDP(ctx.obj["interface"]) as sdp:
        response = sdp.read_status()
    display_output(
        [response],
        sdp.hab_status,
        ctx.obj["use_json"],
        extra_output=f"Response status = {decode_status_code(response)}.",
    )


@main.command()
@click.argument("address", type=INT(), required=True)
@click.pass_context
def jump_address(ctx: click.Context, address: int) -> None:
    """Jumps to the entry point of the image at the given address.

    jump-address will result in the execution of the image once the ROM process
    the IVT and on successful authentication of the image.

    \b
    ADDRESS - starting address of the image
    """
    with SDP(ctx.obj["interface"]) as sdp:
        sdp.jump_and_run(address)
    display_output([], sdp.hab_status)