From 295bbd960223d7da679b8ea5ea1f6df7b6c2de99 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 29 Oct 2021 18:46:59 +0800 Subject: [PATCH 1/6] change windows script from BAT to PS1 --- buildpush.bat | 17 ----------------- buildpush.ps1 | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 17 deletions(-) delete mode 100644 buildpush.bat create mode 100644 buildpush.ps1 diff --git a/buildpush.bat b/buildpush.bat deleted file mode 100644 index 7dd4bdd62..000000000 --- a/buildpush.bat +++ /dev/null @@ -1,17 +0,0 @@ -REM a crappy starter script to help with builds under Windows environments. ymmv. - -cargo xtask hw-image precursors/soc.svd -REM cargo xtask minimal precursors/soc.svd - -CertUtil -hashfile precursors/bbram-test1.nky MD5 -CertUtil -hashfile precursors/soc_csr.bin MD5 - -CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/loader.bin MD5 -CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/xous.img MD5 -scp -i c:/users/bunnie/.ssh/id_pi target/riscv32imac-unknown-xous-elf/release/xous.img target/riscv32imac-unknown-xous-elf/release/loader.bin precursors/soc_csr.bin pi@10.0.245.90:code/precursors/ - -REM CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/loader.bin MD5 -REM CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/xous.img MD5 -REM scp -i c:/users/bunnie/.ssh/id_pi target/riscv32imac-unknown-none-elf/release/xous.img target/riscv32imac-unknown-none-elf/release/loader.bin precursors/soc_csr.bin precursors/bbram-test1.nky pi@10.0.245.90:code/precursors/ - -REM wishbone-tool --load-name target/riscv32imac-unknown-none-elf/release/xous.img --load-address 0x980000 --load-flash diff --git a/buildpush.ps1 b/buildpush.ps1 new file mode 100644 index 000000000..eca0a0dc4 --- /dev/null +++ b/buildpush.ps1 @@ -0,0 +1,20 @@ +# a crappy starter script to help with builds under Windows environments. ymmv. + +# set RUSTFLAGS=--remap-path-prefix=F:\largework\rust-win\code\xous-core\=build +# $env:RUSTFLAGS="--remap-path-prefix=$(Get-Location)=build" + +cargo xtask hw-image precursors/soc.svd +# cargo xtask minimal precursors/soc.svd + +CertUtil -hashfile precursors/bbram-test1.nky MD5 +CertUtil -hashfile precursors/soc_csr.bin MD5 + +CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/loader.bin MD5 +CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/xous.img MD5 +scp -i c:/users/bunnie/.ssh/id_pi target/riscv32imac-unknown-xous-elf/release/xous.img target/riscv32imac-unknown-xous-elf/release/loader.bin precursors/soc_csr.bin pi@10.0.245.90:code/precursors/ + +# CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/loader.bin MD5 +# CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/xous.img MD5 +# scp -i c:/users/bunnie/.ssh/id_pi target/riscv32imac-unknown-none-elf/release/xous.img target/riscv32imac-unknown-none-elf/release/loader.bin precursors/soc_csr.bin precursors/bbram-test1.nky pi@10.0.245.90:code/precursors/ + +# wishbone-tool --load-name target/riscv32imac-unknown-none-elf/release/xous.img --load-address 0x980000 --load-flash From 65bad96f52c239338676d9a1977c773f63fde19f Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 30 Oct 2021 02:14:31 +0800 Subject: [PATCH 2/6] fix killbounce & formatting sleep killbounce wouldn't work because we started limiting the number of connections to the LLIO. This change makes connections to the LLIO unlimited, but perhaps later on we should split out the I2C bus into a separate security domain, so that the LLIO's unlimited connection policy doesn't introduce a risk into a rogue process being able to overwrite the RTC contents. --- services/llio/src/main.rs | 8 ++++++-- services/shellchat/src/cmds/sleep.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index e785d561b..bb3024133 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -696,13 +696,17 @@ fn xmain() -> ! { // - rootkeys (for reboots) // - oqc-test (for testing the vibe motor) // - net (for COM interrupt dispatch) + // - problem: `sleep killbounce` allocates a connection. That would bring us to 10 normally, but 11 when that function is needed. + // for now we're going to leave the total server count as "None" (open-ended) but we probably want to rethink this as + // the I2C access is in this crate. Perhaps we should split I2C out, so that the RTC can be protected and not grouped + // into the same severe security restrictions as the other LLIO items? let num_conns = 10; - let llio_sid = xns.register_name(api::SERVER_NAME_LLIO, Some(num_conns)).expect("can't register server"); + let llio_sid = xns.register_name(api::SERVER_NAME_LLIO, None).expect("can't register server"); log::trace!("registered with NS -- {:?}", llio_sid); // create the I2C handler thread // each connection to llio also creates an i2c connection, so it has the same expectation list - let i2c_sid = xns.register_name(api::SERVER_NAME_I2C, Some(num_conns)).expect("can't register I2C thread"); + let i2c_sid = xns.register_name(api::SERVER_NAME_I2C, None).expect("can't register I2C thread"); log::trace!("registered I2C thread with NS -- {:?}", i2c_sid); let (sid0, sid1, sid2, sid3) = i2c_sid.to_u32(); xous::create_thread_4(i2c_thread, sid0 as usize, sid1 as usize, sid2 as usize, sid3 as usize).expect("couldn't start I2C handler thread"); diff --git a/services/shellchat/src/cmds/sleep.rs b/services/shellchat/src/cmds/sleep.rs index bf0089e95..7dd96b2be 100644 --- a/services/shellchat/src/cmds/sleep.rs +++ b/services/shellchat/src/cmds/sleep.rs @@ -35,7 +35,7 @@ fn kill_thread(bounce: usize) { llio.self_destruct(0x2718_2818).unwrap(); llio.self_destruct(0x3141_5926).unwrap(); com.power_off_soc().unwrap(); - ticktimer.sleep_ms(100).unwrap(); + ticktimer.sleep_ms(1000).unwrap(); log::info!("If you can read this, we failed to destroy ourselves!"); } } From f6e91d626064addac839f8c53c08abd685bbdbfe Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 30 Oct 2021 03:12:58 +0800 Subject: [PATCH 3/6] move the trng test bases to make space for more kernel --- services/trng/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/trng/src/main.rs b/services/trng/src/main.rs index 48217ec7b..1c960368b 100644 --- a/services/trng/src/main.rs +++ b/services/trng/src/main.rs @@ -582,7 +582,7 @@ impl Tester { pub fn new(server_csr: *mut u32) -> Tester { use utralib::generated::*; let buff_a = xous::syscall::map_memory( - xous::MemoryAddress::new(0x4080_0000), // fix this at a known physical address + xous::MemoryAddress::new(0x40B0_0000), // fix this at a known physical address None, crate::TRNG_BUFF_LEN, xous::MemoryFlags::R | xous::MemoryFlags::W, @@ -590,7 +590,7 @@ impl Tester { .expect("couldn't map TRNG comms buffer A"); let buff_b = xous::syscall::map_memory( - xous::MemoryAddress::new(0x4090_0000), // fix this at a known physical address + xous::MemoryAddress::new(0x40C0_0000), // fix this at a known physical address None, crate::TRNG_BUFF_LEN, xous::MemoryFlags::R | xous::MemoryFlags::W, From ad66460543c50c3d399f5a2825b06e51b4b038eb Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 30 Oct 2021 03:14:33 +0800 Subject: [PATCH 4/6] move the trng tester ram locations on the corresponding host-side test script --- tools/trng_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/trng_test.py b/tools/trng_test.py index f0bec4483..3387770f0 100755 --- a/tools/trng_test.py +++ b/tools/trng_test.py @@ -292,8 +292,8 @@ def main(): messible2_in = pc_usb.register('messible2_in') messible_out = pc_usb.register('messible_out') - RAM_A = 0x4080_0000 - RAM_B = 0x4090_0000 + RAM_A = 0x40B0_0000 + RAM_B = 0x40C0_0000 BURST_LEN = 512 * 1024 TIMEOUT = 30.0 From 72df2ff7e4c1f93fa9b5fb09b27d1931652b18a9 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 30 Oct 2021 03:15:53 +0800 Subject: [PATCH 5/6] commit tester stability tweaks --- tools/trng_test.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tools/trng_test.py b/tools/trng_test.py index f0bec4483..a3ae86e77 100755 --- a/tools/trng_test.py +++ b/tools/trng_test.py @@ -41,8 +41,11 @@ class PrecursorUsb: wValue=(addr & 0xffff), wIndex=((addr >> 16) & 0xffff), data_or_wLength=data, timeout=500) except Exception as e: - self.dev.reset() - time.sleep(2) + try: + self.dev.reset() + except usb.core.USBTimeoutError: + pass + time.sleep(3.0) else: break @@ -71,8 +74,11 @@ class PrecursorUsb: data_or_wLength=data, timeout=500) except Exception as e: sys.stderr.write("error; resetting device\n") - self.dev.reset() - time.sleep(2) + try: + self.dev.reset() + except usb.core.USBTimeoutError: + pass + time.sleep(3.0) else: break @@ -111,24 +117,29 @@ class PrecursorUsb: bufsize = maxlen data = array.array('B', _dummy_s * bufsize) + if self.vexdbg_addr != None: + self.poke(self.vexdbg_addr, 0x00020000) + time.sleep(0.1) for attempt in range(10): try: - if self.vexdbg_addr != None: - self.poke(self.vexdbg_addr, 0x00020000) numread = self.dev.ctrl_transfer(bmRequestType=(0x80 | 0x43), bRequest=0, wValue=(cur_addr & 0xffff), wIndex=((cur_addr >> 16) & 0xffff), - data_or_wLength=data, timeout=50000) - if self.vexdbg_addr != None: - self.poke(self.vexdbg_addr, 0x02000000) + data_or_wLength=data, timeout=60000) except Exception as e: sys.stderr.write("error; resetting device\n") - self.dev.reset() - time.sleep(2) + try: + self.dev.reset() + except: + pass + time.sleep(2.2) else: break else: sys.stderr.write("Burst read failed\n") - exit(1) + #exit(1) + if self.vexdbg_addr != None: + self.poke(self.vexdbg_addr, 0x02000000) + time.sleep(0.1) if numread != bufsize: sys.stderr.write("Burst read error: {} bytes requested, {} bytes read at 0x{:08x}\n".format(bufsize, numread, cur_addr)) @@ -313,7 +324,7 @@ def main(): pc_usb.poke(pc_usb.register('reboot_soc_reset'), 0xac, display=False) except usb.core.USBError: pass # we expect an error because we reset the SOC and that includes the USB core - time.sleep(2.0) + time.sleep(3.0) dev = usb.core.find(idProduct=0x5bf0, idVendor=0x1209) dev.set_configuration() pc_usb = PrecursorUsb(dev) From 8da2364832a52ce829ac3afa17b32c3c056be98a Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 30 Oct 2021 19:15:32 +0800 Subject: [PATCH 6/6] clean out some old debug cruft in the susres crate --- services/susres/Cargo.toml | 1 + services/susres/src/main.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/services/susres/Cargo.toml b/services/susres/Cargo.toml index fda9665a0..34c394e39 100644 --- a/services/susres/Cargo.toml +++ b/services/susres/Cargo.toml @@ -21,5 +21,6 @@ rkyv = {version = "0.4.3", default-features = false, features = ["const_generics utralib = { path = "../../utralib"} [features] +sus_reboot = [] # when selected, suspend triggers an immediate reboot instead of suspend. For testing only. debugprint = [] default = [] diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index 9754b5023..790ae6ae8 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -53,7 +53,7 @@ mod implementation { timer.wfo(utra::timer0::EV_PENDING_ZERO, 0b1); } - // this is just for testing, remove for production + #[cfg(feature = "sus_reboot")] static REBOOT_CSR: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0); // we do all the suspend/resume coordination in an interrupt context @@ -74,7 +74,8 @@ mod implementation { if sr.csr.rf(utra::susres::STATE_RESUME) == 0 { //println!("going into suspend"); - if false { // this is just for testing, doing a quick full-soc boot instead of a power down + #[cfg(feature = "sus_reboot")] + { // this is just for testing, doing a quick full-soc boot instead of a power down let mut reboot_csr = CSR::new(REBOOT_CSR.load(Ordering::Relaxed) as *mut u32); reboot_csr.wfo(utra::reboot::SOC_RESET_SOC_RESET, 0xAC); } @@ -163,6 +164,7 @@ mod implementation { xous::MemoryFlags::R | xous::MemoryFlags::W, ) .expect("couldn't map Reboot CSR range"); + #[cfg(feature = "sus_reboot")] REBOOT_CSR.store(reboot_csr.as_mut_ptr() as u32, Ordering::Relaxed); // for testing only let mut sr = SusResHw { csr: CSR::new(csr.as_mut_ptr() as *mut u32), @@ -239,6 +241,7 @@ mod implementation { } } + #[cfg(feature = "debugprint")] println!("Stopping preemption"); // stop pre-emption self.os_timer.wfo(utra::timer0::EN_EN, 0); @@ -250,6 +253,7 @@ mod implementation { // ensure that the resume bit is not set self.csr.wfo(utra::susres::STATE_RESUME, 0); + #[cfg(feature = "debugprint")] println!("Stopping ticktimer"); // stop deferred thread scheduling, by stopping the ticktimer self.csr.wfo(utra::susres::CONTROL_PAUSE, 1); @@ -261,6 +265,7 @@ mod implementation { (self.csr.r(utra::susres::TIME1) as u64) << 32) + 0 // a placeholder in case we need to advance time on save ); + #[cfg(feature = "debugprint")] println!("Stored time: {}", self.stored_time.unwrap()); // setup the clean suspend marker, note if things were forced @@ -339,18 +344,21 @@ mod implementation { index += range; } + #[cfg(feature = "debugprint")] println!("Triggering suspend interrupt"); // trigger an interrupt to process the final suspend bits self.csr.wfo(utra::susres::INTERRUPT_INTERRUPT, 1); // SHOULD_RESUME will be set true by the interrupt context when it re-enters from resume while !SHOULD_RESUME.load(Ordering::Relaxed) { + #[cfg(feature = "debugprint")] println!("Waiting for resume"); xous::yield_slice(); } } pub fn do_resume(&mut self) -> bool { // returns true if the previous suspend was forced // resume the ticktimer where it left off + #[cfg(feature = "debugprint")] println!("Trying to resume"); if let Some(time)= self.stored_time.take() { // zero out the clean-suspend marker @@ -362,6 +370,7 @@ mod implementation { // restore the ticktimer self.csr.wo(utra::susres::RESUME_TIME0, time as u32); self.csr.wo(utra::susres::RESUME_TIME1, (time >> 32) as u32); + #[cfg(feature = "debugprint")] println!("Ticktimer loaded with {}", time); // set up pre-emption timer @@ -384,6 +393,7 @@ mod implementation { log::trace!("Resume {} / control {}", self.csr.r(utra::susres::RESUME_TIME0), self.csr.r(utra::susres::CONTROL)); log::trace!("Ticktimer loaded with {} / {}", time, self.csr.r(utra::susres::TIME0)); self.csr.wo(utra::susres::CONTROL, 0); + #[cfg(feature = "debugprint")] println!("Ticktimer and OS timer now running"); } else {