[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#712521: initramfs-tools: please add early-initramfs support for ucode update



Package: initramfs-tools
Version: 0.112+nmu1
Severity: wishlist
Tags: patch

Enclosed you will find two patches to add early-initramfs support to
initramfs-tools.

It adds, and properly documents, a hook function that allows packages
to _prepend_ data to the main initramfs archive.

It will be used by intel-microcode and amd64-microcode to supply an early
initramfs with microcode data for the kernel.  This is extremely important
to properly work around bugs that would otherwise force the kernel to
disable important functionality (such as the ones in the Atom that requires
disabling PME, which previously required a bios update or the use of Intel
BITS to work around.  We have several documented cases of Debian users that
cannot use either method).

Please review and comment.  If it is OK, please apply.
git tree for git merge available upon request.

-- no debconf information

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
>From 53852844059e8dac529618acfeffc285b32a3ee5 Mon Sep 17 00:00:00 2001
From: Henrique de Moraes Holschuh <hmh@debian.org>
Date: Fri, 31 May 2013 22:16:44 -0300
Subject: [PATCH 1/2] implement early initramfs support

Add a new hook function, prepend_earlyinitramfs(), which prepends
the content of the file passed as a parameter to the initramfs
that will be generated.

This will be used to pass system processor microcode and ACPI table
overrides to the kernel (requires Linux kernel v3.9 or later).

Signed-off-by: Henrique de Moraes Holschuh <hmh@debian.org>
---
 hook-functions    |   10 ++++++++++
 initramfs-tools.8 |   14 ++++++++++++++
 mkinitramfs       |   19 ++++++++++++++++---
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/hook-functions b/hook-functions
index 817d06c..e751021 100644
--- a/hook-functions
+++ b/hook-functions
@@ -10,6 +10,16 @@ catenate_cpiogz() {
 	cat "${1}" >>"${__TMPCPIOGZ}"
 }
 
+prepend_earlyinitramfs() {
+	# Sanity check
+	if [ ! -e "${1}" ]; then
+		echo "W: prepend_earlyinitramfs: arg1='${1}' does not exist." >&2
+		return
+	fi
+
+	cat "${1}" >>"${__TMPEARLYCPIO}"
+}
+
 # force_load module [args...]
 force_load()
 {
diff --git a/initramfs-tools.8 b/initramfs-tools.8
index 375e5c1..546bb01 100644
--- a/initramfs-tools.8
+++ b/initramfs-tools.8
@@ -240,6 +240,20 @@ and copy them to the initramfs. This means that most executables, unless
 compiled with klibc, will automatically include glibc in the image which will
 increase its size by several hundred kilobytes.
 
+.SS Including a system firmware preimage (early initramfs)
+If you need to prepend data to the initramfs image, you need to prepare it
+in a file, and call the \fB\fIprepend_earlyinitramfs\fR function.  The file
+can be disposed of as soon as the function returns.
+
+.B Example:
+.nf
+TEMP_FILE=$(mktemp ...)
+  ...
+prepend_earlyinitramfs ${TEMP_FILE}
+rm -f ${TEMP_FILE}
+
+.RE
+
 .SS Exported variables
 mkinitramfs sets several variables for the hook scripts environment.
 
diff --git a/mkinitramfs b/mkinitramfs
index d9a54e2..cdec420 100755
--- a/mkinitramfs
+++ b/mkinitramfs
@@ -175,6 +175,7 @@ if [ -n "$fs" ] && mount | grep -q "on $fs .*noexec" ; then
 fi
 
 __TMPCPIOGZ="$(mktemp ${TMPDIR:-/var/tmp}/mkinitramfs-OL_XXXXXX)" || exit 1
+__TMPEARLYCPIO="$(mktemp ${TMPDIR:-/var/tmp}/mkinitramfs-FW_XXXXXX)" || exit 1
 
 DPKG_ARCH=`dpkg --print-architecture`
 
@@ -193,6 +194,9 @@ export BUSYBOX
 # Private, used by 'catenate_cpiogz'.
 export __TMPCPIOGZ
 
+# Private, used by 'prepend_earlyinitramfs'.
+export __TMPEARLYCPIO
+
 for d in bin conf/conf.d etc lib/modules run sbin scripts ${MODULESDIR}; do
 	mkdir -p "${DESTDIR}/${d}"
 done
@@ -331,9 +335,17 @@ if [ "$DPKG_ARCH" = armhf ]; then
 fi
 
 [ "${verbose}" = y ] && echo "Building cpio ${outfile} initramfs"
+
+if [ -s "${__TMPEARLYCPIO}" ]; then
+	cat "${__TMPEARLYCPIO}" >"${outfile}" || exit 1
+else
+	# truncate
+	> "${outfile}"
+fi
+
 (
 # work around lack of "set -o pipefail" for the following pipe:
-# cd "${DESTDIR}" && find . | cpio --quiet -R 0:0 -o -H newc | gzip >"${outfile}" || exit 1
+# cd "${DESTDIR}" && find . | cpio --quiet -R 0:0 -o -H newc | gzip >>"${outfile}" || exit 1
 exec 3>&1
 eval `
 	# http://cfaj.freeshell.org/shell/cus-faq-2.html
@@ -343,7 +355,7 @@ eval `
 		find . 4>&-; echo "ec1=$?;" >&4
 	} | {
 		cpio --quiet -R 0:0 -o -H newc 4>&-; echo "ec2=$?;" >&4
-	} | ${compress} >"${outfile}"
+	} | ${compress} >>"${outfile}"
 	echo "ec3=$?;" >&4
 `
 if [ "$ec1" -ne 0 ]; then
@@ -365,10 +377,11 @@ if [ -s "${__TMPCPIOGZ}" ]; then
 fi
 
 if [ "${keep}" = "y" ]; then
-	echo "Working files in ${DESTDIR} and overlay in ${__TMPCPIOGZ}"
+	echo "Working files in ${DESTDIR}, early initramfs in ${__TMPEARLYCPIO} and overlay in ${__TMPCPIOGZ}"
 else
 	rm -rf "${DESTDIR}"
 	rm -rf "${__TMPCPIOGZ}"
+	rm -rf "${__TMPEARLYCPIO}"
 fi
 
 exit 0
-- 
1.7.10.4

>From 810e64e2460978dc509930f64a4f2a3576a1a1b2 Mon Sep 17 00:00:00 2001
From: Henrique de Moraes Holschuh <hmh@debian.org>
Date: Sun, 2 Jun 2013 17:50:36 -0300
Subject: [PATCH 2/2] lsinitramfs(8): document failure to deal with early
 initramfs

lsinitramfs cannot deal with a multi-segmented initramfs archive, such
as one with an uncompressed early initramfs prepended to the main
compressed initramfs.  Document this in the manpage.

The kernel will parse all cpio archives it can find in the initramfs in
sequence, and it doesn't care if some of them are compressed and others
are not.

Signed-off-by: Henrique de Moraes Holschuh <hmh@debian.org>
---
 lsinitramfs.8 |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lsinitramfs.8 b/lsinitramfs.8
index b07ddeb..798aa8d 100644
--- a/lsinitramfs.8
+++ b/lsinitramfs.8
@@ -36,6 +36,13 @@ List content of two initramfs files in verbose mode:
 .PP
 .B lsinitramfs -l /boot/vmlinuz-2.6.31-grml64 /boot/vmlinuz-2.6.33-grml64
 
+.SH BUGS
+.BR lsinitramfs
+cannot deal with multiple-segmented initramfs images, such as those created
+when an early (uncompressed) initramfs with system firmware is prepended to
+the regular compressed initrams, or when overlay data is appended to the
+initramfs.
+
 .SH AUTHOR
 The initramfs-tools are written by Maximilian Attems <maks@debian.org>
 and numerous others.
-- 
1.7.10.4


Reply to: