forked from brl/citadel-tools
Rename modules image to kernel image and add some extra metadata
This commit is contained in:
parent
c992b32946
commit
db820aff68
@ -176,6 +176,9 @@ impl UpdateBuilder {
|
||||
if let Some(kv) = self.config.kernel_version() {
|
||||
writeln!(v, "kernel-version = \"{}\"", kv)?;
|
||||
}
|
||||
if let Some(kid) = self.config.kernel_id() {
|
||||
writeln!(v, "kernel-id = \"{}\"", kid)?;
|
||||
}
|
||||
writeln!(v, "channel = \"{}\"", self.config.channel())?;
|
||||
writeln!(v, "version = {}", self.config.version())?;
|
||||
writeln!(v, "nblocks = {}", self.nblocks.unwrap())?;
|
||||
|
@ -15,6 +15,8 @@ pub struct BuildConfig {
|
||||
source: String,
|
||||
#[serde(rename = "kernel-version")]
|
||||
kernel_version: Option<String>,
|
||||
#[serde(rename = "kernel-id")]
|
||||
kernel_id: Option<String>,
|
||||
|
||||
#[serde(skip)]
|
||||
basedir: PathBuf,
|
||||
@ -57,7 +59,7 @@ impl BuildConfig {
|
||||
|
||||
fn validate(&self) -> Result<()> {
|
||||
let itype = self.image_type.as_str();
|
||||
if itype != "extra" && itype != "rootfs" && itype != "modules" {
|
||||
if itype != "extra" && itype != "rootfs" && itype != "kernel" {
|
||||
bail!("Invalid image type '{}'", self.image_type);
|
||||
};
|
||||
let src = Path::new(&self.source);
|
||||
@ -67,8 +69,8 @@ impl BuildConfig {
|
||||
src.display()
|
||||
);
|
||||
}
|
||||
if self.image_type == "modules" && self.kernel_version.is_none() {
|
||||
bail!("Cannot build 'modules' image without kernel-version field");
|
||||
if self.image_type == "kernel" && self.kernel_version.is_none() {
|
||||
bail!("Cannot build 'kernel' image without kernel-version field");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -90,6 +92,10 @@ impl BuildConfig {
|
||||
self.kernel_version.as_ref().map(|s| s.as_str())
|
||||
}
|
||||
|
||||
pub fn kernel_id(&self) -> Option<&str> {
|
||||
self.kernel_id.as_ref().map(|s| s.as_str())
|
||||
}
|
||||
|
||||
pub fn version(&self) -> usize {
|
||||
self.version
|
||||
}
|
||||
|
@ -77,10 +77,10 @@ impl Installer {
|
||||
MKFS_VFAT,MKFS_BTRFS,LSBLK,BTRFS,MOUNT,UMOUNT,CHOWN,TAR,XZ,CITADEL_IMAGE,
|
||||
];
|
||||
|
||||
let modules_img = self.modules_imagename();
|
||||
let kernel_img = self.kernel_imagename();
|
||||
let artifacts = vec![
|
||||
"bootx64.efi", "bzImage",
|
||||
modules_img.as_str(), EXTRA_IMAGE_NAME,
|
||||
kernel_img.as_str(), EXTRA_IMAGE_NAME,
|
||||
];
|
||||
|
||||
if self.target_device.is_empty() {
|
||||
@ -371,16 +371,16 @@ impl Installer {
|
||||
|
||||
self.copy_artifact(EXTRA_IMAGE_NAME, &resources)?;
|
||||
|
||||
let modules = self.modules_imagename();
|
||||
self.copy_artifact(&modules, &resources)?;
|
||||
let kernel_img = self.kernel_imagename();
|
||||
self.copy_artifact(&kernel_img, &resources)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn modules_imagename(&self) -> String {
|
||||
fn kernel_imagename(&self) -> String {
|
||||
let utsname = util::uname();
|
||||
let v = utsname.release().split("-").collect::<Vec<_>>();
|
||||
format!("citadel-modules-{}.img", v[0])
|
||||
format!("citadel-kernel-{}.img", v[0])
|
||||
}
|
||||
|
||||
fn target_partition(&self, num: usize) -> String {
|
||||
|
@ -18,13 +18,13 @@ use rootfs::Rootfs;
|
||||
/// mount command supports 4 subcommands
|
||||
///
|
||||
/// citadel-mount rootfs
|
||||
/// citadel-mount modules
|
||||
/// citadel-mount kernel
|
||||
/// citadel-mount extra
|
||||
/// citadel-mount copy-artifacts
|
||||
///
|
||||
/// 'rootfs' creates the /dev/mapper/rootfs device which will be mounted as root filesystem
|
||||
///
|
||||
/// 'modules' mounts a resource bundle containing kernel modules
|
||||
/// 'kernel' mounts a resource bundle containing kernel modules
|
||||
/// 'extra' mounts a resource bundle containing extra files
|
||||
///
|
||||
/// 'copy-artifacts' searches for a boot partition containing an /images
|
||||
@ -42,7 +42,7 @@ fn main() {
|
||||
args.next();
|
||||
let result = match args.next() {
|
||||
Some(ref s) if s == "rootfs" => mount_rootfs(),
|
||||
Some(ref s) if s == "modules" => mount_modules(),
|
||||
Some(ref s) if s == "kernel" => mount_kernel(),
|
||||
Some(ref s) if s == "extra" => mount_extra(),
|
||||
_ => Err(format_err!("Bad or missing argument")),
|
||||
};
|
||||
@ -59,9 +59,9 @@ fn mount_rootfs() -> Result<()> {
|
||||
rootfs.setup()
|
||||
}
|
||||
|
||||
fn mount_modules() -> Result<()> {
|
||||
info!("citadel-mount modules");
|
||||
let mut image = ResourceImage::find("modules")?;
|
||||
fn mount_kernel() -> Result<()> {
|
||||
info!("citadel-mount kernel");
|
||||
let mut image = ResourceImage::find("kernel")?;
|
||||
image.mount()?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -88,6 +88,14 @@ impl OsRelease {
|
||||
OsRelease::get_int_value("CITADEL_ROOTFS_VERSION")
|
||||
}
|
||||
|
||||
pub fn citadel_kernel_version() -> Option<&'static str> {
|
||||
OsRelease::get_value("CITADEL_KERNEL_VERSION")
|
||||
}
|
||||
|
||||
pub fn citadel_kernel_id() -> Option<&'static str> {
|
||||
OsRelease::get_value("CITADEL_KERNEL_ID")
|
||||
}
|
||||
|
||||
fn _get_value(&self, key: &str) -> Option<&str> {
|
||||
self.vars.get(key).map(|v| v.as_str())
|
||||
}
|
||||
|
@ -294,6 +294,8 @@ struct MetaInfoToml {
|
||||
channel: String,
|
||||
#[serde(rename = "kernel-version")]
|
||||
kernel_version: Option<String>,
|
||||
#[serde(rename = "kernel-id")]
|
||||
kernel_id: Option<String>,
|
||||
version: u32,
|
||||
#[serde(rename = "base-version")]
|
||||
base_version: Option<u32>,
|
||||
@ -340,6 +342,8 @@ impl MetaInfo {
|
||||
|
||||
pub fn kernel_version(&self) -> Option<&str> { self.toml().kernel_version.as_ref().map(|s| s.as_str()) }
|
||||
|
||||
pub fn kernel_id(&self) -> Option<&str> { self.toml().kernel_id.as_ref().map(|s| s.as_str()) }
|
||||
|
||||
pub fn version(&self) -> u32 {
|
||||
self.toml().version
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use std::ffi::OsStr;
|
||||
use std::io::{self,Seek,SeekFrom};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use {CommandLine,ImageHeader,MetaInfo,Result,Partition,Mount,verity,util};
|
||||
use {CommandLine,OsRelease,ImageHeader,MetaInfo,Result,Partition,Mount,verity,util};
|
||||
|
||||
use failure::ResultExt;
|
||||
|
||||
@ -437,23 +437,25 @@ fn current_kernel_version() -> String {
|
||||
//
|
||||
fn all_matching_images(dir: &Path, image_type: &str, channel: Option<&str>) -> Result<Vec<ResourceImage>> {
|
||||
let kernel_version = current_kernel_version();
|
||||
let kv = if image_type == "modules" {
|
||||
let kv = if image_type == "kernel" {
|
||||
Some(kernel_version.as_str())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let kernel_id = OsRelease::citadel_kernel_id();
|
||||
|
||||
let mut v = Vec::new();
|
||||
for entry in fs::read_dir(dir)? {
|
||||
maybe_add_dir_entry(entry?, image_type, channel, kv, &mut v)?;
|
||||
maybe_add_dir_entry(entry?, image_type, channel, kv, kernel_id, &mut v)?;
|
||||
}
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
// Examine a directory entry to determine if it is a resource image which
|
||||
// matches a given channel and image_type. If the image_type is "modules"
|
||||
// then also match the kernel-version field. If channel is None then don't
|
||||
// consider the channel in the match.
|
||||
// matches a given channel and image_type. If the image_type is "kernel"
|
||||
// then also match the kernel-version and kernel-id fields. If channel
|
||||
// is None then don't consider the channel in the match.
|
||||
//
|
||||
// If the entry is a match, then instantiate a ResourceImage and add it to
|
||||
// the images vector.
|
||||
@ -461,6 +463,7 @@ fn maybe_add_dir_entry(entry: DirEntry,
|
||||
image_type: &str,
|
||||
channel: Option<&str>,
|
||||
kernel_version: Option<&str>,
|
||||
kernel_id: Option<&str>,
|
||||
images: &mut Vec<ResourceImage>) -> Result<()> {
|
||||
|
||||
let path = entry.path();
|
||||
@ -486,8 +489,17 @@ fn maybe_add_dir_entry(entry: DirEntry,
|
||||
}
|
||||
}
|
||||
|
||||
if metainfo.image_type() == image_type && metainfo.kernel_version() == kernel_version {
|
||||
images.push(ResourceImage::new(&path, header, metainfo));
|
||||
if image_type != metainfo.image_type() {
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
if image_type == "kernel" {
|
||||
if metainfo.kernel_version() != kernel_version || metainfo.kernel_id() != kernel_id {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
images.push(ResourceImage::new(&path, header, metainfo));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user