diff --git a/embed/extmod/modtrezorconfig/norcow.c b/embed/extmod/modtrezorconfig/norcow.c index 91878a567..8f4b49c75 100644 --- a/embed/extmod/modtrezorconfig/norcow.c +++ b/embed/extmod/modtrezorconfig/norcow.c @@ -214,7 +214,7 @@ static void compact() norcow_erase(norcow_active_sector, secfalse); norcow_active_sector = norcow_next_sector; - norcow_active_offset = offsetw; + norcow_active_offset = find_free_offset(norcow_active_sector); } /* diff --git a/embed/unix/flash.c b/embed/unix/flash.c index c800b3569..c8bf0c0eb 100644 --- a/embed/unix/flash.c +++ b/embed/unix/flash.c @@ -52,15 +52,12 @@ static const uint32_t sector_table[SECTOR_COUNT + 1] = { [24] = 0x08200000, // last element - not a valid sector }; -static int flash_fd; static uint8_t *flash_buffer; static void flash_exit(void) { int r = munmap(flash_buffer, FLASH_SIZE); ensure(sectrue * (r == 0), "munmap failed"); - r = close(flash_fd); - ensure(sectrue * (r == 0), "close failed"); } secbool flash_init(void) @@ -90,7 +87,6 @@ secbool flash_init(void) void *map = mmap(0, FLASH_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ensure(sectrue * (map != MAP_FAILED), "mmap failed"); - flash_fd = fd; flash_buffer = (uint8_t *)map; atexit(flash_exit); diff --git a/tests/test_trezor.config.py b/tests/test_trezor.config.py index b47523d4d..b97d4bce8 100644 --- a/tests/test_trezor.config.py +++ b/tests/test_trezor.config.py @@ -84,6 +84,17 @@ class TestConfig(unittest.TestCase): value2 = config.get(appid, key) self.assertEqual(value, value2) + def test_compact(self): + config.init() + config.wipe() + self.assertEqual(config.unlock(''), True) + appid, key = 1, 1 + for _ in range(259): + value = random.bytes(259) + config.set(appid, key, value) + value2 = config.get(appid, key) + self.assertEqual(value, value2) + def test_get_default(self): config.init() config.wipe()