Attached is a patch to the latest (2.6.30.5) deblob script, it enhances
the error handling mechanisms, adding some double checks that allow you
to run it over a non-matching kernel version. It gives some extra info:

- If a file is not found, it will search for it and warn you.
- If a variable isn't found in a Makefile, it will search in the others.
- Several changes were made to avoid change attempts against missing
files. No empty files (or .deblob empty copies) are created now.
- The deblob script should be runnable multiple times without harm.
- die(), fatal() and --force handling rewritten, die calls changed.
- It will only print "removed blobs" and other messages when they are
actually done, instead of showing both success and failure messages.
- A simple dev_name macro was added, for compatibility with kernels
prior to 2.6.25. This needs to be tested, it might need a conditional.
- The script will run with no changes if you use the matching kernel.

Hopefully, the script can now be applied to older kernels, combined with
the old deblob script, to add the latest linux-libre features to it.
To do so, you have to run the original deblober -you should get no
errors-, and then this one, ignoring all errors. Then take a look on the
alternative path warnings -if any-, and modify the script accordingly.
If a double-cleaned driver fail to compile, avoid the second pass for
that one. For a piece of mind, run the checker script before publishing.

I'll try to add an optional driver removal mechanism to it anytime soon.
--- deblob-2.6.30_orig	2009-06-12 18:37:42.000000000 +0200
+++ deblob-2.6.30	2009-08-30 02:25:02.104996963 +0200
@@ -2,6 +2,7 @@
 
 #    Copyright (C) 2008, 2009 Alexandre Oliva <[email protected]>
 #    Copyright (C) 2008 Jeff Moe
+#    Copyright (C) 2009 Rubén Rodríguez <[email protected]>
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -45,16 +46,24 @@
 # For each kver release, start extra with an empty string, then count
 # from 1 if changes are needed that require rebuilding the tarball.
 kver=2.6.30 extra=
+filelist=$(mktemp)
+rm $filelist
 
-fatal () {
-  echo "$@"
-  exit 1
-}
-
-case $1 in
---force) die () { echo ERROR: "$@": ignored >&2; }; forced=:; shift;;
-*) die () { fatal "$@"; }; forced=false;;
-esac
+if [ 1$1 = "1--force" ]; then
+    echo "WARNING: Using the force, ignored errors will be"
+    die () {
+        echo ERROR: "$@" >&2; 
+    }
+    forced=true
+    shift
+else
+    die () {
+        echo ERROR: "$@" >&2; 
+	echo Use --force to ignore
+	exit 1
+    }
+    forced=false
+fi
 
 check=`echo "$0" | sed 's,[^/]*$,,;s,^$,.,;s,/*$,,'`/deblob-check
 if [ ! -f $check ] ; then
@@ -68,6 +77,28 @@
   have_check=:
 fi
 
