convert baremetal to use autostatics

This commit is contained in:
bunnie 2025-09-21 21:52:38 +08:00
parent 110d39936d
commit 6e19c4b871
2 changed files with 25 additions and 43 deletions

View file

@ -33,22 +33,6 @@ pub const SYSTEM_CLOCK_FREQUENCY: u32 = 800_000_000;
pub const SYSTEM_TICK_INTERVAL_MS: u32 = 1; pub const SYSTEM_TICK_INTERVAL_MS: u32 = 1;
pub fn early_init() { pub fn early_init() {
// Define the .data region - bootstrap baremetal using these hard-coded parameters.
// Define the .data region - bootstrap baremetal using these hard-coded parameters.
const DATA_ORIGIN: usize = 0x61000000;
const DATA_INIT: [(usize, u32); 5] = [(0x0, 0x2), (0x558, 0x1), (0x55b, 0x1), (0x55e, 0x1), (0x563, 0x1)];
// Clear .data, .bss, .stack, .heap regions & setup .data values
unsafe {
let data_ptr = DATA_ORIGIN as *mut u32;
for i in 0..DATA_SIZE_BYTES / size_of::<u32>() {
data_ptr.add(i).write_volatile(0);
}
for (offset, data) in DATA_INIT {
data_ptr.add(offset).write_volatile(data);
}
}
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32); let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
#[cfg(not(feature = "bao1x-evb"))] #[cfg(not(feature = "bao1x-evb"))]
{ {
@ -178,35 +162,32 @@ pub fn early_init() {
rbist.wo(utra::rbist_wrp::SFRCR_TRM, (14 << 16) | 0b001_010_00_0_0_000_0_00); rbist.wo(utra::rbist_wrp::SFRCR_TRM, (14 << 16) | 0b001_010_00_0_0_000_0_00);
rbist.wo(utra::rbist_wrp::SFRAR_TRM, 0x5a); rbist.wo(utra::rbist_wrp::SFRAR_TRM, 0x5a);
} }
let perclk = unsafe { init_clock_asic(SYSTEM_CLOCK_FREQUENCY) };
// test memory // Now that SRAM trims are setup, initialize all the statics by writing to memory.
// NOTE: this smashes stack - need adjustment if this is going to be a "fixture" // For baremetal, the statics structure is just at the flash base.
/* const STATICS_LOC: usize = FLASH_BASE;
crate::println!("\ntest memory...");
let base = 0x6108_5000; // safety: this data structure is pre-loaded by the image loader and is guaranteed to
let mem_range = unsafe { // only have representable, valid values that are aligned according to the repr(C) spec
core::slice::from_raw_parts_mut(base as *mut u32, (0x6120_0000 - base) / core::mem::size_of::<u32>()) let statics_in_rom: &bao1x_api::StaticsInRom =
}; unsafe { (STATICS_LOC as *const bao1x_api::StaticsInRom).as_ref().unwrap() };
let mut state = 1; assert!(statics_in_rom.version == bao1x_api::STATICS_IN_ROM_VERSION, "Can't find valid statics table");
for m in mem_range.iter_mut() {
state = lfsr_next_u32(state); // Clear .data, .bss, .stack, .heap regions & setup .data values
*m = state; // Safety: only safe if the values computed by the loader are correct.
} unsafe {
state = 1; let data_ptr = statics_in_rom.data_origin as *mut u32;
let mut failures = 0; for i in 0..statics_in_rom.data_size_bytes as usize / size_of::<u32>() {
for m in mem_range.iter() { data_ptr.add(i).write_volatile(0);
state = lfsr_next_u32(state); }
if state != *m { for &(offset, data) in &statics_in_rom.poke_table[..statics_in_rom.valid_pokes as usize] {
failures += 1; data_ptr.add(offset as usize).write_volatile(data);
} }
} }
if failures != 0 {
crate::println!("fast mem test failed"); // set the clock
} else { let perclk = unsafe { init_clock_asic(SYSTEM_CLOCK_FREQUENCY) };
crate::println!("fast mem test passed");
}
*/
crate::println!("scratch page: {:x}, heap start: {:x}", SCRATCH_PAGE, HEAP_START); crate::println!("scratch page: {:x}, heap start: {:x}", SCRATCH_PAGE, HEAP_START);
// setup heap alloc // setup heap alloc

View file

@ -1,7 +1,8 @@
/* bottom 256k reserved for copying code into RAM for JTAG-booting targets */ /* bottom 256k reserved for copying code into RAM for JTAG-booting targets */
MEMORY MEMORY
{ {
FLASH : ORIGIN = 0x60000000, LENGTH = 256k /* Note: ORIGIN is updated by xtask for baremetal targets */
FLASH : ORIGIN = 0x60000100, LENGTH = 256k - 256
RAM : ORIGIN = 0x61000000, LENGTH = 2048k RAM : ORIGIN = 0x61000000, LENGTH = 2048k
} }