Exemplo n.º 1
0
 def get_project_desc(args, ctx):
     desc_path = os.path.join(args.build_dir, "project_description.json")
     if not os.path.exists(desc_path):
         ensure_build_directory(args, ctx.info_name)
     with open(desc_path, "r") as f:
         project_desc = json.load(f)
         return project_desc
Exemplo n.º 2
0
 def flash(action, ctx, args):
     """
     Run esptool to flash the entire project, from an argfile generated by the build system
     """
     ensure_build_directory(args, ctx.info_name)
     esp_port = args.port or _get_default_serial_port(args)
     run_target(action, args, {'ESPBAUD': str(args.baud),'ESPPORT': esp_port})
Exemplo n.º 3
0
    def monitor(action, ctx, args, print_filter, monitor_baud, encrypted, timestamps, timestamp_format):
        """
        Run idf_monitor.py to watch build output
        """

        desc_path = os.path.join(args.build_dir, 'project_description.json')
        if not os.path.exists(desc_path):
            ensure_build_directory(args, ctx.info_name)
        with open(desc_path, 'r') as f:
            project_desc = json.load(f)

        elf_file = os.path.join(args.build_dir, project_desc['app_elf'])
        if not os.path.exists(elf_file):
            raise FatalError("ELF file '%s' not found. You need to build & flash the project before running 'monitor', "
                             'and the binary on the device must match the one in the build directory exactly. '
                             "Try '%s flash monitor'." % (elf_file, ctx.info_name), ctx)
        idf_monitor = os.path.join(os.environ['IDF_PATH'], 'tools/idf_monitor.py')
        monitor_args = [PYTHON, idf_monitor]
        esp_port = args.port or _get_default_serial_port(args)
        monitor_args += ['-p', esp_port]

        if not monitor_baud:
            monitor_baud = os.getenv('IDF_MONITOR_BAUD') or os.getenv('MONITORBAUD') or project_desc['monitor_baud']

        monitor_args += ['-b', monitor_baud]
        monitor_args += ['--toolchain-prefix', project_desc['monitor_toolprefix']]

        coredump_decode = get_sdkconfig_value(project_desc['config_file'], 'CONFIG_ESP_COREDUMP_DECODE')
        if coredump_decode is not None:
            monitor_args += ['--decode-coredumps', coredump_decode]

        target_arch_riscv = get_sdkconfig_value(project_desc['config_file'], 'CONFIG_IDF_TARGET_ARCH_RISCV')
        monitor_args += ['--target', project_desc['target']]
        revision = project_desc.get('rev')
        if revision:
            monitor_args += ['--revision', revision]

        if target_arch_riscv:
            monitor_args += ['--decode-panic', 'backtrace']

        if print_filter is not None:
            monitor_args += ['--print_filter', print_filter]
        monitor_args += [elf_file]

        if encrypted:
            monitor_args += ['--encrypted']

        if timestamps:
            monitor_args += ['--timestamps']

        if timestamp_format:
            monitor_args += ['--timestamp-format', timestamp_format]

        idf_py = [PYTHON] + _get_commandline_options(ctx)  # commands to re-run idf.py
        monitor_args += ['-m', ' '.join("'%s'" % a for a in idf_py)]

        if 'MSYSTEM' in os.environ:
            monitor_args = ['winpty'] + monitor_args

        run_tool('idf_monitor', monitor_args, args.project_dir)
Exemplo n.º 4
0
 def _get_project_desc(ctx, args):
     desc_path = os.path.join(args.build_dir, 'project_description.json')
     if not os.path.exists(desc_path):
         ensure_build_directory(args, ctx.info_name)
     with open(desc_path, 'r') as f:
         project_desc = json.load(f)
     return project_desc
Exemplo n.º 5
0
 def _get_project_desc(ctx: click.core.Context, args: PropertyDict) -> Any:
     desc_path = os.path.join(args.build_dir, 'project_description.json')
     if not os.path.exists(desc_path):
         ensure_build_directory(args, ctx.info_name)
     with open(desc_path, 'r') as f:
         project_desc = json.load(f)
     return project_desc
