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
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
|
#!/bin/bash -x
#
# This script is the first stage in bootstrapping a Fedora build to a
# new platform or architecture. Running with no arguments builds a
# cross-development environment, then cross-builds a minimal rootfs.
# Once you have this minimal rootfs booted, run stage2 in that rootfs
# to build the rest of the bootstrap packages.
#
# This script assumes that all the needed SRPMs are available in
# $SRPMDIR (below) and that there is exactly one rev of each package's
# SRPM. The resulting rootfs will be build in $ROOTFS (below).
#
# Note that SRPMDIR_LOCAL is for local SRPMs that override the
# official ones, for example, board-specific kernel RPMs.
#
# You may pass a single module name on the command line to rebuild
# just that one module. Module names match the big case statement
# below.
#
# For reference, when a package is built multiple times...
#
# foo-host is the "runs on host" part of a standard cross-compiler
# foo-target is the target libraries etc
# target-foo is a cross-built target-native
#
# Note that the "dev" step requires sudo, as it installs special files
# in $ROOTFS/dev/
#
# ------------------------------------------------------------
TOP=$PWD
MYDIR=${0%/*}
STAGE2=$MYDIR/stage2
STAGE3=$MYDIR/stage3
SRPMDIR=$TOP/SRPMs
SRPMDIR_LOCAL=$TOP/SRPMlocal
J=-j12
# default port for native builds is 3632, don't use that
DISTCC_PORT=3639
BUILDDIR=$TOP/builds
PREFIX=$TOP/install
KCONFIGDIR=$BUILDDIR/kernel
KCONFIG=kernel-3.*-arm64.config
# used by kernel and glibc
KARCH=arm64
KIMAGE=uImage
NEED_XLOADER=no
NEED_UBOOT=no
# The cross-compiler target
TARGET=aarch64-redhat-linux-gnu
# the RPMBUILD target for prepping sources
RPMTARGET=aarch64-redhat-linux-gnu
# due to naming politics, the kernel may or may not have a different target
KERNEL_RPMTARGET=arm64-redhat-linux-gnu
# Default library path
case $TARGET in
aarch64-*) SUFFIX=64 ;;
*) SUFFIX= ;;
esac
# this is where the new rootfs will be built
ROOTFS=$TOP/rootfs
CONFIG_EXTRA="--with-arch=armv8
--with-fpu=neon-fp-armv8
"
GCC_CONFIG_EXTRA="--with-arch=armv8-a
"
if [ -f $MYDIR/local.conf ]
then
. $MYDIR/local.conf
fi
# ------------------------------------------------------------
# Sanity checks
error()
{
echo Error: "$@" 1>&2
ERROR=1
}
if [ ! -d $SRPMDIR/. ]
then
error SRPMDIR set to $SRPMDIR, but I see no directory there
echo '$'SRPMDIR usually refers to a symlink to a directory with all the '*'.src.rpm files in it.
echo SRPMDIR_LOCAL may likewise refer to a directory with local srpm overrides in it
fi
test x"$ERROR" = x"1" && exit 1
unset CC
unset CXX
unset CFLAGS
unset CXXFLAGS
unset AR
unset LD
unset AS
if [ -f /usr/local/include/ppl_c.h ]
then
WITHPPL="--with-ppl=/usr/local"
else
WITHPPL=""
fi
# ------------------------------------------------------------
echo
echo Running: $0 $*
echo Date: `date`
echo Cwd: `pwd`
echo
SRCTOP=$TOP/rpmbuild
SRC=$SRCTOP/BUILD
SPECS=$SRCTOP/SPECS
mkdirp()
{
test -d $1 || mkdir -p $1
}
mkdirp $SRC
mkdirp $ROOTFS
mkdirp $PREFIX
mkdirp $BUILDDIR
mkdirp $TOP/done
export PATH=$PREFIX/bin:$PATH
mcd()
{
test -d $1 || mkdir -p $1
cd $1
}
srpm()
{
STOP=${2-$TOP}
STARGET=${3-$RPMTARGET}
SDIR=$SRPMDIR_LOCAL
SRPM=$(cd $SDIR; \ls -1 $1-*.src.rpm 2>/dev/null | egrep -v $1'-.*-.*-' | tail -1)
if [ -f $SDIR/$SRPM ]
then true; else
SDIR=$SRPMDIR
SRPM=$(cd $SDIR; \ls -1 $1-*.src.rpm 2>/dev/null | tail -1)
SRPM=$(cd $SDIR; \ls -1 $1-*.src.rpm 2>/dev/null | egrep -v $1'-.*-.*-' | tail -1)
fi
echo SRPM is $SRPM
SPEC=${SRPM%-*}
SPEC=${SPEC%-*}
if [ -f $STOP/rpmbuild/SPECS/$SPEC.spec ]
then true; else
test -f $SDIR/$SRPM || exit 1
HOME=$STOP rpm -i $SDIR/$SRPM
cd $STOP/rpmbuild/SPECS
HOME=$STOP rpmbuild --target=$STARGET --nodeps -bp $SPEC.spec
cd $TOP
fi
}
rsrpm()
{
srpm $1 $ROOTFS/stage2
}
set -e
BUILD=`gcc -v 2>&1 | grep Target: | sed 's/.*: //'`
# These are for cross-tools like binutils
CONFIGARGS="--prefix=$PREFIX
--libdir=$PREFIX/lib${SUFFIX}
--target=$TARGET
${CONFIG_EXTRA}
--enable-languages=c,c++
--with-sysroot=$ROOTFS
--enable-threads=posix
--enable-64-bit-bfd
$WITHPPL
"
TCONFIGARGS="--prefix=/usr
--libdir=/usr/lib${SUFFIX}
--with-sysroot=/
--with-build-sysroot=$ROOTFS
--build=$BUILD
--host=$TARGET
--target=$TARGET
--enable-werror=no
--enable-cxx
${CONFIG_EXTRA}
--enable-languages=c,c++
--enable-threads=posix
"
# These are for gcc cross-tools (politics sometime result in slightly
# different arch names)
GCC_CONFIGARGS="--prefix=$PREFIX
--libdir=$PREFIX/lib${SUFFIX}
--target=$TARGET
${GCC_CONFIG_EXTRA}
--enable-languages=c,c++
--with-sysroot=$ROOTFS
--enable-threads=posix
--enable-64-bit-bfd
$WITHPPL
"
GCC_TCONFIGARGS="--prefix=/usr
--libdir=/usr/lib${SUFFIX}
--with-sysroot=/
--with-build-sysroot=$ROOTFS
--build=$BUILD
--host=$TARGET
--target=$TARGET
--enable-werror=no
--enable-cxx
${GCC_CONFIG_EXTRA}
--enable-languages=c,c++
--enable-threads=posix
"
KERNELARGS="ARCH=${KARCH} CROSS_COMPILE=${TARGET}-"
# Must use install_root=$ROOTFS on all makes
prefill_gcc_cache()
{
echo 'lt_cv_shlibpath_overrides_runpath=no' > config.cache
echo 'gcc_cv_libc_provides_ssp=yes' > config.cache
}
setup_glibc()
{
# This path MUST be relative, not absolute
GLIBCPORTSSRC=../$(cd $SRC; echo glibc-ports*)
#GLIBCPORTSSRC=ports
GV=$(cd $SRC; echo glibc-2*)
GLIBCARGS0="--prefix=/usr
--libdir=/usr/lib${SUFFIX}
--with-headers=$ROOTFS/usr/include
--enable-kernel=2.6.32
--enable-bind-now
--build $BUILD
--host $TARGET
--disable-profile
--cache-file=config.cache
--without-cvs
--with-elf
--without-gd"
GLIBCARGS1="$GLIBCARGS0
--enable-add-ons=$GLIBCPORTSSRC,nptl
--disable-sanity-checks
--with-tls
--with-__thread
"
GLIBCARGS2="$GLIBCARGS0
--enable-add-ons=$GLIBCPORTSSRC,nptl
--disable-sanity-checks
--with-tls
--with-__thread
"
}
prefill_glibc_cache()
{
echo libc_cv_forced_unwind=yes > config.cache
echo libc_cv_c_cleanup=yes >> config.cache
echo libc_cv_ctors_header=yes >> config.cache
echo ac_cv_header_cpuid_h=yes >> config.cache
echo libc_cv_ssp=no >> config.cache
echo libc_cv_gcc_builtin_expect=yes >> config.cache
}
setup_eglibc()
{
# This path MUST be relative, not absolute
GLIBCPORTSSRC=../$(cd $SRC/eglibc-*; echo ports*)
#GLIBCPORTSSRC=ports
GV=$(cd $SRC; echo eglibc-*/libc)
EGLIBCARGS0="--prefix=/usr
--libdir=/usr/lib${SUFFIX}
--includedir=/usr/include
--with-headers=$ROOTFS/usr/include
--enable-kernel=2.6.32
--enable-bind-now
--build $BUILD
--host $TARGET
--disable-profile
--cache-file=config.cache
--without-cvs
--with-elf
--without-gd"
EGLIBCARGS1="$EGLIBCARGS0
--enable-add-ons=$GLIBCPORTSSRC,nptl
--disable-sanity-checks
--with-tls
--with-__thread
"
EGLIBCARGS2="$EGLIBCARGS0
--enable-add-ons=$GLIBCPORTSSRC,nptl
--disable-sanity-checks
--with-tls
--with-__thread
"
}
prefill_eglibc_cache()
{
echo libc_cv_forced_unwind=yes > config.cache
echo libc_cv_c_cleanup=yes >> config.cache
echo libc_cv_ctors_header=yes >> config.cache
echo libc_cv_ssp=yes >> config.cache
echo libc_cv_gcc_builtin_expect=yes >> config.cache
}
notparallel()
{
echo .NOTPARALLEL: >> Makefile
}
fix_la()
{
for la in $ROOTFS/usr/lib${SUFFIX}/*$1*.la
do
if test -f $la
then
rm $la
fi
done
}
#--------------------------------------------------
go()
{
test -f $TOP/done/$1 && return 0
if "$0" "$@"
then
date > $TOP/done/$1
else
echo
echo Module "$@" failed
return 1
fi
}
case "$1" in
"" )
go usrlinks
go kernel-headers
go binutils
go gcc-host
go glibc-headers
go gcc-libgcc
go glibc
go gcc
go dev
# go kernel
test x"$NEED_XLOADER" == x"yes" && go x-loader
test x"$NEED_UBOOT" == x"yes" && go u-boot
go gmp
go mpfr
go mpc
go ppl
go cloog
go libsepol
go libselinux
go zlib
go t-binutils
go t-gcc
go bash
go make
go sed
go coreutils
go busybox
go util-linux
go tar
# only run this far, for now
exit 0
go gzip
go bzip2
go diffutils
go findutils
go gawk
go patch
go unzip
go which
go xz
go grep
go distcc
go ccache
go stage2
# only run this far, for now
exit 0
go stage3
;;
"clean" )
set -vx
mkdir .quickrm.$$
mv -f $SRCTOP $ROOTFS $PREFIX $BUILDDIR $TOP/done .quickrm.$$
rm -rf .quickrm.$$ &
;;
"sync" )
# echo Copying built rootfs to panda-1...
# rsync -a $ROOTFS/ root@panda-1:/hardfp/
;;
"test1" )
echo test running
go test
echo test passed
;;
"test" )
echo Testing
exit 1
;;
#--------------------------------------------------
# host cross-tools
"kernel-headers" )
srpm kernel $TOP $KERNEL_RPMTARGET
mcd $BUILDDIR/kernel
cd $SRC/kernel-*/linux-*
make $KERNELARGS INSTALL_HDR_PATH=$ROOTFS/usr headers_install
;;
"binutils" )
srpm binutils
mcd $BUILDDIR/binutils
$SRC/binutils-*/configure $CONFIGARGS
notparallel
make $J
make $J install
;;
"gcc-host" )
srpm gcc
mcd $BUILDDIR/gcc
prefill_gcc_cache
$SRC/gcc-*/configure $GCC_CONFIGARGS --with-headers=$ROOTFS/usr/include --cache-file=config.cache
notparallel
make $J all-host
make $J install-host
if false; then
mkdirp $ROOTFS/usr/lib${SUFFIX}
for o in crt Scrt1 crti crtbegin crtbeginS crtend crtendS crtn
do
$TARGET-gcc -nostdlib -nostartfiles -c -x c /dev/null -c -o $ROOTFS/usr/lib${SUFFIX}/$o.o
done
for so in gcc gcc_s c
do
$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $ROOTFS/usr/lib${SUFFIX}/lib$so.so
done
fi
;;
"glibc-headers" )
set -vx
srpm glibc
setup_glibc
mcd $BUILDDIR/glibc-stage1
prefill_glibc_cache
$SRC/$GV/configure $GLIBCARGS1
notparallel
make $J ARCH=${KARCH} cross-compiling=yes install-headers install_root=$ROOTFS
touch $ROOTFS/usr/include/gnu/stubs.h
touch $ROOTFS/usr/include/bits/stdio_lim.h
cp $SRC/$GV/nptl/sysdeps/pthread/pthread.h $ROOTFS/usr/include
( cd $ROOTFS/usr/include/bits
sed '/ifndef.*NO_LONG_DOUBLE/,/#endif/d' < mathdef.h > mathdef.h.new
mv mathdef.h.new mathdef.h
)
# We also build just enough files to link libgcc.so. The fake
# libc.so will never actually get used.
mkdirp $ROOTFS/usr/lib${SUFFIX}
make $J ARCH=${KARCH} cross-compiling=yes csu/subdir_lib
# cp csu/crt*.o $ROOTFS/usr/lib${SUFFIX}
for C in `cd csu; echo crt*.o`; do
echo "" | $TARGET-as -o $ROOTFS/usr/lib${SUFFIX}/$C
done
$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $ROOTFS/usr/lib${SUFFIX}/libc.so
;;
"eglibc-headers" )
set -vx
srpm eglibc
setup_eglibc
mcd $BUILDDIR/eglibc-stage1
prefill_eglibc_cache
$SRC/$GV/configure $EGLIBCARGS1
notparallel
make $J ARCH=arm cross-compiling=yes install-headers install_root=$ROOTFS install-bootstrap-headers=yes
touch $ROOTFS/usr/include/gnu/stubs.h
touch $ROOTFS/usr/include/bits/stdio_lim.h
cp $SRC/$GV/nptl/sysdeps/pthread/pthread.h $ROOTFS/usr/include
( cd $ROOTFS/usr/include/bits
sed '/ifndef.*NO_LONG_DOUBLE/,/#endif/d' < mathdef.h > mathdef.h.new
mv mathdef.h.new mathdef.h
)
# We also build just enough files to link libgcc.so. The fake
# libc.so will never actually get used.
mkdirp $ROOTFS/usr/lib${SUFFIX}
make $J ARCH=arm cross-compiling=yes csu/subdir_lib
cp csu/crt*.o $ROOTFS/usr/lib${SUFFIX}
cp csu/elf-init*.o $ROOTFS/usr/lib${SUFFIX}
cp csu/libc-start*.o $ROOTFS/usr/lib${SUFFIX}
$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $ROOTFS/usr/lib${SUFFIX}/libc.so
;;
"gcc-libgcc" )
srpm gcc
mcd $BUILDDIR/gcc
prefill_gcc_cache
$SRC/gcc-*/configure $GCC_CONFIGARGS --with-headers=$ROOTFS/usr/include --cache-file=config.cache
notparallel
make $J all-target-libgcc all-target-libssp
make $J install-target-libgcc install-target-libssp
;;
"glibc" )
srpm glibc
setup_glibc
mcd $BUILDDIR/glibc
prefill_glibc_cache
$SRC/$GV/configure $GLIBCARGS2
notparallel
make $J ARCH=${KARCH} cross-compiling=yes
make $J ARCH=${KARCH} cross-compiling=yes install install_root=$ROOTFS
( cd $ROOTFS/usr/include/bits
sed '/ifndef.*NO_LONG_DOUBLE/,/#endif/d' < mathdef.h > mathdef.h.new
mv mathdef.h.new mathdef.h
)
;;
"eglibc" )
srpm eglibc
setup_eglibc
mcd $BUILDDIR/eglibc
prefill_eglibc_cache
$SRC/$GV/configure $EGLIBCARGS2
notparallel
make $J ARCH=arm cross-compiling=yes
make $J ARCH=arm cross-compiling=yes install install_root=$ROOTFS
( cd $ROOTFS/usr/include/bits
sed '/ifndef.*NO_LONG_DOUBLE/,/#endif/d' < mathdef.h > mathdef.h.new
mv mathdef.h.new mathdef.h
)
;;
"gcc" )
srpm gcc
mcd $BUILDDIR/gcc
prefill_gcc_cache
$SRC/gcc-*/configure $GCC_CONFIGARGS --with-headers=$ROOTFS/usr/include --cache-file=config.cache
notparallel
make $J
make $J install
mcd $ROOTFS/lib${SUFFIX}/gcc
rsync -av $PREFIX/lib${SUFFIX}/gcc/ $ROOTFS/lib${SUFFIX}/gcc/
rsync -av $PREFIX/$TARGET/lib/ $ROOTFS/lib${SUFFIX}/
;;
#--------------------------------------------------
# target boot support
"usrlinks" )
test -d $ROOTFS || mkdir -p $ROOTFS
mkdir $ROOTFS/usr
for i in bin sbin lib${SUFFIX} libexec
do
ln -s usr/$i $ROOTFS/$i
mkdir $ROOTFS/usr/$i
done
ln -s usr/lib${SUFFIX} $ROOTFS/lib
for i in etc proc sys
do
mkdir $ROOTFS/$i
done
;;
"dev" )
rsync -av $TOP/dev-template/ $ROOTFS/
mcd $ROOTFS/tmp
chmod 1777 .
mcd $ROOTFS/dev
sudo mknod null c 1 3
sudo mknod zero c 1 5
sudo mknod tty c 5 0
sudo mknod console c 5 1
sudo mknod sda b 8 0
sudo mknod sda1 b 8 1
sudo mknod sda2 b 8 2
sudo mknod sda3 b 8 3
sudo mknod sda4 b 8 4
sudo mknod mmcblk0 b 179 0
sudo mknod mmcblk0p1 b 179 1
sudo mknod mmcblk0p2 b 179 2
sudo mknod mmcblk0p3 b 179 3
sudo mknod mmcblk0p4 b 179 4
sudo mknod ttyO0 c 253 0
sudo mknod ttyO1 c 253 1
sudo mknod ttyO2 c 253 2
sudo mknod ttyO3 c 253 3
sudo mknod tty2 c 4 2
sudo mknod tty3 c 4 3
sudo mknod tty4 c 4 4
sudo mknod ttyS0 c 4 64
sudo mknod ttyS1 c 4 65
sudo mknod ttyS2 c 4 66
sudo mknod ttyS3 c 4 67
sudo chmod a+rw null zero
;;
"kernel" )
srpm kernel $TOP $KERNEL_RPMTARGET
mcd $BUILDDIR/kernel
echo copying kernel sources to build area...
rsync -a --delete $SRC/kernel-*/linux-*/ ./
cp $KCONFIGDIR/$KCONFIG .config
make $J ARCH=$KARCH CROSS_COMPILE=${TARGET}- silentoldconfig
#make $J ARCH=$KARCH CROSS_COMPILE=${TARGET}- $KIMAGE
make $J ARCH=$KARCH CROSS_COMPILE=${TARGET}-
make $J ARCH=$KARCH CROSS_COMPILE=${TARGET}- modules
make $J ARCH=$KARCH CROSS_COMPILE=${TARGET}- INSTALL_MOD_PATH=$ROOTFS modules_install
mkdirp $ROOTFS/boot
mkdirp $ROOTFS/lib/firmware
cp arch/$KARCH/boot/$KIMAGE $ROOTFS/boot
;;
"x-loader" )
if [ ! -f $BUILDDIR/x-loader/README ]
then
cd $BUILDDIR
git clone git://gitorious.org/x-loader/x-loader.git
fi
cd $BUILDDIR/x-loader
sed s/-Werror// cpu/omap4/config.mk > cpu/omap4/config.mk.new
mv cpu/omap4/config.mk.new cpu/omap4/config.mk
make $J distclean
make $J CROSS_COMPILE=${TARGET}- omap4430panda_config
make $J CROSS_COMPILE=${TARGET}-
mkdirp $ROOTFS/boot
cp MLO $ROOTFS/boot
;;
"u-boot" )
# git git://git.denx.de/u-boot.git
if [ ! -f $BUILDDIR/u-boot/README ]
then
cd $BUILDDIR
git clone git://git.denx.de/u-boot.git
fi
cd $BUILDDIR/u-boot
make $J distclean
make $J CROSS_COMPILE=${TARGET}- omap4_panda_config
make $J CROSS_COMPILE=${TARGET}- u-boot.img
mkdirp $ROOTFS/boot
cp u-boot.img $ROOTFS/boot/u-boot.img
;;
"djtest" )
cd $TOP/djtest
make $J
make $J install ROOTFS=${ROOTFS}
;;
#--------------------------------------------------
# target-side libraries
gmp | mpfr | ppl )
L=$1
srpm $L
mcd $BUILDDIR/t-$L
$SRC/${L}-*/configure $TCONFIGARGS
make $J
make $J install DESTDIR=${ROOTFS}
fix_la $L
;;
mpc )
L=$1
srpm libmpc
mcd $BUILDDIR/t-$L
$SRC/${L}-*/configure $TCONFIGARGS
make
make $J install DESTDIR=${ROOTFS}
fix_la $L
;;
zlib )
srpm zlib
mcd $BUILDDIR/t-zlib
rsync -av $SRC/zlib-*/ ./
if [ "$SUFFIX" = "64" ]
then
ARGS="--libdir=/usr/lib64"
fi
CHOST=${TARGET} \
prefix=/usr \
./configure $ARGS
make
make $J install DESTDIR=${ROOTFS}
fix_la zlib
;;
"cloog" )
srpm cloog
mcd $BUILDDIR/t-cloog
$SRC/cloog-*/configure $TCONFIGARGS --with-ppl
make $J LDADD="-rpath ${ROOTFS}/lib${SUFFIX} -lcloog"
make $J install DESTDIR=${ROOTFS}
fix_la cloog
;;
libsepol )
srpm libsepol
mcd $BUILDDIR/t-libsepol
rsync -av $SRC/libsepol*/ ./
make $J \
CC=${TARGET}-gcc \
AS=${TARGET}-as \
AR=${TARGET}-ar \
STRIP=${TARGET}-strip \
RANLIB=${TARGET}-ranlib \
CFLAGS="" \
TLSFLAGS="" \
all
ARGS="DESTDIR=${ROOTFS}"
if [ "$SUFFIX" = "64" ]
then
ARGS="$ARGS LIBDIR=${ROOTFS}/usr/lib64 SHLIBDIR=${ROOTFS}/usr/lib64"
fi
make $J $ARGS install
;;
# TLSFLAGS are set in order to avoid a bogus check in
# libselinux/src/Makefile.
libselinux )
srpm libselinux
mcd $BUILDDIR/t-libselinux
rsync -av $SRC/libselinux*/ ./
# libselinux uses $prefix/include for both -I and *.pc, which
# prevents cross compiling.
sed 's@-I$(INCLUDEDIR)@@' < src/Makefile > src/Makefile.stage1
mv src/Makefile.stage1 src/Makefile
make $J \
CC=${TARGET}-gcc \
AS=${TARGET}-as \
AR=${TARGET}-ar \
STRIP=${TARGET}-strip \
RANLIB=${TARGET}-ranlib \
CFLAGS="" \
TLSFLAGS="" \
all LDFLAGS="-Wl,-rpath -Wl,${ROOTFS}/lib${SUFFIX}"
ARGS="DESTDIR=${ROOTFS}"
if [ "$SUFFIX" = "64" ]
then
ARGS="$ARGS LIBDIR=${ROOTFS}/usr/lib64 SHLIBDIR=${ROOTFS}/usr/lib64"
fi
make $J $ARGS install
;;
#--------------------------------------------------
# target-side applications
"bash" )
srpm bash
mcd $BUILDDIR/bash
cat <<EOF > config.cache
bash_cv_func_ctype_nonascii=yes
bash_cv_opendir_not_robust=no
bash_cv_ulimit_maxfds=yes
bash_cv_func_sigsetjmp=present
bash_cv_printf_a_format=yes
bash_cv_job_control_missing=present
bash_cv_sys_named_pipes=present
bash_cv_unusable_rtsigs=no
EOF
$SRC/bash-*/configure --prefix=/ --cache-file=config.cache --build=$BUILD --host=$TARGET
make $J
make $J install DESTDIR=${ROOTFS}
(cd $ROOTFS/bin; ln -s bash sh)
;;
"t-binutils" )
srpm binutils
mcd $BUILDDIR/t-binutils
$SRC/binutils-*/configure $TCONFIGARGS
notparallel
make $J
make $J install DESTDIR=${ROOTFS}
;;
"t-gcc" )
srpm gcc
mcd $BUILDDIR/t-gcc
$SRC/gcc-*/configure $GCC_TCONFIGARGS --enable-linker-build-id
notparallel
make $J
make $J install DESTDIR=${ROOTFS}
test -e ${ROOTFS}/usr/bin/cc && rm ${ROOTFS}/usr/bin/cc
ln -s gcc ${ROOTFS}/usr/bin/cc
;;
make | tar | gzip | diffutils | gawk | which | grep )
srpm $1
mcd $BUILDDIR/$1
$SRC/${1}-*/configure $TCONFIGARGS
notparallel
test -d tools/gnulib/lib && make $J V=1 -C tools/gnulib/lib
make $J V=1
make $J install DESTDIR=${ROOTFS}
;;
findutils )
srpm $1
mcd $BUILDDIR/$1
FINDLIBS="-lselinux -ldl" $SRC/${1}-*/configure $TCONFIGARGS
notparallel
test -d tools/gnulib/lib && make $J V=1 -C tools/gnulib/lib
make $J V=1
make $J install DESTDIR=${ROOTFS}
;;
sed )
srpm $1
mcd $BUILDDIR/$1
$SRC/${1}-*/configure $TCONFIGARGS
notparallel
# Touch sed.1 so that it will not be built.
# The makefile in the sed/doc directory attempts to run the
# built sed binary in order to extract the --help output, but
# this fails because the sed binary is a cross-tool.
touch doc/sed.1
make $J V=1 CFLAGS="-lselinux -Wl,-rpath -Wl,${ROOTFS}/lib${SUFFIX}"
make $J install DESTDIR=${ROOTFS}
;;
patch )
srpm patch
mcd $BUILDDIR/$1
cat <<EOF > config.cache
ac_cv_func_strnlen_working=yes
EOF
$SRC/${1}-*/configure $TCONFIGARGS --cache-file=config.cache
notparallel
make $J V=1
make $J install DESTDIR=${ROOTFS}
;;
xz )
srpm xz
mcd $BUILDDIR/$1
$SRC/${1}-*/configure \
--prefix=/usr \
--libdir=/usr/lib64 \
--build=$BUILD \
--host=$TARGET \
notparallel
make $J V=1
make $J install DESTDIR=${ROOTFS}
;;
unzip )
srpm unzip
mcd $BUILDDIR/$1
rsync -av $SRC/unzip*/ ./
make $J -f unix/Makefile \
CC=${TARGET}-gcc \
AS=${TARGET}-as \
AR=${TARGET}-ar \
STRIP=${TARGET}-strip \
RANLIB=${TARGET}-ranlib \
prefix=/usr \
generic
make $J -f unix/Makefile \
CC=${TARGET}-gcc \
AS=${TARGET}-as \
AR=${TARGET}-ar \
STRIP=${TARGET}-strip \
RANLIB=${TARGET}-ranlib \
prefix=${ROOTFS}/usr \
install
;;
coreutils )
srpm coreutils
mcd $BUILDDIR/$1
$SRC/${1}-*/configure $TCONFIGARGS --disable-pam
notparallel
for i in $(cd $SRC/${1}-*/man; echo *.x)
do
base=`echo $i | sed 's/\.x//'`
touch man/$base.1
done
make $J V=1 CFLAGS="-lselinux -Wl,-rpath -Wl,${ROOTFS}/lib${SUFFIX}"
make $J install DESTDIR=${ROOTFS}
;;
busybox )
srpm busybox
mcd $BUILDDIR/$1
rsync -av $SRC/busybox-*/ ./
notparallel
make TEST_aarch64_f17_defconfig CROSS_COMPILE=${TARGET}-
make busybox CROSS_COMPILE=${TARGET}-
make install CONFIG_PREFIX=${ROOTFS}
# add in an password file for cleaniness (even if it has no passwd)
(
echo "root::0:0:root:/:/bin/bash"
) > $ROOTFS/etc/passwd
# add in some basic mount points
[ -d ${ROOTFS}/proc ] || mkdir ${ROOTFS}/proc
[ -d ${ROOTFS}/sys ] || mkdir ${ROOTFS}/sys
(
echo "proc /proc proc defaults 0 0"
echo "sysfs /sys sysfs defaults 0 0"
) > $ROOTFS/etc/fstab
touch $ROOTFS/etc/mtab
# and a place holder for other useful initializations
[ -d ${ROOTFS}/etc/init.d ] || mkdir -p ${ROOTFS}/etc/init.d
(
echo "#!/bin/sh"
echo "/bin/mount -a"
) > $ROOTFS/etc/init.d/rcS
chmod +x ${ROOTFS}/etc/init.d/rcS
;;
util-linux )
srpm util-linux
mcd $BUILDDIR/$1
cat <<EOF > config.cache
ax_cv_have_tls=yes
scanf_cv_alloc_modifier=yes
EOF
$SRC/${1}-*/configure $TCONFIGARGS --without-ncurses \
--prefix=/usr --libexecdir=/usr/lib${SUFFIX} --libdir=/usr/lib${SUFFIX} \
--disable-wall --cache-file=config.cache
notparallel
make $J V=1
make $J install DESTDIR=${ROOTFS}
;;
bzip2 )
srpm bzip2
mcd $BUILDDIR/bzip2
rsync -av $SRC/bzip2-*/ ./
make $J \
CC=${TARGET}-gcc \
AR=${TARGET}-ar \
RANLIB=${TARGET}-ranlib \
PREFIX=/usr \
CFLAGS="$CFLAGS -fpic -fPIC" \
libbz2.a bzip2 bzip2recover
if [ "$SUFFIX" = "64" ]
then
ARGS="BITS=64"
fi
make $J $ARGS \
CC=${TARGET}-gcc \
AR=${TARGET}-ar \
RANLIB=${TARGET}-ranlib \
PREFIX=${ROOTFS}/usr \
install
# the installation makes symbols links with our host's paths
# in them, we need to redo those.
cd $ROOTFS/usr/bin
rm bzless; ln -s bzmore bzless
rm bzfgrep; ln -s bzgrep bzfgrep
rm bzcmp; ln -s bzdiff bzcmp
rm bzegrep; ln -s bzgrep bzegrep
;;
distcc )
srpm distcc
mcd $BUILDDIR/distcc
$SRC/${1}-*/configure $TCONFIGARGS --disable-Werror --without-avahi
notparallel
make $J V=1
make $J install DESTDIR=${ROOTFS}
mcd $ROOTFS/stage2/distcc-bin
for p in gcc cc g++ c++ as ${TARGET}-gcc ${TARGET}-g++ ${TARGET}-as
do
test -e $p && rm $p
ln -s /usr/bin/distcc $p
done
;;
ccache )
srpm ccache
mcd $BUILDDIR/ccache
$SRC/${1}-*/configure $TCONFIGARGS
notparallel
make $J V=1
make $J install DESTDIR=${ROOTFS}
mcd $ROOTFS/stage2/ccache-bin
for p in gcc cc g++ c++ as ${TARGET}-gcc ${TARGET}-g++ ${TARGET}-as
do
test -e $p && rm $p
ln -s /usr/bin/ccache $p
done
;;
stage2 )
# install source trees in rootfs, so stage2 will have them for
# its builds.
case "$TARGET" in
*i686* )
if [ ! -f $ROOTFS/usr/bin/uname-bin ]
then
mv $ROOTFS/usr/bin/uname $ROOTFS/usr/bin/uname-bin
echo "#!/bin/sh" > $ROOTFS/usr/bin/uname
echo '/usr/bin/uname-bin "$@" | sed s/x86_64/i686/g' >> $ROOTFS/usr/bin/uname
chmod a+x $ROOTFS/usr/bin/uname
fi
;;
esac
mkdirp $ROOTFS/stage2/recipe.d
# FIXME: the recipe files need to be copied into the rootfs
# before they can be used.
cp $MYDIR/recipe.d/* $ROOTFS/stage2/recipe.d
cp $MYDIR/macros.bashrc $ROOTFS/stage2
cp $MYDIR/script2makefile $ROOTFS/stage2
for PKG in $ROOTFS/stage2/recipe.d/*
do
case "$PKG" in
*~ ) ;;
*# ) ;;
*/XXXX-* ) ;;
*)
PKG=$(echo $PKG | sed "s/.*\\///; s/^[0-9][0-9][0-9][0-9]-//")
echo "Installing SRPM for $PKG"
rsrpm $PKG
;;
esac
done
(
cd $ROOTFS/stage2/rpmbuild/BUILD/sqlite-*
test -f sqlite3.h.stage1 \
|| tclsh tool/mksqlite3h.tcl . > sqlite3.h.stage1
)
cp $STAGE2 $ROOTFS/stage2/stage2
(
newJ=$(echo $J | sed 's/-j//')
echo J=-j$newJ
echo DISTCC_HOSTS=$(host $(hostname) | sed 's/.* //'):${DISTCC_PORT}/999
echo DISTCC_BACKOFF_PERIOD=0
echo PATH=/stage2/distcc-bin:\$PATH
echo PATH=/stage2/ccache-bin:\$PATH
echo TARGET=$TARGET
echo RPMTARGET=$RPMTARGET
echo TCONFIGARGS=\"$TCONFIGARGS\" \
| sed 's/--build=[^ ]*//' \
| sed 's/--host=[^ ]*//' \
| sed 's/--target=[^ ]*//' \
| sed 's/--with-sysroot=[^ ]*//' \
| sed 's/--with-build-sysroot=[^ ]*//' \
| sed 's/--with-arch=armv8//' \
| sed 's/--with-fpu=neon-fp-armv8//'
echo SUFFIX=$SUFFIX
echo export J DISTCC_HOSTS DISTCC_BACKOFF_PERIOD PATH
echo export TARGET RPMTARGET TCONFIGARGS SUFFIX
) > $ROOTFS/stage2/local.conf
mcd $PREFIX/distccd-bin
rm -f gcc cc g++ c++ as ${TARGET}-gcc ${TARGET}-g++ ${TARGET}-as
ln -s $PREFIX/bin/${TARGET}-gcc gcc
ln -s $PREFIX/bin/${TARGET}-gcc cc
ln -s $PREFIX/bin/${TARGET}-gcc ${TARGET}-gcc
ln -s $PREFIX/bin/${TARGET}-g++ ${TARGET}-g++
ln -s $PREFIX/bin/${TARGET}-g++ g++
ln -s $PREFIX/bin/${TARGET}-g++ c++
ln -s $PREFIX/bin/${TARGET}-as as
ln -s $PREFIX/bin/${TARGET}-as ${TARGET}-as
cd $TOP
(
echo #!/bin/sh
echo export PATH=$PREFIX/distccd-bin:\$PATH
# The allow means "anyone" since we don't know which host the target is.
# add --wizard to shut off background mode and logs info to stdout
echo distccd --daemon --allow 0.0.0.0/0 --port $DISTCC_PORT '"$@"'
) > distccd.script
chmod a+x distccd.script
echo stage2 ready
;;
stage3 )
# This assumes stage2 was run and the fies are available
test -e $ROOTFS/stage3/local.conf && rm $ROOTFS/stage3/local.conf
ln -s ../stage2/local.conf $ROOTFS/stage3/local.conf
mkdirp $ROOTFS/stage3/stage3.d
cp $MYDIR/stage3.d/* $ROOTFS/stage3/stage3.d
cp $MYDIR/macros.bashrc $ROOTFS/stage3
cp $MYDIR/script2makefile $ROOTFS/stage3
cp $STAGE3 $ROOTFS/stage3/stage3
test -d $ROOTFS/stage3/done || mkdir $ROOTFS/stage3/done
echo stage3 ready
;;
esac
exit 0
|