mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-03-26 00:28:15 -04:00
Do note delete or corrupt preloaded app 0 when storing preloaded app 1
This commit is contained in:
parent
a86cd4a618
commit
feca8f19f4
@ -36,7 +36,7 @@
|
||||
// partition table
|
||||
|
||||
#define N_PRELOADED_APP 2
|
||||
#define ADDR_PRE_LOADED_APP (ADDR_PARTITION_TABLE + SIZE_PARTITION_TABLE)
|
||||
#define ADDR_PRE_LOADED_APP_0 (ADDR_PARTITION_TABLE + SIZE_PARTITION_TABLE)
|
||||
#define SIZE_PRE_LOADED_APP 0x20000UL // 128KiB
|
||||
|
||||
// Pre-loaded app present and authenticated
|
||||
@ -44,7 +44,7 @@
|
||||
// Pre-loaded app present but not yet authenticated
|
||||
#define PRE_LOADED_STATUS_PRESENT 0x02
|
||||
|
||||
#define ADDR_STORAGE_AREA (ADDR_PRE_LOADED_APP + (N_PRELOADED_APP * SIZE_PRE_LOADED_APP))
|
||||
#define ADDR_STORAGE_AREA (ADDR_PRE_LOADED_APP_0 + (N_PRELOADED_APP * SIZE_PRE_LOADED_APP))
|
||||
#define SIZE_STORAGE_AREA 0x20000UL // 128KiB
|
||||
#define N_STORAGE_AREA 4
|
||||
|
||||
|
@ -13,6 +13,10 @@
|
||||
#include "partition_table.h"
|
||||
#include "preload_app.h"
|
||||
|
||||
static uint32_t slot_to_start_address(uint8_t slot) {
|
||||
return ADDR_PRE_LOADED_APP_0 + slot * SIZE_PRE_LOADED_APP;
|
||||
}
|
||||
|
||||
/* Returns non-zero if the app is valid */
|
||||
bool preload_check_valid_app(struct partition_table *part_table,
|
||||
uint8_t slot)
|
||||
@ -44,9 +48,8 @@ int preload_load(struct partition_table *part_table, uint8_t from_slot)
|
||||
uint8_t *loadaddr = (uint8_t *)TK1_RAM_BASE;
|
||||
|
||||
/* Read from flash, straight into RAM */
|
||||
int ret = flash_read_data(ADDR_PRE_LOADED_APP +
|
||||
from_slot * SIZE_PRE_LOADED_APP,
|
||||
loadaddr, part_table->pre_app_data[from_slot].size);
|
||||
int ret = flash_read_data(slot_to_start_address(from_slot), loadaddr,
|
||||
part_table->pre_app_data[from_slot].size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -73,7 +76,7 @@ int preload_store(struct partition_table *part_table, uint32_t offset,
|
||||
return -2;
|
||||
}
|
||||
|
||||
uint32_t address = ADDR_PRE_LOADED_APP + offset;
|
||||
uint32_t address = slot_to_start_address(to_slot) + offset;
|
||||
|
||||
debug_puts("preload_store: write to addr: ");
|
||||
debug_putinthex(address);
|
||||
@ -159,9 +162,8 @@ int preload_delete(struct partition_table *part_table, uint8_t slot)
|
||||
part_table_write(part_table);
|
||||
|
||||
/* Assumes the area is 64 KiB block aligned */
|
||||
flash_block_64_erase(ADDR_PRE_LOADED_APP); // Erase first 64 KB block
|
||||
flash_block_64_erase(ADDR_PRE_LOADED_APP +
|
||||
0x10000); // Erase second 64 KB block
|
||||
flash_block_64_erase(slot_to_start_address(slot)); // Erase first 64 KB block
|
||||
flash_block_64_erase(slot_to_start_address(slot) + 0x10000); // Erase first 64 KB block
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user