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

Bug#717805: Patch for dealing with newer initramfs images with microcode headers



Hi,

Here's a patch to lsinitramfs to deal with initramfs images that start
with the microcode archive and then a real archive afterwards.

-- 
Brett Parker
diff -rU4 initramfs-tools/lsinitramfs initramfs-tools-0.109.1.new/lsinitramfs
--- initramfs-tools/lsinitramfs	2012-03-25 05:12:23.000000000 +0100
+++ initramfs-tools-0.109.1.new/lsinitramfs	2013-09-24 16:05:13.024780933 +0100
@@ -53,8 +53,25 @@
 		elif bzip2 -t "$initramfs" >/dev/null 2>&1 ; then
 			bzip2 -c -d "$initramfs" | cpio ${cpio_args}
 		elif lzop -t "$initramfs" >/dev/null 2>&1 ; then
 			lzop -c -d "$initramfs" | cpio ${cpio_args}
+		elif cpio ${cpio_args} < "$initramfs" >/dev/null 2>&1; then
+			# this is a straight cpio archive followed by a compressed one, yay!
+			cpio ${cpio_args} < "$initramfs"
+			real_offset=$(cpio --io-size=1 --extract --list < "$initramfs" 2>&1 >/dev/null | sed -e '$ { s# .*$##; p; }; d;')
+			# now we need to find the beginning of the actual archive, this is
+			# going to be the number of bytes from above + 8
+
+			# use same logic as above to loop through the potentials
+			if (dd if="$initramfs" bs=$((real_offset+8)) skip=1 status=noxfer 2>/dev/null | zcat -t >/dev/null 2>&1); then
+				dd if="$initramfs" bs=$((real_offset+8)) skip=1 status=noxfer 2>/dev/null | zcat | cpio ${cpio_args}
+			elif (dd if="$initramfs" bs=$((real_offset+8)) skip=1 status=noxfer 2>/dev/null | xzcat -t >/dev/null 2>&1); then
+				dd if="$initramfs" bs=$((real_offset+8)) skip=1 status=noxfer 2>/dev/null | xzcat | cpio ${cpio_args}
+			fi
+			elif (dd if="$initramfs" bs=$((real_offset+8)) skip=1 status=noxfer 2>/dev/null | bzip2 -t >/dev/null 2>&1); then
+				dd if="$initramfs" bs=$((real_offset+8)) skip=1 status=noxfer 2>/dev/null | bzip2 -c -d | cpio ${cpio_args}
+			elif (dd if="$initramfs" bs=$((real_offset+8)) skip=1 status=noxfer 2>/dev/null | lzop -t >/dev/null 2>&1); then
+				dd if="$initramfs" bs=$((real_offset+8)) skip=1 status=noxfer 2>/dev/null | lzop -c -d | cpio ${cpio_args}
 		fi
 
 	fi
 done

Reply to: