diff --git a/loader/src/secboot.rs b/loader/src/secboot.rs index 68ca8380e..f910e5ae1 100755 --- a/loader/src/secboot.rs +++ b/loader/src/secboot.rs @@ -2,7 +2,9 @@ use crate::println; pub const SIGBLOCK_SIZE: usize = 0x1000; -const VERSION_STR: &'static str = "Xous OS Loader v0.9.0\n\r"; +const VERSION_STR: &'static str = "Xous OS Loader v0.9.1\n\r"; +// v0.9.0 -- initial version +// v0.9.1 -- booting with hw acceleration, and "simplest signature" check on the entire xous.img blob pub const STACK_LEN: u32 = 8192 - (7 * 4); // 7 words for backup kernel args pub const STACK_TOP: u32 = 0x4100_0000 - STACK_LEN; @@ -243,6 +245,11 @@ impl Keyrom { // returns true if the kernel is valid // side-effects the "devboot" register in the gfx engine if devkeys were detected pub fn validate_xous_img(xous_img_offset: *const u32) -> bool { + // reset the SHA block, in case we're coming out of a warm reset + let mut sha = CSR::new(utra::sha512::HW_SHA512_BASE as *mut u32); + sha.wfo(utra::sha512::POWER_ON, 1); + sha.wfo(utra::sha512::CONFIG_RESET, 1); // this reset takes ~32 CPU cycles before we can use the SHA block. not a problem. + // conjure the signature struct directly out of memory. super unsafe. let sig_ptr = xous_img_offset as *const SignatureInFlash; let sig: &SignatureInFlash = unsafe{sig_ptr.as_ref().unwrap()}; @@ -255,13 +262,10 @@ pub fn validate_xous_img(xous_img_offset: *const u32) -> bool { }; gfx.init(100_000_000); - // extract the second half of the frame buffer with .chunks_mut(len()/2).skip(1).next().unwrap() - // then iterate through each word, along with an index .iter_mut().enumerate() - // then insert a pattern of alternating 0101/1010 to create a "gray effect" on the bottom half of the fb + // insert a pattern of alternating 0101/1010 to create a "gray effect" on the bottom half of the fb // note that the gray has "stripes" every 32 bits but it's visually easier to look at than stripes every other bit - for (i, word) in - gfx.fb.chunks_mut(gfx.fb.len() / 2).skip(1).next().unwrap() - .iter_mut().enumerate() { + let (_top, bottom) = gfx.fb.split_at_mut(gfx.fb.len() / 2); + for (i, word) in bottom.iter_mut().enumerate() { if i % 2 == 0 { *word = 0xAAAA_AAAA; } else { diff --git a/precursors/soc.svd b/precursors/soc.svd index 6f4d2a7ca..11bd3f218 100755 --- a/precursors/soc.svd +++ b/precursors/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -433,11 +433,27 @@ configure as output for the value to appear on the pin]]> + + USBDISABLE + + 0x001c + 0x00 + 32 + + + usbdisable + 0 + [0:0] + 0 + + + EV_STATUS - 0x001c + 0x0020 0x00 32 @@ -503,7 +519,7 @@ Writes to this register have no effect.]]> EV_PENDING - 0x0020 + 0x0024 0x00 32 @@ -577,7 +593,7 @@ edge.]]> EV_ENABLE - 0x0024 + 0x0028 0x00 32 @@ -642,7 +658,7 @@ register to disable individual events.]]> 0 - 0x28 + 0x2c registers @@ -1222,10 +1238,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x9e37625a + 0xab8658b6 32 @@ -1242,7 +1258,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x3b + 0x3e 32 @@ -3485,7 +3501,7 @@ inject too fast.]]> SEED1 0x0000 - 0x55bba5d1 + 0x2b72d267 32 @@ -3500,7 +3516,7 @@ inject too fast.]]> SEED0 0x0004 - 0x15927727 + 0x2d8ab78 32 @@ -5865,6 +5881,13 @@ savings)]]> 3 + + reset + 4 + [4:4] + 4 + + @@ -6259,52 +6282,59 @@ in bits]]> 32 - read_count - 8 - [8:0] + reset_status + 0 + [0:0] 0 + + + + read_count + 9 + [9:1] + 1 write_count - 17 - [17:9] - 9 + 18 + [18:10] + 10 read_error - 18 - [18:18] - 18 + 19 + [19:19] + 19 write_error - 19 - [19:19] - 19 + 20 + [20:20] + 20 almost_full - 20 - [20:20] - 20 + 21 + [21:21] + 21 almost_empty - 21 - [21:21] - 21 + 22 + [22:22] + 22 running - 22 - [22:22] - 22 + 23 + [23:23] + 23 @@ -6964,7 +6994,7 @@ of the PLL]]> SHA512 0xE0002000 - 0x00000008 + 0x00000004 ENGINE diff --git a/precursors/soc_csr.bin b/precursors/soc_csr.bin index cd6673b4d..4e0850056 100755 Binary files a/precursors/soc_csr.bin and b/precursors/soc_csr.bin differ diff --git a/services/engine-sha512/src/main.rs b/services/engine-sha512/src/main.rs index dfc4c32d1..3eea2b0ae 100644 --- a/services/engine-sha512/src/main.rs +++ b/services/engine-sha512/src/main.rs @@ -65,7 +65,7 @@ mod implementation { .expect("couldn't map Engine512 CSR range"); #[cfg(not(feature = "event_wait"))] - let engine512 = Engine512 { + let mut engine512 = Engine512 { csr: CSR::new(csr.as_mut_ptr() as *mut u32), fifo, }; @@ -87,6 +87,13 @@ mod implementation { // instead, we rely on every usage of this mechanism to explicitly set this enable bit before relying upon it engine512.csr.wfo(utra::sha512::EV_ENABLE_SHA512_DONE, 1); } + // reset the block on boot + // we don't save this as part of the susres set because + // on a "proper" resume, the block was already reset by the secure boot process + // the code path where this really becomes necessary is if we have a WDT reset or + // some sort of server-restart. + engine512.csr.wfo(utra::sha512::CONFIG_RESET, 1); // takes ~32 cycles to complete + engine512 } @@ -206,33 +213,10 @@ mod implementation { pub(crate) fn reset(&mut self) { self.csr.wfo(utra::sha512::POWER_ON, 1); - if self.csr.rf(utra::sha512::FIFO_RUNNING) != 0 { - // if it's running, call digest, then reset - let sha = self.fifo.as_mut_ptr() as *mut u32; - unsafe { sha.write_volatile(0x0); } // stuff a dummy byte, in case the hash was empty - #[cfg(feature = "event_wait")] - { - engine512.csr.wfo(utra::sha512::EV_ENABLE_SHA512_DONE, 1); - self.done = false; - self.csr.wfo(utra::sha512::COMMAND_HASH_PROCESS, 1); - while !self.done { - log::trace!("waiting for sha512_done (reset)"); - xous::wait_event(); - } - log::trace!("moving on (reset)"); - } - #[cfg(not(feature = "event_wait"))] - { - self.csr.wfo(utra::sha512::COMMAND_HASH_PROCESS, 1); - while self.csr.rf(utra::sha512::EV_PENDING_SHA512_DONE) == 0 { - xous::yield_slice(); - } - } - } else { - // engine is already stopped, just clear the pending bits and reset the config - } + self.csr.wfo(utra::sha512::CONFIG_RESET, 1); self.csr.wfo(utra::sha512::EV_PENDING_SHA512_DONE, 1); self.csr.wo(utra::sha512::CONFIG, 0); // clear all config bits, including EN, which resets the unit + while self.csr.rf(utra::sha512::FIFO_RESET_STATUS) == 1 { } // wait for the reset block to finish, if it's not already done by now self.csr.wfo(utra::sha512::POWER_ON, 0); } diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index c64a48c7e..86923992b 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -206,6 +206,7 @@ mod implementation { xl.gpio_susres.push_fixed_value(RegOrField::Reg(utra::gpio::EV_PENDING), 0xFFFF_FFFF); xl.gpio_susres.push(RegOrField::Reg(utra::gpio::EV_ENABLE), None); xl.gpio_susres.push(RegOrField::Field(utra::gpio::UARTSEL_UARTSEL), None); + xl.gpio_susres.push(RegOrField::Reg(utra::gpio::USBDISABLE), None); xl.event_susres.push_fixed_value(RegOrField::Reg(utra::btevents::EV_PENDING), 0xFFFF_FFFF); xl.event_susres.push(RegOrField::Reg(utra::btevents::EV_ENABLE), None); @@ -446,6 +447,20 @@ mod implementation { let value = if ena {1} else {0}; self.power_csr.rmwf(utra::power::EV_PENDING_USB_ATTACH, value); } + pub fn get_usb_disable(&self) -> bool { + if self.gpio_csr.rf(utra::gpio::USBDISABLE_USBDISABLE) != 0 { + true + } else { + false + } + } + pub fn set_usb_disable(&mut self, state: bool) { + if state { + self.gpio_csr.wfo(utra::gpio::USBDISABLE_USBDISABLE, 1); + } else { + self.gpio_csr.wfo(utra::gpio::USBDISABLE_USBDISABLE, 0); + } + } } } @@ -538,6 +553,13 @@ mod implementation { } pub fn wfi_override(&mut self, _override_: bool) { } + + pub fn get_usb_disable(&self) -> bool { + false + } + pub fn set_usb_disable(&mut self, _state: bool) { + } + } } @@ -861,15 +883,23 @@ fn xmain() -> ! { log::debug!("activity/period: {}/{}, {:.2}%", latest_activity, period, (latest_activity as f32 / period as f32) * 100.0); xous::return_scalar2(msg.sender, latest_activity as usize, period as usize).expect("couldn't return activity"); }), - Some(Opcode::DebugUsbOp) => msg_blocking_scalar_unpack!(msg, update_req, _new_state, _, _, { + Some(Opcode::DebugUsbOp) => msg_blocking_scalar_unpack!(msg, update_req, new_state, _, _, { if update_req != 0 { - // do something with new_state: this has yet to be implemented - // if new_state is true, then try to lock the USB port + // if new_state is true (not 0), then try to lock the USB port // if false, try to unlock the USB port + if new_state != 0 { + llio.set_usb_disable(true); + } else { + llio.set_usb_disable(false); + } } // at this point, *read back* the new state -- don't assume it "took". The readback is always based on // a real hardware value and not the requested value. for now, always false. - let is_locked = 0; // for now, always 0 + let is_locked = if llio.get_usb_disable() { + 1 + } else { + 0 + }; // this is a performance optimization. we could always redraw the status, but, instead we only redraw when // the status has changed. However, there is an edge case: on a resume from suspend, the status needs a redraw, diff --git a/services/shellchat/src/cmds.rs b/services/shellchat/src/cmds.rs index dbed16db6..cb3cf261d 100644 --- a/services/shellchat/src/cmds.rs +++ b/services/shellchat/src/cmds.rs @@ -96,6 +96,7 @@ mod trng_cmd; use trng_cmd::*; mod engine; use engine::*; mod console; use console::*; mod memtest; use memtest::*; +mod keys; use keys::*; //mod fcc; use fcc::*; //mod pds; // dependency of the FCC file @@ -119,6 +120,7 @@ pub struct CmdEnv { trng_cmd: TrngCmd, engine_cmd: Engine, memtest_cmd: Memtest, + keys_cmd: Keys, //fcc_cmd: Fcc, } @@ -169,6 +171,7 @@ impl CmdEnv { trng_cmd: TrngCmd::new(), engine_cmd: engine, memtest_cmd: memtest, + keys_cmd: Keys::new(), //fcc_cmd: fcc, } @@ -203,6 +206,7 @@ impl CmdEnv { &mut self.engine_cmd, &mut console_cmd, &mut self.memtest_cmd, + &mut self.keys_cmd, //&mut self.fcc_cmd, ]; diff --git a/services/shellchat/src/cmds/test.rs b/services/shellchat/src/cmds/test.rs index 8bbf4d6a5..f6b7de7fb 100644 --- a/services/shellchat/src/cmds/test.rs +++ b/services/shellchat/src/cmds/test.rs @@ -32,6 +32,7 @@ impl<'a> ShellCmdApi<'a> for Test { write!(ret, "devboot on").unwrap(); } "devbootoff" => { + // this should do nothing if devboot was already set env.gam.set_devboot(false).unwrap(); write!(ret, "devboot off").unwrap(); } diff --git a/tools/README_UPDATE.md b/tools/README_UPDATE.md index f8adee15f..f5e91ba29 100644 --- a/tools/README_UPDATE.md +++ b/tools/README_UPDATE.md @@ -58,8 +58,8 @@ The updater encodes the offsets of every binary location in the script. When the then the updater script should no longer be used for a given Precursor revision. ``` -usage: usb_update.py [-h] [-s [SoC gateware file]] [-l [loader file]] [-k [kernel file]] [-e [EC gateware package]] - [-w [WF200 firmware package]] [--peek ADDR] [--poke ADDR DATA] [--check-poke] [--config] +usage: usb_update.py [-h] [-s [SoC gateware file]] [-l [loader file]] [-k [kernel file]] [-e [EC gateware package]] [-w [WF200 firmware package]] [--audiotest [Test audio clip]] [--peek ADDR] [--poke ADDR DATA] [--check-poke] + [--config] [-i IMAGEFILE ADDR] [-n] [-f] [--bounce] Update/upload to a Precursor device running Xous 0.8/0.9 @@ -75,10 +75,17 @@ optional arguments: EC gateware -w [WF200 firmware package], --wf200 [WF200 firmware package] WF200 firmware + --audiotest [Test audio clip] + Test audio clip (must be 8kHz WAV) --peek ADDR Inspect an address --poke ADDR DATA Write to an address --check-poke Read data before and after the poke --config Print the descriptor + -i IMAGEFILE ADDR, --image IMAGEFILE ADDR + Manually specify an image and address. Offset is relative to bottom of flash. + -n, --no-verify Skip readback verification (may be necessary for large files to avoid WDT timeout). Only honored with -i. + -f, --force Ignore gitrev version on SoC and try to burn an image anyways + --bounce cycle the device through a reset ``` You can try reading the first word out of the ROM to see if `usb_update.py` is working correctly. diff --git a/tools/usb_update.py b/tools/usb_update.py index 5de361609..3e528adc9 100755 --- a/tools/usb_update.py +++ b/tools/usb_update.py @@ -382,6 +382,9 @@ def main(): parser.add_argument( "-f", "--force", help="Ignore gitrev version on SoC and try to burn an image anyways", action="store_true" ) + parser.add_argument( + "--bounce", help="cycle the device through a reset", action="store_true" + ) args = parser.parse_args() if not len(sys.argv) > 1: