Skip to contentSkip to conversation

Assorted Cleanups For prepare-kernel.sh

PATCH Superseded Richard Weinberger 4 participants 28 messages May 25, 2024 – Jun 21, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Assorted Cleanups For prepare-kernel.sh

This series contains the following improvements and cleanups.

- Implement --reverse to undo the effects of the script
- Emit changes that work on any architecture, renders --arch= optional
- Switch from /bin/bash to /bin/sh
- Make shellcheck happy up to warning level, info level is still a lot of work
- Convert the whole script to tabs
- Remove dead and in vain code
- Various fixes

Richard Weinberger (16):
prepare-kernel.sh: Add reverse mode
prepare-kernel.sh: Emit architecture agnostic changes prepare-kernel.sh: Convert to tabs
prepare-kernel.sh: Improve kernel tree check prepare-kernel.sh: Fix shellcheck SC2046 warnings wrt. check_filter prepare-kernel.sh: Disable SC2115 warning around $linux_tree prepare-kernel.sh: Don't use eval
prepare-kernel.sh: Don't depend on bash prepare-kernel.sh: Remove --filterkvers= and --filterarch= prepare-kernel.sh: Remove interactivity prepare-kernel.sh: Remove --forcelink
prepare-kernel.sh: Fix dovetail check
prepare-kernel.sh: Define command line variables prepare-kernel.sh: Remove dead code
prepare-kernel.sh: Don't allow uninitialized variables prepare-kernel.sh: Remove kernel version check

 scripts/Kconfig.frag      |   2 +-
 scripts/prepare-kernel.sh | 585 +++++++++++++++++---------------------
 2 files changed, 267 insertions(+), 320 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH 1/16 prepare-kernel.sh: Add reverse mode

There is currently no way to undo preparing of a kernel, except using --outpatch and reverting the resulting patch later.
But in link mode the kernel tree needs manual cleaning, which can be tedious if a git clean -f -d -x is not possible.

The new --reverse flag offers this feature, it removes all previously created symlinks and directories.
To be able to undo effects by patch_append(), keep a .orig file link as the script already does for symlinks in the linux tree.

---
 scripts/prepare-kernel.sh | 73 +++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 14 deletions(-)
scripts/prepare-kernel.sh +59 -14
index faf3e7235..f0f81471f 100755
@@ -55,7 +55,9 @@ patch_append() {
 	if test -L "$linux_tree/$file" ; then
 	    mv "$linux_tree/$file" "$linux_tree/$file.orig"
 	    cp "$linux_tree/$file.orig" "$linux_tree/$file"
-	fi
+        else
+            cp "$linux_tree/$file" "$linux_tree/$file.orig"
+        fi
 	chmod +w "$linux_tree/$file"
         cat >> "$linux_tree/$file"
     else
@@ -66,6 +68,16 @@ patch_append() {
     fi
 }
 
+patch_reverse() {
+    file="$1"
+    if test "x$output_patch" = "x"; then
+        if test -L "$linux_tree/$file" ; then
+            rm "$linux_tree/$file"
+        fi
+        mv "$linux_tree/$file.orig" "$linux_tree/$file"
+    fi
+}
+
 patch_link() {
     recursive="$1"         # "r" or "n"
     link_file="$2"         # "m", "n" or some file (basename) from $target_dir
@@ -106,11 +118,15 @@ patch_link() {
             f=`echo $f | cut -d/ -f2-`
             d=`dirname $f`
             if test "x$output_patch" = "x"; then
-                mkdir -p $linux_tree/$link_dir/$d
-                if test x$forcelink = x1 -o \
-		   ! $xenomai_root/$target_dir/$f -ef $linux_tree/$link_dir/$f;
-		then
-                    ln -sf $xenomai_root/$target_dir/$f $linux_tree/$link_dir/$f
+                if test x$reverse = x1; then
+                    rm -f $linux_tree/$link_dir/$f
+                else
+                    mkdir -p $linux_tree/$link_dir/$d
+                    if test x$forcelink = x1 -o \
+		       ! $xenomai_root/$target_dir/$f -ef $linux_tree/$link_dir/$f;
+		    then
+                        ln -sf $xenomai_root/$target_dir/$f $linux_tree/$link_dir/$f
+                    fi
                 fi
             else
                 if test `check_filter $link_dir/$f` = "ok"; then
@@ -122,6 +138,11 @@ patch_link() {
                 fi
             fi
         done
+        if test x$reverse = x1; then
+            if ! find $linux_tree/$link_dir -not -type d | grep -q . ; then
+                rm -rf $linux_tree/$link_dir
+            fi
+        fi
     )
 }
 
@@ -138,7 +159,7 @@ generate_patch() {
 }
 
 
-usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>] [--arch=<arch>] [--outpatch=<file> [--filterkvers=y|n] [--filterarch=y|n]] [--forcelink] [--default] [--verbose]'
+usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>] [--arch=<arch>] [--outpatch=<file> [--filterkvers=y|n] [--filterarch=y|n]] [--forcelink] [--default] [--verbose] [--reverse]'
 me=`basename $0`
 
 while test $# -gt 0; do
@@ -174,6 +195,9 @@ while test $# -gt 0; do
     --verbose)
 	verbose=1
 	;;
+    --reverse)
+	reverse=1
+	;;
     --help)
 	echo "$usage"
 	exit 0
@@ -223,8 +247,19 @@ if test \! -r $linux_tree/Makefile; then
    exit 2
 fi
 
+if test x$reverse = x1; then
+    if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$linux_arch/Makefile; then
+        echo "$me: $linux_tree is not prepared with Xenomai" >&2
+	exit 2
+    fi
+fi
+
 # Create an empty output patch file, and initialize the temporary tree.
 if test "x$output_patch" != "x"; then
+    if test x$reverse = x1; then
+	echo "$me: --reverse and --outpatch are not compatible"
+	exit 1
+    fi
 
     temp_tree=`mktemp -d prepare-kernel-XXX --tmpdir`
     if [ $? -ne 0 ]; then
@@ -362,15 +397,18 @@ case $linux_VERSION.$linux_PATCHLEVEL in
 	    -e "s,@SRCARCH@,$linux_arch,g" \
 	    $xenomai_root/scripts/Kconfig.frag |
             patch_append init/Kconfig
+    elif test x$reverse = x1; then
+        patch_reverse init/Kconfig
     fi
 
 test "x$CONFIG_XENO_REVISION_LEVEL" = "x" && CONFIG_XENO_REVISION_LEVEL=0
 
     if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$linux_arch/Makefile; then
-	p="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
-	(echo; echo $p) | patch_append arch/$linux_arch/Makefile
-	p="core-\$(CONFIG_XENOMAI)	+= arch/$linux_arch/xenomai/"
-	echo $p | patch_append arch/$linux_arch/Makefile
+	p1="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
+	p2="core-\$(CONFIG_XENOMAI)	+= arch/$linux_arch/xenomai/"
+	(echo; echo $p1; echo $p2) | patch_append arch/$linux_arch/Makefile
+    elif test x$reverse = x1; then
+        patch_reverse arch/$linux_arch/Makefile
     fi
 
     patch_architecture_specific="n"
@@ -378,11 +416,15 @@ test "x$CONFIG_XENO_REVISION_LEVEL" = "x" && CONFIG_XENO_REVISION_LEVEL=0
     if ! grep -q CONFIG_XENOMAI $linux_tree/drivers/Makefile; then
 	p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
 	( echo ; echo $p ) | patch_append drivers/Makefile
+    elif test x$reverse = x1; then
+        patch_reverse drivers/Makefile
     fi
 
     if ! grep -q CONFIG_XENOMAI $linux_tree/kernel/Makefile; then
 	p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
 	( echo ; echo $p ) | patch_append kernel/Makefile
+    elif test x$reverse = x1; then
+        patch_reverse kernel/Makefile
     fi
     ;;
 
@@ -391,13 +433,15 @@ esac
 # Create local directories then symlink to the source files from
 # there, so that we don't pollute the Xenomai source tree with
 # compilation files.
+#
+# Keep link dirs (4th parameter) descending, otherwise --reverse
+# is not able to cleanup these directories!
 
 patch_kernelversion_specific="n"
 patch_architecture_specific="y"
 patch_link r m kernel/cobalt/arch/$linux_arch arch/$linux_arch/xenomai
 patch_link n n kernel/cobalt/include/dovetail arch/$linux_arch/include/dovetail
 patch_architecture_specific="n"
-patch_link n m kernel/cobalt kernel/xenomai
 patch_link n cobalt-core.h kernel/cobalt/trace include/trace/events
 patch_link n cobalt-rtdm.h kernel/cobalt/trace include/trace/events
 patch_link n cobalt-posix.h kernel/cobalt/trace include/trace/events
@@ -405,14 +449,15 @@ patch_link r n kernel/cobalt/include/asm-generic/xenomai include/asm-generic/xen
 patch_link n m kernel/cobalt/posix kernel/xenomai/posix
 patch_link n m kernel/cobalt/rtdm kernel/xenomai/rtdm
 patch_link n m kernel/cobalt/dovetail kernel/xenomai/pipeline
+patch_link n m kernel/cobalt kernel/xenomai
 patch_link r m kernel/drivers drivers/xenomai
 patch_link n n include/cobalt/kernel include/xenomai/cobalt/kernel
-patch_link r n include/cobalt/kernel/rtdm include/xenomai/rtdm
 patch_link r n include/cobalt/kernel/dovetail/pipeline include/xenomai/pipeline
 patch_link r n include/cobalt/uapi include/xenomai/cobalt/uapi
 patch_link r n include/rtdm/uapi include/xenomai/rtdm/uapi
-patch_link n version.h include/xenomai include/xenomai
+patch_link r n include/cobalt/kernel/rtdm include/xenomai/rtdm
 patch_link n stdarg.h kernel/cobalt/include/linux include/xenomai/linux
+patch_link n version.h include/xenomai include/xenomai
 
 if test "x$output_patch" != "x"; then
     if test x$verbose = x1; then
Signature · 1 line
2.35.3
#2 lore raw

PATCH 2/16 prepare-kernel.sh: Emit architecture agnostic changes

In reply to Richard Weinberger

If --arch= is not passed, emit changes that work on all architectures supported by Xenomai, currently arm, arm64 and x86.
This is especially useful with --outpatch=, the resulting patch can be used for any architecture later and makes maintaining and building a Xenomai enabled kernel easier.

---
 scripts/Kconfig.frag      |  2 +-
 scripts/prepare-kernel.sh | 97 +++++++++++++++++----------------------
 2 files changed, 44 insertions(+), 55 deletions(-)
scripts/Kconfig.frag +1 -1
index b76d25e53..3c9ad2b9f 100644
@@ -16,7 +16,7 @@ menuconfig XENOMAI
 	  Please visit http://xenomai.org for more information.
 
 if XENOMAI
-source "arch/@SRCARCH@/xenomai/Kconfig"
+source "arch/$(SRCARCH)/xenomai/Kconfig"
 endif
 
 if MIGRATION
scripts/prepare-kernel.sh +43 -54

136 lines not on this page · raw message

Signature · 1 line
2.35.3
#3 lore raw

PATCH 3/16 prepare-kernel.sh: Convert to tabs

In reply to Richard Weinberger

Currently the script used a mix of spaces of various lengths and tabs. Let's use tabs everywhere.

---
 scripts/prepare-kernel.sh | 529 +++++++++++++++++++-------------------
 1 file changed, 262 insertions(+), 267 deletions(-)
scripts/prepare-kernel.sh +262 -267
index 826236c34..534531e2b 100755
@@ -29,133 +29,128 @@ patch_architecture_filter="b"
 linux_tree=.
 
 patch_copytempfile() {
-    file="$1"
-    if ! test -f "$temp_tree/$file"; then
-        subdir=`dirname "$file"`
-        mkdir -p "$temp_tree/$subdir"
-        cp "$linux_tree/$file" "$temp_tree/$file"
-    fi
+	file="$1"
+	if ! test -f "$temp_tree/$file"; then
+		subdir=`dirname "$file"`
+		mkdir -p "$temp_tree/$subdir"
+		cp "$linux_tree/$file" "$temp_tree/$file"
+	fi
 }
 
 check_filter() {
-    if test "$patch_kernelversion_specific" != "$patch_kernelversion_filter" \
-        -a "$patch_architecture_specific" != "$patch_architecture_filter"; then
-        echo ok
-    elif test -e "$temp_tree/$1"; then
-        echo "$me: inconsistent multiple changes to $1 in Linux kernel tree" >&2
-	echo error
-    else
-        echo ignore
-    fi
+	if test "$patch_kernelversion_specific" != "$patch_kernelversion_filter" \
+		-a "$patch_architecture_specific" != "$patch_architecture_filter"; then
+		echo ok
+	elif test -e "$temp_tree/$1"; then
+		echo "$me: inconsistent multiple changes to $1 in Linux kernel tree" >&2
+		echo error
+	else
+		echo ignore
+	fi
 }
 
 patch_append() {
-    file="$1"
-    if test "x$output_patch" = "x"; then
-	if test -L "$linux_tree/$file" ; then
-	    mv "$linux_tree/$file" "$linux_tree/$file.orig"
-	    cp "$linux_tree/$file.orig" "$linux_tree/$file"
-        else
-            cp "$linux_tree/$file" "$linux_tree/$file.orig"
-        fi
-	chmod +w "$linux_tree/$file"
-        cat >> "$linux_tree/$file"
-    else
-        if test `check_filter $file` = "ok"; then
-            patch_copytempfile "$file"
-            cat >> "$temp_tree/$file"
-        fi
-    fi
+	file="$1"
+	if test "x$output_patch" = "x"; then
+		if test -L "$linux_tree/$file" ; then
+			mv "$linux_tree/$file" "$linux_tree/$file.orig"
+			cp "$linux_tree/$file.orig" "$linux_tree/$file"
+		else
+			cp "$linux_tree/$file" "$linux_tree/$file.orig"
+		fi
+		chmod +w "$linux_tree/$file"
+		cat >> "$linux_tree/$file"
+	else
+		if test `check_filter $file` = "ok"; then
+			patch_copytempfile "$file"
+			cat >> "$temp_tree/$file"
+		fi
+	fi
 }
 
 patch_reverse() {
-    file="$1"
-    if test "x$output_patch" = "x"; then
-        if test -L "$linux_tree/$file" ; then
-            rm "$linux_tree/$file"
-        fi
-        mv "$linux_tree/$file.orig" "$linux_tree/$file"
-    fi
+	file="$1"
+	if test "x$output_patch" = "x"; then
+		if test -L "$linux_tree/$file" ; then
+			rm "$linux_tree/$file"
+		fi
+		mv "$linux_tree/$file.orig" "$linux_tree/$file"
+	fi
 }
 
 patch_link() {
-    recursive="$1"         # "r" or "n"
-    link_file="$2"         # "m", "n" or some file (basename) from $target_dir
-    target_dir="$3"
-    link_dir="$4"
-
-    (
-        if test \! \( x$link_file = xm -o x$link_file = xn \); then
-	   find_clean_opt="-name $link_file"
-	   find_link_opt=$find_clean_opt
+	recursive="$1"		   # "r" or "n"
+	link_file="$2"		   # "m", "n" or some file (basename) from $target_dir
+	target_dir="$3"
+	link_dir="$4"
+
+	(
+	if test \! \( x$link_file = xm -o x$link_file = xn \); then
+		find_clean_opt="-name $link_file"
+		find_link_opt=$find_clean_opt
 	else
-           link_makefiles_opt=""
-           if test x$link_file = xm; then
-              link_makefiles_opt="-name Makefile -o"
-           fi
-           if test x$recursive = xr; then
-	       recursive_opt="-mindepth 1"
-	       dir_opt="-type d -o"
-           else
-	       recursive_opt="-maxdepth 1"
-	       dir_opt=""
-           fi
-	   find_clean_opt="$recursive_opt \( $dir_opt $link_makefiles_opt -name Kconfig -o -name '*.[chS]' -o -name '*.sh' \)"
-	   find_link_opt="$recursive_opt \( $link_makefiles_opt -name Kconfig -o -name '*.[chS]' -o -name '*.sh' \)"
+		link_makefiles_opt=""
+		if test x$link_file = xm; then
+			link_makefiles_opt="-name Makefile -o"
+		fi
+		if test x$recursive = xr; then
+			recursive_opt="-mindepth 1"
+			dir_opt="-type d -o"
+		else
+			recursive_opt="-maxdepth 1"
+			dir_opt=""
+		fi
+		find_clean_opt="$recursive_opt \( $dir_opt $link_makefiles_opt -name Kconfig -o -name '*.[chS]' -o -name '*.sh' \)"
+		find_link_opt="$recursive_opt \( $link_makefiles_opt -name Kconfig -o -name '*.[chS]' -o -name '*.sh' \)"
+	fi
+
+	if test "x$output_patch" = "x" -a -e $linux_tree/$link_dir; then
+		cd $linux_tree/$link_dir && eval find . $find_clean_opt | while read f; do
+			if test -L $f -a ! -e $xenomai_root/$target_dir/$f; then rm -Rf $f; fi
+		done
 	fi
 
-        if test "x$output_patch" = "x" -a -e $linux_tree/$link_dir; then
-            cd $linux_tree/$link_dir &&
-	    eval find . $find_clean_opt |
-	    while read f; do
-                if test -L $f -a ! -e $xenomai_root/$target_dir/$f; then rm -Rf $f; fi
-            done
-        fi
-
-        cd $xenomai_root/$target_dir &&
-        eval find . $find_link_opt |
-        while read f; do
-            f=`echo $f | cut -d/ -f2-`
-            d=`dirname $f`
-            if test "x$output_patch" = "x"; then
-                if test x$reverse = x1; then
-                    rm -f $linux_tree/$link_dir/$f
-                else
-                    mkdir -p $linux_tree/$link_dir/$d
-                    if test x$forcelink = x1 -o \
-		       ! $xenomai_root/$target_dir/$f -ef $linux_tree/$link_dir/$f;
-		    then
-                        ln -sf $xenomai_root/$target_dir/$f $linux_tree/$link_dir/$f
-                    fi
-                fi
-            else
-                if test `check_filter $link_dir/$f` = "ok"; then
-                    if test -e $linux_tree/$link_dir/$f; then
-                        echo "$me: warning: $link_dir/$f already present in Linux kernel tree, output patch might be defective" >&2
-                    fi
-                    mkdir -p $temp_tree/$link_dir/$d
-                    cp $xenomai_root/$target_dir/$f $temp_tree/$link_dir/$f
-                fi
-            fi
-        done
-        if test x$reverse = x1; then
-            if ! find $linux_tree/$link_dir -not -type d | grep -q . ; then
-                rm -rf $linux_tree/$link_dir
-            fi
-        fi
-    )
+	cd $xenomai_root/$target_dir && eval find . $find_link_opt | while read f; do
+		f=`echo $f | cut -d/ -f2-`
+		d=`dirname $f`
+		if test "x$output_patch" = "x"; then
+			if test x$reverse = x1; then
+				rm -f $linux_tree/$link_dir/$f
+			else
+				mkdir -p $linux_tree/$link_dir/$d
+				if test x$forcelink = x1 -o ! $xenomai_root/$target_dir/$f -ef $linux_tree/$link_dir/$f; then
+					ln -sf $xenomai_root/$target_dir/$f $linux_tree/$link_dir/$f
+				fi
+			fi
+		else
+			if test `check_filter $link_dir/$f` = "ok"; then
+                    		if test -e $linux_tree/$link_dir/$f; then
+                        		echo "$me: warning: $link_dir/$f already present in Linux kernel tree, output patch might be defective" >&2
+                    		fi
+				mkdir -p $temp_tree/$link_dir/$d
+				cp $xenomai_root/$target_dir/$f $temp_tree/$link_dir/$f
+			fi
+		fi
+	done
+
+	if test x$reverse = x1; then
+		if ! find $linux_tree/$link_dir -not -type d | grep -q . ; then
+			rm -rf $linux_tree/$link_dir
+		fi
+	fi
+	)
 }
 
 generate_patch() {
-    (
-    cd "$temp_tree"
-    find . -type f |
-    while read f; do
-        diff -Naurd "$linux_tree/$f" "$f" |
-        sed -e "s,^--- ${linux_tree}/\.\(/.*\)$,--- linux\1," \
-            -e "s,^+++ \.\(/.*\)$,+++ linux-patched\1,"
-    done
-    )
+	(
+	cd "$temp_tree"
+	find . -type f |
+	while read f; do
+		diff -Naurd "$linux_tree/$f" "$f" |
+		sed -e "s,^--- ${linux_tree}/\.\(/.*\)$,--- linux\1," \
+			-e "s,^+++ \.\(/.*\)$,+++ linux-patched\1,"
+	done
+	)
 }
 
 
@@ -163,52 +158,52 @@ usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>]
 me=`basename $0`
 
 while test $# -gt 0; do
-    case "$1" in
-    --linux=*)
-	linux_tree=`echo $1|sed -e 's,^--linux=\\(.*\\)$,\\1,g'`
-	linux_tree=`eval "echo $linux_tree"`
+	case "$1" in
+	--linux=*)
+		linux_tree=`echo $1|sed -e 's,^--linux=\\(.*\\)$,\\1,g'`
+		linux_tree=`eval "echo $linux_tree"`
 	;;
