packaging: Remove variant from Source file name
[platform/kernel/linux-starfive.git] / build.sh
1 #!/bin/bash
2 MOD_DIR="usr/tmp_mod"
3 MOD_IMG="usr/modules.img"
4 MOD_SIZE=32
5 NCPUS=`grep ^processor /proc/cpuinfo | wc -l`
6 NCPUS=$(($NCPUS * 2))
7
8 # Check this system has ccache
9 check_ccache()
10 {
11         type ccache
12         if [ "$?" -eq "0" ]; then
13                 CCACHE=ccache
14         fi
15 }
16
17 function mk_modules() {
18         [ -e /usr/bin/make_ext4fs ] && USE_MAKE_EXT4FS=1
19         if [ "$USE_MAKE_EXT4FS" != "1" ]; then
20                 sudo ls > /dev/null
21         fi
22
23         make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" modules_prepare
24         make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" modules -j ${NCPUS}
25
26         if [ "$?" != "0" ]; then
27                 echo "Failed to make modules"
28                 exit 1
29         fi
30
31         [ -d ${MOD_DIR} ] || mkdir ${MOD_DIR}
32
33         make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" modules_install INSTALL_MOD_PATH=${MOD_DIR} INSTALL_MOD_STRIP=1
34
35         if [ "$USE_MAKE_EXT4FS" == "1" ]; then
36                 /usr/bin/make_ext4fs -b 4096 -L modules -l ${MOD_SIZE}M $MOD_IMG ${MOD_DIR}/lib/modules/
37         else
38                 dd if=/dev/zero of=${MOD_IMG} bs=1M count=${MOD_SIZE}
39                 mkfs.ext4 -F -b 4096 -L modules ${MOD_IMG}
40                 [ -d ${MOD_DIR}/mnt ] || mkdir ${MOD_DIR}/mnt
41                 sudo mount -o loop ${MOD_IMG} ${MOD_DIR}/mnt
42                 sudo cp -rf ${MOD_DIR}/lib/modules/* ${MOD_DIR}/mnt
43                 sync
44                 sudo umount ${MOD_DIR}/mnt
45         fi
46         rm -rf ${MOD_DIR}
47         ls -al ${MOD_IMG}
48 }
49
50 check_ccache
51
52 echo "riscv64"
53 rm -f arch/riscv/boot/Image
54 rm -f arch/riscv/boot/dts/starfive/*.dtb
55 rm -f output/Image
56 rm -f output/*.dtb
57 rm -f output/modules.img
58 rm -f output/*.tar
59
60 CROSS_COMPILER=riscv64-linux-gnu-
61 ARCH=riscv
62 if ! [ -e .config ] ; then
63         make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" tizen_visionfive2_defconfig
64 fi
65 make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" -j8
66 if [ ! -f "./arch/riscv/boot/Image" ]; then
67         echo "Build fail"
68         exit 1
69 fi
70
71 # Make module.img file
72 mk_modules
73
74 if [ ! -d output ] ; then
75         mkdir ./output
76 fi
77
78 cp usr/modules.img ./output
79
80 cp ./arch/riscv/boot/Image ./output
81 cp ./arch/riscv/boot/dts/starfive/*.dtb ./output
82 tar cvf linux-visionfive2.tar -C output Image jh7110-starfive-visionfive-2-v1.2a.dtb jh7110-starfive-visionfive-2-v1.3b.dtb modules.img
83 mv linux-visionfive2.tar ./output/