Bug#717805: Patch for dealing with newer initramfs images with microcode headers
Hi.
On Thu, Sep 26, 2013 at 06:19:38AM +0100, Ben Hutchings wrote:
> On Tue, 2013-09-24 at 16:11 +0100, Brett Parker wrote:
> > Hi,
> >
> > Here's a patch to lsinitramfs to deal with initramfs images that start
> > with the microcode archive and then a real archive afterwards.
>
> Thanks, Brett.
>
What do you think of the proposed version I'm attaching ?
I don't know about the +8 offset, but I do hope I have addressed the rest of the comments.
Not tested on various compressions, but basically helps solve this bug here, AFAICT.
I'm adding the new file as well, as it may help others without having to replay the patch.
Na warranty whatsoever.
Hope this helps.
Best regards,
--
Olivier BERGER
http://www-public.telecom-sudparis.eu/~berger_o/ - OpenPGP-Id: 2048R/5819D7E8
Ingenieur Recherche - Dept INF
Institut Mines-Telecom, Telecom SudParis, Evry (France)
--- lsinitramfs.orig 2013-07-23 19:19:27.000000000 +0200
+++ lsinitramfs 2013-10-29 18:51:44.000000000 +0100
@@ -4,7 +4,7 @@
usage()
{
- echo "Usage: $(basename $0) <initramfs file>"
+ echo "Usage: $(basename $0) [--long] <initramfs file>"
}
if [ "$#" -eq 0 ] ; then
@@ -40,20 +40,44 @@
esac
done
+
+listarchive()
+{
+ archive="$1"
+ if zcat -t "${archive}" >/dev/null 2>&1 ; then
+ zcat "${archive}" | cpio ${cpio_args}
+ elif xzcat -t "${archive}" >/dev/null 2>&1 ; then
+ xzcat "${archive}" | cpio ${cpio_args}
+ elif bzip2 -t "${archive}" >/dev/null 2>&1 ; then
+ bzip2 -c -d "${archive}" | cpio ${cpio_args}
+ elif lzop -t "${archive}" >/dev/null 2>&1 ; then
+ lzop -c -d "${archive}" | cpio ${cpio_args}
+ fi
+}
+
for initramfs in "$@" ; do
if ! [ -r "${initramfs}" ] ; then
echo "Specified file could not be read." >&2
exit 1
else
echo "${initramfs}"
- if zcat -t "${initramfs}" >/dev/null 2>&1 ; then
- zcat "${initramfs}" | cpio ${cpio_args}
- elif xzcat -t "$initramfs" >/dev/null 2>&1 ; then
- xzcat "$initramfs" | cpio ${cpio_args}
- 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}
+ if 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
+ real_offset=$((real_offset+8))
+
+ subarchive=$(mktemp ${TMPDIR:-/var/tmp}/lsinitramfs_XXXXXX)
+ dd if="$initramfs" bs=$real_offset skip=1 status=noxfer >$subarchive 2>/dev/null
+
+ listarchive $subarchive
+
+ rm -fr $subarchive
+ else
+ listarchive "${initramfs}"
fi
fi
#!/bin/sh
set -eu
usage()
{
echo "Usage: $(basename $0) [--long] <initramfs file>"
}
if [ "$#" -eq 0 ] ; then
usage >&2
exit 1
fi
cpio_args="--extract --quiet --list"
OPTIONS=`getopt -o hl --long help,long -n "$0" -- "$@"`
# Check for non-GNU getopt
if [ $? != 0 ] ; then echo "W: non-GNU getopt" >&2 ; exit 1 ; fi
eval set -- "$OPTIONS"
while true; do
case "$1" in
-h|--help)
usage
exit 0
;;
-l|--long)
cpio_args="${cpio_args:+${cpio_args} --verbose}"
shift
;;
--)
shift
break
;;
*)
echo "Internal error!" >&2
exit 1
esac
done
listarchive()
{
archive="$1"
if zcat -t "${archive}" >/dev/null 2>&1 ; then
zcat "${archive}" | cpio ${cpio_args}
elif xzcat -t "${archive}" >/dev/null 2>&1 ; then
xzcat "${archive}" | cpio ${cpio_args}
elif bzip2 -t "${archive}" >/dev/null 2>&1 ; then
bzip2 -c -d "${archive}" | cpio ${cpio_args}
elif lzop -t "${archive}" >/dev/null 2>&1 ; then
lzop -c -d "${archive}" | cpio ${cpio_args}
fi
}
for initramfs in "$@" ; do
if ! [ -r "${initramfs}" ] ; then
echo "Specified file could not be read." >&2
exit 1
else
echo "${initramfs}"
if 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
real_offset=$((real_offset+8))
subarchive=$(mktemp ${TMPDIR:-/var/tmp}/lsinitramfs_XXXXXX)
dd if="$initramfs" bs=$real_offset skip=1 status=noxfer >$subarchive 2>/dev/null
listarchive $subarchive
rm -fr $subarchive
else
listarchive "${initramfs}"
fi
fi
done
Reply to: