diff --git a/hw/application_fpga/fw/tk1/partition_table.h b/hw/application_fpga/fw/tk1/partition_table.h index aff72a2..731b626 100644 --- a/hw/application_fpga/fw/tk1/partition_table.h +++ b/hw/application_fpga/fw/tk1/partition_table.h @@ -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 diff --git a/hw/application_fpga/fw/tk1/preload_app.c b/hw/application_fpga/fw/tk1/preload_app.c index 2037a1c..ecdf2c3 100644 --- a/hw/application_fpga/fw/tk1/preload_app.c +++ b/hw/application_fpga/fw/tk1/preload_app.c @@ -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; }