Add a build script for building tizen kernel on local 26/306626/2
authorJaehoon Chung <jh80.chung@samsung.com>
Fri, 23 Feb 2024 07:13:15 +0000 (16:13 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 26 Mar 2024 05:02:52 +0000 (05:02 +0000)
Add a build script for building tizen kernel.
This script is creating,
     - kernel image
     - dtb file
     - modules image

Change-Id: Id2a63588ac5288cf20e96145feb5b27184ed25e4
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
build-rpi4.sh [new file with mode: 0755]

diff --git a/build-rpi4.sh b/build-rpi4.sh
new file mode 100755 (executable)
index 0000000..8c2d3ce
--- /dev/null
@@ -0,0 +1,150 @@
+#!/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))
+
+if [ $# == 0 ]; then
+       echo "Usage : $0 <architecture> [rt]"
+       echo "  architecture : arm or arm64"
+       echo "  e.g) $0 arm"
+       echo "  e.g) $0 arm64 rt"
+       exit
+fi
+
+# Check this system has ccache
+check_ccache()
+{
+       type ccache
+       if [ "$?" -eq "0" ]; then
+               CCACHE=ccache
+       fi
+}
+
+function mk_modules() {
+       [ -e /usr/bin/make_ext4fs ] && USE_MAKE_EXT4FS=1
+       if [ "$USE_MAKE_EXT4FS" != "1" ]; then
+               sudo ls > /dev/null
+       fi
+
+       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
+
+       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
+
+       cp usr/modules.img ./output
+
+       DATE=`date +%Y%m%d%H%M`
+       if [ $ARM_ARCH = "arm" ]; then
+               cp ./arch/arm/boot/zImage ./output
+               cp ./arch/arm/boot/dts/broadcom/bcm2711-rpi-4-b.dtb ./output
+               tar cvf tizen-local-${DATE}-boot-armv7l-rpi4.tar -C output zImage bcm2711-rpi-4-b.dtb modules.img
+               mv tizen-local-${DATE}-boot-armv7l-rpi4.tar ./output/
+       elif [ $ARM_ARCH = "arm64" ]; then
+               cp ./arch/arm64/boot/Image ./output
+               cp ./arch/arm64/boot/dts/broadcom/bcm2711-rpi-4-b.dtb ./output
+               tar cvf tizen-local-${DATE}-boot-arm64-rpi4.tar -C output Image bcm2711-rpi-4-b.dtb modules.img
+               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
+if [ "$2" = "rt" ]; 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
+
+
+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
+
+# Make module.img file
+mk_modules
+
+# Create Tar file
+create_tar