chore: ♻️ Fix rustfmt and clippy complaints
This commit is contained in:
parent
7de1af043e
commit
ebb73e5cb0
|
@ -10,11 +10,7 @@
|
||||||
use {
|
use {
|
||||||
aarch64_cpu::asm::barrier,
|
aarch64_cpu::asm::barrier,
|
||||||
core::hash::Hasher,
|
core::hash::Hasher,
|
||||||
machine::{
|
machine::{console::console, platform::rpi3::BcmHost, print, println},
|
||||||
devices::SerialOps,
|
|
||||||
platform::rpi3::{gpio::GPIO, pl011_uart::PL011Uart, BcmHost},
|
|
||||||
print, println, CONSOLE,
|
|
||||||
},
|
|
||||||
seahash::SeaHasher,
|
seahash::SeaHasher,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,13 +26,12 @@ unsafe fn kernel_init(max_kernel_size: u64) -> ! {
|
||||||
#[cfg(feature = "jtag")]
|
#[cfg(feature = "jtag")]
|
||||||
machine::arch::jtag::wait_debugger();
|
machine::arch::jtag::wait_debugger();
|
||||||
|
|
||||||
let gpio = GPIO::default();
|
if let Err(x) = machine::platform::drivers::init() {
|
||||||
let uart = PL011Uart::default();
|
panic!("Error initializing platform drivers: {}", x);
|
||||||
let uart = uart.prepare(&gpio).expect("What could go wrong?");
|
}
|
||||||
CONSOLE.lock(|c| {
|
|
||||||
// Move uart into the global CONSOLE.
|
// Initialize all device drivers.
|
||||||
c.replace_with(uart.into());
|
machine::drivers::driver_manager().init_drivers();
|
||||||
});
|
|
||||||
|
|
||||||
// println! is usable from here on.
|
// println! is usable from here on.
|
||||||
|
|
||||||
|
@ -53,17 +48,15 @@ const LOGO: &str = r#"
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
fn read_u64() -> u64 {
|
fn read_u64() -> u64 {
|
||||||
CONSOLE.lock(|c| {
|
let mut val: u64 = u64::from(console().read_byte());
|
||||||
let mut val: u64 = u64::from(c.read_byte());
|
val |= u64::from(console().read_byte()) << 8;
|
||||||
val |= u64::from(c.read_byte()) << 8;
|
val |= u64::from(console().read_byte()) << 16;
|
||||||
val |= u64::from(c.read_byte()) << 16;
|
val |= u64::from(console().read_byte()) << 24;
|
||||||
val |= u64::from(c.read_byte()) << 24;
|
val |= u64::from(console().read_byte()) << 32;
|
||||||
val |= u64::from(c.read_byte()) << 32;
|
val |= u64::from(console().read_byte()) << 40;
|
||||||
val |= u64::from(c.read_byte()) << 40;
|
val |= u64::from(console().read_byte()) << 48;
|
||||||
val |= u64::from(c.read_byte()) << 48;
|
val |= u64::from(console().read_byte()) << 56;
|
||||||
val |= u64::from(c.read_byte()) << 56;
|
val
|
||||||
val
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The main function running after the early init.
|
/// The main function running after the early init.
|
||||||
|
@ -79,14 +72,14 @@ fn kernel_main(max_kernel_size: u64) -> ! {
|
||||||
let kernel_addr: *mut u8 = BcmHost::kernel_load_address() as *mut u8;
|
let kernel_addr: *mut u8 = BcmHost::kernel_load_address() as *mut u8;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
CONSOLE.lock(|c| c.flush());
|
console().flush();
|
||||||
|
|
||||||
// Discard any spurious received characters before starting with the loader protocol.
|
// Discard any spurious received characters before starting with the loader protocol.
|
||||||
CONSOLE.lock(|c| c.clear_rx());
|
console().clear_rx();
|
||||||
|
|
||||||
// Notify `chainofcommand` to send the binary.
|
// Notify `chainofcommand` to send the binary.
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
CONSOLE.lock(|c| c.write_byte(3u8));
|
console().write_byte(3u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the binary's size.
|
// Read the binary's size.
|
||||||
|
@ -108,7 +101,7 @@ fn kernel_main(max_kernel_size: u64) -> ! {
|
||||||
|
|
||||||
// Read the kernel byte by byte.
|
// Read the kernel byte by byte.
|
||||||
for i in 0..size {
|
for i in 0..size {
|
||||||
let val = CONSOLE.lock(|c| c.read_byte());
|
let val = console().read_byte();
|
||||||
unsafe {
|
unsafe {
|
||||||
core::ptr::write_volatile(kernel_addr.offset(i as isize), val);
|
core::ptr::write_volatile(kernel_addr.offset(i as isize), val);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +126,7 @@ fn kernel_main(max_kernel_size: u64) -> ! {
|
||||||
"⏪ Loaded! Executing the payload now from {:p}\n",
|
"⏪ Loaded! Executing the payload now from {:p}\n",
|
||||||
kernel_addr
|
kernel_addr
|
||||||
);
|
);
|
||||||
CONSOLE.lock(|c| c.flush());
|
console().flush();
|
||||||
|
|
||||||
// Use black magic to create a function pointer.
|
// Use black magic to create a function pointer.
|
||||||
let kernel: fn() -> ! = unsafe { core::mem::transmute(kernel_addr) };
|
let kernel: fn() -> ! = unsafe { core::mem::transmute(kernel_addr) };
|
||||||
|
|
|
@ -84,9 +84,10 @@ where
|
||||||
let kernel_size: u64 = kernel_file.metadata()?.len();
|
let kernel_size: u64 = kernel_file.metadata()?.len();
|
||||||
|
|
||||||
to_console2
|
to_console2
|
||||||
.send(Ok(Message::Text(
|
.send(Ok(Message::Text(format!(
|
||||||
format!("⏩ .. {} ({} bytes)\n", kernel, kernel_size).into(),
|
"⏩ .. {} ({} bytes)\n",
|
||||||
)))
|
kernel, kernel_size
|
||||||
|
))))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok((kernel_file, kernel_size))
|
Ok((kernel_file, kernel_size))
|
||||||
|
@ -135,9 +136,10 @@ async fn send_kernel<P: ThePath>(
|
||||||
let hashed_value: u64 = hasher.finish();
|
let hashed_value: u64 = hasher.finish();
|
||||||
|
|
||||||
to_console2
|
to_console2
|
||||||
.send(Ok(Message::Text(
|
.send(Ok(Message::Text(format!(
|
||||||
format!("⏩ Sending image checksum {:x}\n", hashed_value).into(),
|
"⏩ Sending image checksum {:x}\n",
|
||||||
)))
|
hashed_value
|
||||||
|
))))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
to_serial
|
to_serial
|
||||||
|
@ -383,7 +385,7 @@ fn handle_key_event(key_event: KeyEvent) -> Option<Bytes> {
|
||||||
KeyCode::Char(ch) => {
|
KeyCode::Char(ch) => {
|
||||||
if key_event.modifiers & KeyModifiers::CONTROL == KeyModifiers::CONTROL {
|
if key_event.modifiers & KeyModifiers::CONTROL == KeyModifiers::CONTROL {
|
||||||
buf[0] = ch as u8;
|
buf[0] = ch as u8;
|
||||||
if ('a'..='z').contains(&ch) || (ch == ' ') {
|
if ch.is_ascii_lowercase() || (ch == ' ') {
|
||||||
buf[0] &= 0x1f;
|
buf[0] &= 0x1f;
|
||||||
Some(&buf[0..1])
|
Some(&buf[0..1])
|
||||||
} else if ('4'..='7').contains(&ch) {
|
} else if ('4'..='7').contains(&ch) {
|
||||||
|
@ -527,10 +529,8 @@ async fn main() -> Result<()> {
|
||||||
let cont = matches!(e.downcast_ref::<std::io::Error>(),
|
let cont = matches!(e.downcast_ref::<std::io::Error>(),
|
||||||
Some(e) if e.kind() == std::io::ErrorKind::NotFound || e.kind() == std::io::ErrorKind::PermissionDenied)
|
Some(e) if e.kind() == std::io::ErrorKind::NotFound || e.kind() == std::io::ErrorKind::PermissionDenied)
|
||||||
|| matches!(e.downcast_ref::<tokio_serial::Error>(), Some(e) if e.kind == tokio_serial::ErrorKind::NoDevice)
|
|| matches!(e.downcast_ref::<tokio_serial::Error>(), Some(e) if e.kind == tokio_serial::ErrorKind::NoDevice)
|
||||||
|| matches!(
|
|| e.downcast_ref::<tokio::sync::mpsc::error::SendError<Vec<u8>>>()
|
||||||
e.downcast_ref::<tokio::sync::mpsc::error::SendError<Vec<u8>>>(),
|
.is_some();
|
||||||
Some(_)
|
|
||||||
);
|
|
||||||
|
|
||||||
if !cont {
|
if !cont {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -19,11 +19,11 @@ use {
|
||||||
},
|
},
|
||||||
platform, println,
|
platform, println,
|
||||||
},
|
},
|
||||||
core::intrinsics::unlikely,
|
|
||||||
aarch64_cpu::{
|
aarch64_cpu::{
|
||||||
asm::barrier,
|
asm::barrier,
|
||||||
registers::{ID_AA64MMFR0_EL1, SCTLR_EL1, TCR_EL1, TTBR0_EL1},
|
registers::{ID_AA64MMFR0_EL1, SCTLR_EL1, TCR_EL1, TTBR0_EL1},
|
||||||
},
|
},
|
||||||
|
core::intrinsics::unlikely,
|
||||||
tock_registers::interfaces::{ReadWriteable, Readable, Writeable},
|
tock_registers::interfaces::{ReadWriteable, Readable, Writeable},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -231,6 +231,7 @@ impl MiniUartInner {
|
||||||
impl MiniUartInner {
|
impl MiniUartInner {
|
||||||
/// Set baud rate and characteristics (115200 8N1) and map to GPIO
|
/// Set baud rate and characteristics (115200 8N1) and map to GPIO
|
||||||
pub fn prepare(&self) -> Result<(), &'static str> {
|
pub fn prepare(&self) -> Result<(), &'static str> {
|
||||||
|
use tock_registers::interfaces::Writeable;
|
||||||
// initialize UART
|
// initialize UART
|
||||||
self.registers
|
self.registers
|
||||||
.AUX_ENABLES
|
.AUX_ENABLES
|
||||||
|
@ -269,6 +270,7 @@ impl Drop for MiniUartInner {
|
||||||
impl SerialOps for MiniUartInner {
|
impl SerialOps for MiniUartInner {
|
||||||
/// Receive a byte without console translation
|
/// Receive a byte without console translation
|
||||||
fn read_byte(&self) -> u8 {
|
fn read_byte(&self) -> u8 {
|
||||||
|
use tock_registers::interfaces::Readable;
|
||||||
// wait until something is in the buffer
|
// wait until something is in the buffer
|
||||||
crate::arch::loop_until(|| {
|
crate::arch::loop_until(|| {
|
||||||
self.registers
|
self.registers
|
||||||
|
@ -281,6 +283,7 @@ impl SerialOps for MiniUartInner {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_byte(&self, b: u8) {
|
fn write_byte(&self, b: u8) {
|
||||||
|
use tock_registers::interfaces::{Readable, Writeable};
|
||||||
// wait until we can send
|
// wait until we can send
|
||||||
crate::arch::loop_until(|| {
|
crate::arch::loop_until(|| {
|
||||||
self.registers
|
self.registers
|
||||||
|
@ -295,12 +298,14 @@ impl SerialOps for MiniUartInner {
|
||||||
/// Wait until the TX FIFO is empty, aka all characters have been put on the
|
/// Wait until the TX FIFO is empty, aka all characters have been put on the
|
||||||
/// line.
|
/// line.
|
||||||
fn flush(&self) {
|
fn flush(&self) {
|
||||||
|
use tock_registers::interfaces::Readable;
|
||||||
crate::arch::loop_until(|| self.registers.AUX_MU_STAT.is_set(AUX_MU_STAT::TX_DONE));
|
crate::arch::loop_until(|| self.registers.AUX_MU_STAT.is_set(AUX_MU_STAT::TX_DONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consume input until RX FIFO is empty, aka all pending characters have been
|
/// Consume input until RX FIFO is empty, aka all pending characters have been
|
||||||
/// consumed.
|
/// consumed.
|
||||||
fn clear_rx(&self) {
|
fn clear_rx(&self) {
|
||||||
|
use tock_registers::interfaces::Readable;
|
||||||
crate::arch::loop_while(|| {
|
crate::arch::loop_while(|| {
|
||||||
let pending = self
|
let pending = self
|
||||||
.registers
|
.registers
|
||||||
|
@ -317,10 +322,10 @@ impl SerialOps for MiniUartInner {
|
||||||
impl interface::ConsoleOps for MiniUartInner {
|
impl interface::ConsoleOps for MiniUartInner {
|
||||||
/// Send a character
|
/// Send a character
|
||||||
fn write_char(&self, c: char) {
|
fn write_char(&self, c: char) {
|
||||||
let mut b = [0u8; 4];
|
let mut bytes = [0u8; 4];
|
||||||
let _ = c.encode_utf8(&mut b);
|
let _ = c.encode_utf8(&mut bytes);
|
||||||
for x in 0..c.len_utf8() {
|
for &b in bytes.iter().take(c.len_utf8()) {
|
||||||
self.write_byte(b[x]);
|
self.write_byte(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -406,10 +406,10 @@ impl SerialOps for PreparedPL011Uart {
|
||||||
impl ConsoleOps for PreparedPL011Uart {
|
impl ConsoleOps for PreparedPL011Uart {
|
||||||
/// Send a character
|
/// Send a character
|
||||||
fn write_char(&self, c: char) {
|
fn write_char(&self, c: char) {
|
||||||
let mut b = [0u8; 4];
|
let mut bytes = [0u8; 4];
|
||||||
let _ = c.encode_utf8(&mut b);
|
let _ = c.encode_utf8(&mut bytes);
|
||||||
for x in 0..c.len_utf8() {
|
for &b in bytes.iter().take(c.len_utf8()) {
|
||||||
self.write_byte(b[x]);
|
self.write_byte(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -547,11 +547,11 @@ impl<const N_SLOTS: usize, Storage: MailboxStorage + MailboxStorageRef> Mailbox<
|
||||||
/// when passing memory addresses as the data part of a mailbox message,
|
/// when passing memory addresses as the data part of a mailbox message,
|
||||||
/// the addresses should be **bus addresses as seen from the VC.**
|
/// the addresses should be **bus addresses as seen from the VC.**
|
||||||
pub fn do_write(&self, channel: u32) -> Result<()> {
|
pub fn do_write(&self, channel: u32) -> Result<()> {
|
||||||
let buf_ptr = self.buffer.as_ptr() as *const u32 as u32;
|
let buf_ptr = self.buffer.as_ptr();
|
||||||
let buf_ptr = if channel != channel::PropertyTagsArmToVc {
|
let buf_ptr = if channel != channel::PropertyTagsArmToVc {
|
||||||
BcmHost::phys2bus(buf_ptr as usize) as u32
|
BcmHost::phys2bus(buf_ptr as usize) as u32
|
||||||
} else {
|
} else {
|
||||||
buf_ptr
|
buf_ptr as u32
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut count: u32 = 0;
|
let mut count: u32 = 0;
|
||||||
|
|
|
@ -53,6 +53,11 @@ entry!(kernel_init);
|
||||||
|
|
||||||
/// Kernel entry point.
|
/// Kernel entry point.
|
||||||
/// `arch` crate is responsible for calling it.
|
/// `arch` crate is responsible for calling it.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// - Only a single core must be active and running this function.
|
||||||
|
/// - The init calls in this function must appear in the correct order.
|
||||||
pub unsafe fn kernel_init() -> ! {
|
pub unsafe fn kernel_init() -> ! {
|
||||||
#[cfg(feature = "jtag")]
|
#[cfg(feature = "jtag")]
|
||||||
machine::arch::jtag::wait_debugger();
|
machine::arch::jtag::wait_debugger();
|
||||||
|
|
Loading…
Reference in New Issue