Skip to content
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
20 changes: 20 additions & 0 deletions src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct CmdlineOptions {
pub rootfstype: Option<String>,
pub rootflags: Option<String>,
pub rootfsflags: MsFlags,
pub verity_root: Option<String>,
pub nfsroot: Option<String>,
pub init: String,
pub cleanup: bool,
Expand All @@ -29,6 +30,7 @@ impl Default for CmdlineOptions {
rootfstype: None,
rootflags: None,
rootfsflags: MsFlags::MS_RDONLY,
verity_root: None,
nfsroot: None,
init: "/sbin/init".into(),
cleanup: true,
Expand All @@ -49,6 +51,7 @@ impl CmdlineOptions {
"rootflags" => self.rootflags = value.map(str::to_string),
"ro" => self.rootfsflags.insert(MsFlags::MS_RDONLY),
"rw" => self.rootfsflags.remove(MsFlags::MS_RDONLY),
"rsinit.verity_root" => self.verity_root = Some(ensure_value(key, value)?.to_string()),
"nfsroot" => self.nfsroot = Some(ensure_value(key, value)?.to_string()),
"init" => self.init = ensure_value(key, value)?.into(),
_ => {
Expand Down Expand Up @@ -301,4 +304,21 @@ mod tests {

assert_eq!(&*custom_option.borrow(), "xyz");
}

#[test]
fn test_verity() {
let cmdline = "rsinit.verity_root=/dev/mmcblk0p1 rootfstype=ext4\n";

let expected = CmdlineOptions {
verity_root: Some("/dev/mmcblk0p1".into()),
rootfstype: Some("ext4".into()),
..Default::default()
};

let options = CmdlineOptionsParser::new()
.parse_string(cmdline)
.expect("failed");

assert_eq!(options, expected);
}
}
11 changes: 6 additions & 5 deletions src/dmverity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ pub fn prepare_dmverity(options: &mut CmdlineOptions) -> Result<bool> {
if !Path::new("/verity-params").exists() {
return Ok(false);
}
if options.root.is_none() {
return Ok(false);
}
let root_device = options.root.as_ref().ok_or("No root device")?;
match options.rootfstype.as_deref() {
Some("nfs") | Some("9p") => return Ok(false),
_ => wait_for_device(root_device)?,
_ => (),
}
let root_device = options
.verity_root
.as_ref()
.ok_or("No verity root device")?;
wait_for_device(root_device)?;

let mut data_blocks = "";
let mut data_sectors = "";
Expand Down