From 3082c28b1efae0feba02ef8459c6ce3ef2983256 Mon Sep 17 00:00:00 2001 From: Matthias Goebel Date: Fri, 3 May 2024 10:59:39 +0200 Subject: [PATCH] skip CRC when initializing TDBStore Problem: The build_ram_table() function of TDBStore loops over every entry, calculates the checksum and compares them to the stored checksum in the entry header to ensure integrity. For larger TDBStores (e.g. 8 MiB or more) in external single-SPI flash devices this check can take very long, thus rendering it unusable in some cases. Solution: The suggested solution skips the time consuming CRC of the data. After reading the key and calculating its CRC, it sets next_offset to the beginning of the next entry, thereby skipping the data. While this skips the integrity check, it significantly reduces the initial building of the RAM table. The data CRC can be enabled or disabled with a compiler flag. Contribution is provided on behalf of BIOTRONIK. --- storage/kvstore/tdbstore/source/TDBStore.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/storage/kvstore/tdbstore/source/TDBStore.cpp b/storage/kvstore/tdbstore/source/TDBStore.cpp index 7d8d8822f32..15af9e9aa15 100644 --- a/storage/kvstore/tdbstore/source/TDBStore.cpp +++ b/storage/kvstore/tdbstore/source/TDBStore.cpp @@ -374,6 +374,10 @@ int TDBStore::read_record(uint8_t area, uint32_t offset, char *key, if (calc_hash) { hash = calc_crc(hash, chunk_size, dest_buf); +#ifdef KVSTORE_RAM_TABLE_NO_CRC_CHECK + next_offset = align_up(offset + total_size, _prog_size); + return ret; +#endif /* KVSTORE_RAM_TABLE_NO_CRC_CHECK */ } user_key_ptr += chunk_size;