فهرست منبع

mk/image.mk: improve and simplify initramfs generation

Using the kernel tools is a lot better than calling cpio ourselfs, as
this way we can have it create device nodes for us. So no need to reopen
/dev/console and things like that.

While here, fix also initramfs compression (untested), as in my
experience the kernel drops all symbols regarding compression from it's
.config in the first compile phase. Probably one should make the actual
compression algorithm configurable (and ideally depending on what the
kernel supports for the given architecture).

This is a rough hack based on what I'm using in the custom viprinux
build file, so something like this is already running somewhere. ;)
Phil Sutter 13 سال پیش
والد
کامیت
6e06191abd

+ 25 - 18
mk/image.mk

@@ -71,14 +71,12 @@ INITRAMFS=		${ADK_TARGET_SYSTEM}-$(CPU_ARCH)-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}
 ROOTFSSQUASHFS=		${ADK_TARGET_SYSTEM}-$(CPU_ARCH)-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}.img
 ROOTFSTARBALL=		${ADK_TARGET_SYSTEM}-$(CPU_ARCH)-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}+kernel.tar.gz
 ROOTFSUSERTARBALL=	${ADK_TARGET_SYSTEM}-$(CPU_ARCH)-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}.tar.gz
-INITRAMFS_PIGGYBACK=	${ADK_TARGET_SYSTEM}-$(CPU_ARCH)-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}.cpio
 else
 TARGET_KERNEL=		${ADK_TARGET_SYSTEM}-${ADK_TARGET_FS}-kernel
 INITRAMFS=		${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}
 ROOTFSSQUASHFS=		${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}.img
 ROOTFSTARBALL=		${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}+kernel.tar.gz
 ROOTFSUSERTARBALL=	${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}.tar.gz
-INITRAMFS_PIGGYBACK=	${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}.cpio
 endif
 
 ${BIN_DIR}/${ROOTFSTARBALL}: ${TARGET_DIR} kernel-package
@@ -91,29 +89,38 @@ ${BIN_DIR}/${ROOTFSUSERTARBALL}: ${TARGET_DIR}
 		sed "s#\(.*\)#:0:0::::::\1#" | sort | \
 		${TOOLS_DIR}/cpio -o -Hustar -P | gzip -n9 >$@
 
-${BIN_DIR}/${INITRAMFS}: ${TARGET_DIR}
-	cd ${TARGET_DIR}; find . | sed -n '/^\.\//s///p' | \
-		sed "s#\(.*\)#:0:0::::::\1#" | sort | \
-	    ${TOOLS_DIR}/cpio -o -C512 -Hnewc -P | \
-		xz -C crc32 >$@ 2>/dev/null
+${BIN_DIR}/${INITRAMFS}_list: ${TARGET_DIR}
+	sh ${LINUX_DIR}/scripts/gen_initramfs_list.sh -u squash -g squash \
+		${TARGET_DIR}/ >$@
+	( \
+		echo "nod /dev/console 0644 0 0 c 5 1"; \
+		echo "nod /dev/tty 0644 0 0 c 5 0"; \
+		for i in 0 1 2 3 4; do \
+			echo "nod /dev/tty$$i 0644 0 0 c 4 $i"; \
+		done \
+		echo "nod /dev/systty 0644 0 0 c 4 0"; \
+		echo "nod /dev/null 0644 0 0 c 1 3"; \
+		echo "nod /dev/ram 0655 0 0 b 1 1"; \
+	) >>$@
 
-${BUILD_DIR}/${INITRAMFS_PIGGYBACK}: ${TARGET_DIR}
-	${SED} 's/.*CONFIG_(BLK_DEV_INITRD|INITRAMFS_SOURCE).*//' \
-		${LINUX_DIR}/.config
-	echo "CONFIG_BLK_DEV_INITRD=y" >> ${LINUX_DIR}/.config
-	echo 'CONFIG_INITRAMFS_SOURCE="${BUILD_DIR}/${INITRAMFS_PIGGYBACK}"' >> \
-		${LINUX_DIR}/.config
-	cp $(TOPDIR)/scripts/dev.cpio $@
-	cd ${TARGET_DIR}; find . | sed -n '/^\.\//s///p' | \
-		sed "s#\(.*\)#:0:0::::::\1#" | sort | \
-	    ${TOOLS_DIR}/cpio -o -C512 -Hnewc -A -P -O $@ 2>/dev/null
+${BIN_DIR}/${INITRAMFS}: ${BIN_DIR}/${INITRAMFS}_list
+	sh ${LINUX_DIR}/usr/gen_init_cpio ${BIN_DIR}/${INITRAMFS}_list | \
+		gzip -9 -c >$@
 
 ${BUILD_DIR}/root.squashfs: ${TARGET_DIR}
 	${STAGING_HOST_DIR}/bin/mksquashfs ${TARGET_DIR} \
 		${BUILD_DIR}/root.squashfs \
 		-nopad -noappend -root-owned $(MAKE_TRACE)
 
