From d176b8c10411c9da2ed8e130da8f6a5401ab1ca9 Mon Sep 17 00:00:00 2001
From: Andrew Gaffney <agaffney@gentoo.org>
Date: Thu, 13 Mar 2008 01:33:15 +0000
Subject: [PATCH] Get rid of the ENABLE_PEGASOS_HACKS hacks Add
 INTEGRATED_INITRAMFS option to optionally insert the generated initramfs
 directly into the kernel image Change default build order to build the kernel
 last to facilitate the INTEGRATED_INITRAMFS option Add GENZIMAGE option and
 change various checks from ENABLE_PEGASOS_HACKS to GENZIMAGE

git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/genkernel/trunk@631 67a159dc-881f-0410-a524-ba9dfbe2cb84
---
 ChangeLog            |  9 +++++++++
 gen_cmdline.sh       |  8 ++++++--
 gen_compile.sh       |  4 ++--
 gen_determineargs.sh |  7 +++++++
 gen_initramfs.sh     | 10 ++--------
 gen_initrd.sh        | 12 ++++++------
 gen_package.sh       | 10 +++++-----
 genkernel            | 15 +--------------
 8 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fb466e5..3b2a604 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,15 @@
 # Copyright 2006-2008 Gentoo Foundation; Distributed under the GPL v2
 # $Header: $
 
+  13 Mar 2008; Andrew Gaffney <agaffney@gentoo.org> gen_cmdline.sh,
+  gen_compile.sh, gen_determineargs.sh, gen_initramfs.sh, gen_initrd.sh,
+  gen_package.sh, genkernel:
+  Get rid of the ENABLE_PEGASOS_HACKS hacks Add INTEGRATED_INITRAMFS option to
+  optionally insert the generated initramfs directly into the kernel image
+  Change default build order to build the kernel last to facilitate the
+  INTEGRATED_INITRAMFS option Add GENZIMAGE option and change various checks
+  from ENABLE_PEGASOS_HACKS to GENZIMAGE
+
   13 Mar 2008; Andrew Gaffney <agaffney@gentoo.org> gen_initramfs.sh:
   Argh...Changing the right line helps
 
diff --git a/gen_cmdline.sh b/gen_cmdline.sh
index 7b0e58b..6823da4 100755
--- a/gen_cmdline.sh
+++ b/gen_cmdline.sh
@@ -126,6 +126,9 @@ longusage() {
   echo "				Specifies specific firmware files to copy. This"
   echo "				overrides --firmware-dir. For multiple files,"
   echo "				separate the filenames with a comma"
+  echo "	--integrated-initramfs"
+  echo "				Build the generated initramfs into the kernel instead of"
+  echo "				keeping it as a separate file"
 }
 
 usage() {
@@ -474,8 +477,9 @@ parse_cmdline() {
 		--genzimage)
 			KERNEL_MAKE_DIRECTIVE_2='zImage.initrd'
 			KERNEL_BINARY_2='arch/powerpc/boot/zImage.initrd'
-			ENABLE_PEGASOS_HACKS="yes"
-			print_info 2 "ENABLE_PEGASOS_HACKS: ${ENABLE_PEGASOS_HACKS}"
+			CMD_GENZIMAGE="yes"
+#			ENABLE_PEGASOS_HACKS="yes"
+#			print_info 2 "ENABLE_PEGASOS_HACKS: ${ENABLE_PEGASOS_HACKS}"
 			;;
 		--disklabel)
 			CMD_DISKLABEL=1
diff --git a/gen_compile.sh b/gen_compile.sh
index a200ac4..57a093e 100644
--- a/gen_compile.sh
+++ b/gen_compile.sh
@@ -332,7 +332,7 @@ compile_kernel() {
 			"System.map" \
 			"System.map-${KNAME}-${ARCH}-${KV}"
 
-		if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
+		if isTrue "${GENZIMAGE}"
 		then
 			copy_image_with_preserve "kernelz" \
 				"${KERNEL_BINARY_2}" \
@@ -343,7 +343,7 @@ compile_kernel() {
 			gen_die "Could not copy the kernel binary to ${TMPDIR}!"
 		cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
 			gen_die "Could not copy System.map to ${TMPDIR}!"
-		if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
+		if isTrue "${GENZIMAGE}"
 		then
 			cp "${KERNEL_BINARY_2}" "${TMPDIR}/kernelz-${KV}" ||
 				gen_die "Could not copy the kernelz binary to ${TMPDIR}!"
diff --git a/gen_determineargs.sh b/gen_determineargs.sh
index 7203364..55e8836 100644
--- a/gen_determineargs.sh
+++ b/gen_determineargs.sh
@@ -117,6 +117,8 @@ determine_real_args() {
 	set_config_with_override 1 FIRMWARE             CMD_FIRMWARE
 	set_config_with_override 2 FIRMWARE_DIR         CMD_FIRMWARE_DIR         "/lib/firmware"
 	set_config_with_override 2 FIRMWARE_FILES       CMD_FIRMWARE_FILES
+	set_config_with_override 1 INTEGRATED_INITRAMFS CMD_INTEGRATED_INITRAMFS
+	set_config_with_override 1 GENZIMAGE            CMD_GENZIMAGE
 
 		BOOTDIR=`arch_replace "${BOOTDIR}"`
 		BOOTDIR=${BOOTDIR%/}    # Remove any trailing slash
@@ -197,6 +199,11 @@ determine_real_args() {
 	then
 		mkdir -p `dirname ${KERNCACHE}`
 	fi
+
+	if ! isTrue "${BUILD_INITRD}"
+	then
+		INTEGRATED_INITRAMFS=0
+	fi
 	
 	get_KV
 }
diff --git a/gen_initramfs.sh b/gen_initramfs.sh
index af06642..69f20f5 100644
--- a/gen_initramfs.sh
+++ b/gen_initramfs.sh
@@ -492,21 +492,15 @@ create_initramfs() {
 	gzip -9 "${CPIO}"
 	mv -f "${CPIO}.gz" "${CPIO}"
 
-	if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
+	if isTrue "${INTEGRATED_INITRAMFS}"
 	then
-			# Pegasos hack for merging the initramfs into the kernel at compile time
-			cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/arch/powerpc/boot/ramdisk.image.gz &&
-			rm ${TMPDIR}/initramfs-${KV}
-	elif [ ${BUILD_INITRAMFS} -eq '1' ]
-	then
-		# Mips also mimics Pegasos to merge the initramfs into the kernel
 		cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/initramfs.cpio.gz
 		gunzip -f ${KERNEL_DIR}/initramfs.cpio.gz
 	fi
 
 	if ! isTrue "${CMD_NOINSTALL}"
 	then
-		if [ "${ENABLE_PEGASOS_HACKS}" != 'yes' ]
+		if ! isTrue "${INTEGRATED_INITRAMFS}"
 		then
 			copy_image_with_preserve "initramfs" \
 				"${TMPDIR}/initramfs-${KV}" \
diff --git a/gen_initrd.sh b/gen_initrd.sh
index 0a5155e..6b20c8d 100644
--- a/gen_initrd.sh
+++ b/gen_initrd.sh
@@ -348,10 +348,10 @@ create_initrd() {
 			"initrd-${KNAME}-${ARCH}-${KV}"
 	fi
 
-        if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
-        then
-		# Pegasos hack for merging the initramfs into the kernel at compile time
-		cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz &&
-		rm ${TMPDIR}/initrd-${KV}
-	fi
+#	if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
+#	then
+#		# Pegasos hack for merging the initramfs into the kernel at compile time
+#		cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz &&
+#		rm ${TMPDIR}/initrd-${KV}
+#	fi
 }
diff --git a/gen_package.sh b/gen_package.sh
index a4e9bd2..d5b54a7 100644
--- a/gen_package.sh
+++ b/gen_package.sh
@@ -8,7 +8,7 @@ gen_minkernpackage() {
 	then
 		/bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} kernel-${ARCH}-${KV}
 		/bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} config-${ARCH}-${KV}
-		if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
+		if isTrue "${GENZIMAGE}"
 		then
 			/bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} kernelz-${ARCH}-${KV}
 		fi
@@ -16,13 +16,13 @@ gen_minkernpackage() {
 		cd "${KERNEL_DIR}"
 		cp "${KERNEL_BINARY}" "${TEMP}/minkernpackage/kernel-${KV}" || gen_die 'Could not the copy kernel for the min kernel package!'
 		cp ".config" "${TEMP}/minkernpackage/config-${ARCH}-${KV}" || gen_die 'Could not the copy kernel config for the min kernel package!'
-		if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
+		if isTrue "${GENZIMAGE}"
 		then
 			cp "${KERNEL_BINARY_2}" "${TEMP}/minkernpackage/kernelz-${KV}" || gen_die "Could not copy the kernelz for the min kernel package"
 		fi
 	fi
 	
-	if [ "${ENABLE_PEGASOS_HACKS}" != 'yes' ]
+	if ! isTrue "${INTEGRATED_INITRAMFS}"
 	then
 		if [ "${KERN_24}" != '1' ]
 		then
@@ -69,7 +69,7 @@ gen_kerncache()
 	cp "${KERNEL_BINARY}" "${TEMP}/kerncache/kernel-${ARCH}-${KV}" || gen_die 'Could not the copy kernel for the kernel package!'
 	cp "${KERNEL_DIR}/.config" "${TEMP}/kerncache/config-${ARCH}-${KV}"
 	cp "${KERNEL_DIR}/System.map" "${TEMP}/kerncache/System.map-${ARCH}-${KV}"
-	if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
+	if isTrue "${GENZIMAGE}"
         then
         	cp "${KERNEL_BINARY_2}" "${TEMP}/kerncache/kernelz-${ARCH}-${KV}" || gen_die "Could not copy the kernelz for the kernel package"
         fi
@@ -98,7 +98,7 @@ gen_kerncache_extract_kernel()
 		"${TEMP}/kernel-${ARCH}-${KV}" \
 		"kernel-${KNAME}-${ARCH}-${KV}"
 
-	if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
+	if isTrue "${GENZIMAGE}"
 	then
 		copy_image_with_preserve "kernelz" \
 			"${TEMP}/kernelz-${ARCH}-${KV}" \
diff --git a/genkernel b/genkernel
index 5d75a0b..4187f9e 100755
--- a/genkernel
+++ b/genkernel
@@ -231,10 +231,6 @@ then
 	# KV may have changed due to the configuration
 	get_KV
 
-	# Compile kernel; If using --genzimage, or building a mips kernel, skip
-	# compile until after initrd/initramfs is done
-	[ "${ENABLE_PEGASOS_HACKS}" != 'yes' -a ${BUILD_INITRAMFS} -eq '0' ] && compile_kernel
-
 	# Compile modules
 	if [ ${BUILD_MODULES} -eq '1' -a ${BUILD_STATIC} -eq '0' ]
 	then
@@ -247,13 +243,6 @@ then
 		[ ! -e '/etc/kernels' ] && mkdir -p /etc/kernels
 		cp "${KERNEL_DIR}/.config" "/etc/kernels/kernel-config-${ARCH}-${KV}"
 	fi
-	if [ "${KERNCACHE}" != "" ]
-	then
-		if [ "${ENABLE_PEGASOS_HACKS}" != 'yes' -a ${BUILD_INITRAMFS} -eq 0 ]
-		then
-			gen_kerncache
-		fi
-	fi
 fi
 
 if ! isTrue "${CMD_NOINSTALL}"
@@ -326,10 +315,8 @@ else
 	print_info 1 'initrd: Not building since only the kernel was requested...'
 fi
 
-# Pegasos fix
-if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' -o ${BUILD_INITRAMFS} -eq 1 ]
+if isTrue "${INTEGRATED_INITRAMFS}" || [ ${BUILD_KERNEL} -eq '1' -a "${KERNCACHE_IS_VALID}" == "0" ]
 then
-	# Compile kernel, intergrating the initrd into it for Pegasos & mips
 	compile_kernel
 
 	# We skipped the kernel build and kerncache generation
-- 
2.26.2