-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-all.sh
executable file
·832 lines (773 loc) · 38.8 KB
/
build-all.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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
#!/bin/bash
# Main-top-script Invokes selected scripts in sub folder that generates a working armhf Debian Jessie or Stretch/sid sd-card-image().img
# base kernel is the x.xx.xx-rt-ltsi kernel from the alterasoc repo (currently 4.1.22-rt23)
# ongoing work is done to get pluged into the 4.4.4-rt mainline kernel.
#
# !!! warning while using the script to generate u-boot, kernels and sd-image, is quite safe
# the (qemu)rootfs generation can be more tricky. and might potentially overwrite files in your host root file system.
# if something goes wrong underway you need to know how to use lsblk, sudo losetup -D and sudo umount -R
# the machinekit Rip cross build script is in an even higher risc zone, and it is highly recomended to install the .deb packages,
# unless you really need a local rip build for development purposes on you soc.
# as installing machinekit packages works just fine for runtime purposes ....
#
# Initially developed for the Terasic De0 Nano / Altera Atlas Soc-Fpga dev board
# v.03 New rev.
# set -v -e
# 1.initial source: make minimal rootfs on amd64 Debian Jessie, according to "How to create bare minimum Debian Wheezy rootfs from scratch"
# http://olimex.wordpress.com/2014/07/21/how-to-create-bare-minimum-debian-wheezy-rootfs-from-scratch/
#
#------------------------------------------------------------------------------------------------------
# Variables Custom settings
#------------------------------------------------------------------------------------------------------
export DEBIAN_FRONTEND=noninteractive
## Valid boards:
BOARDS=("de0_nano_soc" "de10_nano" "de1_soc" "ultra96v1" "fz3" "ultramyir" "k26-stkit")
BOARD_CLASS=("cvsoc" "mpsoc")
## Valid distros:
DISTROS=("stretch" "buster" "bullseye" "bionic" "petalinux")
## Valid archs:
DISTARCHS=("armhf" "arm64")
## Valid user names
USERS=("machinekit" "holosynth" "ubuntu" "vivado")
#HOME_DEB_MIRR_REPO_URL=http://kubuntu16-srv.holotronic.lan/debian
#HOME_DEB_MIRR_REPO_URL=http://kdeneon-ws/debian
HOME_DEB_MIRR_REPO_URL=http://bullseye-ws2/debian
shell_cmd="/bin/bash"
#DEB_EXT_REPO_URL="http://deb.debian.org//debian/"
DEB_EXT_REPO_URL="http://ftp.dk.debian.org/debian/"
#UB_EXT_REPO_URL=http://ftp.tu-chemnitz.de/pub/linux/ubuntu-ports
UB_EXT_REPO_URL="http://ports.ubuntu.com/ubuntu-ports/"
#final_repo="http://ftp.dk.debian.org/debian/"
final_deb_repo=${DEB_EXT_REPO_URL}
final_ub_repo=${UB_EXT_REPO_URL}
#local_deb_repo=${HOME_DEB_MIRR_REPO_URL}
local_deb_repo=${DEB_EXT_REPO_URL}
local_ub_repo=${UB_EXT_REPO_URL}
#local_ws=kdeneon-ws
local_ws=bullseye-ws2
#local_kernel_repo="http://${local_ws}.holotronic.lan/debian/"
#local_ub_kernel_repo="http://${local_ws}.holotronic.lan/ubuntu/"
local_kernel_repo="http://${local_ws}/debian/"
local_ub_kernel_repo="http://${local_ws}/ubuntu/"
HolosynthV_URL="https://github.com/the-snowwhite/HolosynthV/raw/2020.2.2"
## 3 part Expandable image with swap in p2
ROOTFS_TYPE=ext4
mkfs="mkfs.${ROOTFS_TYPE}"
media_swap_partition=p2
media_rootfs_partition=p3
ROOTFS_MNT="/tmp/myimage"
ROOTFS_LABEL="rootfs"
ROOTFS_IMG_END_TAG="${ROOTFS_LABEL}.img"
ext4_options="-O ^metadata_csum,^64bit"
#mkfs_options="${ext4_options}"
mkfs_options=""
## Select u-boot version:
UBOOT_VERSION="v2018.01"
#UBOOT_VERSION="v2021.01"
XIL_UBOOT_VERSION="xilinx-v2018.2"
UBOOT_MAKE_CONFIG="all"
UBOOT_IMG_FILENAME="u-boot-with-spl.sfp"
XIL_UBOOT_IMG_FILENAME="u-boot"
#XIL_BOOT_FILES_LOC="/home/mib/Development/Docker/petalinux-docker"
XIL_BOOT_FILES_LOC='/home/mib/Projects/sd-boot-files'
#RT_KERNEL_VERSION="4.9.68"
RT_KERNEL_VERSION="5.4.129"
#RT_PATCH_REV="rt60"
RT_PATCH_REV="rt61"
#ALT_GIT_KERNEL_VERSION="4.14.126"
#ALT_GIT_KERNEL_REV="-ltsi-rt"
ALT_GIT_KERNEL_NUM="5.4"
ALT_GIT_KERNEL_VERSION="5.4.114"
ALT_GIT_KERNEL_REV="-lts"
#XIL_GIT_KERNEL_VERSION="xilinx"
XIL_GIT_KERNEL_VERSION="zynqmp"
#XIL_GIT_KERNEL_REV="-v2019.1"
XIL_GIT_KERNEL_REV="-5.4"
ALT_KERNEL_CONF="socfpga_defconfig"
XIL_KERNEL_CONF="xilinx_zynqmp_defconfig"
ALT_GIT_KERNEL_TAG="${ALT_GIT_KERNEL_VERSION}${ALT_GIT_KERNEL_REV}"
XIL_GIT_KERNEL_TAG="${XIL_GIT_KERNEL_VERSION}${XIL_GIT_KERNEL_REV}"
#------------------------------------------------------------------------------------------------------
# Variables Prerequsites
#apt_cmd=apt
apt_cmd="apt-get"
#------------------------------------------------------------------------------------------------------
WORK_DIR=$(pwd)
#HOME_REPO_DIR="/opt/lampp/htdocs/repos/apt"
HOME_REPO_DIR="/var/www/html/repos/apt"
MAIN_SCRIPT_DIR="$(cd $(dirname $0) && pwd)"
SUB_SCRIPT_DIR=${MAIN_SCRIPT_DIR}/subscripts
FUNC_SCRIPT_DIR=${MAIN_SCRIPT_DIR}/functions
PATCH_SCRIPT_DIR=${MAIN_SCRIPT_DIR}/patches
DTS_DIR=${MAIN_SCRIPT_DIR}/../dts
CURRENT_DIR=`pwd`
CURRENT_DATE=`date -I`
REL_DATE=${CURRENT_DATE}
#REL_DATE=2016-03-07
#DEFGROUPS="sudo,kmem,adm,dialout,holosynth,video,plugdev,netdev,audio,tty"
## ---------------------------- Toolchain -----------------------------##
CROSS_GNU_ARCH="arm-linux-gnueabihf"
CROSS_GNU_ARCH_64="aarch64-linux-gnu"
## ------------------------------ Kernel -------------------------------##
RT_KERNEL_TAG="${RT_KERNEL_VERSION}-${RT_PATCH_REV}"
RT_KERNEL_LOCALVERSION="socfpga-${RT_KERNEL_TAG}"
#GIT_KERNEL_LOCALVERSION="socfpga-${ALT_GIT_KERNEL_TAG}"
RT_KERNEL_FOLDER="linux-${RT_KERNEL_VERSION}"
RT_KERNEL_FILE_NAME="${RT_KERNEL_FOLDER}.tar.xz"
KERNEL_URL="https://cdn.kernel.org/pub/linux/kernel/v4.x/${RT_KERNEL_FILE_NAME}"
RT_PATCH_FILE="patch-${RT_KERNEL_TAG}.patch.xz"
#RT_PATCH_URL="https://cdn.kernel.org/pub/linux/kernel/projects/rt/4.9/${RT_PATCH_FILE}"
RT_PATCH_URL="https://cdn.kernel.org/pub/linux/kernel/projects/rt/${ALT_GIT_KERNEL_NUM}/${RT_PATCH_FILE}"
ALT_GIT_KERNEL_PARENT_DIR="${CURRENT_DIR}/arm-linux-${ALT_GIT_KERNEL_TAG}-gnueabihf-kernel"
XIL_GIT_KERNEL_PARENT_DIR="${CURRENT_DIR}/arm-linux-${XIL_GIT_KERNEL_TAG}-aarch64-kernel"
RT_KERNEL_PARENT_DIR="${CURRENT_DIR}/arm-linux-${RT_KERNEL_VERSION}-gnueabihf-kernel"
RT_KERNEL_BUILD_DIR="${RT_KERNEL_PARENT_DIR}/${RT_KERNEL_FOLDER}"
ALT_GIT_KERNEL_BUILD_DIR="${ALT_GIT_KERNEL_PARENT_DIR}/linux"
XIL_GIT_KERNEL_BUILD_DIR="${XIL_GIT_KERNEL_PARENT_DIR}/linux"
#ALT_GIT_KERNEL_URL="https://github.com/altera-opensource/linux-socfpga.git"
ALT_GIT_KERNEL_URL="https://github.com/the-snowwhite/linux-socfpga.git"
XIL_GIT_KERNEL_URL="https://github.com/the-snowwhite/linux-xlnx.git"
ALT_GIT_KERNEL_BRANCH="socfpga-${ALT_GIT_KERNEL_TAG}"
XIL_GIT_KERNEL_BRANCH="socfpga64-${XIL_GIT_KERNEL_TAG}"
ALT_GIT_KERNEL_PATCH_FILE="${ALT_GIT_KERNEL_BRANCH}-changeset.patch"
XIL_GIT_KERNEL_PATCH_FILE="${XIL_GIT_KERNEL_BRANCH}-changeset.patch"
GIT_KERNEL_DIR=linux
# ------------------------------ Uboot --------------------------------##
UBOOT_GIT_URL="git://git.denx.de/u-boot.git"
XIL_UBOOT_GIT_URL="https://github.com/Xilinx/u-boot-xlnx.git"
UBOOT_DIR=uboot
UBOOT_PARENT_DIR="${CURRENT_DIR}/${UBOOT_DIR}"
UBOOT_BUILD_DIR="$UBOOT_PARENT_DIR/${UBOOT_VERSION}"
XIL_UBOOT_BUILD_DIR="$UBOOT_PARENT_DIR/${XIL_UBOOT_VERSION}"
UBOOT_CHKOUT_OPTIONS='-b tmp'
#UBOOT_CHKOUT_OPTIONS=""
HOLOSYNTH_QUAR_PROJ_FOLDER='/home/mib/Developer/the-snowwhite_git/HolosynthV/QuartusProjects/HolosynthIV_DE1SoC-Q15.0_15-inch-lcd'
#----- select global toolchain ------#
#------------------------------------------------------------------------------------------------------
# Variables Postrequsites
#------------------------------------------------------------------------------------------------------
#------------ Toolchain -------------#
CC="${CROSS_GNU_ARCH}-"
CC_64="${CROSS_GNU_ARCH_64}-"
NCORES=`nproc`
#-------------- Kernel --------------#
KERNEL_PRE_CONFIGSTRING="${ALT_KERNEL_CONF}"
POLICY_FILE=${1}/usr/sbin/policy-rc.d
EnableSystemdNetworkedLink='/etc/systemd/system/multi-user.target.wants/systemd-networkd.service'
EnableSystemdResolvedLink='/etc/systemd/system/multi-user.target.wants/systemd-resolved.service'
EnableResize2fsLink='/etc/systemd/system/multi-user.target.wants/resize2fs.service'
#-----------------------------------------------------------------------------------
# local functions
#-----------------------------------------------------------------------------------
usage()
{
echo ""
echo " -h --help (this printout)"
echo " --deps Will install build deps"
echo " --uboot Will clone, patch and build uboot Use =boardname (add =c to skip build)"
echo " --build_git-kernel Will clone, patch and build kernel from git Use =distroname=boardname (add =c to skip build)"
echo " --gitkernel2repo Will add kernel .debs to local repo Use =distroname=distarch"
echo " --mk2repo Will add machinekit .debs to local repo Use =distroname=distarch"
echo " --xf86-video-armsoc2repo Will add xf86-video-armsoc .debs to local repo Use =distroname=distarch"
echo " --gen-base-rootfs Will create single root partition image and generate base rootfs Use =distroname=distarch"
echo " --gen-base-rootfs-desktop Will create single root partition image and generate base rootfs Use =distroname=distarch"
echo " --finalize-rootfs Will create user and configure rootfs for fully working out of the box experience Use =distroname=distarch=username"
echo " --finalize-desktop-rootfs Will create user and configure rootfs with desktop for fully working out of the box experience Use =distroname=distarch=username"
echo " --inst_repo_kernel Will install kernel from local repo Use =distroname=distarch=username"
echo " --inst_repo_kernel-desktop Will install kernel from local repo in desktop version Use =distroname=distarch=username"
echo " --bindmount_rootfsimg Will mount rootfs image"
echo " --bindunmount_rootfsimg Will unmount rootfs image"
echo " --assemble_sd_img Will generate full populated sd imagefile and bmap file Use =boardname=distroname=username"
echo " --assemble_desktop_sd_img Will generate full populated fb sd imagefile and bmap file Use =boardname=distroname=username"
echo ""
}
install_deps() {
## toolchain:
# if [ ! -d ${CC_DIR} ]; then
# echo ""
# echo "Script_MSG: Toolchain not preinstalled .!"
# echo "Script_MSG: ${CC_DIR}"
# echo ""
# cd ${TOOLCHAIN_DIR}
# get_and_extract ${CC_DIR} ${CC_URL} ${CC_FILE}
# # install linaro gcc crosstoolchain dependency:
# sudo ${apt_cmd} -y install lib32stdc++6
# else
# echo ""
# echo "Script_MSG: Toolchain allready installed in -->"
# echo "Script_MSG: ${CC_DIR}"
# echo ""
# fi
install_crossbuild_arm64
install_crossbuild_armhf
install_uboot_dep
install_kernel_dep
sudo ${apt_cmd} install kpartx
install_rootfs_dep
sudo ${apt_cmd} install -y bmap-tools pbzip2 pigz
echo "MSG: deps installed"
}
## parameters: 1: board name
build_uboot() {
echo "in build_uboot()"
contains ${BOARDS[@]} ${1}
if [ "$?" -eq 0 ]; then
echo "Valid boardname = ${1} given"
if [ "${1}" == "ultra96v1" ] || [ "${1}" == "fz3" ] || [ "${1}" == "ultramyir" ] || [ "${1}" == "k26-stkit" ]; then
echo ""
echo "! Please use holosynth petalinux bsp to generate boot files"
echo ""
exit
else
# patches:
UBOOT_PATCH_FILE="u-boot-${UBOOT_VERSION}-de0-de10_nano-de1_soc-changeset.patch"
git_fetch ${UBOOT_PARENT_DIR} ${UBOOT_GIT_URL} ${UBOOT_VERSION} ${UBOOT_VERSION} ${UBOOT_VERSION} ${UBOOT_PATCH_FILE}
UBOOT_BOARD_CONFIG="socfpga_${1}_defconfig"
armhf_build "$UBOOT_PARENT_DIR/${UBOOT_VERSION}" "${UBOOT_BOARD_CONFIG}" "${UBOOT_MAKE_CONFIG}" "envtools"
fi
elif [ "${1}" == "c" ]; then
git_fetch ${UBOOT_PARENT_DIR} ${UBOOT_GIT_URL} ${UBOOT_VERSION} ${UBOOT_VERSION} ${UBOOT_VERSION} ${UBOOT_PATCH_FILE}
else
echo "--build_uboot= bad argument --> ${1}"
echo "Use (=c to skip build) =boardname"
echo "Valid boardnames are:"
echo " ${BOARDS[@]}"
fi
}
## parameters: 1: board name, 2: distro name
build_git_kernel() {
contains ${BOARDS[@]} ${1}
if [ "$?" -eq 0 ]; then
echo "Valid boardname = ${1} given"
if [ "${1}" == "ultra96v1" ] || [ "${1}" == "fz3" ] || [ "${1}" == "ultramyir" ] || [ "${1}" == "k26-stkit" ]; then
echo ""
echo "! Please use holosynth petalinux bsp to generate boot files"
echo ""
exit
else
KERNEL_PKG_VERSION="1.0"
git_fetch ${ALT_GIT_KERNEL_PARENT_DIR} ${ALT_GIT_KERNEL_URL} ${ALT_GIT_KERNEL_TAG} "origin/${ALT_GIT_KERNEL_BRANCH}" ${GIT_KERNEL_DIR} ${ALT_GIT_KERNEL_PATCH_FILE}
armhf_build "${ALT_GIT_KERNEL_BUILD_DIR}" ${ALT_KERNEL_CONF} "deb-pkg" |& tee ${CURRENT_DIR}/Logs/alt_git_kernel_deb_rt-log.txt
fi
else
if [ "${1}" != "c" ]; then
echo "--build_git_kernel bad argument --> ${1}"
echo "Use =boardname or =c --> configure and patch only"
echo "Valid boardnames are:"
echo " ${BOARDS[@]}"
else
echo ""
echo "MSG: kernel configure and patching only"
echo ""
git_fetch ${ALT_GIT_KERNEL_PARENT_DIR} ${ALT_GIT_KERNEL_URL} ${ALT_GIT_KERNEL_TAG} "origin/${ALT_GIT_KERNEL_BRANCH}" ${GIT_KERNEL_DIR} ${ALT_GIT_KERNEL_PATCH_FILE}
echo "MSG: kernel configure and patch finish"
echo ""
fi
fi
}
## parameters: 1: mount dev name, 2: distro name, 3: distro arch
gen_rootfs_image() {
zero=0;
contains ${DISTROS[@]} ${2}
if [ "$?" -eq 0 ]; then
echo "Script_MSG: Valid distroname = ${2} given"
contains ${DISTARCHS[@]} ${3}
if [ "$?" -eq 0 ]; then
echo "Script_MSG: Valid distarch = ${3} given"
create_img "1" rootfs.img
mount_imagefile rootfs.img ${1}
. ${FUNC_SCRIPT_DIR}/rootfs-func.sh
echo ""
if [ "${DESKTOP}" == "yes" ]; then
if [ "${2}" == "bionic" ]; then
run_desktop_debootstrap_bionic ${1} ${2} ${UB_EXT_REPO_URL} ${3}
echo "Script_MSG: run_desktop_debootstrap_bionic (${2}) (${3}) function return value was --> ${output}"
else
if [ "${2}" == "bullseye" ]; then
echo "Script_MSG: will run run_desktop_debootstrap_bullseye"
run_desktop_debootstrap_bullseye ${1} ${2} ${DEB_EXT_REPO_URL} ${3}
echo "Script_MSG: run_desktop_debootstrap_bullseye (${2}) (${3}) function return value was --> ${output}"
else
if [ "${2}" == "buster" ]; then
run_desktop_debootstrap_buster ${1} ${2} ${DEB_EXT_REPO_URL} ${3}
echo "Script_MSG: run_desktop_debootstrap_buster (${2}) (${3}) function return value was --> ${output}"
else
if [ "${2}" == "stretch" ]; then
run_desktop_debootstrap_stretch ${1} ${2} ${DEB_EXT_REPO_URL} ${3}
echo "Script_MSG: run_desktop_debootstrap_buster (${2}) (${3}) function return value was --> ${output}"
else
run_desktop_debootstrap ${1} ${2} ${DEB_EXT_REPO_URL} ${3}
echo "Script_MSG: run_desktop_debootstrap (${2}) (${3}) function return value was --> ${output}"
fi
fi
fi
fi
else
run_debootstrap ${1} ${2} ${DEB_EXT_REPO_URL} ${3}
echo "Script_MSG: run_debootstrap (${2}) (${3}) function return value was --> ${output}"
fi
echo ""
if [[ $output -gt $zero ]]; then
echo "Script_MSG: debootstrap failed"
unmount_binded ${1}
exit 1
else
if [ "${DESKTOP}" == "yes" ]; then
compress_rootfs ${CURRENT_DIR} ${1} "${3}_base-desktop" ${2}
# parameters: 1: work dir, 2: mount dev name, 3: comp prefix, 4 distro name
unmount_binded ${1}
sudo mv rootfs.img "${2}-${3}_base-desktop.img"
echo "Script_MSG: renamed rootfs.img to --> ${2}-${3}_base-desktop.img"
else
compress_rootfs ${CURRENT_DIR} ${1} "${3}_base" ${2}
# parameters: 1: work dir, 2: mount dev name, 3: comp prefix, 4 distro name
unmount_binded ${1}
sudo mv rootfs.img "${CURRENT_DIR}/${2}_${3}-base.img"
echo "Script_MSG: renamed rootfs.img to --> ${CURRENT_DIR}/${2}_${3}-base.img"
fi
echo "Script_MSG: finished debootstrap-only_${2}-${3} with success ... !"
fi
else
echo "--gen_rootfs_image= bad argument --> ${3}"
echo "Use =distroname=distarch"
echo "Valid distarchs are:"
echo " ${DISTARCHS[@]}"
fi
else
echo "--gen_rootfs_image= bad argument --> ${2}"
echo "Use =distroname=distarch"
echo "Valid distrosnames are:"
echo " ${DISTROS[@]}"
echo "Valid distarchs are:"
echo " ${DISTARCHS[@]}"
fi
}
## parameters: 1: mount dev name, 2: distro name, 3: distro arch, 4: user name
finalize_rootfs_image() {
# set -x
contains ${DISTROS[@]} ${2}
if [ "$?" -eq 0 ]; then
echo "Valid distroname = ${2} given"
contains ${USERS[@]} ${4}
if [ "$?" -eq 0 ]; then
echo "Valid user name = ${4} given"
contains ${DISTARCHS[@]} ${3}
if [ "$?" -eq 0 ]; then
echo "Valid distarch = ${3} given"
if [ "$(ls -A ${1})" ]; then
echo "Script_MSG: !! Found ${1} mounted .. will unmount now"
unmount_binded ${1}
fi
create_img "1" rootfs.img
mount_imagefile rootfs.img ${1}
bind_mounted ${1}
. ${FUNC_SCRIPT_DIR}/rootfs-func.sh
if [ "${DESKTOP}" == "yes" ]; then
extract_rootfs ${CURRENT_DIR} ${1} "${3}_base-desktop" ${2}
else
extract_rootfs ${CURRENT_DIR} ${1} "${3}_base" ${2}
fi
echo "Script_MSG: will now run final setup_configfiles with user name: ${4}"
setup_configfiles ${1} ${4} ${2} ${3}
echo "Script_MSG: configfiles setup finished"
initial_rootfs_user_setup_sh ${1} ${4} ${2} ${3}
finalize ${1} ${4} ${2} ${3}
sudo sync
if [ "${DESKTOP}" == "yes" ]; then
compress_rootfs ${CURRENT_DIR} ${1} "${3}_${4}_finalized-desktop" ${2}
sudo sync
unmount_binded ${1}
sudo mv rootfs.img "${CURRENT_DIR}/${2}_${3}_${4}_finalized-desktop.img"
echo "Script_MSG: renamed rootfs.img to --> ${CURRENT_DIR}/${2}_${3}_${4}_finalized.img"
else
compress_rootfs ${CURRENT_DIR} ${1} "${3}_${4}_finalized" ${2}
sudo sync
unmount_binded ${1}
sudo mv rootfs.img "${CURRENT_DIR}/${2}_${3}_${4}_finalized.img"
echo "Script_MSG: renamed rootfs.img to --> ${CURRENT_DIR}/${2}_${3}_${4}_finalized.img"
fi
sudo sync
echo ""
echo "Script_MSG: finished finalize_rootfs_image_${2}-${3}-${4} with success ... !"
else
echo "--finalize_rootfs_image= bad argument --> ${3}"
echo "Use =distroname=username=distarch"
echo "Valid distarchs are:"
echo " ${DISTARCHS[@]}"
fi
else
echo "--finalize_rootfs_image= bad argument --> ${4}"
echo "missing username"
echo "Use =distroname=username=distarch"
echo "Valid distrosnames are:"
echo " ${DISTROS[@]}"
echo "Valid usernames are:"
echo " ${USERS[@]}"
echo "Valid distarchs are:"
echo " ${DISTARCHS[@]}"
fi
else
echo "--finalize_rootfs_image= bad argument --> ${2}"
echo "Use =distroname=username=distarch"
echo "Valid distrosnames are:"
echo " ${DISTROS[@]}"
echo "Valid usernames are:"
echo " ${USERS[@]}"
echo "Valid distarchs are:"
echo " ${DISTARCHS[@]}"
fi
}
## parameters: 1: mount dev name, 2: distroname, 3: distro arch, 4: user name
inst_repo_kernel() {
contains ${DISTROS[@]} ${2}
if [ "$?" -eq 0 ]; then
echo "Valid distroname = ${2} given"
contains ${DISTARCHS[@]} ${3}
if [ "$?" -eq 0 ]; then
echo "Valid distarch = ${3} given"
contains ${USERS[@]} ${4}
if [ "$?" -eq 0 ]; then
echo "Valid user name = ${4} given"
if [ "$(ls -A ${1})" ]; then
echo "Script_MSG: !! Found ${1} mounted .. will unmount now"
unmount_binded ${1}
fi
create_img "1" rootfs.img
mount_imagefile rootfs.img ${1}
bind_mounted ${1}
if [ "${DESKTOP}" == "yes" ]; then
extract_rootfs ${CURRENT_DIR} ${1} "${3}_${4}_finalized-desktop" ${2}
else
extract_rootfs ${CURRENT_DIR} ${1} "${3}_${4}_finalized" ${2}
fi
echo "Script_MSG: will now install kernel"
if [ "${3}" == "arm64" ]; then
if [ "${2}" == "bionic" ] || [ "${2}" == "buster" ]; then
SD_KERNEL_TAG="*socfpga64-4.14"
else
SD_KERNEL_TAG="*socfpga64-5.5"
fi
if [ "${2}" == "bullseye" ]; then
sudo cp -r '/home/mib/Projects/2020v1/kernel_modules/lib/modules' ${1}/lib
else
sudo cp -r '/home/mib/Projects/2019v1/kernel_modules/lib/modules' ${1}/lib
fi
else
SD_KERNEL_TAG="${ALT_GIT_KERNEL_VERSION}-socfpga"
inst_kernel_from_local_repo ${1} ${SD_KERNEL_TAG}
fi
if [ "${DESKTOP}" == "yes" ]; then
compress_rootfs ${CURRENT_DIR} ${1} "${3}_${4}_finalized-desktop_with-kernel" ${2}
unmount_binded ${1}
sudo mv rootfs.img "${2}_${3}_${4}_finalized-desktop_with-kernel.img"
else
compress_rootfs ${CURRENT_DIR} ${1} "${3}_${4}_finalized_with-kernel" ${2}
unmount_binded ${1}
sudo mv rootfs.img "${2}_${3}_${4}_finalized_with-kernel.img"
fi
sudo sync
echo "Script_MSG: finished inst_repo_kernel_${2}-${3}-${4} with success ... !"
else
echo "--inst_repo_kernel= bad argument --> ${4}"
echo "wrong user name"
echo "Use =distroname=distarch=username"
echo "Valid user names are:"
echo " ${USERS[@]}"
echo " ${DISTARCHS[@]}"
echo "Valid distrosnames are:"
echo " ${DISTROS[@]}"
fi
else
echo "--inst_repo_kernel= bad argument --> ${3}"
echo "Use =distroname=distarch=username"
echo "Valid user names are:"
echo " ${USERS[@]}"
echo "Valid distarchs are:"
echo " ${DISTARCHS[@]}"
echo "Valid distrosnames are:"
echo " ${DISTROS[@]}"
fi
else
echo "--inst_repo_kernel= bad argument --> ${2}"
echo "Use =distroname=distarch=username"
echo "Valid user names are:"
echo " ${USERS[@]}"
echo "Valid distarchs are:"
echo " ${DISTARCHS[@]}"
echo "Valid distrosnames are:"
echo " ${DISTROS[@]}"
fi
}
## parameters: 1: mount dev name, 2: rootfs file tag, 3: board name, 4: distroname, 5: user name
assemble_full_sd_img() {
contains ${BOARDS[@]} ${3}
if [ "$?" -eq 0 ]; then
echo "Valid boardname = ${3} given"
contains ${DISTROS[@]} ${4}
if [ "$?" -eq 0 ]; then
echo "Valid distroname = ${4} given"
contains ${USERS[@]} ${5}
if [ "$?" -eq 0 ]; then
echo "Valid user name = ${5} given"
if [ "${3}" == "ultra96v1" ] || [ "${3}" == "fz3" ] || [ "${3}" == "ultramyir" ] || [ "${3}" == "k26-stkit" ]; then
SD_KERNEL_VERSION=${XIL_GIT_KERNEL_TAG}
else
SD_KERNEL_VERSION=${ALT_GIT_KERNEL_TAG}
fi
SD_FILE_PRELUDE="${4}_${5}_${SD_KERNEL_VERSION}-${3}"
if [ "${DESKTOP}" == "yes" ]; then
SD_IMG_NAME="${SD_FILE_PRELUDE}_desktop_sd_${REL_DATE}"
else
SD_IMG_NAME="${SD_FILE_PRELUDE}_console_sd_${REL_DATE}"
fi
SD_IMG_FILE="${CURRENT_DIR}/socfpga_${SD_IMG_NAME}.img"
echo "MSG: step 1 create ${SD_IMG_FILE}"
if [ "${3}" == "ultra96v1" ] || [ "${3}" == "fz3" ] || [ "${3}" == "ultramyir" ] || [ "${3}" == "k26-stkit" ]; then
echo "Script_MSG: Arm64 mpsoc detected"
echo ""
create_img "2" "${SD_IMG_FILE}" "${1}" "p2" "1"
mount_sd_imagefile ${SD_IMG_FILE} ${1} p1
echo "Copying files to boot partition"
if [ "${4}" == "petalinux" ]; then
sudo cp ${XIL_BOOT_FILES_LOC}/peta_built/images/linux/BOOT.BIN ${1}
sudo cp ${XIL_BOOT_FILES_LOC}/peta_built/images/linux/image.ub ${1}
else
if [ "${3}" == "ultra96v1" ]; then
wget ${HolosynthV_URL}/VivadoProjects/Avnet/ultra96v1-holosynthv-2020.2.2.tar.bz2 -O board.tar.bz2
elif [ "${3}" == "fz3" ]; then
wget ${HolosynthV_URL}/VivadoProjects/Myirtech/fz3/fz3-holosynthv-2020.2.tar.bz2 -O board.tar.bz2
elif [ "${3}" == "ultramyir" ]; then
wget ${HolosynthV_URL}/VivadoProjects/Myirtech/ultramyir/ultramyir-holosynthv-2020.2.2.tar.bz2 -O board.tar.bz2
elif [ "${3}" == "k26-stkit" ]; then
wget ${HolosynthV_URL}/VivadoProjects/Xilinx/k26-stkit/k26-stkit-holosynthv-2020.2.2.tar.bz2 -O board.tar.bz2
fi
tar xfS board.tar.bz2 "${3}-holosynthv-2020.2.2"/pre-built/linux/images --use-compress-program lbzip2 --strip-components 3
sudo cp images/* ${1}
# sudo cp ${XIL_BOOT_FILES_LOC}/image.ub ${1}
fi
echo "MSG: Unmounting boot partition"
unmount_binded ${1}
unmount_loopdev
echo "MSG: mounting rootfs partition"
mount_sd_imagefile ${SD_IMG_FILE} ${1} p2
echo "MSG: Extracting to rootfs partition"
if [ "${4}" == "petalinux" ]; then
sudo tar xfS ${XIL_BOOT_FILES_LOC}/peta_built/images/linux/rootfs.tar.bz2 -C ${1} --use-compress-program lbzip2
else
if [ "${DESKTOP}" == "yes" ]; then
# extract_rootfs ${CURRENT_DIR} ${1} "arm64_${5}_finalized-desktop_with-kernel" ${4}
extract_rootfs ${CURRENT_DIR} ${1} "arm64_${5}_finalized-desktop" ${4}
else
# extract_rootfs ${CURRENT_DIR} ${1} "arm64_${5}_finalized_with-kernel" ${4}
extract_rootfs ${CURRENT_DIR} ${1} "arm64_${5}_finalized" ${4}
fi
fi
bind_mounted ${1}
sudo sync
sudo rm -f ${1}/etc/resolv.conf
sudo cp /etc/resolv.conf ${1}/etc/resolv.conf
sudo cp -f ${1}/etc/apt/sources.list-local ${1}/etc/apt/sources.list
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y update'
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y autoremove'
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y upgrade'
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y install dialog'
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y install --reinstall libc6-dev'
sudo sh -c 'LANG=C.UTF-8 chroot --userspec=root:root '${1}' /bin/rm -f /etc/resolv.conf'
sudo sh -c 'LANG=C.UTF-8 chroot --userspec=root:root '${1}' /bin/ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf'
sudo cp -f ${1}/etc/apt/sources.list-final ${1}/etc/apt/sources.list
sudo cp -R ${MAIN_SCRIPT_DIR}/Auto-expand-on-boot/* ${1}
sudo ln -s ${1}/lib/systemd/system/resize2fs.service ${1}/${EnableResize2fsLink}
echo ""
echo "# ---------> Removing qemu policy file <--------------- ---------"
echo ""
if [ -f ${POLICY_FILE} ]; then
echo "removing ${POLICY_FILE}"
sudo rm -f ${POLICY_FILE}
fi
unmount_binded ${1}
unmount_loopdev
else
create_img "3" "${SD_IMG_FILE}" "${1}" "${media_rootfs_partition}"
echo "MSG: step 2 mount:"
mount_sd_imagefile ${SD_IMG_FILE} ${1} ${media_rootfs_partition}
if [ "${DESKTOP}" == "yes" ]; then
extract_rootfs ${CURRENT_DIR} ${1} "armhf_${5}_finalized-desktop_with-kernel" ${4}
else
extract_rootfs ${CURRENT_DIR} ${1} "armhf_${5}_finalized_with-kernel" ${4}
fi
bind_mounted ${1}
sudo sync
sudo rm -f ${1}/etc/resolv.conf
sudo cp /etc/resolv.conf ${1}/etc/resolv.conf
sudo cp -f ${1}/etc/apt/sources.list-local ${1}/etc/apt/sources.list
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y update'
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y autoremove'
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y upgrade'
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y install dialog'
sudo sh -c 'DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 chroot --userspec=root:root '${1}' /usr/bin/'${apt_cmd}' -y install --reinstall libc6-dev'
sudo sh -c 'LANG=C.UTF-8 chroot --userspec=root:root '${1}' /bin/rm -f /etc/resolv.conf'
sudo sh -c 'LANG=C.UTF-8 chroot --userspec=root:root '${1}' /bin/ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf'
sudo cp -f ${1}/etc/apt/sources.list-final ${1}/etc/apt/sources.list
sudo cp -R ${MAIN_SCRIPT_DIR}/Auto-expand-on-boot/* ${1}
sudo ln -s ${1}/lib/systemd/system/resize2fs.service ${1}/${EnableResize2fsLink}
set_fw_uboot_env_mnt ${LOOP_DEV} ${1}
if [ -f ${POLICY_FILE} ]; then
echo ""
echo "# ---------> Removing qemu policy file <--------------- ---------"
echo ""
echo "removing ${POLICY_FILE}"
sudo rm -f ${POLICY_FILE}
fi
unmount_binded ${1}
unmount_loopdev
install_uboot "${UBOOT_BUILD_DIR}" "${UBOOT_IMG_FILENAME}" "${SD_IMG_FILE}"
fi
echo ""
echo "# ---------> Running final steps: <--------------- ---------"
echo ""
make_bmap_image ${CURRENT_DIR} "socfpga_${SD_IMG_NAME}.img"
echo "Script_MSG: finished assemble_full_sd_img_${3}-${4}-${5} with success ... !"
echo ""
echo "# ---------> SD Imaging Completed <--------------- ---------"
echo ""
echo "Script_MSG: Image is now completely built and ready for distribution ... !"
else
echo "--assemble_full_sd_img= bad argument --> ${5}"
echo "Use =boardname=distroname=username"
echo "wrong user name"
echo "Valid user names are:"
echo " ${USERS[@]}"
fi
else
echo "--assemble_full_sd_img= bad argument --> ${4}"
echo "Use =boardname=distroname=username"
echo "wrong distro name"
echo "Valid distrosnames are:"
echo " ${DISTROS[@]}"
fi
else
echo "--assemble_full_sd_img= bad argument --> ${3}"
echo "Use =boardname=distroname=username"
echo "Valid boardnames are:"
echo " ${BOARDS[@]}"
fi
}
#------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------- #
#-----------+++ Full Flow Control +++-------------------- #
#---------------------------------------------------------------------------------- #
. ${FUNC_SCRIPT_DIR}/file_build-func.sh
mkdir -p Logs
if [ "$1" == "" ]; then
echo ""
echo "!! You ran the script without any parameters:"
usage
fi
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE1=`echo $1 | awk -F= '{print $2}'`
VALUE2=`echo $1 | awk -F= '{print $3}'`
VALUE3=`echo $1 | awk -F= '{print $4}'`
case $PARAM in
-h | --help)
usage
exit
;;
--deps)
. ${FUNC_SCRIPT_DIR}/deps-func.sh
echo "--deps --> Not fully implemented yet"
install_deps
;;
--uboot)
build_uboot "${VALUE1}"
;;
--build_git-kernel)
contains ${DISTROS[@]} ${VALUE1}
if [ "$?" -eq 0 ]; then
echo "Valid distarch = ${VALUE1} given"
build_git_kernel "${VALUE2}" "${VALUE1}"
else
echo "--gitkernel2repo bad argument --> ${VALUE1}"
echo "Use =distroname=boardname"
echo "Valid distonames are:"
echo " ${DISTROS[@]}"
fi
;;
--gitkernel2repo)
# set -x
contains ${DISTARCHS[@]} ${VALUE2}
if [ "$?" -eq 0 ]; then
echo "Valid distarch = ${VALUE2} given"
if [ ""${VALUE2}"" = "arm64" ]; then
## parameters: 1: distro name, 2: dir, 3: dist arch, 4: file filter
add2repo "${VALUE1}" ${XIL_GIT_KERNEL_PARENT_DIR} "${VALUE2}" "linux-"
else
## parameters: 1: distro name, 2: dir, 3: dist arch, 4: file filter
add2repo "${VALUE1}" ${ALT_GIT_KERNEL_PARENT_DIR} "${VALUE2}" "linux-"
fi
else
echo "--gitkernel2repo bad argument --> ${VALUE2}"
echo "Use =distroname=distarch"
echo "Valid distarchs are:"
echo " ${DISTARCHS[@]}"
fi
;;
--mk2repo)
## parameters: 1: distro name, 2: dir, 3: dist arch, 4: file filter
add2repo "${VALUE1}" "/home/mib/Development/Docker" "${VALUE2}" "machinekit"
;;
--xf86-video-armsoc2repo)
## parameters: 1: distro name, 2: dir, 3: dist arch, 4: file filter
add2repo "${VALUE1}" "/home/mib/Development/Deb-Pkg/armsoc_debs" "${VALUE2}" "xserver-xorg-video-armsoc"
;;
--gen-base-rootfs)
## parameters: 1: mount dev name, 2: image name, 3: distro name, 4: distro arch
gen_rootfs_image ${ROOTFS_MNT} "${VALUE1}" "${VALUE2}" | tee ${CURRENT_DIR}/Logs/gen-base_rootfs-log.txt
;;
--gen-base-rootfs-desktop)
DESKTOP="yes"
## parameters: 1: mount dev name, 2: image name, 3: distro name, 4: distro arch
gen_rootfs_image ${ROOTFS_MNT} "${VALUE1}" "${VALUE2}" | tee ${CURRENT_DIR}/Logs/gen-base_rootfs-log.txt
;;
--finalize-rootfs)
finalize_rootfs_image ${ROOTFS_MNT} "${VALUE1}" "${VALUE2}" "${VALUE3}" | tee ${CURRENT_DIR}/Logs/finalize_rootfs-log.txt
## parameters: 1: mount dev name, 2: image name, 3: distro name, 4: distro arch, 5: user name
;;
--finalize-desktop-rootfs)
DESKTOP="yes"
finalize_rootfs_image ${ROOTFS_MNT} "${VALUE1}" "${VALUE2}" "${VALUE3}" | tee ${CURRENT_DIR}/Logs/finalize_rootfs-log.txt
## parameters: 1: mount dev name, 2: image name, 3: distro name, 4: distro arch, 5: user name
;;
--inst_repo_kernel)sudo losetup -d
inst_repo_kernel ${ROOTFS_MNT} "${VALUE1}" "${VALUE2}" "${VALUE3}"
## parameters: 1: mount dev name, 2: bzipname end, 3: rootfs image path, 4: distroname, 5: distro arch, 6: user name
;;
--inst_repo_kernel-desktop)
DESKTOP="yes"
inst_repo_kernel ${ROOTFS_MNT} "${VALUE1}" "${VALUE2}" "${VALUE3}"
## parameters: 1: mount dev name, 2: bzipname end, 3: rootfs image path, 4: distroname, 5: distro arch, 6: user name
;;
--bindmount_rootfsimg)
mount_imagefile rootfs.img ${ROOTFS_MNT}
bind_mounted ${ROOTFS_MNT}
;;
--bindunmount_rootfsimg)
unmount_binded ${ROOTFS_MNT}
;;
--assemble_sd_img)
assemble_full_sd_img ${ROOTFS_MNT} "finalized-with-kernel" "${VALUE1}" "${VALUE2}" "${VALUE3}"
;;
--assemble_desktop_sd_img)
DESKTOP="yes"
assemble_full_sd_img ${ROOTFS_MNT} "finalized-with-kernel-and-desktop" "${VALUE1}" "${VALUE2}" "${VALUE3}"
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done
# echo "Script was run from ${CURRENT_DIR}"
# echo ""