mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 12:14:32 +02:00
otatool, parttool: Fix permission denied error on Windows
This commit is contained in:
@@ -83,10 +83,18 @@ def _get_otadata_contents(args, check=True):
|
|||||||
if not output:
|
if not output:
|
||||||
raise RuntimeError("No ota_data partition found")
|
raise RuntimeError("No ota_data partition found")
|
||||||
|
|
||||||
with tempfile.NamedTemporaryFile() as otadata_file:
|
with tempfile.NamedTemporaryFile(delete=False) as f:
|
||||||
invoke_args = ["read_partition", "--output", otadata_file.name]
|
f_name = f.name
|
||||||
|
|
||||||
|
try:
|
||||||
|
invoke_args = ["read_partition", "--output", f_name]
|
||||||
_invoke_parttool(invoke_args, args)
|
_invoke_parttool(invoke_args, args)
|
||||||
return otadata_file.read()
|
with open(f_name, "rb") as f:
|
||||||
|
contents = f.read()
|
||||||
|
finally:
|
||||||
|
os.unlink(f_name)
|
||||||
|
|
||||||
|
return contents
|
||||||
|
|
||||||
|
|
||||||
def _get_otadata_status(otadata_contents):
|
def _get_otadata_status(otadata_contents):
|
||||||
@@ -130,6 +138,10 @@ def switch_otadata(args):
|
|||||||
sys.path.append(os.path.join(IDF_COMPONENTS_PATH, "partition_table"))
|
sys.path.append(os.path.join(IDF_COMPONENTS_PATH, "partition_table"))
|
||||||
import gen_esp32part as gen
|
import gen_esp32part as gen
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False) as f:
|
||||||
|
f_name = f.name
|
||||||
|
|
||||||
|
try:
|
||||||
def is_otadata_status_valid(status):
|
def is_otadata_status_valid(status):
|
||||||
seq = status.seq % (1 << 32)
|
seq = status.seq % (1 << 32)
|
||||||
crc = hex(binascii.crc32(struct.pack("I", seq), 0xFFFFFFFF) % (1 << 32))
|
crc = hex(binascii.crc32(struct.pack("I", seq), 0xFFFFFFFF) % (1 << 32))
|
||||||
@@ -139,13 +151,11 @@ def switch_otadata(args):
|
|||||||
|
|
||||||
# In order to get the number of ota app partitions, we need the partition table
|
# In order to get the number of ota app partitions, we need the partition table
|
||||||
partition_table = None
|
partition_table = None
|
||||||
|
invoke_args = ["get_partition_info", "--table", f_name]
|
||||||
with tempfile.NamedTemporaryFile() as partition_table_file:
|
|
||||||
invoke_args = ["get_partition_info", "--table", partition_table_file.name]
|
|
||||||
|
|
||||||
_invoke_parttool(invoke_args, args)
|
_invoke_parttool(invoke_args, args)
|
||||||
|
|
||||||
partition_table = partition_table_file.read()
|
partition_table = open(f_name, "rb").read()
|
||||||
partition_table = gen.PartitionTable.from_binary(partition_table)
|
partition_table = gen.PartitionTable.from_binary(partition_table)
|
||||||
|
|
||||||
ota_partitions = list()
|
ota_partitions = list()
|
||||||
@@ -221,7 +231,7 @@ def switch_otadata(args):
|
|||||||
ota_seq_crc_next = binascii.crc32(ota_seq_next, 0xFFFFFFFF) % (1 << 32)
|
ota_seq_crc_next = binascii.crc32(ota_seq_next, 0xFFFFFFFF) % (1 << 32)
|
||||||
ota_seq_crc_next = struct.pack("I", ota_seq_crc_next)
|
ota_seq_crc_next = struct.pack("I", ota_seq_crc_next)
|
||||||
|
|
||||||
with tempfile.NamedTemporaryFile() as otadata_next_file:
|
with open(f_name, "wb") as otadata_next_file:
|
||||||
start = (1 if otadata_compute_base == 0 else 0) * (SPI_FLASH_SEC_SIZE >> 1)
|
start = (1 if otadata_compute_base == 0 else 0) * (SPI_FLASH_SEC_SIZE >> 1)
|
||||||
|
|
||||||
otadata_next_file.write(otadata_contents)
|
otadata_next_file.write(otadata_contents)
|
||||||
@@ -234,8 +244,10 @@ def switch_otadata(args):
|
|||||||
|
|
||||||
otadata_next_file.flush()
|
otadata_next_file.flush()
|
||||||
|
|
||||||
_invoke_parttool(["write_partition", "--input", otadata_next_file.name], args)
|
_invoke_parttool(["write_partition", "--input", f_name], args)
|
||||||
status("Updated ota_data partition")
|
status("Updated ota_data partition")
|
||||||
|
finally:
|
||||||
|
os.unlink(f_name)
|
||||||
|
|
||||||
|
|
||||||
def _get_partition_specifier(args):
|
def _get_partition_specifier(args):
|
||||||
|
@@ -74,11 +74,19 @@ def _get_partition_table(args):
|
|||||||
else:
|
else:
|
||||||
port_info = (" on port " + args.port if args.port else "")
|
port_info = (" on port " + args.port if args.port else "")
|
||||||
status("Reading partition table from device{}...".format(port_info))
|
status("Reading partition table from device{}...".format(port_info))
|
||||||
with tempfile.NamedTemporaryFile() as partition_table_file:
|
|
||||||
invoke_args = ["read_flash", str(gen.offset_part_table), str(gen.MAX_PARTITION_LENGTH), partition_table_file.name]
|
f_name = None
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False) as f:
|
||||||
|
f_name = f.name
|
||||||
|
|
||||||
|
try:
|
||||||
|
invoke_args = ["read_flash", str(gen.offset_part_table), str(gen.MAX_PARTITION_LENGTH), f_name]
|
||||||
_invoke_esptool(invoke_args, args)
|
_invoke_esptool(invoke_args, args)
|
||||||
partition_table = gen.PartitionTable.from_binary(partition_table_file.read())
|
with open(f_name, "rb") as f:
|
||||||
|
partition_table = gen.PartitionTable.from_binary(f.read())
|
||||||
status("Partition table read from device" + port_info)
|
status("Partition table read from device" + port_info)
|
||||||
|
finally:
|
||||||
|
os.unlink(f_name)
|
||||||
|
|
||||||
return partition_table
|
return partition_table
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user