Michal Marek c99740
#! /bin/bash
Michal Marek c99740
Michal Marek 0a417c
#############################################################################
Michal Marek 0a417c
# Copyright (c) 2003-2005,2007-2009 Novell, Inc.
Michal Marek 0a417c
# All Rights Reserved.
Michal Marek 0a417c
#
Michal Marek 0a417c
# This program is free software; you can redistribute it and/or
Michal Marek 0a417c
# modify it under the terms of version 2 of the GNU General Public License as
Michal Marek 0a417c
# published by the Free Software Foundation.
Michal Marek 0a417c
#
Michal Marek 0a417c
# This program is distributed in the hope that it will be useful,
Michal Marek 0a417c
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Michal Marek 0a417c
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
Michal Marek 0a417c
# GNU General Public License for more details.
Michal Marek 0a417c
#
Michal Marek 0a417c
# You should have received a copy of the GNU General Public License
Michal Marek 0a417c
# along with this program; if not, contact Novell, Inc.
Michal Marek 0a417c
#
Michal Marek 0a417c
# To contact Novell about this file by physical or electronic mail,
Michal Marek 0a417c
# you may find current contact information at www.novell.com
Michal Marek 0a417c
#############################################################################
Michal Marek 0a417c
Michal Suchanek 7ae988
[ -f $(dirname $0)/../rpm/config.sh ] || exit 0
Michal Suchanek 7ae988
Michal Marek 8ffee5
source $(dirname $0)/../rpm/config.sh
Michal Marek c99740
source $(dirname $0)/wd-functions.sh
Michal Marek c99740
Jeff Mahoney 3d73f5
set -o pipefail
Jeff Mahoney 3d73f5
Michal Marek c99740
have_arch_patches=false
Michal Marek c99740
fuzz="-F0"
Michal Marek 8ffee5
case "$IBS_PROJECT" in
Michal Marek 8ffee5
SUSE:SLE-9*)
Michal Marek c99740
	fuzz=
Michal Marek c99740
	have_arch_patches=true
Michal Marek c99740
esac
Michal Marek c99740
Michal Marek c99740
usage() {
Jeff Mahoney 15348e
    cat <
Jeff Mahoney 15348e
SYNOPSIS: $0 [-qv] [--symbol=...] [--dir=...]
Juergen Gross 134d51
          [--fast] [--rapid] [stop-before-patch-name] [--vanilla] [--fuzz=NUM]
Michal Marek 73541a
          [--patch-dir=PATH] [--build-dir=PATH] [--config=ARCH-FLAVOR [--kabi]]
Petr Tesarik b999a1
          [--ctags] [--cscope] [--etags] [--skip-reverse] [--dry-run]
Jeff Mahoney 15348e
Jeff Mahoney 15348e
  The --build-dir option supports internal shell aliases, like ~, and variable
Jeff Mahoney 15348e
  expansion when the variables are properly escaped.  Environment variables
Jeff Mahoney 15348e
  and the following list of internal variables are permitted:
Jeff Mahoney 15348e
  \$PATCH_DIR:		The expanded source tree
Jeff Mahoney 15348e
  \$SRCVERSION:		The current linux source tarball version
Jeff Mahoney 15348e
  \$TAG:			The current tag or branch of this repo
Jeff Mahoney 15348e
  \$EXT:			A string expanded from current \$EXTRA_SYMBOLS
Jeff Mahoney 149391
  With --config=ARCH-FLAVOR, these have values. Otherwise they are empty.
Jeff Mahoney 149391
  \$CONFIG:		The current ARCH-FLAVOR.
Jeff Mahoney 149391
  \$CONFIG_ARCH:		The current ARCH.
Jeff Mahoney 149391
  \$CONFIG_FLAVOR:	The current FLAVOR.
Jeff Mahoney 3ee854
Jeff Mahoney 3ee854
  The --no-quilt option will still create quilt-style backups for each
Jeff Mahoney 3ee854
  file that is modified but the backups will be removed if the patch
Jeff Mahoney 3ee854
  is successful. This can be fast because the new files may be created
Jeff Mahoney 3ee854
  and removed before writeback occurs so they only exist in memory. A
Jeff Mahoney 3ee854
  failed patch will be rolled back and the caller will be able to diagnose it.
Jeff Mahoney 3ee854
Jeff Mahoney 3ee854
  The --fast option will concatenate all the patches to be applied and
Jeff Mahoney 3ee854
  call patch just once. This is even faster than --no-quilt but if any
Jeff Mahoney 3ee854
  of the component patches fail to apply the tree will not be rolled
Jeff Mahoney 3ee854
  back.
Jeff Mahoney 3ee854
Michal Srb 7178c2
  The --rapid option will use rapidquilt to apply patches.
Michal Srb 7178c2
Petr Tesarik b999a1
  The --dry-run option only works with --fast and --rapid.
Petr Tesarik b999a1
Jeff Mahoney d2affe
  The --signing-key option specifies a pathname for a key to be used for
Jeff Mahoney d2affe
  module signing and for signing the kernel for use with UEFI Secure Boot.
Jeff Mahoney d2affe
Juergen Gross 134d51
  When used with stop-before-patch-name, both --fast and --no-quilt
Jeff Mahoney 3ee854
  will set up a quilt environment for the remaining patches.
Jeff Mahoney 15348e
END
Michal Marek c99740
    exit 1
Michal Marek c99740
}
Michal Marek c99740
Michal Srb 7178c2
apply_rapid_patches() {
Michal Srb 7178c2
    printf "%s\n" ${PATCHES_BEFORE[@]} >> $PATCH_DIR/series
Petr Tesarik b999a1
    rapidquilt push -a -d $PATCH_DIR -p $PWD $fuzz $DRY_RUN
Michal Srb 7178c2
    status=$?
Michal Srb 7178c2
}
Michal Srb 7178c2
Jeff Mahoney 3ee854
apply_fast_patches() {
Jean Delvare 8b2d7c
    echo "[ Fast-applying ${#PATCHES_BEFORE[@]} patches. ${#PATCHES_AFTER[@]} remain. ]"
Michal Marek aafd93
    LAST_LOG=$(echo "${PATCHES_BEFORE[@]}" | xargs cat | \
Michal Marek 0719c3
        patch -d $PATCH_DIR -p1 -E $fuzz --force --no-backup-if-mismatch \
Petr Tesarik b999a1
		-s $DRY_RUN 2>&1)
Jeff Mahoney 3ee854
    STATUS=$?
Jeff Mahoney 3ee854
Jeff Mahoney 3ee854
    if [ $STATUS -ne 0 ]; then
Jean Delvare bb5d6c
        echo "$LAST_LOG" >> $PATCH_LOG
Jean Delvare bb5d6c
        [ -n "$QUIET" ] && echo "$LAST_LOG"
Jean Delvare 721a2b
        echo "All-in-one patch failed (not rolled back)."
Jean Delvare bb5d6c
        echo "Logfile: $PATCH_LOG"
Jean Delvare 721a2b
        status=1
Jeff Mahoney 3ee854
    fi
Jeff Mahoney 3ee854
}
Jeff Mahoney 758fbb
SKIPPED_PATCHES=
Jeff Mahoney 3ee854
Jeff Mahoney 3ee854
# Patch kernel normally
Juergen Gross f24575
apply_one_patch() {
Juergen Gross f24575
    echo "[ $PATCH ]"
Juergen Gross f24575
    echo "[ $PATCH ]" >> $PATCH_LOG
Juergen Gross f24575
    backup_dir=$PATCH_DIR/.pc/$PATCH
Juergen Gross f24575
Juergen Gross f24575
    LAST_LOG=$(patch -d $PATCH_DIR --backup --prefix=$backup_dir/ -p1 -E $fuzz \
Juergen Gross f24575
            --no-backup-if-mismatch --force < $PATCH 2>&1)
Juergen Gross f24575
    STATUS=$?
Juergen Gross f24575
Juergen Gross f24575
    if [ $STATUS -ne 0 ]; then
Juergen Gross f24575
        restore_files $backup_dir $PATCH_DIR
Juergen Gross f24575
Juergen Gross f24575
        if $SKIP_REVERSE; then
Juergen Gross f24575
            patch -R -d $PATCH_DIR -p1 -E $fuzz --force --dry-run \
Juergen Gross f24575
                    < $PATCH > /dev/null 2>&1
Juergen Gross f24575
            ST=$?
Juergen Gross f24575
            if [ $ST -eq 0 ]; then
Juergen Gross f24575
                LAST_LOG="[ skipped: can be reverse-applied ]"
Juergen Gross f24575
                [ -n "$QUIET" ] && echo "$LAST_LOG"
Juergen Gross f24575
                STATUS=0
Juergen Gross f24575
                SKIPPED_PATCHES="$SKIPPED_PATCHES $PATCH"
Juergen Gross f24575
                PATCH="# $PATCH"
Juergen Gross f24575
                remove_rejects $backup_dir $PATCH_DIR
Juergen Gross f24575
            fi
Juergen Gross f24575
        fi
Juergen Gross f24575
Juergen Gross f24575
        # Backup directory is no longer needed
Juergen Gross f24575
        rm -rf $backup_dir
Juergen Gross f24575
    else
Juergen Gross f24575
        if $QUILT; then
Juergen Gross f24575
            echo "$PATCH" >> $PATCH_DIR/.pc/applied-patches
Juergen Gross f24575
        fi
Juergen Gross f24575
    fi
Juergen Gross f24575
Juergen Gross f24575
    if ! $QUILT; then
Juergen Gross f24575
        rm -rf $PATCH_DIR/.pc/
Juergen Gross f24575
    fi
Juergen Gross f24575
    echo "$LAST_LOG" >> $PATCH_LOG
Juergen Gross f24575
    [ -z "$QUIET" ] && echo "$LAST_LOG"
Juergen Gross f24575
    if [ $STATUS -ne 0 ]; then
Juergen Gross f24575
        [ -n "$QUIET" ] && echo "$LAST_LOG"
Juergen Gross f24575
        echo "Patch $PATCH failed (rolled back)."
Juergen Gross f24575
        echo "Logfile: $PATCH_LOG"
Juergen Gross f24575
        status=1
Juergen Gross f24575
        return 1
Juergen Gross f24575
    else
Juergen Gross f24575
        echo "$SERIES_PFX$PATCH" >> $PATCH_DIR/series
Juergen Gross f24575
    fi
Juergen Gross f24575
Juergen Gross f24575
    return 0
Juergen Gross f24575
}
Juergen Gross f24575
Jeff Mahoney 3ee854
apply_patches() {
Juergen Gross 134d51
    for ((n=0; n<${#PATCHES_BEFORE[@]}; n++)); do
Juergen Gross 134d51
        PATCH=${PATCHES_BEFORE[n]}
Juergen Gross 134d51
        if [ ! -r "$PATCH" ]; then
Juergen Gross 134d51
            echo "Patch $PATCH not found."
Juergen Gross 134d51
            status=1
Juergen Gross 134d51
            break
Juergen Gross 134d51
        fi
Juergen Gross 134d51
        apply_one_patch || break
Juergen Gross 134d51
    done
Juergen Gross 134d51
}
Juergen Gross 134d51
Juergen Gross 134d51
apply_rest_patches() {
Juergen Gross 134d51
    STEP_BY_STEP=1
Juergen Gross 134d51
    echo "Stopping before ${PATCHES[0]}"
Juergen Gross 134d51
    for ((n=0; n<${#PATCHES[@]}; n++)); do
Juergen Gross 134d51
        PATCH=${PATCHES[n]}
Juergen Gross 134d51
        if [ ! -r "$PATCH" ]; then
Juergen Gross 134d51
            echo "Patch $PATCH not found."
Juergen Gross 134d51
            status=1
Juergen Gross 134d51
            break
Jeff Mahoney 3ee854
        fi
Jeff Mahoney 3ee854
        if [ -n "$STEP_BY_STEP" ]; then
Jeff Mahoney 3ee854
            while true; do
Jeff Mahoney 3ee854
                echo -n "Continue ([y]es/[n]o/yes to [a]ll)?"
Jeff Mahoney 3ee854
                read YESNO
Jeff Mahoney 3ee854
                case $YESNO in
Jeff Mahoney 3ee854
                    ([yYjJsS])
Jeff Mahoney 3ee854
                        break
Jeff Mahoney 3ee854
                        ;;
Jeff Mahoney 3ee854
                    ([nN])
Juergen Gross 134d51
                        break 2 # break out of outer loop
Jeff Mahoney 3ee854
                        ;;
Jeff Mahoney 3ee854
                    ([aA])
Jeff Mahoney 3ee854
                        unset STEP_BY_STEP
Jeff Mahoney 3ee854
                        break
Jeff Mahoney 3ee854
                        ;;
Jeff Mahoney 3ee854
                esac
Jeff Mahoney 3ee854
            done
Jeff Mahoney 3ee854
        fi
Juergen Gross f24575
        apply_one_patch || break
Jeff Mahoney 3ee854
    done
Jeff Mahoney 3ee854
}
Jeff Mahoney 3ee854
Jeff Mahoney 758fbb
show_skipped() {
Jeff Mahoney 758fbb
    if [ -n "$SKIPPED_PATCHES" ]; then
Jeff Mahoney 758fbb
	echo "The following patches were skipped and can be removed from series.conf:"
Jeff Mahoney 758fbb
	for p in $SKIPPED_PATCHES; do
Jeff Mahoney 758fbb
	    echo "$p"
Jeff Mahoney 758fbb
	done
Jeff Mahoney 758fbb
    fi
Jeff Mahoney 758fbb
}
Jeff Mahoney 758fbb
Michal Marek c99740
# Allow to pass in default arguments via SEQUENCE_PATCH_ARGS.
Michal Marek c99740
set -- $SEQUENCE_PATCH_ARGS "$@"
Michal Marek c99740
Michal Marek c99740
if $have_arch_patches; then
Michal Marek c99740
	arch_opt="arch:"
Michal Marek c99740
else
Michal Marek c99740
	arch_opt=""
Michal Marek c99740
fi
Michal Suchanek 2ea024
options="$(getopt -o qvd:F: --long quilt,no-quilt,$arch_opt,symbol:,dir:,combine,fast,rapid,vanilla,fuzz:,patch-dir:,build-dir:,config:,kabi,ctags,cscope,etags,skip-reverse,dry-run,signing-key: -- "$@")"
Michal Marek c99740
Michal Marek c99740
if [ $? -ne 0 ]
Michal Marek c99740
then
Michal Marek c99740
    usage
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek c99740
eval set -- "$options"
Michal Marek c99740
Michal Marek c99740
QUIET=1
Michal Marek c99740
EXTRA_SYMBOLS=
Michal Marek b0d5a9
QUILT=true
Michal Marek c99740
FAST=
Michal Srb 7178c2
RAPID=
Michal Marek c99740
VANILLA=false
Jeff Mahoney 15348e
SP_BUILD_DIR=
Jeff Mahoney 149391
CONFIG=
Jeff Mahoney 149391
CONFIG_ARCH=
Jeff Mahoney 149391
CONFIG_FLAVOR=
Jeff Mahoney eef527
KABI=false
Jeff Mahoney f7a93d
CTAGS=false
Jeff Mahoney 3d761a
CSCOPE=false
Johannes Thumshirn 798c4e
ETAGS=false
Jeff Mahoney 758fbb
SKIP_REVERSE=false
Petr Tesarik b999a1
DRY_RUN=
Jeff Mahoney d2affe
SIGNING_KEY=
Michal Marek c99740
Michal Marek c99740
while true; do
Michal Marek c99740
    case "$1" in
Michal Marek c99740
    	-q)
Michal Marek c99740
	    QUIET=1
Michal Marek c99740
	    ;;
Michal Marek c99740
    	-v)
Michal Marek c99740
	    QUIET=
Michal Marek c99740
	    ;;
Michal Marek c99740
	--quilt)
Michal Marek b0d5a9
	    QUILT=true
Michal Marek b0d5a9
	    ;;
Michal Marek b0d5a9
	--no-quilt)
Michal Marek b0d5a9
	    QUILT=false
Michal Marek c99740
	    ;;
Michal Marek c99740
	--combine)
Jeff Mahoney 3ee854
	    # ignored
Michal Marek c99740
	    ;;
Michal Marek c99740
       	--fast)
