|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel,v2,1/5] lib/vfscore: Add support to mount initramfs to root
From: Robert Hrusecky <roberth@xxxxxxxxxxxxx>
Modify vfscore boot operation to run cpio extraction algorithm on initrd
memory region and mount the resulting filesystem at root.
Signed-off-by: Robert Hrusecky <roberth@xxxxxxxxxxxxx>
Signed-off-by: Omar Jamil <omarj2898@xxxxxxxxx>
Signed-off-by: Sachin Beldona <sachinbeldona@xxxxxxxxxx>
Signed-off-by: Gabriel Mocanu <gabi.mocanu98@xxxxxxxxx>
---
lib/Makefile.uk | 2 +-
lib/vfscore/Config.uk | 23 +++++++++++++++++++----
lib/vfscore/rootfs.c | 39 ++++++++++++++++++++++++++++++---------
3 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/lib/Makefile.uk b/lib/Makefile.uk
index ff69dfa..7c90723 100644
--- a/lib/Makefile.uk
+++ b/lib/Makefile.uk
@@ -21,7 +21,7 @@ $(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/syscall_shim))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/vfscore))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ramfs))
-$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/cpio))
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/ukcpio))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/devfs))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/9pfs))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/uklock))
diff --git a/lib/vfscore/Config.uk b/lib/vfscore/Config.uk
index 212575c..9938b12 100644
--- a/lib/vfscore/Config.uk
+++ b/lib/vfscore/Config.uk
@@ -9,6 +9,15 @@ config LIBVFSCORE
if LIBVFSCORE
menu "vfscore: Configuration"
+
+config LIBINITRAMFS
+ bool "initramfs: extract the given cpio file to /"
+ default n
+ select LIBRAMFS
+ select LIBUKLIBPARAM
+ select LIBVFSCORE_AUTOMOUNT_ROOTFS
+ select LIBCPIO
+
config LIBVFSCORE_PIPE_SIZE_ORDER
int "Pipe size order"
default 16
@@ -38,6 +47,11 @@ if LIBVFSCORE_AUTOMOUNT_ROOTFS
select LIBUK9P
select LIB9PFS
+ config LIBVFSCORE_ROOTFS_INITRD
+ bool "InitRD"
+ select LIBRAMFS
+ select LIBUKCPIO
+
config LIBVFSCORE_ROOTFS_CUSTOM
bool "Custom argument"
help
@@ -61,13 +75,14 @@ if LIBVFSCORE_AUTOMOUNT_ROOTFS
string
default "ramfs" if LIBVFSCORE_ROOTFS_RAMFS
default "9pfs" if LIBVFSCORE_ROOTFS_9PFS
- default LIBVFSCORE_ROOTFS_CUSTOM_ARG if LIBVFSCORE_ROOTFS_CUSTOM
+ 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
@@ -78,7 +93,7 @@ if LIBVFSCORE_AUTOMOUNT_ROOTFS
# 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.
@@ -86,7 +101,7 @@ if LIBVFSCORE_AUTOMOUNT_ROOTFS
# 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
diff --git a/lib/vfscore/rootfs.c b/lib/vfscore/rootfs.c
index 4b9512a..e83eec8 100644
--- a/lib/vfscore/rootfs.c
+++ b/lib/vfscore/rootfs.c
@@ -42,6 +42,11 @@
#include <sys/stat.h>
#include <sys/mount.h>
#include <uk/init.h>
+#ifdef CONFIG_LIBINITRAMFS
+#include <uk/plat/memory.h>
+#include <uk/cpio.h>
+#include <string.h>
+#endif
static const char *rootfs = CONFIG_LIBVFSCORE_ROOTFS;
@@ -80,16 +85,32 @@ static int vfscore_rootfs(void)
return -1;
}
- 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;
- }
+#if CONFIG_LIBUKCPIO && CONFIG_LIBRAMFS
+ if (strncmp(rootfs, "initrd", 5) == 0) {
+ struct ukplat_memregion_desc initrd;
+ enum ukcpio_error error;
- /*
- * TODO: Alternatively we could extract an archive found
- * as initrd to a ramfs '/' if we have got fsname 'initrd'
- */
+ if (ukplat_memregion_find_initrd0(&initrd) < 0){
+ uk_pr_crit("Could not find an initrd!\n");
+ return -1;
+ }
+
+ if (mount("", "/", "ramfs", 0, NULL) != 0) {
+ uk_pr_crit("Failed to mount ramfs to /: %d\n",
+ errno);
+ return -1;
+ }
+
+ 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
return 0;
}
--
2.17.1
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |