Skip to content

Commit

Permalink
espefuse: Hide traceback when new data value is incorrect for burn_ef…
Browse files Browse the repository at this point in the history
…use cmd

Closes #760
  • Loading branch information
KonstantinKondrashov authored and dobairoland committed Jul 26, 2022
1 parent 2809cdd commit aaabbc5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions espefuse/efuse/base_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later

import argparse
import binascii
import re
import sys

from bitstring import BitArray, BitString
from bitstring import BitArray, BitString, CreationError

import esptool

Expand All @@ -28,7 +27,7 @@ def check_arg_value(efuse, new_value):
if efuse.efuse_type.startswith("bool"):
new_value = 1 if new_value is None else int(new_value, 0)
if new_value != 1:
raise argparse.ArgumentTypeError(
raise esptool.FatalError(
"New value is not accepted for efuse '{}' "
"(will always burn 0->1), given value={}".format(
efuse.name, new_value
Expand All @@ -48,32 +47,32 @@ def check_arg_value(efuse, new_value):
new_value = int(new_value, 0)
else:
if new_value is None:
raise argparse.ArgumentTypeError(
raise esptool.FatalError(
"New value required for efuse '{}' (given None)".format(
efuse.name
)
)
new_value = int(new_value, 0)
if new_value == 0:
raise argparse.ArgumentTypeError(
raise esptool.FatalError(
"New value should not be 0 for '{}' "
"(given value= {})".format(efuse.name, new_value)
)
elif efuse.efuse_type.startswith("bytes"):
if new_value is None:
raise argparse.ArgumentTypeError(
raise esptool.FatalError(
"New value required for efuse '{}' "
"(given None)".format(efuse.name)
)
if len(new_value) * 8 != efuse.bitarray.len:
raise argparse.ArgumentTypeError(
raise esptool.FatalError(
"The length of efuse '{}' ({} bits) "
"(given len of the new value= {} bits)".format(
efuse.name, efuse.bitarray.len, len(new_value) * 8
)
)
else:
raise argparse.ArgumentTypeError(
raise esptool.FatalError(
"The '{}' type for the '{}' efuse is not supported yet.".format(
efuse.efuse_type, efuse.name
)
Expand Down Expand Up @@ -598,7 +597,15 @@ def convert_to_bitstring(self, new_value):
# *[x] - means a byte.
return BitArray(bytes=new_value[::-1], length=len(new_value) * 8)
else:
return BitArray(self.efuse_type + "={}".format(new_value))
try:
return BitArray(self.efuse_type + "={}".format(new_value))
except CreationError as err:
print(
"New value '{}' is not suitable for {} ({})".format(
new_value, self.name, self.efuse_type
)
)
raise esptool.FatalError(err)

def check_new_value(self, bitarray_new_value):
bitarray_old_value = self.get_bitstring() | self.get_bitstring(from_read=False)
Expand Down

0 comments on commit aaabbc5

Please sign in to comment.