forked from loboris/OrangePI-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_linux_kernel.sh
executable file
·158 lines (137 loc) · 5.64 KB
/
build_linux_kernel.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
152
153
154
155
156
157
158
#!/bin/bash
# === USAGE ===========================================
# build_linux_kernel <board> [clean]
# <board> = 2 -> build for OPI-2/OPI-PC
# <board> = plus -> build for OPI-PLUS
# <board> = all -> build for OPI-2/OPI-PC & OPI-PLUS
# <board> = clean -> clean all
# if 2nd parameter is clean, cleans all before build
# =====================================================
# After build uImage and lib are in build directory
# =====================================================
export PATH="$PWD/brandy/gcc-linaro/bin":"$PATH"
cross_comp="arm-linux-gnueabi"
# ##############
# Prepare rootfs
# ##############
cd build
rm rootfs-lobo.img.gz > /dev/null 2>&1
# create new rootfs cpio
cd rootfs-test1
mkdir run > /dev/null 2>&1
mkdir -p conf/conf.d > /dev/null 2>&1
find . | cpio --quiet -o -H newc > ../rootfs-lobo.img
cd ..
gzip rootfs-lobo.img
cd ..
#=========================================================
cd linux-3.4
LINKERNEL_DIR=`pwd`
# build rootfs
rm -rf output/* > /dev/null 2>&1
mkdir -p output/lib > /dev/null 2>&1
cp ../build/rootfs-lobo.img.gz output/rootfs.cpio.gz
#==================================================================================
make_kernel() {
# ############
# Build kernel
# ############
# #################################
# change some board dependant files
if [ "${1}" = "plus" ]; then
cat ../build/sun8iw7p1smp_lobo_defconfig | sed '/CONFIG_GETH_CLK_SYS=y/a CONFIG_GMAC_PHY_POWER=y' > ../build/sun8iw7p1smp_lobo_defconfig.xx1
cat ../build/sun8iw7p1smp_lobo_defconfig.xx1 | sed s/"CONFIG_USB_SUNXI_OHCI0=y"/"# CONFIG_USB_SUNXI_OHCI0 is not set"/g > ../build/sun8iw7p1smp_lobo_defconfig.xx2
cat ../build/sun8iw7p1smp_lobo_defconfig.xx2 | sed s/"CONFIG_USB_SUNXI_OHCI2=y"/"# CONFIG_USB_SUNXI_OHCI2 is not set"/g > ../build/sun8iw7p1smp_lobo_defconfig.xx3
cat ../build/sun8iw7p1smp_lobo_defconfig.xx3 | sed s/"CONFIG_USB_SUNXI_OHCI3=y"/"# CONFIG_USB_SUNXI_OHCI3 is not set"/g > ../build/sun8iw7p1smp_lobo_defconfig.xx4
cp ../build/Kconfig.piplus drivers/net/ethernet/sunxi/eth/Kconfig
cp ../build/sunxi_geth.c.piplus drivers/net/ethernet/sunxi/eth/sunxi_geth.c
cp ../build/sun8iw7p1smp_lobo_defconfig.xx4 arch/arm/configs/sun8iw7p1smp_lobo_defconfig
rm ../build/sun8iw7p1smp_lobo_defconfig.xx?
else
cp ../build/Kconfig.pi2 drivers/net/ethernet/sunxi/eth/Kconfig
cp ../build/sunxi_geth.c.pi2 drivers/net/ethernet/sunxi/eth/sunxi_geth.c
cp ../build/sun8iw7p1smp_lobo_defconfig arch/arm/configs/sun8iw7p1smp_lobo_defconfig
fi
# ###########################
if [ "${2}" = "clean" ]; then
make ARCH=arm CROSS_COMPILE=${cross_comp}- mrproper > /dev/null 2>&1
fi
sleep 1
echo "Building kernel for OPI-${1} (${2}) ..."
echo " Configuring ..."
make ARCH=arm CROSS_COMPILE=${cross_comp}- sun8iw7p1smp_lobo_defconfig > ../kbuild_${1}_${2}.log 2>&1
if [ $? -ne 0 ]; then
echo " Error: KERNEL NOT BUILT."
exit 1
fi
sleep 1
# #############################################################################
# build kernel (use -jN, where N is number of cores you can spare for building)
echo " Building kernel & modules ..."
make -j6 ARCH=arm CROSS_COMPILE=${cross_comp}- uImage modules >> ../kbuild_${1}_${2}.log 2>&1
if [ $? -ne 0 ] || [ ! -f arch/arm/boot/uImage ]; then
echo " Error: KERNEL NOT BUILT."
exit 1
fi
sleep 1
# ########################
# export modules to output
echo " Exporting modules ..."
rm -rf output/lib/*
make ARCH=arm CROSS_COMPILE=${cross_comp}- INSTALL_MOD_PATH=output modules_install >> ../kbuild_${1}_${2}.log 2>&1
if [ $? -ne 0 ] || [ ! -f arch/arm/boot/uImage ]; then
echo " Error."
fi
echo " Exporting firmware ..."
make ARCH=arm CROSS_COMPILE=${cross_comp}- INSTALL_MOD_PATH=output firmware_install >> ../kbuild_${1}_${2}.log 2>&1
if [ $? -ne 0 ] || [ ! -f arch/arm/boot/uImage ]; then
echo " Error."
fi
sleep 1
# #####################
# Copy uImage to output
cp arch/arm/boot/uImage output/uImage
if [ "${1}" = "plus" ]; then
cd ..
./build_mali_driver.sh
cd $LINKERNEL_DIR
cp arch/arm/boot/uImage ../build/uImage_OPI-PLUS
[ ! -d ../build/lib.opiplus ] && mkdir ../build/lib.opiplus
rm -rf ../build/lib.opiplus/*
cp -R output/lib/* ../build/lib.opiplus
else
cd ..
./build_mali_driver.sh
cd $LINKERNEL_DIR
cp arch/arm/boot/uImage ../build/uImage_OPI-2
[ ! -d ../build/lib.opi2 ] && mkdir ../build/lib.opi2
rm -rf ../build/lib.opi2/*
cp -R output/lib/* ../build/lib.opi2
fi
}
#==================================================================================
if [ "${1}" = "clean" ]; then
echo "Cleaning..."
make ARCH=arm CROSS_COMPILE=${cross_comp}- mrproper > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo " Error."
fi
rm -rf ../build/lib.opi2/* > /dev/null 2>&1
rm -rf ../build/lib.opiplus/* > /dev/null 2>&1
rm -f ../build/uImage* > /dev/null 2>&1
rm -f ../kbuild* > /dev/null 2>&1
rm -f ../malibuild* > /dev/null 2>&1
rm if ../linux-3.4/modules/malibuild* > /dev/null 2>&1
rmdir ../build/lib.opi2 > /dev/null 2>&1
rmdir ../build/lib.opiplus > /dev/null 2>&1
rm ../build/rootfs-lobo.img.gz > /dev/null 2>&1
rm -rf output/* > /dev/null 2>&1
elif [ "${1}" = "all" ]; then
make_kernel "2" "${2}"
make_kernel "plus" "${2}"
elif [ "${1}" = "" ]; then
make_kernel "2"
else
make_kernel "${1}" "${2}"
fi
echo "***OK***"