nvs_util: Fix to support write of multiple singlepage big blob data

Closes https://github.com/espressif/esp-idf/issues/3011

(cherry picked from commit ce4944edf01b2a4c997eafe36b66d71f98f2fe29)
(cherry picked from commit 76e4ea7f68)
This commit is contained in:
Shivani Tipnis 2019-02-14 15:17:57 +05:30
parent 8e2b189252
commit c71b38c467
6 changed files with 26 additions and 16 deletions

View file

@ -158,7 +158,7 @@ You can also provide the format version number (in any of the two modes):
You can run the utility in this format by setting the version parameter to v2, as shown below. 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:: 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 0x3000 --version v2 python nvs_partition_gen.py --input sample_multipage_blob.csv --output partition_multipage_blob.bin --size 0x4000 --version v2
**Multipage Blob Support Disabled (v1):** **Multipage Blob Support Disabled (v1):**

View file

@ -379,9 +379,14 @@ class Page(object):
total_entry_count = data_entry_count + 1 # +1 for the entry header total_entry_count = data_entry_count + 1 # +1 for the entry header
# Check if page is already full and new page is needed to be created right away # Check if page is already full and new page is needed to be created right away
if encoding in ["string", "hex2bin", "binary", "base64"]: if version == Page.VERSION1:
if (self.entry_num + total_entry_count) >= Page.PAGE_PARAMS["max_entries"]: if encoding in ["string", "hex2bin", "binary", "base64"]:
raise PageFullError() if (self.entry_num + total_entry_count) >= Page.PAGE_PARAMS["max_entries"]:
raise PageFullError()
else:
if encoding == "string":
if (self.entry_num + total_entry_count) >= Page.PAGE_PARAMS["max_entries"]:
raise PageFullError()
# Entry header # Entry header
entry_struct = bytearray(b'\xff')*32 entry_struct = bytearray(b'\xff')*32

View file

@ -11,4 +11,6 @@ dummyBase64Key,data,base64,MTIzYWJj
hexFileKey,file,hex2bin,testdata/sample.hex hexFileKey,file,hex2bin,testdata/sample.hex
base64FileKey,file,base64,testdata/sample.base64 base64FileKey,file,base64,testdata/sample.base64
stringFileKey,file,string,testdata/sample.txt stringFileKey,file,string,testdata/sample.txt
blobFileAKey,file,binary,testdata/sample_blob.bin
blobFileBKey,file,binary,testdata/sample_blob.bin
binFileKey,file,binary,testdata/sample_multipage_blob.bin binFileKey,file,binary,testdata/sample_multipage_blob.bin

1 key type encoding value
11 hexFileKey file hex2bin testdata/sample.hex
12 base64FileKey file base64 testdata/sample.base64
13 stringFileKey file string testdata/sample.txt
14 blobFileAKey file binary testdata/sample_blob.bin
15 blobFileBKey file binary testdata/sample_blob.bin
16 binFileKey file binary testdata/sample_multipage_blob.bin

View file

@ -11,4 +11,6 @@ dummyBase64Key,data,base64,MTIzYWJj
hexFileKey,file,hex2bin,testdata/sample.hex hexFileKey,file,hex2bin,testdata/sample.hex
base64FileKey,file,base64,testdata/sample.base64 base64FileKey,file,base64,testdata/sample.base64
stringFileKey,file,string,testdata/sample.txt stringFileKey,file,string,testdata/sample.txt
blobFileAKey,file,binary,testdata/sample_blob.bin
blobFileBKey,file,binary,testdata/sample_blob.bin
binFileKey,file,binary,testdata/sample_singlepage_blob.bin binFileKey,file,binary,testdata/sample_singlepage_blob.bin

1 key type encoding value
11 hexFileKey file hex2bin testdata/sample.hex
12 base64FileKey file base64 testdata/sample.base64
13 stringFileKey file string testdata/sample.txt
14 blobFileAKey file binary testdata/sample_blob.bin
15 blobFileBKey file binary testdata/sample_blob.bin
16 binFileKey file binary testdata/sample_singlepage_blob.bin

View file

@ -0,0 +1 @@
start0000000000000000000000start0123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef00000000000000000123456789abcdef0000000000000000end00000000000000000000000000end

View file

