getabis 2.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash

if [ "$#" != "2" ]; then
	echo "Usage: $0 <release> <revision>" 1>&2
	exit 1
fi

if [ "$DEBIAN" = "" ]; then
	. debian/debian.env
fi

ver=$1
revision=$2
14
abi=$(echo $revision | gawk -F. '{print $1}')
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

verabi=$ver-$abi
verfull=$ver-$revision

WGET="wget --tries=1 --timeout=10 --quiet -c"

abidir="`pwd`/$DEBIAN/abi/$verfull"
tmpdir="`pwd`/abi-tmp-$verfull"
origdir="`pwd`"
fwinfo=$abidir/fwinfo

test -d $tmpdir || mkdir $tmpdir

package_prefixes() {
	__package_prefixes="$@"
}

getall() {
	arch=$1
	shift

	mkdir -p $abidir/$arch

	for sub in $@; do
		if [ -f $abidir/$arch/$sub ]; then
			echo "Exists: $sub"
			continue
		fi
		echo -n "Fetching $sub($arch)..."
		prefixes=""
		filenames=""
		cd $tmpdir
		for prefix in $__package_prefixes
		do
			filename=${prefix}-${verabi}-${sub}_${verfull}_${arch}.deb
			for r in "${repo_list[@]}"
			do
				if ! [ -f $filename ]; then
					$WGET $r/$filename
				fi
				if [ -f $filename ]; then
					prefixes="$prefixes $prefix"
					filenames="$filenames $filename"
					break
				fi
			done
		done
		if [ "$filenames" != "" ]; then
			echo -n "extracting$prefixes..."
			for filename in $filenames
			do
				dpkg-deb --extract $filename tmp
			done
			find tmp -name "*.ko" | while read f; do
				modinfo $f | grep ^firmware >> $fwinfo
			done
			if [ -f tmp/boot/abi-* ]; then
				mv tmp/boot/abi-* $abidir/$arch/$sub
			else
				echo -n "NO ABI FILE..."
			fi
			(cd tmp; find lib/modules/$verabi-$sub/kernel -name '*.ko') | \
				sed -e 's/.*\/\([^\/]*\)\.ko/\1/' | sort > \
				$abidir/$arch/$sub.modules
			(
				cd tmp;
				# Prevent exposing some errors when called by python scripts. SIGPIPE seems to get
				# exposed when using the `find ...` form of the command.
				ko=$(find lib/modules/$verabi-$sub/kernel \
					-name '*.ko' | head -1)
85
				readelf -p .comment "$ko" | gawk '
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
					($1 == "[") {
						printf("%s", $3);
						for (n=4; n<=NF; n++) {
							printf(" %s", $n);
						}
						print ""
					}' | sort -u >$abidir/$arch/$sub.compiler
				version=`cat $abidir/$arch/$sub.compiler`
				echo -n "$version..."
			)
			rm -rf tmp $filenames
			echo "done."
		else
			echo "FAILED."
		fi
		cd $origdir
	done
}

# MAIN

# Setup abi directory
mkdir -p $abidir
echo $abi > $abidir/abiname

# NOTE: The flavours are hardcoded, because they may have changed from the
# current build.

__package_prefixes="linux-image"

. $DEBIAN/etc/getabis

compilers=`cat $abidir/*/*.compiler | sort -u | wc -l`
if [ "$compilers" != 1 ]; then
	echo "WARNING: inconsistant compiler versions detected" 1>&2
fi

sort < $fwinfo | uniq > fwinfo.tmp
mv fwinfo.tmp $fwinfo

rmdir $tmpdir
127 128 129 130

# Add the new ABI directory, remove the old
git add $abidir
find $DEBIAN/abi/* -maxdepth 0 -type d | grep -v $verfull | while read f; do git rm -r $f;done