forked from armbian/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boards.sh
245 lines (207 loc) · 11.9 KB
/
boards.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/bin/bash
#
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of tool chain https://github.com/igorpecovnik/lib
#
install_board_specific (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install board common and specific applications
#--------------------------------------------------------------------------------------------------------------------------------
display_alert "Install board specific applications." "$BOARD" "info"
# add some summary to the image
fingerprint_image "$DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/etc/armbian.txt"
# Allwinner
if [[ $LINUXCONFIG == *sunxi* ]] ; then
# add sunxi tools
cp $SOURCES/sunxi-tools/fex2bin $SOURCES/sunxi-tools/bin2fex $SOURCES/sunxi-tools/nand-part $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/usr/local/bin
# add soc temperature app
arm-linux-gnueabihf-gcc $SRC/lib/scripts/sunxi-temp/sunxi_tp_temp.c -o $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/usr/local/bin/sunxi_tp_temp
# lamobo R1 router switch config
tar xfz $SRC/lib/bin/swconfig.tgz -C $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/usr/local/bin
# add NAND boot content
mkdir -p $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/root
cp $SRC/lib/bin/nand1-allwinner.tgz $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/root/.nand1-allwinner.tgz
# convert and add fex files
unset IFS
mkdir -p $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/boot/bin
for i in $(ls -w1 $SRC/lib/config/*.fex | xargs -n1 basename);
do fex2bin $SRC/lib/config/${i%*.fex}.fex $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/boot/bin/${i%*.fex}.bin;
done
# bluetooth device enabler - for cubietruck
install -m 755 $SRC/lib/bin/brcm_patchram_plus $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/usr/local/bin
install $SRC/lib/scripts/brcm40183 $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/etc/default
install -m 755 $SRC/lib/scripts/brcm40183-patch $DEST/debs/$RELEASE/$CHOOSEN_ROOTFS/etc/init.d
# default lirc configuration
sed -i '1i sed -i \x27s/DEVICE="\\/dev\\/input.*/DEVICE="\\/dev\\/input\\/\x27$str\x27"/g\x27 /etc/lirc/hardware.conf' $DEST/cache/sdcard/etc/lirc/hardware.conf
sed -i '1i str=$(cat /proc/bus/input/devices | grep "H: Handlers=sysrq rfkill kbd event" | awk \x27{print $(NF)}\x27)' $DEST/cache/sdcard/etc/lirc/hardware.conf
sed -i '1i # Cubietruck automatic lirc device detection by Igor Pecovnik' $DEST/cache/sdcard/etc/lirc/hardware.conf
sed -e 's/DEVICE=""/DEVICE="\/dev\/input\/event1"/g' -i $DEST/cache/sdcard/etc/lirc/hardware.conf
sed -e 's/DRIVER="UNCONFIGURED"/DRIVER="devinput"/g' -i $DEST/cache/sdcard/etc/lirc/hardware.conf
cp $SRC/lib/config/lirc.conf.cubietruck $DEST/cache/sdcard/etc/lirc/lircd.conf
fi
# udoo
if [[ $BOARD == "udoo" ]] ; then
if [ -f $DEST/cache/sdcard/etc/inittab ]; then sed -e "s/ttyS0/ttymxc1/g" -i $DEST/cache/sdcard/etc/inittab; fi
if [ -f $DEST/cache/sdcard/etc/init/ttyS0.conf ]; then
mv $DEST/cache/sdcard/etc/init/ttyS0.conf $DEST/cache/sdcard/etc/init/ttymxc1.conf;
sed -e "s/ttyS0/ttymxc1/g" -i $DEST/cache/sdcard/etc/init/ttymxc1.conf;
fi
if [ -f $DEST/cache/sdcard/etc/systemd/system/getty.target.wants/[email protected] ]; then mv $DEST/cache/sdcard/etc/systemd/system/getty.target.wants/[email protected] $DEST/cache/sdcard/etc/systemd/system/getty.target.wants/[email protected] ; fi
chroot $DEST/cache/sdcard /bin/bash -c "apt-get -y -qq remove lirc && apt-get -y -qq autoremove"
sed 's/wlan0/wlan2/' -i $DEST/cache/sdcard/etc/network/interfaces.default
sed 's/wlan0/wlan2/' -i $DEST/cache/sdcard/etc/network/interfaces.bonding
sed 's/wlan0/wlan2/' -i $DEST/cache/sdcard/etc/network/interfaces.hostapd
# Udoo doesn't have interactive
sed -e 's/interactive/ondemand/g' -i $DEST/cache/sdcard/etc/init.d/cpufrequtils
fi
# udoo neo
if [[ $BOARD == "udoo-neo" ]] ; then
if [ -f $DEST/cache/sdcard/etc/inittab ]; then sed -e "s/ttyS0/ttymxc0/g" -i $DEST/cache/sdcard/etc/inittab; fi
if [ -f $DEST/cache/sdcard/etc/init/ttyS0.conf ]; then mv $DEST/cache/sdcard/etc/init/ttyS0.conf $DEST/cache/sdcard/etc/init/ttymxc0.conf; sed -e "s/ttyS0/ttymxc0/g" -i $DEST/cache/sdcard/etc/init/ttymxc0.conf; fi
if [ -f $DEST/cache/sdcard/etc/systemd/system/getty.target.wants/[email protected] ]; then mv $DEST/cache/sdcard/etc/systemd/system/getty.target.wants/[email protected] $DEST/cache/sdcard/etc/systemd/system/getty.target.wants/[email protected] ; fi
chroot $DEST/cache/sdcard /bin/bash -c "apt-get -y -qq remove lirc && apt-get -y -qq autoremove"
sed 's/wlan0/wlan2/' -i $DEST/cache/sdcard/etc/network/interfaces.default
sed 's/wlan0/wlan2/' -i $DEST/cache/sdcard/etc/network/interfaces.bonding
sed 's/wlan0/wlan2/' -i $DEST/cache/sdcard/etc/network/interfaces.hostapd
# SD card is elsewhere
sed 's/mmcblk0p1/mmcblk1p1/' -i $DEST/cache/sdcard/etc/fstab
fi
# cubox / hummingboard
if [[ $BOARD == cubox-i* ]] ; then
if [ -f $DEST/cache/sdcard/etc/inittab ]; then sed -e "s/ttyS0/ttymxc0/g" -i $DEST/cache/sdcard/etc/inittab; fi
if [ -f $DEST/cache/sdcard/etc/init/ttyS0.conf ]; then mv $DEST/cache/sdcard/etc/init/ttyS0.conf $DEST/cache/sdcard/etc/init/ttymxc0.conf; sed -e "s/ttyS0/ttymxc0/g" -i $DEST/cache/sdcard/etc/init/ttymxc0.conf; fi
if [ -f $DEST/cache/sdcard/etc/systemd/system/getty.target.wants/[email protected] ]; then mv $DEST/cache/sdcard/etc/systemd/system/getty.target.wants/[email protected] $DEST/cache/sdcard/etc/systemd/system/getty.target.wants/[email protected] ; fi
# default lirc configuration
sed -e 's/DEVICE=""/DEVICE="\/dev\/lirc0"/g' -i $DEST/cache/sdcard/etc/lirc/hardware.conf
sed -e 's/DRIVER="UNCONFIGURED"/DRIVER="default"/g' -i $DEST/cache/sdcard/etc/lirc/hardware.conf
cp $SRC/lib/config/lirc.conf.cubox-i $DEST/cache/sdcard/etc/lirc/lircd.conf
cp $SRC/lib/bin/brcm_patchram_plus_cubox $DEST/cache/sdcard/usr/local/bin/brcm_patchram_plus
chroot $DEST/cache/sdcard /bin/bash -c "chmod +x /usr/local/bin/brcm_patchram_plus"
cp $SRC/lib/scripts/brcm4330 $DEST/cache/sdcard/etc/default
cp $SRC/lib/scripts/brcm4330-patch $DEST/cache/sdcard/etc/init.d
chroot $DEST/cache/sdcard /bin/bash -c "chmod +x /etc/init.d/brcm4330-patch"
chroot $DEST/cache/sdcard /bin/bash -c "update-rc.d brcm4330-patch defaults>> /dev/null"
fi
# create board DEB file
cd $DEST/debs/$RELEASE/
dpkg -b $CHOOSEN_ROOTFS >/dev/null 2>&1
rm -rf $CHOOSEN_ROOTFS
# install custom root package
#cp $CHOOSEN_ROOTFS.deb /tmp/kernel
chroot $DEST/cache/sdcard /bin/bash -c "dpkg -i /tmp/$RELEASE/$CHOOSEN_ROOTFS.deb >/dev/null 2>&1"
# enable first run script
chroot $DEST/cache/sdcard /bin/bash -c "update-rc.d firstrun defaults >/dev/null 2>&1"
display_alert "Creating boot scripts" "$BOARD" "info"
# remove .old on new image
rm -rf $DEST/cache/sdcard/boot/dtb.old
if [[ $BOARD == "udoo" ]] ; then
cp $SRC/lib/config/boot-udoo-next.cmd $DEST/cache/sdcard/boot/boot.cmd
elif [[ $BOARD == "udoo-neo" ]]; then
cp $SRC/lib/config/boot-udoo-neo.cmd $DEST/cache/sdcard/boot/boot.cmd
#chroot $DEST/cache/sdcard /bin/bash -c "ln -s /boot/boot.scr /boot.scr"
elif [[ $BOARD == cubox-i* ]]; then
cp $SRC/lib/config/boot-cubox.cmd $DEST/cache/sdcard/boot/boot.cmd
else
cp $SRC/lib/config/boot.cmd $DEST/cache/sdcard/boot/boot.cmd
# let's prepare for old kernel too
chroot $DEST/cache/sdcard /bin/bash -c "ln -s /boot/bin/$BOARD.bin /boot/script.bin >/dev/null 2>&1 || cp /boot/bin/$BOARD.bin /boot/script.bin"
fi
# if we have a special fat boot partition, alter rootfs=
if [ "$BOOTSIZE" -gt "0" ]; then
display_alert "Adjusting boot scripts" "$BOARD" "info"
sed -e 's/p1 /p2 /g' -i $DEST/cache/sdcard/boot/boot.cmd
echo "/dev/mmcblk0p1 /boot vfat defaults 0 0" >> $DEST/cache/sdcard/etc/fstab
fi
# convert to uboot compatible script
mkimage -C none -A arm -T script -d $DEST/cache/sdcard/boot/boot.cmd $DEST/cache/sdcard/boot/boot.scr >> /dev/null
}
install_kernel (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install kernel to prepared root file-system
#--------------------------------------------------------------------------------------------------------------------------------
display_alert "Install kernel" "$CHOOSEN_KERNEL" "info"
# configure MIN / MAX speed for cpufrequtils
sed -e "s/MIN_SPEED=\"0\"/MIN_SPEED=\"$CPUMIN\"/g" -i $DEST/cache/sdcard/etc/init.d/cpufrequtils
sed -e "s/MAX_SPEED=\"0\"/MAX_SPEED=\"$CPUMAX\"/g" -i $DEST/cache/sdcard/etc/init.d/cpufrequtils
# interactive currently available only on 3.4
if [[ $BRANCH != *next* ]];then
sed -e 's/ondemand/interactive/g' -i $DEST/cache/sdcard/etc/init.d/cpufrequtils
fi
# set hostname
echo $HOST > $DEST/cache/sdcard/etc/hostname
# this is needed for ubuntu
rm $DEST/cache/sdcard/etc/resolv.conf
echo "nameserver 8.8.8.8" >> $DEST/cache/sdcard/etc/resolv.conf
# set hostname in hosts file
cat > $DEST/cache/sdcard/etc/hosts <<EOT
127.0.0.1 localhost $HOST
::1 localhost $HOST ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOT
# create modules file
IFS=" "
if [[ $BRANCH == *next* ]];then
for word in $MODULES_NEXT; do echo $word >> $DEST/cache/sdcard/etc/modules; done
else
for word in $MODULES; do echo $word >> $DEST/cache/sdcard/etc/modules; done
fi
# copy and create symlink to default interfaces configuration
cp $SRC/lib/config/interfaces.* $DEST/cache/sdcard/etc/network/
ln -sf interfaces.default $DEST/cache/sdcard/etc/network/interfaces
# mount deb storage to tmp
mount --bind $DEST/debs/ $DEST/cache/sdcard/tmp
# extract kernel version
VER=$(dpkg --info $DEST/debs/$CHOOSEN_KERNEL | grep Descr | awk '{print $(NF)}')
HEADERS_DIR="linux-headers-"$VER
VER="${VER/-$LINUXFAMILY/}"
# we need package names for dtb, uboot and headers
UBOOT_TMP="${CHOOSEN_KERNEL/image/u-boot}"
DTB_TMP="${CHOOSEN_KERNEL/image/dtb}"
FW_TMP="${CHOOSEN_KERNEL/image/firmware-image}"
HEADERS_TMP="${CHOOSEN_KERNEL/image/headers}"
HEADERS_CACHE="${CHOOSEN_KERNEL/image/cache}"
# install kernel
chroot $DEST/cache/sdcard /bin/bash -c "dpkg -i /tmp/$CHOOSEN_KERNEL >/dev/null 2>&1"
# install uboot
display_alert "Install u-boot" "$UBOOT_TMP" "info"
chroot $DEST/cache/sdcard /bin/bash -c "dpkg -i /tmp/$UBOOT_TMP >/dev/null 2>&1"
# install headers
display_alert "Install headers" "$HEADERS_TMP" "info"
chroot $DEST/cache/sdcard /bin/bash -c "dpkg -i /tmp/$HEADERS_TMP >/dev/null 2>&1"
# install firmware
display_alert "Install firmware" "$FW_TMP" "info"
chroot $DEST/cache/sdcard /bin/bash -c "dpkg -i /tmp/$FW_TMP >/dev/null 2>&1"
# install DTB
if [ -f $DEST/cache/sdcard/tmp/$DTB_TMP ]; then
display_alert "Install DTB" "$DTB_TMP" "info"
chroot $DEST/cache/sdcard /bin/bash -c "dpkg -i /tmp/$DTB_TMP >/dev/null 2>&1";
fi
# recompile headers scripts or use cache if exists
cd $DEST/cache/sdcard/usr/src/$HEADERS_DIR
if [ ! -f $DEST/cache/building/$HEADERS_CACHE.tgz ]; then
display_alert "Compile kernel headers scripts" "$VER" "info"
chroot $DEST/cache/sdcard /bin/bash -c "cd /usr/src/$HEADERS_DIR && make headers_check; make headers_install ; make scripts"
rm -rf $DEST/cache/building/repack
mkdir -p $DEST/cache/building -p $DEST/cache/building/repack/usr/src/$HEADERS_DIR -p $DEST/cache/building/repack/DEBIAN
dpkg-deb -x $DEST/debs/$HEADERS_TMP $DEST/cache/building/repack
dpkg-deb -e $DEST/debs/$HEADERS_TMP $DEST/cache/building/repack/DEBIAN
cp -R . $DEST/cache/building/repack/usr/src/$HEADERS_DIR
dpkg-deb -b $DEST/cache/building/repack $DEST/debs
rm -rf $DEST/cache/building/repack
tar czpf $DEST/cache/building/$HEADERS_CACHE".tgz" .
else
tar xzpf $DEST/cache/building/$HEADERS_CACHE".tgz"
fi
# copy boot splash image
cp $SRC/lib/bin/armbian.bmp $DEST/cache/sdcard/boot/boot.bmp
# add linux firmwares to cache image
unzip -q $SRC/lib/bin/linux-firmware.zip -d $DEST/cache/sdcard/lib/firmware
}