espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
12.99k stars 7.12k forks source link

ModuleNotFoundError: No module named 'parttool' when running otatool (IDFGH-4306) #6149

Closed ZweiEuro closed 3 years ago

ZweiEuro commented 3 years ago

Environment

Problem Description

Wrote OTA example native into my program, tried it out, succeeded. But then i couldn't upload locally anymore since it kept using the OTA'd version.

Parttool just straight up refuses to start (yes I have followed the instructions for installation trice and thoroughly) it keeps saying some py files are missing. Running:

git clone git@github.com:espressif/esp-idf.git
cd esp-idf
git checkout release/v4.0
./install.sh
. ./export.sh

following everything from otatool at https://github.com/espressif/esp-idf/tree/master/examples/system/ota/otatool

cd components/app_update/
./otatool.py

Result: Traceback (most recent call last): File "./otatool.py", line 29, in from parttool import PartitionName, PartitionType, ParttoolTarget, PARTITION_TABLE_OFFSET ModuleNotFoundError: No module named 'parttool'

Which of course causes https://github.com/espressif/esp-idf/tree/master/examples/system/ota/otatool to fail as well. With the same error.

So now i am stuck with a chip i can't change since the version on the ota doesn't have the ota yet.

So i tried using esptool to reset the whole thing with erase_flash and then re-> uploading with a partition table and the firmware.

Now it boots from the new firmware but produces this for spiffs: esp_err_t ret = esp_vfs_spiffs_register(&spiffs_conf); returns ESP_FAIL

and now i am stuck with a dead chip.

did OTA overwrite something ciritcal?

igrr commented 3 years ago

Hi @ZweiEuro, after re-uploading the partition table and new application, have you also uploaded the SPIFFS partition binary? Or is your intention to start from an empty SPIFFS partition?

ZweiEuro commented 3 years ago

@igrr I wanted to start with an all new spiffs since erase_flash just erases everything. My fault though was in esp_vgs_spiffs_conf_t .format_if_mount_failed was false, after changing it to true it works again. (Sorry that issue must've sounded serious )

I am still kinda bummed that I can't use the otatool to free the otadata but still, I now have a way to reset the whole chip if something fails

igrr commented 3 years ago

@ZweiEuro thanks for confirming that the SPIFFS part works. I've reopened the issue so that we can track fixing the otatool failure.

dobairoland commented 3 years ago

Hi @ZweiEuro.

cd components/app_update/
./otatool.py

At this point, do you have $IDF_PATH set? (i.e. echo $IDF_PATH shows a correct path)

Does the following command work for you (and points to the right IDF_PATH)? python -c 'import os; print(os.path.expandvars(os.path.join("$IDF_PATH", "components")))'

ZweiEuro commented 3 years ago

@dobairoland yes, IDF Path shows correctly where i have installed the esp-idf ( in my case /home/zweieuro/Documents/tools/esp-idf)

python -c 'import os; print(os.path.expandvars(os.path.join("$IDF_PATH", "components")))' returns /home/zweieuro/Documents/tools/esp-idf/components

Trying to use an otatool command directly (previously iwas trying it from the ota_example script): command reconstructed from https://github.com/espressif/esp-idf/blob/master/examples/system/ota/otatool/otatool_example.sh ./otatool.py -q --port /dev/ttyUSB0 erase_otadata

Running /home/zweieuro/.espressif/python_env/idf4.0_py3.8_env/bin/python /home/zweieuro/Documents/tools/esp-idf/components/esptool_py/esptool/esptool.py --port /dev/ttyUSB0 read_flash 32768 3072 /tmp/tmpicmy629e...
/home/zweieuro/.espressif/python_env/idf4.0_py3.8_env/bin/python: can't open file '/home/zweieuro/Documents/tools/esp-idf/components/esptool_py/esptool/esptool.py': [Errno 2] No such file or directory
An exception: ** Command '['/home/zweieuro/.espressif/python_env/idf4.0_py3.8_env/bin/python', '/home/zweieuro/Documents/tools/esp-idf/components/esptool_py/esptool/esptool.py', '--port', '/dev/ttyUSB0', 'read_flash', '32768', '3072', '/tmp/tmpicmy629e']' returned non-zero exit status 2. ** occurred in _call_esptool.
Traceback (most recent call last):
  File "./otatool.py", line 388, in <module>
    main()
  File "./otatool.py", line 339, in main
    target = OtatoolTarget(**target_args)
  File "./otatool.py", line 56, in __init__
    self.target = ParttoolTarget(port, baud, partition_table_offset, partition_table_file, esptool_args,
  File "/home/zweieuro/Documents/tools/esp-idf/components/partition_table/parttool.py", line 112, in __init__
    self._call_esptool(["read_flash", str(partition_table_offset), str(gen.MAX_PARTITION_LENGTH), temp_file.name])
  File "/home/zweieuro/Documents/tools/esp-idf/components/partition_table/parttool.py", line 139, in _call_esptool
    raise e
  File "/home/zweieuro/Documents/tools/esp-idf/components/partition_table/parttool.py", line 136, in _call_esptool
    subprocess.check_call(esptool_args, stdout=out, stderr=subprocess.STDOUT)
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/zweieuro/.espressif/python_env/idf4.0_py3.8_env/bin/python', '/home/zweieuro/Documents/tools/esp-idf/components/esptool_py/esptool/esptool.py', '--port', '/dev/ttyUSB0', 'read_flash', '32768', '3072', '/tmp/tmpicmy629e']' returned non-zero exit status 2.

Which reads like esptool wasn't installed properly?

dobairoland commented 3 years ago

@ZweiEuro The esptool issue is probably caused by not initializing the submodules. git submodule update --init --recursive should help.

ZweiEuro commented 3 years ago

@dobairoland after running your command and retrying ./otatool.py -q --port /dev/ttyUSB0 erase_otadata I still get:

Traceback (most recent call last):
  File "./otatool.py", line 29, in <module>
    from parttool import PartitionName, PartitionType, ParttoolTarget, PARTITION_TABLE_OFFSET
ModuleNotFoundError: No module named 'parttool'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./otatool.py", line 35, in <module>
    from parttool import PartitionName, PartitionType, ParttoolTarget, PARTITION_TABLE_OFFSET
ModuleNotFoundError: No module named 'parttool'
dobairoland commented 3 years ago

@ZweiEuro I'm sorry that I cannot give you a straight solution but this is new to me as well.

Can I ask you to try to run idf.py python-clean and see if it helps?

I can run your command successfully for IDFv4.0 you are using.

ZweiEuro commented 3 years ago

I no longer have access to the system that produced this error; Sorry but I can't debug this further (something else completley broke) Should I leave this issue open or close it ? @dobairoland

dobairoland commented 3 years ago

Thank you @ZweiEuro for the feedback. Yes, I'm closing this issue because I cannot reproduce it. Feel free to create a new one if you encounter this again.