|
@@ -132,7 +132,7 @@ class Page(object):
|
|
|
# set Type
|
|
# set Type
|
|
|
if encoding == "string":
|
|
if encoding == "string":
|
|
|
entry_struct[1] = Page.SZ
|
|
entry_struct[1] = Page.SZ
|
|
|
- elif encoding == "hex2bin" or encoding == "binary":
|
|
|
|
|
|
|
+ elif encoding in ["hex2bin", "binary", "base64"]:
|
|
|
entry_struct[1] = Page.BLOB
|
|
entry_struct[1] = Page.BLOB
|
|
|
|
|
|
|
|
# compute CRC of data
|
|
# compute CRC of data
|
|
@@ -248,11 +248,14 @@ class NVS(object):
|
|
|
raise InputError("%s: Invalid data length. Should be multiple of 2." % key)
|
|
raise InputError("%s: Invalid data length. Should be multiple of 2." % key)
|
|
|
value = binascii.a2b_hex(value)
|
|
value = binascii.a2b_hex(value)
|
|
|
|
|
|
|
|
|
|
+ if encoding == "base64":
|
|
|
|
|
+ value = binascii.a2b_base64(value)
|
|
|
|
|
+
|
|
|
if encoding == "string":
|
|
if encoding == "string":
|
|
|
value += '\0'
|
|
value += '\0'
|
|
|
|
|
|
|
|
encoding = encoding.lower()
|
|
encoding = encoding.lower()
|
|
|
- varlen_encodings = ["string", "binary", "hex2bin"]
|
|
|
|
|
|
|
+ varlen_encodings = ["string", "binary", "hex2bin", "base64"]
|
|
|
primitive_encodings = ["u8", "i8", "u16", "u32", "i32"]
|
|
primitive_encodings = ["u8", "i8", "u16", "u32", "i32"]
|
|
|
if encoding in varlen_encodings:
|
|
if encoding in varlen_encodings:
|
|
|
try:
|
|
try:
|
|
@@ -308,7 +311,7 @@ def write_entry(nvs_instance, key, datatype, encoding, value):
|
|
|
:param nvs_instance: Instance of an NVS class returned by nvs_open()
|
|
:param nvs_instance: Instance of an NVS class returned by nvs_open()
|
|
|
:param key: Key of the data
|
|
:param key: Key of the data
|
|
|
:param datatype: Data type. Valid values are "file", "data" and "namespace"
|
|
:param datatype: Data type. Valid values are "file", "data" and "namespace"
|
|
|
- :param encoding: Data encoding. Valid values are "u8", "i8", "u16", "u32", "i32", "string", "binary" and "hex2bin"
|
|
|
|
|
|
|
+ :param encoding: Data encoding. Valid values are "u8", "i8", "u16", "u32", "i32", "string", "binary", "hex2bin" and "base64"
|
|
|
:param value: Data value in ascii encoded string format for "data" datatype and filepath for "file" datatype
|
|
:param value: Data value in ascii encoded string format for "data" datatype and filepath for "file" datatype
|
|
|
:return: None
|
|
:return: None
|
|
|
"""
|
|
"""
|
|
@@ -333,29 +336,42 @@ def nvs_close(nvs_instance):
|
|
|
"""
|
|
"""
|
|
|
nvs_instance.__exit__(None, None, None)
|
|
nvs_instance.__exit__(None, None, None)
|
|
|
|
|
|
|
|
|
|
+def nvs_part_gen(input_filename=None, output_filename=None):
|
|
|
|
|
+ input_file = open(input_filename, 'rb')
|
|
|
|
|
+ output_file = open(output_filename, 'wb')
|
|
|
|
|
+
|
|
|
|
|
+ with nvs_open(output_file) as nvs_obj:
|
|
|
|
|
+ reader = csv.DictReader(input_file, delimiter=',')
|
|
|
|
|
+ for row in reader:
|
|
|
|
|
+ try:
|
|
|
|
|
+ write_entry(nvs_obj, row["key"], row["type"], row["encoding"], row["value"])
|
|
|
|
|
+ except InputError as e:
|
|
|
|
|
+ print(e)
|
|
|
|
|
+ input_file.close()
|
|
|
|
|
+ output_file.close()
|
|
|
|
|
+ exit(-2)
|
|
|
|
|
+
|
|
|
|
|
+ input_file.close()
|
|
|
|
|
+ output_file.close()
|
|
|
|
|
+
|
|
|
def main():
|
|
def main():
|
|
|
parser = argparse.ArgumentParser(description="ESP32 NVS partition generation utility")
|
|
parser = argparse.ArgumentParser(description="ESP32 NVS partition generation utility")
|
|
|
parser.add_argument(
|
|
parser.add_argument(
|
|
|
"input",
|
|
"input",
|
|
|
help="Path to CSV file to parse. Will use stdin if omitted",
|
|
help="Path to CSV file to parse. Will use stdin if omitted",
|
|
|
- type=argparse.FileType('rb'),
|
|
|
|
|
default=sys.stdin)
|
|
default=sys.stdin)
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
parser.add_argument(
|
|
|
"output",
|
|
"output",
|
|
|
help='Path to output converted binary file. Will use stdout if omitted',
|
|
help='Path to output converted binary file. Will use stdout if omitted',
|
|
|
- type=argparse.FileType('wb'),
|
|
|
|
|
default=sys.stdout)
|
|
default=sys.stdout)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
- with nvs_open(args.output) as nvs_obj:
|
|
|
|
|
- reader = csv.DictReader(args.input, delimiter=',')
|
|
|
|
|
- for row in reader:
|
|
|
|
|
- try:
|
|
|
|
|
- write_entry(nvs_obj, row["key"], row["type"], row["encoding"], row["value"])
|
|
|
|
|
- except InputError as e:
|
|
|
|
|
- print(e)
|
|
|
|
|
- exit(-2)
|
|
|
|
|
|
|
+ input_filename = args.input
|
|
|
|
|
+ output_filename = args.output
|
|
|
|
|
+ nvs_part_gen(input_filename, output_filename)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
main()
|
|
main()
|