summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2018-12-11 16:29:26 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-02-07 03:02:08 -0800
commite403f5ccd0581ec62fbfb86de00b8c01958ffa67 (patch)
tree8bc44cbdeba1e57780a27d8092918b00a870bb54 /src
parente54b33834c6adba8921947330583afa19fbd100a (diff)
downloadcrosvm-e403f5ccd0581ec62fbfb86de00b8c01958ffa67.tar
crosvm-e403f5ccd0581ec62fbfb86de00b8c01958ffa67.tar.gz
crosvm-e403f5ccd0581ec62fbfb86de00b8c01958ffa67.tar.bz2
crosvm-e403f5ccd0581ec62fbfb86de00b8c01958ffa67.tar.lz
crosvm-e403f5ccd0581ec62fbfb86de00b8c01958ffa67.tar.xz
crosvm-e403f5ccd0581ec62fbfb86de00b8c01958ffa67.tar.zst
crosvm-e403f5ccd0581ec62fbfb86de00b8c01958ffa67.zip
linux: add support for loading an initrd
Based on Linux boot protocol references:
- x86: Documentation/x86/boot.txt
- arm: Documentation/devicetree/bindings/chosen.txt

BUG=None
TEST=Boot Alpine Linux netboot initrd on x86_64 and aarch64

Change-Id: If4730765638f0a0b8bb8f63203c98e4765a354ee
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1407221
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/linux.rs12
-rw-r--r--src/main.rs6
2 files changed, 18 insertions, 0 deletions
diff --git a/src/linux.rs b/src/linux.rs
index beb1021..b81bc71 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -69,6 +69,7 @@ pub enum Error {
     NetDeviceNew(devices::virtio::NetError),
     NoVarEmpty,
     OpenAndroidFstab(PathBuf, io::Error),
+    OpenInitrd(PathBuf, io::Error),
     OpenKernel(PathBuf, io::Error),
     P9DeviceNew(devices::virtio::P9Error),
     PollContextAdd(sys_util::Error),
@@ -126,6 +127,7 @@ impl fmt::Display for Error {
             }
             Error::NetDeviceNew(e) => write!(f, "failed to set up virtio networking: {:?}", e),
             Error::NoVarEmpty => write!(f, "/var/empty doesn't exist, can't jail devices."),
+            Error::OpenInitrd(p, e) => write!(f, "failed to open initrd {:?}: {}", p, e),
             Error::OpenKernel(p, e) => write!(f, "failed to open kernel image {:?}: {}", p, e),
             Error::OpenAndroidFstab(ref p, ref e) => {
                 write!(f, "failed to open android fstab file {:?}: {}", p, e)
@@ -966,6 +968,15 @@ pub fn run_config(cfg: Config) -> Result<()> {
     // quickly.
     let sigchld_fd = SignalFd::new(libc::SIGCHLD).map_err(Error::CreateSignalFd)?;
 
+    let initrd_image = if let Some(ref initrd_path) = cfg.initrd_path {
+        Some(
+            File::open(initrd_path.as_path())
+                .map_err(|e| Error::OpenInitrd(initrd_path.clone(), e))?,
+        )
+    } else {
+        None
+    };
+
     let components = VmComponents {
         memory_mb: (cfg.memory.unwrap_or(256) << 20) as u64,
         vcpu_count: cfg.vcpu_count.unwrap_or(1),
@@ -978,6 +989,7 @@ pub fn run_config(cfg: Config) -> Result<()> {
                 File::open(x.as_path()).map_err(|e| Error::OpenAndroidFstab(x.to_path_buf(), e))
             })
             .map_or(Ok(None), |v| v.map(Some))?,
+        initrd_image,
         extra_kernel_params: cfg.params.clone(),
         wayland_dmabuf: cfg.wayland_dmabuf,
     };
diff --git a/src/main.rs b/src/main.rs
index 31019f9..8a4fce0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -96,6 +96,7 @@ pub struct Config {
     memory: Option<usize>,
     kernel_path: PathBuf,
     android_fstab: Option<PathBuf>,
+    initrd_path: Option<PathBuf>,
     params: Vec<String>,
     socket_path: Option<PathBuf>,
     plugin: Option<PathBuf>,
@@ -130,6 +131,7 @@ impl Default for Config {
             memory: None,
             kernel_path: PathBuf::default(),
             android_fstab: None,
+            initrd_path: None,
             params: Vec::new(),
             socket_path: None,
             plugin: None,
@@ -569,6 +571,9 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
         "split-irqchip" => {
             cfg.split_irqchip = true;
         }
+        "initrd" => {
+            cfg.initrd_path = Some(PathBuf::from(value.unwrap().to_owned()));
+        }
         "help" => return Err(argument::Error::PrintHelp),
         _ => unreachable!(),
     }
@@ -579,6 +584,7 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> {
     let arguments =
         &[Argument::positional("KERNEL", "bzImage of kernel to run"),
           Argument::value("android-fstab", "PATH", "Path to Android fstab"),
+          Argument::short_value('i', "initrd", "PATH", "Initial ramdisk to load."),
           Argument::short_value('p',
                                 "params",
                                 "PARAMS",