From b765963c7c47044de8ec00aef076e742d62cbc0a Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 22 Jul 2022 15:15:53 +1000 Subject: [PATCH] nvs_partition_gen: Allow up to 4000 byte strings with NVS V2 As documented, the limit for NVS format v2 is 4000 bytes for a string. --- .../nvs_partition_gen.py | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 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 91a724658a..b515d12ac2 100755 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -51,13 +51,6 @@ def reverse_hexbytes(addr_tmp): class Page(object): - PAGE_PARAMS = { - 'max_size': 4096, - 'max_old_blob_size': 1984, - 'max_new_blob_size': 4000, - 'max_entries': 126 - } - # Item type codes U8 = 0x01 I8 = 0x11 @@ -84,6 +77,12 @@ class Page(object): VERSION1 = 0xFF VERSION2 = 0xFE + PAGE_PARAMS = { + 'max_size': 4096, + 'max_blob_size': {VERSION1: 1984, VERSION2: 4000}, + 'max_entries': 126 + } + def __init__(self, page_num, version, is_rsrv_page=False): self.entry_num = 0 self.bitmap_array = array.array('B') @@ -348,14 +347,13 @@ class Page(object): # Set size of data datalen = len(data) - if datalen > Page.PAGE_PARAMS['max_old_blob_size']: - if self.version == Page.VERSION1: - raise InputError(' Input File: Size (%d) exceeds max allowed length `%s` bytes for key `%s`.' - % (datalen, Page.PAGE_PARAMS['max_old_blob_size'], key)) - else: - if encoding == 'string': - raise InputError(' Input File: Size (%d) exceeds max allowed length `%s` bytes for key `%s`.' - % (datalen, Page.PAGE_PARAMS['max_old_blob_size'], key)) + max_blob_size = Page.PAGE_PARAMS['max_blob_size'][self.version] + # V2 blob size limit only applies to strings + blob_limit_applies = self.version == Page.VERSION1 or encoding == 'string' + + if blob_limit_applies and datalen > max_blob_size: + raise InputError(' Input File: Size (%d) exceeds max allowed length `%s` bytes for key `%s`.' + % (datalen, max_blob_size, key)) # Calculate no. of entries data will require rounded_size = (datalen + 31) & ~31