From c53515fc6364cf9dfe2d2b4a106376b3d5803635 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 7 Apr 2024 00:41:18 +0800 Subject: [PATCH] coalesce swap hal into boot config object; read initial swap args this worked, so it validates the encryption/decryption of the swap at least! --- loader/src/main.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/loader/src/main.rs b/loader/src/main.rs index 7dcb99df4..7a803ee93 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -127,7 +127,10 @@ fn boot_sequence(args: KernelArguments, _signature: u32, fs_prehash: [u8; 64]) - read_initial_config(&mut cfg); #[cfg(feature = "swap")] - let mut swap = SwapHal::new(&cfg); + { + cfg.swap_hal = SwapHal::new(&cfg); + read_swap_config(&mut cfg); + } // check to see if we are recovering from a clean suspend or not #[cfg(feature = "resume")] @@ -377,6 +380,26 @@ pub fn read_initial_config(cfg: &mut BootConfig) { assert!(init_seen, "no initial programs found"); } +#[cfg(feature = "swap")] +pub fn read_swap_config(cfg: &mut BootConfig) { + // Read in the swap arguments: should be located at beginning of the first page of swap. + let page0 = cfg.swap_hal.as_mut().unwrap().decrypt_page_at(0); + let swap_args = KernelArguments::new(page0.as_ptr() as *const usize); + for tag in swap_args.iter() { + if tag.name == u32::from_le_bytes(*b"IniS") { + assert!(tag.size >= 4, "invalid Init size"); + cfg.init_process_count += 1; + } else if tag.name == u32::from_le_bytes(*b"XArg") { + // these are actually specified inside the `Swap` arg, this is just + // a mirror because this argument is added by default by the image creator + println!("swap start: {:x}", tag.data[2]); + println!("swap size: {:x}", tag.data[3]); + } else { + println!("Unhandled argument in swap: {:x}", tag.name); + } + } +} + /// Checks a reserved area of RAM for a pattern with a pre-defined mathematical /// relationship. The purpose is to detect if we have a "clean suspend", or if /// we've rebooted from a corrupt/cold RAM state.