-    --dovetail=*)
-	pipeline_patch=`echo $1|sed -e 's,^--dovetail=\\(.*\\)$,\\1,g'`
-	pipeline_patch=`eval "echo $pipeline_patch"`
-	probe_header=include/linux/dovetail.h
-	arch_probe_header=include/asm/dovetail.h
+	--dovetail=*)
+		pipeline_patch=`echo $1|sed -e 's,^--dovetail=\\(.*\\)$,\\1,g'`
+		pipeline_patch=`eval "echo $pipeline_patch"`
+		probe_header=include/linux/dovetail.h
+		arch_probe_header=include/asm/dovetail.h
 	;;
-    --arch=*)
-	linux_arch=`echo $1|sed -e 's,^--arch=\\(.*\\)$,\\1,g'`
+	--arch=*)
+		linux_arch=`echo $1|sed -e 's,^--arch=\\(.*\\)$,\\1,g'`
 	;;
-    --outpatch=*)
-	output_patch=`echo $1|sed -e 's,^--outpatch=\\(.*\\)$,\\1,g'`
+	--outpatch=*)
+		output_patch=`echo $1|sed -e 's,^--outpatch=\\(.*\\)$,\\1,g'`
 	;;
-    --filterkvers=*)
-        patch_kernelversion_filter=`echo $1|sed -e 's,^--filterkvers=\\(.*\\)$,\\1,g'`
-        ;;
-    --filterarch=*)
-        patch_architecture_filter=`echo $1|sed -e 's,^--filterarch=\\(.*\\)$,\\1,g'`
-        ;;
-    --forcelink)
-        forcelink=1
-        ;;
-    --default)
-        usedefault=1
-        ;;
-    --verbose)
-	verbose=1
+	--filterkvers=*)
+		patch_kernelversion_filter=`echo $1|sed -e 's,^--filterkvers=\\(.*\\)$,\\1,g'`
+		;;
+	--filterarch=*)
+		patch_architecture_filter=`echo $1|sed -e 's,^--filterarch=\\(.*\\)$,\\1,g'`
+		;;
+	--forcelink)
+		forcelink=1
+		;;
+	--default)
+		usedefault=1
+		;;
+	--verbose)
+		verbose=1
 	;;
-    --reverse)
-	reverse=1
+	--reverse)
+		reverse=1
 	;;
-    --help)
-	echo "$usage"
-	exit 0
+	--help)
+		echo "$usage"
+		exit 0
 	;;
-    *)
-	echo "$me: unknown flag: $1" >&2
-	echo "$usage" >&2
-	exit 1
+	*)
+		echo "$me: unknown flag: $1" >&2
+		echo "$usage" >&2
+		exit 1
 	;;
-    esac
-    shift
+	esac
+	shift
 done
 
 # Infere the location of the Xenomai source tree from
@@ -223,47 +218,47 @@ xenomai_root=`cd $xenomai_root && pwd`
 default_linux_tree=/lib/modules/`uname -r`/source
 
 while test x$linux_tree = x; do
-   if test x$usedefault = x; then
-      echo -n "Linux tree [default $default_linux_tree]: "
-      read linux_tree
-   fi
-   if test x$linux_tree = x; then
-      linux_tree=$default_linux_tree
-   fi
-   if test \! -x "$linux_tree"; then
-      echo "$me: cannot access Linux tree in $linux_tree"
-      linux_tree=
-      usedefault=
-      default_linux_tree=/usr/src
-   else
-      break
-   fi
+	if test x$usedefault = x; then
+		echo -n "Linux tree [default $default_linux_tree]: "
+		read linux_tree
+	fi
+	if test x$linux_tree = x; then
+		linux_tree=$default_linux_tree
+	fi
+	if test \! -x "$linux_tree"; then
+		echo "$me: cannot access Linux tree in $linux_tree"
+		linux_tree=
+		usedefault=
+		default_linux_tree=/usr/src
+	else
+		break
+	fi
 done
 
 linux_tree=`cd $linux_tree && pwd`
 
 if test \! -r $linux_tree/Makefile; then
-   echo "$me: $linux_tree is not a valid Linux kernel tree" >&2
-   exit 2
+	echo "$me: $linux_tree is not a valid Linux kernel tree" >&2
+	exit 2
 fi
 
 # Create an empty output patch file, and initialize the temporary tree.
 if test "x$output_patch" != "x"; then
-    if test x$reverse = x1; then
-	echo "$me: --reverse and --outpatch are not compatible"
-	exit 1
-    fi
-
-    temp_tree=`mktemp -d prepare-kernel-XXX --tmpdir`
-    if [ $? -ne 0 ]; then
-	echo Temporary directory could not be created.
-	exit 1
-    fi
-
-    patchdir=`dirname $output_patch`
-    patchdir=`cd $patchdir && pwd`
-    output_patch=$patchdir/`basename $output_patch`
-    echo > "$output_patch"
+	if test x$reverse = x1; then
+		echo "$me: --reverse and --outpatch are not compatible"
+		exit 1
+	fi
+
+	temp_tree=`mktemp -d prepare-kernel-XXX --tmpdir`
+	if [ $? -ne 0 ]; then
+		echo Temporary directory could not be created.
+		exit 1
+	fi
+
+	patchdir=`dirname $output_patch`
+	patchdir=`cd $patchdir && pwd`
+	output_patch=$patchdir/`basename $output_patch`
+	echo > "$output_patch"
 
 fi
 
@@ -296,9 +291,9 @@ for a in $target_linux_archs; do
 	fi
 done
 
-foo=`grep '^KERNELSRC    := ' $linux_tree/Makefile | cut -d= -f2`
+foo=`grep '^KERNELSRC	 := ' $linux_tree/Makefile | cut -d= -f2`
 if [ ! -z $foo ] ; then
-    linux_tree=$foo
+	linux_tree=$foo
 fi
 unset foo
 
@@ -310,110 +305,110 @@ eval linux_`grep '^VERSION =' $linux_tree/Makefile | sed -e 's, ,,g'`
 linux_version="$linux_VERSION.$linux_PATCHLEVEL.$linux_SUBLEVEL"
 
 if test x$verbose = x1; then
-echo "Preparing kernel $linux_version$linux_EXTRAVERSION in $linux_tree..."
+	echo "Preparing kernel $linux_version$linux_EXTRAVERSION in $linux_tree..."
 fi
 
 if test -r $linux_tree/$probe_header; then
-    if test x$verbose = x1; then
-       echo "IRQ pipeline found - bypassing patch."
-    fi
+	if test x$verbose = x1; then
+	   echo "IRQ pipeline found - bypassing patch."
+	fi
 else
-   if test x$verbose = x1; then
-      echo "$me: no IRQ pipeline support found." >&2
-   fi
-   while test x$pipeline_patch = x; do
-      echo -n "IRQ pipeline patch: "
-      read pipeline_patch
-      if test \! -r "$pipeline_patch" -o x$pipeline_patch = x; then
-         echo "$me: cannot read IRQ pipeline support from $pipeline_patch" >&2
-         pipeline_patch=
-      fi
-   done
-   patchdir=`dirname $pipeline_patch`;
-   patchdir=`cd $patchdir && pwd`
-   pipeline_patch=$patchdir/`basename $pipeline_patch`
-   curdir=$PWD
-   cd $linux_tree && patch --dry-run -p1 -f < $pipeline_patch || {
-        cd $curdir;
-        echo "$me: Unable to patch kernel $linux_version$linux_EXTRAVERSION with `basename $pipeline_patch`." >&2
-        exit 2;
-   }
-   patch -p1 -f -s < $pipeline_patch
-   cd $curdir
+	if test x$verbose = x1; then
+		echo "$me: no IRQ pipeline support found." >&2
+	fi
+	while test x$pipeline_patch = x; do
+		echo -n "IRQ pipeline patch: "
+		read pipeline_patch
+		if test \! -r "$pipeline_patch" -o x$pipeline_patch = x; then
+			echo "$me: cannot read IRQ pipeline support from $pipeline_patch" >&2
+			pipeline_patch=
+		fi
+	done
+	patchdir=`dirname $pipeline_patch`;
+	patchdir=`cd $patchdir && pwd`
+	pipeline_patch=$patchdir/`basename $pipeline_patch`
+	curdir=$PWD
+	cd $linux_tree && patch --dry-run -p1 -f < $pipeline_patch || {
+		cd $curdir;
+		echo "$me: Unable to patch kernel $linux_version$linux_EXTRAVERSION with `basename $pipeline_patch`." >&2
+		exit 2;
+	}
+	patch -p1 -f -s < $pipeline_patch
+	cd $curdir
 fi
 
 for a in $target_linux_archs; do
-   if test \! -r $linux_tree/arch/$a/$arch_probe_header; then
-      echo "$me: $linux_tree has no IRQ pipeline support for $a" >&2
-      exit 2
-   fi
+	if test \! -r $linux_tree/arch/$a/$arch_probe_header; then
+		echo "$me: $linux_tree has no IRQ pipeline support for $a" >&2
+		exit 2
+	fi
 done
 
 if test x$verbose = x1; then
-   echo "IRQ pipeline installed."
+	echo "IRQ pipeline installed."
 fi
 
 patch_kernelversion_specific="y"
 
 case $linux_VERSION.$linux_PATCHLEVEL in
 
-    2.*)
+	2.*)
 
-    echo "$me: Unsupported kernel version $linux_VERSION.$linux_PATCHLEVEL.x" >&2
-    exit 2
-    ;;
+	echo "$me: Unsupported kernel version $linux_VERSION.$linux_PATCHLEVEL.x" >&2
+	exit 2
+	;;
 
-    *)
+	*)
 
-    patch_architecture_specific="y"
+	patch_architecture_specific="y"
 
-    if ! grep -q XENOMAI $linux_tree/init/Kconfig; then
-	version_stamp=`cat $xenomai_root/config/version-code`
-	version_major=`expr $version_stamp : '\([[0-9]]*\)' || true`
-	version_minor=`expr $version_stamp : '[[0-9]]*\.\([[0-9]*]*\)' || true`
-	revision_level=`expr $version_stamp : '[[0-9]]*\.[[0-9]*]*\.\([[0-9]*]*\)' || true`
+	if ! grep -q XENOMAI $linux_tree/init/Kconfig; then
+		version_stamp=`cat $xenomai_root/config/version-code`
+		version_major=`expr $version_stamp : '\([[0-9]]*\)' || true`
+		version_minor=`expr $version_stamp : '[[0-9]]*\.\([[0-9]*]*\)' || true`
+		revision_level=`expr $version_stamp : '[[0-9]]*\.[[0-9]*]*\.\([[0-9]*]*\)' || true`
 	if [ -z "$revision_level" ]; then
-	    revision_level=0
+		revision_level=0
 	fi
 	version_string=`cat $xenomai_root/config/version-label`
 	sed -e "s,@VERSION_MAJOR@,$version_major,g" \
-	    -e "s,@VERSION_MINOR@,$version_minor,g" \
-	    -e "s,@REVISION_LEVEL@,$revision_level,g" \
-	    -e "s,@VERSION_STRING@,$version_string,g" \
-	    $xenomai_root/scripts/Kconfig.frag |
-            patch_append init/Kconfig
-    elif test x$reverse = x1; then
-        patch_reverse init/Kconfig
-    fi
+		-e "s,@VERSION_MINOR@,$version_minor,g" \
+		-e "s,@REVISION_LEVEL@,$revision_level,g" \
+		-e "s,@VERSION_STRING@,$version_string,g" \
+		$xenomai_root/scripts/Kconfig.frag |
+			patch_append init/Kconfig
+	elif test x$reverse = x1; then
+		patch_reverse init/Kconfig
+	fi
 
 test "x$CONFIG_XENO_REVISION_LEVEL" = "x" && CONFIG_XENO_REVISION_LEVEL=0
 
-    for a in $target_linux_archs; do
-        if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$a/Makefile; then
-            p1="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
-            p2="core-\$(CONFIG_XENOMAI)	+= arch/$a/xenomai/"
-            (echo; echo $p1; echo $p2) | patch_append arch/$a/Makefile
-        elif test x$reverse = x1; then
-            patch_reverse arch/$a/Makefile
-       fi
-    done
-
-    patch_architecture_specific="n"
-
-    if ! grep -q CONFIG_XENOMAI $linux_tree/drivers/Makefile; then
-	p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
-	( echo ; echo $p ) | patch_append drivers/Makefile
-    elif test x$reverse = x1; then
-        patch_reverse drivers/Makefile
-    fi
-
-    if ! grep -q CONFIG_XENOMAI $linux_tree/kernel/Makefile; then
-	p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
-	( echo ; echo $p ) | patch_append kernel/Makefile
-    elif test x$reverse = x1; then
-        patch_reverse kernel/Makefile
-    fi
-    ;;
+	for a in $target_linux_archs; do
+		if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$a/Makefile; then
+			p1="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
+			p2="core-\$(CONFIG_XENOMAI)	+= arch/$a/xenomai/"
+			(echo; echo $p1; echo $p2) | patch_append arch/$a/Makefile
+		elif test x$reverse = x1; then
+			patch_reverse arch/$a/Makefile
+		fi
+	done
+
+	patch_architecture_specific="n"
+
+	if ! grep -q CONFIG_XENOMAI $linux_tree/drivers/Makefile; then
+		p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
+		( echo ; echo $p ) | patch_append drivers/Makefile
+	elif test x$reverse = x1; then
+		patch_reverse drivers/Makefile
+	fi
+
+	if ! grep -q CONFIG_XENOMAI $linux_tree/kernel/Makefile; then
+		p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
+		( echo ; echo $p ) | patch_append kernel/Makefile
+	elif test x$reverse = x1; then
+		patch_reverse kernel/Makefile
+	fi
+	;;
 
 esac
 
@@ -427,8 +422,8 @@ esac
 patch_kernelversion_specific="n"
 patch_architecture_specific="y"
 for a in $target_linux_archs; do
-    patch_link r m kernel/cobalt/arch/$a arch/$a/xenomai
-    patch_link n n kernel/cobalt/include/dovetail arch/$a/include/dovetail
+	patch_link r m kernel/cobalt/arch/$a arch/$a/xenomai
+	patch_link n n kernel/cobalt/include/dovetail arch/$a/include/dovetail
 done
 patch_architecture_specific="n"
 patch_link n cobalt-core.h kernel/cobalt/trace include/trace/events
@@ -449,16 +444,16 @@ patch_link n stdarg.h kernel/cobalt/include/linux include/xenomai/linux
 patch_link n version.h include/xenomai include/xenomai
 
 if test "x$output_patch" != "x"; then
-    if test x$verbose = x1; then
-    echo 'Generating patch.'
-    fi
-    generate_patch > "$output_patch"
-    rm -rf $temp_tree
+	if test x$verbose = x1; then
+		echo 'Generating patch.'
+	fi
+	generate_patch > "$output_patch"
+	rm -rf $temp_tree
 fi
 
 if test x$verbose = x1; then
-echo 'Links installed.'
-echo 'Build system ready.'
+	echo 'Links installed.'
+	echo 'Build system ready.'
 fi
 
 exit 0
Signature · 1 line
2.35.3
#4 lore raw

Re: [PATCH 03/16] prepare-kernel.sh: Convert to tabs

Hi Richard!

Quoted 7 lines · Richard Weinberger

patch_reverse() {

scripts/prepare-kernel.sh +0 -5
-    file="$1"
-    if test "x$output_patch" = "x"; then
-        if test -L "$linux_tree/$file" ; then
-            rm "$linux_tree/$file"
-        fi

scripts/prepare-kernel.sh patch_architecture_filter="b" · line 79

Quoted 10 lines
scripts/prepare-kernel.sh +7 -2
-        mv "$linux_tree/$file.orig" "$linux_tree/$file"
-    fi
+	file="$1"
+	if test "x$output_patch" = "x"; then
+		if test -L "$linux_tree/$file" ; then
+			rm "$linux_tree/$file"
+		fi
+		mv "$linux_tree/$file.orig" "$linux_tree/$file"
+	fi
 }

This part is introduced in patch 1 and completely rewritten in this patch (patch 3).

We could avoid that by applying patch 3 fist, so basically reordering the patches so that patch 3 becomes the first one. Could help if someone has to bisect later...

Best regards,
Florian

#5 lore raw

Re: [PATCH 03/16] prepare-kernel.sh: Convert to tabs

Quoted 24 lines · Florian Bezdeka

Hi Richard!

Quoted 7 lines · Richard Weinberger

patch_reverse() {

scripts/prepare-kernel.sh +0 -5
-    file="$1"
-    if test "x$output_patch" = "x"; then
-        if test -L "$linux_tree/$file" ; then
-            rm "$linux_tree/$file"
-        fi

scripts/prepare-kernel.sh patch_architecture_filter="b" · line 79

Quoted 10 lines
scripts/prepare-kernel.sh +7 -2
-        mv "$linux_tree/$file.orig" "$linux_tree/$file"
-    fi
+	file="$1"
+	if test "x$output_patch" = "x"; then
+		if test -L "$linux_tree/$file" ; then
+			rm "$linux_tree/$file"
+		fi
+		mv "$linux_tree/$file.orig" "$linux_tree/$file"
+	fi
 }

This part is introduced in patch 1 and completely rewritten in this patch (patch 3).

Quoted 4 lines

We could avoid that by applying patch 3 fist, so basically reordering the patches so that patch 3 becomes the first one. Could help if someone has to bisect later...

Yep, that would indeed be nicer.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#6 lore raw

Re: [PATCH 03/16] prepare-kernel.sh: Convert to tabs

In reply to Florian Bezdeka

Florian,

Am Montag, 27. Mai 2024, 09:19:44 CEST schrieb 'Florian Bezdeka' via upstream:

Quoted 24 lines

Hi Richard!

Quoted 7 lines · Richard Weinberger

patch_reverse() {

scripts/prepare-kernel.sh +0 -5
-    file="$1"
-    if test "x$output_patch" = "x"; then
-        if test -L "$linux_tree/$file" ; then
-            rm "$linux_tree/$file"
-        fi

scripts/prepare-kernel.sh patch_architecture_filter="b" · line 79

Quoted 10 lines
scripts/prepare-kernel.sh +7 -2
-        mv "$linux_tree/$file.orig" "$linux_tree/$file"
-    fi
+	file="$1"
+	if test "x$output_patch" = "x"; then
+		if test -L "$linux_tree/$file" ; then
+			rm "$linux_tree/$file"
+		fi
+		mv "$linux_tree/$file.orig" "$linux_tree/$file"
+	fi
 }

This part is introduced in patch 1 and completely rewritten in this patch (patch 3).

Quoted 3 lines

We could avoid that by applying patch 3 fist, so basically reordering the patches so that patch 3 becomes the first one. Could help if someone has to bisect later...

How does it hurt bisecing beside of adding an extra step? But sure, I can reorder.
So, I assume you're fine with tabs? :-)

Thanks,
//richard

Signature · 2 lines
​​​​​sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT
UID/VAT Nr: ATU 66964118 | FN: 374287y
#7 lore raw

PATCH 4/16 prepare-kernel.sh: Improve kernel tree check

In reply to Richard Weinberger

Currently any directory that contains a Makefile is treated as kernel tree. This causes strange errors when calling the script without parameters within the Xenomai tree.

$ ./scripts/prepare-kernel.sh
./scripts/prepare-kernel.sh: line 298: linux_: command not found

Fix it by checking for a more specific file in the kernel tree.

---
 scripts/prepare-kernel.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/prepare-kernel.sh +1 -1
index 534531e2b..800528058 100755
@@ -237,7 +237,7 @@ done
 
 linux_tree=`cd $linux_tree && pwd`
 
-if test \! -r $linux_tree/Makefile; then
+if test \! -r $linux_tree/kernel/kallsyms.c; then
 	echo "$me: $linux_tree is not a valid Linux kernel tree" >&2
 	exit 2
 fi
Signature · 1 line
2.35.3
#8 lore raw

Re: [PATCH 04/16] prepare-kernel.sh: Improve kernel tree check

Quoted 19 lines · Richard Weinberger

Currently any directory that contains a Makefile is treated as kernel tree. This causes strange errors when calling the script without parameters within the Xenomai tree.

$ ./scripts/prepare-kernel.sh
./scripts/prepare-kernel.sh: line 298: linux_: command not found

Fix it by checking for a more specific file in the kernel tree.

---
 scripts/prepare-kernel.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/prepare-kernel.sh +0 -0
index 534531e2b..800528058 100755

scripts/prepare-kernel.sh done · line 240

Quoted 5 lines
scripts/prepare-kernel.sh +1 -1
@@ -237,7 +237,7 @@ done
 
 linux_tree=`cd $linux_tree && pwd`
 
-if test \! -r $linux_tree/Makefile; then
+if test \! -r $linux_tree/kernel/kallsyms.c; then

Fine with checking for a real kernel, but this here is not my favorite method. How about

test "$(head -1 README)" = "Linux kernel"

instead?

scripts/prepare-kernel.sh done · line 243

Quoted 3 lines
scripts/prepare-kernel.sh +0 -0
 	echo "$me: $linux_tree is not a valid Linux kernel tree" >&2
 	exit 2
 fi

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#9 lore raw

Re: [PATCH 04/16] prepare-kernel.sh: Improve kernel tree check

----- Ursprüngliche Mail -----

Quoted 14 lines

scripts/prepare-kernel.sh done · line 240

