Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions scripts/west_commands/runners/esp32.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ def do_create(cls, cfg, args):
if args.esp_tool:
espidf = args.esp_tool
else:
espidf = path.join(args.esp_idf_path, 'tools', 'esptool_py',
'esptool.py')

espidf = os.path.normpath(path.join(args.esp_idf_path, 'tools', 'esptool_py',
'esptool.py')).replace('\\', '/')
return Esp32BinaryRunner(
cfg, args.esp_device, boot_address=args.esp_boot_address,
part_table_address=args.esp_partition_table_address,
Expand All @@ -105,7 +104,10 @@ def do_create(cls, cfg, args):
encrypt=args.esp_encrypt, no_stub=args.esp_no_stub)

def do_run(self, command, **kwargs):
self.require(self.espidf)
if not os.path.exists(self.espidf):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? self.require() should do exactly that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.require(self.espidf) fails with the following error:

FATAL ERROR: required program C:/Users/user/workspace/zephyrproject/external/modules/hal/espressif/tools/esptool_py/esptool.py not found; install it or add its location to PATH

Even though esptool.py does exist at the specified path, the error occurs because shutil.which()—used internally by self.require()—only resolves executables with extensions like .exe, .bat, .cmd, etc., on Windows. Python scripts (.py) are not included in that search.

An alternative (though not included here) would be to modify core.py and replace:

ret = shutil.which(program, path=path)

with:

ret = os.path.abspath(program)

However, this may have wider implications in other parts of the system and would require more extensive testing. Therefore, this PR opts for the safer workaround without touching core components.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add an optional parameter to require() instead that makes it only check for the existence of the file? then you don't affect the rest but you keep using the standard method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I follow you correctly, you mean to do something like this?

def require(self, program, check_path_only=False):

    if check_path_only:
        if not os.path.exists(program):
            ret = program
    else:
        ret = shutil.which(program, path=path)

     if ret is None:
            raise MissingProgram(program)
        ...

self.logger.error(f"Expected esptool.py at: {self.espidf}")
raise RuntimeError("Cannot continue without esptool.py")


# Add Python interpreter
cmd_flash = [sys.executable, self.espidf, '--chip', 'auto']
Expand Down
Loading