-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcompile.sh
More file actions
executable file
·438 lines (381 loc) · 16.9 KB
/
compile.sh
File metadata and controls
executable file
·438 lines (381 loc) · 16.9 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#!/bin/bash
echo " =#%@@@@@###%@@@@%- "
echo " =*###+ :#@* "
echo " +****. :%- "
echo " #++++ ############ :%- @@@@@@@@@@@@ "
echo " .+=== ###======++==*## *+ @@@*#%%#****#@@@ "
echo " -=-+ #+======+=.*===*# @@#**@.*@******%@ "
echo " -=-+ ##======* #====+#. @@****@ @******@@ "
echo " +:- ##+====# #***==+#+ =@@**@@@@ @****%@@ "
echo " =*=* -#*===# ## #===+## @@@***@ @@ @@#*@@@ "
echo " @@@@@@ .. ##+*#- ## #***==#= @@@@@@ @@ +@@@ @@@@@@@ @@@@@ "
echo " @@@ @@@ @@@@ ##= + ## ## #+==#- @@ @@ @@ = @@@ @@ @@ @@ @@ "
echo " @@ .@@#@@@@@@@ @@@ @@@ @@@@@@@@ .# # ## .= #-#++#= @ @ @@ * @* @@* @@ "
echo " @@ @@ @@ @@ @@@@@@@ @@ @@ # =# = + *::=# @ @+ * -@@@ @@@= "
echo " @@@ @@@ @@: @@ @@ @@ @@ # : .- : *::-# @ + # @@ @@ @@ "
echo " @@@@@@ @@@@@@@ @@@@@@ @@ @@@ =# # ## :+ #-#++#+ @ @ @@.* @@ @@@@@@ @@@@@@@@ "
echo " @@ ##+ * ## ## #+==#+ @@@@@ @@ = @@@ "
echo " @@ ##+= = ## #***==#+ @@***@ @@ #@@@ "
echo " : :#*==+#: ## #===+## @@@***@ @@ @@#*@@# "
echo " .%+ ##+====# #***==+#= +@@**@@@@ @****%@@ "
echo " %. ##======* #====*# .*- @@****@ @******@@ "
echo " %= #*======+: *===*# +-=+ @@#**@ -@******@@ "
echo " -@- +##+=====+++=*## ==-=- @@@#%@@#****%@@@ "
echo " *@* =########### -===* @@@@@@@@@@@@ "
echo " @@%. .::=++* "
echo " .#@@%%*-. .:=+**##***+. "
echo " .-+%%%%%%#***=-. "
echo ""
echo "Compiling OpenX32 Operating System for the Behringer X32 Audio-Mixing Console"
cleanup() {
tput csr 0 $(($(tput lines) - 1)) # reset scroll-region
tput rc # restore cursor
echo -e "\nScript beendet."
exit
}
trap cleanup SIGINT SIGTERM
# get terminal-infos
LINES=$(tput lines)
COLUMNS=$(tput cols)
DATA_LINES=$((LINES - 2)) # leave two lines for status-information
# define scroll-Region (row 0 to DATA_LINES)
tput csr 0 $DATA_LINES
clear
update_progress() {
local Percent=$1
local Text=$2
# save cursor-Position
tput sc
# jump to row = rowcount-2 to display separator
tput cup $((LINES - 1)) 0
printf '%*s' "$COLUMNS" '' | tr ' ' '-'
# jump to last row
tput cup $LINES 0
# display progressbar in green
echo -ne "\e[32m[COMPILING OPENX32]: $Percent% - Current: $Text\e[0m"
# move cursor back to old position for next script-output
tput rc
}
# ================ CHECK SCRIPT-PARAMETERS ================
# Standardmäßig werden alle Schritte ausgeführt
COMPILE_UBOOT=true
COMPILE_LINUX=true
COMPILE_BUSYBOX=true
COMPILE_SOFTWARE=true
COMPILE_MUSL=true
USE_LZMA=false
USE_ENCRYPTION=false
CREATE_SSHKEY=false
# Argumente verarbeiten
while [[ $# -gt 0 ]]; do
case $1 in
--skip-uboot)
COMPILE_UBOOT=false
shift # Nächstes Argument prüfen
;;
--skip-linux)
COMPILE_LINUX=false
shift
;;
--skip-busybox)
COMPILE_BUSYBOX=false
shift
;;
--skip-software)
COMPILE_SOFTWARE=false
shift
;;
--glibc)
COMPILE_MUSL=false
shift
;;
--lzma)
USE_LZMA=true
shift
;;
--encrypted)
USE_ENCRYPTION=true
shift
;;
--create-sshkey)
CREATE_SSHKEY=true
shift
;;
*)
echo "Unknown Parameter: $1"
exit 1
;;
esac
done
update_progress 0 "Prepare compilation..."
# we are patching some files in the submodules to mitigate a full fork
# configuration-files
# u-boot-configuration
if ! diff -q files/config_uboot u-boot/.config >/dev/null 2>&1; then
cp files/config_uboot u-boot/.config
echo "Update u-boot/.config (changed content)"
else
echo "u-boot-config is up to date."
fi
# linux-configuration
if ! diff -q files/config_linux linux/.config >/dev/null 2>&1; then
cp files/config_linux linux/.config
echo "Update linux/.config (changed content)"
else
echo "linux-config is up to date."
fi
# busybox-configuration
if ! diff -q files/config_busybox software/busybox/.config >/dev/null 2>&1; then
cp files/config_busybox software/busybox/.config
echo "Update software/busybox/.config (changed content)"
else
echo "busybox-config is up to date."
fi
cp files/meminit.txt software/pyatk/bin/
# patched source-files
cp files/imximage.cfg u-boot/board/freescale/mx25pdk/imximage.cfg
cp files/mx25pdk.c u-boot/board/freescale/mx25pdk/mx25pdk.c
cp files/mx25pdk.h u-boot/include/configs/mx25pdk.h
cp files/imx25-pdk.dts linux/arch/arm/boot/dts/nxp/imx/imx25-pdk.dts
# custom boot logo - fullscreen -> console has only 1 line!
# cp files/linux-boot-logo_final.ppm linux/drivers/video/logo/logo_linux_clut224.ppm
export COPTS="-mcpu=arm926ej-s -Os -fno-caller-saves -pipe -funit-at-a-time -msoft-float -fno-plt -fno-unwind-tables -fno-asynchronous-unwind-tables"
if [ "$COMPILE_MUSL" = true ]; then
export PATH=/opt/cross/bin:$PATH
else
export PATH=/usr/bin:$PATH
fi
# =================== Loader =======================
update_progress 5 "Compile Miniloader..."
cd miniloader
make
if [ "$COMPILE_UBOOT" = true ]; then
update_progress 10 "Compile U-Boot..."
cd ../u-boot
ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make -j$(nproc)
fi
# =================== Linux =======================
if [ "$COMPILE_LINUX" = true ]; then
update_progress 20 "Compile Linux..."
cd ../linux
ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make -j$(nproc) zImage
ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make -j$(nproc) dtbs
mkimage -A ARM -O linux -T kernel -C none -a 0x80060000 -e 0x80060000 -n "Linux kernel (OpenX32)" -d arch/arm/boot/zImage /tmp/uImage
cd ..
fi
# =================== Busybox =======================
if [ "$COMPILE_BUSYBOX" = true ]; then
update_progress 40 "Compile busybox..."
cd software/busybox
ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make -j$(nproc) \
CFLAGS="-flto -fwhole-program -flto-partition=none $COPTS" \
AR=arm-linux-gnueabi-gcc-ar \
RANLIB=arm-linux-gnueabi-gcc-ranlib
ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make -j$(nproc) install \
CFLAGS="-flto -fwhole-program -flto-partition=none $COPTS" \
AR=arm-linux-gnueabi-gcc-ar \
RANLIB=arm-linux-gnueabi-gcc-ranlib
cd ../..
cp -rP /tmp/busybox_install/bin initramfs_root/
cp -rP /tmp/busybox_install/sbin initramfs_root/
cp -rP /tmp/busybox_install/linuxrc initramfs_root/
fi
# =============== Software-Tools ===================
if [ "$COMPILE_SOFTWARE" = true ]; then
cd software
update_progress 45 "Compile x32sdconfig..."
cd x32sdconfig
./compile.sh
cd ..
update_progress 50 "Compile x32ctrl..."
cd x32ctrl
make -j$(nproc)
cd ..
update_progress 55 "Compile dropbear..."
cd dropbear
./configure \
--disable-pam \
--disable-harden \
--disable-lastlog \
--disable-utmp \
--disable-zlib \
--disable-utmpx \
--disable-wtmp \
--disable-wtmpx \
--enable-bundled-libtom \
--disable-pututxline \
--host=arm-linux-gnueabi \
--disable-zlib \
--disable-syslog \
host_alias=arm-linux ac_cv_func_getpass=yes \
LTM_CFLAGS="-flto -fwhole-program -flto-partition=none $COPTS" \
CFLAGS="-g0 -flto -fwhole-program -flto-partition=none $COPTS -DDISABLE_X11FWD -DARGTYPE=3" \
AR=arm-linux-gnueabi-gcc-ar \
RANLIB=arm-linux-gnueabi-gcc-ranlib
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" MULTI=1 SCPPROGRESS=1
cp dropbearmulti ../bin/
cd ..
update_progress 60 "Compile fb-vnc-server..."
cd libvncserver
rm -r build
mkdir build && cd build
if [ "$COMPILE_MUSL" = true ]; then
cmake .. -DCMAKE_TOOLCHAIN_FILE=../../../files/libvncserver_musl_toolchain.cmake \
-DCMAKE_C_FLAGS="-s $COPTS -D_GNU_SOURCE"
else
cmake .. -DCMAKE_TOOLCHAIN_FILE=../../../files/libvncserver_toolchain.cmake \
-DCMAKE_C_FLAGS="-s $COPTS -D_GNU_SOURCE"
fi
cmake --build .
make -j$(nproc)
cd ../..
cd framebuffer-vncserver
rm -r build
mkdir -p build && cd build
VNC_LIB_ROOT=/tmp/armv5_libs
cp ../../libvncserver/build/libvncserver.so.1 $VNC_LIB_ROOT
if [ "$COMPILE_MUSL" = true ]; then
ZLIB_LIB_PATH=/opt/cross/arm-openwrt-linux-muslgnueabi/lib
cmake .. -DCMAKE_TOOLCHAIN_FILE=../../files/framebuffer-vncserver_musl.cmake \
-DLIBVNC=$VNC_LIB_ROOT/libvncserver.so.1 \
-DCMAKE_INSTALL_PREFIX={$VNC_LIB_ROOT} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="$COPTS -I${VNC_LIB_ROOT}/include" \
-DCMAKE_PREFIX_PATH="${VNC_LIB_ROOT}" \
-DCMAKE_FIND_ROOT_PATH="${VNC_LIB_ROOT}" \
-DCMAKE_EXE_LINKER_FLAGS="-L${VNC_LIB_ROOT}/lib -L${ZLIB_LIB_PATH} -lvncserver -lpthread -ldl"
else
ZLIB_LIB_PATH=/usr/lib/arm-linux-gnueabi
cmake .. -DCMAKE_TOOLCHAIN_FILE=../../files/framebuffer-vncserver.cmake \
-DLIBVNC=$VNC_LIB_ROOT/libvncserver.so.1 \
-DCMAKE_INSTALL_PREFIX={$VNC_LIB_ROOT} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="$COPTS -I${VNC_LIB_ROOT}/include" \
-DCMAKE_PREFIX_PATH="${VNC_LIB_ROOT}" \
-DCMAKE_FIND_ROOT_PATH="${VNC_LIB_ROOT}" \
-DCMAKE_EXE_LINKER_FLAGS="-L${VNC_LIB_ROOT}/lib -L${ZLIB_LIB_PATH} -lvncserver -lpthread -ldl"
fi
make -j$(nproc)
cd ../..
# exit software-directory
cd ..
fi
update_progress 75 "Copy and optimize binaries..."
# copy tools to initramFS
mkdir -p initramfs_root/openx32
mkdir -p initramfs_root/lib
cp software/bin/x32sdconfig initramfs_root/openx32/
cp software/bin/x32ctrl initramfs_root/openx32/
cp software/dropbear/dropbearmulti initramfs_root/openx32/
cd initramfs_root/openx32/ && ln -sf dropbearmulti dropbear && cd ../../
cd initramfs_root/openx32/ && ln -sf dropbearmulti dbclient && cd ../../
cd initramfs_root/openx32/ && ln -sf dropbearmulti dropbearconvert && cd ../../
cd initramfs_root/openx32/ && ln -sf dropbearmulti dropbearkey && cd ../../
cd initramfs_root/openx32/ && ln -sf dropbearmulti scp && cd ../../
cp software/framebuffer-vncserver/build/framebuffer-vncserver initramfs_root/openx32/
# copy general libraries
cp software/libvncserver/build/libvncserver.so.1 initramfs_root/lib/libvncserver.so.1
if [ "$COMPILE_MUSL" = true ]; then
# copy specific libraries for musl
cp $(arm-linux-gnueabi-gcc -print-file-name=libc.so) initramfs_root/lib/libc.so
cp $(arm-linux-gnueabi-gcc -print-file-name=libstdc++.so.6) initramfs_root/lib/libstdc++.so.6
cp $(arm-linux-gnueabi-gcc -print-file-name=libgcc_s.so.1) initramfs_root/lib/libgcc_s.so.1
cd initramfs_root/lib/ && ln -sf libc.so ld-musl-arm.so.1 && cd ../../
else
# copy specific libraries for glibc
cp $(arm-linux-gnueabi-gcc -print-file-name=libc.so.6) initramfs_root/lib/libc.so.6
cp $(arm-linux-gnueabi-gcc -print-file-name=ld-linux.so.3) initramfs_root/lib/ld-linux.so.3
cp $(arm-linux-gnueabi-gcc -print-file-name=libgcc_s.so.1) initramfs_root/lib/libgcc_s.so.1
cp $(arm-linux-gnueabi-gcc -print-file-name=libstdc++.so.6) initramfs_root/lib/libstdc++.so.6
cp $(arm-linux-gnueabi-gcc -print-file-name=libm.so.6) initramfs_root/lib/libm.so.6
cp $(arm-linux-gnueabi-gcc -print-file-name=libresolv.so.2) initramfs_root/lib/libresolv.so.2
cp $(arm-linux-gnueabi-gcc -print-file-name=libcrypt.so.1) initramfs_root/lib/libcrypt.so.1
fi
# =================== Optimize binaries =======================
arm-linux-gnueabi-strip initramfs_root/lib/*
arm-linux-gnueabi-strip initramfs_root/openx32/*
arm-linux-gnueabi-strip initramfs_root/bin/*
arm-linux-gnueabi-strip initramfs_root/sbin/*
# =================== Create MOTD =======================
GITREV=$(git describe --tags --always --dirty)
DATE=$(date +%d.%m.%Y)
echo " ____ __ ______ ____" > initramfs_root/etc/motd
echo " / __ \\ \\ \\ / /___ \\__ \\" >> initramfs_root/etc/motd
echo "| | | |_ __ ___ _ __ \\ V / __) | ) |" >> initramfs_root/etc/motd
echo "| | | | '_ \\ / _ \\ '_ \\ > < |__ < / /" >> initramfs_root/etc/motd
echo "| |__| | |_) | __/ | | |/ . \\ ___) / /_ " >> initramfs_root/etc/motd
echo " \\____/| .__/ \\___|_| |_/_/ \\_\\____/____|" >> initramfs_root/etc/motd
echo " | | https://www.openx32.com" >> initramfs_root/etc/motd
echo " |_| " >> initramfs_root/etc/motd
echo "---------------------------------------------------" >> initramfs_root/etc/motd
echo "OpenX32 ${GITREV} ${DATE}" >> initramfs_root/etc/motd
echo "---------------------------------------------------" >> initramfs_root/etc/motd
# =================== Create SSH-KEY =======================
if [ "$CREATE_SSHKEY" = true ]; then
cd initramfs_root/etc/dropbear
dropbearkey -t ed25519 -f openx32_key
cd ../../../
fi
# =================== Create InitramFS =======================
update_progress 80 "Create initramFS..."
cd initramfs_root
mkdir -p dev proc sys etc mnt home usr
rm /tmp/uramdisk.bin
fakeroot sh -c "find . -print0 | cpio --null -ov --format=newc > /tmp/initramfs.cpio"
if [ "$USE_LZMA" = true ]; then
# LZMA is compressing much better, but the startup will be much slower
rm /tmp/initramfs.cpio.lzma
xz --format=lzma -9 -e --lzma1=dict=1MiB /tmp/initramfs.cpio
mkimage -A ARM -O linux -T ramdisk -C lzma -a 0 -e 0 -n "Ramdisk Image" -d /tmp/initramfs.cpio.lzma /tmp/uramdisk.bin
else
# GZIP compression
rm /tmp/initramfs.cpio.gz
gzip -9 /tmp/initramfs.cpio
mkimage -A ARM -O linux -T ramdisk -C none -a 0 -e 0 -n "Ramdisk Image" -d /tmp/initramfs.cpio.gz /tmp/uramdisk.bin
fi
cd ..
# =================== Binary-Blob =======================
rm /tmp/openx32.bin
# Miniloader at offset 0x000000: will be started by i.MX Serial Download Program
update_progress 85 "Merge binary-files...Miniloader -> openx32.bin"
dd if=miniloader/miniloader.bin of=/tmp/openx32.bin conv=notrunc
# U-Boot at offset 0x0000C0: will be started by Miniloader
update_progress 86 "Merge binary-files...U-Boot -> openx32.bin"
dd if=u-boot/u-boot.bin of=/tmp/openx32.bin bs=8 seek=$((0x18)) conv=notrunc
# Linux-Kernel at offset 0x060000 (384 kiB for Miniloader + U-Boot): will be started by U-Boot
update_progress 87 "Merge binary-files...Linux-Kernel -> openx32.bin"
dd if=/tmp/uImage of=/tmp/openx32.bin bs=512 seek=$((0x300)) conv=notrunc
# DeviceTreeBlob at offset 0x300000 (~3 MiB for Kernel)
update_progress 88 "Merge binary-files...DeviceTreeBlob -> openx32.bin"
dd if=linux/arch/arm/boot/dts/nxp/imx/imx25-pdk.dtb of=/tmp/openx32.bin bs=512 seek=$((0x1980)) conv=notrunc
# InitramFS at offset 0x310000 (~64kiB for DeviceTreeBlob)
update_progress 89 "Merge binary-files...InitramFS -> openx32.bin"
dd if=/tmp/uramdisk.bin of=/tmp/openx32.bin bs=512 seek=$((0x1A00)) conv=notrunc
update_progress 90 "Merge binary-files...Finalize openx32.bin"
dd if=/dev/zero of=/tmp/openx32.bin bs=1 count=100 oflag=append conv=notrunc
# =================== DCP-Loader-File =======================
update_progress 95 "Creating final DCP-Loader-File..."
if [ "$USE_ENCRYPTION" = true ]; then
# creating encrypted OpenX32 DCP-Image
mkdir -p /tmp/openx32/binary
cp /tmp/openx32.bin /tmp/openx32/binary/dcpapp.bin
/opt/dcp-tool/dcp-tool -c /tmp/dcp_corefs_openx32.run "OpenX32 ${GITREV} ${DATE} - https://www.OpenX32.com" /tmp/openx32/
else
# creating unencrypted test-application
perl software/dcpapp/dcp_compiler.pl /tmp/openx32.bin:binary/dcpapp.bin /tmp/dcp_corefs_openx32.run
fi
update_progress 100 "Done."
echo " ____ __ ______ ____"
echo " / __ \\ \\ \\ / /___ \\__ \\"
echo "| | | |_ __ ___ _ __ \\ V / __) | ) |"
echo "| | | | '_ \\ / _ \\ '_ \\ > < |__ < / /"
echo "| |__| | |_) | __/ | | |/ . \\ ___) / /_ "
echo " \\____/| .__/ \\___|_| |_/_/ \\_\\____/____|"
echo " | | https://www.openx32.com"
echo " |_| "
echo "Your version of OpenX32 is ready and it smells like fresh bread rolls. Yummie."
echo "The image with Miniloader, u-Boot, Linux Kernel, Ramdisk and DeviceTreeBlob is stored as /tmp/dcp_corefs_openx32.run"
# Am Ende die Scroll-Region wieder freigeben
tput csr 0 $((LINES - 1))
tput cup $LINES 0
echo ""