diff --git a/app/oxide-rot-1/app-dev.toml b/app/oxide-rot-1/app-dev.toml index 50b1263bdd..08cd6ac5bb 100644 --- a/app/oxide-rot-1/app-dev.toml +++ b/app/oxide-rot-1/app-dev.toml @@ -79,7 +79,7 @@ name = "drv-lpc55-sprot-server" priority = 6 max-sizes = {flash = 51168, ram = 32768} uses = ["flexcomm8", "bootrom"] -features = ["spi0"] +features = ["spi0", "sp-ctrl"] start = true notifications = ["spi-irq"] interrupts = {"flexcomm8.hs_spi" = "spi-irq"} diff --git a/app/oxide-rot-1/app.toml b/app/oxide-rot-1/app.toml index 7f42aef6ae..cb595ae523 100644 --- a/app/oxide-rot-1/app.toml +++ b/app/oxide-rot-1/app.toml @@ -70,7 +70,7 @@ name = "drv-lpc55-sprot-server" priority = 6 max-sizes = {flash = 51168, ram = 32768} uses = ["flexcomm8", "bootrom"] -features = ["spi0"] +features = ["spi0", "sp-ctrl"] start = true notifications = ["spi-irq"] interrupts = {"flexcomm8.hs_spi" = "spi-irq"} diff --git a/app/rot-carrier/app.toml b/app/rot-carrier/app.toml index 20f6e6ee29..7082b0c4c2 100644 --- a/app/rot-carrier/app.toml +++ b/app/rot-carrier/app.toml @@ -115,7 +115,7 @@ start = true notifications = ["spi-irq"] interrupts = {"flexcomm8.hs_spi" = "spi-irq"} stacksize = 16384 -task-slots = ["gpio_driver", "syscon_driver", "update_server", "dumper", "attest", "swd"] +task-slots = ["gpio_driver", "syscon_driver", "update_server", "attest"] [tasks.sprot.config] pins = [ @@ -133,47 +133,6 @@ pins = [ { name = "SP_RESET", pin = { port = 0, pin = 9}, alt = 0, direction = "input"}, ] -[tasks.swd] -name = "drv-lpc55-swd" -priority = 4 -max-sizes = {flash = 16384, ram = 4096} -uses = ["flexcomm3", "iocon"] -start = true -stacksize = 1000 -notifications = ["spi-irq", "timer"] -task-slots = ["gpio_driver", "syscon_driver"] -interrupts = {"flexcomm3.irq" = "spi-irq"} - -[tasks.swd.config] -# MOSI = PIO0_3 -# MISO = PIO0_2 - -# Out = MOSI on, MISO off -out_cfg = [ - { pin = { port = 0, pin = 3 }, alt = 1 }, - { pin = { port = 0, pin = 2 }, alt = 0, mode = "PullDown" }, -] -# In = MISO on, MOSI off -in_cfg = [ - { pin = { port = 0, pin = 2 }, alt = 1 }, - { pin = { port = 0, pin = 3 }, alt = 0, mode = "PullDown" }, -] -pins = [ - # SCK - { pin = { port = 0, pin = 6 }, alt = 1 }, - # CS, not strictly necessary but handy for debugging - # { pin = {port = 0, pin = 20}, alt = 1}, -] -spi_num = 3 - -[tasks.dumper] -name = "task-dumper" -priority = 5 -max-sizes = {flash = 16384, ram = 4096} -start = true -stacksize = 2600 -task-slots = ["swd"] - [tasks.pong] name = "task-pong" priority = 7 @@ -185,21 +144,11 @@ notifications = ["timer"] [tasks.hiffy] name = "task-hiffy" priority = 6 -features = ["lpc55", "gpio", "spctrl", "spi"] +features = ["lpc55", "gpio", "spi"] max-sizes = {flash = 32768, ram = 16384 } stacksize = 2048 start = true -task-slots = ["gpio_driver", "swd", "update_server"] - -[tasks.sp_measure] -name = "task-sp-measure" -priority = 6 -max-sizes = {flash = 131072, ram = 8192} -task-slots = ["swd"] -stacksize = 2048 - -[tasks.sp_measure.config] -binary_path = "../../target/gemini-bu/dist/final.bin" +task-slots = ["gpio_driver", "update_server"] [tasks.attest] name = "task-attest" diff --git a/drv/lpc55-sprot-server/Cargo.toml b/drv/lpc55-sprot-server/Cargo.toml index e96d2d3098..0c16f0eae8 100644 --- a/drv/lpc55-sprot-server/Cargo.toml +++ b/drv/lpc55-sprot-server/Cargo.toml @@ -20,10 +20,8 @@ drv-lpc55-gpio-api = { path = "../lpc55-gpio-api" } drv-lpc55-spi = { path = "../lpc55-spi" } drv-lpc55-syscon-api = { path = "../lpc55-syscon-api" } drv-lpc55-update-api = { path = "../lpc55-update-api" } -drv-sp-ctrl-api = { path = "../sp-ctrl-api" } drv-sprot-api = { path = "../sprot-api" } drv-update-api = { path = "../update-api" } -dumper-api = { path = "../../task/dumper-api" } lpc55_romapi = { path = "../../lib/lpc55-romapi" } mutable-statics = { path = "../../lib/mutable-statics" } ringbuf = { path = "../../lib/ringbuf" } @@ -31,6 +29,9 @@ task-jefe-api = { path = "../../task/jefe-api" } userlib = { path = "../../sys/userlib" } lpc55-rom-data = { path = "../../lib/lpc55-rom-data" } +drv-sp-ctrl-api = { path = "../sp-ctrl-api", optional = true } +dumper-api = { path = "../../task/dumper-api", optional = true } + [build-dependencies] build-lpc55pins = { path = "../../build/lpc55pins" } build-util = { path = "../../build/util" } @@ -41,6 +42,7 @@ idol = { workspace = true } [features] spi0 = [] no-ipc-counters = ["idol/no-counters"] +sp-ctrl = ["drv-sp-ctrl-api", "dumper-api"] # This section is here to discourage RLS/rust-analyzer from doing test builds, # since test builds don't work for cross compilation. diff --git a/drv/lpc55-sprot-server/src/handler.rs b/drv/lpc55-sprot-server/src/handler.rs index c29e172b5c..6b86d340e7 100644 --- a/drv/lpc55-sprot-server/src/handler.rs +++ b/drv/lpc55-sprot-server/src/handler.rs @@ -6,15 +6,13 @@ use crate::Trace; use attest_api::Attest; use crc::{Crc, CRC_32_CKSUM}; use drv_lpc55_update_api::{RotPage, SlotId, Update}; -use drv_sp_ctrl_api::SpCtrl; use drv_sprot_api::{ - AttestReq, AttestRsp, CabooseReq, CabooseRsp, DumpReq, DumpRsp, ReqBody, - Request, Response, RotIoStats, RotPageRsp, RotState, RotStatus, RspBody, + AttestReq, AttestRsp, CabooseReq, CabooseRsp, DumpReq, ReqBody, Request, + Response, RotIoStats, RotPageRsp, RotState, RotStatus, RspBody, SprocketsError, SprotError, SprotProtocolError, SwdReq, UpdateReq, - UpdateRsp, WatchdogError, CURRENT_VERSION, MIN_VERSION, REQUEST_BUF_SIZE, + UpdateRsp, CURRENT_VERSION, MIN_VERSION, REQUEST_BUF_SIZE, RESPONSE_BUF_SIZE, }; -use dumper_api::Dumper; use lpc55_romapi::bootrom; use ringbuf::ringbuf_entry_root as ringbuf_entry; use sprockets_rot::RotSprocket; @@ -24,10 +22,12 @@ mod sprockets; task_slot!(UPDATE_SERVER, update_server); +#[cfg(feature = "sp-ctrl")] task_slot!(DUMPER, dumper); task_slot!(ATTEST, attest); +#[cfg(feature = "sp-ctrl")] task_slot!(SP_CTRL, swd); pub const CRC32: Crc = Crc::::new(&CRC_32_CKSUM); @@ -60,7 +60,9 @@ pub struct Handler { update: Update, startup_state: StartupState, attest: Attest, - sp_ctrl: SpCtrl, + + #[cfg(feature = "sp-ctrl")] + sp_ctrl: drv_sp_ctrl_api::SpCtrl, } impl<'a> Handler { @@ -74,7 +76,9 @@ impl<'a> Handler { max_response_size: RESPONSE_BUF_SIZE.try_into().unwrap_lite(), }, attest: Attest::from(ATTEST.get_task_id()), - sp_ctrl: SpCtrl::from(SP_CTRL.get_task_id()), + + #[cfg(feature = "sp-ctrl")] + sp_ctrl: drv_sp_ctrl_api::SpCtrl::from(SP_CTRL.get_task_id()), } } @@ -269,10 +273,24 @@ impl<'a> Handler { None, )), ReqBody::Dump(DumpReq::V1 { addr }) => { - ringbuf_entry!(Trace::Dump(addr)); - let dumper = Dumper::from(DUMPER.get_task_id()); - let err = dumper.dump(addr).err(); - Ok((RspBody::Dump(DumpRsp::V1 { err }), None)) + #[cfg(feature = "sp-ctrl")] + { + use dumper_api::Dumper; + ringbuf_entry!(Trace::Dump(addr)); + let dumper = Dumper::from(DUMPER.get_task_id()); + let err = dumper.dump(addr).err(); + Ok(( + RspBody::Dump(drv_sprot_api::DumpRsp::V1 { err }), + None, + )) + } + #[cfg(not(feature = "sp-ctrl"))] + { + let _ = addr; + Err(SprotError::Protocol( + SprotProtocolError::BadMessageType, + )) + } } ReqBody::Update(UpdateReq::GetBlockSize) => { let size = self.update.block_size()?; @@ -415,16 +433,33 @@ impl<'a> Handler { // Enabling the watchdog doesn't actually do any SWD work, but // we'll call `setup()` now to make sure that the SWD system is // working. + #[cfg(feature = "sp-ctrl")] match self.sp_ctrl.setup().and_then(|()| { self.sp_ctrl.enable_sp_slot_watchdog(time_ms) }) { Ok(()) => Ok((RspBody::Ok, None)), - Err(_e) => Err(SprotError::Watchdog(WatchdogError::SpCtrl)), + Err(_e) => Err(SprotError::Watchdog( + drv_sprot_api::WatchdogError::SpCtrl, + )), + } + + #[cfg(not(feature = "sp-ctrl"))] + { + let _ = time_ms; + Err(SprotError::Protocol( + SprotProtocolError::BadMessageType, + )) } } ReqBody::Swd(SwdReq::DisableSpSlotWatchdog) => { - self.sp_ctrl.disable_sp_slot_watchdog(); - Ok((RspBody::Ok, None)) + #[cfg(feature = "sp-ctrl")] + { + self.sp_ctrl.disable_sp_slot_watchdog(); + Ok((RspBody::Ok, None)) + } + + #[cfg(not(feature = "sp-ctrl"))] + Err(SprotError::Protocol(SprotProtocolError::BadMessageType)) } } } diff --git a/drv/lpc55-sprot-server/src/main.rs b/drv/lpc55-sprot-server/src/main.rs index 7c60463929..b25040321a 100644 --- a/drv/lpc55-sprot-server/src/main.rs +++ b/drv/lpc55-sprot-server/src/main.rs @@ -67,7 +67,6 @@ use handler::Handler; #[derive(Copy, Clone, PartialEq)] pub(crate) enum Trace { None, - Dump(u32), ReceivedBytes(usize), Flush, FlowError, @@ -76,6 +75,9 @@ pub(crate) enum Trace { Err(SprotProtocolError), Stats(RotIoStats), Desynchronized, + + #[cfg(feature = "sp-ctrl")] + Dump(u32), } ringbuf!(Trace, 32, Trace::None); diff --git a/drv/lpc55-swd/src/main.rs b/drv/lpc55-swd/src/main.rs index 77335f3fe6..f65fac92f6 100644 --- a/drv/lpc55-swd/src/main.rs +++ b/drv/lpc55-swd/src/main.rs @@ -775,18 +775,10 @@ impl ServerImpl { } fn swd_dongle_detected(&self) -> bool { - cfg_if::cfg_if! { - if #[cfg(any( - target_board = "oxide-rot-1", - ))] { - use drv_lpc55_gpio_api::*; - - let gpio = Pins::from(self.gpio); - gpio.read_val(SP_TO_ROT_JTAG_DETECT_L) == Value::Zero - } else { - false - } - } + use drv_lpc55_gpio_api::*; + + let gpio = Pins::from(self.gpio); + gpio.read_val(SP_TO_ROT_JTAG_DETECT_L) == Value::Zero } fn swd_setup(&mut self) -> Result<(), Ack> {