-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_images.sh
576 lines (466 loc) · 25.4 KB
/
build_images.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
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
#!/bin/bash
if [ -z $CWD ]; then
exit
fi
get_name_rootfs() {
# name for rootfs image
image_type="$1"
KERNEL_VERSION=$(get_version $SOURCE/$KERNEL_DIR)
if [[ $image_type == server || $image_type == core ]]; then
ROOTFS="${ROOTFS_NAME}-${ARCH}-${image_type}-$BOARD_NAME-$KERNEL_VERSION-build-${ROOTFS_VERSION}"
else
ROOTFS_DESKTOP="${ROOTFS_NAME}-${ARCH}-${image_type}-$BOARD_NAME-$KERNEL_VERSION-build-${ROOTFS_VERSION}"
fi
}
clean_rootfs() {
image_type="$1"
if [[ $image_type == server || $image_type == core ]] && [[ ! -z $ROOTFS ]] && [[ -d $SOURCE/$ROOTFS ]]; then
message "" "clean" "$ROOTFS"
rm -rf $SOURCE/$ROOTFS >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
if [[ $image_type != server ]] && [[ ! -z $ROOTFS_DESKTOP ]] && [[ -d $SOURCE/$ROOTFS_DESKTOP ]] ;then
message "" "clean" "$ROOTFS_DESKTOP"
rm -rf $SOURCE/$ROOTFS_DESKTOP >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
}
prepare_rootfs() {
message "" "prepare" "$ROOTFS"
mkdir -p $SOURCE/$ROOTFS >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
}
setting_fstab() {
if [[ ! $(grep ${UUID_ROOT_FS_EXT4} "$SOURCE/$ROOTFS/etc/fstab") ]]; then
message "" "setting" "fstab"
sed -i "s:# tmpfs:tmpfs:" $SOURCE/$ROOTFS/etc/fstab
if [[ $DISTR == sla* ]]; then
echo "UUID=${UUID_ROOT_FS_EXT4} / ext4 noatime,nodiratime,data=writeback,errors=remount-ro 0 1" >> $SOURCE/$ROOTFS/etc/fstab || exit 1
if [[ $SOCFAMILY == sun20iw1p1 && $KERNEL_SOURCE != next ]]; then
echo "debugfs /sys/kernel/debug debugfs defaults 0 0" >> $SOURCE/$ROOTFS/etc/fstab
elif [[ $SOCFAMILY == bcm2* || $BOARD_NAME == x96_max_plus ]]; then
echo "UUID=${UUID_BOOT_FS_VFAT} /boot vfat defaults 0 1" >> $SOURCE/$ROOTFS/etc/fstab
elif [[ $SOCFAMILY == rk356* ]]; then
echo "UUID=${UUID_BOOT_FS_EXT4} /boot ext4 noatime,nodiratime 0 1" >> $SOURCE/$ROOTFS/etc/fstab
fi
elif [[ $DISTR == crux* ]]; then
sed -i 's:#\(shm\):\1:' $SOURCE/$ROOTFS/etc/fstab || exit 1
sed -i "/\# End of file/ i UUID=${UUID_ROOT_FS_EXT4} \/ ext4 noatime,nodiratime,data=writeback,errors=remount-ro 0 1\n" $SOURCE/$ROOTFS/etc/fstab || exit 1
if [[ $SOCFAMILY == bcm2* || $BOARD_NAME == x96_max_plus ]]; then
sed -i "/\# End of file/ i UUID=${UUID_BOOT_FS_VFAT} \/boot vfat defaults 0 1\n" $SOURCE/$ROOTFS/etc/fstab
elif [[ $SOCFAMILY == rk356* ]]; then
sed -i "/\# End of file/ i UUID=${UUID_BOOT_FS_EXT4} \/boot ext4 noatime,nodiratime 0 1\n" $SOURCE/$ROOTFS/etc/fstab
fi
fi
fi
}
setting_debug() {
message "" "setting" "uart debugging"
if [[ $DISTR == sla* ]]; then
sed -e 's/#\(ttyS[0-2]\)/\1/' \
-e '/#ttyS3/{n;/^#/i ttyFIQ0\nttyAMA0\nttyAML0
}' \
-i "$SOURCE/$ROOTFS/etc/securetty"
sed -e "s/^#\(\(s\(1\)\).*\)\(ttyS0\).*\(9600\)/\1$SERIAL_CONSOLE $SERIAL_CONSOLE_SPEED/" \
-i "$SOURCE/$ROOTFS/etc/inittab"
elif [[ $DISTR == crux* ]]; then
sed -e '/ttyS0/{n;/^/i ttyS1\nttyS2\nttyS3\nttyFIQ0\nttyAMA0\nttyAML0
}' \
-i "$SOURCE/$ROOTFS/etc/securetty"
sed -e "s/^#\(\(s\(1\)\).*\).*\(38400\).*\(ttyS0\)\(.*$\)/\1$SERIAL_CONSOLE_SPEED $SERIAL_CONSOLE\6/" \
-i "$SOURCE/$ROOTFS/etc/inittab"
fi
}
setting_motd() {
message "" "setting" "motd message"
# http://patorjk.com/ font: rectangles
[[ -f "$CWD/config/environment/motd.${DISTR}" ]] && install -m644 -D "$CWD/config/environment/motd.${DISTR}" "$SOURCE/$ROOTFS/etc/motd"
[[ -f "$CWD/config/boards/$BOARD_NAME/motd.board" ]] && cat "$CWD/config/boards/$BOARD_NAME/motd.board" >> "$SOURCE/$ROOTFS/etc/motd"
return 0
}
setting_wifi() {
message "" "setting" "wifi"
# fix wifi driver
if [[ $SOCFAMILY != rk3288 && $KERNEL_SOURCE != next ]]; then
sed -i "s#wext#nl80211#" $SOURCE/$ROOTFS/etc/rc.d/rc.inet1.conf >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
}
build_img() {
local IMAGE="$1"
local PART="1"
[[ -z "$IMAGE" ]] && exit 1
message "" "build" "image: $IMAGE"
LOOP=$(losetup -f)
losetup $LOOP $SOURCE/$IMAGE.img || exit 1
message "" "create" "partition"
if [[ $SOCFAMILY == bcm2* || $BOARD_NAME == x96_max_plus ]]; then
echo -e "\no\nn\np\n1\n$IMAGE_OFFSET\n+512M\n\nt\nc\nn\np\n2\n$IMAGE_OFFSET\n\n\n\nw" | fdisk $LOOP >> $LOG 2>&1 || true
PART="2"
else
write_uboot $LOOP
echo -e "\no\nn\np\n1\n$IMAGE_OFFSET\n\nw" | fdisk $LOOP >> $LOG 2>&1 || true
fi
partprobe $LOOP >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
# device is busy
sleep 2
message "" "create" "filesystem"
if [[ $SOCFAMILY == bcm2* || $BOARD_NAME == x96_max_plus ]]; then
mkfs.vfat ${LOOP}p1 >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
# set UUID
mkfs.vfat -i ${UUID_BOOT_FS_VFAT/-/} ${LOOP}p1 >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
mkfs.ext4 -F -m 0 -L linuxroot ${LOOP}p${PART} >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
message "" "tune" "filesystem"
tune2fs -o journal_data_writeback ${LOOP}p${PART} >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
tune2fs -O ^has_journal ${LOOP}p${PART} >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
e2fsck -yf ${LOOP}p${PART} >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
# set UUID
echo y | tune2fs -U ${UUID_ROOT_FS_EXT4} ${LOOP}p${PART} >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
message "" "create" "mount point and mount image"
mkdir -p $SOURCE/image
mount ${LOOP}p${PART} $SOURCE/image
if [[ $SOCFAMILY == bcm2* || $BOARD_NAME == x96_max_plus ]]; then
mkdir -p $SOURCE/image/boot
mount ${LOOP}p1 $SOURCE/image/boot
write_uboot $LOOP
fi
message "" "copy" "data to image"
rsync -a "$SOURCE/$IMAGE/" "$SOURCE/image/"
if [[ $SOCFAMILY == bcm2* || $BOARD_NAME == x96_max_plus ]]; then
umount $SOURCE/image/boot
fi
umount $SOURCE/image
if [[ -d $SOURCE/image ]]; then
rm -rf $SOURCE/image
fi
losetup -d $LOOP
if [[ -f $SOURCE/$IMAGE.img ]]; then
mv $SOURCE/$IMAGE.img $BUILD/$OUTPUT/$IMAGES
fi
message "" "done" "build image"
}
download_pkg() {
# get parameters
local url=$1
local type=$2
local packages
# read packages type
read_packages "${type}" packages
for pkg in ${packages}; do
category=$(echo $pkg | cut -f1 -d "/")
pkg=$(echo $pkg | cut -f2 -d "/")
if [[ ! -z ${pkg} ]];then
if [[ $USE_SLARM64_MIRROR == yes ]];then
PKG_NAME=($(wget --no-check-certificate -q -O - ${url}/${category}/ | grep -oP '(?<=\"\> ).*(?=\<\/a\>)' | egrep -o "(^$(echo $pkg | sed 's/+/\\\+/g'))-.*(t.z)" | sort -ur))
else
PKG_NAME=($(wget --no-check-certificate -q -O - ${url}/${category}/ | cut -f7 -d '>' | cut -f1 -d '<' | egrep -o "(^$(echo $pkg | sed 's/+/\\\+/g'))-.*(t.z)" | sort -ur))
fi
[[ $DISTR == crux* ]] && PKG_NAME=($(wget --no-check-certificate -q -O - ${url}/${category}/ | cut -f7 -d '>' | cut -f1 -d '<' | egrep -o "(^$(echo $pkg | sed 's/+/\\\+/g'))#.*(t.*z)" | sort -ur))
for raw in ${PKG_NAME[*]};do
if [[ $DISTR == sla* ]]; then
[[ $(echo $raw | rev | cut -d '-' -f4- | rev | grep -ox $pkg) ]] && _PKG_NAME=$raw
elif [[ $DISTR == crux* ]]; then
[[ $(echo $raw | cut -d "#" -f1 | grep -ox $pkg) ]] && _PKG_NAME=${raw/\#/%23}
fi
done
[[ -z ${_PKG_NAME} ]] && ( echo "empty download package ${category}/$pkg" >> $LOG 2>&1 && message "err" "details" && exit 1 )
message "" "download" "package $category/${_PKG_NAME/\%23/#}"
wget --no-check-certificate -c -nc -nd -np ${url}/${category}/${_PKG_NAME} -P $BUILD/$PKG/${type}/${ARCH}/${DISTR_VERSION}/${category}/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
unset _PKG_NAME
fi
done
}
install_pkg(){
if [[ $1 == server || $1 == core* || $1 == opt ]]; then
local ROOTFS="$ROOTFS"
else
local ROOTFS="$ROOTFS_DESKTOP"
fi
local type=$1
local packages
# read packages type
read_packages "${type}" packages
for pkg in ${packages}; do
category=$(echo $pkg | cut -f1 -d "/")
pkg=$(echo $pkg | cut -f2 -d "/")
if [[ ! -z ${pkg} ]];then
message "" "install" "package $category/${pkg}"
if [[ $DISTR == sla* ]]; then
ROOT=$SOURCE/$ROOTFS upgradepkg --install-new $BUILD/$PKG/${type}/${ARCH}/${DISTR_VERSION}/$category/${pkg}-* >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
elif [[ $DISTR == crux* ]]; then
[[ $type == *-update ]] && local up="-u -f"
# fixed install packages
[[ ! -e $SOURCE/$ROOTFS/var/lib/pkg/db ]] && ( install -Dm644 /dev/null $SOURCE/$ROOTFS/var/lib/pkg/db >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1 )
pkgadd ${up} --root $SOURCE/$ROOTFS $BUILD/$PKG/${type}/${ARCH}/${DISTR_VERSION}/$category/${pkg}#* >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
fi
done
}
install_kernel() {
message "" "install" "kernel ${KERNEL_VERSION}"
if [[ $DISTR == sla* ]]; then
ROOT=$SOURCE/$ROOTFS upgradepkg --install-new $BUILD/$PKG/*${SOCFAMILY}*${KERNEL_VERSION/-/_}*.txz >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
elif [[ $DISTR == crux* ]]; then
rsync -av --chown=root:root $BUILD/$PKG/kernel-${SOCFAMILY}/ $SOURCE/$ROOTFS/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
rsync -av --chown=root:root $BUILD/$PKG/kernel-modules/ $SOURCE/$ROOTFS/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
rsync -av --chown=root:root $BUILD/$PKG/kernel-firmware/ $SOURCE/$ROOTFS/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
#rsync -av --chown=root:root $BUILD/$PKG/kernel-source/ $SOURCE/$ROOTFS/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
}
setting_default_start_x() {
local de="$1"
sed "s#id:3#id:4#" -i $SOURCE/$ROOTFS_DESKTOP/etc/inittab
# starting the desktop environment
ln -sf $SOURCE/$ROOTFS_DESKTOP/etc/X11/xinit/xinitrc.${de} \
-r $SOURCE/$ROOTFS_DESKTOP/etc/X11/xinit/xinitrc
}
setting_for_desktop() {
if [[ $SOCFAMILY == sun* && -e $SOURCE/$ROOTFS_DESKTOP/boot/boot.cmd ]]; then
# adjustment for vdpau
sed -i 's#sunxi_ve_mem_reserve=0#sunxi_ve_mem_reserve=128#' "$SOURCE/$ROOTFS_DESKTOP/boot/boot.cmd"
$SOURCE/$BOOT_LOADER_DIR/tools/mkimage -C none -A arm -T script -d $SOURCE/$ROOTFS_DESKTOP/boot/boot.cmd \
"$SOURCE/$ROOTFS_DESKTOP/boot/boot.scr" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
}
setting_bootloader_move_to_disk() {
message "" "save" "bootloader data for move to disk"
# [[ ${BOARD_NAME} == station_m1 ]] && EXCLUDES+=("trust.img" "uboot.img")
for exclude in ${EXCLUDES[*]};do
EXCLUDE+="--exclude=$exclude "
done
rsync -ar $EXCLUDE $BUILD/$OUTPUT/$TOOLS/$BOARD_NAME/boot/ $SOURCE/$ROOTFS/boot >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
}
setting_system() {
message "" "setting" "system"
rsync -av --chown=root:root $CWD/system/overall/$DISTR/ $SOURCE/$ROOTFS/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
if [[ -d $CWD/system/socs/$SOCFAMILY ]]; then
rsync -av --chown=root:root $CWD/system/socs/$SOCFAMILY/ $SOURCE/$ROOTFS/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
if [[ -d $CWD/system/socs/${SOCFAMILY}-${KERNEL_SOURCE} ]]; then
rsync -av --chown=root:root $CWD/system/socs/${SOCFAMILY}-${KERNEL_SOURCE}/ $SOURCE/$ROOTFS/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
if [[ -d $CWD/system/boards/${BOARD_NAME} ]]; then
rsync -av --chown=root:root $CWD/system/boards/${BOARD_NAME}/ $SOURCE/$ROOTFS/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
if [[ -d $CWD/system/boards/${BOARD_NAME}-${KERNEL_SOURCE} ]]; then
rsync -av --chown=root:root $CWD/system/boards/${BOARD_NAME}-${KERNEL_SOURCE}/ $SOURCE/$ROOTFS/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
# setting for root
if [[ -d $SOURCE/$ROOTFS/etc/skel ]]; then
rsync -av --chown=root:root $SOURCE/$ROOTFS/etc/skel/ $SOURCE/$ROOTFS/root/ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
if [[ $DISTR == crux* ]]; then
# crux-arm added firstrun as service
sed -i 's:\(SERVICES=.*\)):\1 firstrun):g' "$SOURCE/$ROOTFS/etc/rc.conf"
# prohibit firmware update
sed -i '/\# End of file/ i \\nUPGRADE \^lib\/firmware\/\.\*$ NO\n' "$SOURCE/$ROOTFS/etc/pkgadd.conf"
fi
}
setting_alsa() {
[[ ! -z "$1" ]] && local ROOTFS="$1"
message "" "setting" "default alsa"
chmod 644 "$SOURCE/$ROOTFS/etc/rc.d/rc.pulseaudio" || exit 1
chmod 755 "$SOURCE/$ROOTFS/etc/rc.d/rc.alsa" || exit 1
mv "$SOURCE/$ROOTFS/etc/asound.conf" "$SOURCE/$ROOTFS/etc/asound.conf.new" || exit 1
}
setting_hostname() {
message "" "setting" "hostname"
if [[ $DISTR == sla* ]]; then
echo $BOARD_NAME | sed 's/_/-/g' > "$SOURCE/$ROOTFS/etc/HOSTNAME"
elif [[ $DISTR == crux* ]]; then
echo $BOARD_NAME | sed 's/_/-/g' | xargs -I {} sed -i 's:\(^HOSTNAME=\).*:\1{}:g' "$SOURCE/$ROOTFS/etc/rc.conf"
fi
}
setting_networkmanager() {
[[ ! -z "$1" ]] && local ROOTFS="$1"
message "" "setting" "networkmanager"
chmod 755 "$SOURCE/$ROOTFS/etc/rc.d/rc.networkmanager" || exit 1
}
setting_ntp() {
message "" "setting" "ntp"
if [[ $DISTR == sla* ]]; then
chmod 755 "$SOURCE/$ROOTFS/etc/rc.d/rc.ntpd" || exit 1
sed 's:^#server:server:g' -i "$SOURCE/$ROOTFS/etc/ntp.conf" || exit 1
elif [[ $DISTR == crux* ]]; then
sed 's:^#\(.*rdate.*ntp.org$\):\1:g' $SOURCE/$ROOTFS/etc/cron/daily/rdate >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
}
create_initrd() {
if [[ $MARCH == "x86_64" ]]; then
if [[ $SOCFAMILY == bcm2* || $BOARD_NAME == x96_max_plus ]]; then
find "$SOURCE/$ROOTFS/boot/" -type l -exec rm -rf {} \+ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
return 0
fi
message "" "create" "initrd"
KERNEL_VERSION=$(get_version $SOURCE/$KERNEL_DIR)
mount --bind /dev "$SOURCE/$ROOTFS/dev"
mount --bind /proc "$SOURCE/$ROOTFS/proc"
if [[ $DISTR != crux* ]]; then
# mkinitrd corrupted for ARM
export MKINITRD_ALLOWEXEC=yes && echo "export MKINITRD_ALLOWEXEC=yes" > "$SOURCE/$ROOTFS/tmp/initrd.sh"
echo "mkinitrd -R -L -u -w 2 -c -k ${KERNEL_VERSION} -m ${INITRD_MODULES} \\" >> "$SOURCE/$ROOTFS/tmp/initrd.sh"
echo " -s /tmp/initrd-tree -o /tmp/initrd.gz" >> "$SOURCE/$ROOTFS/tmp/initrd.sh"
else
echo "mkinitramfs -k ${KERNEL_VERSION} -m ${INITRD_MODULES}" > "$SOURCE/$ROOTFS/tmp/initrd.sh"
echo "mv /tmp/initrd.img-${KERNEL_VERSION} /tmp/initrd-${KERNEL_VERSION}.img" >> "$SOURCE/$ROOTFS/tmp/initrd.sh"
fi
[[ $MARCH == "aarch64" && ( $ARCH == "riscv64" || $ARCH == "arm" ) ]] && prepare_chroot "prepare"
chroot "$SOURCE/$ROOTFS" /bin/bash -c 'chmod +x /tmp/initrd.sh 2>&1 && /tmp/initrd.sh 2>&1 ' >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
[[ $MARCH == "aarch64" && ( $ARCH == "riscv64" || $ARCH == "arm" ) ]] && prepare_chroot "cleaning"
umount "$SOURCE/$ROOTFS/proc"
umount "$SOURCE/$ROOTFS/dev"
if [[ $DISTR != crux* ]]; then
pushd "$SOURCE/$ROOTFS/tmp/initrd-tree/" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
echo "initrd-${KERNEL_VERSION}" > "$SOURCE/$ROOTFS/tmp/initrd-tree/initrd-name"
find . | cpio --quiet -H newc -o | gzip -9 -n > "$SOURCE/$ROOTFS/tmp/initrd-${KERNEL_VERSION}.img" 2>/dev/null
popd >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
mkimage -A $KARCH -O linux -T ramdisk -C gzip -n 'uInitrd' -d "$SOURCE/$ROOTFS/tmp/initrd-${KERNEL_VERSION}.img" "$SOURCE/$ROOTFS/boot/uInitrd-${KERNEL_VERSION}" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
rm -rf $SOURCE/$ROOTFS/tmp/initrd* >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
if [[ $SOCFAMILY == bcm2* || $BOARD_NAME == x96_max_plus ]]; then
cp -a "$SOURCE/$ROOTFS/boot/uInitrd-${KERNEL_VERSION}" "$SOURCE/$ROOTFS/boot/uInitrd" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
find "$SOURCE/$ROOTFS/boot/" -type l -exec rm -rf {} \+ >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
else
ln -sf "$SOURCE/$ROOTFS/boot/uInitrd-${KERNEL_VERSION}" -r "$SOURCE/$ROOTFS/boot/uInitrd" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
}
setting_bootloader() {
message "" "setting" "bootloader"
# u-boot config
if [[ -f $CWD/config/boot_scripts/extlinux-$SOCFAMILY.conf ]]; then
install -Dm644 $CWD/config/boot_scripts/extlinux-$SOCFAMILY.conf "$SOURCE/$ROOTFS/boot/extlinux/extlinux.conf"
# u-boot serial inteface config
sed -e "s:%DISTR%:${DISTR}:g" \
-e "s:%ROOT_DISK%:UUID=${UUID_BOOT_FS_EXT4}:g" \
-e "s:%DEVICE_TREE_BLOB%:${DEVICE_TREE_BLOB}:g" \
-e "s:%SERIAL_CONSOLE%:${SERIAL_CONSOLE}:g" \
-e "s:%SERIAL_CONSOLE_SPEED%:${SERIAL_CONSOLE_SPEED}:g" \
-i "$SOURCE/$ROOTFS/boot/extlinux/extlinux.conf"
return 0
fi
if [[ -f $CWD/config/boot_scripts/boot-$SOCFAMILY.cmd ]]; then
install -Dm644 $CWD/config/boot_scripts/boot-$SOCFAMILY.cmd "$SOURCE/$ROOTFS/boot/boot.cmd"
# u-boot serial inteface config
sed -e "s:%SERIAL_CONSOLE%:${SERIAL_CONSOLE}:g" \
-e "s:%SERIAL_CONSOLE_SPEED%:${SERIAL_CONSOLE_SPEED}:g" \
-i "$SOURCE/$ROOTFS/boot/boot.cmd"
fi
if [[ -f $CWD/config/boot_scripts/boot-$SOCFAMILY.ini ]];then
install -Dm644 $CWD/config/boot_scripts/boot-$SOCFAMILY.ini "$SOURCE/$ROOTFS/boot/boot.ini"
# u-boot serial inteface config
sed -e "s:%SERIAL_CONSOLE%:${SERIAL_CONSOLE}:g" \
-e "s:%SERIAL_CONSOLE_SPEED%:${SERIAL_CONSOLE_SPEED}:g" \
-i "$SOURCE/$ROOTFS/boot/boot.ini"
fi
# amlogic tv box: compile boot script
if [[ -f $CWD/config/boot_scripts/boot-${BOARD_NAME//_/-}-aml_autoscript.cmd ]]; then
install -Dm644 $CWD/config/boot_scripts/boot-${BOARD_NAME//_/-}-aml_autoscript.cmd "$SOURCE/$ROOTFS/boot/aml_autoscript.cmd" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
$SOURCE/$BOOT_LOADER_DIR/tools/mkimage -C none -A $KARCH -T script -a 0 -e 0 -d $SOURCE/$ROOTFS/boot/aml_autoscript.cmd \
"$SOURCE/$ROOTFS/boot/aml_autoscript" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
if [[ -f $CWD/config/boot_scripts/boot-${BOARD_NAME//_/-}-emmc_autoscript.cmd ]]; then
install -Dm644 $CWD/config/boot_scripts/boot-${BOARD_NAME//_/-}-emmc_autoscript.cmd "$SOURCE/$ROOTFS/boot/emmc_autoscript.cmd" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
$SOURCE/$BOOT_LOADER_DIR/tools/mkimage -C none -A $KARCH -T script -a 0 -e 0 -d $SOURCE/$ROOTFS/boot/emmc_autoscript.cmd \
"$SOURCE/$ROOTFS/boot/emmc_autoscript" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
if [[ -f $CWD/config/boot_scripts/boot-${BOARD_NAME//_/-}-s905_autoscript.cmd ]]; then
install -Dm644 $CWD/config/boot_scripts/boot-${BOARD_NAME//_/-}-s905_autoscript.cmd "$SOURCE/$ROOTFS/boot/s905_autoscript.cmd" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
$SOURCE/$BOOT_LOADER_DIR/tools/mkimage -C none -A $KARCH -T script -a 0 -e 0 -d $SOURCE/$ROOTFS/boot/s905_autoscript.cmd \
"$SOURCE/$ROOTFS/boot/s905_autoscript" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
fi
# compile boot script
# for rk35xx, when using mkimage from the rockchip/radxa team/firefly team
# repository, an incorrect header is generated
[[ $SOCFAMILY != rk35* ]] && MKIMAGE_PATH="$SOURCE/$BOOT_LOADER_DIR/tools/"
[[ -f $SOURCE/$ROOTFS/boot/boot.cmd ]] && ( ${MKIMAGE_PATH}mkimage -C none -A $KARCH -T script -d $SOURCE/$ROOTFS/boot/boot.cmd \
"$SOURCE/$ROOTFS/boot/boot.scr" >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1 )
# u-boot
if [[ -f "$CWD/config/boot_scripts/uEnv-$SOCFAMILY.txt" ]]; then
install -Dm644 $CWD/config/boot_scripts/uEnv-$SOCFAMILY.txt "$SOURCE/$ROOTFS/boot/uEnv.txt"
echo "fdtfile=${DEVICE_TREE_BLOB}" >> "$SOURCE/$ROOTFS/boot/uEnv.txt"
# parameter to configure the boot of the legacy kernel
[[ $SOCFAMILY == meson-sm1 && ( $KERNEL_SOURCE != next && $BOARD_NAME != x96_max_plus ) ]] && echo "kernel=$KERNEL_SOURCE" >> "$SOURCE/$ROOTFS/boot/uEnv.txt"
fi
# set root disk
if [[ ! $(grep ${UUID_ROOT_FS_EXT4} "$SOURCE/$ROOTFS/boot/uEnv.txt") ]]; then
echo "rootdev=UUID=${UUID_ROOT_FS_EXT4}" >> "$SOURCE/$ROOTFS/boot/uEnv.txt"
fi
}
setting_governor() {
if [[ ! -z $CPU_GOVERNOR ]]; then
message "" "setting" "governor"
sed "s:#SCALING_\(.*\)=\(.*\):SCALING_\1=$CPU_GOVERNOR:g" -i $SOURCE/$ROOTFS/etc/default/cpufreq
fi
}
setting_datetime() {
message "" "setting" "datetime"
# setting build time
[[ -e $SOURCE/$ROOTFS/usr/local/bin/fakehwclock.sh ]] && touch $SOURCE/$ROOTFS/usr/local/bin/fakehwclock.sh || (message "err" "details" && exit 1) || exit 1
rm -f $SOURCE/$ROOTFS/etc/localtime* >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
ln -vfs /usr/share/zoneinfo/UTC $SOURCE/$ROOTFS/etc/localtime-copied-from >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
cp -favv $SOURCE/$ROOTFS/usr/share/zoneinfo/UTC $SOURCE/$ROOTFS/etc/localtime >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
}
setting_dhcp() {
message "" "setting" "eth0 enabled dhcp"
# set eth0 to be DHCP by default
if [[ $DISTR == sla* ]]; then
sed -i 's/USE_DHCP\[0\]=.*/USE_DHCP\[0\]="yes"/g' $SOURCE/$ROOTFS/etc/rc.d/rc.inet1.conf
elif [[ $DISTR == crux* ]]; then
echo $BOARD_NAME | sed 's/_/-/g' | xargs -I {} sed -i 's:\(^HOSTNAME=\).*:\1{}:g' "$SOURCE/$ROOTFS/etc/rc.conf"
sed -e 's:^\(DEV=\).*:\1eth0:' -e 's:^\(DHCPOPTS=.*\)":\1 \$\{DEV\}":' -i "$SOURCE/$ROOTFS/etc/rc.d/net"
fi
}
setting_ssh() {
message "" "setting" "ssh login under the root"
sed -e 's/^\(#\)\(PermitRootLogin\).*/\2 yes/g' \
-e 's/^\(#\)\(PasswordAuth.*\)/\2/g' \
-e 's/^\(#\)\(PermitEmptyPasswords\).*/\2 yes/g' \
-i "$SOURCE/$ROOTFS/etc/ssh/sshd_config"
# crux-arm added sshd in service
if [[ $DISTR == crux* ]]; then
sed -i 's:\(SERVICES=.*\)\(net\)\(.*\):\1\2 sshd\3:g' "$SOURCE/$ROOTFS/etc/rc.conf"
fi
}
setting_modules() {
if [[ ! -z ${MODULES} ]]; then
message "" "setting" "install modules: ${MODULES}"
tr ' ' '\n' <<< "${MODULES}" | sed -e 's/^/\/sbin\/modprobe /' >> "$SOURCE/$ROOTFS/etc/rc.d/rc.modules.local"
fi
if [[ ! -z ${MODULES_BLACKLIST} ]]; then
message "" "setting" "blacklist modules: ${MODULES_BLACKLIST}"
tr ' ' '\n' <<< "${MODULES_BLACKLIST}" | sed -e 's/^/blacklist /' > "$SOURCE/$ROOTFS/etc/modprobe.d/blacklist-${BOARD_NAME}.conf"
fi
}
setting_overlays() {
if [[ ! -z ${OVERLAYS} ]]; then
message "" "setting" "up dtbo files: ${OVERLAYS}"
echo "overlays=${OVERLAYS}" >> "$SOURCE/$ROOTFS/boot/uEnv.txt"
fi
if [[ ! -z $OVERLAY_PREFIX ]]; then
echo "overlay_prefix=$OVERLAY_PREFIX" >> "$SOURCE/$ROOTFS/boot/uEnv.txt"
fi
}
removed_default_xorg_conf() {
[[ ! -z "$1" ]] && local ROOTFS="$1"
if [[ -e $SOURCE/$ROOTFS/etc/X11/xorg.conf.d/xorg.conf ]]; then
message "" "setting" "removed default xorg.conf"
rm -rf "$SOURCE/$ROOTFS/etc/X11/xorg.conf.d/xorg.conf" || exit 1
fi
}
image_compression() {
local IMG="$1"
pushd $BUILD/$OUTPUT/$IMAGES >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
COMPRESSOR="zstd"
EXT="zst"
PARAMETERS="-qf12 --rm -T${CPUS}"
message "" "compression" "$COMPRESSOR $PARAMETERS ${IMG}.img"
pushd $BUILD/$OUTPUT/$IMAGES >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
$COMPRESSOR $PARAMETERS ${IMG}.img
# testing
message "" "testing" "$COMPRESSOR -qt ${IMG}.img.${EXT}"
$COMPRESSOR -qt ${IMG}.img.${EXT}
# create checksum
local CHECKSUM_EXT="sha256"
local CHECKSUM="${CHECKSUM_EXT}sum"
message "" "create" "checksum ${CHECKSUM} ${IMG}.img.${EXT}.${CHECKSUM_EXT}"
${CHECKSUM} ${IMG}.img.${EXT} > ${IMG}.img.${EXT}.${CHECKSUM_EXT}
popd >> $LOG 2>&1 || (message "err" "details" && exit 1) || exit 1
}