Exemplo n.º 6
0
    def monitor(action, ctx, args, print_filter):
        """
        Run idf_monitor.py to watch build output
        """
        if args.port is None:
            args.port = _get_default_serial_port()
        desc_path = os.path.join(args.build_dir, "project_description.json")
        if not os.path.exists(desc_path):
            ensure_build_directory(args, ctx.info_name)
        with open(desc_path, "r") as f:
            project_desc = json.load(f)

        elf_file = os.path.join(args.build_dir, project_desc["app_elf"])
        if not os.path.exists(elf_file):
            raise FatalError("ELF file '%s' not found. You need to build & flash the project before running 'monitor', "
                             "and the binary on the device must match the one in the build directory exactly. "
                             "Try '%s flash monitor'." % (elf_file, ctx.info_name))
        idf_monitor = os.path.join(os.environ["IDF_PATH"], "tools/idf_monitor.py")
        monitor_args = [PYTHON, idf_monitor]
        if args.port is not None:
            monitor_args += ["-p", args.port]
        monitor_args += ["-b", project_desc["monitor_baud"]]
        monitor_args += ["--toolchain-prefix", project_desc["monitor_toolprefix"]]

        if print_filter is not None:
            monitor_args += ["--print_filter", print_filter]
        monitor_args += [elf_file]

        idf_py = [PYTHON] + _get_commandline_options(ctx)  # commands to re-run idf.py
        monitor_args += ["-m", " ".join("'%s'" % a for a in idf_py)]

        if "MSYSTEM" in os.environ:
            monitor_args = ["winpty"] + monitor_args
        run_tool("idf_monitor", monitor_args, args.project_dir)
Exemplo n.º 7
0
    def build_target(target_name, ctx, args):
        """
        Execute the target build system to build target 'target_name'

        Calls ensure_build_directory() which will run cmake to generate a build
        directory (with the specified generator) as needed.
        """
        ensure_build_directory(args, ctx.info_name)
        run_target(target_name, args)
Exemplo n.º 8
0
    def monitor(action, ctx, args, print_filter, monitor_baud, encrypted):
        """
        Run idf_monitor.py to watch build output
        """
        if args.port is None:
            args.port = _get_default_serial_port()
        desc_path = os.path.join(args.build_dir, "project_description.json")
        if not os.path.exists(desc_path):
            ensure_build_directory(args, ctx.info_name)
        with open(desc_path, "r") as f:
            project_desc = json.load(f)

        elf_file = os.path.join(args.build_dir, project_desc["app_elf"])
        if not os.path.exists(elf_file):
            raise FatalError(
                "ELF file '%s' not found. You need to build & flash the project before running 'monitor', "
                "and the binary on the device must match the one in the build directory exactly. "
                "Try '%s flash monitor'." % (elf_file, ctx.info_name), ctx)
        idf_monitor = os.path.join(os.environ["IDF_PATH"],
                                   "tools/idf_monitor.py")
        monitor_args = [PYTHON, idf_monitor]
        if args.port is not None:
            monitor_args += ["-p", args.port]

        if not monitor_baud:
            if os.getenv("IDF_MONITOR_BAUD"):
                monitor_baud = os.getenv("IDF_MONITOR_BAUD", None)
            elif os.getenv("MONITORBAUD"):
                monitor_baud = os.getenv("MONITORBAUD", None)
            else:
                monitor_baud = project_desc["monitor_baud"]

        monitor_args += ["-b", monitor_baud]
        monitor_args += [
            "--toolchain-prefix", project_desc["monitor_toolprefix"]
        ]

        coredump_decode = get_sdkconfig_value(project_desc["config_file"],
                                              "CONFIG_ESP32_CORE_DUMP_DECODE")
        if coredump_decode is not None:
            monitor_args += ["--decode-coredumps", coredump_decode]

        if print_filter is not None:
            monitor_args += ["--print_filter", print_filter]
        monitor_args += [elf_file]

        if encrypted:
            monitor_args += ['--encrypted']

        idf_py = [PYTHON] + _get_commandline_options(
            ctx)  # commands to re-run idf.py
        monitor_args += ["-m", " ".join("'%s'" % a for a in idf_py)]

        if "MSYSTEM" in os.environ:
            monitor_args = ["winpty"] + monitor_args
        run_tool("idf_monitor", monitor_args, args.project_dir)
Exemplo n.º 9
0
 def set_target(action, ctx, args, idf_target):
     args.define_cache_entry.append("IDF_TARGET=" + idf_target)
     sdkconfig_path = os.path.join(args.project_dir, 'sdkconfig')
     sdkconfig_old = sdkconfig_path + ".old"
     if os.path.exists(sdkconfig_old):
         os.remove(sdkconfig_old)
     if os.path.exists(sdkconfig_path):
         os.rename(sdkconfig_path, sdkconfig_old)
     print("Set Target to: %s, new sdkconfig created. Existing sdkconfig renamed to sdkconfig.old." % idf_target)
     ensure_build_directory(args, ctx.info_name, True)
Exemplo n.º 10
0
    def flash(action, ctx, args):
        """
        Run esptool to flash the entire project, from an argfile generated by the build system
        """
        ensure_build_directory(args, ctx.info_name)
        if args.port is None:
            args.port = _get_default_serial_port()

        run_target(action, args, {"ESPPORT": args.port,
                                  "ESPBAUD": str(args.baud)})
Exemplo n.º 11
0
    def dfu_flash_target(target_name, ctx, args, path):
        ensure_build_directory(args, ctx.info_name)

        try:
            run_target(target_name, args, {"ESP_DFU_PATH": path})
        except FatalError:
            # Cannot capture the error from dfu-util here so the best advise is:
            print('Please have a look at the "Device Firmware Upgrade through USB" chapter in API Guides of the '
                  'ESP-IDF documentation for solving common dfu-util issues.')
            raise
Exemplo n.º 12
0
    def build_target(target_name: str, ctx: Context, args: PropertyDict) -> None:
        """
        Execute the target build system to build target 'target_name'

        Calls ensure_build_directory() which will run cmake to generate a build
        directory (with the specified generator) as needed.
        """
        hints = not args.no_hints
        ensure_build_directory(args, ctx.info_name)
        run_target(target_name, args, force_progression=GENERATORS[args.generator].get('force_progression', False), hints=hints)
Exemplo n.º 13
0
    def flash(action, ctx, args):
        """
        Run esptool to flash the entire project, from an argfile generated by the build system
        """
        ensure_build_directory(args, ctx.info_name)
        project_desc = _get_project_desc(ctx, args)
        if project_desc['target'] == 'linux':
            yellow_print('skipping flash since running on linux...')
            return

        esp_port = args.port or _get_default_serial_port(args)
        run_target(action, args, {'ESPBAUD': str(args.baud), 'ESPPORT': esp_port})
Exemplo n.º 14
0
 def ota_targets(target_name, ctx, args):
     """
     Execute the target build system to build target 'target_name'.
     Additionally set global variables for baud and port.
     Calls ensure_build_directory() which will run cmake to generate a build
     directory (with the specified generator) as needed.
     """
     args.port = args.port or _get_default_serial_port(args)
     ensure_build_directory(args, ctx.info_name)
     run_target(target_name, args, {
         'ESPBAUD': str(args.baud),
         'ESPPORT': args.port
     })
Exemplo n.º 15
0
    def size_target(target_name, ctx, args):
        """
        Builds the app and then executes a size-related target passed in 'target_name'.
        `tool_error_handler` handler is used to suppress errors during the build,
        so size action can run even in case of overflow.

        """
        def tool_error_handler(e):
            pass

        ensure_build_directory(args, ctx.info_name)
        run_target('all', args, custom_error_handler=tool_error_handler)
        run_target(target_name, args)
Exemplo n.º 16
0
    def fallback_target(target_name, ctx, args):
        """
        Execute targets that are not explicitly known to idf.py
        """
        ensure_build_directory(args, ctx.info_name)

        try:
            subprocess.check_output(GENERATORS[args.generator]["dry_run"] + [target_name], cwd=args.build_dir)

        except Exception:
            raise FatalError(
                'command "%s" is not known to idf.py and is not a %s target' % (target_name, args.generator))

        run_target(target_name, args)
Exemplo n.º 17
0
 def set_target(action, ctx, args, idf_target):
     if (not args["preview"] and idf_target in PREVIEW_TARGETS):
         raise FatalError(
             "%s is still in preview. You have to append '--preview' option after idf.py to use any preview feature."
             % idf_target)
     args.define_cache_entry.append("IDF_TARGET=" + idf_target)
     sdkconfig_path = os.path.join(args.project_dir, 'sdkconfig')
     sdkconfig_old = sdkconfig_path + ".old"
     if os.path.exists(sdkconfig_old):
         os.remove(sdkconfig_old)
     if os.path.exists(sdkconfig_path):
         os.rename(sdkconfig_path, sdkconfig_old)
     print("Set Target to: %s, new sdkconfig created. Existing sdkconfig renamed to sdkconfig.old." % idf_target)
     ensure_build_directory(args, ctx.info_name, True)
