mirror of
https://github.com/espressif/esptool.git
synced 2025-10-18 18:01:15 +08:00
fix(merge_bin): treat files starting with colon as raw files
This commit is contained in:

committed by
Radim Karniš

parent
bdeec68cb6
commit
2c0a5daa7b
@@ -13,7 +13,7 @@ import struct
|
||||
import tempfile
|
||||
from typing import BinaryIO, Optional
|
||||
|
||||
from intelhex import IntelHex
|
||||
from intelhex import HexRecordError, IntelHex
|
||||
|
||||
from .loader import ESPLoader
|
||||
from .targets import (
|
||||
@@ -47,14 +47,18 @@ def intel_hex_to_bin(file: BinaryIO, start_addr: Optional[int] = None) -> Binary
|
||||
INTEL_HEX_MAGIC = b":"
|
||||
magic = file.read(1)
|
||||
file.seek(0)
|
||||
if magic == INTEL_HEX_MAGIC:
|
||||
ih = IntelHex()
|
||||
ih.loadhex(file.name)
|
||||
file.close()
|
||||
bin = tempfile.NamedTemporaryFile(suffix=".bin", delete=False)
|
||||
ih.tobinfile(bin, start=start_addr)
|
||||
return bin
|
||||
else:
|
||||
try:
|
||||
if magic == INTEL_HEX_MAGIC:
|
||||
ih = IntelHex()
|
||||
ih.loadhex(file.name)
|
||||
file.close()
|
||||
bin = tempfile.NamedTemporaryFile(suffix=".bin", delete=False)
|
||||
ih.tobinfile(bin, start=start_addr)
|
||||
return bin
|
||||
else:
|
||||
return file
|
||||
except HexRecordError:
|
||||
# file started with HEX magic but the rest was not according to the standard
|
||||
return file
|
||||
|
||||
|
||||
|
@@ -263,6 +263,16 @@ class TestMergeBin:
|
||||
# verify the file itself
|
||||
assert source == merged_bin[0x1000:]
|
||||
|
||||
def test_hex_header_raw_file(self):
|
||||
# use raw binary file starting with colon
|
||||
with tempfile.NamedTemporaryFile(delete=False) as f:
|
||||
f.write(b":")
|
||||
try:
|
||||
merged = self.run_merge_bin("esp32", [(0x0, f.name)])
|
||||
assert merged == b":"
|
||||
finally:
|
||||
os.unlink(f.name)
|
||||
|
||||
|
||||
class UF2Block(object):
|
||||
def __init__(self, bs):
|
||||
|
Reference in New Issue
Block a user