Skip to content

Commit 6f36227

Browse files
romlromlem-goog
authored andcommitted
initramfs: Add skip_initramfs command line option
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 <[email protected]>
1 parent 170fc78 commit 6f36227

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

include/linux/initramfs.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* include/linux/initramfs.h
3+
*
4+
* Copyright (C) 2015, Google
5+
* Rom Lemarchand <[email protected]>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; version 2 of the License.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19+
*/
20+
21+
#ifndef _LINUX_INITRAMFS_H
22+
#define _LINUX_INITRAMFS_H
23+
24+
#include <linux/kconfig.h>
25+
26+
#if IS_BUILTIN(CONFIG_BLK_DEV_INITRD)
27+
28+
int __init default_rootfs(void);
29+
30+
#endif
31+
32+
#endif /* _LINUX_INITRAMFS_H */

init/Makefile

-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
#
44

55
obj-y := main.o version.o mounts.o
6-
ifneq ($(CONFIG_BLK_DEV_INITRD),y)
76
obj-y += noinitramfs.o
8-
else
97
obj-$(CONFIG_BLK_DEV_INITRD) += initramfs.o
10-
endif
118
obj-$(CONFIG_GENERIC_CALIBRATE_DELAY) += calibrate.o
129

1310
ifneq ($(CONFIG_ARCH_INIT_TASK),y)

init/initramfs.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/dirent.h>
1919
#include <linux/syscalls.h>
2020
#include <linux/utime.h>
21+
#include <linux/initramfs.h>
2122

2223
static __initdata char *message;
2324
static void __init error(char *x)
@@ -579,9 +580,25 @@ static void __init clean_rootfs(void)
579580
}
580581
#endif
581582

583+
static int __initdata do_skip_initramfs;
584+
585+
static int __init skip_initramfs_param(char *str)
586+
{
587+
if (*str)
588+
return 0;
589+
do_skip_initramfs = 1;
590+
return 1;
591+
}
592+
__setup("skip_initramfs", skip_initramfs_param);
593+
582594
static int __init populate_rootfs(void)
583595
{
584-
char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
596+
char *err;
597+
598+
if (do_skip_initramfs)
599+
return default_rootfs();
600+
601+
err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
585602
if (err)
586603
panic(err); /* Failed to decompress INTERNAL initramfs */
587604
if (initrd_start) {

init/noinitramfs.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
#include <linux/stat.h>
2222
#include <linux/kdev_t.h>
2323
#include <linux/syscalls.h>
24+
#include <linux/kconfig.h>
25+
#include <linux/initramfs.h>
2426

2527
/*
2628
* Create a simple rootfs that is similar to the default initramfs
2729
*/
28-
static int __init default_rootfs(void)
30+
#if !IS_BUILTIN(CONFIG_BLK_DEV_INITRD)
31+
static
32+
#endif
33+
int __init default_rootfs(void)
2934
{
3035
int err;
3136

@@ -49,4 +54,6 @@ static int __init default_rootfs(void)
4954
printk(KERN_WARNING "Failed to create a rootfs\n");
5055
return err;
5156
}
57+
#if !IS_BUILTIN(CONFIG_BLK_DEV_INITRD)
5258
rootfs_initcall(default_rootfs);
59+
#endif

0 commit comments

Comments
 (0)