-createinitramfs:
+createinitramfs: ${BIN_DIR}/${INITRAMFS}_list
+	${SED} 's/.*CONFIG_(BLK_DEV_INITRD|INITRAMFS_SOURCE).*//' \
+		${LINUX_DIR}/.config
+	( \
+		echo "CONFIG_BLK_DEV_INITRD=y"; \
+		echo 'CONFIG_INITRAMFS_SOURCE="${BIN_DIR}/${INITRAMFS}_list"'; \
+		echo "CONFIG_INITRAMFS_COMPRESSION_GZIP=y"; \
+	) >> ${LINUX_DIR}/.config
+
 	@-rm $(LINUX_DIR)/usr/initramfs_data.cpio* $(MAKE_TRACE)
 	echo N | \
 	$(MAKE) -C $(LINUX_DIR) V=1 CROSS_COMPILE="$(TARGET_CROSS)" \

+ 0 - 1
package/base-files/src/init

@@ -14,7 +14,6 @@ mount -o remount,nosuid,size=128k,mode=0755 -t tmpfs mdev /dev
 [ -d /dev/shm ] || mkdir /dev/shm
 mount -o nosuid,noexec -t tmpfs tmpfs /dev/shm
 mount -o nosuid,noexec -t devpts devpts /dev/pts
-exec 0<>/dev/console >&0 2>&0
 echo >/dev/mdev.seq
 echo "/sbin/mdev" >/proc/sys/kernel/hotplug
 mdev -s

+ 1 - 1
target/arm/Makefile

@@ -74,7 +74,7 @@ ifeq ($(ADK_TARGET_SYSTEM_QEMU_ARM),y)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/$(TARGET_KERNEL)
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifeq ($(ADK_TARGET_SYSTEM_QEMU_ARM),y)

+ 1 - 1
target/avr32/Makefile

@@ -22,7 +22,7 @@ imageinstall: $(BIN_DIR)/$(INITRAMFS)
 	@echo 'The initramfs image is: ${BIN_DIR}/${INITRAMFS}'
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/${TARGET_KERNEL}
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 endif

+ 1 - 1
target/cris/Makefile

@@ -66,7 +66,7 @@ ifeq ($(ADK_TARGET_SYSTEM_QEMU_CRIS),y)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/${TARGET_KERNEL}
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifeq ($(ADK_TARGET_SYSTEM_QEMU_CRIS),y)

+ 1 - 1
target/mips/Makefile

@@ -131,7 +131,7 @@ ifneq ($(ADK_HARDWARE_QEMU),)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/$(TARGET_KERNEL)
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifneq ($(ADK_HARDWARE_QEMU),)

+ 1 - 1
target/native/Makefile

@@ -21,7 +21,7 @@ imageinstall: $(BIN_DIR)/$(INITRAMFS)
 	@echo 'The initramfs image is: ${BIN_DIR}/${INITRAMFS}'
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/${TARGET_KERNEL}
 	@echo 'The kernel+initramfs file is: ${BIN_DIR}/${TARGET_KERNEL}'
 endif

+ 1 - 1
target/ppc/Makefile

@@ -33,7 +33,7 @@ ifeq ($(ADK_TARGET_SYSTEM_QEMU_PPC),y)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/${TARGET_KERNEL}
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifeq ($(ADK_TARGET_SYSTEM_QEMU_PPC),y)

+ 1 - 1
target/ppc64/Makefile

@@ -26,7 +26,7 @@ ifeq ($(ADK_TARGET_SYSTEM_QEMU_PPC64),y)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/${TARGET_KERNEL}
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifeq ($(ADK_TARGET_SYSTEM_QEMU_PPC64),y)

+ 1 - 1
target/sh/Makefile

@@ -26,7 +26,7 @@ ifeq ($(ADK_TARGET_SYSTEM_QEMU_SH),y)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/${TARGET_KERNEL}
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifeq ($(ADK_TARGET_SYSTEM_QEMU_SH),y)

+ 1 - 1
target/sparc/Makefile

@@ -32,7 +32,7 @@ ifeq ($(ADK_TARGET_SYSTEM_QEMU_SPARC),y)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/${TARGET_KERNEL}
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifeq ($(ADK_TARGET_SYSTEM_QEMU_SPARC),y)

+ 1 - 1
target/sparc64/Makefile

@@ -32,7 +32,7 @@ ifeq ($(ADK_TARGET_SYSTEM_QEMU_SPARC64),y)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/${TARGET_KERNEL}
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifeq ($(ADK_TARGET_SYSTEM_QEMU_SPARC64),y)

+ 1 - 1
target/x86/Makefile

@@ -47,7 +47,7 @@ ifeq ($(ADK_HARDWARE_QEMU),y)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/${TARGET_KERNEL}
 	@echo 'The kernel+initramfs file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifeq ($(ADK_HARDWARE_QEMU),y)

+ 1 - 1
target/x86_64/Makefile

@@ -36,7 +36,7 @@ ifeq ($(ADK_TARGET_SYSTEM_QEMU_X86_64),y)
 endif
 endif
 ifeq ($(ADK_TARGET_FS),initramfs-piggyback)
-imageinstall: ${BUILD_DIR}/${INITRAMFS_PIGGYBACK} createinitramfs
+imageinstall: createinitramfs
 	@cp $(KERNEL) $(BIN_DIR)/$(TARGET_KERNEL)
 	@echo 'The kernel file is: $(BIN_DIR)/${TARGET_KERNEL}'
 ifeq ($(ADK_TARGET_SYSTEM_QEMU_X86_64),y)