Quoted 10 lines
scripts/prepare-kernel.sh +1 -1
index 534531e2b..800528058 100755
@@ -237,7 +237,7 @@ done
 
 linux_tree=`cd $linux_tree && pwd`
 
-if test \! -r $linux_tree/Makefile; then
+if test \! -r $linux_tree/kernel/kallsyms.c; then

Fine with checking for a real kernel, but this here is not my favorite method. How about

Quoted 3 lines

test "$(head -1 README)" = "Linux kernel"

instead?

My idea was that kernel/kallsyms.c is an old file which is unlikely to get renamed soon.

It came via:
commit e42f617ecdfc68e68b0108cd337d30224b541352

Author: Ingo Molnar <[email protected]>
Date:   Thu Sep 26 03:31:07 2002 -0700

[PATCH] kksymoops-2.5.38-C9

Make the kernel print out symbolic bactraces if symbol table information is available (CONFIG_KALLSYMS)

and was never renamed since.

README, one other hand, saw more changes. In it's current form it looks more stable, though.

So, I don't have a strong opinion on this.

Thanks,
//richard

#10 lore raw

PATCH 5/16 prepare-kernel.sh: Fix shellcheck SC2046 warnings wrt. check_filter

In reply to Richard Weinberger

Fixes:
In scripts/prepare-kernel.sh line 64:
if test check_filter $file = "ok"; then
^------------------^ SC2046 (warning): Quote this to prevent word splitting.

In scripts/prepare-kernel.sh line 126:
if test check_filter $link_dir/$f = "ok"; then
^-------------------------^ SC2046 (warning): Quote this to prevent word splitting.

---
 scripts/prepare-kernel.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/prepare-kernel.sh +2 -2
index 800528058..d8d63397d 100755
@@ -61,7 +61,7 @@ patch_append() {
 		chmod +w "$linux_tree/$file"
 		cat >> "$linux_tree/$file"
 	else
-		if test `check_filter $file` = "ok"; then
+		if test "`check_filter $file`" = "ok"; then
 			patch_copytempfile "$file"
 			cat >> "$temp_tree/$file"
 		fi
@@ -123,7 +123,7 @@ patch_link() {
 				fi
 			fi
 		else
-			if test `check_filter $link_dir/$f` = "ok"; then
+			if test "`check_filter $link_dir/$f`" = "ok"; then
                     		if test -e $linux_tree/$link_dir/$f; then
                         		echo "$me: warning: $link_dir/$f already present in Linux kernel tree, output patch might be defective" >&2
                     		fi
Signature · 1 line
2.35.3
#11 lore raw

Re: [PATCH 05/16] prepare-kernel.sh: Fix shellcheck SC2046 warnings wrt. check_filter

Quoted 28 lines · Richard Weinberger

Fixes:
In scripts/prepare-kernel.sh line 64:
if test check_filter $file = "ok"; then
^------------------^ SC2046 (warning): Quote this to prevent word splitting.

In scripts/prepare-kernel.sh line 126:
if test check_filter $link_dir/$f = "ok"; then
^-------------------------^ SC2046 (warning): Quote this to prevent word splitting.

---
 scripts/prepare-kernel.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/prepare-kernel.sh +1 -1
index 800528058..d8d63397d 100755
@@ -61,7 +61,7 @@ patch_append() {
 		chmod +w "$linux_tree/$file"
 		cat >> "$linux_tree/$file"
 	else
-		if test `check_filter $file` = "ok"; then
+		if test "`check_filter $file`" = "ok"; then
 			patch_copytempfile "$file"
 			cat >> "$temp_tree/$file"
 		fi

scripts/prepare-kernel.sh patch_link() { · line 129

Quoted 8 lines
scripts/prepare-kernel.sh +1 -1
@@ -123,7 +123,7 @@ patch_link() {
 				fi
 			fi
 		else
-			if test `check_filter $link_dir/$f` = "ok"; then
+			if test "`check_filter $link_dir/$f`" = "ok"; then
                     		if test -e $linux_tree/$link_dir/$f; then
                         		echo "$me: warning: $link_dir/$f already present in Linux kernel tree, output patch might be defective" >&2
                     		fi

command is legacy. Can we switch to $(command) at this chance? Applies to succeeding patches as well.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#12 lore raw

PATCH 6/16 prepare-kernel.sh: Disable SC2115 warning around $linux_tree

In reply to Richard Weinberger

The script makes sure that $linux_tree is valid, it cannot be empty.

---
 scripts/prepare-kernel.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/prepare-kernel.sh +2 -1
index d8d63397d..e78c48e61 100755
@@ -135,7 +135,8 @@ patch_link() {
 
 	if test x$reverse = x1; then
 		if ! find $linux_tree/$link_dir -not -type d | grep -q . ; then
-			rm -rf $linux_tree/$link_dir
+			# shellcheck disable=SC2115
+			rm -rf ${linux_tree}/$link_dir
 		fi
 	fi
 	)
Signature · 1 line
2.35.3
#13 lore raw

PATCH 7/16 prepare-kernel.sh: Don't use eval

In reply to Richard Weinberger

eval is evil and confuses shellcheck.

Fixes:
In scripts/prepare-kernel.sh line 302:
linux_version="$linux_VERSION.$linux_PATCHLEVEL.$linux_SUBLEVEL"

               ^------------^ SC2154 (warning): linux_VERSION is referenced but not assigned (did you mean 'linux_version'?).
                              ^---------------^ SC2154 (warning): linux_PATCHLEVEL is referenced but not assigned.
                                                ^-------------^ SC2154 (warning): linux_SUBLEVEL is referenced but not assigned.

In scripts/prepare-kernel.sh line 305:
echo "Preparing kernel $linux_version$linux_EXTRAVERSION in $linux_tree..."
^-----------------^ SC2154 (warning): linux_EXTRAVERSION is referenced but not assigned.

Instead of using eval plus grep and sed, just use good old awk. Tested also with busybox awk.

---
 scripts/prepare-kernel.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
scripts/prepare-kernel.sh +4 -4
index e78c48e61..3c13d471f 100755
@@ -298,10 +298,10 @@ if [ ! -z $foo ] ; then
 fi
 unset foo
 
-eval linux_`grep '^EXTRAVERSION =' $linux_tree/Makefile | sed -e 's, ,,g'`
-eval linux_`grep '^PATCHLEVEL =' $linux_tree/Makefile | sed -e 's, ,,g'`
-eval linux_`grep '^SUBLEVEL =' $linux_tree/Makefile | sed -e 's, ,,g'`
-eval linux_`grep '^VERSION =' $linux_tree/Makefile | sed -e 's, ,,g'`
+linux_EXTRAVERSION=`awk -F= '/^EXTRAVERSION =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
+linux_PATCHLEVEL=`awk -F= '/^PATCHLEVEL =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
+linux_SUBLEVEL=`awk -F= '/^SUBLEVEL =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
+linux_VERSION=`awk -F= '/^VERSION =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
 
 linux_version="$linux_VERSION.$linux_PATCHLEVEL.$linux_SUBLEVEL"
 
Signature · 1 line
2.35.3
#14 lore raw

PATCH 8/16 prepare-kernel.sh: Don't depend on bash

In reply to Richard Weinberger

- type -p is not POSIX, so use realpath(1), I think it is safe to assume this tool.

- echo -n is also not POSIX, but if some echo command does not support omitting the trailing newline, so what...

---
 scripts/prepare-kernel.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/prepare-kernel.sh +4 -2
index 3c13d471f..f7aca804f 100755
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/bin/sh
 set -e
 
 unset CDPATH
@@ -210,7 +210,7 @@ done
 # Infere the location of the Xenomai source tree from
 # the path of the current script.
 
-script_path=`type -p $0`
+script_path=`realpath $0`
 xenomai_root=`dirname $script_path`/..
 xenomai_root=`cd $xenomai_root && pwd`
 
@@ -220,6 +220,7 @@ default_linux_tree=/lib/modules/`uname -r`/source
 
 while test x$linux_tree = x; do
 	if test x$usedefault = x; then
+		# shellcheck disable=SC3037
 		echo -n "Linux tree [default $default_linux_tree]: "
 		read linux_tree
 	fi
@@ -318,6 +319,7 @@ else
 		echo "$me: no IRQ pipeline support found." >&2
 	fi
 	while test x$pipeline_patch = x; do
+		# shellcheck disable=SC3037
 		echo -n "IRQ pipeline patch: "
 		read pipeline_patch
 		if test \! -r "$pipeline_patch" -o x$pipeline_patch = x; then
Signature · 1 line
2.35.3
#15 lore raw

Re: [PATCH 08/16] prepare-kernel.sh: Don't depend on bash

Quoted 31 lines · Richard Weinberger

- type -p is not POSIX, so use realpath(1), I think it is safe to assume this tool.

- echo -n is also not POSIX, but if some echo command does not support omitting the trailing newline, so what...

---
 scripts/prepare-kernel.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/prepare-kernel.sh +2 -2
index 3c13d471f..f7aca804f 100755
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/bin/sh
 set -e
 
 unset CDPATH
@@ -210,7 +210,7 @@ done
 # Infere the location of the Xenomai source tree from
 # the path of the current script.
 
-script_path=`type -p $0`
+script_path=`realpath $0`
 xenomai_root=`dirname $script_path`/..
 xenomai_root=`cd $xenomai_root && pwd`
 

scripts/prepare-kernel.sh default_linux_tree=/lib/modules/`uname -r`/source · line 224

Quoted 5 lines
scripts/prepare-kernel.sh +1 -0
@@ -220,6 +220,7 @@ default_linux_tree=/lib/modules/`uname -r`/source
 
 while test x$linux_tree = x; do
 	if test x$usedefault = x; then
+		# shellcheck disable=SC3037
 		echo -n "Linux tree [default $default_linux_tree]: "

Better use printf instead.

scripts/prepare-kernel.sh else · line 325

Quoted 10 lines
scripts/prepare-kernel.sh +1 -0
 		read linux_tree
 	fi
@@ -318,6 +319,7 @@ else
 		echo "$me: no IRQ pipeline support found." >&2
 	fi
 	while test x$pipeline_patch = x; do
+		# shellcheck disable=SC3037
 		echo -n "IRQ pipeline patch: "
 		read pipeline_patch
 		if test \! -r "$pipeline_patch" -o x$pipeline_patch = x; then

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#16 lore raw

Re: [PATCH 08/16] prepare-kernel.sh: Don't depend on bash

----- Ursprüngliche Mail -----

Quoted 20 lines

Von: "Jan Kiszka" <[email protected]>

Quoted 19 lines
scripts/prepare-kernel.sh +2 -2
index 3c13d471f..f7aca804f 100755
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/bin/sh
 set -e
 
 unset CDPATH
@@ -210,7 +210,7 @@ done
 # Infere the location of the Xenomai source tree from
 # the path of the current script.
 
-script_path=`type -p $0`
+script_path=`realpath $0`
 xenomai_root=`dirname $script_path`/..
 xenomai_root=`cd $xenomai_root && pwd`
 
Quoted 8 lines

scripts/prepare-kernel.sh default_linux_tree=/lib/modules/`uname -r`/source · line 224

Quoted 6 lines
scripts/prepare-kernel.sh +1 -0
@@ -220,6 +220,7 @@ default_linux_tree=/lib/modules/`uname -r`/source
 
 while test x$linux_tree = x; do
 	if test x$usedefault = x; then
+		# shellcheck disable=SC3037
 		echo -n "Linux tree [default $default_linux_tree]: "

Better use printf instead.

Good point.
If you agree with "[PATCH 10/16] prepare-kernel.sh: Remove interactivity", we can drop this anyway.

Thanks,
//richard

#17 lore raw

Re: [PATCH 08/16] prepare-kernel.sh: Don't depend on bash

Quoted 30 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 20 lines

Von: "Jan Kiszka" <[email protected]>

Quoted 19 lines
scripts/prepare-kernel.sh +2 -2
index 3c13d471f..f7aca804f 100755
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/bin/sh
 set -e
 
 unset CDPATH
@@ -210,7 +210,7 @@ done
 # Infere the location of the Xenomai source tree from
 # the path of the current script.
 
-script_path=`type -p $0`
+script_path=`realpath $0`
 xenomai_root=`dirname $script_path`/..
 xenomai_root=`cd $xenomai_root && pwd`
 
Quoted 8 lines

scripts/prepare-kernel.sh default_linux_tree=/lib/modules/`uname -r`/source · line 224

Quoted 6 lines
scripts/prepare-kernel.sh +1 -0
@@ -220,6 +220,7 @@ default_linux_tree=/lib/modules/`uname -r`/source
 
 while test x$linux_tree = x; do
 	if test x$usedefault = x; then
+		# shellcheck disable=SC3037
 		echo -n "Linux tree [default $default_linux_tree]: "

Better use printf instead.

Quoted 3 lines

Good point.
If you agree with "[PATCH 10/16] prepare-kernel.sh: Remove interactivity", we can drop this anyway.

Absence of comments signals agreement in this case - ack.

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#18 lore raw

PATCH 9/16 prepare-kernel.sh: Remove --filterkvers= and --filterarch=

In reply to Richard Weinberger

These days (not) applying kernel version or architecture specific changes is no longer needed for development.
Let's simplify the code and remove this feature.

---
 scripts/prepare-kernel.sh | 65 ++++++---------------------------------
 1 file changed, 9 insertions(+), 56 deletions(-)
scripts/prepare-kernel.sh +9 -56
index f7aca804f..53ff89abd 100755
@@ -3,28 +3,6 @@ set -e
 
 unset CDPATH
 
-# At all time, this variable must be set to either:
-# "y" if the changes to the Linux tree are specific to the kernel version;
-# "n" otherwise.
-patch_kernelversion_specific="n"
-
-# At all time, this variable must be set to either:
-# "y" if the changes to the Linux tree are specific to the architecture;
-# "n" otherwise.
-patch_architecture_specific="n"
-
-# At all time, this variable must be set to either:
-# "y": ignore kernel-version-specific changes;
-# "n": ignore non-kernel-version-specific changes;
-# "b": don't filter according to the kernel version.
-patch_kernelversion_filter="b"
-
-# At all time, this variable must be set to either:
-# "y": ignore architecture-specific changes;
-# "n": ignore non-architecture-specific changes;
-# "b": don't filter according to the architecture.
-patch_architecture_filter="b"
-
 # Default path to kernel tree
 linux_tree=.
 
@@ -37,18 +15,6 @@ patch_copytempfile() {
 	fi
 }
 
-check_filter() {
-	if test "$patch_kernelversion_specific" != "$patch_kernelversion_filter" \
-		-a "$patch_architecture_specific" != "$patch_architecture_filter"; then
-		echo ok
-	elif test -e "$temp_tree/$1"; then
-		echo "$me: inconsistent multiple changes to $1 in Linux kernel tree" >&2
-		echo error
-	else
-		echo ignore
-	fi
-}
-
 patch_append() {
 	file="$1"
 	if test "x$output_patch" = "x"; then
@@ -61,10 +27,8 @@ patch_append() {
 		chmod +w "$linux_tree/$file"
 		cat >> "$linux_tree/$file"
 	else
-		if test "`check_filter $file`" = "ok"; then
-			patch_copytempfile "$file"
-			cat >> "$temp_tree/$file"
-		fi
+		patch_copytempfile "$file"
+		cat >> "$temp_tree/$file"
 	fi
 }
 
@@ -123,13 +87,11 @@ patch_link() {
 				fi
 			fi
 		else
-			if test "`check_filter $link_dir/$f`" = "ok"; then
-                    		if test -e $linux_tree/$link_dir/$f; then
-                        		echo "$me: warning: $link_dir/$f already present in Linux kernel tree, output patch might be defective" >&2
-                    		fi
-				mkdir -p $temp_tree/$link_dir/$d
-				cp $xenomai_root/$target_dir/$f $temp_tree/$link_dir/$f
+			if test -e $linux_tree/$link_dir/$f; then
+				echo "$me: warning: $link_dir/$f already present in Linux kernel tree, output patch might be defective" >&2
 			fi
+			mkdir -p $temp_tree/$link_dir/$d
+			cp $xenomai_root/$target_dir/$f $temp_tree/$link_dir/$f
 		fi
 	done
 
@@ -155,7 +117,7 @@ generate_patch() {
 }
 
 
-usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>] [--arch=<arch>] [--outpatch=<file> [--filterkvers=y|n] [--filterarch=y|n]] [--forcelink] [--default] [--verbose] [--reverse]'
+usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>] [--arch=<arch>] [--outpatch=<file> [--forcelink] [--default] [--verbose] [--reverse]'
 me=`basename $0`
 
 while test $# -gt 0; do
@@ -177,10 +139,10 @@ while test $# -gt 0; do
 		output_patch=`echo $1|sed -e 's,^--outpatch=\\(.*\\)$,\\1,g'`
 	;;
 	--filterkvers=*)
-		patch_kernelversion_filter=`echo $1|sed -e 's,^--filterkvers=\\(.*\\)$,\\1,g'`
+		echo "$me: warning: --filterkvers= is deprecated and now a no-op" >&2
 		;;
 	--filterarch=*)
-		patch_architecture_filter=`echo $1|sed -e 's,^--filterarch=\\(.*\\)$,\\1,g'`
+		echo "$me: warning: --filterarch= is deprecated and now a no-op" >&2
 		;;
 	--forcelink)
 		forcelink=1
@@ -351,8 +313,6 @@ if test x$verbose = x1; then
 	echo "IRQ pipeline installed."
 fi
 
-patch_kernelversion_specific="y"
-
 case $linux_VERSION.$linux_PATCHLEVEL in
 
 	2.*)
@@ -363,8 +323,6 @@ case $linux_VERSION.$linux_PATCHLEVEL in
 
 	*)
 
-	patch_architecture_specific="y"
-
 	if ! grep -q XENOMAI $linux_tree/init/Kconfig; then
 		version_stamp=`cat $xenomai_root/config/version-code`
 		version_major=`expr $version_stamp : '\([[0-9]]*\)' || true`
@@ -396,8 +354,6 @@ test "x$CONFIG_XENO_REVISION_LEVEL" = "x" && CONFIG_XENO_REVISION_LEVEL=0
 		fi
 	done
 
-	patch_architecture_specific="n"
-
 	if ! grep -q CONFIG_XENOMAI $linux_tree/drivers/Makefile; then
 		p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
 		( echo ; echo $p ) | patch_append drivers/Makefile
@@ -422,13 +378,10 @@ esac
 # Keep link dirs (4th parameter) descending, otherwise --reverse
 # is not able to cleanup these directories!
 
-patch_kernelversion_specific="n"
-patch_architecture_specific="y"
 for a in $target_linux_archs; do
 	patch_link r m kernel/cobalt/arch/$a arch/$a/xenomai
 	patch_link n n kernel/cobalt/include/dovetail arch/$a/include/dovetail
 done
-patch_architecture_specific="n"
 patch_link n cobalt-core.h kernel/cobalt/trace include/trace/events
 patch_link n cobalt-rtdm.h kernel/cobalt/trace include/trace/events
 patch_link n cobalt-posix.h kernel/cobalt/trace include/trace/events
Signature · 1 line
2.35.3
#19 lore raw

PATCH 10/16 prepare-kernel.sh: Remove interactivity

In reply to Richard Weinberger

Let's reduce complexity and remove user interaction, all parameters
shall get set using command line switches instead.
This makes also --default obsolete, if someone passes --linux= (empty)
to the script, it will from now on automatically fall back to /lib/modules/uname -r/source.

---
 scripts/prepare-kernel.sh | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)
scripts/prepare-kernel.sh +9 -29
index 53ff89abd..2b74e9f7b 100755
@@ -117,7 +117,7 @@ generate_patch() {
 }
 
 
-usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>] [--arch=<arch>] [--outpatch=<file> [--forcelink] [--default] [--verbose] [--reverse]'
+usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>] [--arch=<arch>] [--outpatch=<file> [--forcelink] [--verbose] [--reverse]'
 me=`basename $0`
 
 while test $# -gt 0; do
@@ -148,7 +148,7 @@ while test $# -gt 0; do
 		forcelink=1
 		;;
 	--default)
-		usedefault=1
+		echo "$me: warning: --default is deprecated and now always on" >&2
 		;;
 	--verbose)
 		verbose=1
@@ -180,24 +180,9 @@ xenomai_root=`cd $xenomai_root && pwd`
 
 default_linux_tree=/lib/modules/`uname -r`/source
 
-while test x$linux_tree = x; do
-	if test x$usedefault = x; then
-		# shellcheck disable=SC3037
-		echo -n "Linux tree [default $default_linux_tree]: "
-		read linux_tree
-	fi
-	if test x$linux_tree = x; then
-		linux_tree=$default_linux_tree
-	fi
-	if test \! -x "$linux_tree"; then
-		echo "$me: cannot access Linux tree in $linux_tree"
-		linux_tree=
-		usedefault=
-		default_linux_tree=/usr/src
-	else
-		break
-	fi
-done
+if test x$linux_tree = x; then
+	linux_tree=$default_linux_tree
+fi
 
 linux_tree=`cd $linux_tree && pwd`
 
@@ -280,15 +265,10 @@ else
 	if test x$verbose = x1; then
 		echo "$me: no IRQ pipeline support found." >&2
 	fi
