diff --git a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs index 6af410bb6..0db02ac8d 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs @@ -333,13 +333,6 @@ pub fn clk_to_per(top_in_mhz: u32, perclk_in_mhz: u32) -> Option<(u8, u8, u32)> } } -// This function supercedes init_clock_asic() and needs to be back-ported -// into xous-core -// TODO: -// - [ ] Case of clocks <= 48MHz: turn off PLL, divide directly from OSC -// - [ ] Derive clock dividers from freq targets, instead of hard-coding them -// - [ ] Maybe improve dividers to optimize hclk/iclk/pclk settings in lower power? -// - [ ] Very maybe consider setting hclk/iclk/pclk in case of overclocking pub unsafe fn init_clock_asic(freq_hz: u32) -> u32 { use utra::sysctrl; let daric_cgu = sysctrl::HW_SYSCTRL_BASE as *mut u32; diff --git a/bao1x-boot/boot1/src/platform/bao1x/usb/driver.rs b/bao1x-boot/boot1/src/platform/bao1x/usb/driver.rs index f9549e96c..2c6db2569 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/usb/driver.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/usb/driver.rs @@ -10,36 +10,6 @@ use super::*; pub(crate) static mut USB: Option = None; -/// Safety issue: the loader itself doesn't have a loader. So, any .data required by -/// the loader program can't be set up in advance for the loader. -/// -/// The root problem: generally, a `static mut` in the loader will cause some .data -/// to be allocated. The USB handler needs to be a `static mut` because -/// the interrupt handler needs to be able to find it at a globally known location, and -/// the data has to persist beyond the scope of a single interrupt. -/// -/// The assumption: we don't have to include the data section in the loader's ROM image -/// because 1) the data going into the `static mut` interrupt handler is assumed uninitialized -/// (due to the wrapper being an Option set to None); and 2) the RAM is fully zeroized by a -/// small assembly routine that executes before the loader runs. -/// -/// (1) means that in practice, the contents of the .data section is "almost 0". -/// (2) means we can just whack a pointer at where the -/// data section should go and the assumptions are met for the loader. -/// -/// The inconsistency: inspecting the generated binary indicates that the `None` representation -/// for USB is not `0`; it instead has the representation of `2`. This means that if we try to -/// access `USB` prior to initialization, we will get UB. -/// -/// Safe usage: init_usb() must be called before any attempt to access USB, including interrupts. -/// Furthermore, we have to manually guarantee that there are no concurrency/race conditions accessing -/// the USB structure (we are in no_std so we don't have a Mutex). Finally, we have to ensure that -/// USB is initialized with no assumptions about what is in memory prior to any access to it. -/// -/// Even then, we might have some risk of UB if the compiler decides it really wants to rely -/// on some pre-initialized structure of the `USB` static mut `None`. In practice, we haven't -/// seen this, but we run a risk of this breaking in future versions of Rust because the compiler -/// is allowed to assume that `USB` has the correct value to represent a `None` on boot. pub unsafe fn init_usb() { let mut usb = unsafe { bao1x_hal::usb::driver::CorigineUsb::new( @@ -248,20 +218,12 @@ fn handle_event(this: &mut CorigineUsb, event_trb: &mut EventTrbS) -> CrgEvent { USB_REQ_SET_ADDRESS => { crate::println_d!("USB_REQ_SET_ADDRESS: {}, tag: {}", w_value, this.setup_tag); this.set_addr(w_value as u8, CRG_INT_TARGET); - // crate::println_d!(" ******* set address done {}", w_value & 0xff); } USB_REQ_SET_SEL => { crate::println_d!("USB_REQ_SET_SEL"); this.ep0_receive(this.ep0_buf.load(Ordering::SeqCst) as usize, w_length as usize, 0); delay(100); - /* do set sel */ crate::println_d!("SEL_VALUE NOT HANDLED"); - /* - crg_udc->sel_value.u1_sel_value = *ep0_buf; - crg_udc->sel_value.u1_pel_value = *(ep0_buf+1); - crg_udc->sel_value.u2_sel_value = *(uint16_t*)(ep0_buf+2); - crg_udc->sel_value.u2_pel_value = *(uint16_t*)(ep0_buf+4); - */ } USB_REQ_SET_ISOCH_DELAY => { crate::println_d!("USB_REQ_SET_ISOCH_DELAY"); @@ -272,21 +234,11 @@ fn handle_event(this: &mut CorigineUsb, event_trb: &mut EventTrbS) -> CrgEvent { crate::println_d!("USB_REQ_CLEAR_FEATURE"); crate::println_d!("*** UNSUPPORTED (stall) ***"); this.ep_halt(0, USB_RECV); - /* do clear feature */ - // clear_feature_request(setup_pkt.b_request_type, w_index, w_value); } USB_REQ_SET_FEATURE => { crate::println_d!("USB_REQ_SET_FEATURE\r\n"); crate::println_d!("*** UNSUPPORTED (stall) ***"); this.ep_halt(0, USB_RECV); - /* do set feature */ - /* - if crg_udc_get_device_state() == USB_STATE_CONFIGURED { - set_feature_request(setup_pkt.b_request_type, w_index, w_value); - } else { - crg_udc_ep_halt(0, USB_RECV); - } - */ } USB_REQ_SET_CONFIGURATION => { let mut pass = false; diff --git a/bao1x-boot/boot1/src/platform/bao1x/usb/fat32_base.rs b/bao1x-boot/boot1/src/platform/bao1x/usb/fat32_base.rs index 7feaf200c..5349fe509 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/usb/fat32_base.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/usb/fat32_base.rs @@ -1,3 +1,7 @@ +/// This contains a compressed version of a FAT32 filesystem that presents a 128MiB +/// disk image to the host. It was generated by plugging a 128MiB microSD card into a +/// Windows PC, formatting it, and then dumping the format results. Windows was chosen +/// as the template because it is more selective about the formatting than Linux hosts. pub const FAT_DATA: [(usize, [u8; 32]); 62] = [ ( 0x0, diff --git a/bao1x-boot/boot1/src/platform/bao1x/usb/mod.rs b/bao1x-boot/boot1/src/platform/bao1x/usb/mod.rs index 156e1e139..367ad3b02 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/usb/mod.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/usb/mod.rs @@ -7,14 +7,6 @@ pub use handlers::*; use crate::irq::*; -// Note that the trap handler is just placed one page below this, and it -// needs to be manually updated in the assembly because we can't refer to -// consts in that snippet of assembly. That handler also needs a default -// stack area, which is right below that spare page. -const SCRATCH_PAGE: usize = RAMDISK_ADDRESS - 4096; -#[allow(dead_code)] // this reminds us there are two places this has to be changed in assembly-land -const EXCEPTION_STACK: usize = SCRATCH_PAGE; - const USB_TYPE_MASK: u8 = 0x03 << 5; const USB_TYPE_STANDARD: u8 = 0x00 << 5; const USB_TYPE_CLASS: u8 = 0x01 << 5;