Merge pull request #699 from betrusted-io/dabao-sample

Dabao sample
This commit is contained in:
bunnie 2025-10-16 23:35:49 +08:00 committed by GitHub
commit 07dd14057a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 46 additions and 4 deletions

2
.gitignore vendored
View file

@ -4,6 +4,8 @@ target
/emulation/obj
# auto-generated
services/xous-ticktimer/src/version.rs
bao1x-boot/boot0/src/version.rs
bao1x-boot/boot1/src/version.rs
apps/i18n.json
services/gam/src/apps.rs
services/status/src/app_autogen.rs

View file

@ -0,0 +1,8 @@
# Binary Data Used in Programming
## One-Way Counter Defaults
These blobs are burned into the one-way counter array to force some counters to be
tripped, thus pre-configuring the behavior of a given board.
* `dabao-owc.bin`: Sets board type to `dabao`, and sets wait on boot to true

Binary file not shown.

View file

@ -8,6 +8,7 @@ mod asm;
mod platform;
#[cfg(feature = "unsafe-dev")]
mod repl;
mod version;
#[cfg(feature = "unsafe-dev")]
use alloc::collections::VecDeque;
#[cfg(feature = "unsafe-dev")]
@ -51,7 +52,7 @@ pub fn uart_irq_handler() {
#[export_name = "rust_entry"]
pub unsafe extern "C" fn rust_entry() -> ! {
crate::platform::early_init();
crate::println!("\n~~boot0 up!~~\n");
crate::println!("\n~~boot0 up! ({})~~\n", crate::version::SEMVER);
#[cfg(feature = "unsafe-dev")]
let mut repl = crate::repl::Repl::new();

View file

@ -8,6 +8,7 @@ mod platform;
mod repl;
mod secboot;
mod uf2;
mod version;
use alloc::collections::VecDeque;
use core::{
@ -28,6 +29,8 @@ use crate::platform::usb::glue;
use crate::secboot::boot_or_die;
use crate::{delay, platform::irq::disable_all_irqs};
const RELEASE_DESCRIPTION: &'static str = "Dabao Alpha-0 Sample";
static UART_RX: Mutex<RefCell<VecDeque<u8>>> = Mutex::new(RefCell::new(VecDeque::new()));
#[allow(dead_code)]
static USB_RX: Mutex<RefCell<VecDeque<u8>>> = Mutex::new(RefCell::new(VecDeque::new()));
@ -72,7 +75,7 @@ pub unsafe extern "C" fn rust_entry() -> ! {
crate::println_d!("TX_IDLE: {:?}", crate::platform::usb::TX_IDLE.load(Ordering::SeqCst));
let perclk: u32;
(board_type, perclk) = crate::platform::early_init(board_type);
crate::println!("\n~~Boot1 up!~~\n");
crate::println!("\n~~Boot1 up! ({}: {})~~\n", crate::version::SEMVER, RELEASE_DESCRIPTION);
crate::println!("Configured board type: {:?}", board_type);
if board_type == BoardTypeCoding::Baosec {
IS_BAOSEC.store(true, Ordering::SeqCst);

View file

@ -208,6 +208,14 @@ impl Repl {
"Boot partition is: {:?}",
owc.get_decoded::<bao1x_api::offsets::AltBootCoding>()
);
crate::println!("Semver is: {}", crate::version::SEMVER);
crate::println!("Description is: {}", crate::RELEASE_DESCRIPTION);
// TODO: replace this with a proper API, this is a hack to allow an initial
// alpha run of boards to be churned out on short notice. The hard-coded number
// below ostensibly belongs to "data slot 0". For this run, it's just an incrementing
// number, but in the future it might be a truncated hash, or randomly generated number.
let sn = unsafe { core::slice::from_raw_parts(0x603d_c000 as *const u32, 4) };
crate::println!("Device serializer: {:08x}-{:08x}-{:08x}-{:08x}", sn[3], sn[2], sn[1], sn[0]);
crate::println!("Revocations:");
crate::println!("Stage key0 key1 key2 key3");
let key_array = [

View file

@ -245,7 +245,7 @@ pub fn sign_image(
// Write the header
dest_file.write_all(&header.as_ref()[..UNSIGNED_LEN])?;
println!("dest_file wrote {}, {}", dest_file.len(), UNSIGNED_LEN);
// println!("dest_file wrote {}, {}", dest_file.len(), UNSIGNED_LEN);
if defile {
println!(

View file

@ -18,6 +18,8 @@ pub(crate) fn generate_version(add_timestamp: bool) {
let semver = String::from_utf8_lossy(&gitver);
let version_file = "services/xous-ticktimer/src/version.rs";
let boot0_version_file = "bao1x-boot/boot0/src/version.rs";
let boot1_version_file = "bao1x-boot/boot1/src/version.rs";
// Read the existing file to see if it needs to be updated.
let mut existing_data = Vec::new();
@ -39,12 +41,14 @@ pub(crate) fn generate_version(add_timestamp: bool) {
write!(new_data, "#[allow(dead_code)]\npub const TIMESTAMP: &'static str = \"unavailable\";\n")
.expect("couldn't add our timestamp");
}
let mut semver_code = Vec::new();
writeln!(
new_data,
semver_code,
"pub const SEMVER: &'static str = \"{}\";",
semver.strip_suffix("\r\n").or(semver.strip_suffix('\n')).unwrap_or(&semver)
)
.expect("couldn't add our semver");
new_data.extend_from_slice(&semver_code);
if existing_data != new_data {
let mut vfile = OpenOptions::new()
@ -55,6 +59,22 @@ pub(crate) fn generate_version(add_timestamp: bool) {
.open(version_file)
.expect("Can't open our version file for writing");
vfile.write_all(&new_data).expect("couldn't write new timestamp to version.rs");
let mut vfile = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(boot0_version_file)
.expect("Can't open our version file for writing");
vfile.write_all(&semver_code).expect("couldn't write semver to version.rs");
let mut vfile = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(boot1_version_file)
.expect("Can't open our version file for writing");
vfile.write_all(&semver_code).expect("couldn't write semver to version.rs");
}
}