Exemplo n.º 18
0
 def set_target(action: str, ctx: Context, args: PropertyDict, idf_target: str) -> None:
     if (not args['preview'] and idf_target in PREVIEW_TARGETS):
         raise FatalError(
             "%s is still in preview. You have to append '--preview' option after idf.py to use any preview feature."
             % idf_target)
     args.define_cache_entry.append('IDF_TARGET=' + idf_target)
     sdkconfig_path = os.path.join(args.project_dir, 'sdkconfig')
     sdkconfig_old = sdkconfig_path + '.old'
     if os.path.exists(sdkconfig_old):
         os.remove(sdkconfig_old)
     if os.path.exists(sdkconfig_path):
         os.rename(sdkconfig_path, sdkconfig_old)
     print('Set Target to: %s, new sdkconfig created. Existing sdkconfig renamed to sdkconfig.old.' % idf_target)
     ensure_build_directory(args, ctx.info_name, True)
Exemplo n.º 19
0
    def build_target(target_name, ctx, args):
        """
        Execute the target build system to build target 'target_name'

        Calls ensure_build_directory() which will run cmake to generate a build
        directory (with the specified generator) as needed.
        """
        ensure_build_directory(args, ctx.info_name)
        generator_cmd = GENERATOR_CMDS[args.generator]

        if args.verbose:
            generator_cmd += [GENERATOR_VERBOSE[args.generator]]

        run_tool(generator_cmd[0], generator_cmd + [target_name],
                 args.build_dir)
Exemplo n.º 20
0
    def size_target(target_name: str, ctx: Context, args: PropertyDict) -> None:
        """
        Builds the app and then executes a size-related target passed in 'target_name'.
        `tool_error_handler` handler is used to suppress errors during the build,
        so size action can run even in case of overflow.

        """

        def tool_error_handler(e: int, stdout: str, stderr: str) -> None:
            print_hints(stdout, stderr)

        hints = not args.no_hints
        ensure_build_directory(args, ctx.info_name)
        run_target('all', args, force_progression=GENERATORS[args.generator].get('force_progression', False),
                   custom_error_handler=tool_error_handler, hints=hints)
        run_target(target_name, args)
Exemplo n.º 21
0
    def gdb(action, ctx, args, gdb_tui, gdbinit, require_openocd):
        """
        Synchronous GDB target
        """
        watch_openocd = Thread(target=_check_openocd_errors,
                               args=(
                                   fail_if_openocd_failed,
                                   action,
                                   ctx,
                               ))
        watch_openocd.start()
        processes['threads_to_join'].append(watch_openocd)
        desc_path = os.path.join(args.build_dir, 'project_description.json')
        if not os.path.exists(desc_path):
            ensure_build_directory(args, ctx.info_name)
        with open(desc_path, 'r') as f:
            project_desc = json.load(f)

        elf_file = os.path.join(args.build_dir, project_desc['app_elf'])
        if not os.path.exists(elf_file):
            raise FatalError(
                'ELF file not found. You need to build & flash the project before running debug targets',
                ctx)
        gdb = project_desc['monitor_toolprefix'] + 'gdb'
        local_dir = project_desc['build_dir']
        if gdbinit is None:
            gdbinit = os.path.join(local_dir, 'gdbinit')
            create_local_gdbinit(gdbinit, elf_file)
        args = [gdb, '-x={}'.format(gdbinit)]
        if gdb_tui is not None:
            args += ['-tui']
        t = Thread(target=run_gdb, args=(args, ))
        t.start()
        while True:
            try:
                t.join()
                break
            except KeyboardInterrupt:
                # Catching Keyboard interrupt, as this is used for breaking running program in gdb
                continue
            finally:
                watch_openocd.join()
                try:
                    processes['threads_to_join'].remove(watch_openocd)
                except ValueError:
                    # Valid scenario: watch_openocd task won't be in the list if openocd not started from idf.py
                    pass
Exemplo n.º 22
0
 def flash(action, ctx, args):
     """
     Run esptool to flash the entire project, from an argfile generated by the build system
     """
     ensure_build_directory(args, ctx.info_name)
     flasher_args_path = {
         # action -> name of flasher args file generated by build system
         "bootloader-flash": "flash_bootloader_args",
         "partition_table-flash": "flash_partition_table_args",
         "app-flash": "flash_app_args",
         "flash": "flash_project_args",
         "encrypted-app-flash": "flash_encrypted_app_args",
         "encrypted-flash": "flash_encrypted_project_args",
     }[action]
     esptool_args = _get_esptool_args(args)
     esptool_args += ["write_flash", "@" + flasher_args_path]
     run_tool("esptool.py", esptool_args, args.build_dir)
Exemplo n.º 23
0
    def fallback_target(target_name: str, ctx: Context, args: PropertyDict) -> None:
        """
        Execute targets that are not explicitly known to idf.py
        """
        ensure_build_directory(args, ctx.info_name)

        try:
            subprocess.check_output(GENERATORS[args.generator]['dry_run'] + [target_name], cwd=args.build_dir)

        except Exception:
            if target_name in ['clang-check', 'clang-html-report']:
                raise FatalError('command "{}" requires an additional plugin "pyclang". '
                                 'Please install it via "pip install --upgrade pyclang"'.format(target_name))

            raise FatalError(
                'command "%s" is not known to idf.py and is not a %s target' % (target_name, args.generator))

        run_target(target_name, args)
Exemplo n.º 24
0
    def gdb(action, ctx, args, gdb_tui, gdbinit, require_openocd):
        """
        Synchronous GDB target
        """
        watch_openocd = Thread(target=_check_openocd_errors,
                               args=(
                                   fail_if_openocd_failed,
                                   action,
                                   ctx,
                               ))
        watch_openocd.start()
        processes["threads_to_join"].append(watch_openocd)
        desc_path = os.path.join(args.build_dir, "project_description.json")
        if not os.path.exists(desc_path):
            ensure_build_directory(args, ctx.info_name)
        with open(desc_path, "r") as f:
            project_desc = json.load(f)

        elf_file = os.path.join(args.build_dir, project_desc["app_elf"])
        if not os.path.exists(elf_file):
            raise FatalError(
                "ELF file not found. You need to build & flash the project before running debug targets",
                ctx)
        gdb = project_desc["monitor_toolprefix"] + "gdb"
        local_dir = project_desc["build_dir"]
        if gdbinit is None:
            gdbinit = os.path.join(local_dir, 'gdbinit')
            create_local_gdbinit(gdbinit, elf_file)
        args = [gdb, '-x={}'.format(gdbinit)]
        if gdb_tui is not None:
            args += ['-tui']
        t = Thread(target=run_gdb, args=(args, ))
        t.start()
        while True:
            try:
                t.join()
                break
            except KeyboardInterrupt:
                # Catching Keyboard interrupt, as this is used for breaking running program in gdb
                continue
            finally:
                watch_openocd.join()
                processes["threads_to_join"].remove(watch_openocd)
Exemplo n.º 25
0
 def erase_flash(action, ctx, args):
     ensure_build_directory(args, ctx.info_name)
     esptool_args = _get_esptool_args(args)
     esptool_args += ['erase_flash']
     run_tool('esptool.py', esptool_args, args.build_dir)
Exemplo n.º 26
0
 def reconfigure(action, ctx, args):
     ensure_build_directory(args, ctx.info_name, True)
Exemplo n.º 27
0
 def dfu_target(target_name: str, ctx: Context, args: PropertyDict,
                part_size: str) -> None:
     ensure_build_directory(args, ctx.info_name)
     run_target(target_name, args,
                {'ESP_DFU_PART_SIZE': part_size} if part_size else {})
Exemplo n.º 28
0
 def dfu_list_target(target_name: str, ctx: Context,
                     args: PropertyDict) -> None:
     ensure_build_directory(args, ctx.info_name)
     run_target(target_name, args)
Exemplo n.º 29
0
 def dfu_target(target_name, ctx, args):
     ensure_build_directory(args, ctx.info_name)
     run_target(target_name, args)
Exemplo n.º 30
0
 def reconfigure(action: str, ctx: Context, args: PropertyDict) -> None:
     ensure_build_directory(args, ctx.info_name, True)