Skip to content

Commit

Permalink
Replace store statics
Browse files Browse the repository at this point in the history
This patch moves the statics storing the various storage components into
the local resources for the init tasks.  This makes them sound and safe
to use.  Unfortunately, this leads to a significant increase in binary
size.
  • Loading branch information
robin-nitrokey committed May 13, 2024
1 parent 11d7c90 commit 428f262
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 190 deletions.
8 changes: 6 additions & 2 deletions components/boards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use apps::Dispatch;
#[cfg(feature = "se050")]
use embedded_hal::blocking::delay::DelayUs;
use littlefs2::{
driver::Storage,
fs::{Allocation, Filesystem},
io::Result as LfsResult,
};
Expand All @@ -34,17 +35,20 @@ use trussed::{client::Syscall, Platform};

use crate::{
soc::{Soc, Uuid},
store::{RunnerStore, StoragePointers},
store::RunnerStore,
ui::{buttons::UserPresence, rgb_led::RgbLed, UserInterface},
};

pub type Trussed<B> =
trussed::Service<RunnerPlatform<B>, Dispatch<<B as Board>::Twi, <B as Board>::Se050Timer>>;
pub type Apps<B> = apps::Apps<Runner<B>>;

pub trait Board: StoragePointers {
pub trait Board {
type Soc: Soc;

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

type NfcDevice: NfcDevice;
type Buttons: UserPresence;
type Led: RgbLed;
Expand Down
10 changes: 3 additions & 7 deletions components/boards/src/nk3am.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use nrf52840_pac::{FICR, GPIOTE, P0, P1, POWER, PWM0, PWM1, PWM2, SPIM3, TIMER1,
use crate::{
flash::ExtFlashStorage,
soc::nrf52::{flash::FlashStorage, rtic_monotonic::RtcMonotonic, Nrf52},
store::impl_storage_pointers,
ui::UserInterface,
Board,
};
Expand All @@ -38,6 +37,9 @@ pub struct NK3AM;
impl Board for NK3AM {
type Soc = Nrf52;

type InternalStorage = InternalFlashStorage;
type ExternalStorage = ExternalFlashStorage;

type NfcDevice = DummyNfc;
type Buttons = HardwareButtons;
type Led = RgbLed;
Expand Down Expand Up @@ -102,12 +104,6 @@ pub type InternalFlashStorage =
FlashStorage<{ MEMORY_REGIONS.filesystem.start }, { MEMORY_REGIONS.filesystem.end }>;
pub type ExternalFlashStorage = ExtFlashStorage<Spim<SPIM3>, OutPin>;

impl_storage_pointers!(
NK3AM,
Internal = InternalFlashStorage,
External = ExternalFlashStorage,
);

pub struct DummyNfc;

impl NfcDevice for DummyNfc {
Expand Down
11 changes: 4 additions & 7 deletions components/boards/src/nk3xn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use lpc55_hal::{
use memory_regions::MemoryRegions;
use utils::OptionalStorage;

use crate::{flash::ExtFlashStorage, soc::lpc55::Lpc55, store::impl_storage_pointers, Board};
use crate::{flash::ExtFlashStorage, soc::lpc55::Lpc55, Board};

pub mod button;
pub mod led;
Expand Down Expand Up @@ -59,6 +59,9 @@ pub struct NK3xN;
impl Board for NK3xN {
type Soc = Lpc55;

type InternalStorage = InternalFlashStorage;
type ExternalStorage = ExternalFlashStorage;

type NfcDevice = NfcChip;
type Buttons = button::ThreeButtons;
type Led = led::RgbLed;
Expand All @@ -79,12 +82,6 @@ impl Board for NK3xN {
pub type InternalFlashStorage = InternalFilesystem;
pub type ExternalFlashStorage = OptionalStorage<ExtFlashStorage<Spi, FlashCs>>;

impl_storage_pointers!(
NK3xN,
Internal = InternalFlashStorage,
External = ExternalFlashStorage,
);

#[cfg(feature = "se050")]
pub struct TimerDelay<T>(pub T);

Expand Down
10 changes: 3 additions & 7 deletions components/boards/src/nkpk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use super::nk3am::{
};
use crate::{
soc::nrf52::{flash::FlashStorage, Nrf52},
store::impl_storage_pointers,
Board,
};

Expand All @@ -22,6 +21,9 @@ pub struct NKPK;
impl Board for NKPK {
type Soc = Nrf52;

type InternalStorage = InternalFlashStorage;
type ExternalStorage = ExternalFlashStorage;

type NfcDevice = DummyNfc;
type Buttons = HardwareButtons;
type Led = RgbLed;
Expand Down Expand Up @@ -52,9 +54,3 @@ 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>;

impl_storage_pointers!(
NKPK,
Internal = InternalFlashStorage,
External = ExternalFlashStorage,
);
Loading

0 comments on commit 428f262

Please sign in to comment.