From 718dff1589385e3ca729d02766c4501b00435e38 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 24 Jul 2023 11:41:20 +0200 Subject: [PATCH] fixes to db update --- app/ethereum/eth_db.c | 5 ++++- app/mem.c | 1 + app/mem.h | 2 ++ app/storage/fs.c | 4 ++-- app/ur/ur.h | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/ethereum/eth_db.c b/app/ethereum/eth_db.c index 7459db8..8635356 100644 --- a/app/ethereum/eth_db.c +++ b/app/ethereum/eth_db.c @@ -86,7 +86,10 @@ app_err_t eth_db_lookup_erc20(erc20_desc_t* erc20) { app_err_t eth_db_update(fs_entry_t* entries, size_t len) { app_err_t err = fs_erase_all(_eth_db_match_all, NULL); - if (err != ERR_OK) { + // since our matcher doesn't know when it has reached + // completion, if everything went OK the error code + // will be ERR_DATA on success. + if (err != ERR_DATA) { return err; } diff --git a/app/mem.c b/app/mem.c index 74bb8ca..4d1f559 100644 --- a/app/mem.c +++ b/app/mem.c @@ -2,3 +2,4 @@ #include "common.h" APP_ALIGNED(uint8_t g_mem_heap[MEM_HEAP_SIZE], 4); +APP_ALIGNED(uint8_t g_flash_swap[HAL_FLASH_BLOCK_SIZE], 4); diff --git a/app/mem.h b/app/mem.h index 461805c..3d85c8d 100644 --- a/app/mem.h +++ b/app/mem.h @@ -2,9 +2,11 @@ #define _MEM_H_ #include +#include "hal.h" #define MEM_HEAP_SIZE (64 * 1024) extern uint8_t g_mem_heap[MEM_HEAP_SIZE]; +extern uint8_t g_flash_swap[HAL_FLASH_BLOCK_SIZE]; #endif diff --git a/app/storage/fs.c b/app/storage/fs.c index 52ba41e..20f1938 100644 --- a/app/storage/fs.c +++ b/app/storage/fs.c @@ -244,7 +244,7 @@ app_err_t fs_write(fs_entry_t* first_entry, size_t total_length) { } app_err_t fs_erase(fs_entry_t* entry) { - struct fs_erase_ctx erase_ctx = { .block = 0, .data = g_mem_heap, .predicate = _fs_erase_one, .ctx = entry, .err = ERR_OK, .stop = 0 }; + struct fs_erase_ctx erase_ctx = { .block = 0, .data = g_flash_swap, .predicate = _fs_erase_one, .ctx = entry, .err = ERR_OK, .stop = 0 }; _fs_iterate_page((uint8_t*) HAL_FLASH_BLOCK_ADDR(HAL_FLASH_ADDR_TO_BLOCK((uint32_t)entry)), _fs_erase_entries, &erase_ctx); _fs_commit_block(&erase_ctx); @@ -256,7 +256,7 @@ app_err_t fs_erase_all(fs_predicate_t predicate, void* ctx) { return ERR_HW; } - struct fs_erase_ctx erase_ctx = { .block = 0, .data = g_mem_heap, .predicate = predicate, .ctx = ctx, .err = ERR_DATA, .stop = 0, .pending_erase = 0 }; + struct fs_erase_ctx erase_ctx = { .block = 0, .data = g_flash_swap, .predicate = predicate, .ctx = ctx, .err = ERR_DATA, .stop = 0, .pending_erase = 0 }; _fs_iterate(_fs_erase_entries, &erase_ctx); _fs_commit_block(&erase_ctx); diff --git a/app/ur/ur.h b/app/ur/ur.h index 793a559..582e3df 100644 --- a/app/ur/ur.h +++ b/app/ur/ur.h @@ -5,7 +5,7 @@ #include "error.h" #define UR_MAX_PART_COUNT 32 -#define UR_PART_DESC_COUNT (UR_MAX_PART_COUNT + 5) +#define UR_PART_DESC_COUNT (UR_MAX_PART_COUNT + 10) typedef enum { BYTES = 0,