Skip to content

Commit c33df4e

Browse files
Jean-Paul SamanLinus Torvalds
authored andcommitted
[PATCH] disable init/initramfs.c
The file init/initramfs.c is always compiled and linked in the kernel vmlinux even when BLK_DEV_RAM and BLK_DEV_INITRD are disabled and the system isn't using any form of an initramfs or initrd. In this situation the code is only used to unpack a (static) default initial rootfilesystem. The current init/initramfs.c code. usr/initramfs_data.o compiles to a size of ~15 kbytes. Disabling BLK_DEV_RAM and BLK_DEV_INTRD shrinks the kernel code size with ~60 Kbytes. This patch avoids compiling in the code and data for initramfs support if CONFIG_BLK_DEV_INITRD is not defined. Instead of the initramfs code and data it uses a small routine in init/noinitramfs.c to setup an initial static default environment for mounting a rootfilesystem later on in the kernel initialisation process. The new code is: 164 bytes of size. The patch is separated in two parts: 1) doesn't compile initramfs code when CONFIG_BLK_DEV_INITRD is not set 2) changing all plaforms vmlinux.lds.S files to not reserve an area of PAGE_SIZE when CONFIG_BLK_DEV_INITRD is not set. [deweerdt@free.fr: warning fix] Signed-off-by: Jean-Paul Saman <jean-paul.saman@nxp.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: <linux-arch@vger.kernel.org> Signed-off-by: Frederik Deweerdt <frederik.deweerdt@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent dd65aa6 commit c33df4e

5 files changed

Lines changed: 66 additions & 3 deletions

File tree

‎drivers/block/Kconfig‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,10 @@ config BLK_DEV_INITRD
417417
etc. See <file:Documentation/initrd.txt> for details.
418418

419419
If RAM disk support (BLK_DEV_RAM) is also included, this
420-
also enables initial RAM disk (initrd) support.
420+
also enables initial RAM disk (initrd) support and adds
421+
15 Kbytes (more on some other architectures) to the kernel size.
421422

423+
If unsure say Y.
422424

423425
config CDROM_PKTCDVD
424426
tristate "Packet writing on CD/DVD media"

‎init/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,12 @@ config RELAY
280280

281281
If unsure, say N.
282282

283+
if BLK_DEV_INITRD
284+
283285
source "usr/Kconfig"
284286

287+
endif
288+
285289
config CC_OPTIMIZE_FOR_SIZE
286290
bool "Optimize for size (Look out for broken compilers!)"
287291
default y

‎init/Makefile‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
# Makefile for the linux kernel.
33
#
44

5-
obj-y := main.o version.o mounts.o initramfs.o
5+
obj-y := main.o version.o mounts.o
6+
ifneq ($(CONFIG_BLK_DEV_INITRD),y)
7+
obj-y += noinitramfs.o
8+
else
9+
obj-$(CONFIG_BLK_DEV_INITRD) += initramfs.o
10+
endif
611
obj-$(CONFIG_GENERIC_CALIBRATE_DELAY) += calibrate.o
712

813
mounts-y := do_mounts.o

‎init/noinitramfs.c‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* init/noinitramfs.c
3+
*
4+
* Copyright (C) 2006, NXP Semiconductors, All Rights Reserved
5+
* Author: Jean-Paul Saman <jean-paul.saman@nxp.com>
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+
#include <linux/init.h>
21+
#include <linux/stat.h>
22+
#include <linux/kdev_t.h>
23+
#include <linux/syscalls.h>
24+
25+
/*
26+
* Create a simple rootfs that is similar to the default initramfs
27+
*/
28+
static int __init default_rootfs(void)
29+
{
30+
int err;
31+
32+
err = sys_mkdir("/dev", 0755);
33+
if (err < 0)
34+
goto out;
35+
36+
err = sys_mknod((const char __user *) "/dev/console",
37+
S_IFCHR | S_IRUSR | S_IWUSR,
38+
new_encode_dev(MKDEV(5, 1)));
39+
if (err < 0)
40+
goto out;
41+
42+
err = sys_mkdir("/root", 0700);
43+
if (err < 0)
44+
goto out;
45+
46+
return 0;
47+
48+
out:
49+
printk(KERN_WARNING "Failed to create a rootfs\n");
50+
return err;
51+
}
52+
rootfs_initcall(default_rootfs);

‎usr/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PHONY += klibcdirs
77

88

99
# Generate builtin.o based on initramfs_data.o
10-
obj-y := initramfs_data.o
10+
obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
1111

1212
# initramfs_data.o contains the initramfs_data.cpio.gz image.
1313
# The image is included using .incbin, a dependency which is not

0 commit comments

Comments
 (0)