forked from ungureanuvladvictor/BBBlfs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile_tools.sh
executable file
·172 lines (151 loc) · 4.33 KB
/
compile_tools.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
show_help() {
cat << EOF
Usage: ${0##*/} [-ufh]
Compiles all the files for BBBlfs.
-h display this help and exit
-f compiles just the fit image
-u compiles just u-boot
EOF
}
if [ $# -eq 0 ]; then
show_help
exit 1
fi
unset deb_pkgs
check_dpkg() {
LC_ALL=C dpkg --list | awk '{print $2}' | grep "^${pkg}" >/dev/null || deb_pkgs="${deb_pkgs}${pkg} "
}
function aptget_update_install () {
if [ "${deb_pkgs}" ]; then
sudo apt-get update
sudo apt-get -y install ${deb_pkgs}
sudo apt-get clean
fi
}
function install_required_tools () {
pkg="git"
check_dpkg
pkg="pkg-config"
check_dpkg
pkg="libc6:i386"
check_dpkg
pkg="libstdc++6:i386"
check_dpkg
pkg="libncurses5:i386"
check_dpkg
pkg="device-tree-compiler"
check_dpkg
pkg="lzma"
check_dpkg
pkg="lzop"
check_dpkg
pkg="u-boot-tools"
check_dpkg
pkg="libncurses5-dev:i386"
check_dpkg
pkg="zlib1g:i386"
check_dpkg
aptget_update_install
}
check_cc() {
if which arm-linux-gnueabihf-gcc > /dev/null; then
export CROSS_COMPILE=arm-linux-gnueabihf-
else
wget -c https://releases.linaro.org/14.04/components/toolchain/binaries/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.xz
tar xf gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.xz
export CROSS_COMPILE=`pwd`/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux/bin/arm-linux-gnueabihf-
fi
}
compile_u-boot() {
scriptPath=$(dirname $(readlink -f $BASH_SOURCE))
mkdir -p ${scriptPath}/bintest
echo Building custom U-Boot
git clone git://git.denx.de/u-boot.git /tmp/u-boot
pushd /tmp/u-boot
git reset --hard
git checkout 524123a70761110c5cf3ccc5f52f6d4da071b959
wget -c https://raw.githubusercontent.com/ungureanuvladvictor/BBBlfs/master/tools/USB_FLash.patch
patch -p1 < USB_FLash.patch
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE distclean
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE am335x_evm_usbspl_config
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE
cp -p u-boot.img ${scriptPath}/bintest/uboot
cp -p spl/u-boot-spl.bin ${scriptPath}/bintest/spl
popd
}
compile_fit() {
scriptPath=$(dirname $(readlink -f $BASH_SOURCE))
mkdir -p ${scriptPath}/bintest
echo Building the kernel
kernel_source=/tmp/bb-kernel
git clone https://github.com/beagleboard/kernel $kernel_source
pushd $kernel_source
git checkout 3.14
./patch.sh
cp configs/beaglebone kernel/arch/arm/configs/beaglebone_defconfig
wget -c http://arago-project.org/git/projects/?p=am33x-cm3.git\;a=blob_plain\;f=bin/am335x-pm-firmware.bin\;hb=HEAD -O kernel/firmware/am335x-pm-firmware.bin
pushd kernel
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE beaglebone_defconfig -j4
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE zImage dtbs modules -j4
popd
popd
echo Building the ramdisk based of BusyBox
ramdisk_source=/tmp/initramfs
mkdir $ramdisk_source
mkdir -p $ramdisk_source/{bin,sbin,etc,proc,sys}
pushd $ramdisk_source
wget -O init https://raw.githubusercontent.com/ungureanuvladvictor/BBBlfs/master/tools/init
chmod +x init
popd
busybox_source=/tmp/busybox
git clone git://git.busybox.net/busybox $busybox_source
pushd $busybox_source
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE defconfig
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE menuconfig
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE -j4
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE install CONFIG_PREFIX=$ramdisk_source
pushd $kernel_source/kernel
make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE modules_install INSTALL_MOD_PATH=$ramdisk_source
popd
popd
echo Package everything up
maker_source=/tmp/maker
mkdir $maker_source
pushd $ramdisk_source
find . | cpio -H newc -o > ${scriptPath}/bintest/initramfs.cpio
popd
cat ${scriptPath}/bintest/initramfs.cpio | gzip > ${scriptPath}/bintest/initramfs.gz
rm ${scriptPath}/bintest/initramfs.cpio
mv ${scriptPath}/bintest/initramfs.gz $maker_source/ramdisk.cpio.gz
pushd $maker_source
wget -O maker.its https://raw.githubusercontent.com/ungureanuvladvictor/BBBlfs/master/tools/maker.its
cp $kernel_source/kernel/arch/arm/boot/zImage .
cp $kernel_source/kernel/arch/arm/boot/dts/am335x-boneblack.dtb .
mkimage -f maker.its FIT
cp -p FIT ${scriptPath}/bintest/fit
popd
}
check_cc
install_required_tools
while getopts "ufh" opt; do
case "$opt" in
h)
show_help
exit 0
;;
u)
compile_u-boot
;;
f)
compile_fit
;;
'?')
show_help >&2
exit 1
;;
*)
echo "unrecognized option"
;;
esac
done