feature/nvs_partition_gen_utility: Changes to make nvs_partition_gen_utility compatible with ESP8266.

Changes:
Removed version, keygen, encrypt, keyfile options from help.
Updated README.md accordingly
This commit is contained in:
Supreet Deshpande
2019-02-18 10:45:42 +05:30
parent 0eae336342
commit 3d2bd0cce0
2 changed files with 8 additions and 147 deletions

View File

@ -7,13 +7,6 @@ Introduction
:component_file:`nvs_flash/nvs_partition_generator/nvs_partition_gen.py` utility is designed to help create a binary file, compatible with NVS architecture defined in :doc:`Non-Volatile Storage </api-reference/storage/nvs_flash>`, based on user provided key-value pairs in a CSV file.
Utility is ideally suited for generating a binary blob, containing data specific to ODM/OEM, which can be flashed externally at the time of device manufacturing. This helps manufacturers set unique value for various parameters for each device, e.g. serial number, while using same application firmware for all devices.
Prerequisites
-------------
To use this utility in encryption mode, the following packages need to be installed:
- cryptography package
This dependency is already captured by including these packages in `requirement.txt` in top level IDF directory.
CSV file format
---------------
@ -53,26 +46,10 @@ When a new namespace entry is encountered in the CSV file, each follow-up entrie
.. note:: First entry in a CSV file should always be ``namespace`` entry.
Multipage Blob Support
----------------------
By default, binary blobs are allowed to span over multiple pages and written in the format mentioned in section :ref:`structure_of_entry`.
If older format is intended to be used, the utility provides an option to disable this feature.
Encryption Support
-------------------
This utility allows you to create an enrypted binary file also. Encryption used is AES-XTS encryption. Refer to :ref:`nvs_encryption` for more details.
Running the utility
-------------------
**Usage**::
python nvs_partition_gen.py [-h] [--input INPUT] [--output OUTPUT]
[--size SIZE] [--version {v1,v2}]
[--keygen {true,false}] [--encrypt {true,false}]
[--keyfile KEYFILE]
python nvs_partition_gen.py [-h] [--input INPUT] [--output OUTPUT] [--size SIZE]
+------------------------+----------------------------------------------------------------------------------------------+
| Arguments | Description |
@ -83,93 +60,11 @@ Running the utility
+------------------------+----------------------------------------------------------------------------------------------+
| --size SIZE | Size of NVS Partition in bytes (must be multiple of 4096) |
+------------------------+----------------------------------------------------------------------------------------------+
| --version {v1,v2} | Set version. Default: v2 |
+------------------------+----------------------------------------------------------------------------------------------+
| --keygen {true,false} | Generate keys for encryption. Creates an `encryption_keys.bin` file (in current directory). |
| | Default: false |
+------------------------+----------------------------------------------------------------------------------------------+
| --encrypt {true,false} | Set encryption mode. Default: false |
+------------------------+----------------------------------------------------------------------------------------------+
| --keyfile KEYFILE | File having key for encryption (Applicable only if encryption mode is true) |
+------------------------+----------------------------------------------------------------------------------------------+
You can run this utility in two modes:
- Default mode - Binary generated in this mode is an unencrypted binary file.
- Encryption mode - Binary generated in this mode is an encrypted binary file.
**In default mode:**
--------------------
*Usage*::
python nvs_partition_gen.py [-h] --input INPUT --output OUTPUT
--size SIZE [--version {v1,v2}]
[--keygen {true,false}] [--encrypt {true,false}]
[--keyfile KEYFILE]
You can run the utility using below command::
A sample CSV file is provided with the utility::
python nvs_partition_gen.py --input sample.csv --output sample.bin --size 0x3000
**In encryption mode:**
-----------------------
*Usage*::
python nvs_partition_gen.py [-h] --input INPUT --output OUTPUT
--size SIZE --encrypt {true,false}
--keygen {true,false} | --keyfile KEYFILE
[--version {v1,v2}]
You can run the utility using below commands:
- By taking encryption keys as an input file. A sample encryption keys binary file is provided with the utility::
python nvs_partition_gen.py --input sample.csv --output sample_encrypted.bin --size 0x3000 --encrypt true --keyfile testdata/sample_encryption_keys.bin
- By enabling generation of encryption keys::
python nvs_partition_gen.py --input sample.csv --output sample_encrypted.bin --size 0x3000 --encrypt true --keygen true
*To generate* **only** *encryption keys with this utility* ( Creates an `encryption_keys.bin` file in current directory ): ::
python nvs_partition_gen.py --keygen true
.. note:: This `encryption_keys.bin` file is compatible with NVS key-partition structure. Refer to :ref:`nvs_key_partition` for more details.
You can also provide the format version number (in any of the two modes):
- Multipage Blob Support Enabled (v2)
- Multipage Blob Support Disabled (v1)
**Multipage Blob Support Enabled (v2):**
----------------------------------------
You can run the utility in this format by setting the version parameter to v2, as shown below.
A sample CSV file is provided with the utility::
python nvs_partition_gen.py --input sample_multipage_blob.csv --output partition_multipage_blob.bin --size 0x4000 --version v2
**Multipage Blob Support Disabled (v1):**
-----------------------------------------
You can run the utility in this format by setting the version parameter to v1, as shown below.
A sample CSV file is provided with the utility::
python nvs_partition_gen.py --input sample_singlepage_blob.csv --output partition_single_page.bin --size 0x3000 --version v1
.. note:: *Minimum NVS Partition Size needed is 0x3000 bytes.*
.. note:: *When flashing the binary onto the device, make sure it is consistent with the application's sdkconfig.*

