mirror of
https://github.com/espressif/esptool.git
synced 2025-10-20 13:23:38 +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
|
import tempfile
|
||||||
from typing import BinaryIO, Optional
|
from typing import BinaryIO, Optional
|
||||||
|
|
||||||
from intelhex import IntelHex
|
from intelhex import HexRecordError, IntelHex
|
||||||
|
|
||||||
from .loader import ESPLoader
|
from .loader import ESPLoader
|
||||||
from .targets import (
|
from .targets import (
|
||||||
@@ -47,6 +47,7 @@ def intel_hex_to_bin(file: BinaryIO, start_addr: Optional[int] = None) -> Binary
|
|||||||
INTEL_HEX_MAGIC = b":"
|
INTEL_HEX_MAGIC = b":"
|
||||||
magic = file.read(1)
|
magic = file.read(1)
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
|
try:
|
||||||
if magic == INTEL_HEX_MAGIC:
|
if magic == INTEL_HEX_MAGIC:
|
||||||
ih = IntelHex()
|
ih = IntelHex()
|
||||||
ih.loadhex(file.name)
|
ih.loadhex(file.name)
|
||||||
@@ -56,6 +57,9 @@ def intel_hex_to_bin(file: BinaryIO, start_addr: Optional[int] = None) -> Binary
|
|||||||
return bin
|
return bin
|
||||||
else:
|
else:
|
||||||
return file
|
return file
|
||||||
|
except HexRecordError:
|
||||||
|
# file started with HEX magic but the rest was not according to the standard
|
||||||
|
return file
|
||||||
|
|
||||||
|
|
||||||
def LoadFirmwareImage(chip, image_file):
|
def LoadFirmwareImage(chip, image_file):
|
||||||
|
@@ -263,6 +263,16 @@ class TestMergeBin:
|
|||||||
# verify the file itself
|
# verify the file itself
|
||||||
assert source == merged_bin[0x1000:]
|
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):
|
class UF2Block(object):
|
||||||
def __init__(self, bs):
|
def __init__(self, bs):
|
||||||
|
Reference in New Issue
Block a user