mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-04-27 10:29:22 -04:00
fw: Implement redundancy of partition table
This commit is contained in:
parent
6cae31dc1e
commit
d85d60db72
@ -26,30 +26,42 @@ void part_digest(struct partition_table *part_table, uint8_t *out_digest, size_t
|
|||||||
|
|
||||||
int part_table_read(struct partition_table_storage *storage)
|
int part_table_read(struct partition_table_storage *storage)
|
||||||
{
|
{
|
||||||
|
uint32_t offset[2] = {
|
||||||
|
ADDR_PARTITION_TABLE_0,
|
||||||
|
ADDR_PARTITION_TABLE_1,
|
||||||
|
};
|
||||||
|
uint8_t check_digest[PART_DIGEST_SIZE];
|
||||||
|
|
||||||
flash_release_powerdown();
|
flash_release_powerdown();
|
||||||
memset(storage, 0x00, sizeof(*storage));
|
memset(storage, 0x00, sizeof(*storage));
|
||||||
|
|
||||||
flash_read_data(ADDR_PARTITION_TABLE, (uint8_t *)storage,
|
for (int i = 0; i < 2; i ++) {
|
||||||
|
flash_read_data(offset[i], (uint8_t *)storage,
|
||||||
sizeof(*storage));
|
sizeof(*storage));
|
||||||
|
part_digest(&storage->table, check_digest, sizeof(check_digest));
|
||||||
|
|
||||||
// TODO: Implement redundancy
|
if (memeq(check_digest, storage->check_digest, sizeof(check_digest))) {
|
||||||
|
return 0;
|
||||||
uint8_t check_digest[PART_DIGEST_SIZE];
|
}
|
||||||
part_digest(&storage->table, check_digest, sizeof(check_digest));
|
|
||||||
|
|
||||||
if (!memeq(check_digest, storage->check_digest, sizeof(check_digest))) {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int part_table_write(struct partition_table_storage *storage)
|
int part_table_write(struct partition_table_storage *storage)
|
||||||
{
|
{
|
||||||
|
uint32_t offset[2] = {
|
||||||
|
ADDR_PARTITION_TABLE_0,
|
||||||
|
ADDR_PARTITION_TABLE_1,
|
||||||
|
};
|
||||||
|
|
||||||
part_digest(&storage->table, storage->check_digest, sizeof(storage->check_digest));
|
part_digest(&storage->table, storage->check_digest, sizeof(storage->check_digest));
|
||||||
flash_sector_erase(ADDR_PARTITION_TABLE);
|
|
||||||
flash_write_data(ADDR_PARTITION_TABLE, (uint8_t *)storage,
|
for (int i = 0; i < 2; i ++) {
|
||||||
sizeof(*storage));
|
flash_sector_erase(offset[i]);
|
||||||
|
flash_write_data(offset[i], (uint8_t *)storage,
|
||||||
|
sizeof(*storage));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
/* storage 3 128KiB 0xB0000 */
|
/* storage 3 128KiB 0xB0000 */
|
||||||
/* storage 4 128KiB 0xD0000 */
|
/* storage 4 128KiB 0xD0000 */
|
||||||
/* ---- ---- ---- */
|
/* ---- ---- ---- */
|
||||||
|
/* Partition2 64KiB 0xf0000 */
|
||||||
|
|
||||||
/* To simplify all blocks are aligned with the 64KiB blocks on the W25Q80DL
|
/* To simplify all blocks are aligned with the 64KiB blocks on the W25Q80DL
|
||||||
* flash. */
|
* flash. */
|
||||||
@ -30,13 +31,14 @@
|
|||||||
#define ADDR_BITSTREAM 0UL
|
#define ADDR_BITSTREAM 0UL
|
||||||
#define SIZE_BITSTREAM 0x20000UL // 128KiB
|
#define SIZE_BITSTREAM 0x20000UL // 128KiB
|
||||||
|
|
||||||
#define ADDR_PARTITION_TABLE (ADDR_BITSTREAM + SIZE_BITSTREAM)
|
#define ADDR_PARTITION_TABLE_0 (ADDR_BITSTREAM + SIZE_BITSTREAM)
|
||||||
|
#define ADDR_PARTITION_TABLE_1 0xf0000
|
||||||
#define SIZE_PARTITION_TABLE \
|
#define SIZE_PARTITION_TABLE \
|
||||||
0x10000UL // 64KiB, 60 KiB reserved, 2 flash pages (2 x 4KiB) for the
|
0x10000UL // 64KiB, 60 KiB reserved, 2 flash pages (2 x 4KiB) for the
|
||||||
// partition table
|
// partition table
|
||||||
|
|
||||||
#define N_PRELOADED_APP 2
|
#define N_PRELOADED_APP 2
|
||||||
#define ADDR_PRE_LOADED_APP_0 (ADDR_PARTITION_TABLE + SIZE_PARTITION_TABLE)
|
#define ADDR_PRE_LOADED_APP_0 (ADDR_PARTITION_TABLE_0 + SIZE_PARTITION_TABLE)
|
||||||
#define SIZE_PRE_LOADED_APP 0x20000UL // 128KiB
|
#define SIZE_PRE_LOADED_APP 0x20000UL // 128KiB
|
||||||
|
|
||||||
#define ADDR_STORAGE_AREA (ADDR_PRE_LOADED_APP_0 + (N_PRELOADED_APP * SIZE_PRE_LOADED_APP))
|
#define ADDR_STORAGE_AREA (ADDR_PRE_LOADED_APP_0 + (N_PRELOADED_APP * SIZE_PRE_LOADED_APP))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user