-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild
executable file
·959 lines (871 loc) · 33.7 KB
/
build
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
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
#!/bin/bash
set -e
listTargets() {
find device -name config |while read r; do
dirname $r |cut -d/ -f2-
done
}
usage() {
printf '%s\n' "Usage: $0 [ -v VERSION ] target"
printf '%s\n' " -v: Use ${BASE_DISTRO} VERSION (default: cooker)"
printf '%s\n' " -K: Keep already existing build root (default: no)"
printf '%s\n' "Available targets:"
listTargets
}
run() {
local SCRIPT="$1"
shift
printf '%s\n' "Running $SCRIPT"
if [ -e $OURDIR/device/$TARGET/$SCRIPT ]; then
. $OURDIR/device/$TARGET/$SCRIPT "$@"
else
local T="$TARGET"
local DONE=false
while [ "$T" != "." ]; do
T="$(dirname $T)"
if [ -e $OURDIR/device/$T/generic/$SCRIPT ]; then
. $OURDIR/device/$T/generic/$SCRIPT "$@"
break
fi
done
fi
}
isnative() {
local CPU=$(printf '%s\n' $1 |cut -d- -f1)
local ABI=$(printf '%s\n' $1 |rev |cut -d- -f1 |rev)
local NATIVECPU=$(uname -m)
local NATIVEABI=gnu
if ldd /bin/sh |grep -q musl; then
NATIVEABI=musl
fi
if printf '%s\n' $NATIVECPU |grep -q ^arm; then
NATIVEABI="${NATIVEABI}eabihf"
NATIVECPU="armv7hnl"
fi
[ "$CPU" = "znver1" ] && CPU=x86_64
if [ "$CPU" = "$NATIVECPU" ] && [ "$ABI" = "$NATIVEABI" ]; then
return 0
else
return 1
fi
}
rescanPartitions () {
udevadm settle -t 5
partx -a $1 || :
partx -u $1
udevadm settle -t 5
# Workaround for /dev/loopXpY device nodes not being created
# inside the isobuilder container in ABF -- this shouldn't
# run in a normal environment (but can't hurt either)
for i in $(partx -go NR $1); do
if ! [ -e $1p$i ]; then
local LDEV="$(basename $1)"
local NODE="$(cat /sys/block/$LDEV/${LDEV}p${i}/dev)"
mknod /dev/${LDEV}p${i} b ${NODE/:*/} ${NODE/*:/}
fi
done
}
if [ "$(id -u)" != "0" ]; then
printf '%s\n' "Need root privileges to set ownership of extracted files."
exec sudo $0 -u "$(id -un)" "$@"
exit 1
fi
OURDIR="$(realpath $(dirname $0))"
cd "$OURDIR"
PACKAGES=""
PACKAGES_FROM_CMDLINE=""
PACKAGESETS="core"
SERVICES="dbus-broker NetworkManager"
WEAKDEPS=""
if command -v clang-cpp &>/dev/null; then
CPP="clang-cpp"
elif command -v cpp &>/dev/null; then
CPP="cpp"
else
HOSTDEPS="$HOSTDEPS clang"
CPP="clang-cpp"
fi
# for rosa it is http://abf-downloads.rosalinux.ru
ABF_DOWNLOADS="${ABF_DOWNLOADS:-https://abf-downloads.openmandriva.org}"
# for rosa it is rosa-linux-gnu
BASE_TRIPLET="${BASE_TRIPLET:-openmandriva-linux-gnu}"
# ver prefix needed only for rosalinux
# should be just rosa
VER_PREFIX="${VER_PREFIX:-}"
# for rosa it is 2021.1
OMV_VERSION="${OMV_VERSION:-cooker}"
# for rosa it is RosaLinux
BASE_DISTRO="${BASE_DISTRO:-OpenMandriva-Lx}"
BUILDUSER="$(ls -ld ${OURDIR} |cut -d' ' -f3)"
# install xldd only on OpenMandriva
if [ $BASE_DISTRO = "OpenMandriva-Lx" ]; then
XLDD="xldd"
CROSS_ARM="cross-armv7hnl-openmandriva-linux-gnueabihf-gcc"
else
XLDD=""
CROSS_ARM=""
fi
# for rosa it is rosa-repos-main
PRE_PACKAGES="${PRE_PACKAGES:-distro-release-repos}"
[ -z "$FINAL" ] && FINAL=false
OS_VERSION=""
IDENTIFIER=""
while getopts "d:Fi:K:n:o:p:P:r:s:S:u:v:w:W" opt; do
case $opt in
d)
SDDMSESSION="$OPTARG"
;;
F)
FINAL=true
;;
i)
IDENTIFIER="$OPTARG"
;;
v)
OMV_VERSION="$OPTARG"
;;
o)
OS_VERSION="$OPTARG"
;;
p)
PACKAGES_FROM_CMDLINE="$PACKAGES_FROM_CMDLINE ${OPTARG}"
;;
P)
if ! [ -e "$OURDIR/packagesets/${OPTARG}.pkgs" ]; then
printf '%s\n' "Unknown packageset: ${OPTARG}" >&2
exit 1
fi
PACKAGESETS="$PACKAGESETS ${OPTARG}"
;;
r)
EXTRA_REPOS="$EXTRA_REPOS ${OPTARG}"
;;
s)
SERVICES="$SERVICES ${OPTARG}"
;;
S)
SERVICES="$(printf '%s\n' $SERVICES |sed -e "s,^${OPTARG} ,,;s, ${OPTARG} , ,;s,^${OPTARG}\$,,;s, ${OPTARG}\$,,")"
;;
u)
BUILDUSER="${OPTARG}"
;;
w)
WEAKDEPS="--setopt=install_weak_deps=True"
;;
W)
WEAKDEPS="--setopt=install_weak_deps=False"
;;
K)
KEEP_OLD_ROOT=true
;;
n)
IMAGENAME="${OPTARG}"
;;
*)
printf '%s\n' "Unknown option $opt" >&2
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ -z "$1" ]; then
usage
exit 1
fi
if [ -z "$OS_VERSION" ]; then
[ -n "$IDENTIFIER" ] && OS_VERSION="$IDENTIFIER-"
OS_VERSION="$OS_VERSION$OMV_VERSION"
if [ "$FINAL" = "false" ]; then
# BUILD_ID is set by abf
if [ -n "${BUILD_ID}" ]; then
OS_VERSION="${OS_VERSION}-${BUILD_ID}"
else
OS_VERSION="${OS_VERSION}-$(date +%Y%m%d)"
fi
fi
fi
TARGET="$1"
if ! [ -e device/$TARGET/config ]; then
# Allow abbreviations, e.g. db410c instead of qualcomm/db410c
for i in $(find device -name config); do
if printf '%s\n' $i |grep -q "$TARGET/config\$"; then
TARGET="$(dirname $i |cut -d/ -f2-)"
break
fi
done
fi
if ! [ -e device/$TARGET/config ]; then
printf '%s\n' "Invalid target $TARGET"
usage
exit 1
fi
SHORTTARGET="$(basename $TARGET)"
printf '%s\n' "Building ${BASE_DISTRO} $OMV_VERSION image for $TARGET"
run config
[ -n "$HWPACKAGESETS" ] && PACKAGESETS="$PACKAGESETS $HWPACKAGESETS"
# ===================================================================
# Prepare host system
# ===================================================================
if [ -z "$ARCH" ]; then
printf '%s\n' "$TARGET doesn't specify ARCH, assuming aarch64" >&2
ARCH=aarch64
fi
TRIPLET=$ARCH-${BASE_TRIPLET}
case $ARCH in
aarch64)
KERNELARCH=arm64
QEMUARCH=aarch64
# We allow overriding KERNELTARGET in configs because
# some bootloaders support gzipped images, some don't
[ -z "$KERNELTARGET" ] && KERNELTARGET=Image.gz
BOOTEFI=bootaa64.efi
EFIARCH=arm64-efi
DTBS="dtbs"
;;
arm*)
KERNELARCH=arm
QEMUARCH=arm
TRIPLET="${TRIPLET}eabihf"
KERNELTARGET=zImage
BOOTEFI=bootarm.efi
EFIARCH=arm-efi
DTBS="dtbs"
;;
x86_64|znver1)
KERNELARCH=x86
QEMUARCH=x86_64
KERNELTARGET=vmlinux
BOOTEFI=bootx64.efi
EFIARCH=x86_64-efi
DTBS=""
;;
i686)
KERNELARCH=x86
QEMUARCH=i386
KERNELTARGET=vmlinuz
BOOTEFI=bootia32.efi
EFIARCH=i386-efi
DTBS=""
;;
riscv64)
KERNELARCH=riscv
QEMUARCH=$ARCH
KERNELTARGET=vmlinux
BOOTEFI=boot${ARCH}.efi
EFIARCH=${ARCH}-efi
DTBS="dtbs"
;;
*)
# Anything here is possibly wrong...
KERNELARCH=$ARCH
QEMUARCH=$ARCH
KERNELTARGET=vmlinuz
BOOTEFI=boot${ARCH}.efi
EFIARCH=${ARCH}-efi
DTBS="dtbs"
;;
esac
NATIVEBUILD=false
[ "$ARCH" = "$(uname -m)" ] && NATIVEBUILD=true
if [ -n "$KERNEL" ]; then
# We aren't using a packaged kernel, so we need the right toolchain...
if isnative $TRIPLET; then
HOSTDEPS="$HOSTDEPS gcc"
else
HOSTDEPS="$HOSTDEPS cross-$TRIPLET-gcc cross-$TRIPLET-libc cross-$TRIPLET-kernel-headers"
fi
if [ "$ARCH" = "aarch64" ]; then
# Many aarch64 kernels (e.g. rk3399) need a 32-bit ARM compiler
# to target a helper Cortex-M0 etc.
HOSTDEPS="$HOSTDEPS ${CROSS_ARMHF}"
fi
# Build dependencies for binary formats etc.
HOSTDEPS="$HOSTDEPS pkgconfig(libelf) zstd"
fi
$NATIVEBUILD || HOSTDEPS="$HOSTDEPS qemu-static-$QEMUARCH"
# vim-common is for xxd, used to decode EDID information for pinebookpro
HOSTDEPS="$HOSTDEPS bc curl make pahole clang gcc dtc glibc-devel bison flex lib64openssl-devel hostname patch vim-common rpm-build kpartx util-linux gptfdisk e2fsprogs f2fs-tools"
if [ -n "$UBOOT_CONFIG" ]; then
HOSTDEPS="$HOSTDEPS uboot-tools"
fi
if [ -n "$HOSTDEPS" ] && [ -z "$KEEP_OLD_ROOT" ]; then
if ! dnf -y --refresh --nogpgcheck install $HOSTDEPS; then
for i in $HOSTDEPS; do
if ! rpm -q $i &>/dev/null; then
printf '%s\n' "Couldn't install needed HOST tools. Make sure you're running current ${BASE_DISTRO}"
printf '%s\n' "or install $i manually"
exit 1
fi
done
fi
# Make sure the binfmt handler knows about any qemu-static bits we may have installed...
# We also need ld-linux-aarch64.so.1 symlinked to where some binary headers expect it
if [ !"$ARCH" = "aarch64" ]; then
HOSTDEPS="$HOSTDEPS"
printf '%s\n' ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64-static:' >/proc/sys/fs/binfmt_misc/register || :
[ -e /lib/ld-linux-aarch64.so.1 ] || ln -s /usr/$TRIPLET/lib/ld-linux-aarch64.so.1 /lib/
fi
fi
# ===================================================================
# Parse packagesets and add target specific packageset extensions
# (e.g. graphics drivers for the gui package set) specified in the
# config (e.g. HWPACKAGES_gui=...)
# Also, re-parse packages specified on the command line in case they
# contain macros
# ===================================================================
if printf '%s' $ARCH |grep -qE '(64|znver1)'; then
LIB=lib64
else
LIB=lib
fi
CPP="$CPP -undef -nostdinc -P -E -Wno-unused-command-line-argument -I$OURDIR/packagesets -DLIB(x)=${LIB}##x -DARCH_$ARCH=1 -DTARGET_$(printf '%s\n' $TARGET|sed -e 's,/,_,g;s,-,_,g')=1 -DTARGET_$(printf '%s' $SHORTTARGET|sed -e 's,/,_,g;s,-,_,g')=1"
for ps in $PACKAGESETS; do
CPP="$CPP -DPACKAGESET_${ps}=1"
done
for p in $PACKAGES_FROM_CMDLINE; do
PACKAGES="$PACKAGES $(printf '%s' $p |$CPP -)"
done
for ps in $PACKAGESETS; do
eval "XP=\${HWPACKAGES_${ps}}"
if [ -n "$XP" ]; then
PACKAGES="$PACKAGES $(printf '%s' $XP |$CPP -)"
fi
while read p; do
PACKAGES="$PACKAGES $p"
done < <($CPP $OURDIR/packagesets/${ps}.pkgs)
done
# ===================================================================
# Build kernel if necessary
# ===================================================================
SMPFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
[ "$SMPFLAGS" = "-j" ] && SMPFLAGS="-j8"
if isnative $TRIPLET; then
CCOMP=""
else
CCOMP="CROSS_COMPILE=/usr/bin/$TRIPLET-"
fi
# This should usually not be used in production builds.
# It keeps the kernel rpm from a previous run, just
# building everything else.
# It is primarily useful while debugging package installation
# or debugging bootup errors in the running system.
#KEEP_KERNEL_RPM=true
if [ -n "$KEEP_KERNEL_RPM" ]; then
ls $OURDIR/kernel-rpm/RPMS/*/*.rpm 2>/dev/null || unset KEEP_KERNEL_RPM
fi
if [ -n "$KEEP_KERNEL_RPM" ]; then
KERNELRPM="$(ls $OURDIR/kernel-rpm/RPMS/*/*.rpm)"
elif [ -n "$KERNEL" ]; then
printf '%s\n' "Building $TARGET kernel"
KERNELREPO="$(printf '%s' $KERNEL |cut -d'#' -f1)"
KERNELBRANCH="$(printf '%s' $KERNEL |cut -d'#' -f2-)"
[ -n "$KERNELBRANCH" ] && KERNELBRANCH="-b $KERNELBRANCH"
[ -z "$KERNEL_CONFIG" ] && KERNEL_CONFIG="defconfig"
rm -rf kernel
if [ -z "$KERNELBUNDLE" ]; then
if ! git clone --depth 1 $KERNELBRANCH $KERNELREPO kernel; then
# KERNELBRANCH is a tag or commit hash, not a branch
git clone $KERNELREPO kernel
cd kernel
git checkout $KERNELBRANCH $(echo $KERNELBRANCH |cut -b4-)
cd ..
fi
else
# Very special case, but the megi kernel that relies on it
# is very important for several targets...
git clone $KERNELREPO kernel
cd kernel
curl -o .bundle "$KERNELBUNDLE"
git fetch .bundle '+refs/heads/*:refs/remotes/bundle/*'
git checkout -b $KERNELBRANCH bundle/$KERNELBRANCH
git gc --aggressive --prune=all
rm .bundle
cd ..
fi
cd kernel
# Bogus naming, e.g. "rock-5b.config", in some kernels
if echo $KERNEL_CONFIG |grep -q '\.config'; then
cp arch/arm64/configs/${KERNEL_CONFIG} arch/arm64/configs/${KERNEL_CONFIG/.config/_defconfig}
KERNEL_CONFIG=${KERNEL_CONFIG/.config/_defconfig}
fi
[ -e scripts/lld-version.sh ] && sed -i -e "s,' ' -f 2,' ' -f 4," scripts/lld-version.sh
PN=1
for i in ${OURDIR}/device/${TARGET}/kernel-patches/*.patch ${OURDIR}/device/${TARGET}/kernel-patches/*.diff; do
printf '%s\n' "Applying $(basename $i)" >&2
[ -e "$i" ] && patch -p1 -b -z .b${PN}~ <$i
PN=$((PN+1))
done
for i in ${OURDIR}/device/${TARGET}/kernel-patches/*.gitpatch; do
printf '%s\n' "Applying $(basename $i)" >&2
[ -e "$i" ] && git apply $i
done
# Get rid of bracketed version identifier that freaks out
# rpm's dependency generator
sed -i -E 's,(.*)"\["(.*)"\]"(.*),\1"-"\2""\3,' drivers/scsi/aacraid/linit.c
run download_kernel_extras
[ -e ${OURDIR}/device/${TARGET}/../generic/${KERNEL_CONFIG} ] && cp -f ${OURDIR}/device/${TARGET}/../generic/${KERNEL_CONFIG} arch/${KERNELARCH}/configs/
[ -e ${OURDIR}/device/${TARGET}/${KERNEL_CONFIG} ] && cp -f ${OURDIR}/device/${TARGET}/${KERNEL_CONFIG} arch/${KERNELARCH}/configs/
# Get rid of trailing + in version identifiers
sed -i -e 's,"+","",g' scripts/setlocalversion
if [ -n "$KERNEL_EXTRA_CFLAGS_GCC" ] && [ "$KERNEL_GCC" = "yes" ]; then
sed -i -e "s|-std=gnu89|$KERNEL_EXTRA_CFLAGS_GCC -std=gnu89|g" Makefile
fi
if [ -n "$KERNEL_EXTRA_CFLAGS_CLANG" ] && [ "$KERNEL_GCC" != "yes" ]; then
sed -i -e "s|-std=gnu89|$KERNEL_EXTRA_CFLAGS_CLANG -std=gnu89|g" Makefile
fi
if [ -n "$KERNEL_EXTRA_CFLAGS" ]; then
sed -i -e "s|-std=gnu89|$KERNEL_EXTRA_CFLAGS -std=gnu89|g" Makefile
fi
# Get rid of the "-dirty" name in localversion
git add -A || :
git commit -am "Apply OpenMandriva patches" || :
if [ "$KERNEL_GCC" = "yes" ]; then
make $SMPFLAGS ARCH=$KERNELARCH $CCOMP $KERNEL_CONFIG include/config/kernel.release
else
make $SMPFLAGS ARCH=$KERNELARCH $CCOMP LLVM=1 $KERNEL_CONFIG include/config/kernel.release
fi
KERNELVERSION=$(cat include/config/kernel.release)
KERNELVERSION_NUM="$(printf '%s\n' $KERNELVERSION |cut -d- -f1)"
if printf '%s\n' $KERNELVERSION |grep -q -- -; then
KERNELVERSION_EXTRA="$(printf '%s\n' $KERNELVERSION |cut -d- -f2- |sed -e 's,-,.,g')"
fi
cd ..
rm -rf kernel-rpm
mkdir kernel-rpm
tar cf kernel-rpm/kernel.tar kernel
zstd -T0 -19 --rm kernel-rpm/kernel.tar
cat >kernel-rpm/kernel-$SHORTTARGET.spec <<EOF
%define debug_package %{nil}
Name: kernel-$SHORTTARGET
Version: $KERNELVERSION_NUM
EOF
if [ -n "$KERNELVERSION_EXTRA" ]; then
printf '%s\n' "Release: 0.$KERNELVERSION_EXTRA.1" >>kernel-rpm/kernel-$SHORTTARGET.spec
else
printf '%s\n' "Release: 1" >>kernel-rpm/kernel-$SHORTTARGET.spec
fi
cat >>kernel-rpm/kernel-$SHORTTARGET.spec <<EOF
Summary: kernel for $SHORTTARGET devices
# Tarball generated from the $KERNELBRANCH branch
# of $KERNELREPO
# by os-image-builder
Source0: kernel.tar.zst
License: GPLv2
Provides: kernel = %{EVRD}
Provides: kernel-release = %{EVRD}
EOF
cat >>kernel-rpm/kernel-$SHORTTARGET.spec <<EOF
%description
kernel for $SHORTTARGET devices
%prep
%autosetup -p1 -n kernel
%if "%{_vendor}" == "rosa"
%define _modulesdir /usr/lib/modules
grep -Irl /lib/modules | xargs sed -i -e 's,/lib/modules,%{_modulesdir},g'
%else
%define _modulesdir /lib/modules
%endif
%build
EOF
# CROSS_COMPILE_ARM32 is a Sony-ism, but doesn't hurt anywhere else, so we can specify it unconditionally
# FIXME we have to use LD=/usr/bin/$TRIPLET-ld.bfd, for some reason yet to be debugged, aarch64
# kernels linked with lld don't boot on emag/oci-aarch64 (kernel 5.16-rc4, clang 13.0.0)
if isnative $TRIPLET; then
if [ "$KERNEL_GCC" = "yes" ]; then
KERNEL_LD="LD=ld.bfd"
fi
else
if [ "$KERNEL_GCC" = "yes" ]; then
KERNEL_LD="LD=/usr/bin/$TRIPLET-ld.bfd"
fi
fi
if [ "$KERNEL_GCC" = "yes" ]; then
printf '%s\n' "%make_build $SMPFLAGS ARCH=$KERNELARCH $CCOMP CROSS_COMPILE_ARM32=armv7hnl-linux-gnueabihf- $KERNEL_LD $KERNEL_CONFIG" >>kernel-rpm/kernel-$SHORTTARGET.spec
else
printf '%s\n' "%make_build $SMPFLAGS ARCH=$KERNELARCH CLANG_TRIPLE=$TRIPLET- $CCOMP CROSS_COMPILE_ARM32=armv7hnl-linux-gnueabihf- CC=clang LLVM=1 $KERNEL_CONFIG" >>kernel-rpm/kernel-$SHORTTARGET.spec
fi
if [ -n "$KERNEL_EXTRACONFIG" ]; then
printf '%s\n' "scripts/config $KERNEL_EXTRACONFIG" >>kernel-rpm/kernel-$SHORTTARGET.spec
fi
if [ "$KERNEL_GCC" = "yes" ]; then
printf '%s\n' "make syncconfig ARCH=$KERNELARCH $CCOMP CROSS_COMPILE_ARM32=armv7hnl-linux-gnueabihf- $KERNEL_LD" >>kernel-rpm/kernel-$SHORTTARGET.spec
printf '%s\n' "%make_build $KERNELTARGET $DTBS modules ARCH=$KERNELARCH $CCOMP CROSS_COMPILE_ARM32=armv7hnl-linux-gnueabihf- $KERNEL_LD" >>kernel-rpm/kernel-$SHORTTARGET.spec
else
printf '%s\n' "make syncconfig ARCH=$KERNELARCH CLANG_TRIPLE=$TRIPLET- $CCOMP CROSS_COMPILE_ARM32=armv7hnl-linux-gnueabihf- CC=clang LLVM=1" >>kernel-rpm/kernel-$SHORTTARGET.spec
printf '%s\n' "%make_build $KERNELTARGET $DTBS modules ARCH=$KERNELARCH CLANG_TRIPLE=$TRIPLET- $CCOMP CROSS_COMPILE_ARM32=armv7hnl-linux-gnueabihf- CC=clang LLVM=1" >>kernel-rpm/kernel-$SHORTTARGET.spec
fi
cat >>kernel-rpm/kernel-$SHORTTARGET.spec <<EOF
%install
# Install kernel modules, if any
make $SMPFLAGS V=1 INSTALL_MOD_STRIP=1 modules_install ARCH=$KERNELARCH $CCOMP INSTALL_MOD_PATH=%{buildroot} INSTALL_DTBS_PATH=%{buildroot}/boot CROSS_COMPILE_ARM32=armv7hnl-linux-gnueabihf- $KERNEL_LD
# And DTBs -- allow failure here because x86 and old kernels (onyx08 and friends)
# don't have the dtbs_install target
make $SMPFLAGS INSTALL_MOD_STRIP=1 dtbs_install ARCH=$KERNELARCH $CCOMP INSTALL_MOD_PATH=%{buildroot} INSTALL_DTBS_PATH=%{buildroot}/boot CROSS_COMPILE_ARM32=armv7hnl-linux-gnueabihf- $KERNEL_LD || :
mkdir -p %{buildroot}/boot
EOF
if [ "$ARCH" = "x86_64" -o "$ARCH" = "znver1" ]; then
cat >>kernel-rpm/kernel-$SHORTTARGET.spec <<EOF
cp $KERNELTARGET %{buildroot}/boot/vmlinuz-$KERNELVERSION
EOF
else
cat >>kernel-rpm/kernel-$SHORTTARGET.spec <<EOF
cp arch/$KERNELARCH/boot/$KERNELTARGET %{buildroot}/boot/vmlinuz-$KERNELVERSION
EOF
fi
cat >>kernel-rpm/kernel-$SHORTTARGET.spec <<EOF
%files
/boot/*
%{_modulesdir}/*
EOF
chown -R $BUILDUSER kernel-rpm
cd kernel-rpm
echo /sbin/runuser -u $BUILDUSER -- rpmbuild -bb --target $ARCH --define \"_sourcedir $(pwd)\" --define \"_specdir $(pwd)\" --define \"_srcrpmdir $(pwd)/SRPMS\" --define \"_rpmdir $(pwd)/RPMS\" --define \"_builddir $(pwd)/BUILD\" --define \"_buildrootdir $(pwd)/BUILDROOT\" kernel-$SHORTTARGET.spec >$OURDIR/kernelbuild.sh
/sbin/runuser -u $BUILDUSER -- rpmbuild -bb --target $ARCH --define "_sourcedir $(pwd)" --define "_specdir $(pwd)" --define "_srcrpmdir $(pwd)/SRPMS" --define "_rpmdir $(pwd)/RPMS" --define "_builddir $(pwd)/BUILD" --define "_buildrootdir $(pwd)/BUILDROOT" kernel-$SHORTTARGET.spec 2>&1 |tee $OURDIR/kernelbuild.log
cd ..
KERNELRPM="$(ls $OURDIR/kernel-rpm/RPMS/*/*.rpm)"
else
printf '%s\n' "KERNEL not specified in $TARGET config - assuming packaged kernel"
fi
# ===================================================================
# Generate root filesystem
# ===================================================================
# First of all let's find the right repo list...
ROOTDIR="${BASE_DISTRO}-$OMV_VERSION-$ARCH-root"
# Make sure we don't have any dangerous bind mounts left...
cleanup() {
for mp in /proc /sys /sys/firmware/efi/efivars /dev/pts /dev; do
[ -e "$OURDIR/$ROOTDIR$mp" ] && umount -Rq "$OURDIR/$ROOTDIR$mp" || :
done
}
trap "cleanup; exit 1" ERR SIGINT SIGTERM
if [ -z "$KEEP_OLD_ROOT" ]; then
cleanup
rm -rf "$ROOTDIR"
fi
if [ ! -d "$ROOTDIR" ]; then
mkdir -p $ROOTDIR
# setup-rootfs can do things like create a filesystem and
# loopback mount it on $ROOTDIR -- useful for boards that
# need to generate a FS image file rather than a rootfs
# tarball or so.
[ -e $OURDIR/device/$TARGET/setup-rootfs ] && . $OURDIR/device/$TARGET/setup-rootfs
# Poor man's version of "dnf install --installroot=" --
# need to get the repository configs from rpm packages
# without having the repositories configured...
PKGS=${ABF_DOWNLOADS}/${VER_PREFIX}${OMV_VERSION}/repository/$ARCH/main/release/
printf '%s\n' $PKGS
curl -s -L $PKGS |grep '^<a' |cut -d'"' -f2 >PACKAGES
for i in $PRE_PACKAGES; do
P=$(grep "^$i-[0-9].*" PACKAGES |tail -n1)
if [ "$?" != "0" ]; then
printf '%s\n' "Can't find $i package for target" >&2
exit 1
fi
curl -O $PKGS/$P
rpm -r $OURDIR/$ROOTDIR -Uvh --ignorearch --nodeps $P
done
# Don't use mirrors when creating the image
sed -i -e '/mirror.openmandriva.org/d;s,^ ,baseurl=,' "$OURDIR/$ROOTDIR"/etc/yum.repos.d/*.repo
if printf '%s\n' ${VER_PREFIX}${OMV_VERSION} |grep -q '^[0-9]'; then
DNF_VERSION=release
# This also needs to work before the rock symlink is updated on
# a new release...
dnf config-manager --installroot "$OURDIR/$ROOTDIR" --set-disabled rock-$ARCH
dnf config-manager --installroot "$OURDIR/$ROOTDIR" --set-disabled rock-updates-$ARCH
dnf config-manager --installroot "$OURDIR/$ROOTDIR" --set-enabled release-$ARCH
dnf config-manager --installroot "$OURDIR/$ROOTDIR" --set-enabled release-updates-$ARCH
else
DNF_VERSION="${VER_PREFIX}${OMV_VERSION}"
fi
if [ -n "$EXTRA_REPOS" ]; then
for i in $EXTRA_REPOS; do
dnf config-manager --installroot "$OURDIR/$ROOTDIR" --set-enabled $DNF_VERSION-$ARCH-$i
done
fi
if ! $NATIVEBUILD; then
# Make sure we can run %post scripts in the chroot
mkdir -p $OURDIR/$ROOTDIR/usr/bin
cp /usr/bin/qemu-$QEMUARCH-static $OURDIR/$ROOTDIR/usr/bin/
fi
# FIXME workaround for ldd being broken on aarch64 (at least in qemu)
# (causes dracut to miss bash's dependencies)
if [ "$ARCH" = "aarch64" ] && [ "$BASE_DISTRO" == "OpenMandriva-Lx" ]; then
PACKAGES="$PACKAGES ${XLDD}"
fi
if [ "$NEED_INITRD" != "no" ]; then
PACKAGES="$PACKAGES dracut"
fi
if [ "$USE_UEFI" = "yes" ]; then
PACKAGES="$PACKAGES efibootmgr grub2-efi"
fi
if [ "$USE_SYSTEMD_UEFI" = "yes" ]; then
PACKAGES="$PACKAGES efibootmgr systemd-boot"
fi
PACKAGES="$PACKAGES $HWPACKAGES"
# Mount relevant filesystems so %post scripts can access
# the likes of /dev/null and /dev/urandom
for mp in /proc /sys /sys/firmware/efi/efivars /dev /dev/pts; do
mkdir -p "$OURDIR/$ROOTDIR$mp" || :
mount --bind -o ro $mp "$OURDIR/$ROOTDIR$mp"
done
if [ -z $KEEP_OLD_ROOT ]; then
if ! dnf -y install --nogpgcheck --installroot=$OURDIR/$ROOTDIR --releasever=$OMV_VERSION --forcearch=$ARCH $WEAKDEPS $PACKAGES $KERNELRPM; then
if [ -e $OURDIR/$ROOTDIR/bin/sh ]; then
cat >&2 <<EOF
WARNING: dnf returned an error code, but it looks like installation finished.
This is likely something (relatively) harmless like a package's post-install
script failing - but you may want to double-check.
EOF
else
printf '%s\n' "ERROR: dnf failed without installing what looks like a workable system."
exit 1
fi
fi
fi
# FIXME (continued) workaround for ldd being
# broken on aarch64 (at least in qemu)
# (causes dracut to miss bash's dependencies)
if [ "$ARCH" = "aarch64" ] && [ "$BASE_DISTRO" == "OpenMandriva-Lx" ]; then
mv $OURDIR/$ROOTDIR/usr/bin/ldd $OURDIR/$ROOTDIR/usr/bin/ldd.glibc
ln -sf xldd $OURDIR/$ROOTDIR/usr/bin/ldd
fi
# set up system environment, default root password is omv
systemd-firstboot --root="$OURDIR/$ROOTDIR" \
--locale="en_US.UTF-8" \
--keymap="us" \
--timezone="Europe/London" \
--hostname="omv-$(printf '%s\n' ${TARGET} | cut -d '/' -f 2 |sed -e 's,+,,g')" \
--root-password-hashed='$6$rG3bQ92hkTNubV1p$5qPB9FoXBhNcSE1FOklCoEDowveAgjSf2cHYVwCENZaWtgpFQaRRRN5Ihwd8nuaKMdA1R1XouOasJ7u5dbiGt0' \
--force
# set up dirs
systemd-tmpfiles --root="$OURDIR/$ROOTDIR" -E --remove || :
# set up users
systemd-sysusers --root="$OURDIR/$ROOTDIR" || :
# Remove anything created by systemd-tmpfiles and friends that will
# be hidden by tmpfs mounts anyway
rm -rf "$OURDIR/$ROOTDIR/run/* $OURDIR/$ROOTDIR/tmp/*"
# Remove anything created by systemd-tmpfiles and friends that will
# be hidden by tmpfs mounts anyway
rm -rf "$OURDIR/$ROOTDIR/run/* $OURDIR/$ROOTDIR/tmp/*"
if [ "$CREATE_DEFAULT_USER" != "no" ]; then
if ! grep -q '^omv:' $OURDIR/$ROOTDIR/etc/passwd; then
# Create omv user (password omv)
printf '%s\n' 'omv:x:1001:1001::/home/omv:/bin/bash' >>$OURDIR/$ROOTDIR/etc/passwd
printf '%s\n' 'omv:$6$rG3bQ92hkTNubV1p$5qPB9FoXBhNcSE1FOklCoEDowveAgjSf2cHYVwCENZaWtgpFQaRRRN5Ihwd8nuaKMdA1R1XouOasJ7u5dbiGt0:17302:0:99999:7:::' >>$OURDIR/$ROOTDIR/etc/shadow
printf '%s\n' 'omv:x:1001:' >>$OURDIR/$ROOTDIR/etc/group
# Add the omv user to important groups...
for group in audio dialout input lp lpadmin network render sambashare screen storage tty users video wheel; do
sed -i -e "s,$group:.*\$,&omv," $OURDIR/$ROOTDIR/etc/group
done
cp -a $OURDIR/$ROOTDIR/etc/skel $OURDIR/$ROOTDIR/home/omv
chown -R 1001:1001 $OURDIR/$ROOTDIR/home/omv
fi
# If sddm is installed, set it up to autologin as omv
if [ -z "$SDDMSESSION" ]; then
for desktop in plasma lxqt openbox failsafe; do
if [ -e $OURDIR/$ROOTDIR/usr/share/xsessions/$desktop.desktop ]; then
SDDMSESSION=$desktop
break
fi
done
if [ -z "$SDDMSESSION" ]; then
for desktop in plasma-mobile plasmawayland weston; do
if [ -e "$OURDIR/$ROOTDIR"/usr/share/wayland-sessions/$desktop.desktop ]; then
SDDMSESSION=$desktop
break
fi
done
fi
fi
if [ -z "$NO_AUTOLOGIN" ] && [ -e "$OURDIR/$ROOTDIR/etc/sddm.conf" ]; then
sed -i -e "s,^User=,User=omv," $OURDIR/$ROOTDIR/etc/sddm.conf
fi
if [ -n "$SDDMSESSION" ] && [ -e "$OURDIR/$ROOTDIR/etc/sddm.conf" ]; then
sed -i -e "s,^Session=,Session=$SDDMSESSION," $OURDIR/$ROOTDIR/etc/sddm.conf
fi
fi
if [ -z "$KERNEL" ]; then
# Using packaged kernel -- let's determine KERNELVERSION
# nevertheless so we can run dracut and possibly configure
# bootloaders
KERNELVERSION=$(ls --sort=time $OURDIR/$ROOTDIR/boot/vmlinuz-* 2>/dev/null|head -n1 |sed -e 's,.*vmlinuz-,,')
fi
# Handle post-processing scripts needed by packagesets
for PACKAGESET in $PACKAGESETS; do
PACKAGESET_POST="$PACKAGESET.post"
PACKAGESET_POST_PATH="$OURDIR/packagesets/$PACKAGESET_POST"
if [ -e "$PACKAGESET_POST_PATH" ]; then
cp "$PACKAGESET_POST_PATH" "$OURDIR/$ROOTDIR/tmp/$PACKAGESET_POST"
chroot "$OURDIR/$ROOTDIR" "/tmp/$PACKAGESET_POST"
rm "$OURDIR/$ROOTDIR/tmp/$PACKAGESET_POST"
fi
done
run setup-system-files
if [ -e $OURDIR/device/$TARGET/install-openmandriva.in ]; then
sed -e "s,@OS_VERSION@,${OS_VERSION},g;s,@OMV_VERSION@,${OMV_VERSION},g" device/$TARGET/install-openmandriva.in >$OURDIR/$ROOTDIR/home/omv/install-openmandriva
chmod +x $OURDIR/$ROOTDIR/home/omv/install-openmandriva
fi
if [ "$NEED_INITRD" != "no" ] || [ "$USE_UEFI" = "yes" ] || [ "$USE_SYSTEMD_UEFI" != "yes" ] && [ -n "$KERNELVERSION" ]; then
if [ "$NEED_INITRD" != "no" ]; then
run generate-initrd
fi
if [ "$USE_UEFI" = "yes" ]; then
printf '%s\n' "Creating ESP for GRUB."
mkdir -p $OURDIR/$ROOTDIR/boot/efi/EFI/BOOT
chroot "$OURDIR/$ROOTDIR" /usr/bin/grub2-mkimage -o /boot/efi/EFI/BOOT/$BOOTEFI -O $EFIARCH -d /usr/lib/grub/$EFIARCH -p /EFI/BOOT fat part_gpt part_msdos normal boot linux configfile loopback chain efifwsetup efi_gop ls search search_label search_fs_uuid search_fs_file gfxterm gfxterm_background gfxterm_menu gfxmenu test all_video loadenv exfat ext2 part_msdos part_gpt loadenv ls chain btrfs xfs ntfs all_video efifwsetup efinet font probe video loopback gzio xzio zstd
fi
if [ "$USE_SYSTEMD_UEFI" = "yes" ]; then
printf '%s\n' "Creating ESP for systemd-boot."
mkdir -p $OURDIR/$ROOTDIR/boot/efi
# create ESP directory scheme for systemd-boot
for i in "$OURDIR/$ROOTDIR/boot/efi/EFI/BOOT" "$OURDIR/$ROOTDIR/boot/efi/EFI/Linux" "$OURDIR/$ROOTDIR/boot/efi/EFI/systemd" "$OURDIR/$ROOTDIR/boot/efi/loader/entries"; do
mkdir -p $i
done
if [ ! -s "$OURDIR/$ROOTDIR"/usr/lib/kernel/cmdline ]; then
printf '%s\n' 'root=LABEL=OMVAA64' >> "$OURDIR/$ROOTDIR"/usr/lib/kernel/cmdline
for i in ${CMDLINE[@]}; do
printf '%s\n' "$i" >> "$OURDIR/$ROOTDIR"/usr/lib/kernel/cmdline
done
fi
# chroot "$OURDIR/$ROOTDIR" SYSTEMD_RELAX_ESP_CHECKS=1 bootctl install --esp-path=/boot/efi
cp -a "$OURDIR/$ROOTDIR"/usr/lib/systemd/boot/efi/systemd-${BOOTEFI} $OURDIR/$ROOTDIR/boot/efi/EFI/BOOT/${BOOTEFI}
cp -a "$OURDIR/$ROOTDIR"/usr/lib/systemd/boot/efi/systemd-${BOOTEFI} $OURDIR/$ROOTDIR/boot/efi/EFI/systemd
MACH_ID=$(chroot $OURDIR/$ROOTDIR systemd-machine-id-setup --print)
mkdir -p "$OURDIR/$ROOTDIR/boot/efi/$MACH_ID"
chroot "$OURDIR/$ROOTDIR" kernel-install -v add "$KERNELVERSION" "/boot/vmlinuz-$KERNELVERSION"
# tricky part, looks like uboot does not support gziped kernel image in UEFI mode
# so lets gunzip it
mv "$OURDIR/$ROOTDIR/boot/efi/$MACH_ID/$KERNELVERSION"/linux "$OURDIR/$ROOTDIR/boot/efi/$MACH_ID/$KERNELVERSION"/linux.gz
gunzip "$OURDIR/$ROOTDIR/boot/efi/$MACH_ID/$KERNELVERSION"/linux.gz
cat >$OURDIR/$ROOTDIR/boot/efi/loader/loader.conf<<EOF
default $MACH_ID-$KERNELVERSION.conf
timeout 10
EOF
sed -i -e 's,boot\/efi\/,\/,g' "$OURDIR/$ROOTDIR"/boot/efi/loader/entries/$MACH_ID-$KERNELVERSION.conf
if [ -n "${DTB}" ] && ! grep -q devicetree $OURDIR/$ROOTDIR/boot/efi/loader/entries/$MACH_ID-$KERNELVERSION.conf; then
install -D -m644 "$OURDIR/$ROOTDIR/boot/dtb-$KERNELVERSION/${DTB}.dtb" "$OURDIR/$ROOTDIR/boot/efi/$MACH_ID/$KERNELVERSION/dtb/${DTB}.dtb"
printf '%s\n' "devicetree "/$MACH_ID/$KERNELVERSION"/dtb/$DTB.dtb" >> $OURDIR/$ROOTDIR/boot/efi/loader/entries/$MACH_ID-$KERNELVERSION.conf
fi
dd if=/dev/random of="$OURDIR/$ROOTDIR/boot/efi/loader/"random-seed bs=512 count=1
chmod +x -R $OURDIR/$ROOTDIR/boot/efi
fi
fi
# Initialize the random seed to something, systemd might hang forever on
# e.g. an embedded board that doesn't get entropy
dd if=/dev/random of="$OURDIR/$ROOTDIR"/var/lib/systemd/random-seed bs=512 count=1
chmod 0600 "$OURDIR/$ROOTDIR"/var/lib/systemd/random-seed
# Make sure default services are started
for i in "$OURDIR/$ROOTDIR"/lib/systemd/system-preset/*.preset; do
while read r; do
TYPE="$(printf '%s\n' $r |awk '{ print $1; }')"
if [ "$TYPE" = "enable" ] || [ "$TYPE" = "disable" ]; then
[ "$(printf '%s\n' "$r" |awk '{ print $2; }')" = '*' ] && continue
chroot "$OURDIR/$ROOTDIR" /usr/bin/systemctl $r || :
fi
done < $i
done
# Some devices require special alsa configs to initialize
# (e.g. unmuted DAC).
# Since /var/lib/alsa/asound.state is restored (and stored) by
# our systemd files, it's better to just initialize that (and
# not overwrite newly saved states by a package update) than to
# ship the file in a package.
if [ -e "$OURDIR"/device/$TARGET/asound.state ]; then
mkdir -p "$OURDIR/$ROOTDIR"/var/lib/alsa
install -c -m 644 "$OURDIR"/device/$TARGET/asound.state "$OURDIR/$ROOTDIR"/var/lib/alsa/asound.state
fi
# Make sure key services are started even if they're omitted
# in the preset files
chroot "$OURDIR/$ROOTDIR" /usr/bin/systemctl enable [email protected]
[ -e "$OURDIR/$ROOTDIR"/lib/systemd/system/simplelogin.service ] && chroot "$OURDIR/$ROOTDIR" /usr/bin/systemctl enable simplelogin
[ -e "$OURDIR/$ROOTDIR"/lib/systemd/system/sddm.service ] && chroot "$OURDIR/$ROOTDIR" /usr/bin/systemctl enable sddm
if [ -e "$OURDIR/$ROOTDIR/lib/systemd/system/sddm.service" ] || [ -e "$OURDIR/$ROOTDIR/lib/systemd/system/simplelogin.service" ]; then
chroot "$OURDIR/$ROOTDIR" /usr/bin/systemctl set-default graphical.target
else
chroot "$OURDIR/$ROOTDIR" /usr/bin/systemctl set-default multi-user.target
fi
# At least while we're mostly dealing with headless boards
[ -e "$OURDIR/$ROOTDIR/lib/systemd/system/sshd.service" ] && chroot "$OURDIR/$ROOTDIR" /usr/bin/systemctl enable sshd
for i in $SERVICES; do
if [ -e "$OURDIR/$ROOTDIR/lib/systemd/system/$i.service" ]; then
chroot "$OURDIR/$ROOTDIR" /usr/bin/systemctl enable $i
else
printf '%s\n' "WARNING: Service $i requested, but not installed" >&2
fi
done
if [ -x "$OURDIR/$ROOTDIR"/usr/bin/fc-cache ]; then
# set the timestamp on the directories to be a whole second
# fc-cache looks at the nano second portion which will otherwise be
# non-zero as we are on ext4, but then it will compare against the stamps
# on the squashfs live image, squashfs only has second level timestamp resolution
FCTIME=$(date +%Y%m%d%H%M.%S)
chroot "$OURDIR/$ROOTDIR" find /usr/share/fonts -type d -exec touch -t "$FCTIME" {} \;
chroot "$OURDIR/$ROOTDIR" fc-cache -rf
chroot "$OURDIR/$ROOTDIR" /bin/mkdir -p /root/.cache/fontconfig/
chroot "$OURDIR/$ROOTDIR" /bin/mkdir -p /home/omv/.cache/fontconfig/
fi
# Rebuild man-db
[ -x "$OURDIR/$ROOTDIR"/usr/bin/mandb ] && chroot "$OURDIR/$ROOTDIR" /usr/bin/mandb --quiet
# Rebuild mime database
[ -x "$OURDIR/$ROOTDIR"/usr/bin/update-mime-database ] && chroot "$OURDIR/$ROOTDIR" /usr/bin/update-mime-database /usr/share/mime
# Generate gconv-modules.cache
#[ -x "$OURDIR/$ROOTDIR"/usr/sbin/iconvconfig ] && chroot "$OURDIR/$ROOTDIR" /usr/sbin/iconvconfig
chroot "$OURDIR/$ROOTDIR" /sbin/ldconfig
for i in etc var; do
printf "%s\n" 'File created by os-image-builder. See systemd-update-done.service(8).' > "$OURDIR/$ROOTDIR/$i"/.updated
done
cd "$OURDIR/$ROOTDIR"
run postprocess
cleanup
# There shouldn't be any files in the root filesystem. If there are any,
# they're probably core dump files generated by qemu while running systemctl
# and friends.
for i in *; do
[ -f "$i" ] && rm -f "$i"
done
cd ..
else
# Mount relevant filesystems so generate-bootimg can use
# the likes of /dev/null and /dev/urandom in chroot
for mp in /proc /sys /sys/firmware/efi/efivars /dev /dev/pts; do
mkdir -p "$OURDIR/$ROOTDIR$mp" || :
mount --bind -o ro $mp "$OURDIR/$ROOTDIR$mp"
done
fi
# Reinstall distro-release-repos to get mirrors back
[ -z $KEEP_OLD_ROOT ] && dnf -y reinstall --installroot="$OURDIR/$ROOTDIR" --releasever=$OMV_VERSION --forcearch=$ARCH ${PRE_PACKAGES}
[ -d "$OURDIR/$ROOTDIR/var/cache/dnf" ] && rm -rf "$OURDIR/$ROOTDIR/var/cache/dnf/*"
BASENAME="${BASE_DISTRO}-${SHORTTARGET}-${OS_VERSION}"
# generate-bootimg and generate-rootfs can write to results.
# Wipe it clean and make sure it exists
if [ -n "${IMAGENAME}" ]; then
RESULTDIR="results/${IMAGENAME}"
else
RESULTDIR="results/${SHORTTARGET}"
fi
rm -rf ${RESULTDIR} ; mkdir -p ${RESULTDIR}
run generate-bootimg
# Stuff in virtual filesystems should not make it to
# root filesystems...
cleanup
run generate-rootfs
xz -9ef ${RESULTDIR}/*.img &>/dev/null || :
# All of the following are allowed to fail because not
# every board needs/produces every one of them
mv *.img* ${RESULTDIR}/ 2>/dev/null || :
mv *.tar* ${RESULTDIR}/ 2>/dev/null || :
cp -a device/${TARGET}/*.md ${RESULTDIR}/ 2>/dev/null || :
cp -a device/${TARGET}/write2sd ${RESULTDIR}/ 2>/dev/null || :
cp -a device/${TARGET}/write2device ${RESULTDIR}/ 2>/dev/null || :
for i in device/${TARGET}/*.md.in device/${TARGET}/write2sd.in device/${TARGET}/write2device.in; do
[ -e "$i" ] || continue
r="${RESULTDIR}/$(basename $i .in)"
sed -e "s,@OS_VERSION@,${OS_VERSION},g;s,@OMV_VERSION@,${OMV_VERSION},g;s,@BASENAME@,${BASENAME},g" $i >"$r"
[ -x "$i" ] && chmod 0755 "$r"
done
if [ "$ABF" = "1" ]; then
# Make sure the remaining scripts have sufficient access
chown -R omv:omv ${RESULTDIR}
fi
printf '%s\n' 'Building has finished.'