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