#!/bin/bash COLOR_RED_BG=$(tput setab 1) COLOR_RED_BOLD=$(tput bold)$(tput setaf 1) COLOR_RESET=$(tput sgr0) MOD_DIR="usr/tmp_mod" MOD_IMG="usr/modules.img" MOD_SIZE=20 NCPUS=`cat /proc/cpuinfo | grep processor | wc -l` NCPUS=$(($NCPUS * 2)) BUILD_ROOT=$PWD KERNEL_PATH=`basename ${BUILD_ROOT}` if [ $# == 0 ]; then echo "Usage : $0 [rt] [bootimg]" echo " architecture : arm or arm64" echo " e.g) $0 arm" echo " e.g) $0 arm64 rt" echo " e.g) $0 arm64 bootimg" echo " e.g) $0 arm rt bootimg" exit fi # Check this system has ccache check_ccache() { type ccache if [ "$?" -eq "0" ]; then CCACHE=ccache fi } check_sudo() { [ -e /usr/bin/make_ext4fs ] && USE_MAKE_EXT4FS=1 if [ "$USE_MAKE_EXT4FS" != "1" ] || [ "$IS_BOOTIMG" = "1" ]; then sudo ls > /dev/null fi } function mk_bootimg() { TMP_PATH=./tmp_bootimg TMP_UBOOT_PATH=./tmp_uboot BOOT_PATH="rpi4/boot" USER_ID=`id -u` GROUP_ID=`id -g` rm -f boot.img rm -rf ${TMP_PATH} mkdir ${TMP_PATH} # Create boot.img mkfs.vfat -F 16 -C -n BOOT boot.img 65536 sudo mount -o loop,uid=$USER_ID,gid=$GROUP_ID,showexec boot.img ${TMP_PATH} cp -a $BOOT_PATH/LICENCE.broadcom ${TMP_PATH} cp -a $BOOT_PATH/start*.elf ${TMP_PATH} cp -a $BOOT_PATH/fixup*.dat ${TMP_PATH} if [ "$ARM_ARCH" = "arm64" ]; then echo "Create 64bit boot image" cp -a $BOOT_PATH/config_64bit.txt ${TMP_PATH}/config.txt cp -a arch/arm64/boot/Image ${TMP_PATH} cp -a arch/arm64/boot/dts/broadcom/bcm*.dtb ${TMP_PATH} else echo "Create 32bit boot image" cp -a $BOOT_PATH/config.txt ${TMP_PATH} cp -a arch/arm/boot/zImage ${TMP_PATH} cp -a arch/arm/boot/dts/broadcom/bcm*.dtb ${TMP_PATH} fi mkdir -p ${TMP_PATH}/overlays cp -a arch/arm/boot/dts/overlays/*.dtb* ${TMP_PATH}/overlays # install u-boot files extracted from u-boot-rpi4 rpm package in download.tizen.org. rm -rf ${TMP_UBOOT_PATH} mkdir -p ${TMP_UBOOT_PATH} pushd ${TMP_UBOOT_PATH} if [ "$ARM_ARCH" = "arm64" ]; then REPO_URL=http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Unified/latest/repos/standard/packages/aarch64/ else REPO_URL=http://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Unified/latest/repos/standard/packages/armv7l/ BITS=-32b fi rm -f index.html* wget ${REPO_URL} UBOOT=`awk -F\" '{ print $2 }' index.html | grep u-boot-rpi4${BITS}` wget ${REPO_URL}${UBOOT} unrpm ${UBOOT} popd cp -a ${TMP_UBOOT_PATH}/boot/* ${TMP_PATH} sync sudo umount ${TMP_PATH} rm -rf ${TMP_UBOOT_PATH} rm -rf ${TMP_PATH} } function mk_tizen_modules() { if [ -e ${BUILD_ROOT}/../linux-tizen-modules-source ]; then pushd ${BUILD_ROOT}/../linux-tizen-modules-source ln -s ${PWD}/include kernel export LOGGER_MAIN_BUFFER_SIZE=256 export LOGGER_EVENTS_BUFFER_SIZE=256 export LOGGER_RADIO_BUFFER_SIZE=256 export LOGGER_SYSTEM_BUFFER_SIZE=256 export BUILD_dm_bow=m export BUILD_inform_reboot=m export BUILD_kdbus=m export BUILD_logger=m export BUILD_proc_tsm=m export BUILD_zlogger=m ARCH="${ARM_ARCH}" CROSS_COMPILE="${CROSS_COMPILER}" make -C kernel KERNELDIR=${BUILD_ROOT} rm -f kernel/include ARCH="${ARM_ARCH}" CROSS_COMPILE="${CROSS_COMPILER}" make -C kernel modules_install KERNELDIR=${BUILD_ROOT} INSTALL_MOD_PATH=../${KERNEL_PATH}/${MOD_DIR} INSTALL_MOD_STRIP=1 INSTALL_MOD_DIR=extra popd if [ -e ${BUILD_ROOT}/../linux-tizen-modules ]; then mkdir -p ${MOD_DIR}/lib/modules/modprobe.d mkdir -p ${MOD_DIR}/lib/modules/modules-load.d cp ${BUILD_ROOT}/../linux-tizen-modules/conf/tizen-modprobe-rpi4.conf ${MOD_DIR}/lib/modules/modprobe.d cp ${BUILD_ROOT}/../linux-tizen-modules/conf/tizen-modules-rpi4.conf ${MOD_DIR}/lib/modules/modules-load.d fi else echo "linux-tizen-modules-source/linux-tizen-modules are not cloned in parent path, so skip building linux-tizen-modules." echo "To build linux-tizen-modules, please use below command:" echo " git clone git://git.tizen.org/platform/kernel/linux-tizen-modules-source -b tizen ../linux-tizen-modules-source" echo " git clone git://git.tizen.org/platform/kernel/linux-tizen-modules -b tizen ../linux-tizen-modules" fi } function mk_modules() { make ARCH=${ARM_ARCH} CROSS_COMPILE="$CROSS_COMPILER" modules_prepare make ARCH=${ARM_ARCH} CROSS_COMPILE="$CROSS_COMPILER" modules -j ${NCPUS} if [ "$?" != "0" ]; then echo "Failed to make modules" exit 1 fi [ -d ${MOD_DIR} ] || mkdir ${MOD_DIR} make ARCH=${ARM_ARCH} CROSS_COMPILE="$CROSS_COMPILER" modules_install INSTALL_MOD_PATH=${MOD_DIR} INSTALL_MOD_STRIP=1 # build and install linux-tizen-modules if cloned in parent path mk_tizen_modules if [ "$USE_MAKE_EXT4FS" == "1" ]; then /usr/bin/make_ext4fs -b 4096 -L modules -l ${MOD_SIZE}M $MOD_IMG ${MOD_DIR}/lib/modules/ else dd if=/dev/zero of=${MOD_IMG} bs=1M count=${MOD_SIZE} mkfs.ext4 -F -b 4096 -L modules ${MOD_IMG} [ -d ${MOD_DIR}/mnt ] || mkdir ${MOD_DIR}/mnt sudo mount -o loop ${MOD_IMG} ${MOD_DIR}/mnt sudo cp -rf ${MOD_DIR}/lib/modules/* ${MOD_DIR}/mnt sync sudo umount ${MOD_DIR}/mnt fi rm -rf ${MOD_DIR} ls -al ${MOD_IMG} } check_ccache function cleanup_localversion() { rm -f localversion-rt } function create_tar() { if [ ! -d output ] ; then mkdir ./output fi rm -f ./output/* cp $BOOTFILES ./output cp usr/modules.img ./output FILES=`ls output` DATE=`date +%Y%m%d%H%M` if [ $ARM_ARCH = "arm" ]; then tar cvf tizen-local-${DATE}-boot-armv7l-rpi4.tar -C output $FILES mv tizen-local-${DATE}-boot-armv7l-rpi4.tar ./output/ elif [ $ARM_ARCH = "arm64" ]; then tar cvf tizen-local-${DATE}-boot-arm64-rpi4.tar -C output $FILES mv tizen-local-${DATE}-boot-arm64-rpi4.tar ./output/ else echo "There is no proper architecture agrument!" exit 1; fi } DEFCONFIG=tizen_bcm2711_defconfig touch .kernel_buildenv IS_RT=0 if [ "$2" = "rt" ] || [ "$3" = "rt" ]; then IS_RT=1 fi IS_BOOTIMG=0 if [ "$2" = "bootimg" ] || [ "$3" = "bootimg" ]; then IS_BOOTIMG=1 fi if [ "$IS_RT" = "1" ]; then echo "Build RT-Kernel" BUILD_VERSION=`cat .kernel_buildenv` if [ "$BUILD_VERSION" != "RT" ]; then echo "Previous .config is for Normal Kernel, so remove" rm -f .config fi DEFCONFIG=tizen_bcm2711_rt_defconfig cp _localversion-rt localversion-rt trap cleanup_localversion EXIT echo "RT" > ./.kernel_buildenv else echo "Build Normal-Kernel" BUILD_VERSION=`cat .kernel_buildenv` if [ "$BUILD_VERSION" == "RT" ]; then echo "Previous .config is for RT Kernel, so remove" rm -f .config fi echo "NORMAL" > ./.kernel_buildenv fi check_sudo if [ $1 = "arm" ]; then ARM_ARCH="arm" CROSS_COMPILER="${CCACHE} arm-linux-gnueabi-" echo "ARM" elif [ $1 = "arm64" ]; then ARM_ARCH="arm64" CROSS_COMPILER="${CCACHE} aarch64-linux-gnu-" echo "ARM64" else echo "There is no arcitecture type..." exit 1; fi if ! [ -e .config ] ; then make ARCH="${ARM_ARCH}" CROSS_COMPILE="${CROSS_COMPILER}" ${DEFCONFIG} fi make ARCH="${ARM_ARCH}" CROSS_COMPILE="${CROSS_COMPILER}" -j ${NCPUS} 2>&1 | \ sed -e "/error:.*/{s/^.*error:/$(echo -e "${COLOR_RED_BG}&${COLOR_RESET}")/g;q1}" \ -e "/Error.*/{s/^.*Error:/$(echo -e "${COLOR_RED_BG}&${COLOR_RESET}")/g;q1}" \ -e "/ERROR.*/{s/^.*ERROR/$(echo -e "${COLOR_RED_BG}&${COLOR_RESET}")/g;q1}" if [ $? -ne 0 ]; then echo -e "${COLOR_RED_BOLD}Failed to build${COLOR_RESET}" exit 1 fi if [ "$IS_BOOTIMG" = "1" ]; then mk_bootimg BOOTFILES="boot.img" else if [ $ARM_ARCH = "arm" ]; then BOOTFILES="./arch/arm/boot/zImage ./arch/arm/boot/dts/broadcom/bcm2711-rpi-4-b.dtb" else BOOTFILES="./arch/arm64/boot/Image ./arch/arm64/boot/dts/broadcom/bcm2711-rpi-4-b.dtb" fi fi # Make module.img file mk_modules # Create Tar file create_tar cleanup_localversion