From cc495b8c85a51afaa67c55f85bd4ee096a98a475 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 10:37:18 +0200 Subject: [PATCH 01/15] Bump kernel version --- third_party/tock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/tock b/third_party/tock index f1f9d71..c5b7a4f 160000 --- a/third_party/tock +++ b/third_party/tock @@ -1 +1 @@ -Subproject commit f1f9d717a4d9b5ae934a3b50ce6a18e6dff3e7c7 +Subproject commit c5b7a4f2c89a8c067f0f5786788f4037b32329fd From bb2685ca94d45522fbb301bda07d4cb6f205e5f2 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 10:38:36 +0200 Subject: [PATCH 02/15] Update out-of-tree board to new kernel --- boards/nordic/nrf52840_dongle_dfu/Cargo.toml | 2 +- boards/nordic/nrf52840_mdk_dfu/Cargo.toml | 2 +- boards/nordic/nrf52840_mdk_dfu/src/main.rs | 373 ++++++++++++++++--- 3 files changed, 332 insertions(+), 45 deletions(-) diff --git a/boards/nordic/nrf52840_dongle_dfu/Cargo.toml b/boards/nordic/nrf52840_dongle_dfu/Cargo.toml index 35eab8a..10b387c 100644 --- a/boards/nordic/nrf52840_dongle_dfu/Cargo.toml +++ b/boards/nordic/nrf52840_dongle_dfu/Cargo.toml @@ -15,4 +15,4 @@ cortexm4 = { path = "../../../arch/cortex-m4" } capsules = { path = "../../../capsules" } kernel = { path = "../../../kernel" } nrf52840 = { path = "../../../chips/nrf52840" } -nrf52dk_base = { path = "../nrf52dk_base" } +nrf52_components = { path = "../nrf52_components" } diff --git a/boards/nordic/nrf52840_mdk_dfu/Cargo.toml b/boards/nordic/nrf52840_mdk_dfu/Cargo.toml index c0cb7af..03733b8 100644 --- a/boards/nordic/nrf52840_mdk_dfu/Cargo.toml +++ b/boards/nordic/nrf52840_mdk_dfu/Cargo.toml @@ -11,4 +11,4 @@ cortexm4 = { path = "../../../arch/cortex-m4" } capsules = { path = "../../../capsules" } kernel = { path = "../../../kernel" } nrf52840 = { path = "../../../chips/nrf52840" } -nrf52dk_base = { path = "../nrf52dk_base" } +nrf52_components = { path = "../nrf52_components" } diff --git a/boards/nordic/nrf52840_mdk_dfu/src/main.rs b/boards/nordic/nrf52840_mdk_dfu/src/main.rs index 24dc42f..a346da5 100644 --- a/boards/nordic/nrf52840_mdk_dfu/src/main.rs +++ b/boards/nordic/nrf52840_mdk_dfu/src/main.rs @@ -4,14 +4,20 @@ //! many exported I/O and peripherals. #![no_std] -#![no_main] +// Disable this attribute when documenting, as a workaround for +// https://github.com/rust-lang/rust/issues/62184. +#![cfg_attr(not(doc), no_main)] +#![feature(const_in_array_repeat_expressions)] #![deny(missing_docs)] +use capsules::virtual_alarm::VirtualMuxAlarm; +use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferredCallClientState}; use kernel::component::Component; #[allow(unused_imports)] -use kernel::{debug, debug_gpio, debug_verbose, static_init}; +use kernel::{capabilities, create_capability, debug, debug_gpio, debug_verbose, static_init}; +use kernel::hil::usb::UsbController; use nrf52840::gpio::Pin; -use nrf52dk_base::{SpiPins, UartChannel, UartPins}; +use nrf52_components::{self, UartChannel, UartPins}; // The nRF52840 MDK USB Dongle LEDs const LED1_R_PIN: Pin = Pin::P0_23; @@ -27,13 +33,24 @@ const UART_TXD: Pin = Pin::P0_20; const UART_CTS: Option = Some(Pin::P0_03); const UART_RXD: Pin = Pin::P0_19; -const SPI_MOSI: Pin = Pin::P0_05; -const SPI_MISO: Pin = Pin::P0_06; -const SPI_CLK: Pin = Pin::P0_07; +// Constants related to the configuration of the 15.4 network stack +const SRC_MAC: u16 = 0xf00f; +const PAN_ID: u16 = 0xABCD; /// UART Writer pub mod io; +const VENDOR_ID: u16 = 0x1915; // Nordic Semiconductor +const PRODUCT_ID: u16 = 0x521f; // nRF52840 Dongle (PCA10059) +static STRINGS: &'static [&'static str] = &[ + // Manufacturer + "Nordic Semiconductor ASA", + // Product + "OpenSK", + // Serial number + "v0.1", +]; + // State for loading and holding applications. // How should the kernel respond when a process faults. const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultResponse::Panic; @@ -41,12 +58,8 @@ const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultRespons // Number of concurrent processes this platform supports. const NUM_PROCS: usize = 8; -// RAM to be shared by all application processes. -#[link_section = ".app_memory"] -static mut APP_MEMORY: [u8; 0x3C000] = [0; 0x3C000]; - static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = - [None, None, None, None, None, None, None, None]; + [None; NUM_PROCS]; static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation { address: 0xC0000, @@ -61,6 +74,84 @@ static mut CHIP: Option<&'static nrf52840::chip::Chip> = None; #[link_section = ".stack_buffer"] pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000]; +/// Supported drivers by the platform +pub struct Platform { + ble_radio: &'static capsules::ble_advertising_driver::BLE< + 'static, + nrf52840::ble_radio::Radio<'static>, + VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>, + >, + ieee802154_radio: &'static capsules::ieee802154::RadioDriver<'static>, + button: &'static capsules::button::Button<'static, nrf52840::gpio::GPIOPin<'static>>, + pconsole: &'static capsules::process_console::ProcessConsole< + 'static, + components::process_console::Capability, + >, + console: &'static capsules::console::Console<'static>, + gpio: &'static capsules::gpio::GPIO<'static, nrf52840::gpio::GPIOPin<'static>>, + led: &'static capsules::led::LED<'static, nrf52840::gpio::GPIOPin<'static>>, + rng: &'static capsules::rng::RngDriver<'static>, + temp: &'static capsules::temperature::TemperatureSensor<'static>, + ipc: kernel::ipc::IPC, + analog_comparator: &'static capsules::analog_comparator::AnalogComparator< + 'static, + nrf52840::acomp::Comparator<'static>, + >, + alarm: &'static capsules::alarm::AlarmDriver< + 'static, + capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>, + >, + nvmc: &'static nrf52840::nvmc::SyscallDriver, + usb: &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver< + 'static, + 'static, + nrf52840::usbd::Usbd<'static>, + >, +} + +impl kernel::Platform for Platform { + fn with_driver(&self, driver_num: usize, f: F) -> R + where + F: FnOnce(Option<&dyn kernel::Driver>) -> R, + { + match driver_num { + capsules::console::DRIVER_NUM => f(Some(self.console)), + capsules::gpio::DRIVER_NUM => f(Some(self.gpio)), + capsules::alarm::DRIVER_NUM => f(Some(self.alarm)), + capsules::led::DRIVER_NUM => f(Some(self.led)), + capsules::button::DRIVER_NUM => f(Some(self.button)), + capsules::rng::DRIVER_NUM => f(Some(self.rng)), + capsules::ble_advertising_driver::DRIVER_NUM => f(Some(self.ble_radio)), + capsules::ieee802154::DRIVER_NUM => f(Some(self.ieee802154_radio)), + capsules::temperature::DRIVER_NUM => f(Some(self.temp)), + capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)), + nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)), + capsules::usb::usb_ctap::DRIVER_NUM => f(Some(self.usb)), + kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)), + _ => f(None), + } + } + + fn filter_syscall( + &self, + process: &dyn kernel::procs::ProcessType, + syscall: &kernel::syscall::Syscall, + ) -> Result<(), kernel::ReturnCode> { + use kernel::syscall::Syscall; + match *syscall { + Syscall::COMMAND { + driver_number: nrf52840::nvmc::DRIVER_NUM, + subdriver_number: cmd, + arg0: ptr, + arg1: len, + } if (cmd == 2 || cmd == 3) && !process.fits_in_storage_location(ptr, len) => { + Err(kernel::ReturnCode::EINVAL) + } + _ => Ok(()), + } + } +} + /// Entry point in the vector table called on hard reset. #[no_mangle] pub unsafe fn reset_handler() { @@ -72,24 +163,34 @@ pub unsafe fn reset_handler() { kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS) ); // GPIOs - let gpio = components::gpio::GpioComponent::new(board_kernel).finalize( + let gpio = components::gpio::GpioComponent::new( + board_kernel, components::gpio_component_helper!( - &nrf52840::gpio::PORT[Pin::P0_04], - &nrf52840::gpio::PORT[Pin::P0_05], - &nrf52840::gpio::PORT[Pin::P0_06], - &nrf52840::gpio::PORT[Pin::P0_07], - &nrf52840::gpio::PORT[Pin::P0_08] + nrf52840::gpio::GPIOPin, + // left side of the USB plug. Right side is used for UART + 0 => &nrf52840::gpio::PORT[Pin::P0_04], + 1 => &nrf52840::gpio::PORT[Pin::P0_05], + 2 => &nrf52840::gpio::PORT[Pin::P0_06], + 3 => &nrf52840::gpio::PORT[Pin::P0_07], + 4 => &nrf52840::gpio::PORT[Pin::P0_08] ), - ); - let button = components::button::ButtonComponent::new(board_kernel).finalize( - components::button_component_helper!(( - &nrf52840::gpio::PORT[BUTTON_PIN], - kernel::hil::gpio::ActivationMode::ActiveLow, - kernel::hil::gpio::FloatingState::PullUp - )), - ); + ).finalize(components::gpio_component_buf!(nrf52840::gpio::GPIOPin)); - let led = components::led::LedsComponent::new().finalize(components::led_component_helper!( + let button = components::button::ButtonComponent::new( + board_kernel, + components::button_component_helper!( + nrf52840::gpio::GPIOPin, + ( + &nrf52840::gpio::PORT[BUTTON_PIN], + kernel::hil::gpio::ActivationMode::ActiveLow, + kernel::hil::gpio::FloatingState::PullUp + ) + ), + ) + .finalize(components::button_component_buf!(nrf52840::gpio::GPIOPin)); + + let led = components::led::LedsComponent::new(components::led_component_helper!( + nrf52840::gpio::GPIOPin, ( &nrf52840::gpio::PORT[LED1_R_PIN], kernel::hil::gpio::ActivationMode::ActiveLow @@ -102,30 +203,216 @@ pub unsafe fn reset_handler() { &nrf52840::gpio::PORT[LED1_B_PIN], kernel::hil::gpio::ActivationMode::ActiveLow ) - )); + )) + .finalize(components::led_component_buf!(nrf52840::gpio::GPIOPin)); + let chip = static_init!(nrf52840::chip::Chip, nrf52840::chip::new()); CHIP = Some(chip); - nrf52dk_base::setup_board( - board_kernel, + nrf52_components::startup::NrfStartupComponent::new( + false, BUTTON_RST_PIN, - &nrf52840::gpio::PORT, - gpio, - LED1_R_PIN, - LED1_G_PIN, - LED1_B_PIN, - led, - UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD)), - &SpiPins::new(SPI_MOSI, SPI_MISO, SPI_CLK), - &None, + nrf52840::uicr::Regulator0Output::V3_0, + ) + .finalize(()); + + // Create capabilities that the board needs to call certain protected kernel + // functions. + let process_management_capability = + create_capability!(capabilities::ProcessManagementCapability); + let main_loop_capability = create_capability!(capabilities::MainLoopCapability); + let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability); + + let gpio_port = &nrf52840::gpio::PORT; + + // Configure kernel debug gpios as early as possible + kernel::debug::assign_gpios( + Some(&gpio_port[LED1_R_PIN]), + Some(&gpio_port[LED1_G_PIN]), + Some(&gpio_port[LED1_B_PIN]), + ); + + let rtc = &nrf52840::rtc::RTC; + rtc.start(); + let mux_alarm = components::alarm::AlarmMuxComponent::new(rtc) + .finalize(components::alarm_mux_component_helper!(nrf52840::rtc::Rtc)); + let alarm = components::alarm::AlarmDriverComponent::new(board_kernel, mux_alarm) + .finalize(components::alarm_component_helper!(nrf52840::rtc::Rtc)); + let uart_channel = UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD)); + let channel = nrf52_components::UartChannelComponent::new(uart_channel, mux_alarm).finalize(()); + + let dynamic_deferred_call_clients = + static_init!([DynamicDeferredCallClientState; 2], Default::default()); + let dynamic_deferred_caller = static_init!( + DynamicDeferredCall, + DynamicDeferredCall::new(dynamic_deferred_call_clients) + ); + DynamicDeferredCall::set_global_instance(dynamic_deferred_caller); + + // Create a shared UART channel for the console and for kernel debug. + let uart_mux = + components::console::UartMuxComponent::new(channel, 115200, dynamic_deferred_caller) + .finalize(()); + + let pconsole = + components::process_console::ProcessConsoleComponent::new(board_kernel, uart_mux) + .finalize(()); + + // Setup the console. + let console = components::console::ConsoleComponent::new(board_kernel, uart_mux).finalize(()); + // Create the debugger object that handles calls to `debug!()`. + components::debug_writer::DebugWriterComponent::new(uart_mux).finalize(()); + + let ble_radio = + nrf52_components::BLEComponent::new(board_kernel, &nrf52840::ble_radio::RADIO, mux_alarm) + .finalize(()); + + let (ieee802154_radio, _mux_mac) = components::ieee802154::Ieee802154Component::new( + board_kernel, + &nrf52840::ieee802154_radio::RADIO, + &nrf52840::aes::AESECB, + PAN_ID, + SRC_MAC, + ) + .finalize(components::ieee802154_component_helper!( + nrf52840::ieee802154_radio::Radio, + nrf52840::aes::AesECB<'static> + )); + + let temp = components::temperature::TemperatureComponent::new( + board_kernel, + &nrf52840::temperature::TEMP, + ) + .finalize(()); + + let rng = components::rng::RngComponent::new(board_kernel, &nrf52840::trng::TRNG).finalize(()); + + // Initialize AC using AIN5 (P0.29) as VIN+ and VIN- as AIN0 (P0.02) + // These are hardcoded pin assignments specified in the driver + let analog_comparator = components::analog_comparator::AcComponent::new( + &nrf52840::acomp::ACOMP, + components::acomp_component_helper!( + nrf52840::acomp::Channel, + &nrf52840::acomp::CHANNEL_AC0 + ), + ) + .finalize(components::acomp_component_buf!( + nrf52840::acomp::Comparator + )); + + let nvmc = static_init!( + nrf52840::nvmc::SyscallDriver, + nrf52840::nvmc::SyscallDriver::new( + &nrf52840::nvmc::NVMC, + board_kernel.create_grant(&memory_allocation_capability), + ) + ); + + // Configure USB controller + let usb: + &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver< + 'static, + 'static, + nrf52840::usbd::Usbd<'static>, + > = { + let usb_ctap = static_init!( + capsules::usb::usbc_ctap_hid::ClientCtapHID< + 'static, + 'static, + nrf52840::usbd::Usbd<'static>, + >, + capsules::usb::usbc_ctap_hid::ClientCtapHID::new( + &nrf52840::usbd::USBD, + capsules::usb::usbc_client::MAX_CTRL_PACKET_SIZE_NRF52840, + VENDOR_ID, + PRODUCT_ID, + STRINGS, + ) + ); + nrf52840::usbd::USBD.set_client(usb_ctap); + + // Enable power events to be sent to USB controller + nrf52840::power::POWER.set_usb_client(&nrf52840::usbd::USBD); + nrf52840::power::POWER.enable_interrupts(); + + // Configure the USB userspace driver + let usb_driver = static_init!( + capsules::usb::usb_ctap::CtapUsbSyscallDriver< + 'static, + 'static, + nrf52840::usbd::Usbd<'static>, + >, + capsules::usb::usb_ctap::CtapUsbSyscallDriver::new( + usb_ctap, + board_kernel.create_grant(&memory_allocation_capability) + ) + ); + usb_ctap.set_client(usb_driver); + usb_driver as &'static _ + }; + + nrf52_components::NrfClockComponent::new().finalize(()); + + let platform = Platform { button, - true, - &mut APP_MEMORY, + ble_radio, + ieee802154_radio, + pconsole, + console, + led, + gpio, + rng, + temp, + alarm, + analog_comparator, + nvmc, + usb, + ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability), + }; + + platform.pconsole.start(); + debug!("Initialization complete. Entering main loop\r"); + debug!("{}", &nrf52840::ficr::FICR_INSTANCE); + + /// These symbols are defined in the linker script. + extern "C" { + /// Beginning of the ROM region containing app images. + static _sapps: u8; + /// End of the ROM region containing app images. + static _eapps: u8; + /// Beginning of the RAM region for app memory. + static mut _sappmem: u8; + /// End of the RAM region for app memory. + static _eappmem: u8; + } + + kernel::procs::load_processes( + board_kernel, + chip, + core::slice::from_raw_parts( + &_sapps as *const u8, + &_eapps as *const u8 as usize - &_sapps as *const u8 as usize, + ), + core::slice::from_raw_parts_mut( + &mut _sappmem as *mut u8, + &_eappmem as *const u8 as usize - &_sappmem as *const u8 as usize, + ), &mut PROCESSES, FAULT_RESPONSE, - nrf52840::uicr::Regulator0Output::V3_0, - false, - &Some(&nrf52840::usbd::USBD), + &process_management_capability, + ) + .unwrap_or_else(|err| { + debug!("Error loading processes!"); + debug!("{:?}", err); + }); + + let scheduler = components::sched::round_robin::RoundRobinComponent::new(&PROCESSES) + .finalize(components::rr_component_helper!(NUM_PROCS)); + board_kernel.kernel_loop( + &platform, chip, + Some(&platform.ipc), + scheduler, + &main_loop_capability, ); } From a660d5cfda19354fcc261dee3608dc48665d5b87 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 10:40:08 +0200 Subject: [PATCH 03/15] Remove unnecessary patch --- patches/tock/05-backport-fix-1960.patch | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 patches/tock/05-backport-fix-1960.patch diff --git a/patches/tock/05-backport-fix-1960.patch b/patches/tock/05-backport-fix-1960.patch deleted file mode 100644 index 4bffaa8..0000000 --- a/patches/tock/05-backport-fix-1960.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/capsules/src/segger_rtt.rs b/capsules/src/segger_rtt.rs -index 89a9ddbf..135e7b45 100644 ---- a/capsules/src/segger_rtt.rs -+++ b/capsules/src/segger_rtt.rs -@@ -240,7 +240,7 @@ impl<'a, A: hil::time::Alarm<'a>> uart::Transmit<'a> for SeggerRtt<'a, A> { - - // Start a short timer so that we get a callback and - // can issue the callback to the client. -- let interval = (100 as u32) * ::frequency() / 1000000; -+ let interval = (1000 as u32) * ::frequency() / 1000000; - let tics = self.alarm.now().wrapping_add(interval); - self.alarm.set_alarm(tics); - }) From 5ca23c4e05ca5f74b1f3f0461b47880a32042606 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 11:35:19 +0200 Subject: [PATCH 04/15] Update patches for newer kernel --- patches/tock/01-persistent-storage.patch | 319 +++++++++++------- patches/tock/02-usb.patch | 410 +++++++++++++++-------- patches/tock/03-usb-debugging.patch | 22 +- patches/tock/04-additional-boards.patch | 7 +- 4 files changed, 466 insertions(+), 292 deletions(-) diff --git a/patches/tock/01-persistent-storage.patch b/patches/tock/01-persistent-storage.patch index f364279..e28db71 100644 --- a/patches/tock/01-persistent-storage.patch +++ b/patches/tock/01-persistent-storage.patch @@ -1,11 +1,11 @@ diff --git a/boards/nordic/nrf52840_dongle/src/main.rs b/boards/nordic/nrf52840_dongle/src/main.rs -index 040f4d3a..f6e1069c 100644 +index fc53f59..d72d204 100644 --- a/boards/nordic/nrf52840_dongle/src/main.rs +++ b/boards/nordic/nrf52840_dongle/src/main.rs -@@ -49,6 +49,11 @@ static mut APP_MEMORY: [u8; 0x3C000] = [0; 0x3C000]; +@@ -55,6 +55,11 @@ const NUM_PROCS: usize = 8; static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = - [None, None, None, None, None, None, None, None]; - + [None; NUM_PROCS]; + +static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation { + address: 0xC0000, + size: 0x40000, @@ -13,64 +13,20 @@ index 040f4d3a..f6e1069c 100644 + // Static reference to chip for panic dumps static mut CHIP: Option<&'static nrf52840::chip::Chip> = None; - -@@ -63,7 +68,10 @@ pub unsafe fn reset_handler() { - // Loads relocations and clears BSS - nrf52840::init(); - -- let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES)); -+ let board_kernel = static_init!( -+ kernel::Kernel, -+ kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS) -+ ); - // GPIOs - let gpio = components::gpio::GpioComponent::new(board_kernel).finalize( - components::gpio_component_helper!( -diff --git a/boards/nordic/nrf52840dk/src/main.rs b/boards/nordic/nrf52840dk/src/main.rs -index 44a6c1cc..2ebc2868 100644 ---- a/boards/nordic/nrf52840dk/src/main.rs -+++ b/boards/nordic/nrf52840dk/src/main.rs -@@ -117,6 +117,11 @@ static mut APP_MEMORY: [u8; 0x3C000] = [0; 0x3C000]; - static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = - [None, None, None, None, None, None, None, None]; - -+static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation { -+ address: 0xC0000, -+ size: 0x40000, -+}]; -+ - static mut CHIP: Option<&'static nrf52840::chip::Chip> = None; - - /// Dummy buffer that causes the linker to reserve enough space for the stack. -@@ -146,7 +151,10 @@ pub unsafe fn reset_handler() { - UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD)) - }; - -- let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES)); -+ let board_kernel = static_init!( -+ kernel::Kernel, -+ kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS) -+ ); - let gpio = components::gpio::GpioComponent::new(board_kernel).finalize( - components::gpio_component_helper!( - &nrf52840::gpio::PORT[Pin::P1_01], -diff --git a/boards/nordic/nrf52dk_base/src/lib.rs b/boards/nordic/nrf52dk_base/src/lib.rs -index 5dd4328e..a117d35f 100644 ---- a/boards/nordic/nrf52dk_base/src/lib.rs -+++ b/boards/nordic/nrf52dk_base/src/lib.rs -@@ -104,6 +104,7 @@ pub struct Platform { - // The nRF52dk does not have the flash chip on it, so we make this optional. - nonvolatile_storage: - Option<&'static capsules::nonvolatile_storage_driver::NonvolatileStorage<'static>>, -+ nvmc: &'static nrf52::nvmc::SyscallDriver, + +@@ -90,6 +95,7 @@ pub struct Platform { + 'static, + capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>, + >, ++ nvmc: &'static nrf52840::nvmc::SyscallDriver, } - + impl kernel::Platform for Platform { -@@ -128,10 +129,30 @@ impl kernel::Platform for Platform { - capsules::nonvolatile_storage_driver::DRIVER_NUM => { - f(self.nonvolatile_storage.map_or(None, |nv| Some(nv))) - } -+ nrf52::nvmc::DRIVER_NUM => f(Some(self.nvmc)), +@@ -108,19 +114,42 @@ impl kernel::Platform for Platform { + capsules::ieee802154::DRIVER_NUM => f(Some(self.ieee802154_radio)), + capsules::temperature::DRIVER_NUM => f(Some(self.temp)), + capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)), ++ nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)), kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)), _ => f(None), } @@ -84,7 +40,7 @@ index 5dd4328e..a117d35f 100644 + use kernel::syscall::Syscall; + match *syscall { + Syscall::COMMAND { -+ driver_number: nrf52::nvmc::DRIVER_NUM, ++ driver_number: nrf52840::nvmc::DRIVER_NUM, + subdriver_number: cmd, + arg0: ptr, + arg1: len, @@ -95,56 +51,160 @@ index 5dd4328e..a117d35f 100644 + } + } } - - /// Generic function for starting an nrf52dk board. -@@ -405,6 +426,14 @@ pub unsafe fn setup_board( - ); - nrf52::acomp::ACOMP.set_client(analog_comparator); - + + /// Entry point in the vector table called on hard reset. + #[no_mangle] + pub unsafe fn reset_handler() { + // Loads relocations and clears BSS + nrf52840::init(); + +- let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES)); ++ let board_kernel = static_init!( ++ kernel::Kernel, ++ kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS) ++ ); + + // GPIOs + let gpio = components::gpio::GpioComponent::new( +@@ -286,6 +315,14 @@ pub unsafe fn reset_handler() { + nrf52840::acomp::Comparator + )); + + let nvmc = static_init!( -+ nrf52::nvmc::SyscallDriver, -+ nrf52::nvmc::SyscallDriver::new( -+ &nrf52::nvmc::NVMC, ++ nrf52840::nvmc::SyscallDriver, ++ nrf52840::nvmc::SyscallDriver::new( ++ &nrf52840::nvmc::NVMC, + board_kernel.create_grant(&memory_allocation_capability), + ) + ); + - // Start all of the clocks. Low power operation will require a better - // approach than this. - nrf52::clock::CLOCK.low_stop(); -@@ -431,6 +460,7 @@ pub unsafe fn setup_board( - analog_comparator: analog_comparator, - nonvolatile_storage: nonvolatile_storage, + nrf52_components::NrfClockComponent::new().finalize(()); + + let platform = Platform { +@@ -300,6 +337,7 @@ pub unsafe fn reset_handler() { + temp, + alarm, + analog_comparator, ++ nvmc, ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability), -+ nvmc: nvmc, }; - - platform.pconsole.start(); + +diff --git a/boards/nordic/nrf52840dk/src/main.rs b/boards/nordic/nrf52840dk/src/main.rs +index 169f3d3..2ebb384 100644 +--- a/boards/nordic/nrf52840dk/src/main.rs ++++ b/boards/nordic/nrf52840dk/src/main.rs +@@ -123,6 +123,11 @@ const NUM_PROCS: usize = 8; + static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = + [None; NUM_PROCS]; + ++static mut STORAGE_LOCATIONS: [kernel::StorageLocation; 1] = [kernel::StorageLocation { ++ address: 0xC0000, ++ size: 0x40000, ++}]; ++ + static mut CHIP: Option<&'static nrf52840::chip::Chip> = None; + + /// Dummy buffer that causes the linker to reserve enough space for the stack. +@@ -158,6 +163,7 @@ pub struct Platform { + capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>, + >, + nonvolatile_storage: &'static capsules::nonvolatile_storage_driver::NonvolatileStorage<'static>, ++ nvmc: &'static nrf52840::nvmc::SyscallDriver, + } + + impl kernel::Platform for Platform { +@@ -177,10 +183,30 @@ impl kernel::Platform for Platform { + capsules::temperature::DRIVER_NUM => f(Some(self.temp)), + capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)), + capsules::nonvolatile_storage_driver::DRIVER_NUM => f(Some(self.nonvolatile_storage)), ++ nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)), + kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)), + _ => f(None), + } + } ++ ++ fn filter_syscall( ++ &self, ++ process: &dyn kernel::procs::ProcessType, ++ syscall: &kernel::syscall::Syscall, ++ ) -> Result<(), kernel::ReturnCode> { ++ use kernel::syscall::Syscall; ++ match *syscall { ++ Syscall::COMMAND { ++ driver_number: nrf52840::nvmc::DRIVER_NUM, ++ subdriver_number: cmd, ++ arg0: ptr, ++ arg1: len, ++ } if (cmd == 2 || cmd == 3) && !process.fits_in_storage_location(ptr, len) => { ++ Err(kernel::ReturnCode::EINVAL) ++ } ++ _ => Ok(()), ++ } ++ } + } + + /// Entry point in the vector table called on hard reset. +@@ -204,7 +230,10 @@ pub unsafe fn reset_handler() { + UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD)) + }; + +- let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES)); ++ let board_kernel = static_init!( ++ kernel::Kernel, ++ kernel::Kernel::new_with_storage(&PROCESSES, &STORAGE_LOCATIONS) ++ ); + + let gpio = components::gpio::GpioComponent::new( + board_kernel, +@@ -411,6 +440,14 @@ pub unsafe fn reset_handler() { + nrf52840::acomp::Comparator + )); + ++ let nvmc = static_init!( ++ nrf52840::nvmc::SyscallDriver, ++ nrf52840::nvmc::SyscallDriver::new( ++ &nrf52840::nvmc::NVMC, ++ board_kernel.create_grant(&memory_allocation_capability), ++ ) ++ ); ++ + nrf52_components::NrfClockComponent::new().finalize(()); + + let platform = Platform { +@@ -426,6 +463,7 @@ pub unsafe fn reset_handler() { + alarm, + analog_comparator, + nonvolatile_storage, ++ nvmc, + ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability), + }; + diff --git a/chips/nrf52/src/nvmc.rs b/chips/nrf52/src/nvmc.rs -index 60fc2da8..ca41b899 100644 +index b70162c..9dcb82b 100644 --- a/chips/nrf52/src/nvmc.rs +++ b/chips/nrf52/src/nvmc.rs -@@ -3,6 +3,7 @@ +@@ -3,15 +3,16 @@ //! Used in order read and write to internal flash. - + use core::cell::Cell; +use core::convert::TryFrom; use core::ops::{Index, IndexMut}; use kernel::common::cells::OptionalCell; use kernel::common::cells::TakeCell; -@@ -11,7 +12,7 @@ use kernel::common::deferred_call::DeferredCall; + use kernel::common::cells::VolatileCell; + use kernel::common::deferred_call::DeferredCall; use kernel::common::registers::{register_bitfields, ReadOnly, ReadWrite}; use kernel::common::StaticRef; use kernel::hil; -use kernel::ReturnCode; +use kernel::{AppId, AppSlice, Callback, Driver, Grant, ReturnCode, Shared}; - + use crate::deferred_call_tasks::DeferredCallTask; - + @@ -141,7 +142,13 @@ register_bitfields! [u32, static DEFERRED_CALL: DeferredCall = unsafe { DeferredCall::new(DeferredCallTask::Nvmc) }; - + +type WORD = u32; +const WORD_SIZE: usize = core::mem::size_of::(); const PAGE_SIZE: usize = 4096; @@ -152,13 +212,13 @@ index 60fc2da8..ca41b899 100644 +const MAX_PAGE_ERASES: usize = 10000; +const WORD_MASK: usize = WORD_SIZE - 1; +const PAGE_MASK: usize = PAGE_SIZE - 1; - + /// This is a wrapper around a u8 array that is sized to a single page for the /// nrf. Users of this module must pass an object of this type to use the -@@ -215,6 +222,11 @@ impl Nvmc { +@@ -219,6 +226,11 @@ impl Nvmc { } } - + + pub fn configure_readonly(&self) { + let regs = &*self.registers; + regs.config.write(Configuration::WEN::Ren); @@ -167,7 +227,7 @@ index 60fc2da8..ca41b899 100644 /// Configure the NVMC to allow writes to flash. pub fn configure_writeable(&self) { let regs = &*self.registers; -@@ -230,7 +242,7 @@ impl Nvmc { +@@ -234,7 +246,7 @@ impl Nvmc { let regs = &*self.registers; regs.config.write(Configuration::WEN::Een); while !self.is_ready() {} @@ -175,17 +235,17 @@ index 60fc2da8..ca41b899 100644 + regs.eraseuicr.write(EraseUicr::ERASEUICR::ERASE); while !self.is_ready() {} } - -@@ -322,7 +334,7 @@ impl Nvmc { + +@@ -326,7 +338,7 @@ impl Nvmc { // Put the NVMC in write mode. regs.config.write(Configuration::WEN::Wen); - + - for i in (0..data.len()).step_by(4) { + for i in (0..data.len()).step_by(WORD_SIZE) { let word: u32 = (data[i + 0] as u32) << 0 | (data[i + 1] as u32) << 8 | (data[i + 2] as u32) << 16 -@@ -390,3 +402,180 @@ impl hil::flash::Flash for Nvmc { +@@ -394,3 +406,180 @@ impl hil::flash::Flash for Nvmc { self.erase_page(page_number) } } @@ -367,26 +427,26 @@ index 60fc2da8..ca41b899 100644 + } +} diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs -index ebe8052a..a6dcd278 100644 +index dbe5035..428d90c 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs -@@ -47,7 +47,7 @@ pub use crate::platform::systick::SysTick; - pub use crate::platform::{mpu, Chip, Platform}; - pub use crate::platform::{ClockInterface, NoClockControl, NO_CLOCK_CONTROL}; - pub use crate::returncode::ReturnCode; --pub use crate::sched::Kernel; -+pub use crate::sched::{Kernel, StorageLocation}; - +@@ -123,7 +123,7 @@ pub use crate::sched::cooperative::{CoopProcessNode, CooperativeSched}; + pub use crate::sched::mlfq::{MLFQProcessNode, MLFQSched}; + pub use crate::sched::priority::PrioritySched; + pub use crate::sched::round_robin::{RoundRobinProcessNode, RoundRobinSched}; +-pub use crate::sched::{Kernel, Scheduler}; ++pub use crate::sched::{Kernel, Scheduler, StorageLocation}; + // Export only select items from the process module. To remove the name conflict // this cannot be called `process`, so we use a shortened version. These diff --git a/kernel/src/memop.rs b/kernel/src/memop.rs -index 7537d2b4..61870ccd 100644 +index 348c746..5465c95 100644 --- a/kernel/src/memop.rs +++ b/kernel/src/memop.rs -@@ -108,6 +108,25 @@ crate fn memop(process: &dyn ProcessType, op_type: usize, r1: usize) -> ReturnCo +@@ -108,6 +108,25 @@ pub(crate) fn memop(process: &dyn ProcessType, op_type: usize, r1: usize) -> Ret ReturnCode::SUCCESS } - + + // Op Type 12: Number of storage locations. + 12 => ReturnCode::SuccessWithValue { value: process.number_storage_locations() }, + @@ -410,13 +470,13 @@ index 7537d2b4..61870ccd 100644 } } diff --git a/kernel/src/process.rs b/kernel/src/process.rs -index eb00f274..41243c8e 100644 +index 4dfde3b..0ceff3e 100644 --- a/kernel/src/process.rs +++ b/kernel/src/process.rs -@@ -281,6 +281,15 @@ pub trait ProcessType { +@@ -360,6 +360,15 @@ pub trait ProcessType { /// writeable flash region. fn get_writeable_flash_region(&self, region_index: usize) -> (u32, u32); - + + /// How many storage locations are defined for this process. + fn number_storage_locations(&self) -> usize; + @@ -429,10 +489,10 @@ index eb00f274..41243c8e 100644 /// Debug function to update the kernel on where the stack starts for this /// process. Processes are not required to call this through the memop /// system call, but it aids in debugging the process. -@@ -999,6 +1008,32 @@ impl ProcessType for Process<'a, C> { +@@ -1015,6 +1024,32 @@ impl ProcessType for Process<'_, C> { self.header.get_writeable_flash_region(region_index) } - + + fn number_storage_locations(&self) -> usize { + self.kernel.storage_locations().len() + } @@ -462,10 +522,10 @@ index eb00f274..41243c8e 100644 fn update_stack_start_pointer(&self, stack_pointer: *const u8) { if stack_pointer >= self.mem_start() && stack_pointer < self.mem_end() { self.debug.map(|debug| { -@@ -1604,6 +1639,33 @@ impl Process<'a, C> { - return Ok((None, 0)); +@@ -1664,6 +1699,33 @@ impl Process<'_, C> { + return Err(ProcessLoadError::MpuInvalidFlashLength); } - + + // Allocate MPU region for the storage locations. The storage locations are currently + // readable by all processes due to lack of stable app id. + for storage_location in kernel.storage_locations() { @@ -490,20 +550,20 @@ index eb00f274..41243c8e 100644 + process_name + ); + } -+ return Ok((None, 0)); ++ return Ok((None, remaining_memory)); + } + // Determine how much space we need in the application's // memory space just for kernel and grant state. We need to make // sure we allocate enough memory just for that. diff --git a/kernel/src/sched.rs b/kernel/src/sched.rs -index fbd68319..43cce76f 100644 +index 88eea40..ed3ae82 100644 --- a/kernel/src/sched.rs +++ b/kernel/src/sched.rs -@@ -24,6 +24,12 @@ const KERNEL_TICK_DURATION_US: u32 = 10000; - /// Skip re-scheduling a process if its quanta is nearly exhausted - const MIN_QUANTA_THRESHOLD_US: u32 = 500; - +@@ -118,15 +118,24 @@ pub enum SchedulingDecision { + TrySleep, + } + +/// Represents a storage location in flash. +pub struct StorageLocation { + pub address: usize, @@ -513,18 +573,20 @@ index fbd68319..43cce76f 100644 /// Main object for the kernel. Each board will need to create one. pub struct Kernel { /// How many "to-do" items exist at any given time. These include -@@ -33,6 +39,9 @@ pub struct Kernel { + /// outstanding callbacks and processes in the Running state. + work: Cell, + /// This holds a pointer to the static array of Process pointers. processes: &'static [Option<&'static dyn process::ProcessType>], - + + /// List of storage locations. + storage_locations: &'static [StorageLocation], + /// A counter which keeps track of how many process identifiers have been /// created. This is used to create new unique identifiers for processes. process_identifier_max: Cell, -@@ -51,9 +60,17 @@ pub struct Kernel { - +@@ -170,9 +179,17 @@ pub enum StoppedExecutingReason { + impl Kernel { pub fn new(processes: &'static [Option<&'static dyn process::ProcessType>]) -> Kernel { + Kernel::new_with_storage(processes, &[]) @@ -536,17 +598,20 @@ index fbd68319..43cce76f 100644 + ) -> Kernel { Kernel { work: Cell::new(0), - processes: processes, + processes, + storage_locations: storage_locations, process_identifier_max: Cell::new(0), grant_counter: Cell::new(0), grants_finalized: Cell::new(false), -@@ -599,4 +616,8 @@ impl Kernel { - } - systick.reset(); +@@ -899,4 +916,8 @@ impl Kernel { + + (return_reason, time_executed_us) } + + pub fn storage_locations(&self) -> &'static [StorageLocation] { + self.storage_locations + } } +-- +libgit2 1.0.1 + diff --git a/patches/tock/02-usb.patch b/patches/tock/02-usb.patch index 3daa5ed..ba45dbf 100644 --- a/patches/tock/02-usb.patch +++ b/patches/tock/02-usb.patch @@ -1,107 +1,90 @@ diff --git a/boards/nordic/nrf52840_dongle/src/main.rs b/boards/nordic/nrf52840_dongle/src/main.rs -index 9a8dccfd..ad3e69b8 100644 +index d72d204..8b97f8d 100644 --- a/boards/nordic/nrf52840_dongle/src/main.rs +++ b/boards/nordic/nrf52840_dongle/src/main.rs -@@ -152,6 +152,7 @@ pub unsafe fn reset_handler() { - FAULT_RESPONSE, - nrf52840::uicr::Regulator0Output::V3_0, - false, -+ &Some(&nrf52840::usbd::USBD), - chip, - ); - } -diff --git a/boards/nordic/nrf52840dk/src/main.rs b/boards/nordic/nrf52840dk/src/main.rs -index 127c4f2f..a5847805 100644 ---- a/boards/nordic/nrf52840dk/src/main.rs -+++ b/boards/nordic/nrf52840dk/src/main.rs -@@ -244,6 +244,7 @@ pub unsafe fn reset_handler() { - FAULT_RESPONSE, - nrf52840::uicr::Regulator0Output::DEFAULT, - false, -+ &Some(&nrf52840::usbd::USBD), - chip, - ); - } -diff --git a/boards/nordic/nrf52dk/src/main.rs b/boards/nordic/nrf52dk/src/main.rs -index d67ac695..b0bd8bf1 100644 ---- a/boards/nordic/nrf52dk/src/main.rs -+++ b/boards/nordic/nrf52dk/src/main.rs -@@ -213,6 +213,7 @@ pub unsafe fn reset_handler() { - FAULT_RESPONSE, - nrf52832::uicr::Regulator0Output::DEFAULT, - false, -+ &None, - chip, - ); - } -diff --git a/boards/nordic/nrf52dk_base/src/lib.rs b/boards/nordic/nrf52dk_base/src/lib.rs -index 105f7120..535e5cd8 100644 ---- a/boards/nordic/nrf52dk_base/src/lib.rs -+++ b/boards/nordic/nrf52dk_base/src/lib.rs -@@ -101,6 +101,13 @@ pub struct Platform { - 'static, - capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52::rtc::Rtc<'static>>, +@@ -15,6 +15,7 @@ use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferred + use kernel::component::Component; + #[allow(unused_imports)] + use kernel::{capabilities, create_capability, debug, debug_gpio, debug_verbose, static_init}; ++use kernel::hil::usb::UsbController; + use nrf52840::gpio::Pin; + use nrf52_components::{self, UartChannel, UartPins}; + +@@ -45,6 +46,17 @@ const PAN_ID: u16 = 0xABCD; + /// UART Writer + pub mod io; + ++const VENDOR_ID: u16 = 0x1915; // Nordic Semiconductor ++const PRODUCT_ID: u16 = 0x521f; // nRF52840 Dongle (PCA10059) ++static STRINGS: &'static [&'static str] = &[ ++ // Manufacturer ++ "Nordic Semiconductor ASA", ++ // Product ++ "OpenSK", ++ // Serial number ++ "v0.1", ++]; ++ + // State for loading and holding applications. + // How should the kernel respond when a process faults. + const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultResponse::Panic; +@@ -96,6 +108,11 @@ pub struct Platform { + capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>, >, -+ usb: Option< -+ &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver< -+ 'static, -+ 'static, -+ nrf52::usbd::Usbd<'static>, -+ >, + nvmc: &'static nrf52840::nvmc::SyscallDriver, ++ usb: &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver< ++ 'static, ++ 'static, ++ nrf52840::usbd::Usbd<'static>, + >, - // The nRF52dk does not have the flash chip on it, so we make this optional. - nonvolatile_storage: - Option<&'static capsules::nonvolatile_storage_driver::NonvolatileStorage<'static>>, -@@ -130,6 +137,9 @@ impl kernel::Platform for Platform { - f(self.nonvolatile_storage.map_or(None, |nv| Some(nv))) - } - nrf52::nvmc::DRIVER_NUM => f(Some(self.nvmc)), -+ capsules::usb::usb_ctap::DRIVER_NUM => { -+ f(self.usb.map(|ctap| ctap as &dyn kernel::Driver)) -+ } + } + + impl kernel::Platform for Platform { +@@ -115,6 +132,7 @@ impl kernel::Platform for Platform { + capsules::temperature::DRIVER_NUM => f(Some(self.temp)), + capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)), + nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)), ++ capsules::usb::usb_ctap::DRIVER_NUM => f(Some(self.usb)), kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)), _ => f(None), } -@@ -176,6 +186,7 @@ pub unsafe fn setup_board( - app_fault_response: kernel::procs::FaultResponse, - reg_vout: Regulator0Output, - nfc_as_gpios: bool, -+ usb: &Option<&'static nrf52::usbd::Usbd<'static>>, - chip: &'static nrf52::chip::NRF52, - ) { - // Make non-volatile memory writable and activate the reset button -@@ -434,6 +445,44 @@ pub unsafe fn setup_board( +@@ -323,6 +341,49 @@ pub unsafe fn reset_handler() { ) ); - -+ // Configure USB controller if supported -+ let usb_driver: Option< + ++ // Configure USB controller ++ let usb: + &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver< + 'static, + 'static, -+ nrf52::usbd::Usbd<'static>, -+ >, -+ > = usb.map(|driver| { ++ nrf52840::usbd::Usbd<'static>, ++ > = { + let usb_ctap = static_init!( + capsules::usb::usbc_ctap_hid::ClientCtapHID< + 'static, + 'static, -+ nrf52::usbd::Usbd<'static>, ++ nrf52840::usbd::Usbd<'static>, + >, -+ capsules::usb::usbc_ctap_hid::ClientCtapHID::new(driver) ++ capsules::usb::usbc_ctap_hid::ClientCtapHID::new( ++ &nrf52840::usbd::USBD, ++ capsules::usb::usbc_client::MAX_CTRL_PACKET_SIZE_NRF52840, ++ VENDOR_ID, ++ PRODUCT_ID, ++ STRINGS, ++ ) + ); -+ driver.set_client(usb_ctap); ++ nrf52840::usbd::USBD.set_client(usb_ctap); + + // Enable power events to be sent to USB controller -+ nrf52::power::POWER.set_usb_client(driver); -+ nrf52::power::POWER.enable_interrupts(); ++ nrf52840::power::POWER.set_usb_client(&nrf52840::usbd::USBD); ++ nrf52840::power::POWER.enable_interrupts(); + + // Configure the USB userspace driver + let usb_driver = static_init!( + capsules::usb::usb_ctap::CtapUsbSyscallDriver< + 'static, + 'static, -+ nrf52::usbd::Usbd<'static>, ++ nrf52840::usbd::Usbd<'static>, + >, + capsules::usb::usb_ctap::CtapUsbSyscallDriver::new( + usb_ctap, @@ -110,36 +93,145 @@ index 105f7120..535e5cd8 100644 + ); + usb_ctap.set_client(usb_driver); + usb_driver as &'static _ -+ }); ++ }; + - // Start all of the clocks. Low power operation will require a better - // approach than this. - nrf52::clock::CLOCK.low_stop(); -@@ -458,6 +507,7 @@ pub unsafe fn setup_board( - temp: temp, - alarm: alarm, - analog_comparator: analog_comparator, -+ usb: usb_driver, - nonvolatile_storage: nonvolatile_storage, + nrf52_components::NrfClockComponent::new().finalize(()); + + let platform = Platform { +@@ -338,6 +399,7 @@ pub unsafe fn reset_handler() { + alarm, + analog_comparator, + nvmc, ++ usb, ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability), - nvmc: nvmc, + }; + +diff --git a/boards/nordic/nrf52840dk/src/main.rs b/boards/nordic/nrf52840dk/src/main.rs +index 2ebb384..303a451 100644 +--- a/boards/nordic/nrf52840dk/src/main.rs ++++ b/boards/nordic/nrf52840dk/src/main.rs +@@ -72,6 +72,7 @@ use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferred + use kernel::component::Component; + #[allow(unused_imports)] + use kernel::{capabilities, create_capability, debug, debug_gpio, debug_verbose, static_init}; ++use kernel::hil::usb::UsbController; + use nrf52840::gpio::Pin; + use nrf52_components::{self, UartChannel, UartPins}; + +@@ -113,6 +114,17 @@ pub mod io; + // - Set to true to use Segger RTT over USB. + const USB_DEBUGGING: bool = false; + ++const VENDOR_ID: u16 = 0x1915; // Nordic Semiconductor ++const PRODUCT_ID: u16 = 0x521f; // nRF52840 Dongle (PCA10059) ++static STRINGS: &'static [&'static str] = &[ ++ // Manufacturer ++ "Nordic Semiconductor ASA", ++ // Product ++ "OpenSK", ++ // Serial number ++ "v0.1", ++]; ++ + // State for loading and holding applications. + // How should the kernel respond when a process faults. + const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultResponse::Panic; +@@ -164,6 +176,11 @@ pub struct Platform { + >, + nonvolatile_storage: &'static capsules::nonvolatile_storage_driver::NonvolatileStorage<'static>, + nvmc: &'static nrf52840::nvmc::SyscallDriver, ++ usb: &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver< ++ 'static, ++ 'static, ++ nrf52840::usbd::Usbd<'static>, ++ >, + } + + impl kernel::Platform for Platform { +@@ -184,6 +201,7 @@ impl kernel::Platform for Platform { + capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)), + capsules::nonvolatile_storage_driver::DRIVER_NUM => f(Some(self.nonvolatile_storage)), + nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)), ++ capsules::usb::usb_ctap::DRIVER_NUM => f(Some(self.usb)), + kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)), + _ => f(None), + } +@@ -448,6 +466,49 @@ pub unsafe fn reset_handler() { + ) + ); + ++ // Configure USB controller ++ let usb: ++ &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver< ++ 'static, ++ 'static, ++ nrf52840::usbd::Usbd<'static>, ++ > = { ++ let usb_ctap = static_init!( ++ capsules::usb::usbc_ctap_hid::ClientCtapHID< ++ 'static, ++ 'static, ++ nrf52840::usbd::Usbd<'static>, ++ >, ++ capsules::usb::usbc_ctap_hid::ClientCtapHID::new( ++ &nrf52840::usbd::USBD, ++ capsules::usb::usbc_client::MAX_CTRL_PACKET_SIZE_NRF52840, ++ VENDOR_ID, ++ PRODUCT_ID, ++ STRINGS, ++ ) ++ ); ++ nrf52840::usbd::USBD.set_client(usb_ctap); ++ ++ // Enable power events to be sent to USB controller ++ nrf52840::power::POWER.set_usb_client(&nrf52840::usbd::USBD); ++ nrf52840::power::POWER.enable_interrupts(); ++ ++ // Configure the USB userspace driver ++ let usb_driver = static_init!( ++ capsules::usb::usb_ctap::CtapUsbSyscallDriver< ++ 'static, ++ 'static, ++ nrf52840::usbd::Usbd<'static>, ++ >, ++ capsules::usb::usb_ctap::CtapUsbSyscallDriver::new( ++ usb_ctap, ++ board_kernel.create_grant(&memory_allocation_capability) ++ ) ++ ); ++ usb_ctap.set_client(usb_driver); ++ usb_driver as &'static _ ++ }; ++ + nrf52_components::NrfClockComponent::new().finalize(()); + + let platform = Platform { +@@ -464,6 +525,7 @@ pub unsafe fn reset_handler() { + analog_comparator, + nonvolatile_storage, + nvmc, ++ usb, + ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability), + }; + diff --git a/capsules/src/driver.rs b/capsules/src/driver.rs -index bfc06429..5858d352 100644 +index 256fc0e..ae458b3 100644 --- a/capsules/src/driver.rs +++ b/capsules/src/driver.rs -@@ -25,6 +25,7 @@ pub enum NUM { +@@ -26,6 +26,7 @@ pub enum NUM { I2cMaster = 0x20003, UsbUser = 0x20005, I2cMasterSlave = 0x20006, + UsbCtap = 0x20009, - + // Radio BleAdvertising = 0x30000, diff --git a/capsules/src/usb/mod.rs b/capsules/src/usb/mod.rs -index e5c8d6ad..7af3da2e 100644 +index 767f5de..3f3a4f6 100644 --- a/capsules/src/usb/mod.rs +++ b/capsules/src/usb/mod.rs -@@ -1,4 +1,6 @@ +@@ -1,5 +1,7 @@ + pub mod cdc; pub mod descriptors; +pub mod usb_ctap; pub mod usb_user; @@ -148,7 +240,7 @@ index e5c8d6ad..7af3da2e 100644 +pub mod usbc_ctap_hid; diff --git a/capsules/src/usb/usb_ctap.rs b/capsules/src/usb/usb_ctap.rs new file mode 100644 -index 00000000..da3d16d8 +index 0000000..da3d16d --- /dev/null +++ b/capsules/src/usb/usb_ctap.rs @@ -0,0 +1,355 @@ @@ -509,16 +601,15 @@ index 00000000..da3d16d8 +} diff --git a/capsules/src/usb/usbc_ctap_hid.rs b/capsules/src/usb/usbc_ctap_hid.rs new file mode 100644 -index 00000000..4b1916cf +index 0000000..d97b72d --- /dev/null +++ b/capsules/src/usb/usbc_ctap_hid.rs -@@ -0,0 +1,359 @@ +@@ -0,0 +1,363 @@ +//! A USB HID client of the USB hardware interface + ++use super::descriptors; +use super::descriptors::Buffer64; -+use super::descriptors::ConfigurationDescriptor; +use super::descriptors::DescriptorType; -+use super::descriptors::DeviceDescriptor; +use super::descriptors::EndpointAddress; +use super::descriptors::EndpointDescriptor; +use super::descriptors::HIDCountryCode; @@ -535,36 +626,11 @@ index 00000000..4b1916cf +use kernel::hil; +use kernel::hil::usb::TransferType; + -+const VENDOR_ID: u16 = 0x1915; // Nordic Semiconductor -+const PRODUCT_ID: u16 = 0x521f; // nRF52840 Dongle (PCA10059) -+ +static LANGUAGES: &'static [u16; 1] = &[ + 0x0409, // English (United States) +]; + -+static STRINGS: &'static [&'static str] = &[ -+ // Manufacturer -+ "Nordic Semiconductor ASA", -+ // Product -+ "OpenSK", -+ // Serial number -+ "v0.1", -+]; -+ -+static ENDPOINTS: &'static [EndpointDescriptor] = &[ -+ EndpointDescriptor { -+ endpoint_address: EndpointAddress::new_const(1, TransferDirection::HostToDevice), -+ transfer_type: TransferType::Interrupt, -+ max_packet_size: 64, -+ interval: 5, -+ }, -+ EndpointDescriptor { -+ endpoint_address: EndpointAddress::new_const(1, TransferDirection::DeviceToHost), -+ transfer_type: TransferType::Interrupt, -+ max_packet_size: 64, -+ interval: 5, -+ }, -+]; ++const ENDPOINT_NUM: usize = 1; + +static CTAP_REPORT_DESCRIPTOR: &'static [u8] = &[ + 0x06, 0xD0, 0xF1, // HID_UsagePage ( FIDO_USAGE_PAGE ), @@ -616,41 +682,71 @@ index 00000000..4b1916cf +} + +impl<'a, 'b, C: hil::usb::UsbController<'a>> ClientCtapHID<'a, 'b, C> { -+ pub fn new(controller: &'a C) -> Self { -+ ClientCtapHID { -+ client_ctrl: ClientCtrl::new( -+ controller, -+ DeviceDescriptor { -+ // TODO: set this field at the board level. -+ max_packet_size_ep0: 64, -+ vendor_id: VENDOR_ID, -+ product_id: PRODUCT_ID, ++ pub fn new( ++ controller: &'a C, ++ max_ctrl_packet_size: u8, ++ vendor_id: u16, ++ product_id: u16, ++ strings: &'static [&'static str] ++ ) -> Self { ++ let interfaces: &mut [InterfaceDescriptor] = &mut [ ++ // Interface declared in the FIDO2 specification, section 8.1.8.1 ++ InterfaceDescriptor { ++ interface_class: 0x03, // HID ++ interface_subclass: 0x00, ++ interface_protocol: 0x00, ++ ..InterfaceDescriptor::default() ++ }, ++ ]; ++ ++ let endpoints: &[&[EndpointDescriptor]] = &[&[ ++ EndpointDescriptor { ++ endpoint_address: EndpointAddress::new_const(ENDPOINT_NUM, TransferDirection::HostToDevice), ++ transfer_type: TransferType::Interrupt, ++ max_packet_size: 64, ++ interval: 5, ++ }, ++ EndpointDescriptor { ++ endpoint_address: EndpointAddress::new_const(ENDPOINT_NUM, TransferDirection::DeviceToHost), ++ transfer_type: TransferType::Interrupt, ++ max_packet_size: 64, ++ interval: 5, ++ }, ++ ]]; ++ ++ let (device_descriptor_buffer, other_descriptor_buffer) = ++ descriptors::create_descriptor_buffers( ++ descriptors::DeviceDescriptor { ++ vendor_id: vendor_id, ++ product_id: product_id, + manufacturer_string: 1, + product_string: 2, + serial_number_string: 3, -+ ..Default::default() ++ max_packet_size_ep0: max_ctrl_packet_size, ++ ..descriptors::DeviceDescriptor::default() + }, -+ ConfigurationDescriptor { -+ // Must be non-zero, otherwise dmesg prints the following error: -+ // [...] usb 2-3: config 0 descriptor?? ++ descriptors::ConfigurationDescriptor { + configuration_value: 1, -+ ..Default::default() ++ ..descriptors::ConfigurationDescriptor::default() + }, -+ // Interface declared in the FIDO2 specification, section 8.1.8.1 -+ InterfaceDescriptor { -+ interface_class: 0x03, // HID -+ interface_subclass: 0x00, -+ interface_protocol: 0x00, -+ ..Default::default() -+ }, -+ ENDPOINTS, ++ interfaces, ++ endpoints, ++ Some(&HID), ++ None, // No CDC descriptor array ++ ); ++ ++ ClientCtapHID { ++ client_ctrl: ClientCtrl::new( ++ controller, ++ device_descriptor_buffer, ++ other_descriptor_buffer, + Some(&HID), + Some(&CTAP_REPORT), + LANGUAGES, -+ STRINGS, ++ strings, + ), -+ in_buffer: Default::default(), -+ out_buffer: Default::default(), ++ in_buffer: Buffer64::default(), ++ out_buffer: Buffer64::default(), + client: OptionalCell::empty(), + tx_packet: OptionalCell::empty(), + pending_in: Cell::new(false), @@ -872,3 +968,19 @@ index 00000000..4b1916cf + self.client.map(|client| client.packet_transmitted()); + } +} +diff --git a/chips/nrf52840/src/lib.rs b/chips/nrf52840/src/lib.rs +index 942d028..ce73e1f 100644 +--- a/chips/nrf52840/src/lib.rs ++++ b/chips/nrf52840/src/lib.rs +@@ -2,7 +2,7 @@ + + pub use nrf52::{ + acomp, adc, aes, ble_radio, clock, constants, crt1, ficr, i2c, ieee802154_radio, init, nvmc, +- pinmux, ppi, pwm, rtc, spi, temperature, timer, trng, uart, uicr, usbd, ++ pinmux, power, ppi, pwm, rtc, spi, temperature, timer, trng, uart, uicr, usbd, + }; + pub mod chip; + pub mod gpio; +-- +libgit2 1.0.1 + diff --git a/patches/tock/03-usb-debugging.patch b/patches/tock/03-usb-debugging.patch index 892a0f9..57bd7f5 100644 --- a/patches/tock/03-usb-debugging.patch +++ b/patches/tock/03-usb-debugging.patch @@ -1,22 +1,16 @@ diff --git a/boards/nordic/nrf52840dk/src/main.rs b/boards/nordic/nrf52840dk/src/main.rs -index a5847805..f0b303bf 100644 +index 303a451..18fd331 100644 --- a/boards/nordic/nrf52840dk/src/main.rs +++ b/boards/nordic/nrf52840dk/src/main.rs -@@ -102,7 +102,7 @@ pub mod io; +@@ -112,7 +112,7 @@ pub mod io; // Whether to use UART debugging or Segger RTT (USB) debugging. // - Set to false to use UART. // - Set to true to use Segger RTT over USB. -const USB_DEBUGGING: bool = false; +const USB_DEBUGGING: bool = true; - - // State for loading and holding applications. - // How should the kernel respond when a process faults. -@@ -112,7 +112,7 @@ const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultRespons - const NUM_PROCS: usize = 8; - - #[link_section = ".app_memory"] --static mut APP_MEMORY: [u8; 0x3C000] = [0; 0x3C000]; -+static mut APP_MEMORY: [u8; 0x3A000] = [0; 0x3A000]; - - static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] = - [None, None, None, None, None, None, None, None]; + + const VENDOR_ID: u16 = 0x1915; // Nordic Semiconductor + const PRODUCT_ID: u16 = 0x521f; // nRF52840 Dongle (PCA10059) +-- +libgit2 1.0.1 + diff --git a/patches/tock/04-additional-boards.patch b/patches/tock/04-additional-boards.patch index 88cd1c3..fa5b51b 100644 --- a/patches/tock/04-additional-boards.patch +++ b/patches/tock/04-additional-boards.patch @@ -1,9 +1,9 @@ diff --git a/Cargo.toml b/Cargo.toml -index 18f4a10d..db88dc1d 100644 +index 83c4855..cfd63b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,8 @@ members = [ - "boards/launchxl", + "boards/msp_exp432p401r", "boards/nordic/nrf52840dk", "boards/nordic/nrf52840_dongle", + "boards/nordic/nrf52840_dongle_dfu", @@ -11,3 +11,6 @@ index 18f4a10d..db88dc1d 100644 "boards/nordic/nrf52dk", "boards/nucleo_f429zi", "boards/nucleo_f446re", +-- +libgit2 1.0.1 + From 9e8e83fb3264e3d967767b23df86f975e6941188 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 11:48:59 +0200 Subject: [PATCH 05/15] Patch cleanup --- patches/tock/01-persistent-storage.patch | 3 --- patches/tock/02-usb.patch | 3 --- patches/tock/03-usb-debugging.patch | 3 --- patches/tock/04-additional-boards.patch | 3 --- 4 files changed, 12 deletions(-) diff --git a/patches/tock/01-persistent-storage.patch b/patches/tock/01-persistent-storage.patch index e28db71..ea6b004 100644 --- a/patches/tock/01-persistent-storage.patch +++ b/patches/tock/01-persistent-storage.patch @@ -612,6 +612,3 @@ index 88eea40..ed3ae82 100644 + self.storage_locations + } } --- -libgit2 1.0.1 - diff --git a/patches/tock/02-usb.patch b/patches/tock/02-usb.patch index ba45dbf..9650633 100644 --- a/patches/tock/02-usb.patch +++ b/patches/tock/02-usb.patch @@ -981,6 +981,3 @@ index 942d028..ce73e1f 100644 }; pub mod chip; pub mod gpio; --- -libgit2 1.0.1 - diff --git a/patches/tock/03-usb-debugging.patch b/patches/tock/03-usb-debugging.patch index 57bd7f5..2bebb33 100644 --- a/patches/tock/03-usb-debugging.patch +++ b/patches/tock/03-usb-debugging.patch @@ -11,6 +11,3 @@ index 303a451..18fd331 100644 const VENDOR_ID: u16 = 0x1915; // Nordic Semiconductor const PRODUCT_ID: u16 = 0x521f; // nRF52840 Dongle (PCA10059) --- -libgit2 1.0.1 - diff --git a/patches/tock/04-additional-boards.patch b/patches/tock/04-additional-boards.patch index fa5b51b..b4f0ba9 100644 --- a/patches/tock/04-additional-boards.patch +++ b/patches/tock/04-additional-boards.patch @@ -11,6 +11,3 @@ index 83c4855..cfd63b1 100644 "boards/nordic/nrf52dk", "boards/nucleo_f429zi", "boards/nucleo_f446re", --- -libgit2 1.0.1 - From 730670eac8b8dd0cba1b69f1f5b3877d760212d4 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 12:03:45 +0200 Subject: [PATCH 06/15] Update reproducible references --- .../reference_binaries_macos-10.15.sha256sum | 18 +++--- .../reference_binaries_ubuntu-18.04.sha256sum | 18 +++--- .../reference_elf2tab_macos-10.15.txt | 60 ++++++++++++------- .../reference_elf2tab_ubuntu-18.04.txt | 60 ++++++++++++------- 4 files changed, 98 insertions(+), 58 deletions(-) diff --git a/reproducible/reference_binaries_macos-10.15.sha256sum b/reproducible/reference_binaries_macos-10.15.sha256sum index 15e210d..0b371d5 100644 --- a/reproducible/reference_binaries_macos-10.15.sha256sum +++ b/reproducible/reference_binaries_macos-10.15.sha256sum @@ -1,9 +1,9 @@ -91a98f475cb3042dd5184598a8292edb2a414df8d967a35c8f2295826b5a161b third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -7cc5c802e22e73c1edfd5b890642c5f6c4a1f888b61f0cd6d638a770eb0af739 target/nrf52840dk_merged.hex -a5943c5311158b0f99370246d37782eb9b12fc36c56387eadb6587a3a4fe8fd5 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -9ff31263bd33e92b5f1f59d83f557046cb4d022919a5082931a197a2f6ec4398 target/nrf52840_dongle_merged.hex -663297e3e29b9e2a972b68cea1592aaf965d797242579bb5bca09cd73cdfb637 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -4b1f17b3dda2460fe83adc157f8ae1fb2559fb151b8897806e7b0aa25c898ec1 target/nrf52840_dongle_dfu_merged.hex -162a05d056aafc16d4868d5c3aa10518e41299dddd60608f96954dc9cf964cd3 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -90369c2f5c1b3b3a443114be069fd2da0806444865830a7e992ed52e036c5a39 target/nrf52840_mdk_dfu_merged.hex -299201ff87cd84bd767516143b4e6a54759e01fcd864c0e579c62217b21d4fa4 target/tab/ctap2.tab +dd054bcb95f2b0f79b769338d67c92a8b4820b7c3da1dfa74ce8b9dd9ce7eb2e third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin +c115a70552fb9fad43abab3ce5258c8c5ccf31d52bac395bb721f3a6db8fc2af target/nrf52840dk_merged.hex +3e8f042d9f3cf9ab54b9bc002a0166bababd119cc5659040dac77d2a5a0c4214 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin +124e5ed2b079df6d0bae7c291f4842e4b38a7fc2fabb7233ce0b5feaa256f757 target/nrf52840_dongle_merged.hex +00ab26ca646c2f7a91513ac12fb34e59cb7f127162204fa779745b28a7652b43 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin +d4a4e14bd62af48272b7288132980b601ad90d6cd7095ec23a1b3372a74f5e5f target/nrf52840_dongle_dfu_merged.hex +1e44c023be5d5b8a4fa9b63b89da5642e21171797ee5683f574c899a01bc02f4 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin +8936bf9efdaaec6092b52e4503937d8f0da89e336f0acd9e8ce7b80cf4355477 target/nrf52840_mdk_dfu_merged.hex +dd311ff3bc4d20ce26362f72aa85c7bc45d7b49e605fe07bc6f5caf5677dda1b target/tab/ctap2.tab diff --git a/reproducible/reference_binaries_ubuntu-18.04.sha256sum b/reproducible/reference_binaries_ubuntu-18.04.sha256sum index a752d4b..96a396f 100644 --- a/reproducible/reference_binaries_ubuntu-18.04.sha256sum +++ b/reproducible/reference_binaries_ubuntu-18.04.sha256sum @@ -1,9 +1,9 @@ -3feb5d29a3d669107b460a00391440be4ebc5e50461f9ef3248714f4f99c070e third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -875fdc2bbd473a5c77c119ba860e54a43f8097c20931cc5ae83a26e9311ce124 target/nrf52840dk_merged.hex -8eebe1c1dfe22003466c2570b3735c54c58ae91b8168582ad363ab79c9230a15 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -70c1249370144c6ca55ad490dc5e418f9c2994c2649941dec41d769963a0e0ad target/nrf52840_dongle_merged.hex -779d77071d1e629f92210ac313e230bcaea6d77c710210c1ac4b40f8085cdad7 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -6c12edd4ec4d952619e976e635df39235d821eec9902e8882563fc43a1690ddb target/nrf52840_dongle_dfu_merged.hex -f466490d6498f6c06c7c4a717eb437ba2fb06d1985532c23f145d38b9daa8259 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -7b67e726071ac5161344212821b9869c8f289559c8b91a5f2a0f17624855ce8a target/nrf52840_mdk_dfu_merged.hex -4dd8753dba382bdbadd0c9761949f7bdacbd77408cfc8dc466107a81ff664b15 target/tab/ctap2.tab +5f1c0025d32f5dec4add376821b90862f1a32e29060a756fd222fb0e92962f82 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin +b28238d680243d32b6ac20c7bc331d3f56473daa1dbf366362cfc5c6177ed1a5 target/nrf52840dk_merged.hex +167bfb73fee0bbc1ef175dd3297c814348a197b9714b6dd95aacbb21f208fb1c third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin +9ed8fe50434024c92235aa6dced008366403455fe4c881ada17dca28e93e18a9 target/nrf52840_dongle_merged.hex +6598d68be26168ace3166229de6e5fbc6595cfc569b053d090002c63c6fab5f4 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin +6252822fcf6d16665728047d82fd8eba5bf6fdc9a7d2ea464f0b3f4fee24678e target/nrf52840_dongle_dfu_merged.hex +bd6e9d5aaea4edb7d3572da4eb5659faaadb742fe49cd718ebfb63d3792f26a8 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin +0aa364726611aa4a0c5f702fa52d21843c11cb555607610df94fcc4a99b71234 target/nrf52840_mdk_dfu_merged.hex +3524a90b67817d86bc75a4910b6fe407c606cf52f147d4e09bdaed3e59c23d8e target/tab/ctap2.tab diff --git a/reproducible/reference_elf2tab_macos-10.15.txt b/reproducible/reference_elf2tab_macos-10.15.txt index 25d9573..e48bd81 100644 --- a/reproducible/reference_elf2tab_macos-10.15.txt +++ b/reproducible/reference_elf2tab_macos-10.15.txt @@ -1,76 +1,96 @@ ======================================== Board: nrf52840dk ---------------------------------------- +Creating "target/tab/thumbv7em-none-eabi.tbf" Min RAM size from sections in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178688 (0x2ba00) bytes. - Adding .stack section. Offset: 178816 (0x2ba80). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes. + Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_dongle ---------------------------------------- +Creating "target/tab/thumbv7em-none-eabi.tbf" Min RAM size from sections in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178688 (0x2ba00) bytes. - Adding .stack section. Offset: 178816 (0x2ba80). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes. + Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_dongle_dfu ---------------------------------------- +Creating "target/tab/thumbv7em-none-eabi.tbf" Min RAM size from sections in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178688 (0x2ba00) bytes. - Adding .stack section. Offset: 178816 (0x2ba80). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes. + Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_mdk_dfu ---------------------------------------- +Creating "target/tab/thumbv7em-none-eabi.tbf" Min RAM size from sections in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178688 (0x2ba00) bytes. - Adding .stack section. Offset: 178816 (0x2ba80). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes. + Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + diff --git a/reproducible/reference_elf2tab_ubuntu-18.04.txt b/reproducible/reference_elf2tab_ubuntu-18.04.txt index b652638..e48bd81 100644 --- a/reproducible/reference_elf2tab_ubuntu-18.04.txt +++ b/reproducible/reference_elf2tab_ubuntu-18.04.txt @@ -1,76 +1,96 @@ ======================================== Board: nrf52840dk ---------------------------------------- +Creating "target/tab/thumbv7em-none-eabi.tbf" Min RAM size from sections in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178536 (0x2b968) bytes. - Adding .stack section. Offset: 178664 (0x2b9e8). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes. + Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_dongle ---------------------------------------- +Creating "target/tab/thumbv7em-none-eabi.tbf" Min RAM size from sections in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178536 (0x2b968) bytes. - Adding .stack section. Offset: 178664 (0x2b9e8). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes. + Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_dongle_dfu ---------------------------------------- +Creating "target/tab/thumbv7em-none-eabi.tbf" Min RAM size from sections in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178536 (0x2b968) bytes. - Adding .stack section. Offset: 178664 (0x2b9e8). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes. + Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_mdk_dfu ---------------------------------------- +Creating "target/tab/thumbv7em-none-eabi.tbf" Min RAM size from sections in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178536 (0x2b968) bytes. - Adding .stack section. Offset: 178664 (0x2b9e8). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 179168 (0x2bbe0) bytes. + Adding .stack section. Offset: 179296 (0x2bc60). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + From b4e77e54e36a6dbb3968384c8a6d56906f8346c5 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 12:13:30 +0200 Subject: [PATCH 07/15] Fix references --- reproducible/reference_elf2tab_macos-10.15.txt | 8 ++++---- reproducible/reference_elf2tab_ubuntu-18.04.txt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/reproducible/reference_elf2tab_macos-10.15.txt b/reproducible/reference_elf2tab_macos-10.15.txt index e48bd81..3f0ea27 100644 --- a/reproducible/reference_elf2tab_macos-10.15.txt +++ b/reproducible/reference_elf2tab_macos-10.15.txt @@ -2,7 +2,7 @@ Board: nrf52840dk ---------------------------------------- Creating "target/tab/thumbv7em-none-eabi.tbf" -Min RAM size from sections in ELF: 20 bytes +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section @@ -26,7 +26,7 @@ TBF Header: Board: nrf52840_dongle ---------------------------------------- Creating "target/tab/thumbv7em-none-eabi.tbf" -Min RAM size from sections in ELF: 20 bytes +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section @@ -50,7 +50,7 @@ TBF Header: Board: nrf52840_dongle_dfu ---------------------------------------- Creating "target/tab/thumbv7em-none-eabi.tbf" -Min RAM size from sections in ELF: 20 bytes +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section @@ -74,7 +74,7 @@ TBF Header: Board: nrf52840_mdk_dfu ---------------------------------------- Creating "target/tab/thumbv7em-none-eabi.tbf" -Min RAM size from sections in ELF: 20 bytes +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section diff --git a/reproducible/reference_elf2tab_ubuntu-18.04.txt b/reproducible/reference_elf2tab_ubuntu-18.04.txt index e48bd81..3f0ea27 100644 --- a/reproducible/reference_elf2tab_ubuntu-18.04.txt +++ b/reproducible/reference_elf2tab_ubuntu-18.04.txt @@ -2,7 +2,7 @@ Board: nrf52840dk ---------------------------------------- Creating "target/tab/thumbv7em-none-eabi.tbf" -Min RAM size from sections in ELF: 20 bytes +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section @@ -26,7 +26,7 @@ TBF Header: Board: nrf52840_dongle ---------------------------------------- Creating "target/tab/thumbv7em-none-eabi.tbf" -Min RAM size from sections in ELF: 20 bytes +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section @@ -50,7 +50,7 @@ TBF Header: Board: nrf52840_dongle_dfu ---------------------------------------- Creating "target/tab/thumbv7em-none-eabi.tbf" -Min RAM size from sections in ELF: 20 bytes +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section @@ -74,7 +74,7 @@ TBF Header: Board: nrf52840_mdk_dfu ---------------------------------------- Creating "target/tab/thumbv7em-none-eabi.tbf" -Min RAM size from sections in ELF: 20 bytes +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section From a70c57f57b1fc0aa0ea91033ea69db2535ffaae9 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 13:56:53 +0200 Subject: [PATCH 08/15] Fix reproducibility --- build.rs | 1 + reproducible/{ => sample_crypto_data}/aaguid.txt | 0 2 files changed, 1 insertion(+) rename reproducible/{ => sample_crypto_data}/aaguid.txt (100%) diff --git a/build.rs b/build.rs index e9f2835..cce31f2 100644 --- a/build.rs +++ b/build.rs @@ -29,6 +29,7 @@ use uuid::Uuid; fn main() { println!("cargo:rerun-if-changed=crypto_data/opensk.key"); println!("cargo:rerun-if-changed=crypto_data/opensk_cert.pem"); + println!("cargo:rerun-if-changed=crypto_data/aaguid.txt"); let out_dir = env::var_os("OUT_DIR").unwrap(); let priv_key_bin_path = Path::new(&out_dir).join("opensk_pkey.bin"); diff --git a/reproducible/aaguid.txt b/reproducible/sample_crypto_data/aaguid.txt similarity index 100% rename from reproducible/aaguid.txt rename to reproducible/sample_crypto_data/aaguid.txt From 4f6b1fa04e3adf955e649f144ffb3a6b52064232 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 14:07:13 +0200 Subject: [PATCH 09/15] Update hashes. --- reproducible/reference_binaries_macos-10.15.sha256sum | 10 +++++----- reproducible/reference_binaries_ubuntu-18.04.sha256sum | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/reproducible/reference_binaries_macos-10.15.sha256sum b/reproducible/reference_binaries_macos-10.15.sha256sum index 0b371d5..feaab06 100644 --- a/reproducible/reference_binaries_macos-10.15.sha256sum +++ b/reproducible/reference_binaries_macos-10.15.sha256sum @@ -1,9 +1,9 @@ dd054bcb95f2b0f79b769338d67c92a8b4820b7c3da1dfa74ce8b9dd9ce7eb2e third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -c115a70552fb9fad43abab3ce5258c8c5ccf31d52bac395bb721f3a6db8fc2af target/nrf52840dk_merged.hex +64f82a30ac60328f86e85fb40a816396e79ce62ceb689d218dfded85389680c3 target/nrf52840dk_merged.hex 3e8f042d9f3cf9ab54b9bc002a0166bababd119cc5659040dac77d2a5a0c4214 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -124e5ed2b079df6d0bae7c291f4842e4b38a7fc2fabb7233ce0b5feaa256f757 target/nrf52840_dongle_merged.hex +d0b3606d665e490845742e08619e2b1a0046c243b052a6d1b6c939a06c6f6a0e target/nrf52840_dongle_merged.hex 00ab26ca646c2f7a91513ac12fb34e59cb7f127162204fa779745b28a7652b43 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -d4a4e14bd62af48272b7288132980b601ad90d6cd7095ec23a1b3372a74f5e5f target/nrf52840_dongle_dfu_merged.hex +bdae1f0a646c7b83e62e2508315d0363979aae63c18403437a0b46336c2bcc7a target/nrf52840_dongle_dfu_merged.hex 1e44c023be5d5b8a4fa9b63b89da5642e21171797ee5683f574c899a01bc02f4 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -8936bf9efdaaec6092b52e4503937d8f0da89e336f0acd9e8ce7b80cf4355477 target/nrf52840_mdk_dfu_merged.hex -dd311ff3bc4d20ce26362f72aa85c7bc45d7b49e605fe07bc6f5caf5677dda1b target/tab/ctap2.tab +0661860b541850303c6125298d7f8f3ad53af3c8890da39357c702ab6c2c6e9f target/nrf52840_mdk_dfu_merged.hex +898a78d4f1ecc94d2894552caf62f0b382a743aecb316ac3791df70fc62370b9 target/tab/ctap2.tab diff --git a/reproducible/reference_binaries_ubuntu-18.04.sha256sum b/reproducible/reference_binaries_ubuntu-18.04.sha256sum index 96a396f..7b3aedd 100644 --- a/reproducible/reference_binaries_ubuntu-18.04.sha256sum +++ b/reproducible/reference_binaries_ubuntu-18.04.sha256sum @@ -1,9 +1,9 @@ 5f1c0025d32f5dec4add376821b90862f1a32e29060a756fd222fb0e92962f82 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -b28238d680243d32b6ac20c7bc331d3f56473daa1dbf366362cfc5c6177ed1a5 target/nrf52840dk_merged.hex +fff683de6c7f5d8882e66f3612a405e9349e6c2c8685f55994d504c0507bfd2e target/nrf52840dk_merged.hex 167bfb73fee0bbc1ef175dd3297c814348a197b9714b6dd95aacbb21f208fb1c third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -9ed8fe50434024c92235aa6dced008366403455fe4c881ada17dca28e93e18a9 target/nrf52840_dongle_merged.hex +712248ce61d13151e2b9caa585b039b88238dfe50b5a6708003e11e493cba485 target/nrf52840_dongle_merged.hex 6598d68be26168ace3166229de6e5fbc6595cfc569b053d090002c63c6fab5f4 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -6252822fcf6d16665728047d82fd8eba5bf6fdc9a7d2ea464f0b3f4fee24678e target/nrf52840_dongle_dfu_merged.hex +af09a491d27b626ab28f41bac759028f61f342d7487f93a5a6740ba4fb625001 target/nrf52840_dongle_dfu_merged.hex bd6e9d5aaea4edb7d3572da4eb5659faaadb742fe49cd718ebfb63d3792f26a8 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -0aa364726611aa4a0c5f702fa52d21843c11cb555607610df94fcc4a99b71234 target/nrf52840_mdk_dfu_merged.hex -3524a90b67817d86bc75a4910b6fe407c606cf52f147d4e09bdaed3e59c23d8e target/tab/ctap2.tab +e82e4558ac8d378930ce09c12a8e01bc3fa206fdec8778688d059ee5f7d1c091 target/nrf52840_mdk_dfu_merged.hex +327a46a4f591072004d47e48983ad0b8c2ee5eb2fc64e5aba78cd3d2b1916336 target/tab/ctap2.tab From 62151ed614a18171617b02ef1bc317080bbeddb1 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 17:15:33 +0200 Subject: [PATCH 10/15] Fix MPU issue --- patches/tock/05-mpu-fix.patch | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 patches/tock/05-mpu-fix.patch diff --git a/patches/tock/05-mpu-fix.patch b/patches/tock/05-mpu-fix.patch new file mode 100644 index 0000000..4a3c4e4 --- /dev/null +++ b/patches/tock/05-mpu-fix.patch @@ -0,0 +1,12 @@ +diff --git a/kernel/src/sched.rs b/kernel/src/sched.rs +index ed3ae8260..f109960d3 100644 +--- a/kernel/src/sched.rs ++++ b/kernel/src/sched.rs +@@ -632,6 +632,7 @@ impl Kernel { + let context_switch_reason = process.switch_to(); + scheduler_timer.disarm(); + chip.mpu().disable_app_mpu(); ++ chip.mpu().clear_mpu(); + + // Now the process has returned back to the kernel. Check + // why and handle the process as appropriate. From 2b2b9ecc6facef75ca33105c37a0a0839d4b4855 Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Wed, 16 Sep 2020 17:24:53 +0200 Subject: [PATCH 11/15] Update reproducible hashes --- .../reference_binaries_macos-10.15.sha256sum | 16 ++++++++-------- .../reference_binaries_ubuntu-18.04.sha256sum | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/reproducible/reference_binaries_macos-10.15.sha256sum b/reproducible/reference_binaries_macos-10.15.sha256sum index feaab06..2284958 100644 --- a/reproducible/reference_binaries_macos-10.15.sha256sum +++ b/reproducible/reference_binaries_macos-10.15.sha256sum @@ -1,9 +1,9 @@ -dd054bcb95f2b0f79b769338d67c92a8b4820b7c3da1dfa74ce8b9dd9ce7eb2e third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -64f82a30ac60328f86e85fb40a816396e79ce62ceb689d218dfded85389680c3 target/nrf52840dk_merged.hex -3e8f042d9f3cf9ab54b9bc002a0166bababd119cc5659040dac77d2a5a0c4214 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -d0b3606d665e490845742e08619e2b1a0046c243b052a6d1b6c939a06c6f6a0e target/nrf52840_dongle_merged.hex -00ab26ca646c2f7a91513ac12fb34e59cb7f127162204fa779745b28a7652b43 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -bdae1f0a646c7b83e62e2508315d0363979aae63c18403437a0b46336c2bcc7a target/nrf52840_dongle_dfu_merged.hex -1e44c023be5d5b8a4fa9b63b89da5642e21171797ee5683f574c899a01bc02f4 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -0661860b541850303c6125298d7f8f3ad53af3c8890da39357c702ab6c2c6e9f target/nrf52840_mdk_dfu_merged.hex +c242b0237b93328eea0213411916f84e3ce631c3eea3bf56d6769ae5aa0b8d06 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin +34e36dc04716c159800ae3ab3f2750bee4ea66df40e08b864a93d873c34142e7 target/nrf52840dk_merged.hex +259a54fae11cb8f1306051354825d19223ba4c33f3adfdb2d3e9d9efc7229302 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin +64f4b7b21ab3ff492f1e108ed72c96ec9c8cba5d44774c3fa0900e443f3d2de8 target/nrf52840_dongle_merged.hex +49d647374a1448c9c3107758b6e0a1cabdf008c3e53524a3b047a16c27b8af29 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin +cb70d4547756f8cbfc54ec94ee350022b2a0433c370a240a35d22128c8864337 target/nrf52840_dongle_dfu_merged.hex +06a38a0d6d356145467a73c765e28a945878f663664016f888393207097bfe10 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin +affb4c7ca43212a6734aa112fb19aa23cb2f0571bc085d5dfd4b6fe08c97f110 target/nrf52840_mdk_dfu_merged.hex 898a78d4f1ecc94d2894552caf62f0b382a743aecb316ac3791df70fc62370b9 target/tab/ctap2.tab diff --git a/reproducible/reference_binaries_ubuntu-18.04.sha256sum b/reproducible/reference_binaries_ubuntu-18.04.sha256sum index 7b3aedd..c5839fa 100644 --- a/reproducible/reference_binaries_ubuntu-18.04.sha256sum +++ b/reproducible/reference_binaries_ubuntu-18.04.sha256sum @@ -1,9 +1,9 @@ -5f1c0025d32f5dec4add376821b90862f1a32e29060a756fd222fb0e92962f82 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -fff683de6c7f5d8882e66f3612a405e9349e6c2c8685f55994d504c0507bfd2e target/nrf52840dk_merged.hex -167bfb73fee0bbc1ef175dd3297c814348a197b9714b6dd95aacbb21f208fb1c third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -712248ce61d13151e2b9caa585b039b88238dfe50b5a6708003e11e493cba485 target/nrf52840_dongle_merged.hex -6598d68be26168ace3166229de6e5fbc6595cfc569b053d090002c63c6fab5f4 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -af09a491d27b626ab28f41bac759028f61f342d7487f93a5a6740ba4fb625001 target/nrf52840_dongle_dfu_merged.hex -bd6e9d5aaea4edb7d3572da4eb5659faaadb742fe49cd718ebfb63d3792f26a8 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -e82e4558ac8d378930ce09c12a8e01bc3fa206fdec8778688d059ee5f7d1c091 target/nrf52840_mdk_dfu_merged.hex +dab66677002854f6abfb1745d24d1c9e4e93c9bba286b14024e42cb8f2b99b9a third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin +8e33b850330bdd19314e443792a170e04669fe932122af5498dcdd38bf47af7b target/nrf52840dk_merged.hex +70cf9f6c1d6b2149c1ca88664073a92e092215faaf551310f8bfd8e171d3d3a1 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin +4cf4a438a9796091e91e80d15cc1ca840d0cf7e7cf5816a9650e7c33f0a78120 target/nrf52840_dongle_merged.hex +f550b6493c8cd401d191306510de50ddd6d4c709dcf90ea1bd3a9f1bcffd11b5 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin +02f529795cb2faf09a82e0b42cc1152a9d0f7fa2679135333d2b8e9e19069f59 target/nrf52840_dongle_dfu_merged.hex +1baaf518a74c6077cb936d9cf178b6dd0232e7562fa56174886b05b77886cc32 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin +1c32f85c081d69eaf88bf08b885ee2c4b0a590f824045fa73350a14ad2b4f0b9 target/nrf52840_mdk_dfu_merged.hex 327a46a4f591072004d47e48983ad0b8c2ee5eb2fc64e5aba78cd3d2b1916336 target/tab/ctap2.tab From ff73936a4d142ed989193ee375d3463b6d19cbce Mon Sep 17 00:00:00 2001 From: Guillaume Endignoux Date: Tue, 22 Sep 2020 13:14:33 +0200 Subject: [PATCH 12/15] Fix imports in ctap, embedded_flash and lang-items. --- src/ctap/ctap1.rs | 2 +- src/ctap/hid/mod.rs | 6 +++--- src/ctap/hid/receive.rs | 4 ++-- src/ctap/storage.rs | 8 ++++---- src/ctap/timed_permission.rs | 2 +- src/embedded_flash/mod.rs | 4 ++++ src/embedded_flash/store/mod.rs | 10 +++++++--- src/lib.rs | 5 +++++ src/main.rs | 1 + third_party/lang-items/src/lib.rs | 7 +++++++ 10 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/ctap/ctap1.rs b/src/ctap/ctap1.rs index 56bec45..d412eed 100644 --- a/src/ctap/ctap1.rs +++ b/src/ctap/ctap1.rs @@ -16,11 +16,11 @@ use super::hid::ChannelID; use super::key_material::{ATTESTATION_CERTIFICATE, ATTESTATION_PRIVATE_KEY}; use super::status_code::Ctap2StatusCode; use super::CtapState; -use crate::timer::ClockValue; use alloc::vec::Vec; use core::convert::Into; use core::convert::TryFrom; use crypto::rng256::Rng256; +use libtock_drivers::timer::ClockValue; // The specification referenced in this file is at: // https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-raw-message-formats-v1.2-ps-20170411.pdf diff --git a/src/ctap/hid/mod.rs b/src/ctap/hid/mod.rs index 877a9fa..115bc3a 100644 --- a/src/ctap/hid/mod.rs +++ b/src/ctap/hid/mod.rs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -mod receive; -mod send; +pub mod receive; +pub mod send; use self::receive::MessageAssembler; use self::send::HidPacketIterator; @@ -22,13 +22,13 @@ use super::ctap1; use super::status_code::Ctap2StatusCode; use super::timed_permission::TimedPermission; use super::CtapState; -use crate::timer::{ClockValue, Duration, Timestamp}; use alloc::vec::Vec; #[cfg(feature = "debug_ctap")] use core::fmt::Write; use crypto::rng256::Rng256; #[cfg(feature = "debug_ctap")] use libtock_drivers::console::Console; +use libtock_drivers::timer::{ClockValue, Duration, Timestamp}; // CTAP specification (version 20190130) section 8.1 // TODO: Channel allocation, section 8.1.3? diff --git a/src/ctap/hid/receive.rs b/src/ctap/hid/receive.rs index ae2e707..fef51a4 100644 --- a/src/ctap/hid/receive.rs +++ b/src/ctap/hid/receive.rs @@ -13,9 +13,9 @@ // limitations under the License. use super::{ChannelID, CtapHid, HidPacket, Message, ProcessedPacket}; -use crate::timer::Timestamp; use alloc::vec::Vec; use core::mem::swap; +use libtock_drivers::timer::Timestamp; // A structure to assemble CTAPHID commands from a series of incoming USB HID packets. pub struct MessageAssembler { @@ -195,7 +195,7 @@ impl MessageAssembler { #[cfg(test)] mod test { use super::*; - use crate::timer::Duration; + use libtock_drivers::timer::Duration; // Except for tests that exercise timeouts, all packets are synchronized at the same dummy // timestamp. diff --git a/src/ctap/storage.rs b/src/ctap/storage.rs index 24456c8..7480147 100644 --- a/src/ctap/storage.rs +++ b/src/ctap/storage.rs @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::crypto::rng256::Rng256; #[cfg(feature = "with_ctap2_1")] use crate::ctap::data_formats::{extract_array, extract_text_string}; use crate::ctap::data_formats::{CredentialProtectionPolicy, PublicKeyCredentialSource}; use crate::ctap::pin_protocol_v1::PIN_AUTH_LENGTH; use crate::ctap::status_code::Ctap2StatusCode; use crate::ctap::{key_material, USE_BATCH_ATTESTATION}; +use crate::embedded_flash::{self, StoreConfig, StoreEntry, StoreError}; use alloc::string::String; use alloc::vec::Vec; use core::convert::TryInto; -use ctap2::embedded_flash::{self, StoreConfig, StoreEntry, StoreError}; +use crypto::rng256::Rng256; #[cfg(any(test, feature = "ram_storage"))] type Storage = embedded_flash::BufferStorage; @@ -660,9 +660,9 @@ fn _serialize_min_pin_length_rp_ids(rp_ids: Vec) -> Result, Ctap #[cfg(test)] mod test { use super::*; - use crate::crypto; - use crate::crypto::rng256::{Rng256, ThreadRng256}; use crate::ctap::data_formats::{PublicKeyCredentialSource, PublicKeyCredentialType}; + use crypto; + use crypto::rng256::{Rng256, ThreadRng256}; fn create_credential_source( rng: &mut ThreadRng256, diff --git a/src/ctap/timed_permission.rs b/src/ctap/timed_permission.rs index d56ba09..fcc0ada 100644 --- a/src/ctap/timed_permission.rs +++ b/src/ctap/timed_permission.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::timer::{ClockValue, Duration}; +use libtock_drivers::timer::{ClockValue, Duration}; #[derive(Clone, Copy, Debug)] pub enum TimedPermission { diff --git a/src/embedded_flash/mod.rs b/src/embedded_flash/mod.rs index 8551a52..05407c0 100644 --- a/src/embedded_flash/mod.rs +++ b/src/embedded_flash/mod.rs @@ -12,12 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +#[cfg(any(test, feature = "ram_storage"))] mod buffer; mod storage; mod store; +#[cfg(not(any(test, feature = "ram_storage")))] mod syscall; +#[cfg(any(test, feature = "ram_storage"))] pub use self::buffer::{BufferOptions, BufferStorage}; pub use self::storage::{Index, Storage, StorageError, StorageResult}; pub use self::store::{Store, StoreConfig, StoreEntry, StoreError, StoreIndex}; +#[cfg(not(any(test, feature = "ram_storage")))] pub use self::syscall::SyscallStorage; diff --git a/src/embedded_flash/store/mod.rs b/src/embedded_flash/store/mod.rs index c5cf838..49ab487 100644 --- a/src/embedded_flash/store/mod.rs +++ b/src/embedded_flash/store/mod.rs @@ -163,9 +163,11 @@ mod bitfield; mod format; use self::format::{Format, IsReplace}; -#[cfg(feature = "std")] -use super::BufferStorage; use super::{Index, Storage}; +#[cfg(any(test, feature = "ram_storage"))] +use crate::embedded_flash::BufferStorage; +#[cfg(any(test, feature = "ram_storage"))] +use alloc::boxed::Box; use alloc::collections::BTreeMap; use alloc::vec::Vec; @@ -402,6 +404,7 @@ impl Store { /// Computes the length in bytes that would be used in the storage if an insert operation is /// executed provided the data of the inserted entry has `length` bytes and whether this data is /// sensitive. + #[allow(dead_code)] pub fn insert_len(&self, sensitive: bool, length: usize) -> usize { self.format.entry_size(IsReplace::Insert, sensitive, length) } @@ -410,6 +413,7 @@ impl Store { /// /// The value at index `page` of the result is the number of times page `page` was erased. This /// number is an underestimate in case power was lost when this page was erased. + #[allow(dead_code)] pub fn compaction_info(&self) -> Vec { let mut info = Vec::with_capacity(self.format.num_pages); for page in 0..self.format.num_pages { @@ -766,7 +770,7 @@ impl Store { } // Those functions are not meant for production. -#[cfg(feature = "std")] +#[cfg(any(test, feature = "ram_storage"))] impl Store { /// Takes a snapshot of the storage after a given amount of word operations. pub fn arm_snapshot(&mut self, delay: usize) { diff --git a/src/lib.rs b/src/lib.rs index ae3ca56..0df6552 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,8 +16,13 @@ #[macro_use] extern crate alloc; +#[macro_use] +extern crate arrayref; +#[macro_use] +extern crate cbor; extern crate lang_items; extern crate libtock_core; extern crate libtock_drivers; +pub mod ctap; pub mod embedded_flash; diff --git a/src/main.rs b/src/main.rs index 2cb7a8c..8a3470f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ extern crate cbor; extern crate crypto; mod ctap; +pub mod embedded_flash; use core::cell::Cell; #[cfg(feature = "debug_ctap")] diff --git a/third_party/lang-items/src/lib.rs b/third_party/lang-items/src/lib.rs index c4fdcf8..3d517ac 100644 --- a/third_party/lang-items/src/lib.rs +++ b/third_party/lang-items/src/lib.rs @@ -7,3 +7,10 @@ mod allocator; mod panic_handler; #[cfg(not(feature = "std"))] mod util; + +#[cfg(feature = "std")] +#[no_mangle] +unsafe fn libtock_alloc_init(_app_heap_start: usize, _app_heap_size: usize) { + // Stub so that the symbol is present. + unimplemented!() +} From 361f8753c0365864fd1c3fba92d28b4cde04c1ce Mon Sep 17 00:00:00 2001 From: Guillaume Endignoux Date: Tue, 22 Sep 2020 13:28:21 +0200 Subject: [PATCH 13/15] Fix reference binaries. --- .../reference_binaries_macos-10.15.sha256sum | 10 +-- .../reference_binaries_ubuntu-18.04.sha256sum | 10 +-- .../reference_elf2tab_macos-10.15.txt | 68 ++++++++++++------- .../reference_elf2tab_ubuntu-18.04.txt | 68 ++++++++++++------- 4 files changed, 98 insertions(+), 58 deletions(-) diff --git a/reproducible/reference_binaries_macos-10.15.sha256sum b/reproducible/reference_binaries_macos-10.15.sha256sum index 15e210d..8bb017f 100644 --- a/reproducible/reference_binaries_macos-10.15.sha256sum +++ b/reproducible/reference_binaries_macos-10.15.sha256sum @@ -1,9 +1,9 @@ 91a98f475cb3042dd5184598a8292edb2a414df8d967a35c8f2295826b5a161b third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -7cc5c802e22e73c1edfd5b890642c5f6c4a1f888b61f0cd6d638a770eb0af739 target/nrf52840dk_merged.hex +fd7febdc4497c59d3adeeba572effbd20d95cb7e58dc29619306f002c919495f target/nrf52840dk_merged.hex a5943c5311158b0f99370246d37782eb9b12fc36c56387eadb6587a3a4fe8fd5 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -9ff31263bd33e92b5f1f59d83f557046cb4d022919a5082931a197a2f6ec4398 target/nrf52840_dongle_merged.hex +4f4a5428fb06548ad2cf16f050bde37c9af5fac4629141455064fdb7f96dfbd9 target/nrf52840_dongle_merged.hex 663297e3e29b9e2a972b68cea1592aaf965d797242579bb5bca09cd73cdfb637 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -4b1f17b3dda2460fe83adc157f8ae1fb2559fb151b8897806e7b0aa25c898ec1 target/nrf52840_dongle_dfu_merged.hex +4367026ef48c8109f0635d5e635ec5999f0a1f2e0af9c5f35e51969ebd3fd3c0 target/nrf52840_dongle_dfu_merged.hex 162a05d056aafc16d4868d5c3aa10518e41299dddd60608f96954dc9cf964cd3 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -90369c2f5c1b3b3a443114be069fd2da0806444865830a7e992ed52e036c5a39 target/nrf52840_mdk_dfu_merged.hex -299201ff87cd84bd767516143b4e6a54759e01fcd864c0e579c62217b21d4fa4 target/tab/ctap2.tab +009f4e60074ad1dc6d0aacbeb7e78fa7b6de9e39fa79a6aaad33105389f8ed02 target/nrf52840_mdk_dfu_merged.hex +09b7ff9a4d44cd675c4ee581d43713addb5f3931ea9e7c8d71d448e0539f7070 target/tab/ctap2.tab diff --git a/reproducible/reference_binaries_ubuntu-18.04.sha256sum b/reproducible/reference_binaries_ubuntu-18.04.sha256sum index a752d4b..cae795d 100644 --- a/reproducible/reference_binaries_ubuntu-18.04.sha256sum +++ b/reproducible/reference_binaries_ubuntu-18.04.sha256sum @@ -1,9 +1,9 @@ 3feb5d29a3d669107b460a00391440be4ebc5e50461f9ef3248714f4f99c070e third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -875fdc2bbd473a5c77c119ba860e54a43f8097c20931cc5ae83a26e9311ce124 target/nrf52840dk_merged.hex +b0711a92223dfd2b3801caf38b2f004a4e18fa2dbd1ca8d5ec60b7b7b0720a8e target/nrf52840dk_merged.hex 8eebe1c1dfe22003466c2570b3735c54c58ae91b8168582ad363ab79c9230a15 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -70c1249370144c6ca55ad490dc5e418f9c2994c2649941dec41d769963a0e0ad target/nrf52840_dongle_merged.hex +2af04acdc8705f9a06535dee1fdbedc6e39d1e59e88ced9acc2fd3e2b585c29b target/nrf52840_dongle_merged.hex 779d77071d1e629f92210ac313e230bcaea6d77c710210c1ac4b40f8085cdad7 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -6c12edd4ec4d952619e976e635df39235d821eec9902e8882563fc43a1690ddb target/nrf52840_dongle_dfu_merged.hex +0b9591842b56e5c9a1c4a9160681d023a11135593373c483f383c39142be9a8f target/nrf52840_dongle_dfu_merged.hex f466490d6498f6c06c7c4a717eb437ba2fb06d1985532c23f145d38b9daa8259 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -7b67e726071ac5161344212821b9869c8f289559c8b91a5f2a0f17624855ce8a target/nrf52840_mdk_dfu_merged.hex -4dd8753dba382bdbadd0c9761949f7bdacbd77408cfc8dc466107a81ff664b15 target/tab/ctap2.tab +43393a780ed9fe89cfb000a153a6e8af3735e75c5ccc0b34795381a4914973e2 target/nrf52840_mdk_dfu_merged.hex +0fe175c3cf5a77a9f6df8f5aa3f82715986536e2f737aee44cb680a1e801dac4 target/tab/ctap2.tab diff --git a/reproducible/reference_elf2tab_macos-10.15.txt b/reproducible/reference_elf2tab_macos-10.15.txt index 25d9573..cdc178c 100644 --- a/reproducible/reference_elf2tab_macos-10.15.txt +++ b/reproducible/reference_elf2tab_macos-10.15.txt @@ -1,76 +1,96 @@ ======================================== Board: nrf52840dk ---------------------------------------- -Min RAM size from sections in ELF: 20 bytes +Creating "target/tab/thumbv7em-none-eabi.tbf" +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178688 (0x2ba00) bytes. - Adding .stack section. Offset: 178816 (0x2ba80). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 186112 (0x2d700) bytes. + Adding .stack section. Offset: 186240 (0x2d780). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_dongle ---------------------------------------- -Min RAM size from sections in ELF: 20 bytes +Creating "target/tab/thumbv7em-none-eabi.tbf" +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178688 (0x2ba00) bytes. - Adding .stack section. Offset: 178816 (0x2ba80). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 186112 (0x2d700) bytes. + Adding .stack section. Offset: 186240 (0x2d780). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_dongle_dfu ---------------------------------------- -Min RAM size from sections in ELF: 20 bytes +Creating "target/tab/thumbv7em-none-eabi.tbf" +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178688 (0x2ba00) bytes. - Adding .stack section. Offset: 178816 (0x2ba80). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 186112 (0x2d700) bytes. + Adding .stack section. Offset: 186240 (0x2d780). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_mdk_dfu ---------------------------------------- -Min RAM size from sections in ELF: 20 bytes +Creating "target/tab/thumbv7em-none-eabi.tbf" +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178688 (0x2ba00) bytes. - Adding .stack section. Offset: 178816 (0x2ba80). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 186112 (0x2d700) bytes. + Adding .stack section. Offset: 186240 (0x2d780). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + diff --git a/reproducible/reference_elf2tab_ubuntu-18.04.txt b/reproducible/reference_elf2tab_ubuntu-18.04.txt index b652638..b0c067f 100644 --- a/reproducible/reference_elf2tab_ubuntu-18.04.txt +++ b/reproducible/reference_elf2tab_ubuntu-18.04.txt @@ -1,76 +1,96 @@ ======================================== Board: nrf52840dk ---------------------------------------- -Min RAM size from sections in ELF: 20 bytes +Creating "target/tab/thumbv7em-none-eabi.tbf" +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178536 (0x2b968) bytes. - Adding .stack section. Offset: 178664 (0x2b9e8). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 186080 (0x2d6e0) bytes. + Adding .stack section. Offset: 186208 (0x2d760). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_dongle ---------------------------------------- -Min RAM size from sections in ELF: 20 bytes +Creating "target/tab/thumbv7em-none-eabi.tbf" +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178536 (0x2b968) bytes. - Adding .stack section. Offset: 178664 (0x2b9e8). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 186080 (0x2d6e0) bytes. + Adding .stack section. Offset: 186208 (0x2d760). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_dongle_dfu ---------------------------------------- -Min RAM size from sections in ELF: 20 bytes +Creating "target/tab/thumbv7em-none-eabi.tbf" +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178536 (0x2b968) bytes. - Adding .stack section. Offset: 178664 (0x2b9e8). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 186080 (0x2d6e0) bytes. + Adding .stack section. Offset: 186208 (0x2d760). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + ======================================== Board: nrf52840_mdk_dfu ---------------------------------------- -Min RAM size from sections in ELF: 20 bytes +Creating "target/tab/thumbv7em-none-eabi.tbf" +Min RAM size from segments in ELF: 20 bytes Number of writeable flash regions: 0 Adding .crt0_header section. Offset: 64 (0x40). Length: 64 (0x40) bytes. Entry point is in .text section - Adding .text section. Offset: 128 (0x80). Length: 178536 (0x2b968) bytes. - Adding .stack section. Offset: 178664 (0x2b9e8). Length: 16384 (0x4000) bytes. + Adding .text section. Offset: 128 (0x80). Length: 186080 (0x2d6e0) bytes. + Adding .stack section. Offset: 186208 (0x2d760). Length: 16384 (0x4000) bytes. Searching for .rel.X sections to add. TBF Header: version: 2 0x2 - header_size: 44 0x2C + header_size: 56 0x38 total_size: 262144 0x40000 flags: 1 0x1 - init_fn_offset: 85 0x55 - protected_size: 20 0x14 + init_fn_offset: 73 0x49 + protected_size: 8 0x8 minimum_ram_size: 107428 0x1A3A4 + + start_process_ram: 4294967295 0xFFFFFFFF + start_process_flash: 262208 0x40040 + From a3b9724165a3ea76cfc00a39cf69f4632baaf7ff Mon Sep 17 00:00:00 2001 From: Guillaume Endignoux Date: Tue, 22 Sep 2020 16:33:52 +0200 Subject: [PATCH 14/15] Add console_test example to stress-test Tock's console driver. --- deploy.py | 7 +++++ examples/console_test.rs | 33 ++++++++++++++++++++++ third_party/libtock-drivers/src/console.rs | 14 +++++---- 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 examples/console_test.rs diff --git a/deploy.py b/deploy.py index 421ead0..2109a20 100755 --- a/deploy.py +++ b/deploy.py @@ -913,6 +913,13 @@ if __name__ == "__main__": const="oom_test", help=("Compiles and installs the oom_test example that tests the " "allocator until an out-of-memory error occurs.")) + apps_group.add_argument( + "--console_test", + dest="application", + action="store_const", + const="console_test", + help=("Compiles and installs the console_test example that tests the " + "console driver with messages of various lengths.")) main_parser.set_defaults(features=["with_ctap1"]) diff --git a/examples/console_test.rs b/examples/console_test.rs new file mode 100644 index 0000000..0bdd307 --- /dev/null +++ b/examples/console_test.rs @@ -0,0 +1,33 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#![no_std] + +extern crate lang_items; + +use libtock_drivers::console::{Console, BUFFER_SIZE}; + +fn main() { + // Write messages of length up to the console driver's buffer size. + let mut buf = [0; BUFFER_SIZE]; + loop { + for i in 1..buf.len() { + for j in 0..i { + buf[j] = b'0' + ((i % 10) as u8); + } + buf[i] = b'\n'; + Console::write_unbuffered(&mut buf[..(i + 1)]); + } + } +} diff --git a/third_party/libtock-drivers/src/console.rs b/third_party/libtock-drivers/src/console.rs index 3c93803..4784a42 100644 --- a/third_party/libtock-drivers/src/console.rs +++ b/third_party/libtock-drivers/src/console.rs @@ -17,7 +17,7 @@ mod allow_nr { pub const SHARE_BUFFER: usize = 1; } -const BUFFER_SIZE: usize = 1024; +pub const BUFFER_SIZE: usize = 1024; pub struct Console { allow_buffer: [u8; BUFFER_SIZE], @@ -70,11 +70,13 @@ impl Console { // Clear the buffer even in case of error, to avoid an infinite loop. self.count_pending = 0; - let result = syscalls::allow( - DRIVER_NUMBER, - allow_nr::SHARE_BUFFER, - &mut self.allow_buffer[..count], - ); + Console::write_unbuffered(&mut self.allow_buffer[..count]); + } + + pub fn write_unbuffered(buf: &mut [u8]) { + let count = buf.len(); + + let result = syscalls::allow(DRIVER_NUMBER, allow_nr::SHARE_BUFFER, buf); if result.is_err() { return; } From 8ff1c02b9a97f9508e434467a8c4efbe7cf4166e Mon Sep 17 00:00:00 2001 From: Jean-Michel Picod Date: Tue, 22 Sep 2020 17:24:17 +0200 Subject: [PATCH 15/15] Update reproducible hashes --- .../reference_binaries_macos-10.15.sha256sum | 18 +++++++++--------- .../reference_binaries_ubuntu-18.04.sha256sum | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/reproducible/reference_binaries_macos-10.15.sha256sum b/reproducible/reference_binaries_macos-10.15.sha256sum index cb48486..ce57eb9 100644 --- a/reproducible/reference_binaries_macos-10.15.sha256sum +++ b/reproducible/reference_binaries_macos-10.15.sha256sum @@ -1,9 +1,9 @@ -91a98f475cb3042dd5184598a8292edb2a414df8d967a35c8f2295826b5a161b third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -fd7febdc4497c59d3adeeba572effbd20d95cb7e58dc29619306f002c919495f target/nrf52840dk_merged.hex -a5943c5311158b0f99370246d37782eb9b12fc36c56387eadb6587a3a4fe8fd5 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -4f4a5428fb06548ad2cf16f050bde37c9af5fac4629141455064fdb7f96dfbd9 target/nrf52840_dongle_merged.hex -663297e3e29b9e2a972b68cea1592aaf965d797242579bb5bca09cd73cdfb637 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -4367026ef48c8109f0635d5e635ec5999f0a1f2e0af9c5f35e51969ebd3fd3c0 target/nrf52840_dongle_dfu_merged.hex -162a05d056aafc16d4868d5c3aa10518e41299dddd60608f96954dc9cf964cd3 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -009f4e60074ad1dc6d0aacbeb7e78fa7b6de9e39fa79a6aaad33105389f8ed02 target/nrf52840_mdk_dfu_merged.hex -09b7ff9a4d44cd675c4ee581d43713addb5f3931ea9e7c8d71d448e0539f7070 target/tab/ctap2.tab \ No newline at end of file +c242b0237b93328eea0213411916f84e3ce631c3eea3bf56d6769ae5aa0b8d06 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin +9fca5250e6730276bc361661994495c9c9c707fb46d61cee75410bef5549dd62 target/nrf52840dk_merged.hex +259a54fae11cb8f1306051354825d19223ba4c33f3adfdb2d3e9d9efc7229302 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin +6d4b85a31b8f16962478f6cb72ccec94bbed4f6e955484dc8e73405d8fcd27ea target/nrf52840_dongle_merged.hex +49d647374a1448c9c3107758b6e0a1cabdf008c3e53524a3b047a16c27b8af29 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin +bf2407823be0550c7d606d97e240d3dc8b2572225f2f55383f903bbf58c4f26a target/nrf52840_dongle_dfu_merged.hex +06a38a0d6d356145467a73c765e28a945878f663664016f888393207097bfe10 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin +1dbc1c8aacfc2e996e8b318b0ef8f64db385e1b887f092ed6cff4d5425542836 target/nrf52840_mdk_dfu_merged.hex +09b7ff9a4d44cd675c4ee581d43713addb5f3931ea9e7c8d71d448e0539f7070 target/tab/ctap2.tab diff --git a/reproducible/reference_binaries_ubuntu-18.04.sha256sum b/reproducible/reference_binaries_ubuntu-18.04.sha256sum index cae795d..0840999 100644 --- a/reproducible/reference_binaries_ubuntu-18.04.sha256sum +++ b/reproducible/reference_binaries_ubuntu-18.04.sha256sum @@ -1,9 +1,9 @@ -3feb5d29a3d669107b460a00391440be4ebc5e50461f9ef3248714f4f99c070e third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin -b0711a92223dfd2b3801caf38b2f004a4e18fa2dbd1ca8d5ec60b7b7b0720a8e target/nrf52840dk_merged.hex -8eebe1c1dfe22003466c2570b3735c54c58ae91b8168582ad363ab79c9230a15 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin -2af04acdc8705f9a06535dee1fdbedc6e39d1e59e88ced9acc2fd3e2b585c29b target/nrf52840_dongle_merged.hex -779d77071d1e629f92210ac313e230bcaea6d77c710210c1ac4b40f8085cdad7 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin -0b9591842b56e5c9a1c4a9160681d023a11135593373c483f383c39142be9a8f target/nrf52840_dongle_dfu_merged.hex -f466490d6498f6c06c7c4a717eb437ba2fb06d1985532c23f145d38b9daa8259 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin -43393a780ed9fe89cfb000a153a6e8af3735e75c5ccc0b34795381a4914973e2 target/nrf52840_mdk_dfu_merged.hex +dab66677002854f6abfb1745d24d1c9e4e93c9bba286b14024e42cb8f2b99b9a third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin +316b393bd4b18fd154e9203b15f6abb5d27a3ac2c98f19c95b80033091aeccb6 target/nrf52840dk_merged.hex +70cf9f6c1d6b2149c1ca88664073a92e092215faaf551310f8bfd8e171d3d3a1 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin +a03a6b5239703c38c0eee7e76ab7b1b8a3813abdd7d84f51c495b8889d4b9605 target/nrf52840_dongle_merged.hex +f550b6493c8cd401d191306510de50ddd6d4c709dcf90ea1bd3a9f1bcffd11b5 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin +249ed37202b5ce102ae4c112358e4f4bcd275a19ac6dea2c474920342bcf6e79 target/nrf52840_dongle_dfu_merged.hex +1baaf518a74c6077cb936d9cf178b6dd0232e7562fa56174886b05b77886cc32 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin +93e23a8e9964bf22794c2f453738af68ae348456fdd898cddfe8e2b3ada8bf79 target/nrf52840_mdk_dfu_merged.hex 0fe175c3cf5a77a9f6df8f5aa3f82715986536e2f737aee44cb680a1e801dac4 target/tab/ctap2.tab