-	while test x$pipeline_patch = x; do
-		# shellcheck disable=SC3037
-		echo -n "IRQ pipeline patch: "
-		read pipeline_patch
-		if test \! -r "$pipeline_patch" -o x$pipeline_patch = x; then
-			echo "$me: cannot read IRQ pipeline support from $pipeline_patch" >&2
-			pipeline_patch=
-		fi
-	done
+	if test x$pipeline_patch = x; then
+		echo "$me: no IRQ pipeline support found in $linux_tree and --dovetail= not set" >&2
+		exit 2
+	fi
 	patchdir=`dirname $pipeline_patch`;
 	patchdir=`cd $patchdir && pwd`
 	pipeline_patch=$patchdir/`basename $pipeline_patch`
Signature · 1 line
2.35.3
#20 lore raw

PATCH 11/16 prepare-kernel.sh: Remove --forcelink

In reply to Richard Weinberger

To my best knowledge, the idea behind --forcelink was forcing
the script to recreate the symlinks if the xenomai tree has changed.
But since 7098866e0 ("Fix prepare-kernel.sh when it is run in order to change the xenomai directory to which the kernel is linked"). the script is smart enough to figure whether links need an update.
So, --forcelink is essentially in vain and can be removed.

---
 scripts/prepare-kernel.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/prepare-kernel.sh +3 -3
index 2b74e9f7b..214a008e3 100755
@@ -82,7 +82,7 @@ patch_link() {
 				rm -f $linux_tree/$link_dir/$f
 			else
 				mkdir -p $linux_tree/$link_dir/$d
-				if test x$forcelink = x1 -o ! $xenomai_root/$target_dir/$f -ef $linux_tree/$link_dir/$f; then
+				if test ! $xenomai_root/$target_dir/$f -ef $linux_tree/$link_dir/$f; then
 					ln -sf $xenomai_root/$target_dir/$f $linux_tree/$link_dir/$f
 				fi
 			fi
@@ -117,7 +117,7 @@ generate_patch() {
 }
 
 
-usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>] [--arch=<arch>] [--outpatch=<file> [--forcelink] [--verbose] [--reverse]'
+usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>] [--arch=<arch>] [--outpatch=<file> [--verbose] [--reverse]'
 me=`basename $0`
 
 while test $# -gt 0; do
@@ -145,7 +145,7 @@ while test $# -gt 0; do
 		echo "$me: warning: --filterarch= is deprecated and now a no-op" >&2
 		;;
 	--forcelink)
-		forcelink=1
+		echo "$me: warning: --forcelink is deprecated and now a no-op" >&2
 		;;
 	--default)
 		echo "$me: warning: --default is deprecated and now always on" >&2
Signature · 1 line
2.35.3
#21 lore raw

PATCH 12/16 prepare-kernel.sh: Fix dovetail check

In reply to Richard Weinberger

$probe_header and $arch_probe_header are only set when --dovetail= is used, otherwise they are unset and checking whether the kernel has dovetail always succeeds.

Fix by remove the variables and use the header files directly.

---
 scripts/prepare-kernel.sh | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
scripts/prepare-kernel.sh +2 -4
index 214a008e3..a8179518b 100755
@@ -129,8 +129,6 @@ while test $# -gt 0; do
 	--dovetail=*)
 		pipeline_patch=`echo $1|sed -e 's,^--dovetail=\\(.*\\)$,\\1,g'`
 		pipeline_patch=`eval "echo $pipeline_patch"`
-		probe_header=include/linux/dovetail.h
-		arch_probe_header=include/asm/dovetail.h
 	;;
 	--arch=*)
 		linux_arch=`echo $1|sed -e 's,^--arch=\\(.*\\)$,\\1,g'`
@@ -257,7 +255,7 @@ if test x$verbose = x1; then
 	echo "Preparing kernel $linux_version$linux_EXTRAVERSION in $linux_tree..."
 fi
 
-if test -r $linux_tree/$probe_header; then
+if test -r $linux_tree/include/linux/dovetail.h; then
 	if test x$verbose = x1; then
 	   echo "IRQ pipeline found - bypassing patch."
 	fi
@@ -283,7 +281,7 @@ else
 fi
 
 for a in $target_linux_archs; do
-	if test \! -r $linux_tree/arch/$a/$arch_probe_header; then
+	if test \! -r $linux_tree/arch/$a/include/asm/dovetail.h; then
 		echo "$me: $linux_tree has no IRQ pipeline support for $a" >&2
 		exit 2
 	fi
Signature · 1 line
2.35.3
#22 lore raw

PATCH 13/16 prepare-kernel.sh: Define command line variables

In reply to Richard Weinberger

To use "set -u" later, define all variables that can be set via the command line.

---
 scripts/prepare-kernel.sh | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
scripts/prepare-kernel.sh +8 -3
index a8179518b..43883ded3 100755
@@ -3,9 +3,6 @@ set -e
 
 unset CDPATH
 
-# Default path to kernel tree
-linux_tree=.
-
 patch_copytempfile() {
 	file="$1"
 	if ! test -f "$temp_tree/$file"; then
@@ -120,6 +117,14 @@ generate_patch() {
 usage='usage: prepare-kernel --linux=<linux-tree> [--dovetail=<dovetail-patch>] [--arch=<arch>] [--outpatch=<file> [--verbose] [--reverse]'
 me=`basename $0`
 
+# Default path to kernel tree
+linux_tree=.
+output_patch=""
+linux_arch=""
+reverse=0
+pipeline_patch=""
+verbose=0
+
 while test $# -gt 0; do
 	case "$1" in
 	--linux=*)
Signature · 1 line
2.35.3
#23 lore raw

PATCH 14/16 prepare-kernel.sh: Remove dead code

In reply to Richard Weinberger

CONFIG_XENO_REVISION_LEVEL was added via
b370b7d54 ("build: introduce core API revision level in userland"), to my best knowledge it was dead code since ever.
Let's remove it.

---
 scripts/prepare-kernel.sh | 2 --
 1 file changed, 2 deletions(-)
scripts/prepare-kernel.sh +0 -2
index 43883ded3..fe9dd5de5 100755
@@ -325,8 +325,6 @@ case $linux_VERSION.$linux_PATCHLEVEL in
 		patch_reverse init/Kconfig
 	fi
 
-test "x$CONFIG_XENO_REVISION_LEVEL" = "x" && CONFIG_XENO_REVISION_LEVEL=0
-
 	for a in $target_linux_archs; do
 		if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$a/Makefile; then
 			p1="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
Signature · 1 line
2.35.3
#25 lore raw

PATCH 16/16 prepare-kernel.sh: Remove kernel version check

In reply to Richard Weinberger

The kernel version is only used to test whether the kernel is extremely old and verbose logging.
IMHO it's worth the complexity of reading it from the kernel tree.

---
 scripts/prepare-kernel.sh | 98 ++++++++++++++++-----------------------
 1 file changed, 39 insertions(+), 59 deletions(-)
scripts/prepare-kernel.sh +39 -59
index f6eedc1a0..b5644a4a9 100755
@@ -250,15 +250,8 @@ if [ ! -z $foo ] ; then
 fi
 unset foo
 
-linux_EXTRAVERSION=`awk -F= '/^EXTRAVERSION =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
-linux_PATCHLEVEL=`awk -F= '/^PATCHLEVEL =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
-linux_SUBLEVEL=`awk -F= '/^SUBLEVEL =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
-linux_VERSION=`awk -F= '/^VERSION =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
-
-linux_version="$linux_VERSION.$linux_PATCHLEVEL.$linux_SUBLEVEL"
-
 if test x$verbose = x1; then
-	echo "Preparing kernel $linux_version$linux_EXTRAVERSION in $linux_tree..."
+	echo "Preparing kernel $linux_tree..."
 fi
 
 if test -r $linux_tree/include/linux/dovetail.h; then
@@ -279,7 +272,7 @@ else
 	curdir=$PWD
 	cd $linux_tree && patch --dry-run -p1 -f < $pipeline_patch || {
 		cd $curdir;
-		echo "$me: Unable to patch kernel $linux_version$linux_EXTRAVERSION with `basename $pipeline_patch`." >&2
+		echo "$me: Unable to patch kernel $linux_tree with `basename $pipeline_patch`." >&2
 		exit 2;
 	}
 	patch -p1 -f -s < $pipeline_patch
@@ -297,61 +290,48 @@ if test x$verbose = x1; then
 	echo "IRQ pipeline installed."
 fi
 
-case $linux_VERSION.$linux_PATCHLEVEL in
-
-	2.*)
-
-	echo "$me: Unsupported kernel version $linux_VERSION.$linux_PATCHLEVEL.x" >&2
-	exit 2
-	;;
-
-	*)
-
-	if ! grep -q XENOMAI $linux_tree/init/Kconfig; then
-		version_stamp=`cat $xenomai_root/config/version-code`
-		version_major=`expr $version_stamp : '\([[0-9]]*\)' || true`
-		version_minor=`expr $version_stamp : '[[0-9]]*\.\([[0-9]*]*\)' || true`
-		revision_level=`expr $version_stamp : '[[0-9]]*\.[[0-9]*]*\.\([[0-9]*]*\)' || true`
-	if [ -z "$revision_level" ]; then
-		revision_level=0
-	fi
-	version_string=`cat $xenomai_root/config/version-label`
-	sed -e "s,@VERSION_MAJOR@,$version_major,g" \
-		-e "s,@VERSION_MINOR@,$version_minor,g" \
-		-e "s,@REVISION_LEVEL@,$revision_level,g" \
-		-e "s,@VERSION_STRING@,$version_string,g" \
-		$xenomai_root/scripts/Kconfig.frag |
-			patch_append init/Kconfig
-	elif test x$reverse = x1; then
-		patch_reverse init/Kconfig
-	fi
-
-	for a in $target_linux_archs; do
-		if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$a/Makefile; then
-			p1="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
-			p2="core-\$(CONFIG_XENOMAI)	+= arch/$a/xenomai/"
-			(echo; echo $p1; echo $p2) | patch_append arch/$a/Makefile
-		elif test x$reverse = x1; then
-			patch_reverse arch/$a/Makefile
-		fi
-	done
+if ! grep -q XENOMAI $linux_tree/init/Kconfig; then
+	version_stamp=`cat $xenomai_root/config/version-code`
+	version_major=`expr $version_stamp : '\([[0-9]]*\)' || true`
+	version_minor=`expr $version_stamp : '[[0-9]]*\.\([[0-9]*]*\)' || true`
+	revision_level=`expr $version_stamp : '[[0-9]]*\.[[0-9]*]*\.\([[0-9]*]*\)' || true`
+if [ -z "$revision_level" ]; then
+	revision_level=0
+fi
+version_string=`cat $xenomai_root/config/version-label`
+sed -e "s,@VERSION_MAJOR@,$version_major,g" \
+	-e "s,@VERSION_MINOR@,$version_minor,g" \
+	-e "s,@REVISION_LEVEL@,$revision_level,g" \
+	-e "s,@VERSION_STRING@,$version_string,g" \
+	$xenomai_root/scripts/Kconfig.frag |
+		patch_append init/Kconfig
+elif test x$reverse = x1; then
+	patch_reverse init/Kconfig
+fi
 
