espressif / esptool

Espressif SoC serial bootloader utility
https://docs.espressif.com/projects/esptool
GNU General Public License v2.0
5.51k stars 1.37k forks source link

Intelhex check can prevent flashing of binary file. (ESPTOOL-855) #978

Closed tacozMacleo closed 4 months ago

tacozMacleo commented 4 months ago

Operating System

Fedora linux 40

Esptool Version

esptool.py v4.7.0 4.7.0

Python Version

Python 3.12.2

Full Esptool Command Line that Was Run

No response

Esptool Output

Traceback (most recent call last):
  File "/opt/esp/python_env/idf5.0_py3.8_env/bin/esptool.py", line 37, in <module>
    esptool._main()
  File "/opt/esp/python_env/idf5.0_py3.8_env/lib/python3.8/site-packages/esptool/__init__.py", line 1139, in _main
    main()
  File "/opt/esp/python_env/idf5.0_py3.8_env/lib/python3.8/site-packages/esptool/__init__.py", line 669, in main
    args = parser.parse_args(argv)
  File "/usr/lib/python3.8/argparse.py", line 1780, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.8/argparse.py", line 1812, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.8/argparse.py", line 2000, in _parse_known_args
    positionals_end_index = consume_positionals(start_index)
  File "/usr/lib/python3.8/argparse.py", line 1977, in consume_positionals
    take_action(action, args)
  File "/usr/lib/python3.8/argparse.py", line 1886, in take_action
    action(self, namespace, argument_values, option_string)
  File "/usr/lib/python3.8/argparse.py", line 1171, in __call__
    subnamespace, arg_strings = parser.parse_known_args(arg_strings, None)
  File "/usr/lib/python3.8/argparse.py", line 1812, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.8/argparse.py", line 2021, in _parse_known_args
    stop_index = consume_positionals(start_index)
  File "/usr/lib/python3.8/argparse.py", line 1977, in consume_positionals
    take_action(action, args)
  File "/usr/lib/python3.8/argparse.py", line 1886, in take_action
    action(self, namespace, argument_values, option_string)
  File "/opt/esp/python_env/idf5.0_py3.8_env/lib/python3.8/site-packages/esptool/__init__.py", line 1113, in __call__
    argfile = intel_hex_to_bin(argfile, address)
  File "/opt/esp/python_env/idf5.0_py3.8_env/lib/python3.8/site-packages/esptool/bin_image.py", line 51, in intel_hex_to_bin
    ih.loadhex(file.name)
  File "/opt/esp/python_env/idf5.0_py3.8_env/lib/python3.8/site-packages/intelhex/__init__.py", line 210, in loadhex
    for s in fobj:
  File "/usr/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 1: invalid continuation byte

What is the Expected Behaviour?

I expect that I can flash a bin-file that is encrypted, without have to ensure it do not randomly start with :.

More Information

by shire chance the encrypted bin file for the esp32 started with a :, and the esptool tries to parse it as a intel Hex-file. The file name do have the file-extension: .bin and NOT the .ihex or .rom that a intelhex-file could have.

Other Steps to Reproduce

No response

tacozMacleo commented 4 months ago

It looks like a workaround have been make for v4.8.dev2.