2019-02-12 22:18:17 +00:00
|
|
|
// Copyright 2019 SoloKeys Developers
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
|
|
|
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
|
|
|
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
|
|
|
// copied, modified, or distributed except according to those terms.
|
2018-12-04 01:06:44 +00:00
|
|
|
#ifndef _MEMORY_LAYOUT_H_
|
|
|
|
#define _MEMORY_LAYOUT_H_
|
|
|
|
|
|
|
|
#define PAGE_SIZE 2048
|
|
|
|
#define PAGES 128
|
|
|
|
|
|
|
|
// Pages 119-127 are data
|
|
|
|
// Location of counter page and it's backup page
|
|
|
|
// The flash is wear leveled and counter should be fault tolerant
|
|
|
|
#define COUNTER2_PAGE (PAGES - 4)
|
|
|
|
#define COUNTER1_PAGE (PAGES - 3)
|
|
|
|
|
|
|
|
// State of FIDO2 application
|
2019-10-27 12:58:12 +00:00
|
|
|
#define STATE2_PAGE (PAGES - 2)
|
|
|
|
#define STATE1_PAGE (PAGES - 1)
|
|
|
|
|
|
|
|
#define STATE1_PAGE_ADDR (0x08000000 + ((STATE1_PAGE)*PAGE_SIZE))
|
|
|
|
#define STATE2_PAGE_ADDR (0x08000000 + ((STATE2_PAGE)*PAGE_SIZE))
|
2018-12-04 01:06:44 +00:00
|
|
|
|
|
|
|
// Storage of FIDO2 resident keys
|
|
|
|
#define RK_NUM_PAGES 10
|
|
|
|
#define RK_START_PAGE (PAGES - 14)
|
2018-12-11 01:37:12 +00:00
|
|
|
#define RK_END_PAGE (PAGES - 14 + RK_NUM_PAGES) // not included
|
2018-12-04 01:06:44 +00:00
|
|
|
|
|
|
|
// Start of application code
|
2018-12-05 02:12:21 +00:00
|
|
|
#ifndef APPLICATION_START_PAGE
|
2019-08-22 10:52:50 +00:00
|
|
|
#define APPLICATION_START_PAGE (10)
|
2018-12-05 02:12:21 +00:00
|
|
|
#endif
|
|
|
|
#define APPLICATION_START_ADDR (0x08000000 + ((APPLICATION_START_PAGE)*PAGE_SIZE))
|
2018-12-04 01:06:44 +00:00
|
|
|
|
2018-12-11 01:37:12 +00:00
|
|
|
// where attestation key is located
|
2019-10-27 11:51:02 +00:00
|
|
|
#define ATTESTATION_PAGE (PAGES - 15)
|
|
|
|
#define ATTESTATION_PAGE_ADDR (0x08000000 + ATTESTATION_PAGE*PAGE_SIZE)
|
2018-12-11 01:37:12 +00:00
|
|
|
|
2018-12-04 01:06:44 +00:00
|
|
|
// End of application code. Leave some extra room for future data storage.
|
2018-12-05 02:12:21 +00:00
|
|
|
// NOT included in application
|
2019-08-22 10:52:50 +00:00
|
|
|
#define APPLICATION_END_PAGE ((PAGES - 20))
|
2018-12-05 02:12:21 +00:00
|
|
|
#define APPLICATION_END_ADDR ((0x08000000 + ((APPLICATION_END_PAGE)*PAGE_SIZE))-8)
|
2018-12-04 01:06:44 +00:00
|
|
|
|
|
|
|
// Bootloader state.
|
2018-12-05 05:13:34 +00:00
|
|
|
#define AUTH_WORD_ADDR (APPLICATION_END_ADDR)
|
2018-12-04 01:06:44 +00:00
|
|
|
|
2019-08-22 10:52:50 +00:00
|
|
|
#define LAST_ADDR (APPLICATION_END_ADDR-2048 + 8)
|
|
|
|
#define BOOT_VERSION_PAGE (APPLICATION_END_PAGE)
|
2019-08-24 06:49:31 +00:00
|
|
|
#define BOOT_VERSION_ADDR (0x08000000 + BOOT_VERSION_PAGE*FLASH_PAGE_SIZE + 8)
|
2019-08-22 10:52:50 +00:00
|
|
|
#define LAST_PAGE (APPLICATION_END_PAGE-1)
|
|
|
|
|
|
|
|
struct flash_memory_st{
|
2019-08-23 15:52:51 +00:00
|
|
|
uint8_t bootloader[APPLICATION_START_PAGE*2*1024];
|
2019-08-24 07:03:15 +00:00
|
|
|
uint8_t application[(APPLICATION_END_PAGE-APPLICATION_START_PAGE)*2*1024-8];
|
2019-08-24 06:52:54 +00:00
|
|
|
uint8_t auth_word[4];
|
|
|
|
uint8_t bootloader_disabled[4];
|
|
|
|
// place for more user data
|
|
|
|
uint8_t _reserved_application_end_mark[8];
|
|
|
|
uint8_t bootloader_data[2*1024-8];
|
2019-08-22 10:52:50 +00:00
|
|
|
uint8_t user_data[38*1024];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
typedef struct flash_memory_st flash_memory_st;
|
|
|
|
|
2019-08-24 06:52:54 +00:00
|
|
|
#include <assert.h>
|
2019-08-22 10:52:50 +00:00
|
|
|
static_assert(sizeof(flash_memory_st) == 256*1024, "Data structure doesn't match flash size");
|
|
|
|
|
2019-12-01 19:32:10 +00:00
|
|
|
#define ATTESTATION_CONFIGURED_TAG 0xaa551e79
|
2019-10-27 11:51:02 +00:00
|
|
|
|
|
|
|
struct flash_attestation_page{
|
|
|
|
uint8_t attestation_key[32];
|
2019-10-27 12:40:06 +00:00
|
|
|
// DWORD padded.
|
2019-10-27 13:27:56 +00:00
|
|
|
uint64_t device_settings;
|
2019-10-27 12:40:06 +00:00
|
|
|
uint64_t attestation_cert_size;
|
2019-10-27 13:27:56 +00:00
|
|
|
uint8_t attestation_cert[2048 - 32 - 8 - 8];
|
2019-10-27 11:51:02 +00:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
typedef struct flash_attestation_page flash_attestation_page;
|
|
|
|
|
|
|
|
static_assert(sizeof(flash_attestation_page) == 2048, "Data structure doesn't match flash size");
|
|
|
|
|
2019-08-22 10:52:50 +00:00
|
|
|
|
2018-12-04 01:06:44 +00:00
|
|
|
#endif
|