Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ memory-regions = { path = "components/memory-regions" }

# unreleased libraries
p256-cortex-m4 = { git = "https://github.com/ycrypto/p256-cortex-m4.git", rev = "cdb31e12594b4dc1f045b860a885fdc94d96aee2" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "e107ed315a07dc6c992fac39d542e847cc3a1b6c" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "7c19c00a8959a88a498032fb096d4574d1a85007" }
trussed-usbip = { git = "https://github.com/trussed-dev/pc-usbip-runner.git", rev = "504674453c9573a30aa2f155101df49eb2af1ba7" }

# applications
Expand All @@ -37,8 +37,8 @@ trussed-rsa-alloc = { git = "https://github.com/trussed-dev/trussed-rsa-backend.
trussed-se050-backend = { git = "https://github.com/Nitrokey/trussed-se050-backend.git", tag = "v0.5.0" }
trussed-staging = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "v0.3.3" }
littlefs2-sys = { git = "https://github.com/trussed-dev/littlefs2-sys.git", rev = "v0.3.1-nitrokey.1" }
littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "v0.6.1-nitrokey.1" }
littlefs2-core = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "v0.6.1-nitrokey.1" }
littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "d0ebffac28f264990e8eedea98074005f318f0f4"}
littlefs2-core = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "d0ebffac28f264990e8eedea98074005f318f0f4"}

[profile.release]
codegen-units = 1
Expand Down
2 changes: 1 addition & 1 deletion components/boards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trussed = { version = "0.1", default-features = false }
usb-device = "0.2"
usbd-ccid = "0.3"
usbd-ctaphid = "0.3"
utils = { path = "../utils" }
utils = { path = "../utils", features = ["storage"]}

