From bc39e9ac75540e58d4b71a362e0c3316c4e12f2b Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Tue, 11 Sep 2018 13:43:05 +0530 Subject: [PATCH 01/24] Update mfg utility as per updated nvs partition util --- tools/mass_mfg/docs/README.rst | 6 ++++-- tools/mass_mfg/mfg_gen.py | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) mode change 100644 => 100755 tools/mass_mfg/mfg_gen.py diff --git a/tools/mass_mfg/docs/README.rst b/tools/mass_mfg/docs/README.rst index 4914806d0..f71ec7eac 100644 --- a/tools/mass_mfg/docs/README.rst +++ b/tools/mass_mfg/docs/README.rst @@ -115,11 +115,13 @@ The mfg\_gen.py utility is using the generated CSV Configuration file and Master **Usage**:: - $ ./mfg_gen.py [-h] --conf CONFIG_FILE --values VALUES_FILE --prefix PREFIX [--fileid FILEID] [--outdir OUTDIR] + $ ./mfg_gen.py [-h] --size PART_SIZE --conf CONFIG_FILE --values VALUES_FILE --prefix PREFIX [--fileid FILEID] [--outdir OUTDIR] +------------------------+----------------------------------------------------------------------------------------------+ | Arguments | Description | +========================+==============================================================================================+ +| --size PART_SIZE | the size of NVS Partition in KB. Eg. 12KB | ++------------------------+----------------------------------------------------------------------------------------------+ | --conf CONFIG_FILE | the input configuration csv file | +------------------------+----------------------------------------------------------------------------------------------+ | --values VALUES_FILE | the input values csv file | @@ -134,7 +136,7 @@ The mfg\_gen.py utility is using the generated CSV Configuration file and Master **You can use the below command to run this utility with the sample files provided**:: - $ ./mfg_gen.py --conf sample_config.csv --values sample_values.csv --prefix Fan + $ ./mfg_gen.py --size 12KB --conf samples/sample_config.csv --values samples/sample_values.csv --prefix Fan .. note:: The default numeric value: 1,2,3... of ``fileid`` argument, corresponds to each row having device instance values in master csv values file. diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py old mode 100644 new mode 100755 index 9060dde22..56aa61cac --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -284,6 +284,11 @@ file_identifier=None,output_dir_path=None): description="Create binary files from input config and values file", formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--size", + dest='part_size', + required=True, + help='Size of NVS Partition in KB. Eg. 12KB') + parser.add_argument('--conf', dest='config_file', required=True, @@ -320,6 +325,7 @@ file_identifier=None,output_dir_path=None): if not args.outdir.endswith('/'): args.outdir = args.outdir + '/' + input_part_size = args.part_size input_config_file = args.config_file input_values_file = args.values_file target_file_name_prefix = args.prefix @@ -472,7 +478,8 @@ file_identifier=None,output_dir_path=None): # Create output csv and bin file print "CSV Generated: " + str(output_csv_file) - nvs_partition_gen.nvs_part_gen(input_filename = output_csv_file, output_filename = output_bin_file) + nvs_partition_gen.nvs_part_gen(input_filename = output_csv_file, output_filename = output_bin_file,\ + input_size=input_part_size) print "NVS Flash Binary Generated: " + str(output_bin_file) files_created = True From 98433d48f1387284d1008dd9e6922e3718fa6170 Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Wed, 3 Oct 2018 17:01:00 +0530 Subject: [PATCH 02/24] mfg_gen: Add changes to make Python2 and Python3 compatible --- tools/mass_mfg/mfg_gen.py | 102 +++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 29 deletions(-) diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index 56aa61cac..a9813ae22 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -15,25 +15,32 @@ # limitations under the License. # +from __future__ import print_function import sys import os import csv import argparse import shutil import distutils.dir_util +from itertools import zip_longest sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen - def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file """ line_no = 1 key_count_in_values_file = len(keys_in_values_file) - values_file = open(input_values_file,'rb') + if sys.version_info[0] < 3: + values_file = open(input_values_file, 'rb') + else: + values_file = open(input_values_file, 'r', newline='') values_file_reader = csv.reader(values_file, delimiter=',') - keys = values_file_reader.next() + if sys.version_info[0] < 3: + keys = values_file_reader.next() + else: + keys = next(values_file_reader) for values_data in values_file_reader: line_no +=1 @@ -59,12 +66,11 @@ def verify_keys_exist(values_file_keys, input_config_file): else: keys_missing.append([config_data[0], line_no]) - + if keys_missing: - print "Oops..." for key, line_no in keys_missing: - print "Key:`" + str(key) + "` at line no:" + str(line_no) + \ - " in config file is not found in values file..." + print("Key:`", str(key), "` at line no:", str(line_no),\ + " in config file is not found in values file.") config_file.close() raise SystemExit(1) @@ -131,7 +137,7 @@ def verify_data_in_file(input_config_file, input_values_file, config_file_keys, verify_values_exist(input_values_file, keys_in_values_file) except StandardError as std_err: - print std_err + print(std_err) except: raise @@ -203,6 +209,7 @@ def add_data_to_file(config_data_to_write, key_value_pair, output_csv_file): data_to_write = [] target_csv_file = open(output_csv_file, 'w') + output_file_writer = csv.writer(target_csv_file, delimiter=',') output_file_writer.writerow(header) @@ -246,9 +253,17 @@ def set_repeat_value(total_keys_repeat, keys, csv_file): target_filename = filename + "_created" + file_ext with open(csv_file, 'r') as read_from, open(target_filename,'w') as write_to: csv_file_reader = csv.reader(read_from, delimiter=',') - headers = csv_file_reader.next() - values = csv_file_reader.next() - total_keys_values = map(None, keys, values) + if sys.version_info[0] < 3: + headers = csv_file_reader.next() + values = csv_file_reader.next() + else: + headers = next(csv_file_reader) + values = next(csv_file_reader) + + if sys.version_info[0] < 3: + total_keys_values = map(None, keys, values) + else: + total_keys_values = list(zip_longest(keys, values)) csv_file_writer = csv.writer(write_to, delimiter=',') csv_file_writer.writerow(headers) @@ -257,7 +272,11 @@ def set_repeat_value(total_keys_repeat, keys, csv_file): # read new data, add value if key has repeat tag, write to new file for row in csv_file_reader: index = -1 - key_val_new = map(None, keys, row) + if sys.version_info[0] < 3: + key_val_new = map(None, keys, row) + else: + key_val_new = list(zip_longest(keys, row)) + key_val_pair = total_keys_values[:] key_repeated = total_keys_repeat[:] while key_val_new and key_repeated: @@ -270,7 +289,7 @@ def set_repeat_value(total_keys_repeat, keys, csv_file): del key_repeated[0] del key_val_new[0] del key_val_pair[0] - + return target_filename @@ -288,7 +307,7 @@ file_identifier=None,output_dir_path=None): dest='part_size', required=True, help='Size of NVS Partition in KB. Eg. 12KB') - + parser.add_argument('--conf', dest='config_file', required=True, @@ -387,7 +406,7 @@ file_identifier=None,output_dir_path=None): csv_config_file.close() except Exception as e: - print e + print(e) finally: csv_config_file.close() @@ -395,7 +414,10 @@ file_identifier=None,output_dir_path=None): # Verify values file does not have empty lines - csv_values_file = open(input_values_file,'rb') + if sys.version_info[0] < 3: + csv_values_file = open(input_values_file,'rb') + else: + csv_values_file = open(input_values_file,'r', newline='') try: values_file_reader = csv.reader(csv_values_file, delimiter=',') for values_data in values_file_reader: @@ -414,11 +436,14 @@ file_identifier=None,output_dir_path=None): csv_values_file.seek(0) # Extract keys from values file - keys_in_values_file = values_file_reader.next() + if sys.version_info[0] < 3: + keys_in_values_file = values_file_reader.next() + else: + keys_in_values_file = next(values_file_reader) csv_values_file.close() except Exception as e: - print e + print(e) exit(1) finally: csv_values_file.close() @@ -437,16 +462,35 @@ file_identifier=None,output_dir_path=None): config_data_to_write = add_config_data_per_namespace(input_config_file) try: - with open(input_values_file,'rb') as csv_values_file: - values_file_reader = csv.reader(csv_values_file, delimiter=',') - keys = values_file_reader.next() + if sys.version_info[0] < 3: + with open(input_values_file,'rb') as csv_values_file: + values_file_reader = csv.reader(csv_values_file, delimiter=',') + keys = values_file_reader.next() + else: + with open(input_values_file,'r', newline='') as csv_values_file: + values_file_reader = csv.reader(csv_values_file, delimiter=',') + keys = next(values_file_reader) + target_values_file = set_repeat_value(keys_repeat, keys, input_values_file) - csv_values_file = open(target_values_file, 'rb') + + if sys.version_info[0] < 3: + csv_values_file = open(target_values_file, 'rb') + else: + csv_values_file = open(target_values_file, 'r', newline='') + values_file_reader = csv.reader(csv_values_file, delimiter=',') - values_file_reader.next() + if sys.version_info[0] < 3: + values_file_reader.next() + else: + next(values_file_reader) + for values_data_line in values_file_reader: - key_value_data = map(None,keys_in_values_file,values_data_line) + if sys.version_info[0] < 3: + key_value_data = map(None,keys_in_values_file,values_data_line) + else: + key_value_data = list(zip_longest(keys_in_values_file,values_data_line)) + # Get file identifier value from values file file_identifier_value = get_fileid_val(file_identifier, keys_in_config_file, \ @@ -477,16 +521,16 @@ file_identifier=None,output_dir_path=None): raise SystemExit("Target csv file: `" + output_bin_file + "` already exists...") # Create output csv and bin file - print "CSV Generated: " + str(output_csv_file) + print("CSV Generated: ", str(output_csv_file)) nvs_partition_gen.nvs_part_gen(input_filename = output_csv_file, output_filename = output_bin_file,\ input_size=input_part_size) - print "NVS Flash Binary Generated: " + str(output_bin_file) + print("NVS Flash Binary Generated: ", str(output_bin_file)) files_created = True csv_values_file.close() except Exception as e: - print e + print(e) exit(1) finally: csv_values_file.close() @@ -494,8 +538,8 @@ file_identifier=None,output_dir_path=None): return csv_file_list, files_created - except StandardError as std_err: - print std_err + except ValueError as err: + print(err) except: raise From ff30a1fbd35a01dfbbbb4bb6420db956f78e002a Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Mon, 8 Oct 2018 10:32:09 +0530 Subject: [PATCH 03/24] nvs_part_gen: Update to make python version compatible (cherry picked from commit 3506b2d60792e5d4ed4f744b28f2da6733c6aae7) --- .../nvs_partition_gen.py | 199 +++++++++++++----- .../nvs_flash/test_nvs_host/test_nvs.cpp | 13 +- 2 files changed, 154 insertions(+), 58 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 0f641d612..a1cc81a65 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -28,6 +28,7 @@ import os import array import csv import zlib +import codecs from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend @@ -81,9 +82,9 @@ class Page(object): # set page state to active page_header= bytearray(b'\xff')*32 page_state_active_seq = Page.ACTIVE - page_header[0:4] = struct.pack('= Page.PAGE_PARAMS["max_entries"]: raise PageFullError() - entry_struct = bytearray('\xff')*32 + entry_struct = bytearray(b'\xff')*32 entry_struct[0] = ns_index # namespace index entry_struct[2] = 0x01 # Span chunk_index = Page.CHUNK_ANY entry_struct[3] = chunk_index # write key - key_array = bytearray('\x00')*16 + key_array = bytearray(b'\x00')*16 entry_struct[8:24] = key_array - entry_struct[8:8 + len(key)] = key + + if sys.version_info[0] < 3: + entry_struct[8:8 + len(key)] = key + else: + entry_struct[8:8 + len(key)] = key.encode('utf8') + if encoding == "u8": entry_struct[1] = Page.U8 - entry_struct[24] = struct.pack(' Date: Mon, 8 Oct 2018 11:11:56 +0530 Subject: [PATCH 04/24] nvs_part_gen: Add changes to partition size input --- .../nvs_partition_generator/README.rst | 2 +- .../nvs_partition_gen.py | 23 +++++++++---------- tools/mass_mfg/docs/README.rst | 4 ++-- tools/mass_mfg/mfg_gen.py | 5 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/README.rst b/components/nvs_flash/nvs_partition_generator/README.rst index aa7a945c2..f0c6d6623 100644 --- a/components/nvs_flash/nvs_partition_generator/README.rst +++ b/components/nvs_flash/nvs_partition_generator/README.rst @@ -123,7 +123,7 @@ A sample CSV file is provided with the utility:: +------------------------+----------------------------------------------------------------------------------------------+ | output | Path to output converted binary file. Will use stdout if omitted | +------------------------+----------------------------------------------------------------------------------------------+ -| size | Size of NVS Partition in KB. Eg. 12KB | +| size | Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000 | +------------------------+----------------------------------------------------------------------------------------------+ | --version {v1,v2} | Set version. Default: v2 | +-------------------------------+---------------------------------------------------------------------------------------+ diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index a1cc81a65..2b11877ca 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -179,7 +179,7 @@ class Page(object): data_input = byte_arr - + if sys.version_info[0] < 3: data_input = binascii.hexlify(bytearray(data_input)) else: @@ -214,7 +214,6 @@ class Page(object): data_val = str(data_bytes) + (init_data_val * (data_len_needed - len(data_bytes))) encr_data_ret = self.encrypt_entry(data_val, tweak_val, encr_key_input) - #print("\n<<<\n") encr_data_to_write = encr_data_to_write + encr_data_ret # Update values for encrypting next set of data bytes start_idx = end_idx @@ -233,7 +232,7 @@ class Page(object): encr_data[0:len(encr_data_ret)] = encr_data_ret else: encr_data[0:len(encr_data_ret)] = encr_data_ret - + data = encr_data data_offset = Page.FIRST_ENTRY_OFFSET + (Page.SINGLE_ENTRY_SIZE * self.entry_num) @@ -311,7 +310,7 @@ class Page(object): if not sys.version_info[0] < 3: if type(data_chunk) == str: data_chunk = codecs.encode(data_chunk, 'utf8') - + crc = zlib.crc32(data_chunk, 0xFFFFFFFF) struct.pack_into(' Date: Thu, 11 Oct 2018 11:49:32 +0530 Subject: [PATCH 05/24] nvs_util: Add Python2 and Python3 compatible --- .../nvs_partition_gen.py | 171 +++++------------- 1 file changed, 50 insertions(+), 121 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 2b11877ca..2330c6102 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -17,8 +17,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from __future__ import division -from __future__ import print_function + +from __future__ import division, print_function #, unicode_literals +from future.utils import raise_ +from builtins import int, range +from io import open import sys import argparse import binascii @@ -80,7 +83,7 @@ class Page(object): global page_header # set page state to active - page_header= bytearray(b'\xff')*32 + page_header= bytearray(b'\xff') *32 page_state_active_seq = Page.ACTIVE struct.pack_into(' Date: Tue, 11 Sep 2018 13:43:05 +0530 Subject: [PATCH 06/24] Update mfg utility as per updated nvs partition util --- tools/mass_mfg/mfg_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index ca9c94cb0..c02c0e156 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -308,7 +308,7 @@ file_identifier=None,output_dir_path=None): dest='part_size', required=True, help='Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000') - + parser.add_argument('--conf', dest='config_file', required=True, From 24fa2342e8434317d5bd693141e7f37989bd4c3a Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Wed, 3 Oct 2018 17:01:00 +0530 Subject: [PATCH 07/24] mfg_gen: Add changes to make Python2 and Python3 compatible --- tools/mass_mfg/mfg_gen.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index c02c0e156..255aa50b1 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -22,10 +22,9 @@ import csv import argparse import shutil import distutils.dir_util +from itertools import zip_longest sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen -if not sys.version_info[0] < 3: - from itertools import zip_longest def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file From 226b6929e526055ac570ad5cfd468441136b8f7f Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Mon, 8 Oct 2018 10:32:09 +0530 Subject: [PATCH 08/24] nvs_part_gen: Update to make python version compatible (cherry picked from commit 3506b2d60792e5d4ed4f744b28f2da6733c6aae7) --- .../nvs_partition_generator/nvs_partition_gen.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 2330c6102..d0c529791 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -193,6 +193,7 @@ class Page(object): data_val = data_bytes + (init_data_val * (data_len_needed - len(data_bytes))) encr_data_ret = self.encrypt_entry(data_val, tweak_val, encr_key_input) + #print("\n<<<\n") encr_data_to_write = encr_data_to_write + encr_data_ret # Update values for encrypting next set of data bytes start_idx = end_idx @@ -207,13 +208,24 @@ class Page(object): if self.is_encrypt: encr_data_ret = self.encrypt_data(data, entrycount,nvs_obj) - encr_data[0:len(encr_data_ret)] = encr_data_ret + if sys.version_info[0] < 3: + encr_data[0:len(encr_data_ret)] = encr_data_ret + else: + encr_data[0:len(encr_data_ret)] = encr_data_ret + data = encr_data data_offset = Page.FIRST_ENTRY_OFFSET + (Page.SINGLE_ENTRY_SIZE * self.entry_num) start_idx = data_offset end_idx = data_offset + len(data) - self.page_buf[start_idx:end_idx] = data + if not sys.version_info[0] < 3: + if type(data) == str: + self.page_buf[start_idx:end_idx] = data + else: + self.page_buf[start_idx:end_idx] = data + else: + self.page_buf[start_idx:end_idx] = data + # Set bitmap array for entries in current page for i in range(0, entrycount): From 0064357a986a0a15dc1d79d3693c8d89a1ba5667 Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Mon, 8 Oct 2018 11:11:56 +0530 Subject: [PATCH 09/24] nvs_part_gen: Add changes to partition size input --- .../nvs_flash/nvs_partition_generator/nvs_partition_gen.py | 3 +-- tools/mass_mfg/mfg_gen.py | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index d0c529791..003d1bab9 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -193,7 +193,6 @@ class Page(object): data_val = data_bytes + (init_data_val * (data_len_needed - len(data_bytes))) encr_data_ret = self.encrypt_entry(data_val, tweak_val, encr_key_input) - #print("\n<<<\n") encr_data_to_write = encr_data_to_write + encr_data_ret # Update values for encrypting next set of data bytes start_idx = end_idx @@ -212,7 +211,7 @@ class Page(object): encr_data[0:len(encr_data_ret)] = encr_data_ret else: encr_data[0:len(encr_data_ret)] = encr_data_ret - + data = encr_data data_offset = Page.FIRST_ENTRY_OFFSET + (Page.SINGLE_ENTRY_SIZE * self.entry_num) diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index 255aa50b1..ca9c94cb0 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -22,9 +22,10 @@ import csv import argparse import shutil import distutils.dir_util -from itertools import zip_longest sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen +if not sys.version_info[0] < 3: + from itertools import zip_longest def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file @@ -307,7 +308,7 @@ file_identifier=None,output_dir_path=None): dest='part_size', required=True, help='Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000') - + parser.add_argument('--conf', dest='config_file', required=True, From b521f1b8ba209ec3bd2fa726c66d5ce2be16c4e6 Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Thu, 11 Oct 2018 11:49:32 +0530 Subject: [PATCH 10/24] nvs_util: Add Python2 and Python3 compatible --- .../nvs_partition_generator/nvs_partition_gen.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 003d1bab9..2330c6102 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -207,24 +207,13 @@ class Page(object): if self.is_encrypt: encr_data_ret = self.encrypt_data(data, entrycount,nvs_obj) - if sys.version_info[0] < 3: - encr_data[0:len(encr_data_ret)] = encr_data_ret - else: - encr_data[0:len(encr_data_ret)] = encr_data_ret - + encr_data[0:len(encr_data_ret)] = encr_data_ret data = encr_data data_offset = Page.FIRST_ENTRY_OFFSET + (Page.SINGLE_ENTRY_SIZE * self.entry_num) start_idx = data_offset end_idx = data_offset + len(data) - if not sys.version_info[0] < 3: - if type(data) == str: - self.page_buf[start_idx:end_idx] = data - else: - self.page_buf[start_idx:end_idx] = data - else: - self.page_buf[start_idx:end_idx] = data - + self.page_buf[start_idx:end_idx] = data # Set bitmap array for entries in current page for i in range(0, entrycount): From 64728a74f970b6dd3cb501da54544584023cee83 Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Thu, 11 Oct 2018 17:50:12 +0530 Subject: [PATCH 11/24] tools: Add Python2 and Python3 compatibility support to nvs util tool and mfg tool --- .../nvs_partition_gen.py | 1 - tools/mass_mfg/mfg_gen.py | 108 ++++++------------ 2 files changed, 34 insertions(+), 75 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 2330c6102..2a01d0744 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -19,7 +19,6 @@ # from __future__ import division, print_function #, unicode_literals -from future.utils import raise_ from builtins import int, range from io import open import sys diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index ca9c94cb0..07b2b28e6 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -16,6 +16,8 @@ # from __future__ import print_function +from builtins import map, range +from future.moves.itertools import zip_longest import sys import os import csv @@ -24,8 +26,6 @@ import shutil import distutils.dir_util sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen -if not sys.version_info[0] < 3: - from itertools import zip_longest def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file @@ -33,21 +33,15 @@ def verify_values_exist(input_values_file, keys_in_values_file): line_no = 1 key_count_in_values_file = len(keys_in_values_file) - if sys.version_info[0] < 3: - values_file = open(input_values_file, 'rb') - else: - values_file = open(input_values_file, 'r', newline='') + values_file = open(input_values_file, 'r') values_file_reader = csv.reader(values_file, delimiter=',') - if sys.version_info[0] < 3: - keys = values_file_reader.next() - else: - keys = next(values_file_reader) + keys = next(values_file_reader) for values_data in values_file_reader: line_no +=1 if len(values_data) != key_count_in_values_file: - raise SystemExit("\nOops...Number of values is not equal to number of keys in file: '" + \ - str(input_values_file) + "' at line No:" + str(line_no) ) + raise SystemExit("\nOops...Number of values is not equal to number of keys in file: %s at line No:%s\n"\ + % (str(input_values_file), str(line_no))) def verify_keys_exist(values_file_keys, input_config_file): @@ -91,12 +85,12 @@ def verify_datatype_encoding(input_config_file): for config_data in config_file_reader: line_no+=1 if config_data[1] not in valid_datatypes: - raise SystemExit("Oops...config file: `" + str(input_config_file) + \ - "` has invalid datatype at line no:" + str(line_no)) + raise SystemExit("Oops...config file: %s has invalid datatype at line no:%s\n`" \ + % (str(input_config_file), str(line_no))) if 'namespace' not in config_data: if config_data[2] not in valid_encodings: - raise SystemExit("Oops...config file: `" + str(input_config_file) + \ - "` has invalid encoding at line no:" + str(line_no)) + raise SystemExit("Oops...config file: %s has invalid encoding at line no:%s\n`" \ + % (str(input_config_file), str(line_no))) @@ -110,9 +104,8 @@ def verify_file_data_count(input_config_file, keys_repeat): for line in config_file_reader: line_no += 1 if len(line) != 3 and line[0] not in keys_repeat: - raise SystemExit("Oops...data missing in config file at line no: " + str(line_no) + \ - " ") - + raise SystemExit("Oops...data missing in config file at line no:%s \n" \ + % str(line_no) ) config_file.close() @@ -254,29 +247,17 @@ def set_repeat_value(total_keys_repeat, keys, csv_file): target_filename = filename + "_created" + file_ext with open(csv_file, 'r') as read_from, open(target_filename,'w') as write_to: csv_file_reader = csv.reader(read_from, delimiter=',') - if sys.version_info[0] < 3: - headers = csv_file_reader.next() - values = csv_file_reader.next() - else: - headers = next(csv_file_reader) - values = next(csv_file_reader) - - if sys.version_info[0] < 3: - total_keys_values = map(None, keys, values) - else: - total_keys_values = list(zip_longest(keys, values)) - + headers = next(csv_file_reader) + values = next(csv_file_reader) csv_file_writer = csv.writer(write_to, delimiter=',') csv_file_writer.writerow(headers) csv_file_writer.writerow(values) + total_keys_values = list(zip_longest(keys, values)) # read new data, add value if key has repeat tag, write to new file for row in csv_file_reader: index = -1 - if sys.version_info[0] < 3: - key_val_new = map(None, keys, row) - else: - key_val_new = list(zip_longest(keys, row)) + key_val_new = list(zip_longest(keys, row)) key_val_pair = total_keys_values[:] key_repeated = total_keys_repeat[:] @@ -371,11 +352,11 @@ file_identifier=None,output_dir_path=None): # Verify config file is not empty if os.stat(input_config_file).st_size == 0: - raise SystemExit("Oops...config file: " + input_config_file + " is empty...") + raise SystemExit("Oops...config file: %s is empty." % input_config_file) # Verify values file is not empty if os.stat(input_values_file).st_size == 0: - raise SystemExit("Oops...values file: " + input_values_file + " is empty...") + raise SystemExit("Oops...values file: %s is empty." % input_values_file ) # Verify config file does not have empty lines csv_config_file = open(input_config_file,'r') @@ -390,9 +371,9 @@ file_identifier=None,output_dir_path=None): is_empty_line = False break if is_empty_line: - raise SystemExit("Oops...config file: " + input_config_file + " cannot have empty lines...") + raise SystemExit("Oops...config file: %s cannot have empty lines. " % input_config_file ) if not config_data: - raise SystemExit("Oops...config file: " + input_config_file + " cannot have empty lines...") + raise SystemExit("Oops...config file: %s cannot have empty lines." % input_config_file ) csv_config_file.seek(0) @@ -415,10 +396,7 @@ file_identifier=None,output_dir_path=None): # Verify values file does not have empty lines - if sys.version_info[0] < 3: - csv_values_file = open(input_values_file,'rb') - else: - csv_values_file = open(input_values_file,'r', newline='') + csv_values_file = open(input_values_file, 'r') try: values_file_reader = csv.reader(csv_values_file, delimiter=',') for values_data in values_file_reader: @@ -430,17 +408,14 @@ file_identifier=None,output_dir_path=None): is_empty_line = False break if is_empty_line: - raise SystemExit("Oops...values file: " + input_values_file + " cannot have empty lines...") + raise SystemExit("Oops...values file: %s cannot have empty lines." % input_values_file ) if not values_data: - raise SystemExit("Oops...values file: " + input_values_file + " cannot have empty lines...") + raise SystemExit("Oops...values file: %s cannot have empty lines." % input_values_file ) csv_values_file.seek(0) # Extract keys from values file - if sys.version_info[0] < 3: - keys_in_values_file = values_file_reader.next() - else: - keys_in_values_file = next(values_file_reader) + keys_in_values_file = next(values_file_reader) csv_values_file.close() except Exception as e: @@ -452,8 +427,8 @@ file_identifier=None,output_dir_path=None): # Verify file identifier exists in values file if file_identifier: if file_identifier not in keys_in_values_file: - raise SystemExit('Oops...target_file_identifier: ' + file_identifier + \ - ' does not exist in values file...\n') + raise SystemExit('Oops...target_file_identifier: %s does not exist in values file.\n' % file_identifier ) + # Verify data in the input_config_file and input_values_file verify_data_in_file(input_config_file, input_values_file, keys_in_config_file,\ @@ -463,35 +438,20 @@ file_identifier=None,output_dir_path=None): config_data_to_write = add_config_data_per_namespace(input_config_file) try: - if sys.version_info[0] < 3: - with open(input_values_file,'rb') as csv_values_file: - values_file_reader = csv.reader(csv_values_file, delimiter=',') - keys = values_file_reader.next() - else: - with open(input_values_file,'r', newline='') as csv_values_file: - values_file_reader = csv.reader(csv_values_file, delimiter=',') - keys = next(values_file_reader) + with open(input_values_file, 'r') as csv_values_file: + values_file_reader = csv.reader(csv_values_file, delimiter=',') + keys = next(values_file_reader) target_values_file = set_repeat_value(keys_repeat, keys, input_values_file) - if sys.version_info[0] < 3: - csv_values_file = open(target_values_file, 'rb') - else: - csv_values_file = open(target_values_file, 'r', newline='') + csv_values_file = open(target_values_file, 'r') values_file_reader = csv.reader(csv_values_file, delimiter=',') - if sys.version_info[0] < 3: - values_file_reader.next() - else: - next(values_file_reader) + next(values_file_reader) for values_data_line in values_file_reader: - if sys.version_info[0] < 3: - key_value_data = map(None,keys_in_values_file,values_data_line) - else: - key_value_data = list(zip_longest(keys_in_values_file,values_data_line)) - + key_value_data = list(zip_longest(keys_in_values_file,values_data_line)) # Get file identifier value from values file file_identifier_value = get_fileid_val(file_identifier, keys_in_config_file, \ @@ -507,7 +467,7 @@ file_identifier=None,output_dir_path=None): csv_file_list.append(csv_filename) output_csv_file = output_target_dir + csv_filename if os.path.isfile(output_csv_file): - raise SystemExit("Target csv file: `" + output_csv_file + "` already exists...") + raise SystemExit("Target csv file: %s already exists.`" % output_csv_file ) # Add values corresponding to each key to csv target file add_data_to_file(config_data_to_write, key_value_pair, output_csv_file) @@ -519,7 +479,7 @@ file_identifier=None,output_dir_path=None): output_bin_file = output_target_dir + target_file_name_prefix + "-" +\ file_identifier_value + ".bin" if os.path.isfile(output_bin_file): - raise SystemExit("Target csv file: `" + output_bin_file + "` already exists...") + raise SystemExit("Target csv file: %s already exists.`" % output_bin_file ) # Create output csv and bin file print("CSV Generated: ", str(output_csv_file)) From 94f6b1a9ee7290366d94fdd571c8a4325cad943a Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Fri, 12 Oct 2018 10:16:39 +0530 Subject: [PATCH 12/24] util: Update docs as per review comments --- components/nvs_flash/nvs_partition_generator/README.rst | 3 ++- .../nvs_flash/nvs_partition_generator/nvs_partition_gen.py | 4 ++-- tools/mass_mfg/docs/README.rst | 2 +- tools/mass_mfg/mfg_gen.py | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/README.rst b/components/nvs_flash/nvs_partition_generator/README.rst index f0c6d6623..bea753864 100644 --- a/components/nvs_flash/nvs_partition_generator/README.rst +++ b/components/nvs_flash/nvs_partition_generator/README.rst @@ -116,6 +116,7 @@ A sample CSV file is provided with the utility:: python nvs_partition_gen.py sample_singlepage_blob.csv partition_single_page.bin --version v1 + +------------------------+----------------------------------------------------------------------------------------------+ | Arguments | Description | +========================+==============================================================================================+ @@ -123,7 +124,7 @@ A sample CSV file is provided with the utility:: +------------------------+----------------------------------------------------------------------------------------------+ | output | Path to output converted binary file. Will use stdout if omitted | +------------------------+----------------------------------------------------------------------------------------------+ -| size | Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000 | +| size | Size of NVS Partition in bytes (must be multiple of 4096) | +------------------------+----------------------------------------------------------------------------------------------+ | --version {v1,v2} | Set version. Default: v2 | +-------------------------------+---------------------------------------------------------------------------------------+ diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 2a01d0744..416c146fc 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -18,7 +18,7 @@ # limitations under the License. # -from __future__ import division, print_function #, unicode_literals +from __future__ import division, print_function from builtins import int, range from io import open import sys @@ -732,7 +732,7 @@ def main(): parser.add_argument( "size", - help='Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000') + help='Size of NVS Partition in bytes (must be multiple of 4096)') parser.add_argument( "--version", diff --git a/tools/mass_mfg/docs/README.rst b/tools/mass_mfg/docs/README.rst index 8d50aedf8..881fed696 100644 --- a/tools/mass_mfg/docs/README.rst +++ b/tools/mass_mfg/docs/README.rst @@ -120,7 +120,7 @@ The mfg\_gen.py utility is using the generated CSV Configuration file and Master +------------------------+----------------------------------------------------------------------------------------------+ | Arguments | Description | +========================+==============================================================================================+ -| --size PART_SIZE | Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000 | +| --size PART_SIZE | Size of NVS Partition in bytes (must be multiple of 4096) | +------------------------+----------------------------------------------------------------------------------------------+ | --conf CONFIG_FILE | the input configuration csv file | +------------------------+----------------------------------------------------------------------------------------------+ diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index 07b2b28e6..c5502161c 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -16,7 +16,7 @@ # from __future__ import print_function -from builtins import map, range +from builtins import range from future.moves.itertools import zip_longest import sys import os @@ -27,6 +27,7 @@ import distutils.dir_util sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen + def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file """ @@ -288,7 +289,7 @@ file_identifier=None,output_dir_path=None): parser.add_argument("--size", dest='part_size', required=True, - help='Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000') + help='Size of NVS Partition in bytes (must be multiple of 4096)') parser.add_argument('--conf', dest='config_file', From 17c907b35e913c8608c6104d627c4d08880c3ade Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Tue, 11 Sep 2018 13:43:05 +0530 Subject: [PATCH 13/24] Update mfg utility as per updated nvs partition util --- tools/mass_mfg/docs/README.rst | 6 ++++-- tools/mass_mfg/mfg_gen.py | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) mode change 100644 => 100755 tools/mass_mfg/mfg_gen.py diff --git a/tools/mass_mfg/docs/README.rst b/tools/mass_mfg/docs/README.rst index 4914806d0..f71ec7eac 100644 --- a/tools/mass_mfg/docs/README.rst +++ b/tools/mass_mfg/docs/README.rst @@ -115,11 +115,13 @@ The mfg\_gen.py utility is using the generated CSV Configuration file and Master **Usage**:: - $ ./mfg_gen.py [-h] --conf CONFIG_FILE --values VALUES_FILE --prefix PREFIX [--fileid FILEID] [--outdir OUTDIR] + $ ./mfg_gen.py [-h] --size PART_SIZE --conf CONFIG_FILE --values VALUES_FILE --prefix PREFIX [--fileid FILEID] [--outdir OUTDIR] +------------------------+----------------------------------------------------------------------------------------------+ | Arguments | Description | +========================+==============================================================================================+ +| --size PART_SIZE | the size of NVS Partition in KB. Eg. 12KB | ++------------------------+----------------------------------------------------------------------------------------------+ | --conf CONFIG_FILE | the input configuration csv file | +------------------------+----------------------------------------------------------------------------------------------+ | --values VALUES_FILE | the input values csv file | @@ -134,7 +136,7 @@ The mfg\_gen.py utility is using the generated CSV Configuration file and Master **You can use the below command to run this utility with the sample files provided**:: - $ ./mfg_gen.py --conf sample_config.csv --values sample_values.csv --prefix Fan + $ ./mfg_gen.py --size 12KB --conf samples/sample_config.csv --values samples/sample_values.csv --prefix Fan .. note:: The default numeric value: 1,2,3... of ``fileid`` argument, corresponds to each row having device instance values in master csv values file. diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py old mode 100644 new mode 100755 index 9060dde22..56aa61cac --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -284,6 +284,11 @@ file_identifier=None,output_dir_path=None): description="Create binary files from input config and values file", formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--size", + dest='part_size', + required=True, + help='Size of NVS Partition in KB. Eg. 12KB') + parser.add_argument('--conf', dest='config_file', required=True, @@ -320,6 +325,7 @@ file_identifier=None,output_dir_path=None): if not args.outdir.endswith('/'): args.outdir = args.outdir + '/' + input_part_size = args.part_size input_config_file = args.config_file input_values_file = args.values_file target_file_name_prefix = args.prefix @@ -472,7 +478,8 @@ file_identifier=None,output_dir_path=None): # Create output csv and bin file print "CSV Generated: " + str(output_csv_file) - nvs_partition_gen.nvs_part_gen(input_filename = output_csv_file, output_filename = output_bin_file) + nvs_partition_gen.nvs_part_gen(input_filename = output_csv_file, output_filename = output_bin_file,\ + input_size=input_part_size) print "NVS Flash Binary Generated: " + str(output_bin_file) files_created = True From 807e72adce0d5afd267a954ed6a706864b795c84 Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Wed, 3 Oct 2018 17:01:00 +0530 Subject: [PATCH 14/24] mfg_gen: Add changes to make Python2 and Python3 compatible --- tools/mass_mfg/mfg_gen.py | 102 +++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 29 deletions(-) diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index 56aa61cac..a9813ae22 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -15,25 +15,32 @@ # limitations under the License. # +from __future__ import print_function import sys import os import csv import argparse import shutil import distutils.dir_util +from itertools import zip_longest sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen - def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file """ line_no = 1 key_count_in_values_file = len(keys_in_values_file) - values_file = open(input_values_file,'rb') + if sys.version_info[0] < 3: + values_file = open(input_values_file, 'rb') + else: + values_file = open(input_values_file, 'r', newline='') values_file_reader = csv.reader(values_file, delimiter=',') - keys = values_file_reader.next() + if sys.version_info[0] < 3: + keys = values_file_reader.next() + else: + keys = next(values_file_reader) for values_data in values_file_reader: line_no +=1 @@ -59,12 +66,11 @@ def verify_keys_exist(values_file_keys, input_config_file): else: keys_missing.append([config_data[0], line_no]) - + if keys_missing: - print "Oops..." for key, line_no in keys_missing: - print "Key:`" + str(key) + "` at line no:" + str(line_no) + \ - " in config file is not found in values file..." + print("Key:`", str(key), "` at line no:", str(line_no),\ + " in config file is not found in values file.") config_file.close() raise SystemExit(1) @@ -131,7 +137,7 @@ def verify_data_in_file(input_config_file, input_values_file, config_file_keys, verify_values_exist(input_values_file, keys_in_values_file) except StandardError as std_err: - print std_err + print(std_err) except: raise @@ -203,6 +209,7 @@ def add_data_to_file(config_data_to_write, key_value_pair, output_csv_file): data_to_write = [] target_csv_file = open(output_csv_file, 'w') + output_file_writer = csv.writer(target_csv_file, delimiter=',') output_file_writer.writerow(header) @@ -246,9 +253,17 @@ def set_repeat_value(total_keys_repeat, keys, csv_file): target_filename = filename + "_created" + file_ext with open(csv_file, 'r') as read_from, open(target_filename,'w') as write_to: csv_file_reader = csv.reader(read_from, delimiter=',') - headers = csv_file_reader.next() - values = csv_file_reader.next() - total_keys_values = map(None, keys, values) + if sys.version_info[0] < 3: + headers = csv_file_reader.next() + values = csv_file_reader.next() + else: + headers = next(csv_file_reader) + values = next(csv_file_reader) + + if sys.version_info[0] < 3: + total_keys_values = map(None, keys, values) + else: + total_keys_values = list(zip_longest(keys, values)) csv_file_writer = csv.writer(write_to, delimiter=',') csv_file_writer.writerow(headers) @@ -257,7 +272,11 @@ def set_repeat_value(total_keys_repeat, keys, csv_file): # read new data, add value if key has repeat tag, write to new file for row in csv_file_reader: index = -1 - key_val_new = map(None, keys, row) + if sys.version_info[0] < 3: + key_val_new = map(None, keys, row) + else: + key_val_new = list(zip_longest(keys, row)) + key_val_pair = total_keys_values[:] key_repeated = total_keys_repeat[:] while key_val_new and key_repeated: @@ -270,7 +289,7 @@ def set_repeat_value(total_keys_repeat, keys, csv_file): del key_repeated[0] del key_val_new[0] del key_val_pair[0] - + return target_filename @@ -288,7 +307,7 @@ file_identifier=None,output_dir_path=None): dest='part_size', required=True, help='Size of NVS Partition in KB. Eg. 12KB') - + parser.add_argument('--conf', dest='config_file', required=True, @@ -387,7 +406,7 @@ file_identifier=None,output_dir_path=None): csv_config_file.close() except Exception as e: - print e + print(e) finally: csv_config_file.close() @@ -395,7 +414,10 @@ file_identifier=None,output_dir_path=None): # Verify values file does not have empty lines - csv_values_file = open(input_values_file,'rb') + if sys.version_info[0] < 3: + csv_values_file = open(input_values_file,'rb') + else: + csv_values_file = open(input_values_file,'r', newline='') try: values_file_reader = csv.reader(csv_values_file, delimiter=',') for values_data in values_file_reader: @@ -414,11 +436,14 @@ file_identifier=None,output_dir_path=None): csv_values_file.seek(0) # Extract keys from values file - keys_in_values_file = values_file_reader.next() + if sys.version_info[0] < 3: + keys_in_values_file = values_file_reader.next() + else: + keys_in_values_file = next(values_file_reader) csv_values_file.close() except Exception as e: - print e + print(e) exit(1) finally: csv_values_file.close() @@ -437,16 +462,35 @@ file_identifier=None,output_dir_path=None): config_data_to_write = add_config_data_per_namespace(input_config_file) try: - with open(input_values_file,'rb') as csv_values_file: - values_file_reader = csv.reader(csv_values_file, delimiter=',') - keys = values_file_reader.next() + if sys.version_info[0] < 3: + with open(input_values_file,'rb') as csv_values_file: + values_file_reader = csv.reader(csv_values_file, delimiter=',') + keys = values_file_reader.next() + else: + with open(input_values_file,'r', newline='') as csv_values_file: + values_file_reader = csv.reader(csv_values_file, delimiter=',') + keys = next(values_file_reader) + target_values_file = set_repeat_value(keys_repeat, keys, input_values_file) - csv_values_file = open(target_values_file, 'rb') + + if sys.version_info[0] < 3: + csv_values_file = open(target_values_file, 'rb') + else: + csv_values_file = open(target_values_file, 'r', newline='') + values_file_reader = csv.reader(csv_values_file, delimiter=',') - values_file_reader.next() + if sys.version_info[0] < 3: + values_file_reader.next() + else: + next(values_file_reader) + for values_data_line in values_file_reader: - key_value_data = map(None,keys_in_values_file,values_data_line) + if sys.version_info[0] < 3: + key_value_data = map(None,keys_in_values_file,values_data_line) + else: + key_value_data = list(zip_longest(keys_in_values_file,values_data_line)) + # Get file identifier value from values file file_identifier_value = get_fileid_val(file_identifier, keys_in_config_file, \ @@ -477,16 +521,16 @@ file_identifier=None,output_dir_path=None): raise SystemExit("Target csv file: `" + output_bin_file + "` already exists...") # Create output csv and bin file - print "CSV Generated: " + str(output_csv_file) + print("CSV Generated: ", str(output_csv_file)) nvs_partition_gen.nvs_part_gen(input_filename = output_csv_file, output_filename = output_bin_file,\ input_size=input_part_size) - print "NVS Flash Binary Generated: " + str(output_bin_file) + print("NVS Flash Binary Generated: ", str(output_bin_file)) files_created = True csv_values_file.close() except Exception as e: - print e + print(e) exit(1) finally: csv_values_file.close() @@ -494,8 +538,8 @@ file_identifier=None,output_dir_path=None): return csv_file_list, files_created - except StandardError as std_err: - print std_err + except ValueError as err: + print(err) except: raise From 4bc87a414f471c1b23ddd9e93a2295af80374351 Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Mon, 8 Oct 2018 10:32:09 +0530 Subject: [PATCH 15/24] nvs_part_gen: Update to make python version compatible (cherry picked from commit 3506b2d60792e5d4ed4f744b28f2da6733c6aae7) --- .../nvs_partition_gen.py | 199 +++++++++++++----- .../nvs_flash/test_nvs_host/test_nvs.cpp | 13 +- 2 files changed, 154 insertions(+), 58 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 0f641d612..a1cc81a65 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -28,6 +28,7 @@ import os import array import csv import zlib +import codecs from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend @@ -81,9 +82,9 @@ class Page(object): # set page state to active page_header= bytearray(b'\xff')*32 page_state_active_seq = Page.ACTIVE - page_header[0:4] = struct.pack('= Page.PAGE_PARAMS["max_entries"]: raise PageFullError() - entry_struct = bytearray('\xff')*32 + entry_struct = bytearray(b'\xff')*32 entry_struct[0] = ns_index # namespace index entry_struct[2] = 0x01 # Span chunk_index = Page.CHUNK_ANY entry_struct[3] = chunk_index # write key - key_array = bytearray('\x00')*16 + key_array = bytearray(b'\x00')*16 entry_struct[8:24] = key_array - entry_struct[8:8 + len(key)] = key + + if sys.version_info[0] < 3: + entry_struct[8:8 + len(key)] = key + else: + entry_struct[8:8 + len(key)] = key.encode('utf8') + if encoding == "u8": entry_struct[1] = Page.U8 - entry_struct[24] = struct.pack(' Date: Mon, 8 Oct 2018 11:11:56 +0530 Subject: [PATCH 16/24] nvs_part_gen: Add changes to partition size input --- .../nvs_partition_generator/README.rst | 2 +- .../nvs_partition_gen.py | 23 +++++++++---------- tools/mass_mfg/docs/README.rst | 4 ++-- tools/mass_mfg/mfg_gen.py | 5 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/README.rst b/components/nvs_flash/nvs_partition_generator/README.rst index aa7a945c2..f0c6d6623 100644 --- a/components/nvs_flash/nvs_partition_generator/README.rst +++ b/components/nvs_flash/nvs_partition_generator/README.rst @@ -123,7 +123,7 @@ A sample CSV file is provided with the utility:: +------------------------+----------------------------------------------------------------------------------------------+ | output | Path to output converted binary file. Will use stdout if omitted | +------------------------+----------------------------------------------------------------------------------------------+ -| size | Size of NVS Partition in KB. Eg. 12KB | +| size | Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000 | +------------------------+----------------------------------------------------------------------------------------------+ | --version {v1,v2} | Set version. Default: v2 | +-------------------------------+---------------------------------------------------------------------------------------+ diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index a1cc81a65..2b11877ca 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -179,7 +179,7 @@ class Page(object): data_input = byte_arr - + if sys.version_info[0] < 3: data_input = binascii.hexlify(bytearray(data_input)) else: @@ -214,7 +214,6 @@ class Page(object): data_val = str(data_bytes) + (init_data_val * (data_len_needed - len(data_bytes))) encr_data_ret = self.encrypt_entry(data_val, tweak_val, encr_key_input) - #print("\n<<<\n") encr_data_to_write = encr_data_to_write + encr_data_ret # Update values for encrypting next set of data bytes start_idx = end_idx @@ -233,7 +232,7 @@ class Page(object): encr_data[0:len(encr_data_ret)] = encr_data_ret else: encr_data[0:len(encr_data_ret)] = encr_data_ret - + data = encr_data data_offset = Page.FIRST_ENTRY_OFFSET + (Page.SINGLE_ENTRY_SIZE * self.entry_num) @@ -311,7 +310,7 @@ class Page(object): if not sys.version_info[0] < 3: if type(data_chunk) == str: data_chunk = codecs.encode(data_chunk, 'utf8') - + crc = zlib.crc32(data_chunk, 0xFFFFFFFF) struct.pack_into(' Date: Thu, 11 Oct 2018 11:49:32 +0530 Subject: [PATCH 17/24] nvs_util: Add Python2 and Python3 compatible --- .../nvs_partition_gen.py | 171 +++++------------- 1 file changed, 50 insertions(+), 121 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 2b11877ca..2330c6102 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -17,8 +17,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from __future__ import division -from __future__ import print_function + +from __future__ import division, print_function #, unicode_literals +from future.utils import raise_ +from builtins import int, range +from io import open import sys import argparse import binascii @@ -80,7 +83,7 @@ class Page(object): global page_header # set page state to active - page_header= bytearray(b'\xff')*32 + page_header= bytearray(b'\xff') *32 page_state_active_seq = Page.ACTIVE struct.pack_into(' Date: Tue, 11 Sep 2018 13:43:05 +0530 Subject: [PATCH 18/24] Update mfg utility as per updated nvs partition util --- tools/mass_mfg/mfg_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index ca9c94cb0..c02c0e156 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -308,7 +308,7 @@ file_identifier=None,output_dir_path=None): dest='part_size', required=True, help='Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000') - + parser.add_argument('--conf', dest='config_file', required=True, From 302d339640f06a382ea23b715456af7d08687b3b Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Wed, 3 Oct 2018 17:01:00 +0530 Subject: [PATCH 19/24] mfg_gen: Add changes to make Python2 and Python3 compatible --- tools/mass_mfg/mfg_gen.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index c02c0e156..255aa50b1 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -22,10 +22,9 @@ import csv import argparse import shutil import distutils.dir_util +from itertools import zip_longest sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen -if not sys.version_info[0] < 3: - from itertools import zip_longest def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file From 60df21115ed59f2cfebe4a6463db8bdceb9b901c Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Mon, 8 Oct 2018 10:32:09 +0530 Subject: [PATCH 20/24] nvs_part_gen: Update to make python version compatible (cherry picked from commit 3506b2d60792e5d4ed4f744b28f2da6733c6aae7) --- .../nvs_partition_generator/nvs_partition_gen.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 2330c6102..d0c529791 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -193,6 +193,7 @@ class Page(object): data_val = data_bytes + (init_data_val * (data_len_needed - len(data_bytes))) encr_data_ret = self.encrypt_entry(data_val, tweak_val, encr_key_input) + #print("\n<<<\n") encr_data_to_write = encr_data_to_write + encr_data_ret # Update values for encrypting next set of data bytes start_idx = end_idx @@ -207,13 +208,24 @@ class Page(object): if self.is_encrypt: encr_data_ret = self.encrypt_data(data, entrycount,nvs_obj) - encr_data[0:len(encr_data_ret)] = encr_data_ret + if sys.version_info[0] < 3: + encr_data[0:len(encr_data_ret)] = encr_data_ret + else: + encr_data[0:len(encr_data_ret)] = encr_data_ret + data = encr_data data_offset = Page.FIRST_ENTRY_OFFSET + (Page.SINGLE_ENTRY_SIZE * self.entry_num) start_idx = data_offset end_idx = data_offset + len(data) - self.page_buf[start_idx:end_idx] = data + if not sys.version_info[0] < 3: + if type(data) == str: + self.page_buf[start_idx:end_idx] = data + else: + self.page_buf[start_idx:end_idx] = data + else: + self.page_buf[start_idx:end_idx] = data + # Set bitmap array for entries in current page for i in range(0, entrycount): From 0f6bcec2bc442159b1a0335fc04cb2a526870f64 Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Mon, 8 Oct 2018 11:11:56 +0530 Subject: [PATCH 21/24] nvs_part_gen: Add changes to partition size input --- .../nvs_flash/nvs_partition_generator/nvs_partition_gen.py | 3 +-- tools/mass_mfg/mfg_gen.py | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index d0c529791..003d1bab9 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -193,7 +193,6 @@ class Page(object): data_val = data_bytes + (init_data_val * (data_len_needed - len(data_bytes))) encr_data_ret = self.encrypt_entry(data_val, tweak_val, encr_key_input) - #print("\n<<<\n") encr_data_to_write = encr_data_to_write + encr_data_ret # Update values for encrypting next set of data bytes start_idx = end_idx @@ -212,7 +211,7 @@ class Page(object): encr_data[0:len(encr_data_ret)] = encr_data_ret else: encr_data[0:len(encr_data_ret)] = encr_data_ret - + data = encr_data data_offset = Page.FIRST_ENTRY_OFFSET + (Page.SINGLE_ENTRY_SIZE * self.entry_num) diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index 255aa50b1..ca9c94cb0 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -22,9 +22,10 @@ import csv import argparse import shutil import distutils.dir_util -from itertools import zip_longest sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen +if not sys.version_info[0] < 3: + from itertools import zip_longest def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file @@ -307,7 +308,7 @@ file_identifier=None,output_dir_path=None): dest='part_size', required=True, help='Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000') - + parser.add_argument('--conf', dest='config_file', required=True, From 1d38d8a17fed8f4ea5d200d5bb8fe0a509aba67b Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Thu, 11 Oct 2018 11:49:32 +0530 Subject: [PATCH 22/24] nvs_util: Add Python2 and Python3 compatible --- .../nvs_partition_generator/nvs_partition_gen.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 003d1bab9..2330c6102 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -207,24 +207,13 @@ class Page(object): if self.is_encrypt: encr_data_ret = self.encrypt_data(data, entrycount,nvs_obj) - if sys.version_info[0] < 3: - encr_data[0:len(encr_data_ret)] = encr_data_ret - else: - encr_data[0:len(encr_data_ret)] = encr_data_ret - + encr_data[0:len(encr_data_ret)] = encr_data_ret data = encr_data data_offset = Page.FIRST_ENTRY_OFFSET + (Page.SINGLE_ENTRY_SIZE * self.entry_num) start_idx = data_offset end_idx = data_offset + len(data) - if not sys.version_info[0] < 3: - if type(data) == str: - self.page_buf[start_idx:end_idx] = data - else: - self.page_buf[start_idx:end_idx] = data - else: - self.page_buf[start_idx:end_idx] = data - + self.page_buf[start_idx:end_idx] = data # Set bitmap array for entries in current page for i in range(0, entrycount): From 5bee9faf49ce1f4aabb194507cf3f13ce3b15409 Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Thu, 11 Oct 2018 17:50:12 +0530 Subject: [PATCH 23/24] tools: Add Python2 and Python3 compatibility support to nvs util tool and mfg tool --- .../nvs_partition_gen.py | 1 - tools/mass_mfg/mfg_gen.py | 108 ++++++------------ 2 files changed, 34 insertions(+), 75 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 2330c6102..2a01d0744 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -19,7 +19,6 @@ # from __future__ import division, print_function #, unicode_literals -from future.utils import raise_ from builtins import int, range from io import open import sys diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index ca9c94cb0..07b2b28e6 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -16,6 +16,8 @@ # from __future__ import print_function +from builtins import map, range +from future.moves.itertools import zip_longest import sys import os import csv @@ -24,8 +26,6 @@ import shutil import distutils.dir_util sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen -if not sys.version_info[0] < 3: - from itertools import zip_longest def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file @@ -33,21 +33,15 @@ def verify_values_exist(input_values_file, keys_in_values_file): line_no = 1 key_count_in_values_file = len(keys_in_values_file) - if sys.version_info[0] < 3: - values_file = open(input_values_file, 'rb') - else: - values_file = open(input_values_file, 'r', newline='') + values_file = open(input_values_file, 'r') values_file_reader = csv.reader(values_file, delimiter=',') - if sys.version_info[0] < 3: - keys = values_file_reader.next() - else: - keys = next(values_file_reader) + keys = next(values_file_reader) for values_data in values_file_reader: line_no +=1 if len(values_data) != key_count_in_values_file: - raise SystemExit("\nOops...Number of values is not equal to number of keys in file: '" + \ - str(input_values_file) + "' at line No:" + str(line_no) ) + raise SystemExit("\nOops...Number of values is not equal to number of keys in file: %s at line No:%s\n"\ + % (str(input_values_file), str(line_no))) def verify_keys_exist(values_file_keys, input_config_file): @@ -91,12 +85,12 @@ def verify_datatype_encoding(input_config_file): for config_data in config_file_reader: line_no+=1 if config_data[1] not in valid_datatypes: - raise SystemExit("Oops...config file: `" + str(input_config_file) + \ - "` has invalid datatype at line no:" + str(line_no)) + raise SystemExit("Oops...config file: %s has invalid datatype at line no:%s\n`" \ + % (str(input_config_file), str(line_no))) if 'namespace' not in config_data: if config_data[2] not in valid_encodings: - raise SystemExit("Oops...config file: `" + str(input_config_file) + \ - "` has invalid encoding at line no:" + str(line_no)) + raise SystemExit("Oops...config file: %s has invalid encoding at line no:%s\n`" \ + % (str(input_config_file), str(line_no))) @@ -110,9 +104,8 @@ def verify_file_data_count(input_config_file, keys_repeat): for line in config_file_reader: line_no += 1 if len(line) != 3 and line[0] not in keys_repeat: - raise SystemExit("Oops...data missing in config file at line no: " + str(line_no) + \ - " ") - + raise SystemExit("Oops...data missing in config file at line no:%s \n" \ + % str(line_no) ) config_file.close() @@ -254,29 +247,17 @@ def set_repeat_value(total_keys_repeat, keys, csv_file): target_filename = filename + "_created" + file_ext with open(csv_file, 'r') as read_from, open(target_filename,'w') as write_to: csv_file_reader = csv.reader(read_from, delimiter=',') - if sys.version_info[0] < 3: - headers = csv_file_reader.next() - values = csv_file_reader.next() - else: - headers = next(csv_file_reader) - values = next(csv_file_reader) - - if sys.version_info[0] < 3: - total_keys_values = map(None, keys, values) - else: - total_keys_values = list(zip_longest(keys, values)) - + headers = next(csv_file_reader) + values = next(csv_file_reader) csv_file_writer = csv.writer(write_to, delimiter=',') csv_file_writer.writerow(headers) csv_file_writer.writerow(values) + total_keys_values = list(zip_longest(keys, values)) # read new data, add value if key has repeat tag, write to new file for row in csv_file_reader: index = -1 - if sys.version_info[0] < 3: - key_val_new = map(None, keys, row) - else: - key_val_new = list(zip_longest(keys, row)) + key_val_new = list(zip_longest(keys, row)) key_val_pair = total_keys_values[:] key_repeated = total_keys_repeat[:] @@ -371,11 +352,11 @@ file_identifier=None,output_dir_path=None): # Verify config file is not empty if os.stat(input_config_file).st_size == 0: - raise SystemExit("Oops...config file: " + input_config_file + " is empty...") + raise SystemExit("Oops...config file: %s is empty." % input_config_file) # Verify values file is not empty if os.stat(input_values_file).st_size == 0: - raise SystemExit("Oops...values file: " + input_values_file + " is empty...") + raise SystemExit("Oops...values file: %s is empty." % input_values_file ) # Verify config file does not have empty lines csv_config_file = open(input_config_file,'r') @@ -390,9 +371,9 @@ file_identifier=None,output_dir_path=None): is_empty_line = False break if is_empty_line: - raise SystemExit("Oops...config file: " + input_config_file + " cannot have empty lines...") + raise SystemExit("Oops...config file: %s cannot have empty lines. " % input_config_file ) if not config_data: - raise SystemExit("Oops...config file: " + input_config_file + " cannot have empty lines...") + raise SystemExit("Oops...config file: %s cannot have empty lines." % input_config_file ) csv_config_file.seek(0) @@ -415,10 +396,7 @@ file_identifier=None,output_dir_path=None): # Verify values file does not have empty lines - if sys.version_info[0] < 3: - csv_values_file = open(input_values_file,'rb') - else: - csv_values_file = open(input_values_file,'r', newline='') + csv_values_file = open(input_values_file, 'r') try: values_file_reader = csv.reader(csv_values_file, delimiter=',') for values_data in values_file_reader: @@ -430,17 +408,14 @@ file_identifier=None,output_dir_path=None): is_empty_line = False break if is_empty_line: - raise SystemExit("Oops...values file: " + input_values_file + " cannot have empty lines...") + raise SystemExit("Oops...values file: %s cannot have empty lines." % input_values_file ) if not values_data: - raise SystemExit("Oops...values file: " + input_values_file + " cannot have empty lines...") + raise SystemExit("Oops...values file: %s cannot have empty lines." % input_values_file ) csv_values_file.seek(0) # Extract keys from values file - if sys.version_info[0] < 3: - keys_in_values_file = values_file_reader.next() - else: - keys_in_values_file = next(values_file_reader) + keys_in_values_file = next(values_file_reader) csv_values_file.close() except Exception as e: @@ -452,8 +427,8 @@ file_identifier=None,output_dir_path=None): # Verify file identifier exists in values file if file_identifier: if file_identifier not in keys_in_values_file: - raise SystemExit('Oops...target_file_identifier: ' + file_identifier + \ - ' does not exist in values file...\n') + raise SystemExit('Oops...target_file_identifier: %s does not exist in values file.\n' % file_identifier ) + # Verify data in the input_config_file and input_values_file verify_data_in_file(input_config_file, input_values_file, keys_in_config_file,\ @@ -463,35 +438,20 @@ file_identifier=None,output_dir_path=None): config_data_to_write = add_config_data_per_namespace(input_config_file) try: - if sys.version_info[0] < 3: - with open(input_values_file,'rb') as csv_values_file: - values_file_reader = csv.reader(csv_values_file, delimiter=',') - keys = values_file_reader.next() - else: - with open(input_values_file,'r', newline='') as csv_values_file: - values_file_reader = csv.reader(csv_values_file, delimiter=',') - keys = next(values_file_reader) + with open(input_values_file, 'r') as csv_values_file: + values_file_reader = csv.reader(csv_values_file, delimiter=',') + keys = next(values_file_reader) target_values_file = set_repeat_value(keys_repeat, keys, input_values_file) - if sys.version_info[0] < 3: - csv_values_file = open(target_values_file, 'rb') - else: - csv_values_file = open(target_values_file, 'r', newline='') + csv_values_file = open(target_values_file, 'r') values_file_reader = csv.reader(csv_values_file, delimiter=',') - if sys.version_info[0] < 3: - values_file_reader.next() - else: - next(values_file_reader) + next(values_file_reader) for values_data_line in values_file_reader: - if sys.version_info[0] < 3: - key_value_data = map(None,keys_in_values_file,values_data_line) - else: - key_value_data = list(zip_longest(keys_in_values_file,values_data_line)) - + key_value_data = list(zip_longest(keys_in_values_file,values_data_line)) # Get file identifier value from values file file_identifier_value = get_fileid_val(file_identifier, keys_in_config_file, \ @@ -507,7 +467,7 @@ file_identifier=None,output_dir_path=None): csv_file_list.append(csv_filename) output_csv_file = output_target_dir + csv_filename if os.path.isfile(output_csv_file): - raise SystemExit("Target csv file: `" + output_csv_file + "` already exists...") + raise SystemExit("Target csv file: %s already exists.`" % output_csv_file ) # Add values corresponding to each key to csv target file add_data_to_file(config_data_to_write, key_value_pair, output_csv_file) @@ -519,7 +479,7 @@ file_identifier=None,output_dir_path=None): output_bin_file = output_target_dir + target_file_name_prefix + "-" +\ file_identifier_value + ".bin" if os.path.isfile(output_bin_file): - raise SystemExit("Target csv file: `" + output_bin_file + "` already exists...") + raise SystemExit("Target csv file: %s already exists.`" % output_bin_file ) # Create output csv and bin file print("CSV Generated: ", str(output_csv_file)) From 7c08fcccafb22d8e5e1a571d1df7d80de61ea94c Mon Sep 17 00:00:00 2001 From: Shivani Tipnis Date: Fri, 12 Oct 2018 10:16:39 +0530 Subject: [PATCH 24/24] util: Update docs as per review comments --- components/nvs_flash/nvs_partition_generator/README.rst | 3 ++- .../nvs_flash/nvs_partition_generator/nvs_partition_gen.py | 4 ++-- tools/mass_mfg/docs/README.rst | 2 +- tools/mass_mfg/mfg_gen.py | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/nvs_flash/nvs_partition_generator/README.rst b/components/nvs_flash/nvs_partition_generator/README.rst index f0c6d6623..bea753864 100644 --- a/components/nvs_flash/nvs_partition_generator/README.rst +++ b/components/nvs_flash/nvs_partition_generator/README.rst @@ -116,6 +116,7 @@ A sample CSV file is provided with the utility:: python nvs_partition_gen.py sample_singlepage_blob.csv partition_single_page.bin --version v1 + +------------------------+----------------------------------------------------------------------------------------------+ | Arguments | Description | +========================+==============================================================================================+ @@ -123,7 +124,7 @@ A sample CSV file is provided with the utility:: +------------------------+----------------------------------------------------------------------------------------------+ | output | Path to output converted binary file. Will use stdout if omitted | +------------------------+----------------------------------------------------------------------------------------------+ -| size | Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000 | +| size | Size of NVS Partition in bytes (must be multiple of 4096) | +------------------------+----------------------------------------------------------------------------------------------+ | --version {v1,v2} | Set version. Default: v2 | +-------------------------------+---------------------------------------------------------------------------------------+ diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py index 2a01d0744..416c146fc 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -18,7 +18,7 @@ # limitations under the License. # -from __future__ import division, print_function #, unicode_literals +from __future__ import division, print_function from builtins import int, range from io import open import sys @@ -732,7 +732,7 @@ def main(): parser.add_argument( "size", - help='Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000') + help='Size of NVS Partition in bytes (must be multiple of 4096)') parser.add_argument( "--version", diff --git a/tools/mass_mfg/docs/README.rst b/tools/mass_mfg/docs/README.rst index 8d50aedf8..881fed696 100644 --- a/tools/mass_mfg/docs/README.rst +++ b/tools/mass_mfg/docs/README.rst @@ -120,7 +120,7 @@ The mfg\_gen.py utility is using the generated CSV Configuration file and Master +------------------------+----------------------------------------------------------------------------------------------+ | Arguments | Description | +========================+==============================================================================================+ -| --size PART_SIZE | Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000 | +| --size PART_SIZE | Size of NVS Partition in bytes (must be multiple of 4096) | +------------------------+----------------------------------------------------------------------------------------------+ | --conf CONFIG_FILE | the input configuration csv file | +------------------------+----------------------------------------------------------------------------------------------+ diff --git a/tools/mass_mfg/mfg_gen.py b/tools/mass_mfg/mfg_gen.py index 07b2b28e6..c5502161c 100755 --- a/tools/mass_mfg/mfg_gen.py +++ b/tools/mass_mfg/mfg_gen.py @@ -16,7 +16,7 @@ # from __future__ import print_function -from builtins import map, range +from builtins import range from future.moves.itertools import zip_longest import sys import os @@ -27,6 +27,7 @@ import distutils.dir_util sys.path.insert(0, os.getenv('IDF_PATH') + "/components/nvs_flash/nvs_partition_generator/") import nvs_partition_gen + def verify_values_exist(input_values_file, keys_in_values_file): """ Verify all keys have corresponding values in values file """ @@ -288,7 +289,7 @@ file_identifier=None,output_dir_path=None): parser.add_argument("--size", dest='part_size', required=True, - help='Size of NVS Partition in hex (must be multiple of 4096). Eg. 0x1000') + help='Size of NVS Partition in bytes (must be multiple of 4096)') parser.add_argument('--conf', dest='config_file',