Compare commits

..

15 Commits

23 changed files with 45 additions and 53 deletions

View File

@ -1,9 +1,11 @@
[target.armv7-none-eabihf] [target.armv7-none-eabihf]
rustflags = [ rustflags = [
"-C", "link-arg=-Tlink.x", "-C", "link-arg=-Tlink.x",
"-C", "target-feature=a9,armv7-a,neon",
"-C", "target-cpu=cortex-a9", "-C", "target-cpu=cortex-a9",
] ]
[build] [build]
target = "armv7-none-eabihf.json" target = "armv7-none-eabihf.json"
[future-incompat-report]
frequency = "never"

4
Cargo.lock generated
View File

@ -34,9 +34,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "compiler_builtins" name = "compiler_builtins"
version = "0.1.49" version = "0.1.108"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20b1438ef42c655665a8ab2c1c6d605a305f031d38d9be689ddfef41a20f3aa2" checksum = "d68bc55329711cd719c2687bb147bc06211b0521f97ef398280108ccb23227e9"
[[package]] [[package]]
name = "core_io" name = "core_io"

View File

@ -9,6 +9,7 @@ members = [
"experiments", "experiments",
"szl", "szl",
] ]
resolver = "2"
[profile.release] [profile.release]
panic = "abort" panic = "abort"

View File

@ -4,7 +4,7 @@
"emit-debug-gdb-scripts": false, "emit-debug-gdb-scripts": false,
"env": "", "env": "",
"executables": true, "executables": true,
"features": "+v7,+vfp3,-d32,+thumb2,-neon", "features": "+v7,+vfp3,-d32,+thumb2,+neon,+a9,+armv7-a",
"is-builtin": false, "is-builtin": false,
"linker": "rust-lld", "linker": "rust-lld",
"linker-flavor": "ld.lld", "linker-flavor": "ld.lld",

View File

@ -3,7 +3,7 @@ name = "experiments"
description = "Developing bare-metal Rust on Zynq" description = "Developing bare-metal Rust on Zynq"
version = "0.0.0" version = "0.0.0"
authors = ["M-Labs"] authors = ["M-Labs"]
edition = "2018" edition = "2021"
[features] [features]
target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706"] target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706"]

View File

@ -1,14 +1,13 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#![allow(incomplete_features)]
#![feature(naked_functions)] #![feature(naked_functions)]
#![feature(asm)]
#![feature(inline_const)] #![feature(inline_const)]
extern crate alloc; extern crate alloc;
use alloc::collections::BTreeMap; use alloc::collections::BTreeMap;
use core::arch::asm; use core::arch::asm;
use::core::ptr::addr_of_mut;
use libasync::{ use libasync::{
delay, delay,
smoltcp::{Sockets, TcpStream}, smoltcp::{Sockets, TcpStream},
@ -73,7 +72,7 @@ interrupt_handler!(IRQ, irq, __irq_stack0_start, __irq_stack1_start, {
if id.0 == 0 { if id.0 == 0 {
gic.end_interrupt(id); gic.end_interrupt(id);
asm::exit_irq(); asm::exit_irq();
SP.write(&mut __stack1_start as *mut _ as u32); SP.write(addr_of_mut!(__stack1_start) as u32);
asm::enable_irq(); asm::enable_irq();
CORE1_RESTART.store(false, Ordering::Relaxed); CORE1_RESTART.store(false, Ordering::Relaxed);
notify_spin_lock(); notify_spin_lock();

8
flake.lock generated
View File

@ -2,16 +2,16 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1736867362, "lastModified": 1734529975,
"narHash": "sha256-i/UJ5I7HoqmFMwZEH6vAvBxOrjjOJNU739lnZnhUln8=", "narHash": "sha256-ze3IJksru9dN0keqUxY0WNf8xrwfs8Ty/z9v/keyBbg=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9c6b49aeac36e2ed73a8c472f1546f6d9cf1addc", "rev": "72d11d40b9878a67c38f003c240c2d2e1811e72a",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixos-24.11", "ref": "nixos-24.05",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }

View File

@ -1,7 +1,7 @@
{ {
description = "Bare-metal Rust on Zynq-7000"; description = "Bare-metal Rust on Zynq-7000";
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-24.11; inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-24.05;
inputs.rust-overlay = { inputs.rust-overlay = {
url = "github:oxalica/rust-overlay?ref=snapshot/2024-08-01"; url = "github:oxalica/rust-overlay?ref=snapshot/2024-08-01";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -11,7 +11,7 @@
let let
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import rust-overlay) crosspkgs-overlay ]; }; pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import rust-overlay) crosspkgs-overlay ]; };
rust = pkgs.rust-bin.nightly."2021-09-01".default.override { rust = pkgs.rust-bin.nightly."2024-04-06".default.override {
extensions = [ "rust-src" ]; extensions = [ "rust-src" ];
targets = [ ]; targets = [ ];
}; };
@ -95,9 +95,7 @@
dontFixup = true; dontFixup = true;
}; };
cargo-xbuild = pkgs.cargo-xbuild.overrideAttrs(oa: { cargo-xbuild = pkgs.cargo-xbuild;
postPatch = "substituteInPlace src/sysroot.rs --replace 2021 2018";
});
build-crate = name: crate: features: rustPlatform.buildRustPackage rec { build-crate = name: crate: features: rustPlatform.buildRustPackage rec {
name = "${crate}"; name = "${crate}";
@ -113,7 +111,7 @@
}; };
}; };
nativeBuildInputs = [ cargo-xbuild pkgs.llvmPackages_13.clang-unwrapped ]; nativeBuildInputs = [ cargo-xbuild pkgs.llvmPackages_18.clang-unwrapped ];
buildPhase = '' buildPhase = ''
export XARGO_RUST_SRC="${rust}/lib/rustlib/src/rust/library" export XARGO_RUST_SRC="${rust}/lib/rustlib/src/rust/library"
export CARGO_HOME=$(mktemp -d cargo-home.XXX) export CARGO_HOME=$(mktemp -d cargo-home.XXX)
@ -169,7 +167,7 @@
pkgs.openocd pkgs.gdb pkgs.openocd pkgs.gdb
pkgs.openssh pkgs.rsync pkgs.openssh pkgs.rsync
pkgs.llvmPackages_13.clang-unwrapped pkgs.llvmPackages_18.clang-unwrapped
(pkgs.python3.withPackages(ps: [ ps.pyftdi ])) (pkgs.python3.withPackages(ps: [ ps.pyftdi ]))
]; ];
}; };

