Skip to content

Commit

Permalink
chore!: replace boot_flow with target option
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed May 27, 2024
1 parent 5e3bff2 commit b6e2f66
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
27 changes: 13 additions & 14 deletions crates/rugpi-bakery/src/bake/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{

use anyhow::Context;
use rugpi_common::{
boot::BootFlow,
disk::{
gpt::gpt_types, mbr::mbr_types, parse_size, DiskId, NumBlocks, Partition, PartitionTable,
PartitionTableType,
Expand All @@ -24,7 +23,7 @@ use xscript::{run, Run};
use crate::{
bake::targets::{
generic_grub_efi::initialize_grub, rpi_tryboot::initialize_tryboot,
rpi_uboot::initialize_uboot,
rpi_uboot::initialize_uboot, Target,
},
project::images::{self, grub_efi_image_layout, pi_image_layout, ImageConfig, ImageLayout},
utils::prelude::*,
Expand Down Expand Up @@ -54,21 +53,21 @@ pub fn make_image(config: &ImageConfig, src: &Path, image: &Path) -> Anyhow<()>

// Initialize config and boot partitions based the selected on boot flow.
info!("Initialize boot flow.");
if let Some(boot_flow) = config.boot_flow {
match boot_flow {
BootFlow::Tryboot => {
if let Some(target) = config.target {
match target {
Target::RpiTryboot => {
initialize_tryboot(&config_dir, &boot_dir, &root_dir)?;
}
BootFlow::UBoot => {
Target::RpiUboot => {
initialize_uboot(config, &config_dir, &boot_dir, &root_dir)?;
}
BootFlow::GrubEfi => {
Target::GenericGrubEfi => {
initialize_grub(config, &config_dir)?;
}
}
}
// Always copy second stage boot scripts independently of the boot flow.
if config.boot_flow.is_some() {
if config.target.is_some() {
info!("Copy second stage boot scripts.");
copy_recursive(
"/usr/share/rugpi/boot/u-boot/bin/second.scr",
Expand All @@ -85,10 +84,10 @@ pub fn make_image(config: &ImageConfig, src: &Path, image: &Path) -> Anyhow<()>
.layout
.clone()
.or_else(|| {
config.boot_flow.map(|boot_flow| match boot_flow {
BootFlow::Tryboot => pi_image_layout(),
BootFlow::UBoot => pi_image_layout(),
BootFlow::GrubEfi => grub_efi_image_layout(),
config.target.map(|target| match target {
Target::RpiTryboot => pi_image_layout(),
Target::RpiUboot => pi_image_layout(),
Target::GenericGrubEfi => grub_efi_image_layout(),
})
})
.ok_or_else(|| anyhow!("image layout needs to be specified"))?;
Expand All @@ -109,8 +108,8 @@ pub fn make_image(config: &ImageConfig, src: &Path, image: &Path) -> Anyhow<()>
info!("Writing image partition table.");
table.write(image)?;

if let Some(boot_flow) = &config.boot_flow {
if matches!(boot_flow, BootFlow::Tryboot | BootFlow::UBoot) {
if let Some(target) = &config.target {
if matches!(target, Target::RpiTryboot | Target::RpiUboot) {
let disk_id = match table.disk_id {
DiskId::Mbr(mbr_id) => mbr_id.into_raw(),
_ => bail!("unsupported GPT partition layout"),
Expand Down
1 change: 0 additions & 1 deletion crates/rugpi-bakery/src/bake/targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ pub enum Target {
GenericGrubEfi,
RpiTryboot,
RpiUboot,
Unknown,
}
8 changes: 3 additions & 5 deletions crates/rugpi-bakery/src/project/images.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use rugpi_common::{
boot::BootFlow,
disk::{gpt::gpt_types, PartitionTableType, PartitionType},
};
use rugpi_common::disk::{gpt::gpt_types, PartitionTableType, PartitionType};
use serde::{Deserialize, Serialize};

use super::config::Architecture;
use crate::bake::targets::Target;

#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
Expand All @@ -15,7 +13,7 @@ pub struct ImageConfig {
#[serde(default)]
pub architecture: Architecture,
/// Indicates which boot flow to use for the image.
pub boot_flow: Option<BootFlow>,
pub target: Option<Target>,
pub size: Option<String>,
pub layout: Option<ImageLayout>,
}
Expand Down
9 changes: 4 additions & 5 deletions examples/debian-grub-efi/rugpi-bakery.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ rugpi-extra = { git = "https://github.com/silitics/rugpi-extra.git", branch = "v
[images.generic-amd64]
layer = "generic-amd64"
architecture = "amd64"
boot_flow = "grub-efi"
target = "generic-grub-efi"

[images.generic-amd64-vm]
layer = "generic-amd64"
architecture = "amd64"
boot_flow = "grub-efi"
target = "generic-grub-efi"
size = "16G"

[images.generic-arm64]
layer = "generic-arm64"
architecture = "arm64"
boot_flow = "grub-efi"
target = "generic-grub-efi"

[images.generic-arm64-vm]
layer = "generic-arm64"
architecture = "arm64"
boot_flow = "grub-efi"
target = "generic-grub-efi"
size = "16G"

8 changes: 4 additions & 4 deletions tests/rugpi-bakery.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ rugpi-extra = { git = "https://github.com/silitics/rugpi-extra.git" }

[images.tryboot]
layer = "customized"
boot_flow = "tryboot"
target = "rpi-tryboot"

[images.pi4]
layer = "customized-pi4"
boot_flow = "tryboot"
target = "rpi-tryboot"

[images.u-boot]
layer = "customized"
boot_flow = "u-boot"
target = "rpi-uboot"

[images.u-boot-armhf]
layer = "customized"
architecture = "armhf"
boot_flow = "u-boot"
target = "rpi-uboot"

0 comments on commit b6e2f66

Please sign in to comment.