From 1601c0ad385d50828ca345a4c78407ca54309119 Mon Sep 17 00:00:00 2001 From: kerms Date: Wed, 11 Mar 2026 11:03:42 +0100 Subject: [PATCH] fix(crc32): use correct init value for ESP-IDF ROM CRC32 esp_rom_crc32_le(0xFFFFFFFF, ...) inverts the input (~0xFFFFFFFF = 0), so the effective init is 0x00000000, not 0xFFFFFFFF (standard zlib). This caused all NVS page/entry CRC checks to fail silently. --- lib/shared/crc32.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/shared/crc32.ts b/lib/shared/crc32.ts index 95da4f9..2117247 100644 --- a/lib/shared/crc32.ts +++ b/lib/shared/crc32.ts @@ -1,6 +1,6 @@ /** * Pre-computed CRC32 lookup table using reflected polynomial 0xEDB88320. - * Compatible with zlib.crc32() used by ESP-IDF. + * Compatible with esp_rom_crc32_le(0xFFFFFFFF, ...) used by ESP-IDF NVS/OTA. */ const CRC32_TABLE: Uint32Array = (() => { const table = new Uint32Array(256); @@ -16,7 +16,7 @@ const CRC32_TABLE: Uint32Array = (() => { /** Compute CRC32 of a Uint8Array. Returns unsigned 32-bit integer. */ export function crc32(data: Uint8Array): number { - let crc = 0xFFFFFFFF; + let crc = 0x00000000; for (let i = 0; i < data.length; i++) { crc = (crc >>> 8) ^ CRC32_TABLE[(crc ^ data[i]) & 0xFF]; }