diff --git a/xtask/src/builder.rs b/xtask/src/builder.rs index a64cc23db..826fe1837 100644 --- a/xtask/src/builder.rs +++ b/xtask/src/builder.rs @@ -153,6 +153,8 @@ pub(crate) struct Builder { change_target: bool, baremetal: bool, sigblock_size: usize, + board: String, + detached_app_features: Vec, } impl Builder { @@ -184,6 +186,8 @@ impl Builder { change_target: false, baremetal: false, sigblock_size: 4096, + board: String::new(), + detached_app_features: Vec::new(), } } @@ -463,6 +467,12 @@ impl Builder { self } + pub fn set_board(&mut self, board: &str) -> &mut Builder { + assert!(self.board.len() == 0, "attempt to set board parameter twice!"); + self.board.push_str(board); + self + } + /// remove a feature previously added by a previous call #[allow(dead_code)] pub fn remove_feature(&mut self, feature: &str) -> &mut Builder { @@ -479,6 +489,11 @@ impl Builder { self } + pub fn add_detached_app_feature(&mut self, feature: &str) -> &mut Builder { + self.detached_app_features.push(feature.into()); + self + } + /// add a feature to be passed on to just the loader #[allow(dead_code)] pub fn add_kernel_feature(&mut self, feature: &str) -> &mut Builder { @@ -708,6 +723,8 @@ impl Builder { } else if self.utra_target.contains("bao1x") { self.features.push("bao1x".into()); self.features.push(format!("utralib/{}", &self.utra_target)); + self.detached_app_features.push("bao1x".into()); + self.detached_app_features.push(format!("utralib/{}", &self.utra_target)); self.kernel_features.push("bao1x".into()); self.kernel_features.push(format!("utralib/{}", &self.utra_target)); self.loader_features.push("bao1x".into()); @@ -742,15 +759,20 @@ impl Builder { _ => {} } } - generate_app_menus(&app_names); - let mut services_path = self.builder( - &[&self.services[..], &self.apps[..]].concat(), - &self.features, - &self.target.as_deref(), - self.stream, - &[], - false, - )?; + let mut services_path = if self.board == "board-dabao" { + // apps are built separately on dabao + self.builder(&self.services, &self.features, &self.target.as_deref(), self.stream, &[], false)? + } else { + generate_app_menus(&app_names); + self.builder( + &[&self.services[..], &self.apps[..]].concat(), + &self.features, + &self.target.as_deref(), + self.stream, + &[], + false, + )? + }; // ------ either stop here, create an image, or launch hosted mode ------ if self.no_image { @@ -941,6 +963,19 @@ impl Builder { } } + // ------ build "detached" apps ------ + if self.board == "board-dabao" { + let detached_app_path = self.builder( + &self.apps, + &self.detached_app_features, + &self.target.as_deref(), + self.stream, + &[], + false, + )?; + self.create_detached_image(&detached_app_path)?; + } + // ------ build the kernel ------ let mut kernel_extra = vec![]; if self.kernel_disable_defaults { @@ -1224,6 +1259,71 @@ impl Builder { Ok(project_root().join(output_file)) } + fn create_detached_image(&self, inif: &[String]) -> Result { + assert!(self.board == "board-dabao", "Detached app images are only supported on dabao target"); + let stream = self.stream.as_str(); + let mut args = vec!["run", "--package", "tools", "--bin", "create-detached-app"]; + args.push("--features"); + args.push("bao1x"); + args.push("--"); + + let mut output_file = PathBuf::new(); + output_file.push("target"); + output_file.push(self.target.as_ref().expect("target")); + output_file.push(stream); + output_file.push("app-presign.img"); + args.push(output_file.to_str().unwrap()); + + for i in inif { + args.push("--inif"); + // strip '@' version specifiers out of the package names, if they exist. + let i = if i.contains('@') { i.split('@').next().unwrap() } else { i }; + args.push(i); + } + + args.push("--detached-offset"); + let detached_offset = + format!("{}", bao1x_api::offsets::dabao::APP_RRAM_START - bao1x_api::offsets::KERNEL_START); + args.push(&detached_offset); + let status = Command::new(cargo()).current_dir(project_root()).args(&args).status()?; + + if !status.success() { + return Err("cargo build failed".into()); + } + + let mut app_img_path = output_file.parent().unwrap().to_owned(); + app_img_path.push("app.img"); + + Command::new(cargo()) + .current_dir(project_root()) + .args([ + "run", + "--package", + "tools", + "--bin", + "sign-image", + "--", + "--kernel-image", + output_file.to_str().unwrap(), + "--kernel-key", + &self.kernel_key, + "--kernel-output", + app_img_path.to_str().unwrap(), + "--min-xous-ver", + &self.min_ver, + "--sig-length", + &self.sigblock_size.to_string(), + "--with-jump", // bao1x target has a jump inserted in the sig block + "--bao1x", + "--function-code", + "app", + // "--defile", + ]) + .status()?; + + Ok(project_root().join(output_file)) + } + fn fetch_prebuilds(&self) -> Result, DynError> { let mut paths = Vec::::new(); for item in [&self.services[..], &self.apps[..]].concat() { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 9a9c6ed10..ae1686708 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -153,7 +153,7 @@ fn main() -> Result<(), Box> { Ok(o) => o, Err(e) => { return Err(format!( - "Error: offset should be hex number without 0x prefix {}: {:?}", + "Error: size should be hex number without 0x prefix {}: {:?}", swap_parts[1], e ) .into()); @@ -188,6 +188,10 @@ fn main() -> Result<(), Box> { for feature in loader_features { builder.add_loader_feature(&feature); } + let detached_app_features = get_flag("--app-feature")?; + for feature in detached_app_features { + builder.add_detached_app_feature(&feature); + } if !language_set { // the default language is english @@ -655,6 +659,7 @@ fn main() -> Result<(), Box> { (bao1x_api::LOADER_START + sigblock_size + STATICS_LEN) as u32, )?; // select the board + builder.set_board(board); builder.add_feature(board); builder.add_loader_feature(board); builder.add_kernel_feature(board); @@ -683,11 +688,14 @@ fn main() -> Result<(), Box> { "usb-bao1x", "bao1x-hal-service", "bao-console", + "modals", + "pddb", ] .to_vec(); - let bao_swap_pkgs = ["modals", /* "pddb", */ "bao-video"].to_vec(); + let bao_swap_pkgs = ["bao-video"].to_vec(); if !builder.is_swap_set() { - builder.set_swap(0, 8 * 1024 * 1024); + // reserve 3MiB for system services: ultimately, "pddb, modals, and bao-video" + builder.set_swap(0, bao1x_api::offsets::baosec::SWAP_RAM_LEN as _); } builder.add_loader_feature("swap"); builder.add_kernel_feature("swap"); @@ -723,9 +731,46 @@ fn main() -> Result<(), Box> { for service in bao_swap_pkgs { builder.add_service(service, LoaderRegion::Swap); } + for app in get_cratespecs() { + builder.add_service(&app, LoaderRegion::Swap); + } // builder.add_feature("modal-testing"); } + Some("dabao") => { + let board = "board-dabao"; + let sigblock_size = 0x300; + update_flash_origin( + "loader/src/platform/bao1x/link.x", + (bao1x_api::LOADER_START + sigblock_size + STATICS_LEN) as u32, + )?; + // select the board + builder.set_board(board); + builder.add_feature(board); + builder.add_loader_feature(board); + builder.add_kernel_feature(board); + builder.add_detached_app_feature(board); + builder.set_sigblock_size(sigblock_size); + + // minimal set of services for app development on a dabao. Need to save space for the app itself! + let bao_rram_pkgs = + ["xous-ticktimer", "xous-log", "xous-names", "usb-bao1x", "bao1x-hal-service"].to_vec(); + let bao_app_pkgs = ["dabao-console", "helloworld"].to_vec(); + + builder.add_loader_feature("debug-print"); + builder.add_kernel_feature("v2p"); + match task.as_deref() { + Some("dabao") => builder.target_bao1x_soc(), + _ => panic!("should be unreachable"), + }; + + for service in bao_rram_pkgs { + builder.add_service(service, LoaderRegion::Flash); + } + builder.add_apps(&bao_app_pkgs); + builder.add_apps(&get_cratespecs()); + } + // ------ ARM hardware image configs ------ Some("arm-tiny") => { builder @@ -796,6 +841,9 @@ fn print_help() { eprintln!( "cargo xtask [verb] [cratespecs ..] [--feature [feature name]] + [--loader-feature [loader feature name]] + [--kernel-feature [kernel feature name]] + [--app-feature [detached app feature name]] [--lkey [loader key]] [--kkey [kernel key]] [--swap [offset:size]] [--app [cratespec]] @@ -849,6 +897,7 @@ Hardware images: av-test automation framework for TRNG testing (AV directly, no CPRNG). [cratespecs] ignored. tiny Precursor tiny image. For testing with services built out-of-tree. baosec Baosec application target image. + dabao Dabao application target image. bao1x-baremetal Baremetal image for baochip1x targets. bao1x-boot0 Boot0 partition for baochip1x targets. bao1x-boot1 Boot1 partition for baochip1x targets.