Michal Marek c99740
	    FAST=1
Michal Marek c99740
	    ;;
Michal Srb 7178c2
	--rapid)
Michal Srb 7178c2
	    RAPID=1
Michal Srb 7178c2
	    ;;
Michal Marek c99740
	--arch)
Michal Marek c99740
	    export PATCH_ARCH=$2
Michal Marek c99740
	    shift
Michal Marek c99740
	    ;;
Michal Marek c99740
	--symbol)
Michal Marek c99740
	    EXTRA_SYMBOLS="$EXTRA_SYMBOLS $2"
Michal Marek c99740
	    shift
Michal Marek c99740
	    ;;
Michal Marek c99740
	-d|--dir)
Michal Marek c99740
	    SCRATCH_AREA=$2
Michal Marek c99740
	    shift
Michal Marek c99740
	    ;;
Michal Marek c99740
	--vanilla)
Michal Marek c99740
	    VANILLA=true
Michal Marek c99740
	    ;;
Michal Marek c99740
	-F|--fuzz)
Michal Marek c99740
	    fuzz="-F$2"
Michal Marek c99740
	    shift
Michal Marek c99740
	    ;;
Michal Marek 73541a
        --patch-dir)
Michal Marek 73541a
            PATCH_DIR=$2
Michal Marek 73541a
            shift
Michal Marek 73541a
            ;;
Jeff Mahoney 15348e
	--build-dir)
Jeff Mahoney 15348e
	    SP_BUILD_DIR="$2"
Jeff Mahoney 15348e
	    shift
Jeff Mahoney 15348e
	    ;;
Jeff Mahoney 149391
	--config)
Jeff Mahoney 149391
	    CONFIG="$2"
Jeff Mahoney 149391
	    shift
Jeff Mahoney 149391
	    ;;
Jeff Mahoney eef527
	--kabi)
Jeff Mahoney eef527
	    KABI=true
Jeff Mahoney eef527
	    ;;
Jeff Mahoney f7a93d
	--ctags)
Jeff Mahoney f7a93d
	    CTAGS=true
Jeff Mahoney f7a93d
	    ;;
Jeff Mahoney 3d761a
	--cscope)
Jeff Mahoney 3d761a
	    CSCOPE=true
Jeff Mahoney 3d761a
	    ;;
Johannes Thumshirn 798c4e
	--etags)
Johannes Thumshirn 798c4e
	    ETAGS=true
Johannes Thumshirn 798c4e
	    ;;
Jeff Mahoney 758fbb
	--skip-reverse)
Jeff Mahoney 758fbb
	    SKIP_REVERSE=true
Jeff Mahoney 758fbb
	    ;;
Petr Tesarik b999a1
	--dry-run)
Petr Tesarik b999a1
	    DRY_RUN=--dry-run
Petr Tesarik b999a1
	    ;;
Jeff Mahoney d2affe
	--signing-key)
Jeff Mahoney d2affe
            SIGNING_KEY="$2"
Jeff Mahoney d2affe
            shift
Jeff Mahoney d2affe
            ;;
Michal Marek c99740
	--)
Michal Marek c99740
	    shift
Michal Marek c99740
	    break ;;
Michal Marek c99740
	*)
Michal Marek c99740
	    usage ;;
Michal Marek c99740
    esac
Michal Marek c99740
    shift
Michal Marek c99740
done
Michal Marek c99740
Michal Marek c99740
unset LIMIT
Michal Marek c99740
if [ $# -ge 1 ]; then
Michal Marek c99740
    LIMIT=$1
Michal Marek c99740
    shift
Michal Marek c99740
fi
Michal Marek c99740
Petr Tesarik b999a1
if ! [ -z "$DRY_RUN" -o -n "$FAST" -o -n "$RAPID" ]; then
Petr Tesarik b999a1
    echo "--dry-run requires --fast or --rapid"
Petr Tesarik b999a1
    exit 1
Petr Tesarik b999a1
fi
Petr Tesarik b999a1
Michal Marek 59eff2
if test -z "$CONFIG"; then
Jean Delvare 443fd4
	if test "$VANILLA_ONLY" = 1 || $VANILLA; then
Michal Marek d70c5d
		CONFIG=$(uname -m)-vanilla
Michal Marek d70c5d
	else
Michal Marek 52adc6
		machine=$(uname -m)
Michal Marek e1cea1
		# XXX: We could use scripts/arch-symbols here, but it is
Michal Marek e1cea1
		# not unified among branches and has weird behavior in some
Michal Marek 52adc6
		case "$machine" in
Michal Marek 52adc6
		i?86)
Michal Marek 52adc6
			machine=i386
Michal Marek e1cea1
			;;
Michal Marek e1cea1
		aarch64)
Michal Marek e1cea1
			machine=arm64
Michal Marek e1cea1
			;;
Michal Marek d70c5d
		esac
Michal Marek 52adc6
		if test -e "config/$machine/smp"; then
Michal Marek 52adc6
			CONFIG=$machine-smp
Michal Marek 52adc6
		elif test -e "config/$machine/pae"; then
Michal Marek 52adc6
			CONFIG=$machine-pae
Olaf Hering c2c287
		elif test -e "config/$machine/azure"; then
Olaf Hering c2c287
			CONFIG=$machine-azure
Michal Marek d1c414
		elif test -e "config/$machine/default"; then
Michal Marek 52adc6
			CONFIG=$machine-default
Michal Marek 4f08ae
		elif test -n "$VARIANT" -a -e "config/$machine/${VARIANT#-}"; then
Michal Marek 4f08ae
			CONFIG=$machine$VARIANT
Michal Marek d1c414
		else
Michal Marek a3ed51
			# Try other architectures and assume the user is able
Michal Marek a3ed51
			# to cross-compile
Michal Marek 924b91
			for machine in ${machine/ppc64le/ppc64} \
Michal Marek 924b91
				${machine/ppc64/ppc64le} x86_64 \
Michal Marek 924b91
				ppc64 ppc64le arm64 s390x; do
Michal Marek a3ed51
				if test -e "config/$machine/default"; then
Michal Marek a3ed51
					CONFIG=$machine-default
Michal Marek a3ed51
					break
Michal Marek a3ed51
				fi
Michal Marek a3ed51
			done
Michal Marek a3ed51
		fi
Michal Marek a3ed51
		if test -z "$CONFIG"; then
Michal Marek d1c414
			echo "Cannot determine default config for arch $machine"
Michal Marek 52adc6
		fi
Michal Marek d70c5d
	fi
Michal Marek 59eff2
fi
Michal Marek 59eff2
Michal Marek d1c414
if test -n "$CONFIG"; then
Michal Marek d1c414
	CONFIG_ARCH=${CONFIG%%-*}
Michal Marek d1c414
	CONFIG_FLAVOR=${CONFIG##*-}
Michal Marek d1c414
	if [ "$CONFIG" = "$CONFIG_ARCH" -o "$CONFIG" = "$CONFIG_FLAVOR" -o \
Michal Marek d1c414
			-z "$CONFIG_ARCH" -o -z "$CONFIG_FLAVOR" ]; then
Michal Marek d1c414
		echo "Invalid config spec: --config=ARCH-FLAVOR is expected."
Michal Marek d1c414
		usage
Michal Marek d1c414
	fi
Jeff Mahoney 149391
fi
Jeff Mahoney 149391
Michal Marek c99740
if [ $# -ne 0 ]; then
Michal Marek c99740
    usage
Michal Marek c99740
fi
Michal Marek c99740
Luis R. Rodriguez dd15fe
# We need at least 2.7 now due to kselftests-kmp-default requiring
Luis R. Rodriguez dd15fe
# selftests with the need to ensure scripts are execuable.
Luis R. Rodriguez dd15fe
PATCH_VERSION_REQ="2.7"
Luis R. Rodriguez dd15fe
PATCH_VERSION_REQ_LD_VERSION=$(echo $PATCH_VERSION_REQ | scripts/ld-version.sh)
Luis R. Rodriguez dd15fe
PATCH_VERSION=$(patch --version | head -1 | awk '{print $3}')
Luis R. Rodriguez dd15fe
PATCH_VERSION_LD=$(echo $PATCH_VERSION | scripts/ld-version.sh)
Luis R. Rodriguez dd15fe
Luis R. Rodriguez dd15fe
if [ $PATCH_VERSION_LD -lt $PATCH_VERSION_REQ_LD_VERSION ]; then
Luis R. Rodriguez dd15fe
	echo "$0 requires at least patch version $PATCH_VERSION_REQ"
Michal Marek c99740
	exit 1
Luis R. Rodriguez dd15fe
fi
Michal Marek c99740
Michal Marek c99740
# Check SCRATCH_AREA.
Michal Marek c99740
if [ -z "$SCRATCH_AREA" ]; then
Michal Marek c99740
    echo "SCRATCH_AREA not defined (defaulting to \"tmp\")"
Michal Marek c99740
    SCRATCH_AREA=tmp
Michal Marek c99740
fi
Michal Marek c99740
if [ ! -d "$SCRATCH_AREA" ]; then
Michal Marek c99740
    if ! mkdir -p $SCRATCH_AREA; then
Michal Marek c99740
	echo "creating scratch dir $SCRATCH_AREA failed"
Michal Marek c99740
	exit 1
Michal Marek c99740
    fi
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek c99740
[ "${SCRATCH_AREA:0:1}" != "/" ] \
Michal Marek c99740
    && SCRATCH_AREA="$PWD/$SCRATCH_AREA"
Michal Marek c99740
Michal Marek c99740
TMPDIR=$SCRATCH_AREA
Michal Marek c99740
export TMPDIR
Michal Marek c99740
ORIG_DIR=$SCRATCH_AREA/linux-$SRCVERSION.orig
Michal Marek c99740
TAG=$(get_branch_name)
Michal Marek 5536ab
TAG=${TAG//\//_}
Qu Wenruo 4be920
TAG=${TAG//\#/_}
Michal Marek 4618ac
if $VANILLA; then
Jeff Mahoney a10893
	TAG=${TAG}-vanilla
Jeff Mahoney a10893
fi
Michal Marek c99740
PATCH_LOG=$SCRATCH_AREA/patch-$SRCVERSION${TAG:+-$TAG}.log
Michal Marek c99740
Michal Marek c99740
# Check series.conf.
Michal Marek c99740
if [ ! -r series.conf ]; then
Michal Marek c99740
    echo "Configuration file \`series.conf' not found"
Michal Marek c99740
    exit 1
Michal Marek c99740
fi
Michal Marek c99740
if $have_arch_patches; then
Michal Marek c99740
    if [ -z "$ARCH_SYMBOLS" ]; then
Michal Marek 627f64
        if [ -x ./arch-symbols ]; then
Michal Marek 627f64
            ARCH_SYMBOLS=./arch-symbols
Michal Marek c99740
        elif [ -x scripts/arch-symbols ]; then
Michal Marek c99740
            ARCH_SYMBOLS=scripts/arch-symbols
Michal Marek c99740
        else
Michal Marek c99740
            echo "Cannot locate \`arch-symbols' script (export ARCH_SYMBOLS)"
Michal Marek c99740
            exit 1
Michal Marek c99740
        fi
Michal Marek c99740
    else
Michal Marek c99740
        if [ ! -x "$ARCH_SYMBOLS" ]; then
Michal Marek c99740
            echo "Cannot execute \`arch-symbols' script"
Michal Marek c99740
            exit 1
Michal Marek c99740
        fi
Michal Marek c99740
    fi
Michal Marek c99740
    SYMBOLS=$($ARCH_SYMBOLS)
Michal Marek c99740
    if [ -z "$SYMBOLS" ]; then
Michal Marek c99740
        echo "Unsupported architecture \`$ARCH'" >&2
Michal Marek c99740
        exit 1
Michal Marek c99740
    fi
Michal Marek c99740
echo "Architecture symbol(s): $SYMBOLS"
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek c99740
if [ -s extra-symbols ]; then
Michal Marek c99740
	EXTRA_SYMBOLS="$EXTRA_SYMBOLS $(cat extra-symbols)"
Michal Marek c99740
fi
Michal Marek c99740
if [ -n "$EXTRA_SYMBOLS" ]; then
Michal Marek c99740
    EXTRA_SYMBOLS=${EXTRA_SYMBOLS# }
Michal Marek c99740
    echo "Extra symbols: $EXTRA_SYMBOLS"
Michal Marek c99740
    SYMBOLS="$SYMBOLS $EXTRA_SYMBOLS"
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek c99740
EXT=${EXTRA_SYMBOLS// /-}
Michal Marek c99740
EXT=${EXT//\//}
Michal Marek 73541a
Michal Marek 73541a
if test -z "$PATCH_DIR"; then
Michal Marek 96f69a
    PATCH_DIR=$SCRATCH_AREA/linux-$SRCVERSION${TAG:+-$TAG}${EXT:+-}$EXT
Michal Marek 73541a
fi
Michal Marek c99740
Jeff Mahoney 15348e
if [ -n "$SP_BUILD_DIR" ]; then
Jeff Mahoney 15348e
    # This allows alias (~) and variable expansion
Jeff Mahoney 15348e
    SP_BUILD_DIR=$(eval echo "$SP_BUILD_DIR")
Jeff Mahoney 15348e
else
Jeff Mahoney 15348e
    SP_BUILD_DIR="$PATCH_DIR"
Jeff Mahoney 15348e
fi
Jeff Mahoney 15348e
Petr Tesarik b999a1
if [ -z "$DRY_RUN" ]; then
Petr Tesarik b999a1
    echo "Creating tree in $PATCH_DIR"
Michal Marek c99740
Petr Tesarik b999a1
    # Clean up from previous run
Petr Tesarik b999a1
    rm -f "$PATCH_LOG"
Petr Tesarik b999a1
    if [ -e $PATCH_DIR ]; then
Petr Tesarik b999a1
	echo "Cleaning up from previous run"
Petr Tesarik b999a1
	rm -rf $PATCH_DIR
Petr Tesarik b999a1
    fi
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek c99740
# Create fresh $SCRATCH_AREA/linux-$SRCVERSION.
Michal Marek c99740
if ! [ -d $ORIG_DIR ]; then
67bee1
    unpack_tarball "$SRCVERSION" "$ORIG_DIR" "$URL"
Michal Marek c99740
    find $ORIG_DIR -type f | xargs chmod a-w,a+r
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek c99740
if $VANILLA; then
Andreas Stieger 7a787f
	PATCHES=( $(scripts/guards $SYMBOLS < series.conf | grep -E '^patches\.(kernel\.org|rpmify)/') )
Michal Marek c99740
else
Michal Marek 4618ac
	PATCHES=( $(scripts/guards $SYMBOLS < series.conf) )
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek c99740
# Check if patch $LIMIT exists
Jeff Mahoney 1419f5
if [ -n "$LIMIT" ]; then
Michal Marek c99740
    for ((n=0; n<${#PATCHES[@]}; n++)); do
Michal Marek c99740
	if [ "$LIMIT" = - ]; then
Michal Marek c99740
	    LIMIT=${PATCHES[n]}
Michal Marek c99740
	    break
Michal Marek c99740
	fi
Michal Marek c99740
	case "${PATCHES[n]}" in
Michal Marek c99740
	$LIMIT|*/$LIMIT)
Michal Marek c99740
	    LIMIT=${PATCHES[n]}
Michal Marek c99740
	    break
Michal Marek c99740
	    ;;
Michal Marek c99740
	esac
Michal Marek c99740
    done
Jeff Mahoney 568324
    if [ -n "$LIMIT" ] && ((n == ${#PATCHES[@]})); then
Michal Marek c99740
	echo "No patch \`$LIMIT' found."
Michal Marek c99740
	exit 1
Michal Marek c99740
    fi
Michal Marek c99740
    PATCHES_BEFORE=()
Michal Marek c99740
    for ((m=0; m
Michal Marek c99740
	PATCHES_BEFORE[m]=${PATCHES[m]}
Michal Marek c99740
    done
Michal Marek c99740
    PATCHES_AFTER=()
Michal Marek c99740
    for ((m=n; m<${#PATCHES[@]}; m++)); do
Michal Marek c99740
	PATCHES_AFTER[m-n]=${PATCHES[m]}
Michal Marek c99740
    done
Michal Marek c99740
else
Michal Marek c99740
    PATCHES_BEFORE=( "${PATCHES[@]}" )
Michal Marek c99740
    PATCHES_AFTER=()
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek c99740
# Helper function to restore files backed up by patch. This is
Michal Marek c99740
# faster than doing a --dry-run first.
Michal Marek c99740
restore_files() {
Jean Delvare 106424
    local backup_dir=$1 patch_dir=$2 file
Michal Marek c99740
    local -a remove restore
Michal Marek c99740
 
Michal Marek c99740
    if [ -d $backup_dir ]; then
Michal Marek c99740
	pushd $backup_dir > /dev/null
Michal Marek c99740
	for file in $(find . -type f) ; do
Michal Marek c99740
	    if [ -s "$file" ]; then
Michal Marek c99740
		restore[${#restore[@]}]="$file"
Michal Marek c99740
	    else
Michal Marek c99740
		remove[${#remove[@]}]="$file"
Michal Marek c99740
	    fi
Michal Marek c99740
	done
Michal Marek c99740
	#echo "Restore: ${restore[@]}"
Michal Marek c99740
	[ ${#restore[@]} -ne 0 ] \
Michal Marek c99740
	    && printf "%s\n" "${restore[@]}" \
Michal Marek c99740
		| xargs cp -f --parents --target $patch_dir
Michal Marek c99740
	cd $patch_dir
Michal Marek c99740
	#echo "Remove: ${remove[@]}"
Michal Marek c99740
	[ ${#remove[@]} -ne 0 ] \
Michal Marek c99740
	    && printf "%s\n" "${remove[@]}" | xargs rm -f
Michal Marek c99740
	popd > /dev/null
Michal Marek c99740
    fi
Michal Marek c99740
}
Michal Marek c99740
Jean Delvare 411274
# Helper function to remove stray .rej files.
Jean Delvare 411274
remove_rejects() {
Jean Delvare 411274
    local backup_dir=$1 patch_dir=$2 file
Jean Delvare 411274
    local -a remove
Jean Delvare 411274
Jean Delvare 411274
    if [ -d $backup_dir ]; then
Jean Delvare 411274
	pushd $backup_dir > /dev/null
Jean Delvare 411274
	for file in $(find . -type f) ; do
Jean Delvare 411274
	    if [ -f "$patch_dir/$file.rej" ]; then
Jean Delvare 411274
		remove[${#remove[@]}]="$file.rej"
Jean Delvare 411274
	    fi
Jean Delvare 411274
	done
Jean Delvare 411274
	cd $patch_dir
Jean Delvare 411274
	#echo "Remove rejects: ${remove[@]}"
Jean Delvare 411274
	[ ${#remove[@]} -ne 0 ] \
Jean Delvare 411274
	    && printf "%s\n" "${remove[@]}" | xargs rm -f
Jean Delvare 411274
	popd > /dev/null
Jean Delvare 411274
    fi
Jean Delvare 411274
}
Jean Delvare 411274
Petr Tesarik b999a1
if [ -z "$DRY_RUN" ]; then
Petr Tesarik b999a1
    # Create hardlinked source tree
Petr Tesarik b999a1
    echo "Linking from $ORIG_DIR"
Petr Tesarik b999a1
    cp -rld $ORIG_DIR $PATCH_DIR
Petr Tesarik b999a1
    # create a relative symlink
Petr Tesarik b999a1
    ln -snf ${PATCH_DIR#$SCRATCH_AREA/} $SCRATCH_AREA/current
Petr Tesarik b999a1
else
Petr Tesarik b999a1
    PATCH_DIR="$ORIG_DIR"
Petr Tesarik b999a1
fi
Michal Marek c99740
Michal Marek c99740
echo -e "# Symbols: $SYMBOLS\n#" > $PATCH_DIR/series
Michal Marek c99740
SERIES_PFX=
Michal Marek b0d5a9
if ! $QUILT; then
Michal Marek c99740
    SERIES_PFX="# "
Michal Marek c99740
fi
Michal Marek c99740
Petr Tesarik b999a1
if [ -z "$DRY_RUN" ]; then
Petr Tesarik b999a1
    mkdir $PATCH_DIR/.pc
Petr Tesarik b999a1
    echo 2 > $PATCH_DIR/.pc/.version
Petr Tesarik b999a1
fi
Michal Marek c99740
Michal Srb 7178c2
if [ -n "$FAST" ]; then
Jeff Mahoney 3ee854
    apply_fast_patches
Michal Srb 7178c2
elif [ -n "$RAPID" ]; then
Michal Srb 7178c2
    apply_rapid_patches
Michal Srb 7178c2
else
Michal Srb 7178c2
    apply_patches
Jeff Mahoney 3ee854
fi
Michal Marek c99740
Juergen Gross 134d51
PATCHES=( ${PATCHES_AFTER[@]} )
Juergen Gross 134d51
Juergen Gross 134d51
if ! $QUILT && [ -z "$FAST$RAPID" ]; then
Juergen Gross 134d51
    apply_rest_patches
Juergen Gross 134d51
fi
Juergen Gross 134d51
Petr Tesarik b999a1
if [ -n "$DRY_RUN" ]; then
Petr Tesarik b999a1
    exit $status
Petr Tesarik b999a1
fi
Petr Tesarik b999a1
Michal Marek c99740
if [ -n "$EXTRA_SYMBOLS" ]; then
Michal Marek c99740
    echo "$EXTRA_SYMBOLS" > $PATCH_DIR/extra-symbols
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek b0d5a9
if ! $QUILT; then
Michal Marek c99740
    rm $PATCH_DIR/series
Michal Marek c99740
fi
Michal Marek c99740
Michal Marek c99740
ln -s $PWD $PATCH_DIR/patches
Michal Marek 20589b
ln -s patches/scripts/{refresh_patch,run_oldconfig}.sh $PATCH_DIR/
Michal Marek 4618ac
if $VANILLA; then
Michal Marek 4618ac
	touch "$PATCH_DIR/.is_vanilla"
Michal Marek 4618ac
fi
Michal Marek b0d5a9
if $QUILT; then
Michal Marek b0d5a9
    [ -r $HOME/.quiltrc ] && . $HOME/.quiltrc
Michal Marek b0d5a9
    [ ${QUILT_PATCHES-patches} != patches ] \
Michal Marek b0d5a9
        && ln -s $PWD $PATCH_DIR/${QUILT_PATCHES-patches}
Michal Marek c99740
fi
Michal Marek c99740
echo "[ Tree: $PATCH_DIR ]"
Michal Marek c99740
Jeff Mahoney 15348e
if test "$SP_BUILD_DIR" != "$PATCH_DIR"; then
Jeff Mahoney 15348e
    mkdir -p "$SP_BUILD_DIR"
Jeff Mahoney 15348e
    echo "[ Build Dir: $SP_BUILD_DIR ]"
Jeff Mahoney 15348e
    rm -f "$SP_BUILD_DIR/source"
Jeff Mahoney 15348e
    rm -f "$SP_BUILD_DIR/patches"
Jeff Mahoney 15348e
    ln -sf "$PATCH_DIR" "$SP_BUILD_DIR/source"
Jeff Mahoney 15348e
    ln -sf "source/patches" "$SP_BUILD_DIR/patches"
cb2b93
    cat > $PATCH_DIR/GNUmakefile <
4d7cdd
ifeq (\$(filter tags TAGS cscope gtags, \$(MAKECMDGOALS)),)
cb2b93
ifndef KBUILD_OUTPUT
cb2b93
KBUILD_OUTPUT=$SP_BUILD_DIR
cb2b93
endif
f81154
endif
cb2b93
include Makefile
cb2b93
EOF
Jeff Mahoney 15348e
fi
Jeff Mahoney 15348e
Michal Marek b95a39
# If there are any remaining patches, add them to the series so
Michal Marek b95a39
# they can be fixed up with quilt (or similar).
Jeff Mahoney 3ee854
if [ -n "${PATCHES[*]}" ]; then
Jeff Mahoney 3ee854
    ( IFS=$'\n' ; echo "${PATCHES[*]}" ) >> $PATCH_DIR/series
Michal Marek 3fd959
fi
Michal Marek 7ee246
show_skipped
Michal Marek 3fd959
if test "0$status" -ne 0; then
Michal Marek 3fd959
    exit $status
Michal Marek b95a39
fi
Michal Marek b95a39
Michal Marek e3632b
if test -e supported.conf; then
Michal Marek e3632b
    echo "[ Generating Module.supported ]"
Jeff Mahoney d897f7
    scripts/guards --list --with-guards < supported.conf | \
Jeff Mahoney d897f7
    awk '
Jeff Mahoney d897f7
	    /\+external / {
Jeff Mahoney d897f7
		    print $(NF) " external";
Jeff Mahoney d897f7
		    next;
Jeff Mahoney d897f7
	    }
Jeff Mahoney d897f7
	    /^-/ {
Jeff Mahoney d897f7
		    print $(NF) " no";
Jeff Mahoney d897f7
		    next;
Jeff Mahoney d897f7
	    }
Jeff Mahoney d897f7
	    {
Jeff Mahoney d897f7
		    print $(NF);
Jeff Mahoney d897f7
	    }
Jeff Mahoney d897f7
    ' > "$SP_BUILD_DIR/Module.supported"
Michal Marek e3632b
fi
Jeff Mahoney fe6923
Jeff Mahoney 149391
if test -n "$CONFIG"; then
Jeff Mahoney 149391
    if test -e "config/$CONFIG_ARCH/$CONFIG_FLAVOR"; then
Michal Marek 59eff2
	echo "[ Copying config/$CONFIG_ARCH/$CONFIG_FLAVOR ]"
Michal Marek 838fb1
	if ! grep -q CONFIG_MMU= "config/$CONFIG_ARCH/$CONFIG_FLAVOR"; then
Jeff Mahoney 32677c
	    if [ "$CONFIG_ARCH" = "i386" ]; then
Michal Marek 838fb1
		config_base="config/$CONFIG_ARCH/pae"
Jeff Mahoney 32677c
	    else
Michal Marek 838fb1
		config_base="config/$CONFIG_ARCH/default"
Jeff Mahoney 32677c
	    fi
Michal Marek 838fb1
	    scripts/config-merge "$config_base" \
Jeff Mahoney 32677c
				 "config/$CONFIG_ARCH/$CONFIG_FLAVOR" \
Jeff Mahoney 32677c
				 > "$SP_BUILD_DIR/.config"
Jeff Mahoney 32677c
	else
Jeff Mahoney 32677c
	    cp -a "config/$CONFIG_ARCH/$CONFIG_FLAVOR" "$SP_BUILD_DIR/.config"
Jeff Mahoney 32677c
	fi
Jeff Mahoney 149391
    else
Jeff Mahoney 149391
	echo "[ Config $CONFIG does not exist. ]"
Jeff Mahoney 149391
    fi
Jeff Mahoney eef527
Jeff Mahoney eef527
    if $KABI; then
Jeff Mahoney eef527
	if [ ! -x rpm/modversions ]; then
Jeff Mahoney eef527
	    echo "[ This branch does not support the modversions kABI mechanism. Skipping. ]"
Jeff Mahoney eef527
	elif [ -e "kabi/$CONFIG_ARCH/symtypes-$CONFIG_FLAVOR" ]; then
Jeff Mahoney eef527
	    echo "[ Expanding kABI references for $CONFIG ]"
Jeff Mahoney eef527
	    rpm/modversions --unpack "$SP_BUILD_DIR" < \
Jeff Mahoney eef527
		"kabi/$CONFIG_ARCH/symtypes-$CONFIG_FLAVOR"
Jeff Mahoney eef527
	else
Jeff Mahoney eef527
	    echo "[ No kABI references for $CONFIG ]"
Jeff Mahoney eef527
	fi
Jeff Mahoney eef527
    fi
Michal Kubecek 0d0454
    if test -f ${PATCH_DIR}/scripts/kconfig/Makefile && \
Michal Kubecek 0d0454
       grep -q syncconfig ${PATCH_DIR}/scripts/kconfig/Makefile; then
Michal Kubecek 0d0454
        syncconfig="syncconfig"
Michal Kubecek 0d0454
    else
Michal Kubecek 0d0454
        syncconfig="silentoldconfig"
Michal Kubecek 0d0454
    fi
61e97d
    test "$SP_BUILD_DIR" != "$PATCH_DIR" && \
Michal Kubecek 0d0454
	make -C $PATCH_DIR O=$SP_BUILD_DIR -s $syncconfig
Jeff Mahoney 149391
fi
Jeff Mahoney 149391
Jeff Mahoney d2affe
filter_fingerprints() {
Jeff Mahoney d2affe
    grep 'SHA1 Fingerprint' | sed -e 's/SHA1 Fingerprint.//' | \
Jeff Mahoney d2affe
        tr -d ' :' | tr a-z A-Z
Jeff Mahoney d2affe
}
Jeff Mahoney d2affe
Jeff Mahoney d2affe
cert_fingerprint() {
Jeff Mahoney d2affe
    local cert=$1
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    openssl x509 -fingerprint -noout -in "$cert" | filter_fingerprints
Jeff Mahoney d2affe
}
Jeff Mahoney d2affe
Jeff Mahoney d2affe
cert_fingerprint8() {
Jeff Mahoney d2affe
    local cert=$1
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    cert_fingerprint "$cert" | cut -b 1-8
Jeff Mahoney d2affe
}
Jeff Mahoney d2affe
Jeff Mahoney d2affe
cert_signature_algo() {
Jeff Mahoney d2affe
    local cert=$1
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    # openssl doesn't have a way to just show the algo
Jeff Mahoney d2affe
    openssl x509 -noout -text -in "$cert" | grep 'Signature Algorithm' | \
Jeff Mahoney d2affe
        tr -d ' ' | uniq |  cut -d ':' -f 2
Jeff Mahoney d2affe
}
Jeff Mahoney d2affe
Jeff Mahoney d2affe
get_config_option() {
Jeff Mahoney d2affe
    local config=$1
Jeff Mahoney d2affe
    local option=$2
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    sed -n "/^CONFIG_$option=/s///p" "$config" |tr -d '"' | tail -1
Jeff Mahoney d2affe
}
Jeff Mahoney d2affe
Jeff Mahoney d2affe
set_config_option() {
Jeff Mahoney d2affe
    local config=$1
Jeff Mahoney d2affe
    local option=$2
Jeff Mahoney d2affe
    local value=$3
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    sed -i -e "/^CONFIG_$option=/s;=.*;=$value;" "$config"
Jeff Mahoney d2affe
}
Jeff Mahoney d2affe
Jeff Mahoney d2affe
set_config_option_string() {
Jeff Mahoney d2affe
    local config=$1
Jeff Mahoney d2affe
    local option=$2
Jeff Mahoney d2affe
    local value=$3
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    set_config_option "$config" "$option" "\"$value\""
Jeff Mahoney d2affe
}
Jeff Mahoney d2affe
Jeff Mahoney d2affe
copy_signing_key() {
Jeff Mahoney d2affe
    local cert=$1
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    echo "[ Copying signing key $SIGNING_KEY ]"
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    if ! test -f "$cert"; then
Jeff Mahoney d2affe
        echo "*** ERROR: Signing key $cert does not exist"
Jeff Mahoney d2affe
        return
Jeff Mahoney d2affe
    fi
Jeff Mahoney d2affe
    keyexts=$(openssl x509 -in $cert -ext keyUsage,extendedKeyUsage -noout)
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    if ! echo $keyexts | grep -q "Code Signing"; then
Jeff Mahoney d2affe
        echo "*** WARNING: Signing key must have extendedKeyUsage=codeSigning" \
Jeff Mahoney d2affe
             "to be used to sign kernel for Secure Boot" >&2
Jeff Mahoney d2affe
    fi
Jeff Mahoney d2affe
    if ! echo $keyexts | grep -q "Digital Signature"; then
Jeff Mahoney d2affe
        echo "*** WARNING: Signing key must have keyUsage=digitalSignature" \
Jeff Mahoney d2affe
             "to be used to sign modules" >&2
Jeff Mahoney d2affe
    fi
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    mkdir -p "$SP_BUILD_DIR/certs"
Jeff Mahoney d2affe
    certname="$(cert_fingerprint8 "$cert").pem"
Jeff Mahoney d2affe
    cp "$cert" "$SP_BUILD_DIR/certs/$certname"
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    if test -z "$CONFIG"; then
Jeff Mahoney d2affe
        echo "*** WARNING: signing key copied to certs/$certname but" \
Jeff Mahoney d2affe
             "no config available to enable"
Jeff Mahoney d2affe
        return
Jeff Mahoney d2affe
    fi
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    local config="$SP_BUILD_DIR/.config"
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    # Check for algo compatibility
Jeff Mahoney d2affe
    config_algo="$(get_config_option $config MODULE_SIG_HASH)"
Jeff Mahoney d2affe
    if test -z "$config_algo"; then
Jeff Mahoney d2affe
        echo "*** WARNING: Module signing is disabled in active config"
Jeff Mahoney d2affe
        return
Jeff Mahoney d2affe
    fi
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    cert_algo=$(cert_signature_algo $cert)
Jeff Mahoney d2affe
    cert_algo=${cert_algo%%WithRSAEncryption}
Jeff Mahoney d2affe
    if test "$config_algo" != "$cert_algo"; then
Jeff Mahoney d2affe
        echo "*** WARNING: Signing key uses hash algo '$cert_algo' but" \
Jeff Mahoney d2affe
             " kernel config uses '$config_algo'"
Jeff Mahoney d2affe
    fi
Jeff Mahoney d2affe
Jeff Mahoney d2affe
    set_config_option_string $config MODULE_SIG_KEY "certs/$certname"
Jeff Mahoney d2affe
}
Jeff Mahoney d2affe
Jeff Mahoney d2affe
if test -n "$SIGNING_KEY"; then
Jeff Mahoney d2affe
    copy_signing_key $SIGNING_KEY
Jeff Mahoney d2affe
fi
Jeff Mahoney d2affe
Michal Hocko bd52f3
# Some archs we use for the config do not exist or have a different name in the
Michal Hocko bd52f3
# kernl source tree
Michal Hocko bd52f3
case $CONFIG_ARCH in
Michal Hocko bd52f3
	s390x) TAGS_ARCH=s390 ;;
Michal Hocko bd52f3
	ppc64|ppc64le) TAGS_ARCH=powerpc ;;
Michal Hocko bd52f3
	*) TAGS_ARCH=$CONFIG_ARCH ;;
Michal Hocko bd52f3
esac
Jeff Mahoney f7a93d
if $CTAGS; then
Jeff Mahoney f7a93d
    if ctags --version > /dev/null; then
Jeff Mahoney f7a93d
	echo "[ Generating ctags (this may take a while)]"
Michal Hocko bd52f3
	ARCH=$TAGS_ARCH make -s --no-print-directory -C "$PATCH_DIR" O="$SP_BUILD_DIR" tags
Jeff Mahoney f7a93d
    else
Jeff Mahoney f7a93d
	echo "[ Could not generate ctags: ctags not found ]"
Jeff Mahoney 3d761a
    fi
Jeff Mahoney 3d761a
fi
Jeff Mahoney 3d761a
Jeff Mahoney 3d761a
if $CSCOPE; then
Jeff Mahoney 3d761a
    if cscope -V 2> /dev/null; then
Jeff Mahoney 3d761a
	echo "[ Generating cscope db (this may take a while)]"
Michal Hocko bd52f3
	ARCH=$TAGS_ARCH make -s --no-print-directory -C "$PATCH_DIR" O="$SP_BUILD_DIR" cscope
Jeff Mahoney 3d761a
    else
Jeff Mahoney 3d761a
	echo "[ Could not generate cscope db: cscope not found ]"
Jeff Mahoney f7a93d
    fi
Jeff Mahoney f7a93d
fi
Johannes Thumshirn 798c4e
Johannes Thumshirn 798c4e
if $ETAGS; then
Johannes Thumshirn 798c4e
    if etags --version > /dev/null; then
Johannes Thumshirn 798c4e
	echo "[ Generating etags (this may take a while)]"
Johannes Thumshirn 798c4e
	ARCH=$TAGS_ARCH make -s --no-print-directory -C "$PATCH_DIR" O="$SP_BUILD_DIR" TAGS
Johannes Thumshirn 798c4e
    else
Johannes Thumshirn 798c4e
	echo "[ Could not generate etags: etags not found ]"
Johannes Thumshirn 798c4e
    fi
Johannes Thumshirn 798c4e
fi