VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
40997fb8799da (Masahiro Yamada   2019-10-03 16:58:25 +0900  1) #!/bin/sh
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100  2) # SPDX-License-Identifier: GPL-2.0
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100  3) # Linux kernel symbol namespace import generator
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100  4) #
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100  5) # This script requires a minimum spatch version.
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100  6) SPATCH_REQ_VERSION="1.0.4"
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100  7) 
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100  8) DIR="$(dirname $(readlink -f $0))/.."
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100  9) SPATCH="`which ${SPATCH:=spatch}`"
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 10) if [ ! -x "$SPATCH" ]; then
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 11) 	echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 12) 	exit 1
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 13) fi
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 14) 
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 15) SPATCH_VERSION=$($SPATCH --version | head -1 | awk '{print $3}')
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 16) 
33114c4359592 (Masahiro Yamada   2020-12-13 01:54:29 +0900 17) if ! { echo "$SPATCH_REQ_VERSION"; echo "$SPATCH_VERSION"; } | sort -CV ; then
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 18) 	echo "spatch needs to be version $SPATCH_REQ_VERSION or higher"
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 19) 	exit 1
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 20) fi
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 21) 
bc35d4bda205d (Masahiro Yamada   2019-10-29 21:38:08 +0900 22) if [ "$KBUILD_EXTMOD" ]; then
bc35d4bda205d (Masahiro Yamada   2019-10-29 21:38:08 +0900 23) 	src_prefix=
bc35d4bda205d (Masahiro Yamada   2019-10-29 21:38:08 +0900 24) else
bc35d4bda205d (Masahiro Yamada   2019-10-29 21:38:08 +0900 25) 	src_prefix=$srctree/
bc35d4bda205d (Masahiro Yamada   2019-10-29 21:38:08 +0900 26) fi
bc35d4bda205d (Masahiro Yamada   2019-10-29 21:38:08 +0900 27) 
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 28) generate_deps_for_ns() {
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 29) 	$SPATCH --very-quiet --in-place --sp-file \
55c7549819e43 (Matthias Maennich 2020-06-04 18:41:45 +0200 30) 		$srctree/scripts/coccinelle/misc/add_namespace.cocci -D nsdeps -D ns=$1 $2
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 31) }
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 32) 
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 33) generate_deps() {
bbc55bded4aaf (Masahiro Yamada   2019-10-29 21:38:07 +0900 34) 	local mod=${1%.ko:}
bbc55bded4aaf (Masahiro Yamada   2019-10-29 21:38:07 +0900 35) 	shift
bbc55bded4aaf (Masahiro Yamada   2019-10-29 21:38:07 +0900 36) 	local namespaces="$*"
bbc55bded4aaf (Masahiro Yamada   2019-10-29 21:38:07 +0900 37) 	local mod_source_files="`cat $mod.mod | sed -n 1p                      \
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 38) 					      | sed -e 's/\.o/\.c/g'           \
bc35d4bda205d (Masahiro Yamada   2019-10-29 21:38:08 +0900 39) 					      | sed "s|[^ ]* *|${src_prefix}&|g"`"
bbc55bded4aaf (Masahiro Yamada   2019-10-29 21:38:07 +0900 40) 	for ns in $namespaces; do
bbc55bded4aaf (Masahiro Yamada   2019-10-29 21:38:07 +0900 41) 		echo "Adding namespace $ns to module $mod.ko."
57baec7b1b045 (Jessica Yu        2019-11-05 11:10:23 +0100 42) 		generate_deps_for_ns $ns "$mod_source_files"
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 43) 		# sort the imports
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 44) 		for source_file in $mod_source_files; do
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 45) 			sed '/MODULE_IMPORT_NS/Q' $source_file > ${source_file}.tmp
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 46) 			offset=$(wc -l ${source_file}.tmp | awk '{print $1;}')
77a88274dc1a2 (Masahiro Yamada   2021-04-30 10:56:27 +0900 47) 			cat $source_file | grep MODULE_IMPORT_NS | LC_ALL=C sort -u >> ${source_file}.tmp
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 48) 			tail -n +$((offset +1)) ${source_file} | grep -v MODULE_IMPORT_NS >> ${source_file}.tmp
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 49) 			if ! diff -q ${source_file} ${source_file}.tmp; then
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 50) 				mv ${source_file}.tmp ${source_file}
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 51) 			else
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 52) 				rm ${source_file}.tmp
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 53) 			fi
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 54) 		done
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 55) 	done
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 56) }
eb8305aecb958 (Matthias Maennich 2019-09-06 11:32:32 +0100 57) 
bbc55bded4aaf (Masahiro Yamada   2019-10-29 21:38:07 +0900 58) while read line
bbc55bded4aaf (Masahiro Yamada   2019-10-29 21:38:07 +0900 59) do
bbc55bded4aaf (Masahiro Yamada   2019-10-29 21:38:07 +0900 60) 	generate_deps $line
bc35d4bda205d (Masahiro Yamada   2019-10-29 21:38:08 +0900 61) done < $MODULES_NSDEPS