@ -2057,14 +2057,14 @@ TEST_CASE("Recovery from power-off during modification of blob present in old-fo
TEST_ESP_ERR(p3.findItem(1, ItemType::BLOB, "singlepage"), ESP_ERR_NVS_NOT_FOUND); TEST_ESP_ERR(p3.findItem(1, ItemType::BLOB, "singlepage"), ESP_ERR_NVS_NOT_FOUND);
} }
static void check_nvs_part_gen_args(char const *part_name, char const *filename, bool is_encr, nvs_sec_cfg_t* xts_cfg) static void check_nvs_part_gen_args(char const *part_name, int size, char const *filename, bool is_encr, nvs_sec_cfg_t* xts_cfg)
{ {
nvs_handle handle; nvs_handle handle;
if (is_encr) if (is_encr)
TEST_ESP_OK(nvs_flash_secure_init_custom(part_name, 0, 3, xts_cfg)); TEST_ESP_OK(nvs_flash_secure_init_custom(part_name, 0, size, xts_cfg));
else else
TEST_ESP_OK( nvs_flash_init_custom(part_name, 0, 3) ); TEST_ESP_OK( nvs_flash_init_custom(part_name, 0, size) );
TEST_ESP_OK( nvs_open_from_partition(part_name, "dummyNamespace", NVS_READONLY, &handle)); TEST_ESP_OK( nvs_open_from_partition(part_name, "dummyNamespace", NVS_READONLY, &handle));
uint8_t u8v; uint8_t u8v;
@ -2148,7 +2148,7 @@ TEST_CASE("check and read data from partition generated via partition generation
TEST_ESP_OK(nvs_flash_deinit()); TEST_ESP_OK(nvs_flash_deinit());
check_nvs_part_gen_args("test", "../nvs_partition_generator/testdata/sample_singlepage_blob.bin", false, NULL); check_nvs_part_gen_args("test", 3, "../nvs_partition_generator/testdata/sample_singlepage_blob.bin", false, NULL);
} }
@ -2163,7 +2163,7 @@ TEST_CASE("check and read data from partition generated via partition generation
"--output", "--output",
"../nvs_partition_generator/partition_multipage_blob.bin", "../nvs_partition_generator/partition_multipage_blob.bin",
"--size", "--size",
"0x3000", "0x4000",
"--version", "--version",
"v2",NULL)); "v2",NULL));
} else { } else {
@ -2175,7 +2175,7 @@ TEST_CASE("check and read data from partition generated via partition generation
SpiFlashEmulator emu("../nvs_partition_generator/partition_multipage_blob.bin"); SpiFlashEmulator emu("../nvs_partition_generator/partition_multipage_blob.bin");
check_nvs_part_gen_args("test", "../nvs_partition_generator/testdata/sample_multipage_blob.bin",false,NULL); check_nvs_part_gen_args("test", 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin",false,NULL);
} }
@ -2329,7 +2329,7 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
"--output", "--output",
"../nvs_partition_generator/partition_encrypted.bin", "../nvs_partition_generator/partition_encrypted.bin",
"--size", "--size",
"0x3000", "0x4000",
"--encrypt", "--encrypt",
"True", "True",
"--keyfile", "--keyfile",
@ -2349,7 +2349,7 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
cfg.tky[count] = 0x22; cfg.tky[count] = 0x22;
} }
check_nvs_part_gen_args(NVS_DEFAULT_PART_NAME, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg); check_nvs_part_gen_args(NVS_DEFAULT_PART_NAME, 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg);
} }
@ -2366,7 +2366,7 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
"--output", "--output",
"../nvs_partition_generator/partition_encrypted_using_keygen.bin", "../nvs_partition_generator/partition_encrypted_using_keygen.bin",
"--size", "--size",
"0x3000", "0x4000",
"--encrypt", "--encrypt",
"True", "True",
"--keygen", "--keygen",
@ -2396,7 +2396,7 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
cfg.tky[count] = buffer[count+32] & 255; cfg.tky[count] = buffer[count+32] & 255;
} }
check_nvs_part_gen_args(NVS_DEFAULT_PART_NAME, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg); check_nvs_part_gen_args(NVS_DEFAULT_PART_NAME, 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg);
} }
@ -2413,7 +2413,7 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
"--output", "--output",
"../nvs_partition_generator/partition_encrypted_using_keyfile.bin", "../nvs_partition_generator/partition_encrypted_using_keyfile.bin",
"--size", "--size",
"0x3000", "0x4000",
"--encrypt", "--encrypt",
"True", "True",
"--keyfile", "--keyfile",
@ -2443,7 +2443,7 @@ TEST_CASE("test nvs apis for nvs partition generator utility with encryption ena
cfg.tky[count] = buffer[count+32] & 255; cfg.tky[count] = buffer[count+32] & 255;
} }
check_nvs_part_gen_args(NVS_DEFAULT_PART_NAME, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg); check_nvs_part_gen_args(NVS_DEFAULT_PART_NAME, 4, "../nvs_partition_generator/testdata/sample_multipage_blob.bin", true, &cfg);
childpid = fork(); childpid = fork();
if (childpid == 0) { if (childpid == 0) {