mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-08-18 03:10:25 -04:00
Add filesystem code and storage syscalls
Adds syscalls: - ALLOCATE_AREA - DEALLOCATE_AREA - WRITE_DATA - READ_DATA and code to access the filesystem and the flash over SPI. Based on original work by Daniel Jobson <jobson@tillitis.see> for these files: - auth_app.[ch] - flash.[ch] - spi.[ch] - partition_table.[ch] - rng.[ch] - storage.[ch] which are used with small changes to integrate with the new syscall method. Co-authored-by: Daniel Jobson <jobson@tillitis.se> Co-authored-by: Mikael Ågren <mikael@tillitis.se>
This commit is contained in:
parent
bd2df9bd3f
commit
20b008d20e
19 changed files with 974 additions and 7 deletions
50
hw/application_fpga/fw/tk1/partition_table.c
Normal file
50
hw/application_fpga/fw/tk1/partition_table.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Copyright (C) 2024 - Tillitis AB
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
#include <stdint.h>
|
||||
#include <tkey/lib.h>
|
||||
|
||||
#include "flash.h"
|
||||
#include "partition_table.h"
|
||||
#include "proto.h"
|
||||
|
||||
int part_table_read(struct partition_table *part_table)
|
||||
{
|
||||
// Read from flash, if it exists, otherwise create a new one.
|
||||
|
||||
flash_release_powerdown();
|
||||
memset(part_table, 0x00, sizeof(*part_table));
|
||||
|
||||
flash_read_data(ADDR_PARTITION_TABLE, (uint8_t *)part_table,
|
||||
sizeof(*part_table));
|
||||
|
||||
// TODO: Implement redundancy and consistency check
|
||||
|
||||
if (part_table->header.version != PART_TABLE_VERSION) {
|
||||
// Partition table is not ours. Make a new one, and store it.
|
||||
memset(part_table, 0x00, sizeof(*part_table));
|
||||
|
||||
part_table->header.version = PART_TABLE_VERSION;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
part_table->app_storage[i].addr_start =
|
||||
(ADDR_STORAGE_AREA + i * SIZE_STORAGE_AREA);
|
||||
part_table->app_storage[i].size = SIZE_STORAGE_AREA;
|
||||
}
|
||||
|
||||
part_table_write(part_table);
|
||||
}
|
||||
|
||||
// Now the partition table is synced between flash and RAM.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int part_table_write(struct partition_table *part_table)
|
||||
{
|
||||
flash_sector_erase(ADDR_PARTITION_TABLE);
|
||||
flash_write_data(ADDR_PARTITION_TABLE, (uint8_t *)part_table,
|
||||
sizeof(*part_table));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue