Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fido-authenticator: Use delog-panic #467

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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
12 changes: 11 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ memory-regions = { path = "components/memory-regions" }
# forked
admin-app = { git = "https://github.com/Nitrokey/admin-app.git", tag = "v0.1.0-nitrokey.11" }
cbor-smol = { git = "https://github.com/Nitrokey/cbor-smol.git", tag = "v0.4.0-nitrokey.1" }
fido-authenticator = { git = "https://github.com/Nitrokey/fido-authenticator.git", tag = "v0.1.1-nitrokey.14" }
fido-authenticator = { git = "https://github.com/Nitrokey/fido-authenticator.git", branch = "delog-panic" }
flexiber = { git = "https://github.com/Nitrokey/flexiber", tag = "0.1.1.nitrokey" }
lpc55-hal = { git = "https://github.com/Nitrokey/lpc55-hal", tag = "v0.3.0-nitrokey.2" }
serde-indexed = { git = "https://github.com/nitrokey/serde-indexed.git", tag = "v0.1.0-nitrokey.2" }
Expand Down
1 change: 1 addition & 0 deletions components/boards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cortex-m-rtic = "1.0"
cortex-m-rt = "0.6.15"
ctaphid-dispatch = "0.1"
delog = "0.1"
delog-panic.git = "https://github.com/trussed-dev/delog-panic"
embedded-hal = "0.2.3"
embedded-time = "0.12"
generic-array = "0.14"
Expand Down
7 changes: 4 additions & 3 deletions components/boards/src/flash.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::cell::RefCell;

use delog_panic::DelogPanic as _;
use embedded_hal::{blocking::spi::Transfer, digital::v2::OutputPin};
use littlefs2::{driver::Storage, io::Error};
use spi_memory::{BlockDevice, Read};
Expand Down Expand Up @@ -103,9 +104,9 @@ where
CS: OutputPin,
{
fn raw_command(spim: &mut SPI, cs: &mut CS, buf: &mut [u8]) {
cs.set_low().ok().unwrap();
spim.transfer(buf).ok().unwrap();
cs.set_high().ok().unwrap();
cs.set_low().ok().delog_unwrap();
spim.transfer(buf).ok().delog_unwrap();
cs.set_high().ok().delog_unwrap();
}

pub fn try_new(mut spim: SPI, mut cs: CS) -> Option<Self> {
Expand Down
5 changes: 3 additions & 2 deletions components/boards/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use apps::{AdminData, Data, Dispatch, FidoData, InitStatus};
use ctaphid_dispatch::{dispatch::Dispatch as CtaphidDispatch, types::Channel as CtapChannel};
#[cfg(not(feature = "no-delog"))]
use delog::delog;
use delog_panic::DelogPanic as _;
use interchange::Channel;
use nfc_device::Iso14443;
use rand::{CryptoRng, Rng as _, RngCore, SeedableRng};
Expand Down Expand Up @@ -93,8 +94,8 @@ pub fn init_usb_nfc<B: Board>(
static CTAP_INTERRUPT: OptionRefSwap<'static, InterruptFlag> = OptionRefSwap::new(None);

/* claim interchanges */
let (ccid_rq, ccid_rp) = CCID_CHANNEL.split().unwrap();
let (ctaphid_rq, ctaphid_rp) = CTAP_CHANNEL.split().unwrap();
let (ccid_rq, ccid_rp) = CCID_CHANNEL.split().delog_unwrap();
let (ctaphid_rq, ctaphid_rp) = CTAP_CHANNEL.split().delog_unwrap();

/* initialize dispatchers */
let apdu_dispatch = ApduDispatch::new(ccid_rp, nfc_rp);
Expand Down
15 changes: 8 additions & 7 deletions components/boards/src/nk3xn/button.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::ui::buttons::{Button, Edge, Press, State, UserPresence};
use core::convert::Infallible;
use delog_panic::DelogPanic as _;
use lpc55_hal::{
drivers::{pins, timer},
peripherals::ctimer,
Expand Down Expand Up @@ -41,14 +42,14 @@ where
iocon: &mut lpc55_hal::Iocon<lpc55_hal::Enabled>,
) -> XpressoButtons<CTIMER> {
let user_button = UserButtonPin::take()
.unwrap()
.delog_unwrap()
.into_gpio_pin(iocon, gpio)
.into_input();
// let wakeup_button = WakeupButtonPin::take().unwrap().into_gpio_pin(iocon, gpio).into_input();
let buts = State {
a: user_button.is_high().ok().unwrap(),
b: user_button.is_high().ok().unwrap(),
middle: user_button.is_high().ok().unwrap(),
a: user_button.is_high().ok().delog_unwrap(),
b: user_button.is_high().ok().delog_unwrap(),
middle: user_button.is_high().ok().delog_unwrap(),
};
Self {
user_button,
Expand All @@ -66,9 +67,9 @@ where
// A minimal button implementation for Xpresso
fn is_pressed(&mut self, but: Button) -> bool {
match but {
Button::A => self.user_button.is_low().ok().unwrap(),
Button::B => self.user_button.is_low().ok().unwrap(),
_ => self.user_button.is_low().ok().unwrap(),
Button::A => self.user_button.is_low().ok().delog_unwrap(),
Button::B => self.user_button.is_low().ok().delog_unwrap(),
_ => self.user_button.is_low().ok().delog_unwrap(),
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions components/boards/src/nk3xn/led.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::ui::rgb_led;
use delog_panic::DelogPanic as _;
use lpc55_hal::{
drivers::pins,
drivers::pwm,
Expand Down Expand Up @@ -42,9 +43,9 @@ pub struct RgbLed {

impl RgbLed {
pub fn new(mut pwm: PwmDriver, iocon: &mut Iocon<init_state::Enabled>) -> RgbLed {
let red = RedLedPin::take().unwrap();
let green = GreenLedPin::take().unwrap();
let blue = BlueLedPin::take().unwrap();
let red = RedLedPin::take().delog_unwrap();
let green = GreenLedPin::take().delog_unwrap();
let blue = BlueLedPin::take().delog_unwrap();

pwm.set_duty(RedLed::CHANNEL, 0);
pwm.set_duty(GreenLed::CHANNEL, 0);
Expand Down
3 changes: 2 additions & 1 deletion components/boards/src/nk3xn/nfc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::spi::Spi;
use apps::InitStatus;
use delog_panic::DelogPanic as _;
use lpc55_hal::{
self,
drivers::{
Expand Down Expand Up @@ -33,7 +34,7 @@ pub fn try_setup(
) -> Option<NfcChip> {
// Start unselected.
let nfc_cs = NfcCsPin::take()
.unwrap()
.delog_unwrap()
.into_gpio_pin(iocon, gpio)
.into_output_high();

Expand Down
7 changes: 4 additions & 3 deletions components/boards/src/nk3xn/spi.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use delog_panic::DelogPanic as _;
use lpc55_hal::{
self,
drivers::{
Expand Down Expand Up @@ -52,9 +53,9 @@ impl SpiConfig {
}

pub fn init(spi: Spi0<Enabled>, iocon: &mut Iocon<Enabled>, config: SpiConfig) -> Spi {
let sck = SckPin::take().unwrap().into_spi0_sck_pin(iocon);
let mosi = MosiPin::take().unwrap().into_spi0_mosi_pin(iocon);
let miso = MisoPin::take().unwrap().into_spi0_miso_pin(iocon);
let sck = SckPin::take().delog_unwrap().into_spi0_sck_pin(iocon);
let mosi = MosiPin::take().delog_unwrap().into_spi0_mosi_pin(iocon);
let miso = MisoPin::take().delog_unwrap().into_spi0_miso_pin(iocon);
configure(spi, (sck, mosi, miso, NoCs), config)
}

Expand Down
5 changes: 3 additions & 2 deletions components/boards/src/soc/lpc55/clock_controller.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use delog_panic::{delog_panic, DelogPanic as _};
use lpc55_hal::{
drivers::{
clocks::Clocks,
Expand Down Expand Up @@ -49,7 +50,7 @@ impl DynamicClockController {
iocon: &mut Iocon<Enabled>,
) -> DynamicClockController {
let signal_button = SignalPin::take()
.unwrap()
.delog_unwrap()
.into_gpio_pin(iocon, gpio)
.into_output_high();

Expand Down Expand Up @@ -178,7 +179,7 @@ impl DynamicClockController {
}
let result = self.adc.resfifo[0].read().bits();
if (result & 0x80000000) == 0 {
panic!("underflow on compare");
delog_panic!("underflow on compare");
}
let sample = (result & 0xffff) as u16;

Expand Down
3 changes: 2 additions & 1 deletion components/boards/src/soc/lpc55/monotonic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use delog_panic::DelogPanic as _;
use embedded_time::duration::units::Milliseconds;
use systick_monotonic::{
fugit::{MillisDurationU64, TimerDurationU64, TimerInstantU64},
Expand Down Expand Up @@ -63,5 +64,5 @@ impl<M: rtic::Monotonic> From<M> for MonotonicWrapper<M> {

fn convert<const FREQ_HZ: u32>(instant: TimerInstantU64<FREQ_HZ>) -> Milliseconds {
let duration: MillisDurationU64 = instant.duration_since_epoch().convert();
Milliseconds(duration.ticks().try_into().unwrap())
Milliseconds(duration.ticks().try_into().delog_unwrap())
}
11 changes: 6 additions & 5 deletions components/boards/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use core::{
};

use apps::InitStatus;
use delog_panic::{delog_panic, DelogPanic as _};
use littlefs2::{
const_ram_storage,
driver::Storage,
Expand Down Expand Up @@ -37,7 +38,7 @@ const_ram_storage!(
#[allow(clippy::missing_safety_doc)]
#[cfg(feature = "provisioner")]
pub unsafe fn steal_internal_storage<S: StoragePointers>() -> &'static mut S::InternalStorage {
S::ifs_storage().as_mut().unwrap()
S::ifs_storage().as_mut().delog_unwrap()
}

// FIXME: document safety
Expand Down Expand Up @@ -192,7 +193,7 @@ pub fn init_store<B: Board>(
static CLAIMED: AtomicBool = AtomicBool::new(false);
CLAIMED
.compare_exchange_weak(false, true, Ordering::AcqRel, Ordering::Acquire)
.expect("multiple instances of RunnerStore are not allowed");
.delog_expect("multiple instances of RunnerStore are not allowed");

static mut VOLATILE_STORAGE: Option<VolatileStorage> = None;
static mut VOLATILE_FS_ALLOC: Option<Allocation<VolatileStorage>> = None;
Expand All @@ -210,23 +211,23 @@ pub fn init_store<B: Board>(
Ok(ifs) => B::ifs().insert(ifs),
Err(_e) => {
error!("IFS Mount Error {:?}", _e);
panic!("IFS");
delog_panic!("IFS");
}
};

let efs = match init_efs::<B>(efs_storage, efs_alloc, simulated_efs, status) {
Ok(efs) => B::efs().insert(efs),
Err(_e) => {
error!("EFS Mount Error {:?}", _e);
panic!("EFS");
delog_panic!("EFS");
}
};

let vfs = match init_vfs(vfs_storage, vfs_alloc) {
Ok(vfs) => VOLATILE_FS.insert(vfs),
Err(_e) => {
error!("VFS Mount Error {:?}", _e);
panic!("VFS");
delog_panic!("VFS");
}
};

Expand Down