Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
build_kernel.sh 5.94 KiB
Newer Older
Robert Nelson's avatar
Robert Nelson committed
#!/bin/sh -e
# Copyright (c) 2009-2013 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.

DIR=$PWD

mkdir -p ${DIR}/deploy/

Robert Nelson's avatar
Robert Nelson committed
patch_kernel () {
	cd ${DIR}/KERNEL
Robert Nelson's avatar
Robert Nelson committed
	export DIR GIT_OPTS
Robert Nelson's avatar
Robert Nelson committed
	/bin/sh -e ${DIR}/patch.sh || { git add . ; exit 1 ; }
	if [ ! "${RUN_BISECT}" ] ; then
		git add .
		git commit --allow-empty -a -m "${KERNEL_TAG}-${BUILD} patchset"
	fi
	cd ${DIR}/
Robert Nelson's avatar
Robert Nelson committed
copy_defconfig () {
	cd ${DIR}/KERNEL/
	make ARCH=arm CROSS_COMPILE=${CC} distclean
	make ARCH=arm CROSS_COMPILE=${CC} ${config}
	cp -v .config ${DIR}/patches/ref_${config}
	cp -v ${DIR}/patches/defconfig .config
	cd ${DIR}/
Robert Nelson's avatar
Robert Nelson committed
make_menuconfig () {
	cd ${DIR}/KERNEL/
	make ARCH=arm CROSS_COMPILE=${CC} menuconfig
	cp -v .config ${DIR}/patches/defconfig
	cd ${DIR}/
Robert Nelson's avatar
Robert Nelson committed
make_kernel () {
	echo "-----------------------------"
Robert Nelson's avatar
Robert Nelson committed
	echo "make -j${CORES} ARCH=arm LOCALVERSION=-${BUILD} CROSS_COMPILE=\"${CC}\" zImage modules"
	echo "-----------------------------"
Robert Nelson's avatar
Robert Nelson committed
	make -j${CORES} ARCH=arm LOCALVERSION=-${BUILD} CROSS_COMPILE="${CC}" zImage modules
Robert Nelson's avatar
Robert Nelson committed
	unset DTBS
Robert Nelson's avatar
Robert Nelson committed
	cat ${DIR}/KERNEL/arch/arm/Makefile | grep "dtbs:" >/dev/null 2>&1 && DTBS=1
	if [ "x${DTBS}" != "x" ] ; then
Robert Nelson's avatar
Robert Nelson committed
		echo "-----------------------------"
Robert Nelson's avatar
Robert Nelson committed
		echo "make -j${CORES} ARCH=arm LOCALVERSION=-${BUILD} CROSS_COMPILE=\"${CC}\" dtbs"
Robert Nelson's avatar
Robert Nelson committed
		echo "-----------------------------"
Robert Nelson's avatar
Robert Nelson committed
		make -j${CORES} ARCH=arm LOCALVERSION=-${BUILD} CROSS_COMPILE="${CC}" dtbs
		ls arch/arm/boot/* | grep dtb >/dev/null 2>&1 || unset DTBS
	KERNEL_UTS=$(cat ${DIR}/KERNEL/include/generated/utsrelease.h | awk '{print $3}' | sed 's/\"//g' )

	deployfile=".zImage"
	if [ -f "${DIR}/deploy/${KERNEL_UTS}${deployfile}" ] ; then
		rm -rf "${DIR}/deploy/${KERNEL_UTS}${deployfile}" || true
		rm -rf "${DIR}/deploy/${KERNEL_UTS}.config" || true
	fi

	if [ -f ./arch/arm/boot/zImage ] ; then
		cp -v arch/arm/boot/zImage "${DIR}/deploy/${KERNEL_UTS}.zImage"
		cp -v .config "${DIR}/deploy/${KERNEL_UTS}.config"

	if [ ! -f "${DIR}/deploy/${KERNEL_UTS}${deployfile}" ] ; then
		export ERROR_MSG="File Generation Failure: [${KERNEL_UTS}${deployfile}]"
		/bin/sh -e "${DIR}/scripts/error.sh" && { exit 1 ; }
	else
		ls -lh "${DIR}/deploy/${KERNEL_UTS}${deployfile}"
	fi
Robert Nelson's avatar
Robert Nelson committed
make_pkg () {
	cd ${DIR}/KERNEL/

Robert Nelson's avatar
Robert Nelson committed
	deployfile="-${pkg}.tar.gz"
	if [ -f "${DIR}/deploy/${KERNEL_UTS}${deployfile}" ] ; then
		rm -rf "${DIR}/deploy/${KERNEL_UTS}${deployfile}" || true
	fi

Robert Nelson's avatar
Robert Nelson committed
	if [ -d ${DIR}/deploy/tmp ] ; then
		rm -rf ${DIR}/deploy/tmp || true
	fi
	mkdir -p ${DIR}/deploy/tmp

Robert Nelson's avatar
Robert Nelson committed
	echo "-----------------------------"
	echo "Building ${pkg} archive..."

Robert Nelson's avatar
Robert Nelson committed
	case "${pkg}" in
	modules)
Robert Nelson's avatar
Robert Nelson committed
		make -s ARCH=arm CROSS_COMPILE=${CC} modules_install INSTALL_MOD_PATH=${DIR}/deploy/tmp
Robert Nelson's avatar
Robert Nelson committed
		;;
	firmware)
Robert Nelson's avatar
Robert Nelson committed
		make -s ARCH=arm CROSS_COMPILE=${CC} firmware_install INSTALL_FW_PATH=${DIR}/deploy/tmp
Robert Nelson's avatar
Robert Nelson committed
		;;
	dtbs)
		find ./arch/arm/boot/ -iname "*.dtb" -exec cp -v '{}' ${DIR}/deploy/tmp/ \;
		;;
	esac
Robert Nelson's avatar
Robert Nelson committed
	echo "Compressing ${KERNEL_UTS}${deployfile}..."
Robert Nelson's avatar
Robert Nelson committed
	cd ${DIR}/deploy/tmp
	tar czf ../${KERNEL_UTS}${deployfile} *
	cd ${DIR}/
Robert Nelson's avatar
Robert Nelson committed
	rm -rf ${DIR}/deploy/tmp || true

	if [ ! -f "${DIR}/deploy/${KERNEL_UTS}${deployfile}" ] ; then
		export ERROR_MSG="File Generation Failure: [${KERNEL_UTS}${deployfile}]"
		/bin/sh -e "${DIR}/scripts/error.sh" && { exit 1 ; }
	else
		ls -lh "${DIR}/deploy/${KERNEL_UTS}${deployfile}"
	fi
Robert Nelson's avatar
Robert Nelson committed
make_modules_pkg () {
	pkg="modules"
	make_pkg
}
Robert Nelson's avatar
Robert Nelson committed
make_firmware_pkg () {
	pkg="firmware"
	make_pkg
Robert Nelson's avatar
Robert Nelson committed
make_dtbs_pkg () {
Robert Nelson's avatar
Robert Nelson committed
	pkg="dtbs"
	make_pkg
Robert Nelson's avatar
Robert Nelson committed
/bin/sh -e ${DIR}/tools/host_det.sh || { exit 1 ; }
if [ ! -f ${DIR}/system.sh ] ; then
	cp ${DIR}/system.sh.sample ${DIR}/system.sh
Robert Nelson's avatar
Robert Nelson committed
else
	#fixes for bash -> sh conversion...
	sed -i 's/bash/sh/g' ${DIR}/system.sh
	sed -i 's/==/=/g' ${DIR}/system.sh
Robert Nelson's avatar
Robert Nelson committed
if [ -f "${DIR}/branches.list" ] ; then
	echo "-----------------------------"
	echo "Please checkout one of the active branches:"
	echo "-----------------------------"
	cat ${DIR}/branches.list | grep -v INACTIVE
	echo "-----------------------------"
	exit
fi
Robert Nelson's avatar
Robert Nelson committed
if [ -f "${DIR}/branch.expired" ] ; then
Robert Nelson's avatar
Robert Nelson committed
	echo "-----------------------------"
	echo "Support for this branch has expired."
	unset response
	echo -n "Do you wish to bypass this warning and support your self: (y/n)? "
	read response
	if [ "x${response}" != "xy" ] ; then
		exit
	fi
	echo "-----------------------------"
fi
Robert Nelson's avatar
Robert Nelson committed

unset CC
unset LINUX_GIT
. ${DIR}/system.sh
/bin/sh -e "${DIR}/scripts/gcc.sh" || { exit 1 ; }
. ${DIR}/.CC
echo "debug: CC=${CC}"

. ${DIR}/version.sh
export LINUX_GIT

#unset FULL_REBUILD
FULL_REBUILD=1
if [ "${FULL_REBUILD}" ] ; then
Robert Nelson's avatar
Robert Nelson committed
	/bin/sh -e "${DIR}/scripts/git.sh" || { exit 1 ; }
	if [ "${RUN_BISECT}" ] ; then
Robert Nelson's avatar
Robert Nelson committed
		/bin/sh -e "${DIR}/scripts/bisect.sh" || { exit 1 ; }
	patch_kernel
	copy_defconfig
fi
if [ ! ${AUTO_BUILD} ] ; then
	make_menuconfig
fi
make_kernel
make_modules_pkg
Robert Nelson's avatar
Robert Nelson committed
make_firmware_pkg
if [ "x${DTBS}" != "x" ] ; then
	make_dtbs_pkg
Robert Nelson's avatar
Robert Nelson committed
fi
echo "-----------------------------"
echo "Script Complete"
echo "eewiki.net: [user@localhost:~$ export kernel_version=${KERNEL_UTS}]"
Robert Nelson's avatar
Robert Nelson committed
echo "-----------------------------"