コード例 #1
0
def call(commands=None, config=None, search=None, blocking=True, silent=False):
    commands = utils.listify(commands)
    config = utils.listify(config)
    search = utils.listify(search)
    if silent:
        commands.append("log_output /dev/null")

    # Provide additional search paths via the OPENOCD_SCRIPTS environment variable
    # See http://openocd.org/doc/html/Running.html
    # os.environ.get("OPENOCD_SCRIPTS", "")

    command_openocd = "openocd {} {} {}".format(
        " ".join(map('-s "{}"'.format, search)),
        " ".join(map('-f "{}"'.format, config)),
        " ".join(map('-c "{}"'.format, commands))
    )
    # print(command_openocd)

    if blocking:
        return subprocess.call(command_openocd, cwd=os.getcwd(), shell=True)
    else:
        # We have to start openocd in its own session ID, so that Ctrl-C in GDB
        # does not kill OpenOCD. See https://github.com/RIOT-OS/RIOT/pull/3619.
        return subprocess.Popen(command_openocd, cwd=os.getcwd(), shell=True,
                                preexec_fn=os.setsid)
コード例 #2
0
ファイル: openocd.py プロジェクト: ozetroc/modm
def call(commands=None, config=None, search=None, blocking=True, silent=False):
    commands = utils.listify(commands)
    config = utils.listify(config)
    search = utils.listify(search)
    if silent:
        null_file = "nul" if "Windows" in platform.platform() else "/dev/null"
        commands.append("log_output " + null_file)

    # Provide additional search paths via the OPENOCD_SCRIPTS environment variable
    # See http://openocd.org/doc/html/Running.html
    # os.environ.get("OPENOCD_SCRIPTS", "")

    command_openocd = "openocd {} {} {}".format(
        " ".join(map('-s "{}"'.format, search)),
        " ".join(map('-f "{}"'.format, config)),
        " ".join(map('-c "{}"'.format, commands))
    )
    # print(command_openocd)

    kwargs = {"cwd": os.getcwd(), "shell": True}
    if blocking:
        return subprocess.call(command_openocd, **kwargs)
    # We have to start openocd in its own session ID, so that Ctrl-C in GDB
    # does not kill OpenOCD. See https://github.com/RIOT-OS/RIOT/pull/3619.
    if "Windows" in platform.platform():
        kwargs["creationflags"] = subprocess.CREATE_NEW_PROCESS_GROUP
    else:
        kwargs["preexec_fn"] = os.setsid
    return subprocess.Popen(command_openocd, **kwargs)
コード例 #3
0
def program(source, device, programmer, port=None, baudrate=None, fuses=None, options=None):
    command = ["avrdude", "-V", "-p {}".format(device), "-c {}".format(programmer)]

    # Attempt to find a serial port automatically
    if port == "auto" and baudrate:
        port = utils.guess_serial_port(programmer)

    if port is not None:
        command.append("-P {}".format(port))
    if baudrate is not None:
        command.append("-b {}".format(baudrate))

    with open(str(source), "rb") as src:
        elffile = ELFFile(src)
        sections = [section.name for section in elffile.iter_sections()]

    command.append("-U flash:w:{}".format(source))
    if ".eeprom" in sections:
        command.append("-U eeprom:w:{}".format(source))
    for fuse in utils.listify(fuses):
        command.append("-U {}:w:{}".format(fuse, source))
    command += utils.listify(options)

    command = " ".join(command)
    # print(command)
    subprocess.call(command, cwd=os.getcwd(), shell=True)
コード例 #4
0
def scan(basepath, extensions, ignorePaths=None, ignoreFiles=None):
    ignoreFiles = utils.listify(ignoreFiles)
    if ignorePaths is not None and len(ignorePaths):
        ignorePaths = [
            relpath(p, basepath) if isabs(p) else p
            for p in utils.listify(ignorePaths)
        ]
        ignoreFiles += [join(f, "**/*") for f in ignorePaths]
    files = set(
        str(p) for ext in utils.listify(extensions)
        for p in Path(basepath).glob("**/*{}".format(ext)))
    files -= set(
        str(p) for ign in utils.listify(ignoreFiles)
        for p in Path(basepath).glob(ign))
    return sorted(list(files))
コード例 #5
0
def call(source=None, config=None, commands=None, backend=None, ui=None):
    if backend is None:
        backend = bem.Empty()
    source = utils.listify(source)
    if len(source): source = source[0]
    else: source = None

    # Build GBD config and command
    args = list(map('-ex "{}"'.format, utils.listify(backend.init(source))))
    args += list(map('-x "{}"'.format, utils.listify(config)))
    args += list(map('-ex "{}"'.format, utils.listify(commands)))

    # Build complete command string
    if ui is None:
        gdb_command = 'arm-none-eabi-gdb -nx --batch {args} {source}'
    elif 'tui' in ui:
        gdb_command = 'arm-none-eabi-gdb -tui ' \
                '-ex "layout split" ' \
                '-ex "focus cmd" ' \
                '{args} ' \
                '-ex "refresh" ' \
                '{source}'
    elif 'web' in ui:
        gdb_command = 'gdbgui {source} ' \
                '-g arm-none-eabi-gdb ' \
                "--gdb-args='{args} {source}'"
    else:
        raise ValueError("Unknown UI mode! '{}'".format(ui))

    gdb_command = gdb_command.format(source="" if source is None else source,
                                     args=" ".join(args))

    # Start Backend in the background
    with bem.Scope(backend) as b:
        try:
            # This call is now blocking
            subprocess.call(gdb_command, cwd=os.getcwd(), shell=True)
        except KeyboardInterrupt:
            pass

    return True
コード例 #6
0
ファイル: bossac.py プロジェクト: henrikssn/modm
def program(source, offset=None, port=None, erase=False, options=None):
    command = ["bossac", "-b", "-R"]

    # Attempt to find a serial port automatically
    if port == "auto":
        port = utils.guess_serial_port("bossac")

    if port is not None:
        command.append("--port={}".format(port))

    if offset is not None:
        command.append("--offset={}".format(offset))

    if erase:
        command.append("-e")

    command.extend(utils.listify(options))
    command.extend(["-v", "-w", str(source)])

    command = " ".join(command)
    # print(command)
    subprocess.call(command, cwd=os.getcwd(), shell=True)
コード例 #7
0
 def __init__(self, commands=None, config=None, search=None):
     self.commands = utils.listify(commands)
     self.config = utils.listify(config)
     self.search = utils.listify(search)
     self.process = None