-	if ! grep -q CONFIG_XENOMAI $linux_tree/drivers/Makefile; then
-		p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
-		( echo ; echo $p ) | patch_append drivers/Makefile
+for a in $target_linux_archs; do
+	if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$a/Makefile; then
+		p1="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
+		p2="core-\$(CONFIG_XENOMAI)	+= arch/$a/xenomai/"
+		(echo; echo $p1; echo $p2) | patch_append arch/$a/Makefile
 	elif test x$reverse = x1; then
-		patch_reverse drivers/Makefile
+		patch_reverse arch/$a/Makefile
 	fi
+done
 
-	if ! grep -q CONFIG_XENOMAI $linux_tree/kernel/Makefile; then
-		p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
-		( echo ; echo $p ) | patch_append kernel/Makefile
-	elif test x$reverse = x1; then
-		patch_reverse kernel/Makefile
-	fi
-	;;
+if ! grep -q CONFIG_XENOMAI $linux_tree/drivers/Makefile; then
+	p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
+	( echo ; echo $p ) | patch_append drivers/Makefile
+elif test x$reverse = x1; then
+	patch_reverse drivers/Makefile
+fi
 
-esac
+if ! grep -q CONFIG_XENOMAI $linux_tree/kernel/Makefile; then
+	p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
+	( echo ; echo $p ) | patch_append kernel/Makefile
+elif test x$reverse = x1; then
+	patch_reverse kernel/Makefile
+fi
 
 # Create local directories then symlink to the source files from
 # there, so that we don't pollute the Xenomai source tree with
Signature · 1 line
2.35.3
#26 lore raw

Re: [PATCH 16/16] prepare-kernel.sh: Remove kernel version check

Quoted 14 lines · Richard Weinberger

The kernel version is only used to test whether the kernel is extremely old and verbose logging.
IMHO it's worth the complexity of reading it from the kernel tree.

---
 scripts/prepare-kernel.sh | 98 ++++++++++++++++-----------------------
 1 file changed, 39 insertions(+), 59 deletions(-)
scripts/prepare-kernel.sh +0 -0
index f6eedc1a0..b5644a4a9 100755

scripts/prepare-kernel.sh if [ ! -z $foo ] ; then · line 257

Quoted 8 lines
scripts/prepare-kernel.sh +0 -5
@@ -250,15 +250,8 @@ if [ ! -z $foo ] ; then
 fi
 unset foo
 
-linux_EXTRAVERSION=`awk -F= '/^EXTRAVERSION =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
-linux_PATCHLEVEL=`awk -F= '/^PATCHLEVEL =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
-linux_SUBLEVEL=`awk -F= '/^SUBLEVEL =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
-linux_VERSION=`awk -F= '/^VERSION =/{ gsub(/ /, "", $2); print $2}' $linux_tree/Makefile`
-

Oh, that's the nice awk code I was about to comment on earlier. If we agree on removing, that earlier refactoring should not be done, rather this patch pulled to the front if needed.

Quoted 106 lines
scripts/prepare-kernel.sh +33 -53
-linux_version="$linux_VERSION.$linux_PATCHLEVEL.$linux_SUBLEVEL"
-
 if test x$verbose = x1; then
-	echo "Preparing kernel $linux_version$linux_EXTRAVERSION in $linux_tree..."
+	echo "Preparing kernel $linux_tree..."
 fi
 
 if test -r $linux_tree/include/linux/dovetail.h; then
@@ -279,7 +272,7 @@ else
 	curdir=$PWD
 	cd $linux_tree && patch --dry-run -p1 -f < $pipeline_patch || {
 		cd $curdir;
-		echo "$me: Unable to patch kernel $linux_version$linux_EXTRAVERSION with `basename $pipeline_patch`." >&2
+		echo "$me: Unable to patch kernel $linux_tree with `basename $pipeline_patch`." >&2
 		exit 2;
 	}
 	patch -p1 -f -s < $pipeline_patch
@@ -297,61 +290,48 @@ if test x$verbose = x1; then
 	echo "IRQ pipeline installed."
 fi
 
-case $linux_VERSION.$linux_PATCHLEVEL in
-
-	2.*)
-
-	echo "$me: Unsupported kernel version $linux_VERSION.$linux_PATCHLEVEL.x" >&2
-	exit 2
-	;;
-
-	*)
-
-	if ! grep -q XENOMAI $linux_tree/init/Kconfig; then
-		version_stamp=`cat $xenomai_root/config/version-code`
-		version_major=`expr $version_stamp : '\([[0-9]]*\)' || true`
-		version_minor=`expr $version_stamp : '[[0-9]]*\.\([[0-9]*]*\)' || true`
-		revision_level=`expr $version_stamp : '[[0-9]]*\.[[0-9]*]*\.\([[0-9]*]*\)' || true`
-	if [ -z "$revision_level" ]; then
-		revision_level=0
-	fi
-	version_string=`cat $xenomai_root/config/version-label`
-	sed -e "s,@VERSION_MAJOR@,$version_major,g" \
-		-e "s,@VERSION_MINOR@,$version_minor,g" \
-		-e "s,@REVISION_LEVEL@,$revision_level,g" \
-		-e "s,@VERSION_STRING@,$version_string,g" \
-		$xenomai_root/scripts/Kconfig.frag |
-			patch_append init/Kconfig
-	elif test x$reverse = x1; then
-		patch_reverse init/Kconfig
-	fi
-
-	for a in $target_linux_archs; do
-		if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$a/Makefile; then
-			p1="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
-			p2="core-\$(CONFIG_XENOMAI)	+= arch/$a/xenomai/"
-			(echo; echo $p1; echo $p2) | patch_append arch/$a/Makefile
-		elif test x$reverse = x1; then
-			patch_reverse arch/$a/Makefile
-		fi
-	done
+if ! grep -q XENOMAI $linux_tree/init/Kconfig; then
+	version_stamp=`cat $xenomai_root/config/version-code`
+	version_major=`expr $version_stamp : '\([[0-9]]*\)' || true`
+	version_minor=`expr $version_stamp : '[[0-9]]*\.\([[0-9]*]*\)' || true`
+	revision_level=`expr $version_stamp : '[[0-9]]*\.[[0-9]*]*\.\([[0-9]*]*\)' || true`
+if [ -z "$revision_level" ]; then
+	revision_level=0
+fi
+version_string=`cat $xenomai_root/config/version-label`
+sed -e "s,@VERSION_MAJOR@,$version_major,g" \
+	-e "s,@VERSION_MINOR@,$version_minor,g" \
+	-e "s,@REVISION_LEVEL@,$revision_level,g" \
+	-e "s,@VERSION_STRING@,$version_string,g" \
+	$xenomai_root/scripts/Kconfig.frag |
+		patch_append init/Kconfig
+elif test x$reverse = x1; then
+	patch_reverse init/Kconfig
+fi
 
-	if ! grep -q CONFIG_XENOMAI $linux_tree/drivers/Makefile; then
-		p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
-		( echo ; echo $p ) | patch_append drivers/Makefile
+for a in $target_linux_archs; do
+	if ! grep -q CONFIG_XENOMAI $linux_tree/arch/$a/Makefile; then
+		p1="KBUILD_CFLAGS += -I\$(srctree)/arch/\$(SRCARCH)/xenomai/include -I\$(srctree)/include/xenomai"
+		p2="core-\$(CONFIG_XENOMAI)	+= arch/$a/xenomai/"
+		(echo; echo $p1; echo $p2) | patch_append arch/$a/Makefile
 	elif test x$reverse = x1; then
-		patch_reverse drivers/Makefile
+		patch_reverse arch/$a/Makefile
 	fi
+done
 
-	if ! grep -q CONFIG_XENOMAI $linux_tree/kernel/Makefile; then
-		p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
-		( echo ; echo $p ) | patch_append kernel/Makefile
-	elif test x$reverse = x1; then
-		patch_reverse kernel/Makefile
-	fi
-	;;
+if ! grep -q CONFIG_XENOMAI $linux_tree/drivers/Makefile; then
+	p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
+	( echo ; echo $p ) | patch_append drivers/Makefile
+elif test x$reverse = x1; then
+	patch_reverse drivers/Makefile
+fi
 

scripts/prepare-kernel.sh if test x$verbose = x1; then · line 337

Quoted 10 lines
scripts/prepare-kernel.sh +6 -1
-esac
+if ! grep -q CONFIG_XENOMAI $linux_tree/kernel/Makefile; then
+	p="obj-\$(CONFIG_XENOMAI)		+= xenomai/"
+	( echo ; echo $p ) | patch_append kernel/Makefile
+elif test x$reverse = x1; then
+	patch_reverse kernel/Makefile
+fi
 
 # Create local directories then symlink to the source files from
 # there, so that we don't pollute the Xenomai source tree with

I agree that the current check is complex and in this form useless. I just wonder if we should remove or modernize it. No clear opinion yet, but it was you who raised that question just the other week, no?

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center
#27 lore raw
In reply to Richard Weinberger
Quoted 28 lines · Richard Weinberger

This series contains the following improvements and cleanups.

- Implement --reverse to undo the effects of the script
- Emit changes that work on any architecture, renders --arch= optional
- Switch from /bin/bash to /bin/sh
- Make shellcheck happy up to warning level, info level is still a lot of work
- Convert the whole script to tabs
- Remove dead and in vain code
- Various fixes

Richard Weinberger (16):
prepare-kernel.sh: Add reverse mode
prepare-kernel.sh: Emit architecture agnostic changes prepare-kernel.sh: Convert to tabs
prepare-kernel.sh: Improve kernel tree check prepare-kernel.sh: Fix shellcheck SC2046 warnings wrt. check_filter prepare-kernel.sh: Disable SC2115 warning around $linux_tree prepare-kernel.sh: Don't use eval
prepare-kernel.sh: Don't depend on bash prepare-kernel.sh: Remove --filterkvers= and --filterarch= prepare-kernel.sh: Remove interactivity prepare-kernel.sh: Remove --forcelink
prepare-kernel.sh: Fix dovetail check
prepare-kernel.sh: Define command line variables prepare-kernel.sh: Remove dead code
prepare-kernel.sh: Don't allow uninitialized variables prepare-kernel.sh: Remove kernel version check

Quoted 4 lines
 scripts/Kconfig.frag      |   2 +-
 scripts/prepare-kernel.sh | 585 +++++++++++++++++---------------------
 2 files changed, 267 insertions(+), 320 deletions(-)

We still need some v2 of this before 3.3-rc1...

Jan

Signature · 2 lines
Siemens AG, Technology
Linux Expert Center