Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
patch.sh 11.8 KiB
Newer Older
Robert Nelson's avatar
Robert Nelson committed
# Copyright (c) 2009-2019 Robert Nelson <robertcnelson@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Split out, so build_kernel.sh and build_deb.sh can share..

Robert Nelson's avatar
Robert Nelson committed
shopt -s nullglob

if [ -f ${DIR}/system.sh ] ; then
Robert Nelson's avatar
Robert Nelson committed
	. ${DIR}/system.sh
git_bin=$(which git)
#git hard requirements:
#git: --no-edit
if [ "${RUN_BISECT}" ] ; then
echo "Starting patch.sh"

Robert Nelson's avatar
Robert Nelson committed
git_add () {
	${git_bin} add .
	${git_bin} commit -a -m 'testing patchset'
Robert Nelson's avatar
Robert Nelson committed
start_cleanup () {
Robert Nelson's avatar
Robert Nelson committed
cleanup () {
Robert Nelson's avatar
Robert Nelson committed
	if [ "${number}" ] ; then
			${git_bin} format-patch -${number} -o ${DIR}/patches/
Robert Nelson's avatar
Robert Nelson committed
			if [ ! -d ${DIR}/patches/${wdir}/ ] ; then
				mkdir -p ${DIR}/patches/${wdir}/
			fi
			${git_bin} format-patch -${number} -o ${DIR}/patches/${wdir}/
Robert Nelson's avatar
Robert Nelson committed
dir () {
	wdir="$1"
	if [ -d "${DIR}/patches/$wdir" ]; then
		echo "dir: $wdir"

		if [ "x${regenerate}" = "xenable" ] ; then
			start_cleanup
		fi

		number=
		for p in "${DIR}/patches/$wdir/"*.patch; do
			${git} "$p"
			number=$(( $number + 1 ))
		done

		if [ "x${regenerate}" = "xenable" ] ; then
			cleanup
		fi
	fi
	unset wdir
}

Robert Nelson's avatar
Robert Nelson committed
cherrypick () {
	if [ ! -d ../patches/${cherrypick_dir} ] ; then
		mkdir -p ../patches/${cherrypick_dir}
	${git_bin} format-patch -1 ${SHA} --start-number ${num} -o ../patches/${cherrypick_dir}
external_git () {
	git_tag=""
	echo "pulling: ${git_tag}"
	${git_bin} pull --no-edit ${git_patchset} ${git_tag}
can_isotp () {
	#regenerate="enable"
	if [ "x${regenerate}" = "xenable" ] ; then
		cd ../
		if [ ! -d ./can-isotp ] ; then
			${git_bin} clone https://github.com/hartkopp/can-isotp --depth=1
		else
			rm -rf ./can-isotp || true
			${git_bin} clone https://github.com/hartkopp/can-isotp --depth=1
		fi

		cd ./KERNEL/

		cp -v ../can-isotp/include/uapi/linux/can/isotp.h  include/uapi/linux/can/
		cp -v ../can-isotp/net/can/isotp.c net/can/

		${git_bin} add .
		${git_bin} commit -a -m 'merge: can-isotp: https://github.com/hartkopp/can-isotp' -m "https://github.com/hartkopp/can-isotp/commit/${isotp_hash}" -s
		${git_bin} format-patch -1 -o ../patches/can_isotp/
		echo "CAN-ISOTP: https://github.com/hartkopp/can-isotp/commit/${isotp_hash}" > ../patches/git/CAN-ISOTP

		rm -rf ../can-isotp/ || true

		${git_bin} reset --hard HEAD~1

		start_cleanup

		${git} "${DIR}/patches/can_isotp/0001-merge-can-isotp-https-github.com-hartkopp-can-isotp.patch"

		wdir="can_isotp"
		number=1
		cleanup

		exit 2
	fi
	dir 'can_isotp'
}

rt_cleanup () {
	echo "rt: needs fixup"
	exit 2
}

rt () {
	rt_patch="${KERNEL_REL}${kernel_rt}"
Robert Nelson's avatar
Robert Nelson committed
	#${git_bin} revert --no-edit xyz
	#regenerate="enable"
	if [ "x${regenerate}" = "xenable" ] ; then
		wget -c https://www.kernel.org/pub/linux/kernel/projects/rt/${KERNEL_REL}/patch-${rt_patch}.patch.xz
		xzcat patch-${rt_patch}.patch.xz | patch -p1 || rt_cleanup
		rm -f patch-${rt_patch}.patch.xz
		rm -f localversion-rt
		${git_bin} commit -a -m 'merge: CONFIG_PREEMPT_RT Patch Set' -m "patch-${rt_patch}.patch.xz" -s
		${git_bin} format-patch -1 -o ../patches/rt/
		echo "RT: patch-${rt_patch}.patch.xz" > ../patches/git/RT
Robert Nelson's avatar
Robert Nelson committed
	dir 'rt'
Robert Nelson's avatar
Robert Nelson committed
wireguard_fail () {
	echo "WireGuard failed"
	exit 2
}

wireguard () {
	#regenerate="enable"
	if [ "x${regenerate}" = "xenable" ] ; then
		cd ../
		if [ ! -d ./WireGuard ] ; then
Robert Nelson's avatar
Robert Nelson committed
			${git_bin} clone https://git.zx2c4.com/WireGuard --depth=1
Robert Nelson's avatar
Robert Nelson committed
		else
			rm -rf ./WireGuard || true
Robert Nelson's avatar
Robert Nelson committed
			${git_bin} clone https://git.zx2c4.com/WireGuard --depth=1
Robert Nelson's avatar
Robert Nelson committed
		fi
Robert Nelson's avatar
Robert Nelson committed

		#cd ./WireGuard/
		#${git_bin}  revert --no-edit xyz
		#cd ../

Robert Nelson's avatar
Robert Nelson committed
		cd ./KERNEL/

		../WireGuard/contrib/kernel-tree/create-patch.sh | patch -p1 || wireguard_fail

		${git_bin} add .
		${git_bin} commit -a -m 'merge: WireGuard' -m "https://git.zx2c4.com/WireGuard/commit/${wireguard_hash}" -s
Robert Nelson's avatar
Robert Nelson committed
		${git_bin} format-patch -1 -o ../patches/WireGuard/
		echo "WIREGUARD: https://git.zx2c4.com/WireGuard/commit/${wireguard_hash}" > ../patches/git/WIREGUARD
Robert Nelson's avatar
Robert Nelson committed

		rm -rf ../WireGuard/ || true

Robert Nelson's avatar
Robert Nelson committed
		${git_bin} reset --hard HEAD^
Robert Nelson's avatar
Robert Nelson committed

		start_cleanup

		${git} "${DIR}/patches/WireGuard/0001-merge-WireGuard.patch"

		wdir="WireGuard"
		number=1
		cleanup
	fi

Robert Nelson's avatar
Robert Nelson committed
	dir 'WireGuard'
Robert Nelson's avatar
Robert Nelson committed
ti_pm_firmware () {
Robert Nelson's avatar
Robert Nelson committed
	#http://git.ti.com/gitweb/?p=processor-firmware/ti-amx3-cm3-pm-firmware.git;a=shortlog;h=refs/heads/ti-v4.1.y-next
Robert Nelson's avatar
Robert Nelson committed
	#regenerate="enable"
	if [ "x${regenerate}" = "xenable" ] ; then

		cd ../
		if [ ! -d ./ti-amx3-cm3-pm-firmware ] ; then
			${git_bin} clone -b ti-v4.1.y-next git://git.ti.com/processor-firmware/ti-amx3-cm3-pm-firmware.git --depth=1
			cd ./ti-amx3-cm3-pm-firmware
				ti_amx3_cm3_hash=$(git rev-parse HEAD)
			cd -
Robert Nelson's avatar
Robert Nelson committed
		else
			rm -rf ./ti-amx3-cm3-pm-firmware || true
			${git_bin} clone -b ti-v4.1.y-next git://git.ti.com/processor-firmware/ti-amx3-cm3-pm-firmware.git --depth=1
			cd ./ti-amx3-cm3-pm-firmware
				ti_amx3_cm3_hash=$(git rev-parse HEAD)
			cd -
Robert Nelson's avatar
Robert Nelson committed
		fi
		cd ./KERNEL/

		mkdir -p ./firmware/ || true
Robert Nelson's avatar
Robert Nelson committed
		cp -v ../ti-amx3-cm3-pm-firmware/bin/am* ./firmware/

		${git_bin} add -f ./firmware/am*
		${git_bin} commit -a -m 'Add AM335x CM3 Power Managment Firmware' -m "http://git.ti.com/gitweb/?p=processor-firmware/ti-amx3-cm3-pm-firmware.git;a=commit;h=${ti_amx3_cm3_hash}" -s
Robert Nelson's avatar
Robert Nelson committed
		${git_bin} format-patch -1 -o ../patches/drivers/ti/firmware/
		echo "TI_AMX3_CM3: http://git.ti.com/gitweb/?p=processor-firmware/ti-amx3-cm3-pm-firmware.git;a=commit;h=${ti_amx3_cm3_hash}" > ../patches/git/TI_AMX3_CM3
Robert Nelson's avatar
Robert Nelson committed

		rm -rf ../ti-amx3-cm3-pm-firmware/ || true

		${git_bin} reset --hard HEAD^

		start_cleanup

		${git} "${DIR}/patches/drivers/ti/firmware/0001-Add-AM335x-CM3-Power-Managment-Firmware.patch"
Robert Nelson's avatar
Robert Nelson committed

		wdir="drivers/ti/firmware"
		number=1
		cleanup
	fi

Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/ti/firmware'
}
dtb_makefile_append_omap4 () {
	sed -i -e 's:omap4-panda.dtb \\:omap4-panda.dtb \\\n\t'$device' \\:g' arch/arm/boot/dts/Makefile
}

dtb_makefile_append () {
	sed -i -e 's:am335x-boneblack.dtb \\:am335x-boneblack.dtb \\\n\t'$device' \\:g' arch/arm/boot/dts/Makefile
}

beagleboard_dtbs () {
Robert Nelson's avatar
Robert Nelson committed
	#regenerate="enable"
	if [ "x${regenerate}" = "xenable" ] ; then
		cd ../
		if [ ! -d ./BeagleBoard-DeviceTrees ] ; then
			${git_bin} clone -b ${bbdtbs} https://github.com/beagleboard/BeagleBoard-DeviceTrees --depth=1
			cd ./BeagleBoard-DeviceTrees
				bbdtbs_hash=$(git rev-parse HEAD)
			cd -
Robert Nelson's avatar
Robert Nelson committed
		else
			rm -rf ./BeagleBoard-DeviceTrees || true
			${git_bin} clone -b ${bbdtbs} https://github.com/beagleboard/BeagleBoard-DeviceTrees --depth=1
			cd ./BeagleBoard-DeviceTrees
				bbdtbs_hash=$(git rev-parse HEAD)
			cd -
Robert Nelson's avatar
Robert Nelson committed
		fi
		cd ./KERNEL/

		cp -vr ../BeagleBoard-DeviceTrees/src/arm/* arch/arm/boot/dts/
		cp -vr ../BeagleBoard-DeviceTrees/include/dt-bindings/* ./include/dt-bindings/

		device="omap4-panda-es-b3.dtb" ; dtb_makefile_append_omap4
Robert Nelson's avatar
Robert Nelson committed

		device="am335x-abbbi.dtb" ; dtb_makefile_append
		device="am335x-bonegreen-gateway.dtb" ; dtb_makefile_append
Robert Nelson's avatar
Robert Nelson committed

		device="am335x-boneblack-uboot.dtb" ; dtb_makefile_append
Robert Nelson's avatar
Robert Nelson committed

		device="am335x-bone-uboot-univ.dtb" ; dtb_makefile_append
		device="am335x-boneblack-uboot-univ.dtb" ; dtb_makefile_append
		device="am335x-bonegreen-wireless-uboot-univ.dtb" ; dtb_makefile_append
Robert Nelson's avatar
Robert Nelson committed

		${git_bin} add -f arch/arm/boot/dts/
		${git_bin} add -f include/dt-bindings/
		${git_bin} commit -a -m "Add BeagleBoard.org DTBS: $bbdtbs" -m "https://github.com/beagleboard/BeagleBoard-DeviceTrees/tree/${bbdtbs}" -m "https://github.com/beagleboard/BeagleBoard-DeviceTrees/commit/${bbdtbs_hash}" -s
Robert Nelson's avatar
Robert Nelson committed
		${git_bin} format-patch -1 -o ../patches/soc/ti/beagleboard_dtbs/
		echo "BBDTBS: https://github.com/beagleboard/BeagleBoard-DeviceTrees/commit/${bbdtbs_hash}" > ../patches/git/BBDTBS
Robert Nelson's avatar
Robert Nelson committed

		rm -rf ../BeagleBoard-DeviceTrees/ || true

		${git_bin} reset --hard HEAD^

		start_cleanup

		${git} "${DIR}/patches/soc/ti/beagleboard_dtbs/0001-Add-BeagleBoard.org-DTBS-$bbdtbs.patch"

		wdir="soc/ti/beagleboard_dtbs"
		number=1
		cleanup
	fi

	dir 'soc/ti/beagleboard_dtbs'
Robert Nelson's avatar
Robert Nelson committed
}

local_patch () {
	echo "dir: dir"
	${git} "${DIR}/patches/dir/0001-patch.patch"
}

Robert Nelson's avatar
Robert Nelson committed
#rt
Robert Nelson's avatar
Robert Nelson committed
wireguard
Robert Nelson's avatar
Robert Nelson committed
ti_pm_firmware
Robert Nelson's avatar
Robert Nelson committed
beagleboard_dtbs
pre_backports () {
	echo "dir: backports/${subsystem}"

	cd ~/linux-src/
	${git_bin} pull --no-edit https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git master
	${git_bin} pull --no-edit https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git master --tags
	${git_bin} pull --no-edit https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master --tags
	if [ ! "x${backport_tag}" = "x" ] ; then
		${git_bin} checkout ${backport_tag} -b tmp
	fi
	cd -
}

post_backports () {
	if [ ! "x${backport_tag}" = "x" ] ; then
		cd ~/linux-src/
		${git_bin} checkout master -f ; ${git_bin} branch -D tmp
		cd -
	fi

	${git_bin} add .
	${git_bin} commit -a -m "backports: ${subsystem}: from: linux.git" -m "Reference: ${backport_tag}" -s
	if [ ! -d ../patches/backports/${subsystem}/ ] ; then
		mkdir -p ../patches/backports/${subsystem}/
	fi
	${git_bin} format-patch -1 -o ../patches/backports/${subsystem}/
}

patch_backports (){
	echo "dir: backports/${subsystem}"
	${git} "${DIR}/patches/backports/${subsystem}/0001-backports-${subsystem}-from-linux.git.patch"
}

backports () {
	#regenerate="enable"
	if [ "x${regenerate}" = "xenable" ] ; then
		pre_backports

		mkdir -p ./x/
		cp -v ~/linux-src/x/* ./x/
Robert Nelson's avatar
Robert Nelson committed
reverts () {
	echo "dir: reverts"
	#regenerate="enable"
	if [ "x${regenerate}" = "xenable" ] ; then
		start_cleanup
	fi

Robert Nelson's avatar
Robert Nelson committed
	## notes
	##git revert --no-edit xyz -s
Robert Nelson's avatar
Robert Nelson committed
	#${git} "${DIR}/patches/reverts/0001-Revert-xyz.patch"
Robert Nelson's avatar
Robert Nelson committed
	if [ "x${regenerate}" = "xenable" ] ; then
Robert Nelson's avatar
Robert Nelson committed
		wdir="reverts"
Robert Nelson's avatar
Robert Nelson committed
		cleanup
	fi
}

drivers () {
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/ar1021_i2c'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/pwm'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/spi'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/tps65217'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/ti/overlays'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/ti/cpsw'
Robert Nelson's avatar
Robert Nelson committed
#	dir 'drivers/ti/eqep'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/ti/rpmsg'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/ti/serial'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/ti/tsc'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/ti/gpio'
Robert Nelson's avatar
Robert Nelson committed
	dir 'drivers/greybus'
Robert Nelson's avatar
Robert Nelson committed
}
Robert Nelson's avatar
Robert Nelson committed
soc () {
Robert Nelson's avatar
Robert Nelson committed
#	dir 'soc/imx/udoo'
#	dir 'soc/imx/wandboard'
Robert Nelson's avatar
Robert Nelson committed
#	dir 'soc/imx/imx7'
Robert Nelson's avatar
Robert Nelson committed
	dir 'soc/ti/panda'
Robert Nelson's avatar
Robert Nelson committed
#reverts
Robert Nelson's avatar
Robert Nelson committed
	#regenerate="enable"
	if [ "x${regenerate}" = "xenable" ] ; then
		cp -v "${DIR}/3rdparty/packaging/builddeb" "${DIR}/KERNEL/scripts/package"
		${git_bin} commit -a -m 'packaging: sync builddeb changes' -s
		${git_bin} format-patch -1 -o "${DIR}/patches/packaging"
	else
		${git} "${DIR}/patches/packaging/0001-packaging-sync-builddeb-changes.patch"
	fi
Robert Nelson's avatar
Robert Nelson committed
packaging