View File

@ -497,10 +497,6 @@ class NVS(object):
break
result = self.get_binary_data()
if version == Page.VERSION1:
print("Version: ", VERSION1_PRINT)
else:
print("Version: ", VERSION2_PRINT)
self.fout.write(result)
def create_new_page(self, is_rsrv_page=False):
@ -786,48 +782,18 @@ def main():
"--size",
help='Size of NVS Partition in bytes (must be multiple of 4096)')
nvs_part_gen_group.add_argument(
"--version",
help='Set version. Default: v2',
choices=['v1','v2'],
default='v2',
type=str.lower)
keygen_action=nvs_part_gen_group.add_argument(
"--keygen",
help='Generate keys for encryption. Creates an `encryption_keys.bin` file. Default: false',
choices=['true','false'],
default= 'false',
type=str.lower)
nvs_part_gen_group.add_argument(
"--encrypt",
help='Set encryption mode. Default: false',
choices=['true','false'],
default='false',
type=str.lower)
nvs_part_gen_group.add_argument(
"--keyfile",
help='File having key for encryption (Applicable only if encryption mode is true)',
default = None)
key_gen_group = parser.add_argument_group('To generate encryption keys')
key_gen_group._group_actions.append(keygen_action)
args = parser.parse_args()
input_filename = args.input
output_filename = args.output
part_size = args.size
version_no = args.version
is_key_gen = args.keygen
is_encrypt_data = args.encrypt
key_file = args.keyfile
version_no = 'v1'
is_key_gen = 'false'
is_encrypt_data = 'false'
key_file = None
print_arg_str = "Invalid.\nTo generate nvs partition binary --input, --output and --size arguments are mandatory.\nTo generate encryption keys --keygen argument is mandatory."
print_encrypt_arg_str = "Missing parameter. Enter --keyfile or --keygen."
print_arg_str = "Invalid.\nTo generate nvs partition binary --input, --output and --size arguments are mandatory."
check_input_args(input_filename,output_filename, part_size, is_key_gen, is_encrypt_data, key_file, version_no, print_arg_str, print_encrypt_arg_str)
check_input_args(input_filename,output_filename, part_size, is_key_gen, is_encrypt_data, key_file, version_no, print_arg_str)
nvs_part_gen(input_filename, output_filename, part_size, is_key_gen, is_encrypt_data, key_file, version_no)