From eecd825d23f999a3891069cabff4f4ca1bbfcc20 Mon Sep 17 00:00:00 2001 From: occheung Date: Wed, 25 Aug 2021 15:22:19 +0800 Subject: [PATCH] firmware: suppress warning --- artiq/firmware/bootloader/main.rs | 4 +- artiq/firmware/ksupport/eh_artiq.rs | 2 +- artiq/firmware/ksupport/lib.rs | 18 ++++----- artiq/firmware/libboard_artiq/lib.rs | 4 +- artiq/firmware/libboard_misoc/config.rs | 6 +-- artiq/firmware/libboard_misoc/sdram.rs | 14 +++---- artiq/firmware/libdyld/lib.rs | 4 +- artiq/firmware/libeh/eh_rust.rs | 3 -- artiq/firmware/libio/lib.rs | 1 - artiq/firmware/libproto_artiq/lib.rs | 1 - artiq/firmware/libproto_artiq/rpc_proto.rs | 12 +++--- artiq/firmware/runtime/main.rs | 47 ++++++++++------------ artiq/firmware/runtime/sched.rs | 4 +- artiq/firmware/satman/main.rs | 4 +- 14 files changed, 56 insertions(+), 68 deletions(-) diff --git a/artiq/firmware/bootloader/main.rs b/artiq/firmware/bootloader/main.rs index 865293840..b33722d5a 100644 --- a/artiq/firmware/bootloader/main.rs +++ b/artiq/firmware/bootloader/main.rs @@ -47,7 +47,7 @@ fn memory_test(total: &mut usize, wrong: &mut usize) -> bool { MEMORY[$index:expr] = $data:expr } ) => ({ - $prepare; + $prepare for $i in $range { unsafe { ptr::write_volatile(MEMORY.offset($index as isize), $data) }; *total += 1; @@ -56,7 +56,7 @@ fn memory_test(total: &mut usize, wrong: &mut usize) -> bool { cache::flush_cpu_dcache(); cache::flush_l2_cache(); - $prepare; + $prepare for $i in $range { if unsafe { ptr::read_volatile(MEMORY.offset($index as isize)) } != $data { *wrong += 1; diff --git a/artiq/firmware/ksupport/eh_artiq.rs b/artiq/firmware/ksupport/eh_artiq.rs index 471510930..f7923807a 100644 --- a/artiq/firmware/ksupport/eh_artiq.rs +++ b/artiq/firmware/ksupport/eh_artiq.rs @@ -8,7 +8,7 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(private_no_mangle_fns, non_camel_case_types)] +#![allow(non_camel_case_types)] use core::{ptr, mem}; use cslice::CSlice; diff --git a/artiq/firmware/ksupport/lib.rs b/artiq/firmware/ksupport/lib.rs index cf030b3a7..e3613d1dc 100644 --- a/artiq/firmware/ksupport/lib.rs +++ b/artiq/firmware/ksupport/lib.rs @@ -1,5 +1,5 @@ #![feature(lang_items, llvm_asm, panic_unwind, libc, unwind_attributes, - panic_handler, panic_info_message, nll)] + panic_info_message, nll)] #![no_std] extern crate libc; @@ -204,15 +204,13 @@ fn terminate(exception: &eh_artiq::Exception, backtrace: &mut [usize]) -> ! { #[unwind(aborts)] extern fn cache_get<'a>(ret: &'a mut CSlice, key: &CSlice) -> &'a CSlice<'a, i32> { - unsafe { - send(&CacheGetRequest { - key: str::from_utf8(key.as_ref()).unwrap() - }); - recv!(&CacheGetReply { value } => { - *ret = value.as_c_slice(); - ret - }) - } + send(&CacheGetRequest { + key: str::from_utf8(key.as_ref()).unwrap() + }); + recv!(&CacheGetReply { value } => { + *ret = value.as_c_slice(); + ret + }) } #[unwind(allowed)] diff --git a/artiq/firmware/libboard_artiq/lib.rs b/artiq/firmware/libboard_artiq/lib.rs index 1550db7dd..694805cfa 100644 --- a/artiq/firmware/libboard_artiq/lib.rs +++ b/artiq/firmware/libboard_artiq/lib.rs @@ -1,12 +1,10 @@ -#![feature(asm, lang_items, never_type)] +#![feature(lang_items, never_type)] #![no_std] extern crate failure; #[cfg(has_drtio)] #[macro_use] extern crate failure_derive; -#[macro_use] -extern crate bitflags; extern crate byteorder; extern crate crc; #[macro_use] diff --git a/artiq/firmware/libboard_misoc/config.rs b/artiq/firmware/libboard_misoc/config.rs index 7ed368efd..9a737e303 100644 --- a/artiq/firmware/libboard_misoc/config.rs +++ b/artiq/firmware/libboard_misoc/config.rs @@ -77,10 +77,10 @@ mod imp { mod lock { use core::slice; - use core::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; + use core::sync::atomic::{AtomicUsize, Ordering}; use super::Error; - static LOCKED: AtomicUsize = ATOMIC_USIZE_INIT; + static LOCKED: AtomicUsize = AtomicUsize::new(0); pub struct Lock; @@ -216,7 +216,7 @@ mod imp { let mut offset = 0; let mut iter = Iter::new(old_data); 'iter: while let Some(result) = iter.next() { - let (key, mut value) = result?; + let (key, value) = result?; if value.is_empty() { // This is a removed entry, ignore it. continue diff --git a/artiq/firmware/libboard_misoc/sdram.rs b/artiq/firmware/libboard_misoc/sdram.rs index 6e3071c4b..61951e725 100644 --- a/artiq/firmware/libboard_misoc/sdram.rs +++ b/artiq/firmware/libboard_misoc/sdram.rs @@ -31,7 +31,7 @@ mod ddr { } #[cfg(ddrphy_wlevel)] - unsafe fn write_level_scan(logger: &mut Option<&mut fmt::Write>) { + unsafe fn write_level_scan(logger: &mut Option<&mut dyn fmt::Write>) { #[cfg(kusddrphy)] log!(logger, "DQS initial delay: {} taps\n", ddrphy::wdly_dqs_taps_read()); log!(logger, "Write leveling scan:\n"); @@ -82,7 +82,7 @@ mod ddr { } #[cfg(ddrphy_wlevel)] - unsafe fn write_level(logger: &mut Option<&mut fmt::Write>, + unsafe fn write_level(logger: &mut Option<&mut dyn fmt::Write>, delay: &mut [u16; DQS_SIGNAL_COUNT], high_skew: &mut [bool; DQS_SIGNAL_COUNT]) -> bool { #[cfg(kusddrphy)] @@ -172,7 +172,7 @@ mod ddr { } #[cfg(ddrphy_wlevel)] - unsafe fn read_bitslip(logger: &mut Option<&mut fmt::Write>, + unsafe fn read_bitslip(logger: &mut Option<&mut dyn fmt::Write>, delay: &[u16; DQS_SIGNAL_COUNT], high_skew: &[bool; DQS_SIGNAL_COUNT]) { let threshold_opt = delay.iter().zip(high_skew.iter()) @@ -203,7 +203,7 @@ mod ddr { } } - unsafe fn read_level_scan(logger: &mut Option<&mut fmt::Write>) { + unsafe fn read_level_scan(logger: &mut Option<&mut dyn fmt::Write>) { log!(logger, "Read leveling scan:\n"); // Generate pseudo-random sequence @@ -286,7 +286,7 @@ mod ddr { spin_cycles(15); } - unsafe fn read_level(logger: &mut Option<&mut fmt::Write>) -> bool { + unsafe fn read_level(logger: &mut Option<&mut dyn fmt::Write>) -> bool { log!(logger, "Read leveling: "); // Generate pseudo-random sequence @@ -417,7 +417,7 @@ mod ddr { true } - pub unsafe fn level(logger: &mut Option<&mut fmt::Write>) -> bool { + pub unsafe fn level(logger: &mut Option<&mut dyn fmt::Write>) -> bool { #[cfg(ddrphy_wlevel)] { let mut delay = [0; DQS_SIGNAL_COUNT]; @@ -442,7 +442,7 @@ use core::fmt; use csr; use sdram_phy; -pub unsafe fn init(mut _logger: Option<&mut fmt::Write>) -> bool { +pub unsafe fn init(mut _logger: Option<&mut dyn fmt::Write>) -> bool { sdram_phy::initialize(); #[cfg(has_ddrphy)] diff --git a/artiq/firmware/libdyld/lib.rs b/artiq/firmware/libdyld/lib.rs index 8626b2920..5137b257b 100644 --- a/artiq/firmware/libdyld/lib.rs +++ b/artiq/firmware/libdyld/lib.rs @@ -159,7 +159,7 @@ impl<'a> Library<'a> { Ok(()) } - fn resolve_rela(&self, rela: &Elf32_Rela, resolve: &Fn(&[u8]) -> Option) + fn resolve_rela(&self, rela: &Elf32_Rela, resolve: &dyn Fn(&[u8]) -> Option) -> Result<(), Error<'a>> { let sym; if ELF32_R_SYM(rela.r_info) == 0 { @@ -204,7 +204,7 @@ impl<'a> Library<'a> { self.update_rela(rela, value) } - pub fn load(data: &[u8], image: &'a mut [u8], resolve: &Fn(&[u8]) -> Option) + pub fn load(data: &[u8], image: &'a mut [u8], resolve: &dyn Fn(&[u8]) -> Option) -> Result, Error<'a>> { #![allow(unused_assignments)] diff --git a/artiq/firmware/libeh/eh_rust.rs b/artiq/firmware/libeh/eh_rust.rs index 5692beb54..399ccdf6b 100644 --- a/artiq/firmware/libeh/eh_rust.rs +++ b/artiq/firmware/libeh/eh_rust.rs @@ -14,11 +14,8 @@ // // By design, this personality function is only ever called in the search phase, although // to keep things simple and close to upstream, it is not modified -#![allow(private_no_mangle_fns)] - use unwind as uw; use libc::{c_int, uintptr_t}; -use cslice::AsCSlice; use dwarf::{self, EHAction, EHContext}; diff --git a/artiq/firmware/libio/lib.rs b/artiq/firmware/libio/lib.rs index 235fd82c0..cb1c34002 100644 --- a/artiq/firmware/libio/lib.rs +++ b/artiq/firmware/libio/lib.rs @@ -1,6 +1,5 @@ #![no_std] #![feature(never_type)] -#![cfg_attr(feature = "alloc", feature(alloc))] extern crate failure; #[macro_use] diff --git a/artiq/firmware/libproto_artiq/lib.rs b/artiq/firmware/libproto_artiq/lib.rs index 66c04d5e6..d343d7d61 100644 --- a/artiq/firmware/libproto_artiq/lib.rs +++ b/artiq/firmware/libproto_artiq/lib.rs @@ -1,5 +1,4 @@ #![no_std] -#![cfg_attr(feature = "alloc", feature(alloc))] extern crate failure; #[macro_use] diff --git a/artiq/firmware/libproto_artiq/rpc_proto.rs b/artiq/firmware/libproto_artiq/rpc_proto.rs index bff4d46b0..0295b5297 100644 --- a/artiq/firmware/libproto_artiq/rpc_proto.rs +++ b/artiq/firmware/libproto_artiq/rpc_proto.rs @@ -18,7 +18,7 @@ unsafe fn align_ptr_mut(ptr: *mut ()) -> *mut T { } unsafe fn recv_value(reader: &mut R, tag: Tag, data: &mut *mut (), - alloc: &Fn(usize) -> Result<*mut (), E>) + alloc: &dyn Fn(usize) -> Result<*mut (), E>) -> Result<(), E> where R: Read + ?Sized, E: From> @@ -63,7 +63,7 @@ unsafe fn recv_value(reader: &mut R, tag: Tag, data: &mut *mut (), } Tag::List(it) => { #[repr(C)] - struct List { elements: *mut (), length: u32 }; + struct List { elements: *mut (), length: u32 } consume_value!(List, |ptr| { (*ptr).length = reader.read_u32()?; let length = (*ptr).length as usize; @@ -151,7 +151,7 @@ unsafe fn recv_value(reader: &mut R, tag: Tag, data: &mut *mut (), } pub fn recv_return(reader: &mut R, tag_bytes: &[u8], data: *mut (), - alloc: &Fn(usize) -> Result<*mut (), E>) + alloc: &dyn Fn(usize) -> Result<*mut (), E>) -> Result<(), E> where R: Read + ?Sized, E: From> @@ -208,7 +208,7 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) } Tag::List(it) => { #[repr(C)] - struct List { elements: *const (), length: u32 }; + struct List { elements: *const (), length: u32 } consume_value!(List, |ptr| { let length = (*ptr).length as usize; writer.write_u32((*ptr).length)?; @@ -287,7 +287,7 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) } Tag::Keyword(it) => { #[repr(C)] - struct Keyword<'a> { name: CSlice<'a, u8> }; + struct Keyword<'a> { name: CSlice<'a, u8> } consume_value!(Keyword, |ptr| { writer.write_string(str::from_utf8((*ptr).name.as_ref()).unwrap())?; let tag = it.clone().next().expect("truncated tag"); @@ -299,7 +299,7 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) } Tag::Object => { #[repr(C)] - struct Object { id: u32 }; + struct Object { id: u32 } consume_value!(*const Object, |ptr| writer.write_u32((**ptr).id)) } diff --git a/artiq/firmware/runtime/main.rs b/artiq/firmware/runtime/main.rs index 17e4c0a42..5a8fdf3d7 100644 --- a/artiq/firmware/runtime/main.rs +++ b/artiq/firmware/runtime/main.rs @@ -1,5 +1,4 @@ -#![feature(lang_items, alloc, try_from, nonzero, asm, - panic_handler, panic_info_message)] +#![feature(lang_items, panic_info_message)] #![no_std] extern crate eh; @@ -280,32 +279,30 @@ pub struct TrapFrame { #[no_mangle] pub extern fn exception(regs: *const TrapFrame) { - unsafe { - let pc = mepc::read(); - let cause = mcause::read().cause(); - match cause { - mcause::Trap::Interrupt(source) => { - info!("Called interrupt with {:?}", source); - }, - mcause::Trap::Exception(e) => { - println!("Trap frame: {:x?}", unsafe { *regs }); + let pc = mepc::read(); + let cause = mcause::read().cause(); + match cause { + mcause::Trap::Interrupt(source) => { + info!("Called interrupt with {:?}", source); + }, + mcause::Trap::Exception(e) => { + println!("Trap frame: {:x?}", unsafe { *regs }); - fn hexdump(addr: u32) { - let addr = (addr - addr % 4) as *const u32; - let mut ptr = addr; - println!("@ {:08p}", ptr); - for _ in 0..4 { - print!("+{:04x}: ", ptr as usize - addr as usize); - print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1); - print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1); - print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1); - print!("{:08x}\n", unsafe { *ptr }); ptr = ptr.wrapping_offset(1); - } + fn hexdump(addr: u32) { + let addr = (addr - addr % 4) as *const u32; + let mut ptr = addr; + println!("@ {:08p}", ptr); + for _ in 0..4 { + print!("+{:04x}: ", ptr as usize - addr as usize); + print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1); + print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1); + print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1); + print!("{:08x}\n", unsafe { *ptr }); ptr = ptr.wrapping_offset(1); } - - hexdump(u32::try_from(pc).unwrap()); - panic!("exception {:?} at PC 0x{:x}", e, u32::try_from(pc).unwrap()) } + + hexdump(u32::try_from(pc).unwrap()); + panic!("exception {:?} at PC 0x{:x}", e, u32::try_from(pc).unwrap()) } } } diff --git a/artiq/firmware/runtime/sched.rs b/artiq/firmware/runtime/sched.rs index 43dae0f55..7b182a3e4 100644 --- a/artiq/firmware/runtime/sched.rs +++ b/artiq/firmware/runtime/sched.rs @@ -35,7 +35,7 @@ type SocketSet = ::smoltcp::socket::SocketSet<'static, 'static, 'static>; #[derive(Debug)] struct WaitRequest { - event: Option<*mut FnMut() -> bool>, + event: Option<*mut dyn FnMut() -> bool>, timeout: Option } @@ -240,7 +240,7 @@ impl<'a> Io<'a> { } pub fn until bool>(&self, mut f: F) -> Result<(), Error> { - let f = unsafe { mem::transmute::<&mut FnMut() -> bool, *mut FnMut() -> bool>(&mut f) }; + let f = unsafe { mem::transmute::<&mut dyn FnMut() -> bool, *mut dyn FnMut() -> bool>(&mut f) }; self.suspend(WaitRequest { timeout: None, event: Some(f) diff --git a/artiq/firmware/satman/main.rs b/artiq/firmware/satman/main.rs index 4d1869bcd..f9e3d9e7c 100644 --- a/artiq/firmware/satman/main.rs +++ b/artiq/firmware/satman/main.rs @@ -539,7 +539,7 @@ pub extern fn main() -> i32 { } while !drtiosat_link_rx_up() { drtiosat_process_errors(); - for mut rep in repeaters.iter_mut() { + for rep in repeaters.iter_mut() { rep.service(&routing_table, rank); } #[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))] @@ -568,7 +568,7 @@ pub extern fn main() -> i32 { while drtiosat_link_rx_up() { drtiosat_process_errors(); process_aux_packets(&mut repeaters, &mut routing_table, &mut rank); - for mut rep in repeaters.iter_mut() { + for rep in repeaters.iter_mut() { rep.service(&routing_table, rank); } #[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))]