View File

@ -3,7 +3,7 @@ name = "libasync"
description = "low-level async support" description = "low-level async support"
version = "0.0.0" version = "0.0.0"
authors = ["M-Labs"] authors = ["M-Labs"]
edition = "2018" edition = "2021"
[dependencies] [dependencies]
#futures = { version = "0.3", default-features = false } #futures = { version = "0.3", default-features = false }

View File

@ -3,7 +3,7 @@ name = "libboard_zynq"
description = "Drivers for peripherals in the Zynq PS" description = "Drivers for peripherals in the Zynq PS"
version = "0.0.0" version = "0.0.0"
authors = ["M-Labs"] authors = ["M-Labs"]
edition = "2018" edition = "2021"
[features] [features]
target_zc706 = [] target_zc706 = []

View File

@ -9,7 +9,6 @@ use super::time::Milliseconds;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use libregister::{RegisterR, RegisterRW, RegisterW}; use libregister::{RegisterR, RegisterRW, RegisterW};
use log::{trace, debug}; use log::{trace, debug};
use nb;
/// Basic SDIO Struct with common low-level functions. /// Basic SDIO Struct with common low-level functions.
pub struct Sdio { pub struct Sdio {

View File

@ -2,7 +2,7 @@
name = "libconfig" name = "libconfig"
version = "0.1.0" version = "0.1.0"
authors = ["M-Labs"] authors = ["M-Labs"]
edition = "2018" edition = "2021"
[dependencies] [dependencies]
libboard_zynq = { path = "../libboard_zynq" } libboard_zynq = { path = "../libboard_zynq" }

View File

@ -1,5 +1,4 @@
use core_io::{BufRead, Error, ErrorKind, Read, Result as IoResult, Seek, SeekFrom, Write}; use core_io::{BufRead, Error, ErrorKind, Read, Result as IoResult, Seek, SeekFrom, Write};
use fatfs;
use libboard_zynq::sdio::{sd_card::SdCard, CmdTransferError}; use libboard_zynq::sdio::{sd_card::SdCard, CmdTransferError};
use log::debug; use log::debug;
use alloc::vec::Vec; use alloc::vec::Vec;

View File

@ -2,7 +2,7 @@
name = "libcortex_a9" name = "libcortex_a9"
version = "0.0.0" version = "0.0.0"
authors = ["M-Labs"] authors = ["M-Labs"]
edition = "2018" edition = "2021"
[features] [features]
power_saving = [] power_saving = []

View File

@ -1,10 +1,6 @@
#![no_std] #![no_std]
#![feature(never_type)] #![feature(never_type)]
#![feature(global_asm)]
#![feature(asm)]
#![allow(incomplete_features)]
#![feature(inline_const)] #![feature(inline_const)]
#![feature(const_fn_trait_bound)]
extern crate alloc; extern crate alloc;

View File

@ -1,6 +1,7 @@
use bit_field::BitField; use bit_field::BitField;
use super::{regs::*, asm::*, cache::*}; use super::{regs::*, asm::*, cache::*};
use libregister::RegisterW; use libregister::RegisterW;
use core::ptr::{addr_of_mut};
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(u8)] #[repr(u8)]
@ -136,7 +137,7 @@ pub struct L1Table {
impl L1Table { impl L1Table {
pub fn get() -> &'static mut Self { pub fn get() -> &'static mut Self {
unsafe { unsafe {
&mut L1_TABLE &mut *addr_of_mut!(L1_TABLE)
} }
} }

View File

@ -37,7 +37,7 @@ impl<'a, T> Sender<'a, T> where T: Clone {
notify_spin_lock(); notify_spin_lock();
if !prev.is_null() { if !prev.is_null() {
unsafe { unsafe {
Box::from_raw(prev); let _ = Box::from_raw(prev);
} }
} }
Ok(()) Ok(())
@ -91,7 +91,7 @@ impl<'a, T> Sender<'a, T> where T: Clone {
for v in self.list.iter() { for v in self.list.iter() {
let original = v.swap(core::ptr::null_mut(), Ordering::Relaxed); let original = v.swap(core::ptr::null_mut(), Ordering::Relaxed);
if !original.is_null() { if !original.is_null() {
Box::from_raw(original); let _ = Box::from_raw(original);
} }
} }
} }
@ -177,10 +177,7 @@ macro_rules! sync_channel {
{ {
use core::sync::atomic::{AtomicUsize, AtomicPtr}; use core::sync::atomic::{AtomicUsize, AtomicPtr};
use $crate::sync_channel::{Sender, Receiver}; use $crate::sync_channel::{Sender, Receiver};
const fn new_atomic() -> AtomicPtr<$t> { static LIST: [AtomicPtr<$t>; $cap + 1] = [const { AtomicPtr::new(core::ptr::null_mut()) }; $cap + 1];
AtomicPtr::new(core::ptr::null_mut())
}
static LIST: [AtomicPtr<$t>; $cap + 1] = [const { new_atomic() }; $cap + 1];
static WRITE: AtomicUsize = AtomicUsize::new(0); static WRITE: AtomicUsize = AtomicUsize::new(0);
static READ: AtomicUsize = AtomicUsize::new(0); static READ: AtomicUsize = AtomicUsize::new(0);
(Sender::new(&LIST, &WRITE, &READ), Receiver::new(&LIST, &WRITE, &READ)) (Sender::new(&LIST, &WRITE, &READ), Receiver::new(&LIST, &WRITE, &READ))

View File

@ -2,7 +2,7 @@
name = "libregister" name = "libregister"
version = "0.0.0" version = "0.0.0"
authors = ["M-Labs"] authors = ["M-Labs"]
edition = "2018" edition = "2021"
[dependencies] [dependencies]
vcell = "0.1" vcell = "0.1"

View File

@ -3,7 +3,7 @@ name = "libsupport_zynq"
description = "Software support for running in the Zynq PS" description = "Software support for running in the Zynq PS"
version = "0.0.0" version = "0.0.0"
authors = ["M-Labs"] authors = ["M-Labs"]
edition = "2018" edition = "2021"
[features] [features]
target_zc706 = ["libboard_zynq/target_zc706"] target_zc706 = ["libboard_zynq/target_zc706"]
@ -20,7 +20,7 @@ default = ["panic_handler", "dummy_irq_handler", "dummy_fiq_handler"]
[dependencies] [dependencies]
r0 = "1" r0 = "1"
compiler_builtins = "=0.1.49" compiler_builtins = "=0.1.108"
linked_list_allocator = { version = "0.8", default-features = false, features = ["const_mut_refs"] } linked_list_allocator = { version = "0.8", default-features = false, features = ["const_mut_refs"] }
libregister = { path = "../libregister" } libregister = { path = "../libregister" }
libcortex_a9 = { path = "../libcortex_a9" } libcortex_a9 = { path = "../libcortex_a9" }

View File

@ -1,5 +1,5 @@
use r0::zero_bss; use r0::zero_bss;
use core::ptr::write_volatile; use core::ptr::{addr_of, addr_of_mut, write_volatile};
use core::arch::asm; use core::arch::asm;
use libregister::{ use libregister::{
VolatileCell, VolatileCell,
@ -43,7 +43,7 @@ unsafe extern "C" fn boot_core0() -> ! {
let mpcore = mpcore::RegisterBlock::mpcore(); let mpcore = mpcore::RegisterBlock::mpcore();
mpcore.scu_invalidate.invalidate_all_cores(); mpcore.scu_invalidate.invalidate_all_cores();
zero_bss(&mut __bss_start, &mut __bss_end); zero_bss(addr_of_mut!(__bss_start), addr_of_mut!(__bss_end));
let mmu_table = mmu::L1Table::get() let mmu_table = mmu::L1Table::get()
.setup_flat_layout(); .setup_flat_layout();
@ -66,10 +66,12 @@ unsafe extern "C" fn boot_core0() -> ! {
unsafe extern "C" fn boot_core1() -> ! { unsafe extern "C" fn boot_core1() -> ! {
l1_cache_init(); l1_cache_init();
enable_fpu();
let mpcore = mpcore::RegisterBlock::mpcore(); let mpcore = mpcore::RegisterBlock::mpcore();
mpcore.scu_invalidate.invalidate_core1(); mpcore.scu_invalidate.invalidate_core1();
let mmu_table = mmu::L1Table::get(); let mmu_table = mmu::L1Table::get()
.setup_flat_layout();
mmu::with_mmu(mmu_table, || { mmu::with_mmu(mmu_table, || {
ACTLR.enable_smp(); ACTLR.enable_smp();
ACTLR.enable_prefetch(); ACTLR.enable_prefetch();
@ -132,7 +134,7 @@ impl Core1 {
CORE1_ENABLED.set(true); CORE1_ENABLED.set(true);
} }
// Flush cache-line // Flush cache-line
cache::dcc(unsafe { &CORE1_ENABLED }); cache::dcc(unsafe { &*addr_of!(CORE1_ENABLED) });
if sdram { if sdram {
cache::dccmvac(0); cache::dccmvac(0);
asm::dsb(); asm::dsb();
@ -153,7 +155,7 @@ impl Core1 {
pub fn disable(&self) { pub fn disable(&self) {
unsafe { unsafe {
CORE1_ENABLED.set(false); CORE1_ENABLED.set(false);
cache::dccmvac(&CORE1_ENABLED as *const _ as usize); cache::dccmvac(addr_of!(CORE1_ENABLED) as usize);
asm::dsb(); asm::dsb();
} }
self.restart(); self.restart();

View File

@ -3,8 +3,6 @@
#![feature(alloc_error_handler)] #![feature(alloc_error_handler)]
#![feature(panic_info_message)] #![feature(panic_info_message)]
#![feature(naked_functions)] #![feature(naked_functions)]
#![feature(global_asm)]
#![feature(asm)]
pub extern crate alloc; pub extern crate alloc;
pub extern crate compiler_builtins; pub extern crate compiler_builtins;

View File

@ -3,7 +3,7 @@ name = "szl"
description = "Simple Zynq Loader" description = "Simple Zynq Loader"
version = "0.1.0" version = "0.1.0"
authors = ["M-Labs"] authors = ["M-Labs"]
edition = "2018" edition = "2021"
[features] [features]
target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706", "libconfig/target_zc706"] target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706", "libconfig/target_zc706"]

View File

@ -7,7 +7,7 @@ extern crate log;
mod netboot; mod netboot;
use alloc::rc::Rc; use alloc::rc::Rc;
use core::mem; use core::{mem, ptr::{addr_of, addr_of_mut}};
use core_io::{Read, Seek}; use core_io::{Read, Seek};
use libboard_zynq::{ use libboard_zynq::{
self as zynq, self as zynq,
@ -116,18 +116,18 @@ pub fn main_core0() {
unsafe { unsafe {
let max_len = let max_len =
&__runtime_end as *const usize as usize - &__runtime_start as *const usize as usize; addr_of!(__runtime_end) as usize - addr_of!(__runtime_start) as usize;
match slcr::RegisterBlock::unlocked(|slcr| slcr.boot_mode.read().boot_mode_pins()) { match slcr::RegisterBlock::unlocked(|slcr| slcr.boot_mode.read().boot_mode_pins()) {
slcr::BootModePins::Jtag => netboot::netboot( slcr::BootModePins::Jtag => netboot::netboot(
&mut bootgen_file, &mut bootgen_file,
config, config,
&mut __runtime_start as *mut usize as *mut u8, addr_of_mut!(__runtime_start).cast(),
max_len, max_len,
), ),
slcr::BootModePins::SdCard => { slcr::BootModePins::SdCard => {
if boot_sd( if boot_sd(
&mut bootgen_file, &mut bootgen_file,
&mut __runtime_start as *mut usize as *mut u8, addr_of_mut!(__runtime_start).cast(),
max_len, max_len,
) )
.is_err() .is_err()
@ -137,7 +137,7 @@ pub fn main_core0() {
netboot::netboot( netboot::netboot(
&mut bootgen_file, &mut bootgen_file,
config, config,
&mut __runtime_start as *mut usize as *mut u8, addr_of_mut!(__runtime_start).cast(),
max_len, max_len,
) )
} }
@ -148,7 +148,7 @@ pub fn main_core0() {
netboot::netboot( netboot::netboot(
&mut bootgen_file, &mut bootgen_file,
config, config,
&mut __runtime_start as *mut usize as *mut u8, addr_of_mut!(__runtime_start).cast(),
max_len, max_len,
) )
} }