select LIBUK9P
select LIB9PFS
+ config LIBVFSCORE_ROOTFS_INITRD
+ bool "InitRD"
+ select LIBRAMFS
+ select LIBUKCPIO
+
config LIBVFSCORE_ROOTFS_CUSTOM
bool "Custom argument"
help
string
default "ramfs" if LIBVFSCORE_ROOTFS_RAMFS
default "9pfs" if LIBVFSCORE_ROOTFS_9PFS
+ default "initrd" if LIBVFSCORE_ROOTFS_INITRD
default LIBVFSCORE_ROOTFS_CUSTOM_ARG if LIBVFSCORE_ROOTFS_CUSTOM
default ""
# The root device option is hidden for RamFS and 9PFS
config LIBVFSCORE_ROOTDEV
string "Default root device"
- depends on !LIBVFSCORE_ROOTFS_RAMFS
+ depends on !LIBVFSCORE_ROOTFS_RAMFS && !LIBVFSCORE_ROOTFS_INITRD
default "rootfs" if LIBVFSCORE_ROOTFS_9PFS
default ""
help
# The root flags is hidden for RamFS
config LIBVFSCORE_ROOTFLAGS
hex "Default root mount flags"
- depends on !LIBVFSCORE_ROOTFS_RAMFS
+ depends on !LIBVFSCORE_ROOTFS_RAMFS && !LIBVFSCORE_ROOTFS_INITRD
default 0x0
help
Mount flags.
# The root options are hidden for RamFS
config LIBVFSCORE_ROOTOPTS
string "Default root mount options"
- depends on !LIBVFSCORE_ROOTFS_RAMFS
+ depends on !LIBVFSCORE_ROOTFS_RAMFS && !LIBVFSCORE_ROOTFS_INITRD
default ""
help
Usually a comma-separated list of additional mount
* Mount VFS root
*
* Authors: Simon Kuenzer <simon.kuenzer@neclab.eu>
- *
+ * Robert Hrusecky <roberth@cs.utexas.edu>
+ * Omar Jamil <omarj2898@gmail.com>
+ * Sachin Beldona <sachinbeldona@utexas.edu>
*
* Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
* All rights reserved.
#include <sys/stat.h>
#include <sys/mount.h>
#include <uk/init.h>
+#ifdef CONFIG_LIBVFSCORE_ROOTFS_INITRD
+#include <uk/plat/memory.h>
+#include <uk/cpio.h>
+#include <string.h>
+#endif /* CONFIG_LIBVFSCORE_ROOTFS_INITRD */
static const char *rootfs = CONFIG_LIBVFSCORE_ROOTFS;
return -1;
}
+#if CONFIG_LIBVFSCORE_ROOTFS_INITRD
+ if (strncmp(rootfs, "initrd", 5) == 0) {
+ struct ukplat_memregion_desc initrd;
+ enum ukcpio_error error;
+
+ if (ukplat_memregion_find_initrd0(&initrd) < 0) {
+ uk_pr_crit("Could not find an initrd!\n");
+ return -1;
+ }
+
+ uk_pr_info("Mount ramfs to /...\n");
+
+ if (mount("", "/", "ramfs", 0, NULL) != 0) {
+ uk_pr_crit("Failed to mount ramfs to /: %d\n",
+ errno);
+ return -1;
+ }
+
+ uk_pr_info("Extracting initrd @ %p (%"__PRIsz" bytes) to /...\n",
+ initrd.base, initrd.len);
+
+ error = ukcpio_extract("/", initrd.base, initrd.len);
+ if (error < 0) {
+ uk_pr_crit("Failed to extract cpio archive to /: %d\n",
+ error);
+ return -1;
+ }
+
+ return 0;
+ }
+#endif /* CONFIG_LIBVFSCORE_ROOTFS_INITRD */
+
uk_pr_info("Mount %s to /...\n", rootfs);
if (mount(rootdev, "/", rootfs, rootflags, rootopts) != 0) {
uk_pr_crit("Failed to mount /: %d\n", errno);
return -1;
}
- /*
- * TODO: Alternatively we could extract an archive found
- * as initrd to a ramfs '/' if we have got fsname 'initrd'
- */
-
return 0;
}