-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·152 lines (127 loc) · 5.04 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# ---------------------------------------------------------
# Simple kernel build script (c) by EoF Software Labs
# ---------------------------------------------------------
# if not in kernel directory
if [ -d kernel -a ! -f Kbuild ] ; then
cd kernel
fi
SRC_DIR=`pwd`
OS_HOST=`uname -m`
MP="-j3"
# Output directory
UPDATE_DIR="/mnt/ssd/boot-update"
if [ ${OS_HOST} == "x86_64" ] ; then
#using Ubuntu gcc-10-aarch64
#TOOL_CHAIN="/opt/FriendlyARM/toolchain/6.4-aarch64"
UPDATE_DIR="/workspace/projects/kernels/output/aio-rk3568j"
CROSS_COMPILE="aarch64-linux-gnu-"
CC="${CROSS_COMPILE}gcc-10"
LD="${CROSS_COMPILE}ld"
MP="-j8"
KRNL_ARCH="arm64"
REMOTE_SSHKEY="${HOME}/.ssh/id_rsa_tux_deploy"
REMOTE_HOST="192.168.181.112"
#dev-sd
#REMOTE_HOST="192.168.181.12"
#prod
if [ "x$1" == "xprod" ] ; then
REMOTE_HOST="192.168.181.113"
fi
REMOTE_TARGET="root@${REMOTE_HOST}:/mnt/ssd/boot-update/"
if [ -e ${TOOL_CHAIN} ] ; then
if [[ ! ${PATH} =~ "${TOOL_CHAIN}" ]]; then
export PATH=${TOOL_CHAIN}/bin/:$PATH
fi
fi
else
KRNL_ARCH="arm64"
CC="gcc"
LD="ld"
fi
# Used kernel branch
#KRNL_BRANCH="nanopi4-linux-v4.4.y"
KRNL_BRANCH=`git branch`
# Get kernel version
KRNL_VER="`make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} kernelrelease`"
echo "----------------------------------------------------"
echo "SRC_DIR......: ${SRC_DIR}"
echo "OS_HOST......: ${OS_HOST}"
echo "UPDATE_DIR...: ${UPDATE_DIR}"
echo "KERNEL_VER...: ${KRNL_VER}"
echo "KERNEL_ARCH..: ${KRNL_ARCH}"
echo "KERNEL_BRANCH: ${KRNL_BRANCH}"
echo "TOOLCHAIN....: ${TOOL_CHAIN}"
echo "CROSS_COMPILE: ${CROSS_COMPILE}"
echo "REMOTE_TARGET: ${REMOTE_TARGET}"
echo "----------------------------------------------------"
#echo | ${CC} -dM -E -
#echo "----------------------------------------------------"
mkdir -p ${UPDATE_DIR}
if [ "x$1" == "xmenuconfig" ] ; then
make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} menuconfig || exit 1
exit 0
fi
if [ ! -f .config ] ; then
echo "----------------------------------------------------"
echo "++ Configure kernel from eof_defconfig"
make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} eof_defconfig
make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} kernelrelease || exit 1
fi
# ===============================================================
# Build and installtion
# ===============================================================
echo "----------------------------------------------------"
echo "++ Build kernel targets: Image modules dtbs"
make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} Image modules dtbs || exit 1
if [ "x$1" == "xcompile" ] ; then
exit 0
fi
echo "----------------------------------------------------"
echo "++ Install kernel image to: ${UPDATE_DIR}"
make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} \
INSTALL_PATH=${UPDATE_DIR} install || exit 1
echo "----------------------------------------------------"
echo "++ Install modules to: ${UPDATE_DIR}"
make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} \
INSTALL_MOD_PATH=${UPDATE_DIR} modules_install || exit 1
echo "----------------------------------------------------"
echo "++ Install device tree DTBs to: ${UPDATE_DIR}"
make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} \
INSTALL_DTBS_PATH=${UPDATE_DIR}/dtbs dtbs_install || exit 1
echo "----------------------------------------------------"
echo "++ Install kernel userspace headers to: ${UPDATE_DIR}"
make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} \
INSTALL_HDR_PATH=${UPDATE_DIR}/usr/src headers_install || exit 1
# change path name into distribution name
rm -fR ${UPDATE_DIR}/usr/src/linux-headers-$KRNL_VER
mv ${UPDATE_DIR}/usr/src/include ${UPDATE_DIR}/usr/src/linux-headers-$KRNL_VER
# FriendlyArm SOM-RK3399 generate EMMC images files
if [ "x${BOARD_TYPE}" == "xRK3399" ] ; then
echo "----------------------------------------------------"
echo "++ Generate nanopi4 kernel images..."
make ${MP} CC=${CC} LD=${LD} CROSS_COMPILE=${CROSS_COMPILE} ARCH=${KRNL_ARCH} nanopi4-images || exit 1
fi
rm -vf ${UPDATE_DIR}/lib/modules/$KRNL_VER/source
rm -vf ${UPDATE_DIR}/lib/modules/$KRNL_VER/build
cp -Rpvu System.map ${UPDATE_DIR}/System.map-${KRNL_VER}
cp -Rpvu .config ${UPDATE_DIR}/config-${KRNL_VER}
# FriendlyArm SOM-RK3399 EMMC image files
if [ ! -e ${REMOTE_TARGET} ] ; then
# Remote SBC
#eval $(ssh-agent) # Create agent and environment variables
ssh-add ${REMOTE_SSHKEY}
OPTS="-arluvt"
SOURCE="${UPDATE_DIR}/"
echo "Enter manual following commands:"
# SOK-RK3399
[ -f kernel.img -a -f resource.img ] && \
echo "scp -r -i ${REMOTE_SSHKEY} resource.img kernel.img ${REMOTE_TARGET}"
# @ all
rsync ${OPTS} ${SOURCE} ${REMOTE_TARGET}
else
# Local SBC
[ -f kernel.img -a -f resource.img ] && \
cp -Rpvu resource.img kernel.img ${UPDATE_DIR}/
fi
exit $?