# soc-lpc55
lpc55-hal = { version = "0.4", optional = true }
Expand Down
33 changes: 26 additions & 7 deletions components/boards/src/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,32 @@ where
SPI: Transfer<u8>,
CS: OutputPin,
{
const BLOCK_SIZE: usize = 4096;
const READ_SIZE: usize = 4;
const WRITE_SIZE: usize = 256;
const BLOCK_COUNT: usize =
(FLASH_PROPERTIES.size / Self::BLOCK_SIZE) - (SPARE_LEN / Self::BLOCK_SIZE);
type CACHE_SIZE = generic_array::typenum::U256;
type LOOKAHEAD_SIZE = generic_array::typenum::U1;
fn read_size(&self) -> usize {
4
}

fn write_size(&self) -> usize {
256
}

fn block_size(&self) -> usize {
4096
}

fn cache_size(&self) -> usize {
256
}

fn lookahead_size(&self) -> usize {
1
}

fn block_count(&self) -> usize {
(FLASH_PROPERTIES.size / self.block_size()) - (SPARE_LEN / self.block_size())
}

type CACHE_BUFFER = [u8; 256];
type LOOKAHEAD_BUFFER = [u8; 8];

fn read(&mut self, off: usize, buf: &mut [u8]) -> Result<usize, Error> {
/*trace!("EFr {:x} {:x}", off, buf.len());
Expand Down
12 changes: 12 additions & 0 deletions components/boards/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ impl<B: Board> Resources<B> {
}
}

impl<B: Board> Default for Resources<B> {
fn default() -> Self {
Self::new()
}
}

pub struct UsbResources<B: Board> {
usb_bus: Option<UsbBusAllocator<<B::Soc as Soc>::UsbBus>>,
}
Expand All @@ -63,6 +69,12 @@ impl<B: Board> UsbResources<B> {
}
}

impl<B: Board> Default for UsbResources<B> {
fn default() -> Self {
Self::new()
}
}

#[derive(Debug)]
pub struct DelogFlusher {}

Expand Down
3 changes: 2 additions & 1 deletion components/boards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use littlefs2::{
use nfc_device::traits::nfc::Device as NfcDevice;
use rand_chacha::ChaCha8Rng;
use trussed::{client::Syscall, Platform};
use utils::MaybeStorage;

use crate::{
soc::{Soc, Uuid},
Expand All @@ -51,7 +52,7 @@ pub trait Board {
type Led: RgbLed;

type InternalStorage: Storage + 'static;
type ExternalStorage: Storage + 'static;
type ExternalStorage: MaybeStorage;

#[cfg(feature = "se050")]
type Se050Timer: se05x::embedded_hal::Delay + 'static;
Expand Down
2 changes: 1 addition & 1 deletion components/boards/src/nk3am.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Board for NK3AM {
// regular mount failed, try mounting "old" (pre-journaling) IFS
let pac = unsafe { nrf52840_pac::Peripherals::steal() };
let mut old_ifs_storage = OldFlashStorage::new(pac.NVMC);
let mut old_ifs_alloc: Allocation<OldFlashStorage> = Filesystem::allocate();
let mut old_ifs_alloc: Allocation<OldFlashStorage> = Filesystem::allocate(&old_ifs_storage);
let old_mountable = Filesystem::is_mountable(&mut old_ifs_storage);

// we can mount the old ifs filesystem, thus we need to migrate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,32 @@ pub struct FlashStorage {
}

impl littlefs2::driver::Storage for FlashStorage {
const BLOCK_SIZE: usize = 256;
const READ_SIZE: usize = 4;
const WRITE_SIZE: usize = 4;
const BLOCK_COUNT: usize = FLASH_SIZE / Self::BLOCK_SIZE;
fn read_size(&self) -> usize {
4
}

fn write_size(&self) -> usize {
4
}

fn block_size(&self) -> usize {
256
}

fn cache_size(&self) -> usize {
256
}

fn lookahead_size(&self) -> usize {
1
}

fn block_count(&self) -> usize {
FLASH_SIZE / self.block_size()
}

type CACHE_SIZE = generic_array::typenum::U256;
type LOOKAHEAD_SIZE = generic_array::typenum::U1;
type CACHE_BUFFER = [u8; 256];
type LOOKAHEAD_BUFFER = [u8; 8];

fn read(&mut self, off: usize, buf: &mut [u8]) -> Result<usize, littlefs2::io::Error> {
// w/o this too much spam is generated, thus writes/deletes traces get lost
Expand Down
32 changes: 24 additions & 8 deletions components/boards/src/nk3xn/prince.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// License: Apache-2.0 or MIT

use littlefs2::{
consts::{U512, U8},
driver::Storage,
io::{Error, Result},
};
Expand Down Expand Up @@ -111,15 +110,32 @@ impl InternalFilesystem {
}

impl Storage for InternalFilesystem {
const READ_SIZE: usize = READ_SIZE;
const WRITE_SIZE: usize = WRITE_SIZE;
const BLOCK_SIZE: usize = BLOCK_SIZE;
fn read_size(&self) -> usize {
READ_SIZE
}
fn write_size(&self) -> usize {
WRITE_SIZE
}
fn block_size(&self) -> usize {
BLOCK_SIZE
}
fn cache_size(&self) -> usize {
512
}
fn lookahead_size(&self) -> usize {
8
}

fn block_cycles(&self) -> isize {
-1
}

const BLOCK_COUNT: usize = BLOCK_COUNT;
const BLOCK_CYCLES: isize = -1;
fn block_count(&self) -> usize {
BLOCK_COUNT
}

type CACHE_SIZE = U512;
type LOOKAHEAD_SIZE = U8;
type CACHE_BUFFER = [u8; 512];
type LOOKAHEAD_BUFFER = [u8; 8 * 8];

fn read(&mut self, off: usize, buf: &mut [u8]) -> Result<usize> {
with_enabled(&mut self.prince, || {
Expand Down
4 changes: 2 additions & 2 deletions components/boards/src/nkpk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use littlefs2::{fs::Allocation, io::Result as LfsResult};
use memory_regions::MemoryRegions;
use utils::RamStorage;
use utils::PhantomStorage;

use super::nk3am::{
self,
Expand Down Expand Up @@ -55,4 +55,4 @@ impl Board for NKPK {
pub type InternalFlashStorage =
FlashStorage<{ MEMORY_REGIONS.filesystem.start }, { MEMORY_REGIONS.filesystem.end }>;
// TODO: Do we want to mirror the NK3AM EFS?
pub type ExternalFlashStorage = RamStorage<nk3am::ExternalFlashStorage, 256>;
pub type ExternalFlashStorage = PhantomStorage<nk3am::ExternalFlashStorage>;
34 changes: 26 additions & 8 deletions components/boards/src/soc/nrf52/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,32 @@ impl<const START: usize, const END: usize> FlashStorage<START, END> {
}

impl<const START: usize, const END: usize> littlefs2::driver::Storage for FlashStorage<START, END> {
const BLOCK_SIZE: usize = FTL_BLOCK_SIZE;
const READ_SIZE: usize = 4;
const WRITE_SIZE: usize = FTL_BLOCK_SIZE;
const BLOCK_COUNT: usize =
((END - START) / Self::BLOCK_SIZE) - (FTL_BLOCKS_IN_REAL * FTL_JOURNAL_BLOCKS);

type CACHE_SIZE = generic_array::typenum::U256;
type LOOKAHEAD_SIZE = generic_array::typenum::U1;
fn read_size(&self) -> usize {
4
}

fn write_size(&self) -> usize {
FTL_BLOCK_SIZE
}

fn block_size(&self) -> usize {
FTL_BLOCK_SIZE
}

fn cache_size(&self) -> usize {
256
}

fn lookahead_size(&self) -> usize {
1
}

fn block_count(&self) -> usize {
((END - START) / self.block_size()) - (FTL_BLOCKS_IN_REAL * FTL_JOURNAL_BLOCKS)
}

type CACHE_BUFFER = [u8; 256];
type LOOKAHEAD_BUFFER = [u8; 8];

fn read(&mut self, off: usize, buf: &mut [u8]) -> Result<usize, littlefs2::io::Error> {
// skip journal blocks
Expand Down
Loading