forked from akhepcat/build-pine64-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkern-compile
executable file
·142 lines (114 loc) · 3.73 KB
/
kern-compile
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
#!/bin/bash
DATE=$(date '+%Y%m%d%H%M')
PROG="${0##*/}"
ARGS="${*} default"
DO_RETURN=${SHLVL}
trap do_exit SIGINT SIGTERM SIGKILL SIGQUIT SIGABRT SIGSTOP SIGSEGV
do_exit()
{
STATUS=${1:-0}
REASON=${2}
[[ -n "${REASON}" ]] && echo "${REASON}"
[[ ${DO_RETURN} -eq 1 ]] && return $STATUS || exit $STATUS
}
cd /usr/src/
if [ ! -e /usr/src/linux-pine64/.git/config ]
then
echo "no current linux repository, cloning may take some time."
git clone --depth 1 --single-branch -b pine64-hacks-1.2 https://github.com/longsleep/linux-pine64
ARGS="update"
fi
cd /usr/src/linux-pine64
if [ -z "${ARGS##*update*}" ]
then
make mrproper
git pull
echo "ctrl-z, run 'git checkout -b \${branch}' here, then fg and 'enter' to continue."
read waiting
else
echo "skipping update ('$0 update' to force a new kernel) and starting to build"
fi
if [ ! -e ".config" ]
then
echo "ctrl-z, and run either 'make sun50iw1p1smp_linux_defconfig' or copy a saved config here as .config, run 'make oldconfig', then fg and 'enter' to continue."
read waiting
fi
test -e /usr/src/linux-pine64/arch/arm64/boot/dts/sun50i-a64-pine64-plus.dts || \
curl -sSL https://github.com/longsleep/build-pine64-image/raw/master/blobs/pine64.dts > /usr/src/linux-pine64/arch/arm64/boot/dts/sun50i-a64-pine64-plus.dts
CPUS=$(grep processor /proc/cpuinfo | wc -l)
if [ -z "${ARGS##*CPUS=*}" ]
then
CPUS=${ARGS##*CPUS=}
CPUS=${CPUS[0]}
CPUS=${CPUS//[^0-9]/}
fi
make -j${CPUS} Image sun50i-a64-pine64-plus.dtb modules
if [ 0 -ne $? ]
then
echo "Make broke. fix and resume manually"
do_exit 1
fi
make modules_install
if [ 0 -ne $? ]
then
echo "Make (modules_install) broke. fix and resume manually"
do_exit 1
fi
make firmware_install
if [ 0 -ne $? ]
then
echo "Make (firmware_install) broke. fix and resume manually"
do_exit 1
fi
# this really doesn't need to be updated except for major revision changes.
# so... a difference of 100 in the kernel version, maybe?
if [ -e /usr/include/linux/version.h ]
then
OLDV=$(grep LINUX_VERSION_CODE /usr/include/linux/version.h | awk '{print $3}')
NEWV=$(grep LINUX_VERSION_CODE /usr/src/linux-pine64/include/generated/uapi/linux/version.h | awk '{print $3}')
DIFF=$(( ${NEWV:-0} - ${OLDV:-0} ))
#negatives mean older, but bash math, so normalize to zero.
DIFF=${DIFF##-*}
if [ ${NEWV:-0} -gt ${OLDV:-0} -a ${DIFF:-0} -gt 100 ]
then
make headers_install INSTALL_HDR_PATH=/usr
fi
else
# if there's no linux include directory, we install it forcefully
make headers_install INSTALL_HDR_PATH=/usr
fi
kver=$( make kernelrelease )
kb=${kver//\./}
kb=${kb//-pine64}
kb="k0${kb//-/.}"
test -e .config && cp .config /usr/src/config-pine64-${kver}-${DATE}
# and install it...
if [ -z "$(mount | grep boot)" ]
then
echo "/boot not mounted: ctrl-z, 'mount /boot', then fg and 'enter' to continue."
read waiting
fi
mkdir /boot/${kb}
FREE=$(df -k /boot/ | awk '/boot/ {print $4}')
if [ ${FREE:-0} -lt 20000 ]
then
echo "not enough free space in /boot: ctrl-z, clean up space, then fg and 'enter' to continue."
read waiting
fi
cp arch/arm64/boot/dts/sun50i-a64-pine64-plus.dtb arch/arm64/boot/Image /boot/${kb}/
update-initramfs -c -k ${kver} -b /boot/${kb}/
mv /boot/${kb}/initrd.img-${kver} /boot/${kb}/initrd.img
## adjust the /boot/uEnv.txt
if [ -e /boot/uEnv.txt ]
then
echo "About to fixup /boot/uEnv.txt, enter to continue, or ctrl-c to abort this auto-updating"
read waiting
fi
sed -i "s/\(kernel_filename\)=.*/\1=${kb}\/Image/gi; s/\(initrd_filename\)=.*/\1=${kb}\/initrd.img/gi;" /boot/uEnv.txt
if [ -z "$(grep fdt_filename_prefix /boot/uEnv.txt)" ]
then
sed -i "s/\(fdt_filename_prefix\)=.*/\1=${kb}\/sun50i-a64-/gi;" /boot/uEnv.txt
else
echo "fdt_filename_prefix=${kb}/sun50i-a64-" >> /boot/uEnv.txt
fi
echo "completed"