Skip to content

Commit

Permalink
chore: work on new flexible update engine
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Sep 4, 2024
1 parent ea35128 commit b5bf71e
Show file tree
Hide file tree
Showing 17 changed files with 997 additions and 179 deletions.
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"buildx",
"Buildx",
"camino",
"canonicalize",
"Chunker",
"cmdline",
"composability",
Expand All @@ -54,6 +55,7 @@
"GPIO",
"GRUBENV",
"Imager",
"indexmap",
"indicatif",
"libc",
"libfdisk",
Expand All @@ -75,6 +77,7 @@
"postgresql",
"Qcow",
"raspios",
"RAUC",
"rbind",
"readwrite",
"repart",
Expand Down
8 changes: 6 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions crates/rugpi-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ tracing.workspace = true
uuid = "1.8.0"
xscript.workspace = true
xz2 = "0.1.7"
indexmap = { version = "2.5.0", features = ["serde"] }

[dev-dependencies]
clap.workspace = true

[features]
compat-rauc = []
compat-mender = []
default = ["compat-rauc", "compat-mender"]

[lints]
workspace = true
33 changes: 29 additions & 4 deletions crates/rugpi-common/src/boot/grub.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! Utilities for the Grub boot flow.
use std::{collections::HashMap, fs::File, io::Write, path::Path};
use std::{
collections::HashMap,
fs::{self, File},
io::Write,
path::Path,
};

use anyhow::bail;
use sha1::{Digest, Sha1};
Expand Down Expand Up @@ -100,9 +105,7 @@ pub fn grub_envblk_encode(values: &HashMap<String, String>) -> Result<String, In
}

pub fn read_default_partitions(config_partition: &ConfigPartition) -> Anyhow<PartitionSet> {
let bootpart_env = grub_envblk_decode(&std::fs::read_to_string(
&config_partition.path().join("rugpi/primary.grubenv"),
)?)?;
let bootpart_env = load_grub_env(config_partition.path().join("rugpi/primary.grubenv"))?;
let Some(bootpart) = bootpart_env.get(RUGPI_BOOTPART) else {
bail!("Invalid bootpart environment.");
};
Expand Down Expand Up @@ -159,6 +162,28 @@ pub fn grub_write_defaults(config_path: &Path) -> Anyhow<()> {
Ok(())
}

pub type GrubEnv = HashMap<String, String>;

pub fn load_grub_env<P: AsRef<Path>>(path: P) -> Anyhow<GrubEnv> {
fn inner(path: &Path) -> Anyhow<GrubEnv> {
Ok(grub_envblk_decode(&fs::read_to_string(path)?)?)
}
inner(path.as_ref())
}

pub fn save_grub_env<P: AsRef<Path>>(path: P, env: &GrubEnv) -> Anyhow<()> {
fn inner(path: &Path, env: &GrubEnv) -> Anyhow<()> {
let mut tmp_path = path.to_path_buf();
tmp_path.as_mut_os_string().push(".tmp");
let mut tmp_file = fs::File::create(&tmp_path)?;
tmp_file.write_all(grub_envblk_encode(env)?.as_bytes())?;
tmp_file.sync_all()?;
fs::rename(&tmp_path, path)?;
Ok(())
}
inner(path.as_ref(), env)
}

pub fn commit(system: &System) -> Anyhow<()> {
let mut envblk = HashMap::new();
match system.hot_partitions() {
Expand Down
8 changes: 0 additions & 8 deletions crates/rugpi-common/src/disk/blkdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,6 @@ pub fn is_block_device<P: AsRef<Path>>(path: P) -> io::Result<bool> {
inner(path.as_ref())
}

/// Get the size of a block device.
///
/// Directly use [`BlockDevice::size`] instead.
#[deprecated]
pub fn get_size<P: AsRef<Path>>(path: P) -> io::Result<u64> {
BlockDevice::new(path)?.size()
}

/// Find the block device where a given path resides on.
///
/// Returns [`None`] when the path is not on a block device.
Expand Down
7 changes: 5 additions & 2 deletions crates/rugpi-common/src/disk/sfdisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use anyhow::anyhow;
use serde::Deserialize;
use xscript::{read_str, run, Run};

use super::{blkdev, gpt::Guid, mbr, DiskId, NumBlocks, Partition, PartitionTable, PartitionType};
use super::{
blkdev::BlockDevice, gpt::Guid, mbr, DiskId, NumBlocks, Partition, PartitionTable,
PartitionType,
};
use crate::{utils::units::NumBytes, Anyhow};

/// Path to the `sfdisk` executable.
Expand All @@ -21,7 +24,7 @@ pub(crate) fn sfdisk_read(dev: &Path) -> Anyhow<PartitionTable> {
.partition_table;
let metadata = dev.metadata()?;
let size = if metadata.file_type().is_block_device() {
NumBlocks::from_raw(blkdev::get_size(dev)? / json_table.sector_size)
NumBlocks::from_raw(BlockDevice::new(dev)?.size()? / json_table.sector_size)
} else {
NumBlocks::from_raw(metadata.size() / json_table.sector_size)
};
Expand Down
159 changes: 0 additions & 159 deletions crates/rugpi-common/src/system.rs

This file was deleted.

Loading

0 comments on commit b5bf71e

Please sign in to comment.