fix(espefuse): Close serial port even when espefuse fails

Closes https://github.com/espressif/esptool/issues/803
This commit is contained in:
radim.karnis
2022-12-05 14:20:02 +01:00
committed by Radim Karniš
parent 14605173da
commit 26df171d24

View File

@@ -249,27 +249,28 @@ def main(custom_commandline=None):
if there_are_multiple_burn_commands_in_args:
efuses.batch_mode_cnt += 1
for rem_args in grouped_remaining_args:
args, unused_args = parser.parse_known_args(rem_args, namespace=common_args)
if args.operation is None:
parser.print_help()
parser.exit(1)
assert len(unused_args) == 0, 'Not all commands were recognized "{}"'.format(
unused_args
)
try:
for rem_args in grouped_remaining_args:
args, unused_args = parser.parse_known_args(rem_args, namespace=common_args)
if args.operation is None:
parser.print_help()
parser.exit(1)
assert (
len(unused_args) == 0
), 'Not all commands were recognized "{}"'.format(unused_args)
operation_func = vars(efuse_operations)[args.operation]
# each 'operation' is a module-level function of the same name
print('\n=== Run "{}" command ==='.format(args.operation))
operation_func(esp, efuses, args)
operation_func = vars(efuse_operations)[args.operation]
# each 'operation' is a module-level function of the same name
print('\n=== Run "{}" command ==='.format(args.operation))
operation_func(esp, efuses, args)
if there_are_multiple_burn_commands_in_args:
efuses.batch_mode_cnt -= 1
if not efuses.burn_all(check_batch_mode=True):
raise esptool.FatalError("BURN was not done")
if common_args.virt is False:
esp._port.close()
if there_are_multiple_burn_commands_in_args:
efuses.batch_mode_cnt -= 1
if not efuses.burn_all(check_batch_mode=True):
raise esptool.FatalError("BURN was not done")
finally:
if not common_args.virt and esp._port:
esp._port.close()
def _main():