+filetest () {
+	if ! [ -f $1 ]
+	then	
+		if [ $( basename $1) = Makefile ] || [ $( basename $1) = Kconfig ]
+		then
+			die File not found: $1
+			return 1
+		fi
+		
+		file=$( basename $1)
+		[ -f $filelist ] || find > $filelist
+		if alternatives=$(egrep  /$file$ $filelist)
+		then
+			die File not found: $1
+			echo WARNING: alternative\(s\) to $1 found: $alternatives
+		else
+			die File not found: $1, no alternatives found
+		fi
+		return 1
+	fi
+}
+
 announce () {
 	echo
 	echo "$@"
@@ -75,34 +106,30 @@
 
 clean_file () {
 	#$1 = filename
-	if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	fi
+	filetest $1 || return
 	rm $1
 	echo $1: removed
 }
 
 check_changed () {
-	if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	elif cmp $1.deblob $1 > /dev/null; then
-		die $1 did not change, something is wrong
+	#$1 = filename
+	if cmp $1.deblob $1 > /dev/null; then
+		rm $1.deblob
+		die $1 did not change, something is wrong && return 1
 	fi
-	mv $1.deblob $1
+		mv $1.deblob $1
+		return 0
 }
 
 clean_blob () {
 	#$1 = filename
+	filetest $1 || return
 	if $have_check; then
-	    if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	    fi
 	    name=$1
 	    set fnord "$@" -d
 	    shift 2
 	    $check "$@" -i linux-$kver $name > $name.deblob
-	    echo $name: removed blobs
-	    check_changed $name
+	    check_changed $name && echo $name: removed blobs
 	else
 	    clean_file $1
 	fi
@@ -111,9 +138,9 @@
 dummy_blob () {
 	#$1 = filename
 	if test -f $1; then
-	    die $1 exists, something is wrong
+	    die $1 exists, something is wrong && return
 	elif test ! -f firmware/Makefile; then
-	    die firmware/Makefile does not exist, something is wrong
+	    die firmware/Makefile does not exist, something is wrong && return
 	fi
 
 	clean_sed "s,`echo $1 | sed s,^firmware/,,`,\$(DEBLOBBED),g" \
@@ -122,10 +149,9 @@
 
 clean_fw () {
 	#$1 = firmware text input, $2 = firmware output
-	if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	elif test -f $2; then
-		die $2 exists, something is wrong
+	filetest $1 || return
+	if test -f $2; then
+		die $2 exists, something is wrong && return
 	fi
 	clean_blob $1 -s 4
 	dummy_blob $2
@@ -133,10 +159,9 @@
 
 drop_fw_file () {
 	#$1 = firmware text input, $2 = firmware output
-	if test ! -f $1; then
-		die $1 does not exist, something is wrong
-	elif test -f $2; then
-		die $2 exists, something is wrong
+	filetest $1 || return
+	if test -f $2; then
+		die $2 exists, something is wrong && return
 	fi
 	clean_file $1
 	dummy_blob $2
@@ -154,11 +179,11 @@
 		fi
 		;;
 	esac
+	filetest $1 || return
 	sed "/^config \\($2\\)\$/{p;i\
 	depends on NONFREE
 d;}" $1 > $1.deblob
-	echo $1: marked config $2 as depending on NONFREE
-	check_changed $1
+	check_changed $1 && echo $1: marked config $2 as depending on NONFREE
 }
 
 clean_mk () {
@@ -167,22 +192,29 @@
 	# sed -i "/\\($1\\)/d" $2
 	# echo $2: removed $1 support
 	# check_changed $2
+	filetest $2 || return
 	if sed -n "/\\($1\\)/p" $2 | grep . > /dev/null; then
 	    :
 	else
 	    die $2 does not contain matches for $1
+	    if alternatives=$(grep Makefile $filelist | xargs grep $1)
+	    then
+		    echo WARNING: alternative matches found at $alternatives
+	    fi
+	
 	fi
 }
 
 clean_sed () {
 	#$1 = sed-script $2 = file $3 = comment
+	filetest $2 || return
 	sed -e "$1" "$2" > "$2".deblob
-	echo $2: ${3-applied sed script $1}
-	check_changed "$2"
+	check_changed $2 && echo $2: ${3-applied sed script $1} 
 }
 
 reject_firmware () {
 	#$1 = file
+	filetest $1 || return
 	clean_sed '
 s,request\(_ihex\)\?_firmware\(_nowait\)\?,reject_firmware\2,g
 ' "$1" 'disabled non-Free firmware-loading machinery'
@@ -190,6 +222,7 @@
 
 maybe_reject_firmware () {
 	#$1 = file
+	filetest $1 || return
 	clean_sed '
 s,request_firmware\(_nowait\)\?,maybe_reject_firmware\1,g
 ' "$1" 'retain Free firmware-loading machinery, disabling non-Free one'
@@ -255,18 +288,17 @@
     sound/pci/cs46xx/imgs/cwcdma.asp \
 ; do
   if test ! $f; then
-    die $f is not present, something is amiss
+    die $f is not present, something is amiss && return
   fi
 done
 
 # Identify the tarball.
-clean_sed "
-s,^EXTRAVERSION.*,&-libre$extra,
+grep -q EXTRAVERSION.*libre.* Makefile || clean_sed "s,^EXTRAVERSION.*,&-libre$extra,
 " Makefile 'added -libre to EXTRAVERSION'
 
 # Add reject_firmware and maybe_reject_firmware
-clean_sed '
-$i\
+grep -q LINUX_LIBRE include/linux/firmware.h || clean_sed '$i\
+#define dev_name(dev) ((dev)->bus_id) /* Undefined in kernels prior to 2.6.25 */
 #ifndef _LINUX_LIBRE_FIRMWARE_H\
 #define _LINUX_LIBRE_FIRMWARE_H\
 \
@@ -1953,4 +1985,5 @@
 clean_blob firmware/README.AddingFirmware
 clean_blob firmware/WHENCE
 
+[ -f $filelist ] && rm $filelist
 exit 0
_______________________________________________
linux-libre mailing list
[email protected]
http://www.fsfla.org/cgi-bin/mailman/listinfo/linux-libre

Reply via email to