script: add a build script for amlogic boards 63/249963/2
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 18 Dec 2020 03:53:41 +0000 (12:53 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 18 Dec 2020 04:40:53 +0000 (13:40 +0900)
Add a build script for amlogic boards.

For Odroid-C4/N2, it will create the below files.
- odroid/Image.gz
- meson64-odroidc4.dtb
- meson64-odroidn2_drm.dtb
- modules.img (with ${version}-TIZEN-amlogic-odroid+)

For Khadas VIM3/VIM3L, it will create the below files.
- kvim/Image.gz
- kvim3_linux.dtb
- kvim3l_linux.dtb
- modules.img (with ${version}-TIZEN-amlogic-kvim+)

For 'all' boards build, it will create the below files.
- odroid/Image.gz
- kvim/Image.gz
- meson64-odroidc4.dtb
- meson64-odroidn2_drm.dtb
- kvim3_linux.dtb
- kvim3l_linux.dtb
- modules.img (with ${version}-TIZEN-amlogic-odroid+ and ${version}-TIZEN-amlogic-kvim+)

Change-Id: I7bd9ae47576ab53d206b7c268f035b244a22f8e2
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Hoegeun Kwon <hoegeun.kwon@samsung.com>
[sw0312.kim: add to support 'all' board option]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
build-amlogic.sh [new file with mode: 0755]

diff --git a/build-amlogic.sh b/build-amlogic.sh
new file mode 100755 (executable)
index 0000000..b700898
--- /dev/null
@@ -0,0 +1,204 @@
+#!/bin/bash
+
+CROSS_COMPILE=${CROSS_COMPILE:-aarch64-linux-gnu-}
+ARM_ARCH=arm64
+NCPUS=`cat /proc/cpuinfo | grep processor | wc -l`
+
+# Check this system has ccache
+check_ccache()
+{
+       type ccache
+       if [ "$?" -eq "0" ]; then
+               CCACHE=ccache
+       fi
+}
+
+clean_output()
+{
+       if [ -d output ]; then
+               rm -rf output/*
+       else
+               mkdir -p output
+       fi
+}
+
+set_names()
+{
+       case $1 in
+       c4|n2)
+               CONFIG=odroidg12
+               DTB1=meson64_odroidc4.dtb
+               DTB2=meson64_odroidn2_drm.dtb
+               OUT_DIR=odroid
+               ;;
+
+       vim3|vim3l)
+               CONFIG=kvims
+               DTB1=kvim3_linux.dtb
+               DTB2=kvim3l_linux.dtb
+               OUT_DIR=kvim
+               ;;
+       esac
+}
+
+set_extra_version()
+{
+       # set EXTRAVERSION for each board
+       sed -i "s/^EXTRAVERSION.*/EXTRAVERSION = -TIZEN-amlogic-${OUT_DIR}/" Makefile
+}
+
+clear_extra_version()
+{
+       # clear EXTRAVERSION
+       sed -i "s/^EXTRAVERSION.*/EXTRAVERSION =/" Makefile
+}
+
+build_kernel()
+{
+       rm -f arch/arm64/boot/Image*
+
+       [ -d output/${OUT_DIR} ] || mkdir -p output/${OUT_DIR}
+
+       if ! [ -e .config ]; then
+               make tizen_${CONFIG}_defconfig
+       fi
+       make -j $NCPUS Image.gz dtbs
+       if [ ! -f "./arch/arm64/boot/Image.gz" ]; then
+               echo "Build fail"
+               clear_extra_version
+               exit 1
+       fi
+
+       cp arch/arm64/boot/dts/amlogic/${DTB1} ./output/
+       cp arch/arm64/boot/dts/amlogic/${DTB2} ./output/
+       cp arch/arm64/boot/Image.gz ./output/${OUT_DIR}/
+}
+
+check_ext4_tool()
+{
+       [ -e /usr/bin/make_ext4fs ] && USE_MAKE_EXT4FS=1
+       if [ "$USE_MAKE_EXT4FS" != "1" ]; then
+               # get sudo permission for mount
+               sudo echo "dummy" > /dev/null
+       fi
+}
+
+mk_modules()
+{
+       MOD_DIR="usr/tmp_mod"
+
+       [ -d ${MOD_DIR} ] || mkdir ${MOD_DIR}
+
+       make -j $NCPUS modules
+       make modules_install INSTALL_MOD_PATH=${MOD_DIR} INSTALL_MOD_STRIP=1
+}
+
+mk_modules_image()
+{
+       MOD_DIR="usr/tmp_mod"
+       MOD_IMG="usr/modules.img"
+       MOD_SIZE=100
+
+       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
+               sudo -n chown root:root ${MOD_DIR}/mnt -R
+               sync
+               sudo umount ${MOD_DIR}/mnt
+       fi
+       cp usr/modules.img ./output
+
+       rm -rf ${MOD_DIR}
+       rm -rf ${MOD_IMG}
+}
+
+create_tar()
+{
+       # Create boot tarball for the lthor flashing
+       DATE=`date +%Y%m%d`
+       BOOT_TARBALL=tizen-local-${DATE}-boot-arm64-${BOARDS}.tar.gz
+
+       cd ./output/
+       OUTPUT_FILES=`find * -type f`
+       cd ..
+       tar czf output/${BOOT_TARBALL} -C output ${OUTPUT_FILES}
+       if [ "$?" != "0" ]; then
+               echo "Failed to create boot tarball"
+               exit 1
+       fi
+
+       echo "Crated output/${BOOT_TARBALL}"
+}
+
+case $1 in
+c4|n2|vim3|vim3l)
+       BOARDS=$1
+       ;;
+
+all)
+       # in kernel tree, c4 and n2 are built as a result
+       # and vim3 and vim3l are built as a result.
+       BOARDS="c4 vim3"
+       ;;
+
+*)
+       echo "linux kernel building script for tizen amlogic boards"
+       echo "usage: $0 target"
+       echo "where target is one of: c4 n2 vim3 vim3l all"
+       exit
+       ;;
+esac
+
+check_ext4_tool
+check_ccache
+clean_output
+
+export ARCH=${ARM_ARCH}
+export CROSS_COMPILE="$CCACHE $CROSS_COMPILE"
+
+if [ "$1" = "all" ]; then
+       echo "It will remove local .config to build entire boards"
+else
+       if [ -e .config ]; then
+               CHECK_ODROID=`grep CONFIG_ARCH_MESON64_ODROID_COMMON=y .config`
+               if [ "$BOARDS" = "c4" ] || [ "$BOARDS" = "n2" ]; then
+                       if [ "z${CHECK_ODROID}" = "z" ]; then
+                               echo "There is local .config, but it is differen from ${BOARD}."
+                               echo "Please try after removing .config."
+                       fi
+                       exit
+               else
+                       if [ "z${CHECK_ODROID}" != "z" ]; then
+                               echo "There is local .config, but it is differen from ${BOARD}."
+                               echo "Please try after removing .config."
+                               exit
+                       fi
+               fi
+               echo "There is local .config and build with the file."
+       fi
+fi
+
+for BOARD in $BOARDS
+do
+       if [ "$1" = "all" ]; then
+               rm -f .config
+       fi
+       set_names $BOARD
+       set_extra_version
+       build_kernel
+       mk_modules
+done
+clear_extra_version
+mk_modules_image
+
+if [ "$1" = "all" ]; then
+       BOARDS=amlogic
+fi
+create_tar