initramfs: Add skip_initramfs command line option
authorRom Lemarchand <romlem@android.com>
Mon, 6 Jul 2015 23:50:33 +0000 (16:50 -0700)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 27 Oct 2015 08:28:09 +0000 (16:28 +0800)
Add a skip_initramfs option to allow choosing whether to boot using
the initramfs or not at runtime.

Change-Id: If30428fa748c1d4d3d7b9d97c1f781de5e4558c3
Signed-off-by: Rom Lemarchand <romlem@google.com>
(cherry picked from commit 6f36227aa43c9e4b17a2dcda6a38e79d1b00d1b5)

include/linux/initramfs.h [new file with mode: 0644]
init/Makefile
init/initramfs.c
init/noinitramfs.c

diff --git a/include/linux/initramfs.h b/include/linux/initramfs.h
new file mode 100644 (file)
index 0000000..fc7da63
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * include/linux/initramfs.h
+ *
+ * Copyright (C) 2015, Google
+ * Rom Lemarchand <romlem@android.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _LINUX_INITRAMFS_H
+#define _LINUX_INITRAMFS_H
+
+#include <linux/kconfig.h>
+
+#if IS_BUILTIN(CONFIG_BLK_DEV_INITRD)
+
+int __init default_rootfs(void);
+
+#endif
+
+#endif /* _LINUX_INITRAMFS_H */
index 7bc47ee31c369d442676edba32233fbb2ddbb462..692b91f1c1d4fb04e118e7fd170bf461f94aa72d 100644 (file)
@@ -3,11 +3,8 @@
 #
 
 obj-y                          := main.o version.o mounts.o
-ifneq ($(CONFIG_BLK_DEV_INITRD),y)
 obj-y                          += noinitramfs.o
-else
 obj-$(CONFIG_BLK_DEV_INITRD)   += initramfs.o
-endif
 obj-$(CONFIG_GENERIC_CALIBRATE_DELAY) += calibrate.o
 
 ifneq ($(CONFIG_ARCH_INIT_TASK),y)
index a67ef9dbda9dae0ea7a1619a393c55157a6d8592..43ae0cc9df48c1851a8611a247b26875430249a2 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/dirent.h>
 #include <linux/syscalls.h>
 #include <linux/utime.h>
+#include <linux/initramfs.h>
 
 static __initdata char *message;
 static void __init error(char *x)
@@ -579,9 +580,25 @@ static void __init clean_rootfs(void)
 }
 #endif
 
+static int __initdata do_skip_initramfs;
+
+static int __init skip_initramfs_param(char *str)
+{
+       if (*str)
+               return 0;
+       do_skip_initramfs = 1;
+       return 1;
+}
+__setup("skip_initramfs", skip_initramfs_param);
+
 static int __init populate_rootfs(void)
 {
-       char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
+       char *err;
+
+       if (do_skip_initramfs)
+               return default_rootfs();
+
+       err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
        if (err)
                panic(err);     /* Failed to decompress INTERNAL initramfs */
        if (initrd_start) {
index 267739d851791b0a3e4526a3be5fb4944d8b507e..bcc8bcb053eeb05dc095780fcbc276fa2f311bd4 100644 (file)
 #include <linux/stat.h>
 #include <linux/kdev_t.h>
 #include <linux/syscalls.h>
+#include <linux/kconfig.h>
+#include <linux/initramfs.h>
 
 /*
  * Create a simple rootfs that is similar to the default initramfs
  */
-static int __init default_rootfs(void)
+#if !IS_BUILTIN(CONFIG_BLK_DEV_INITRD)
+static
+#endif
+int __init default_rootfs(void)
 {
        int err;
 
@@ -49,4 +54,6 @@ out:
        printk(KERN_WARNING "Failed to create a rootfs\n");
        return err;
 }
+#if !IS_BUILTIN(CONFIG_BLK_DEV_INITRD)
 rootfs_initcall(default_rootfs);
+#endif