mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
add a progress bar to loader for baosec targets
The OS image for baosec is substantially larger and requires more operations, so a progress bar makes the screen-up experience a little more tolerable.
This commit is contained in:
parent
d4933e96a4
commit
5f20953bf9
4 changed files with 148 additions and 8 deletions
|
|
@ -470,6 +470,15 @@ fn boot_sequence(
|
||||||
_perclk_freq: u32,
|
_perclk_freq: u32,
|
||||||
detached_app: bool,
|
detached_app: bool,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
let mut iox = bao1x_hal::iox::Iox::new(utralib::utra::iox::HW_IOX_BASE as *mut u32);
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
let mut udma_global = bao1x_hal::udma::GlobalConfig::new();
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
let mut oled = crate::platform::oled_init(&mut iox, &mut udma_global, _perclk_freq);
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
crate::platform::progress_bar(&mut oled, 0);
|
||||||
|
|
||||||
// Store the initial boot config on the stack. We don't know
|
// Store the initial boot config on the stack. We don't know
|
||||||
// where in heap this memory will go.
|
// where in heap this memory will go.
|
||||||
#[allow(clippy::cast_ptr_alignment)] // This test only works on 32-bit systems
|
#[allow(clippy::cast_ptr_alignment)] // This test only works on 32-bit systems
|
||||||
|
|
@ -525,8 +534,19 @@ fn boot_sequence(
|
||||||
// cold boot path
|
// cold boot path
|
||||||
println!("No suspend marker found, doing a cold boot!");
|
println!("No suspend marker found, doing a cold boot!");
|
||||||
clear_ram(&mut cfg);
|
clear_ram(&mut cfg);
|
||||||
phase_1(&mut cfg, detached_app);
|
|
||||||
phase_2(&mut cfg, env_variables);
|
#[cfg(feature = "board-baosec")]
|
||||||
|
{
|
||||||
|
phase_1(&mut cfg, detached_app, Some(&mut oled));
|
||||||
|
phase_2(&mut cfg, env_variables, Some(&mut oled));
|
||||||
|
crate::platform::progress_bar(&mut oled, 100);
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "board-baosec"))]
|
||||||
|
{
|
||||||
|
phase_1(&mut cfg, detached_app, None);
|
||||||
|
phase_2(&mut cfg, env_variables, None);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "debug-print", feature = "swap"))]
|
#[cfg(any(feature = "debug-print", feature = "swap"))]
|
||||||
if VDBG || SDBG {
|
if VDBG || SDBG {
|
||||||
check_load(&mut cfg);
|
check_load(&mut cfg);
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ pub struct InitialProcess {
|
||||||
/// We don't memorize the allocated results (in part because we don't have malloc/alloc to stick
|
/// We don't memorize the allocated results (in part because we don't have malloc/alloc to stick
|
||||||
/// the table, and we don't know a priori how big it will be); we simply memorize the maximum extent,
|
/// the table, and we don't know a priori how big it will be); we simply memorize the maximum extent,
|
||||||
/// after which we allocate the book-keeping tables.
|
/// after which we allocate the book-keeping tables.
|
||||||
pub fn phase_1(cfg: &mut BootConfig, detached_app: bool) {
|
pub fn phase_1(cfg: &mut BootConfig, detached_app: bool, fb: Option<&mut dyn ux_api::minigfx::FrameBuffer>) {
|
||||||
// Allocate space for the stack pointer.
|
// Allocate space for the stack pointer.
|
||||||
// The bootloader should have placed the stack pointer at the end of RAM
|
// The bootloader should have placed the stack pointer at the end of RAM
|
||||||
// prior to jumping to our program. Reserve space for the stack, so that it does not smash
|
// prior to jumping to our program. Reserve space for the stack, so that it does not smash
|
||||||
|
|
@ -161,7 +161,7 @@ pub fn phase_1(cfg: &mut BootConfig, detached_app: bool) {
|
||||||
// Copy the processes to RAM, if requested.
|
// Copy the processes to RAM, if requested.
|
||||||
if !cfg.no_copy {
|
if !cfg.no_copy {
|
||||||
println!("Copying processes");
|
println!("Copying processes");
|
||||||
copy_processes(cfg);
|
copy_processes(cfg, fb);
|
||||||
}
|
}
|
||||||
// activate this to debug stack-smashing during copy_process(). The RPT is the first structure that gets
|
// activate this to debug stack-smashing during copy_process(). The RPT is the first structure that gets
|
||||||
// smashed if the stack overflows! It should be all 0's if the stack did not overrun.
|
// smashed if the stack overflows! It should be all 0's if the stack did not overrun.
|
||||||
|
|
@ -499,9 +499,10 @@ impl TagType {
|
||||||
|
|
||||||
/// Copy program data from the SPI flash into newly-allocated RAM
|
/// Copy program data from the SPI flash into newly-allocated RAM
|
||||||
/// located at the end of memory space.
|
/// located at the end of memory space.
|
||||||
fn copy_processes(cfg: &mut BootConfig) {
|
fn copy_processes(cfg: &mut BootConfig, mut fb: Option<&mut dyn ux_api::minigfx::FrameBuffer>) {
|
||||||
let mut _pid = 1;
|
let mut _pid = 1;
|
||||||
for tag in cfg.args.iter() {
|
let arg_len = cfg.args.iter().count();
|
||||||
|
for (i, tag) in cfg.args.iter().enumerate() {
|
||||||
let tag_type = TagType::from(tag.name);
|
let tag_type = TagType::from(tag.name);
|
||||||
match tag_type {
|
match tag_type {
|
||||||
TagType::IniF | TagType::IniE => {
|
TagType::IniF | TagType::IniE => {
|
||||||
|
|
@ -879,6 +880,14 @@ fn copy_processes(cfg: &mut BootConfig) {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
if let Some(ref mut fb) = fb {
|
||||||
|
let start = 5;
|
||||||
|
let end = 70;
|
||||||
|
let increment = (end - start) / arg_len;
|
||||||
|
let _percentage = start + increment * i;
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
crate::platform::progress_bar(*fb, _percentage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use ux_api::minigfx::FrameBuffer;
|
||||||
#[cfg(feature = "swap")]
|
#[cfg(feature = "swap")]
|
||||||
use xous::arch::{SWAP_CFG_VADDR, SWAP_COUNT_VADDR, SWAP_PT_VADDR};
|
use xous::arch::{SWAP_CFG_VADDR, SWAP_COUNT_VADDR, SWAP_PT_VADDR};
|
||||||
|
|
||||||
|
|
@ -9,7 +10,7 @@ use crate::{env::EnvVariables, *};
|
||||||
///
|
///
|
||||||
/// Set up all the page tables, allocating new root page tables for SATPs and corresponding
|
/// Set up all the page tables, allocating new root page tables for SATPs and corresponding
|
||||||
/// sub-pages starting from the base of previously copied process data.
|
/// sub-pages starting from the base of previously copied process data.
|
||||||
pub fn phase_2(cfg: &mut BootConfig, env_variables: EnvVariables) {
|
pub fn phase_2(cfg: &mut BootConfig, env_variables: EnvVariables, mut fb: Option<&mut dyn FrameBuffer>) {
|
||||||
let args = cfg.args;
|
let args = cfg.args;
|
||||||
|
|
||||||
// This is the offset in RAM where programs are loaded from.
|
// This is the offset in RAM where programs are loaded from.
|
||||||
|
|
@ -41,7 +42,8 @@ pub fn phase_2(cfg: &mut BootConfig, env_variables: EnvVariables) {
|
||||||
#[cfg(feature = "bao1x")]
|
#[cfg(feature = "bao1x")]
|
||||||
trng.setup_raw_generation(32); // this is safe to call multiple times to affirm the TRNG state
|
trng.setup_raw_generation(32); // this is safe to call multiple times to affirm the TRNG state
|
||||||
|
|
||||||
for tag in args.iter() {
|
let arg_len = args.iter().count();
|
||||||
|
for (i, tag) in args.iter().enumerate() {
|
||||||
let mut env_header = crate::env::EnvHeader::default();
|
let mut env_header = crate::env::EnvHeader::default();
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut pid_env = env_variables.clone();
|
let mut pid_env = env_variables.clone();
|
||||||
|
|
@ -104,6 +106,14 @@ pub fn phase_2(cfg: &mut BootConfig, env_variables: EnvVariables) {
|
||||||
}
|
}
|
||||||
process_offset -= load_size_rounded;
|
process_offset -= load_size_rounded;
|
||||||
}
|
}
|
||||||
|
if let Some(ref mut fb) = fb {
|
||||||
|
let start = 70;
|
||||||
|
let end = 95;
|
||||||
|
let increment = (end - start) / arg_len;
|
||||||
|
let _percentage = start + increment * i;
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
crate::platform::progress_bar(*fb, _percentage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Done loading.");
|
println!("Done loading.");
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,13 @@ use bao1x_api::signatures::SIGBLOCK_LEN;
|
||||||
use bao1x_api::*;
|
use bao1x_api::*;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use bao1x_hal::iox::Iox;
|
use bao1x_hal::iox::Iox;
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
use bao1x_hal::sh1107::Oled128x128;
|
||||||
#[cfg(feature = "bao1x")]
|
#[cfg(feature = "bao1x")]
|
||||||
use bao1x_hal::udma;
|
use bao1x_hal::udma;
|
||||||
use utralib::generated::*;
|
use utralib::generated::*;
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
use ux_api::minigfx::FrameBuffer;
|
||||||
|
|
||||||
// Notes about the reset vector location
|
// Notes about the reset vector location
|
||||||
// This can be set using fuses in the IFR (also called 'info') region
|
// This can be set using fuses in the IFR (also called 'info') region
|
||||||
|
|
@ -211,6 +215,26 @@ pub fn early_init_hw() -> u32 {
|
||||||
perclk
|
perclk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
pub fn oled_init<'a>(
|
||||||
|
iox: &'a mut Iox,
|
||||||
|
udma_global: &'a mut bao1x_hal::udma::GlobalConfig,
|
||||||
|
perclk: u32,
|
||||||
|
) -> Oled128x128<'a> {
|
||||||
|
use ux_api::minigfx::FrameBuffer;
|
||||||
|
let mut sh1107 = bao1x_hal::sh1107::Oled128x128::new(
|
||||||
|
bao1x_hal::sh1107::MainThreadToken::new(),
|
||||||
|
perclk,
|
||||||
|
iox,
|
||||||
|
udma_global,
|
||||||
|
);
|
||||||
|
sh1107.init();
|
||||||
|
sh1107.buffer_mut().fill(0xFFFF_FFFF);
|
||||||
|
sh1107.blit_screen(&ux_api::bitmaps::baochip128x128::BITMAP);
|
||||||
|
sh1107.draw();
|
||||||
|
sh1107
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "board-dabao")]
|
#[cfg(feature = "board-dabao")]
|
||||||
pub fn setup_console<T: IoSetup + IoGpio>(
|
pub fn setup_console<T: IoSetup + IoGpio>(
|
||||||
board_type: &bao1x_api::BoardTypeCoding,
|
board_type: &bao1x_api::BoardTypeCoding,
|
||||||
|
|
@ -316,3 +340,80 @@ pub fn delay_at_sysfreq(ms: usize, sysclk_freq: u32) {
|
||||||
timer.wfo(utra::timer0::EV_PENDING_ZERO, 1);
|
timer.wfo(utra::timer0::EV_PENDING_ZERO, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
/// Progress is a number from 0-100 that represents how complete the operation is.
|
||||||
|
pub fn progress_bar(fb: &mut dyn FrameBuffer, progress: usize) {
|
||||||
|
use ux_api::bitmaps::baochip128x128::MARQUEE_BELOW;
|
||||||
|
use ux_api::minigfx::{DrawStyle, PixelColor, Point, Rectangle};
|
||||||
|
|
||||||
|
const DISPLAY_WIDTH: isize = 128;
|
||||||
|
const DISPLAY_HEIGHT: isize = 128;
|
||||||
|
|
||||||
|
/// Left/right margin of the progress bar relative to the display edges, in pixels.
|
||||||
|
const PROGRESS_BAR_MARGIN: isize = 8;
|
||||||
|
|
||||||
|
/// Maximum height of the progress bar, in pixels.
|
||||||
|
const PROGRESS_BAR_HEIGHT: isize = 8;
|
||||||
|
|
||||||
|
// cast the fb into a concrete type that can be used with the minigfx::op
|
||||||
|
let mut fb = ux_api::minigfx::DynFb(fb);
|
||||||
|
|
||||||
|
let progress = progress.min(100);
|
||||||
|
|
||||||
|
// The available vertical region is between MARQUEE_BELOW and the bottom of the display.
|
||||||
|
let region_top = MARQUEE_BELOW as isize;
|
||||||
|
let region_height = DISPLAY_HEIGHT - region_top;
|
||||||
|
|
||||||
|
// Center the bar vertically within that region.
|
||||||
|
let bar_top = region_top + (region_height - PROGRESS_BAR_HEIGHT) / 2;
|
||||||
|
let bar_bottom = bar_top + PROGRESS_BAR_HEIGHT; // exclusive
|
||||||
|
|
||||||
|
if progress == 0 {
|
||||||
|
// blank out the marquee
|
||||||
|
ux_api::minigfx::op::rectangle(
|
||||||
|
&mut fb,
|
||||||
|
Rectangle::new_with_style(
|
||||||
|
Point::new(0, MARQUEE_BELOW as isize),
|
||||||
|
Point::new(DISPLAY_WIDTH, DISPLAY_HEIGHT),
|
||||||
|
DrawStyle::new(ux_api::minigfx::PixelColor::Dark, ux_api::minigfx::PixelColor::Dark, 1),
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Outline (always full width) ---
|
||||||
|
ux_api::minigfx::op::rectangle(
|
||||||
|
&mut fb,
|
||||||
|
Rectangle {
|
||||||
|
tl: Point { x: PROGRESS_BAR_MARGIN, y: bar_top },
|
||||||
|
br: Point { x: DISPLAY_WIDTH - PROGRESS_BAR_MARGIN, y: bar_bottom },
|
||||||
|
style: DrawStyle { fill_color: None, stroke_color: Some(PixelColor::Light), stroke_width: 1 },
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// --- Fill (grows left to right with progress) ---
|
||||||
|
// Interior is 1px inset from the stroke on every side.
|
||||||
|
let inner_x0 = PROGRESS_BAR_MARGIN + 1;
|
||||||
|
let inner_x1 = DISPLAY_WIDTH - PROGRESS_BAR_MARGIN - 1;
|
||||||
|
let inner_width = inner_x1 - inner_x0;
|
||||||
|
|
||||||
|
let fill_width = (inner_width * progress as isize) / 100;
|
||||||
|
|
||||||
|
if fill_width > 0 {
|
||||||
|
ux_api::minigfx::op::rectangle(
|
||||||
|
&mut fb,
|
||||||
|
Rectangle {
|
||||||
|
tl: Point { x: inner_x0, y: bar_top + 1 },
|
||||||
|
br: Point { x: inner_x0 + fill_width, y: bar_bottom - 1 },
|
||||||
|
style: DrawStyle { fill_color: Some(PixelColor::Light), stroke_color: None, stroke_width: 0 },
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fb.0.draw();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue