예제 #1
0
def setup():
    # Optional: Launch a console monitor so we can
    # keep an eye on the underlying operations. We
    # use a terminal-based monitor here.
    mon = Monitor.create('term')

    # Connect to the target device's serial port
    console = Console('/dev/ttyUSB0', baudrate=115200, monitor=mon)

    # Create and return an initialized Depthcharge context
    return Depthcharge(console)
예제 #2
0
#!/usr/bin/env python3
import traceback
from depthcharge import Console, Depthcharge, log

ctx = None

try:
    console = Console('/dev/ttyUSB0', baudrate=115200)
    ctx = Depthcharge.load('my_device.cfg', console)

    # Comment out the above ctx creation and uncomment the following one in
    # order to possibly make more operations available to Depthcharge by allowing
    # it to deploy executable payloads to RAM and reboot/crash the platform.
    #ctx = Depthcharge(console, allow_deploy=True, allow_reboot=True)

    # Perform actions here

except Exception as error:
    log.error(str(error))

    # Shown if DEPTHCHARGE_LOG_LEVEL=debug in environment
    log.debug(traceback.format_exc())

finally:
    # Save any updates or new information to the device config
    if ctx:
        ctx.save('my_device.cfg')
예제 #3
0
#!/usr/bin/env python3
import traceback
from depthcharge import Console, Depthcharge, log

ctx = None

try:
    console = Console('/dev/ttyUSB0', baudrate=115200)
    ctx = Depthcharge(console, arch='arm')

    # Comment out the above ctx creation and uncomment the following one in
    # order to possibly make more operations available to Depthcharge by allowing
    # it to deploy executable payloads to RAM and reboot/crash the platform.
    #ctx = Depthcharge(console, allow_deploy=True, allow_reboot=True)

    # Perform actions here via API calls on ctx handle

except Exception as error:
    log.error(str(error))

    # Shown if DEPTHCHARGE_LOG_LEVEL=debug in environment
    log.debug(traceback.format_exc())

finally:
    # Save gathered information to a device configuration file
    if ctx:
        ctx.save('my_device.cfg')
예제 #4
0
    resp = ctx.send_command(cmd, check=True)
    log.note('Device response: ' + resp.strip())

    log.info('Reading RAM buffer to file: ' + filename)
    ctx.read_memory_to_file(load_addr, size, filename)


if __name__ == '__main__':
    config_file = 'my_device.cfg'
    ctx = None

    try:
        console = Console('/dev/ttyUSB0', baudrate=115200)

        if os.path.exists(config_file):
            ctx = Depthcharge.load(config_file, console)
        else:
            ctx = Depthcharge(console)

        # Check for the presence of commands and variables we'll use
        env = validate_requirements(ctx)

        # While technically unneccessary to convert enviornment variables to
        # integers here, only to then convert them back to strings when used
        # in a command, this affords a chance to confirm they are valid values
        # before we attempt to use them.
        read_nand_to_file(ctx, 'kernel.bin', env['image'],
                          int(env['loadaddr'], 0), int(env['kernel_offset'],
                                                       0),
                          int(env['kernel_size'], 0))
예제 #5
0
    log.info('Reading RAM buffer to file: ' + filename)
    ctx.read_memory_to_file(load_addr, size, filename)


if __name__ == '__main__':
    config_file = 'my_device.cfg'
    ctx = None

    try:
        console = Console('/dev/ttyUSB0', baudrate=115200)

        if os.path.exists(config_file):
            ctx = Depthcharge.load(config_file,
                                   console,
                                   arch='arm',
                                   allow_deploy=True,
                                   allow_reboot=True)
        else:
            ctx = Depthcharge(console,
                              arch='arm',
                              allow_deploy=True,
                              allow_reboot=True)

        # Check for the presence of commands and variables we'll use
        env = validate_requirements(ctx)

        # While technically unneccessary to convert enviornment variables to
        # integers here, only to then convert them back to strings when used
        # in a command, this affords a chance to confirm they are valid values
        # before we attempt to use them.
#!/usr/bin/env python3
import traceback
from depthcharge import Console, Depthcharge, log

ctx = None

try:
    console = Console('/dev/ttyUSB0', baudrate=115200)
    ctx = Depthcharge(console)

    # Perform actions here

except Exception as error:
    log.error(str(error))

    # Shown if DEPTHCHARGE_LOG_LEVEL=debug in environment
    log.debug(traceback.format_exc())

finally:
    # Save gathered information to a device configuration file
    if ctx:
        ctx.save('my_device.cfg')