From 9a008730f63ae9a2150d6ce863431af92fa3ad1c Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 31 Jan 2026 02:08:45 +0800 Subject: [PATCH] add the ability to specify regions for apps; eliminate default apps Default apps for base xous configs are now eliminated - this allows third party builds to add their apps without having to delete the default apps used for initial testing (the upshot is that the CI scripts elsewhere are now all modified to include the apps I'm using to test the system; which is fine). So now, `dabao` and `baosec` build what is a baseline set of services that I think are expected in either platform. In the case of dabao, apps get stuck in the detached-app area; in the case of baosec, apps are stick in swap. So: `cargo xtask baosec bao-console vault2` by default sticks the app `bao-console` and `vault2` into swap. If you want one of these programs to go into RRAM instead, you would specify the build like this: `cargo xtask baosec bao-console~flash vault2` The `~` syntax indicates that the thing to the left of `~` is the name of the app; and to the right is a region spec, one of: [swap, flash, ram]. No checking is done that these regions are valid or even good for placing these things, the image just tries its best to whack 'em in there. If you blow out the size of the kernel, at least, a warning will be emitted. This change enables more flexible out-of-tree options for developers who don't want to build the whole Xous kernel, but at the moment, caveat hacker - things are still in flux and under heavy development. I think in about 2-3 months things will settle down enough that we'll cut a release and then the APIs should be cleaner/more stable, but for now anyone developing with a pre-release dabao board is recommended to either build kernel from scratch or at least fetch the latest CI image off of the CI server if things seem squirrelly. --- .gitignore | 2 ++ xtask/src/builder.rs | 37 ++++++++++++++++++++++++++++++++----- xtask/src/main.rs | 15 ++++++++++----- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index a4c63ae59..592ec7267 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,8 @@ buildpush.ps1 tools/test-backup-analyze.sh todo.md notes/ +# no uf2 files in the root directory +/*.uf2 # SSH id file for convenience /id_pi diff --git a/xtask/src/builder.rs b/xtask/src/builder.rs index 331e8762f..1186f5e55 100644 --- a/xtask/src/builder.rs +++ b/xtask/src/builder.rs @@ -84,17 +84,41 @@ impl CrateSpec { } } } + +/// Detects a pattern of "crate~region", as in "vault2~swap" to specify where +/// a crate should go. The region is case-insensitive. This feature is added to help +/// give more control for bao1x builds, but as of yet no configurations need to +/// use anything other than the default locations, so this is only lightly tested. +pub fn region_from_name(name_spec: &str, default_region: LoaderRegion) -> (&str, LoaderRegion) { + if name_spec.contains('~') { + let (name, spec) = name_spec.split_once('~').unwrap(); + let region = match spec.to_ascii_lowercase().as_str() { + "swap" => LoaderRegion::Swap, + "flash" => LoaderRegion::Flash, + "ram" => LoaderRegion::Ram, + _ => LoaderRegion::Invalid, + }; + (name, region) + } else { + (name_spec, default_region) + } +} + impl From<&str> for CrateSpec { fn from(spec: &str) -> CrateSpec { // remote crates are specified as "name^version", i.e. "xous-names^0.9.9" if spec.contains('^') { let (name, version) = spec.split_once('^').expect("couldn't parse crate specifier"); - CrateSpec::CratesIo(name.to_string(), version.to_string(), LoaderRegion::Ram) + let (name, region) = region_from_name(name, LoaderRegion::Ram); + CrateSpec::CratesIo(name.to_string(), version.to_string(), region) + // prebuilt crates are specified as "name#url" // i.e. "espeak-embedded#https://ci.betrusted.io/job/espeak-embedded/lastSuccessfulBuild/artifact/target/riscv32imac-unknown-xous-elf/release/" } else if spec.contains('#') { let (name, url) = spec.split_once('#').expect("couldn't parse crate specifier"); - CrateSpec::Prebuilt(name.to_string(), url.to_string(), LoaderRegion::Ram) + let (name, region) = region_from_name(name, LoaderRegion::Ram); + CrateSpec::Prebuilt(name.to_string(), url.to_string(), region) + // local files are specified as paths, which, at a minimum include one directory separator "/" or "\" // i.e. "./local_file" // Note that this is after a test for the '#' character, so that disambiguates URL slashes @@ -104,12 +128,15 @@ impl From<&str> for CrateSpec { //optionally a BinaryFile can have a name associated with it as "name:path" if spec.find(':').is_some() { let (name, path) = spec.split_once(':').unwrap(); - CrateSpec::BinaryFile(Some(name.to_string()), path.to_string(), LoaderRegion::Ram) + let (name, region) = region_from_name(name, LoaderRegion::Ram); + CrateSpec::BinaryFile(Some(name.to_string()), path.to_string(), region) } else { - CrateSpec::BinaryFile(None, spec.to_string(), LoaderRegion::Ram) + let (name, region) = region_from_name(spec, LoaderRegion::Ram); + CrateSpec::BinaryFile(None, name.to_string(), region) } } else { - CrateSpec::Local(spec.to_string(), LoaderRegion::Ram) + let (name, region) = region_from_name(spec, LoaderRegion::Ram); + CrateSpec::Local(name.to_string(), region) } } } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index f9843a9d9..2ac6ab13e 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -814,7 +814,7 @@ fn main() -> Result<(), Box> { let bao_rram_pkgs = ["xous-ticktimer", "keystore", "xous-log", "xous-names", "usb-bao1x", "bao1x-hal-service"] .to_vec(); - let bao_app_pkgs: Vec<&'static str> = ["dabao-console"].to_vec(); + let bao_app_pkgs: Vec<&'static str> = [].to_vec(); builder.add_loader_feature("debug-print"); builder.add_kernel_feature("v2p"); @@ -829,7 +829,11 @@ fn main() -> Result<(), Box> { builder.add_service(service, LoaderRegion::Flash); } builder.add_apps(&bao_app_pkgs); - builder.add_apps(&get_cratespecs()); + + for app in get_cratespecs() { + let (name, region) = crate::builder::region_from_name(&app, LoaderRegion::Flash); + builder.add_service(name, region); + } } // ------ ARM hardware image configs ------ @@ -1177,7 +1181,7 @@ fn baosec_common(builder: &mut Builder) -> std::io::Result<()> { "bao-video", ] .to_vec(); - let bao_swap_pkgs = ["bao-console", "vault2"].to_vec(); + let bao_swap_pkgs = [].to_vec(); if !builder.is_swap_set() { // reserve 3MiB for system services: ultimately, "pddb, modals, and bao-video" builder.set_swap(0, bao1x_api::offsets::baosec::SWAP_RAM_LEN as _); @@ -1213,12 +1217,13 @@ fn baosec_common(builder: &mut Builder) -> std::io::Result<()> { for service in bao_rram_pkgs { builder.add_service(service, LoaderRegion::Flash); } - builder.add_services(&get_cratespecs()); for service in bao_swap_pkgs { builder.add_service(service, LoaderRegion::Swap); } + for app in get_cratespecs() { - builder.add_service(&app, LoaderRegion::Swap); + let (name, region) = crate::builder::region_from_name(&app, LoaderRegion::Swap); + builder.add_service(name, region); } // builder.add_feature("modal-testing"); Ok(())