mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 19:03:27 +00:00
Utilize libflate crate to compress and decompress payload
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
930b0d208d
commit
6752baf166
@ -17,6 +17,8 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
use linux_bzimage_builder::PayloadEncoding;
|
||||
|
||||
pub fn main() {
|
||||
let load_config = |common_args: &CommonArgs| {
|
||||
let manifest = TomlManifest::load();
|
||||
@ -358,4 +360,11 @@ pub struct CommonArgs {
|
||||
global = true
|
||||
)]
|
||||
pub qemu_args: Vec<String>,
|
||||
#[arg(
|
||||
long = "encoding",
|
||||
help = "Denote the encoding format for kernel self-decompression",
|
||||
value_name = "FORMAT",
|
||||
global = true
|
||||
)]
|
||||
pub encoding: Option<PayloadEncoding>,
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ use std::{
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use linux_bzimage_builder::{legacy32_rust_target_json, make_bzimage, BzImageType};
|
||||
use linux_bzimage_builder::{
|
||||
legacy32_rust_target_json, make_bzimage, BzImageType, PayloadEncoding,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
arch::Arch,
|
||||
@ -23,6 +25,7 @@ pub fn make_install_bzimage(
|
||||
target_dir: impl AsRef<Path>,
|
||||
aster_elf: &AsterBin,
|
||||
linux_x86_legacy_boot: bool,
|
||||
encoding: PayloadEncoding,
|
||||
) -> AsterBin {
|
||||
let target_name = get_current_crate_info().name;
|
||||
let image_type = if linux_x86_legacy_boot {
|
||||
@ -55,7 +58,13 @@ pub fn make_install_bzimage(
|
||||
let install_path = install_dir.as_ref().join(target_name);
|
||||
info!("Building bzImage");
|
||||
println!("install_path: {:?}", install_path);
|
||||
make_bzimage(&install_path, image_type, aster_elf.path(), &setup_bin);
|
||||
make_bzimage(
|
||||
&install_path,
|
||||
image_type,
|
||||
aster_elf.path(),
|
||||
&setup_bin,
|
||||
encoding,
|
||||
);
|
||||
|
||||
AsterBin::new(
|
||||
&install_path,
|
||||
@ -162,6 +171,10 @@ fn install_setup_with_arch(
|
||||
cmd.arg("install").arg("linux-bzimage-setup");
|
||||
cmd.arg("--force");
|
||||
cmd.arg("--root").arg(install_dir.as_ref());
|
||||
if std::env::var("AUTO_TEST").is_ok() || std::env::var("OSDK_INTEGRATION_TEST").is_ok() {
|
||||
cmd.arg("--path")
|
||||
.arg("../../../ostd/libs/linux-bzimage/setup");
|
||||
}
|
||||
// Remember to upgrade this version if new version of linux-bzimage-setup is released.
|
||||
const LINUX_BZIMAGE_SETUP_VERSION: &str = "0.1.0";
|
||||
cmd.arg("--version").arg(LINUX_BZIMAGE_SETUP_VERSION);
|
||||
|
@ -57,6 +57,7 @@ pub fn create_bootdev_image(
|
||||
&target_dir,
|
||||
aster_bin,
|
||||
action.build.linux_x86_legacy_boot,
|
||||
config.build.encoding.clone(),
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
|
@ -16,7 +16,10 @@ mod test;
|
||||
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use scheme::{Action, ActionScheme, BootScheme, Build, GrubScheme, QemuScheme, Scheme};
|
||||
use linux_bzimage_builder::PayloadEncoding;
|
||||
use scheme::{
|
||||
Action, ActionScheme, BootProtocol, BootScheme, Build, GrubScheme, QemuScheme, Scheme,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
arch::{get_default_arch, Arch},
|
||||
@ -88,6 +91,11 @@ fn apply_args_after_finalize(action: &mut Action, args: &CommonArgs) {
|
||||
|
||||
impl Config {
|
||||
pub fn new(scheme: &Scheme, common_args: &CommonArgs) -> Self {
|
||||
let check_compatibility = |protocol: BootProtocol, encoding: PayloadEncoding| {
|
||||
if protocol != BootProtocol::Linux && encoding != PayloadEncoding::Raw {
|
||||
panic!("The encoding format is not allowed to be specified if the boot protocol is not {:#?}", BootProtocol::Linux);
|
||||
}
|
||||
};
|
||||
let target_arch = common_args.target_arch.unwrap_or(get_default_arch());
|
||||
let default_scheme = ActionScheme {
|
||||
boot: scheme.boot.clone(),
|
||||
@ -95,12 +103,18 @@ impl Config {
|
||||
qemu: scheme.qemu.clone(),
|
||||
build: scheme.build.clone(),
|
||||
};
|
||||
let build = {
|
||||
let mut build = scheme.build.clone().unwrap_or_default().finalize();
|
||||
build.apply_common_args(common_args);
|
||||
build
|
||||
};
|
||||
let run = {
|
||||
let mut run = scheme.run.clone().unwrap_or_default();
|
||||
run.inherit(&default_scheme);
|
||||
apply_args_before_finalize(&mut run, common_args);
|
||||
let mut run = run.finalize(target_arch);
|
||||
apply_args_after_finalize(&mut run, common_args);
|
||||
check_compatibility(run.grub.boot_protocol, run.build.encoding.clone());
|
||||
run
|
||||
};
|
||||
let test = {
|
||||
@ -109,6 +123,7 @@ impl Config {
|
||||
apply_args_before_finalize(&mut test, common_args);
|
||||
let mut test = test.finalize(target_arch);
|
||||
apply_args_after_finalize(&mut test, common_args);
|
||||
check_compatibility(test.grub.boot_protocol, test.build.encoding.clone());
|
||||
test
|
||||
};
|
||||
Self {
|
||||
@ -117,7 +132,7 @@ impl Config {
|
||||
.clone()
|
||||
.unwrap_or_else(|| env::current_dir().unwrap()),
|
||||
target_arch,
|
||||
build: scheme.build.clone().unwrap_or_default().finalize(),
|
||||
build,
|
||||
run,
|
||||
test,
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use linux_bzimage_builder::PayloadEncoding;
|
||||
|
||||
use super::{inherit_optional, Boot, BootScheme, Grub, GrubScheme, Qemu, QemuScheme};
|
||||
|
||||
use crate::{cli::CommonArgs, config::Arch};
|
||||
@ -23,6 +25,7 @@ pub struct BuildScheme {
|
||||
pub linux_x86_legacy_boot: bool,
|
||||
#[serde(default)]
|
||||
pub strip_elf: bool,
|
||||
pub encoding: Option<PayloadEncoding>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@ -38,6 +41,7 @@ pub struct Build {
|
||||
pub linux_x86_legacy_boot: bool,
|
||||
#[serde(default)]
|
||||
pub strip_elf: bool,
|
||||
pub encoding: PayloadEncoding,
|
||||
}
|
||||
|
||||
impl Default for Build {
|
||||
@ -49,6 +53,7 @@ impl Default for Build {
|
||||
override_configs: Vec::new(),
|
||||
linux_x86_legacy_boot: false,
|
||||
strip_elf: false,
|
||||
encoding: PayloadEncoding::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -71,6 +76,9 @@ impl Build {
|
||||
if common_args.strip_elf {
|
||||
self.strip_elf = true;
|
||||
}
|
||||
if let Some(encoding) = common_args.encoding.clone() {
|
||||
self.encoding.clone_from(&encoding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,6 +99,9 @@ impl BuildScheme {
|
||||
if parent.strip_elf {
|
||||
self.strip_elf = true;
|
||||
}
|
||||
if self.encoding.is_none() {
|
||||
self.encoding.clone_from(&parent.encoding);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn finalize(self) -> Build {
|
||||
@ -101,6 +112,7 @@ impl BuildScheme {
|
||||
override_configs: Vec::new(),
|
||||
linux_x86_legacy_boot: self.linux_x86_legacy_boot,
|
||||
strip_elf: self.strip_elf,
|
||||
encoding: self.encoding.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user