-
Notifications
You must be signed in to change notification settings - Fork 16
/
build-kernel
executable file
·137 lines (115 loc) · 4.6 KB
/
build-kernel
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
#!/bin/sh
# ------------------------------------------------------------------------------
# build-kernel - Builds the ev3dev kernel.
# ------------------------------------------------------------------------------
echo
echo -------------------------------------------------------------------------------
echo BUILDING KERNEL
echo -------------------------------------------------------------------------------
echo
set -e
. ./setup-env
kernel_src_path="$EV3DEV_KERNEL"
obj_path="$EV3DEV_OBJ"
kernel_install_path="$EV3DEV_INSTALL_KERNEL"
modules_install_path="$EV3DEV_INSTALL_MODULES"
dtbs_install_path="$EV3DEV_INSTALL_DTBS"
make_args="$EV3DEV_MAKE_ARGS -C ${kernel_src_path}
KBUILD_OUTPUT=${obj_path}
ARCH=arm
CROSS_COMPILE=$EV3DEV_TOOLCHAIN/$EV3DEV_ABI"
extra_default_targets="$EV3DEV_EXTRA_DEFAULT_TARGETS"
uenv_txt_install_path="$EV3DEV_INSTALL_UENV_TXT"
if [ ! -d "${obj_path}" ]
then
echo "CREATING OBJ DIRECTORY"
make ${make_args} mrproper
fi
if [ ! -f "${obj_path}/.config" ]
then
echo "LOADING DEFAULT KERNEL CONFIGURATION"
make ${make_args} defconfig KBUILD_DEFCONFIG=${EV3DEV_DEFCONFIG}
fi
if [ $# -eq 0 ]
then
echo "CROSS COMPILING KERNEL"
make ${make_args} ${extra_default_targets} modules
if [ ! -d "${kernel_install_path}" ]
then
echo "CREATING KERNEL INSTALL DIRECTORY"
mkdir -p "${kernel_install_path}"
fi
if [ ! -d "${modules_install_path}" ]
then
echo "CREATING MODULE INSTALL DIRECTORY"
mkdir -p "${modules_install_path}"
fi
echo "COPYING BOOTABLE IMAGE TO INSTALL DIRECTORY"
if [ "$EV3DEV_KERNEL_FLAVOR" = "ev3" ]; then
if [ -n "$EV3DEV_APPEND_DTB" ]; then
cat ${obj_path}/arch/arm/boot/zImage ${obj_path}/arch/arm/boot/dts/$EV3DEV_APPEND_DTB > ${obj_path}/arch/arm/boot/zImage+dtb
mkimage -A arm -O linux -T kernel -C none -a 0xC0008000 -e 0xC0008000 \
-n kernel -d ${obj_path}/arch/arm/boot/zImage+dtb ${obj_path}/arch/arm/boot/uImage
fi
cp ${obj_path}/arch/arm/boot/uImage ${kernel_install_path}
elif [ "$EV3DEV_KERNEL_FLAVOR" = "bb.org" ]; then
cp ${obj_path}/arch/arm/boot/zImage ${kernel_install_path}
elif [ "$EV3DEV_KERNEL_FLAVOR" = "rpi" ]; then
cp ${obj_path}/arch/arm/boot/zImage ${kernel_install_path}/kernel.img
elif [ "$EV3DEV_KERNEL_FLAVOR" = "rpi2" ]; then
cp ${obj_path}/arch/arm/boot/zImage ${kernel_install_path}/kernel7.img
fi
echo "COPYING MODULES TO INSTALL DIRECTORY"
make ${make_args} modules_install INSTALL_MOD_PATH=${modules_install_path}
if [ ! -z ${EV3DEV_INSTALL_DTBS} ]; then
echo "COPYING DEVICE TREE BLOCKS TO INSTALL DIRECTORY"
make ${make_args} dtbs_install INSTALL_DTBS_PATH=${dtbs_install_path}
fi
if [ ! -z ${EV3DEV_COPY_DTB} ]; then
echo "COPYING DEVICE TREE TO KERNEL INSTALL DIRECTORY"
cp ${dtbs_install_path}/${EV3DEV_COPY_DTB} ${kernel_install_path}/${EV3DEV_COPY_DTB}
fi
if [ "$EV3DEV_KERNEL_FLAVOR" = "bb.org" ]; then
echo "COPYING UENV.TXT TO INSTALL DIRECTORY"
cat > ${uenv_txt_install_path}/uEnv.txt.new <<EOF
cape=$EV3DEV_CAPE
cmdline=splash console=tty1
loadaddr=0x82000000
fdtaddr=0x88000000
rdaddr=0x88080000
initrd_high=0xffffffff
fdt_high=0xffffffff
##These are needed to be compliant with Debian 2014-05-14 u-boot.
loadximage=echo debug: [/zImage] ... ; load mmc 0:1 \${loadaddr} /zImage
loadxfdt=echo debug: [/dtbs/\${fdtfile}] ... ;load mmc 0:1 \${fdtaddr} /dtbs/\${fdtfile}
check_cape=if test -n \${cape}; then setenv fdtfile \${fdtbase}-\${cape}.dtb;fi;
check_dtb=if test -n \${dtb}; then setenv fdtfile \${dtb};fi;
loadall=run check_cape; run check_dtb; run loadximage; run loadxfdt;
mmcargs=setenv bootargs console=tty0 console=\${console} \${optargs} \${cape_disable} \${cape_enable} root=/dev/mmcblk0p2 rootfstype=\${mmcrootfstype} \${cmdline}
uenvcmd=run loadall; run mmcargs; echo debug: [\${bootargs}] ... ; echo debug: [bootz \${loadaddr} - \${fdtaddr}] ... ; bootz \${loadaddr} - \${fdtaddr};
EOF
if [ -e ${uenv_txt_install_path}/uEnv.txt ]; then
if cmp ${uenv_txt_install_path}/uEnv.txt.new ${uenv_txt_install_path}/uEnv.txt --quiet; then
# Files are the same, so no need to replace existing file
rm ${uenv_txt_install_path}/uEnv.txt.new
else
# Files are different, so backup and replace existing file
mv --backup=existing --suffix=.old ${uenv_txt_install_path}/uEnv.txt.new ${uenv_txt_install_path}/uEnv.txt
fi
else
# File does not exist, so just move
mv ${uenv_txt_install_path}/uEnv.txt.new ${uenv_txt_install_path}/uEnv.txt
fi
fi
else
echo "CROSS COMPILING KERNEL"
make ${make_args} $@
for arg in "$@"
do
# If cleaning, remove the files generated by this script too.
if [ "$arg" = "clean" -o "$arg" = "mrproper" -o "$arg" = "distclean" ]
then
rm -rf kernel
fi
done
fi