Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow variants to specify extra kernel parameters #1491

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ ARG VARIANT
ARG PRETTY_NAME
ARG IMAGE_NAME
ARG IMAGE_FORMAT
ENV VARIANT=${VARIANT} VERSION_ID=${VERSION_ID} BUILD_ID=${BUILD_ID} PRETTY_NAME=${PRETTY_NAME} IMAGE_NAME=${IMAGE_NAME} IMAGE_FORMAT=${IMAGE_FORMAT}
ARG KERNEL_PARAMETERS
ENV VARIANT=${VARIANT} VERSION_ID=${VERSION_ID} BUILD_ID=${BUILD_ID} PRETTY_NAME=${PRETTY_NAME} IMAGE_NAME=${IMAGE_NAME} IMAGE_FORMAT=${IMAGE_FORMAT} KERNEL_PARAMETERS=${KERNEL_PARAMETERS}
WORKDIR /root

USER root
Expand Down
12 changes: 11 additions & 1 deletion tools/buildsys/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ pub(crate) struct VariantBuilder;

impl VariantBuilder {
/// Build a variant with the specified packages installed.
pub(crate) fn build(packages: &[String], image_format: Option<&ImageFormat>) -> Result<Self> {
pub(crate) fn build(
packages: &[String],
image_format: Option<&ImageFormat>,
kernel_parameters: Option<&Vec<String>>,
) -> Result<Self> {
let output_dir: PathBuf = getenv("BUILDSYS_OUTPUT_DIR")?.into();

let variant = getenv("BUILDSYS_VARIANT")?;
Expand All @@ -102,6 +106,12 @@ impl VariantBuilder {
Some(ImageFormat::Vmdk) => "vmdk",
},
);
args.build_arg(
"KERNEL_PARAMETERS",
kernel_parameters
.map(|v| v.join(" "))
.unwrap_or_else(|| "".to_string()),
);

// Always rebuild variants since they are located in a different workspace,
// and don't directly track changes in the underlying packages.
Expand Down
4 changes: 3 additions & 1 deletion tools/buildsys/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ fn build_variant() -> Result<()> {

if let Some(packages) = manifest.included_packages() {
let image_format = manifest.image_format();
VariantBuilder::build(&packages, image_format).context(error::BuildAttempt)?;
let kernel_parameters = manifest.kernel_parameters();
VariantBuilder::build(&packages, image_format, kernel_parameters)
.context(error::BuildAttempt)?;
} else {
println!("cargo:warning=No included packages in manifest. Skipping variant build.");
}
Expand Down
31 changes: 31 additions & 0 deletions tools/buildsys/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ variant-sensitive = true
[package.metadata.build-variant]
included-packages = ["release"]
```

`image-format` is the desired format of the built image.
This can be `raw` (the default), `vmdk`, or `qcow2`.
```
[package.metadata.build-variant]
image-format = "vmdk"
```

`supported-arches` is the list of architectures the variant is able to run on.
The values can be `x86_64` and `aarch64`.
If not specified, the variant can run on any of those architectures.
```
[package.metadata.build-variant]
supported-arches = ["x86_64"]
```

`kernel-parameters` is a list of extra parameters to be added to the kernel command line.
The given parameters are inserted at the start of the command line.
```
[package.metadata.build-variant]
kernel-parameters = [
"console=ttyS42",
]
```
*/

pub(crate) mod error;
Expand Down Expand Up @@ -123,6 +147,12 @@ impl ManifestInfo {
.and_then(|b| b.supported_arches.as_ref())
}

/// Convenience method to return the kernel parameters for this variant.
pub(crate) fn kernel_parameters(&self) -> Option<&Vec<String>> {
self.build_variant()
.and_then(|b| b.kernel_parameters.as_ref())
}

/// Helper methods to navigate the series of optional struct fields.
fn build_package(&self) -> Option<&BuildPackage> {
self.package
Expand Down Expand Up @@ -167,6 +197,7 @@ pub(crate) struct BuildVariant {
pub(crate) included_packages: Option<Vec<String>>,
pub(crate) image_format: Option<ImageFormat>,
pub(crate) supported_arches: Option<HashSet<SupportedArch>>,
pub(crate) kernel_parameters: Option<Vec<String>>,
}

#[derive(Deserialize, Debug)]
Expand Down
4 changes: 3 additions & 1 deletion tools/rpm2img
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ set default="0"
set timeout="0"

menuentry "${PRETTY_NAME} ${VERSION_ID}" {
linux (\$root)/vmlinuz root=/dev/dm-0 rootwait ro \\
linux (\$root)/vmlinuz \\
${KERNEL_PARAMETERS} \\
root=/dev/dm-0 rootwait ro \\
console=tty0 console=ttyS0 random.trust_cpu=on selinux=1 enforcing=1 \\
systemd.log_target=journal-or-kmsg systemd.log_color=0 net.ifnames=0 \\
biosdevname=0 dm_verity.max_bios=-1 dm_verity.dev_wait=1 \\
Expand Down