From 05844c76467c172e389d1a0428f9dc4bd89c446d Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 6 May 2024 02:28:11 +0800 Subject: [PATCH] reflect API changes in code --- loader/src/platform/cramium/cramium.rs | 4 +++- loader/src/platform/cramium/swap.rs | 27 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/loader/src/platform/cramium/cramium.rs b/loader/src/platform/cramium/cramium.rs index b41a6d834..ec8a4e99b 100644 --- a/loader/src/platform/cramium/cramium.rs +++ b/loader/src/platform/cramium/cramium.rs @@ -437,6 +437,7 @@ pub fn early_init() { 16, // just enough space to send commands 4096, Some(8), + None, IframRange::from_raw_parts(SPIM_FLASH_IFRAM_ADDR, SPIM_FLASH_IFRAM_ADDR, 4096 * 2), ) }; @@ -455,6 +456,7 @@ pub fn early_init() { 1024, // this is limited by the page length 1024, Some(6), + None, IframRange::from_raw_parts(SPIM_RAM_IFRAM_ADDR, SPIM_RAM_IFRAM_ADDR, 4096 * 2), ) }; @@ -600,7 +602,7 @@ pub fn early_init() { } } - crate::println!("Press any key to continue..."); + udma_uart.write("Press any key to continue...".as_bytes()); getc(); crate::println!("\n\rBooting!\n\r"); } diff --git a/loader/src/platform/cramium/swap.rs b/loader/src/platform/cramium/swap.rs index 1c9d8119d..335d4866a 100644 --- a/loader/src/platform/cramium/swap.rs +++ b/loader/src/platform/cramium/swap.rs @@ -202,6 +202,7 @@ impl SwapHal { 16, // just enough space to send commands 4096, Some(6), + None, IframRange::from_raw_parts(SPIM_FLASH_IFRAM_ADDR, SPIM_FLASH_IFRAM_ADDR, 4096 * 2), ) }; @@ -220,7 +221,8 @@ impl SwapHal { 1024, // this is limited by the page length 1024, Some(6), - IframRange::from_raw_parts(SPIM_RAM_IFRAM_ADDR, SPIM_RAM_IFRAM_ADDR, 4096 * 2), + None, + IframRange::from_raw_parts(SPIM_RAM_IFRAM_ADDR, SPIM_RAM_IFRAM_ADDR, 4096), ) }; // turn off QPI mode, in case it was set from a reboot in a bad state @@ -265,7 +267,7 @@ impl SwapHal { // allocate the buf let mut buf = RawPage { data: [0u8; 4096] }; // fetch the header - flash_spim.mem_read(SWAP_IMG_START as u32, &mut buf.data); + flash_spim.mem_read(SWAP_IMG_START as u32, &mut buf.data, false); // compute offsets for swap let mac_size = (swap.ram_size as usize / 4096) * size_of::(); @@ -347,7 +349,7 @@ impl SwapHal { // compensate for the unencrypted header that is not included in the `src_data_area` slice let offset = offset - 0x1000; self.buf_addr = offset; - self.flash_spim.mem_read((self.image_start + offset) as u32, &mut self.buf.data); + self.flash_spim.mem_read((self.image_start + offset) as u32, &mut self.buf.data, false); let mut nonce = [0u8; size_of::()]; nonce[..4].copy_from_slice(&(offset as u32).to_be_bytes()); nonce[4..].copy_from_slice(&self.partial_nonce); @@ -357,8 +359,11 @@ impl SwapHal { // cheaper than the Refcell bookkeeping. let mut aad = [0u8; 64]; aad[..self.aad_len].copy_from_slice(self.aad()); - self.flash_spim - .mem_read((self.image_mac_start + (offset / 4096) * size_of::()) as u32, &mut tag); + self.flash_spim.mem_read( + (self.image_mac_start + (offset / 4096) * size_of::()) as u32, + &mut tag, + false, + ); match self.src_cipher.decrypt_in_place_detached( Nonce::from_slice(&nonce), &aad[..self.aad_len], @@ -393,10 +398,11 @@ impl SwapHal { let aad: &[u8] = &[]; match self.dst_cipher.encrypt_in_place_detached(Nonce::from_slice(&nonce), aad, buf) { Ok(tag) => { - self.ram_spim.mem_ram_write(dest_offset as u32, buf); + self.ram_spim.mem_ram_write(dest_offset as u32, buf, false); self.ram_spim.mem_ram_write( (self.swap_mac_start + (dest_offset / PAGE_SIZE) * size_of::()) as u32, tag.as_slice(), + false, ); } Err(e) => panic!("Encryption error to swap ram: {:?}", e), @@ -416,9 +422,12 @@ impl SwapHal { nonce[9..12].copy_from_slice(&(vpage_masked as u32).to_be_bytes()[..3]); let aad: &[u8] = &[]; let mut tag = [0u8; size_of::()]; - self.ram_spim - .mem_read((self.swap_mac_start + (src_offset / PAGE_SIZE) * size_of::()) as u32, &mut tag); - self.ram_spim.mem_read(src_offset as u32, &mut self.buf.data); + self.ram_spim.mem_read( + (self.swap_mac_start + (src_offset / PAGE_SIZE) * size_of::()) as u32, + &mut tag, + false, + ); + self.ram_spim.mem_read(src_offset as u32, &mut self.buf.data, false); match self.dst_cipher.decrypt_in_place_detached( Nonce::from_slice(&nonce), aad,