Exemple #1
0
def test_format_data():
    data = bytes(range(20))
    expect_8 = "00 01 02 03 04 05 06 07\n08 09 0a 0b 0c 0d 0e 0f\n10 11 12 13"
    assert expect_8 == utils.format_raw_data(data,
                                             use_hexdump=False,
                                             line_length=8)
    expect_16 = "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n10 11 12 13"
    assert expect_16 == utils.format_raw_data(data,
                                              use_hexdump=False,
                                              line_length=16)
Exemple #2
0
def read_register(
    ctx: click.Context,
    address: int,
    item_length: int,
    count: int,
    file: click.File,
    use_hexdump: bool,
) -> None:
    """Reads the contents of a memory location or register value.

    The address of the register or memory location should be passed in as the first argument.
    Optional arguments include the data format of the register value in the number of bits
    and number of bytes to read.

    \b
    ADDRESS - starting address where to read
    FORMAT  - bits per item: valid values: 8, 16, 32; default 32
    COUNT   - bytes to read; default size of FORMAT
    FILE    - write data into a file; write to stdout if not specified
    """
    with SDP(ctx.obj["interface"]) as sdp:
        response = sdp.read_safe(address, count, item_length)
    if not response:
        click.echo(
            f"Error: invalid sub-command or arguments 'read-register {address:#8X} {item_length} {count}'"
        )
        sys.exit(1)
    if file:
        file.write(response)  # type: ignore
    else:
        click.echo(format_raw_data(response, use_hexdump=use_hexdump))
    display_output([], sdp.hab_status, ctx.obj["use_json"])
Exemple #3
0
def read_register(ctx: click.Context, address: int, item_length: int, count: int,
                  file: click.File, use_hexdump: bool) -> None:
    """Read one or more registers.

    \b
    ADDRESS - starting address where to read
    FORMAT  - bits per item: valid values: 8, 16, 32; default 32
    COUNT   - items to read; default 1
    FILE    - write data into a file; write to stdout if not specified
    """
    with SDP(ctx.obj['interface']) as sdp:
        response = sdp.read_safe(address, count, item_length)
    if not response:
        click.echo(f"Error: invalid command or arguments 'read-register {address:#8X} {item_length} {count}'")
        sys.exit(1)
    if file:
        file.write(response)  # type: ignore
    else:
        click.echo(format_raw_data(response, use_hexdump=use_hexdump))
    display_output([], sdp.response_value, ctx.obj['use_json'])
Exemple #4
0
def read_memory(ctx: click.Context, address: int, byte_count: int,
                out_file: click.File, memory_id: int,
                use_hexdump: bool) -> None:
    """Read memory.

    \b
    ADDRESS     - starting address
    BYTE_COUNT  - number of bytes to read
    FILE        - store result into this file, if not specified use stdout
    MEMORY_ID   - id of memory to read from (default: 0)
    """
    with McuBoot(ctx.obj['interface']) as mboot:
        response = mboot.read_memory(address, byte_count, memory_id)
    assert response, "Error reading memory"
    if out_file:
        out_file.write(response)  # type: ignore
    else:
        click.echo(format_raw_data(response, use_hexdump=use_hexdump))

    display_output([len(response)], mboot.status_code, ctx.obj['use_json'],
                   f"Read {len(response)} of {byte_count} bytes.")