-
Notifications
You must be signed in to change notification settings - Fork 4
/
XOpup_kernel_builder.sh
executable file
·1076 lines (987 loc) · 34.3 KB
/
XOpup_kernel_builder.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
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
#!/bin/bash
#
# This script will build a kernel capable of running puppylinux
# on the OLPC XO-1, XO-1.5, XO-1.75 and XO-4 laptops.
# Use in combination with the create_xo_puppy script to make any
# flavor XOpup running an updated 2.6.35 OLPC kernel or the new
# (and for now experimental) OLPC 3.3.0 kernel or the armv7 3.0 and
# 3.5 kernels. You'll need Fedora 16-18 or an armv7 or an x86_64
# machine for ARM kernel building
#
# GPL2 (see /usr/share/doc) (c) mavrothal, 01micko
# NO WARRANTY
#ver
VER=16
# fail-safe switch in case someone clicks the script in ROX
#echo -e "\\0033[1;34m"
#read -p "Press ENTER to begin" dummy
#echo -en "\\0033[0;39m"
BASEDIR=`pwd`
CWD="$BASEDIR"
INSIDE=`echo $BASEDIR | grep Pox_git`
if [ "$INSIDE" != "" ] ; then
echo -e "\\0033[1;31m"
echo "Running this script from within the Pox_git folder will fail"
echo "Run it from the XO_build directory that make_build generates"
echo -en "\\0033[0;39m"
sleep 5
exit 0
fi
mkdir $BASEDIR/kernel_sources
sources="$BASEDIR/kernel_sources"
git_clone="$sources/olpc-2.6"
git_clone_aufs2="$sources/aufs2-standalone"
git_clone_aufs3="$sources/aufs3-standalone"
union_patch="$sources/unionfs-2.5.11_for_3.3.*.diff"
patches="$BASEDIR/XO_kernel_patches"
if [ "`uname -m | grep -i armv7`" = "" ] ; then
CPUs=`cat /proc/cpuinfo | grep "model name" | wc -l`
else
CPUs=`cat /proc/cpuinfo | grep Processor | wc -l`
fi
#bit of fun! (curtesy of 01micko)
clear
xoolpcfunc()
{
echo ""
echo -en "\033[1;33m""\t1""\033[0m" "|" "\033[1;32m" "L""\033[0m" \
"|""\033[1;36m"" ->""\033[0m" "|""\033[1;35m" "X"; echo -e "\033[0m"
echo ""
}
export -f xoolpcfunc
xoolpcfunc
#usage
usagefunc()
{
cat <<_USAGE
Usage:
This program will build Puppylinux-compatible kernels for the
OLPC XO-1 and XO-1.5 laptops
-h|--help display this usage
-v|--version display script version
-d|--download only download the sources
-1|--xo1 download and build the XO-1 kernel
-5|--xo15 download and build the XO-1.5 kernel
-7|--xo175 download and build the XO-1.75 kernel
-4|--xo4 download and build the XO-4 kernel
-x|--x86 download and build the XO-1 and XO-1.5 kernels
-a|--ARM download and build the XO-1.75 and XO-4 kernels
-b|--build-all download and build all 4 kernels
NOTE: The program will download ~600 MB of data and requires
at least 1 GB of free disk space. Make sure you have all the
compiling tools for your Linux distribution
(c) Created by mavrothal and 01micko @murga-linux puppy forum
GPLv2. See /usr/share/doc/legal/
NO WARRANTY of any kind is given or implied
While all care is taken NO responsibility is accepted
_USAGE
xoolpcfunc
exit 0
}
export -f usagefunc
case "$#" in
0) usagefunc ;;
[2-9])echo "too many arguments"; usagefunc ;;
esac
# Check if we have development tools installed
check_dev()
{
if [ -f /etc/rc.d/BOOTCONFIG ] ; then
. /etc/rc.d/BOOTCONFIG
DEVX=`echo "$EXTRASFSLIST" | grep devx`
if [ "$DEVX" = "" ] && [ "`cat /etc/issue | grep -i fatdog`" = "" ] ; then
echo -e "\\0033[1;31m"
echo "You _must_ have devx loaded for this script to run properly"
echo "Please load the devx SFS and try again"
echo -en "\\0033[0;39m"
xoolpcfunc
exit 0
fi
else
if [ "`which gcc | grep no\ `" != "" ] || [ `which gcc` = "" ] \
|| [ "`which make | grep no\ `" != "" ] || [ `which make` = "" ] ; then
echo -e "\\0033[1;31m"
echo "You _must_ have development tools installed for this script"
echo " to run properly. Please install them and try again"
echo -en "\\0033[0;39m"
xoolpcfunc
exit 0
fi
fi
if [ "`which git`" = "" ] ; then
echo -e "\\0033[1;31m"
echo "You _must_ have git installed for this script"
echo " to run properly. Please install git and try again"
echo -en "\\0033[0;39m"
xoolpcfunc
exit 0
fi
}
export -f check_dev
check_space()
{
#test for free space
BASEDISK="`echo $CWD|cut -d '/' -f 1,2,3`" #returns eg "/mnt/sda1"
BASEPART="`echo $CWD|cut -d '/' -f 3`" #returns eg "sda1" if not in pupsave
if [ "$BASEPART" = "home" ] ; then
DF="`df -m|grep dev_save|awk '{print $4}'`"
else
DF="`df -m|grep $BASEPART|awk '{print $4}'`"
fi
#puppy specific
if [ -f /etc/DISTRO_SPECS ];then #puppy test only added 110825 01micko
. /etc/rc.d/PUPSTATE
if [[ "$PUPMODE" = "7" || "$PUPMODE" = "13" ]];then
echo "You have a USB install to slow media and this program"
echo "will fail if you try to run it on the usb media"
echo "make absolutely sure you run this in a linux filesystem on a HDD"
echo "or if you have over a gigabyte of RAM, make a ramdisk .."
echo "...for advanced users only!"
echo "Hit enter to continue"
read goon
fi
#cheat!
if [ "`echo $BASEDISK|grep "root"`" != "" ];then
DF="`cat /tmp/pup_event_sizefreem`"
fi
fi
if test "$DF" -lt "1000" ;then EXIT=1
echo "space check... disk space free is $DF MB"
echo "...not enough space, do this on another partiton"
else EXIT=0
echo "space check... disk space free is $DF MB"
fi
}
export -f check_space
get_sources()
{
# Get needed files
if [ ! -d "$git_clone" ] ; then
cd $sources
echo " Please be patient. It can take an hour..."
git clone git://dev.laptop.org/olpc-2.6 2>&1
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to download the kernel sources."
echo "Check the connection and try again"
echo -en "\\0033[0;39m"
echo "OLPC-2.6 kernel source dowanload failed. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Downloaded OLPC-2.6 kernel source. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
else
cd $git_clone
git reset --hard HEAD@{1}
git clean -fdx
git fetch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to update the kernel sources."
echo -e "\\0033[1;34m"
echo "Hit \"c\" and then \"enter\" to continue"
echo "with the old sources or just \"enter\" to quit,"
echo "check the connection and try latter."
echo -en "\\0033[0;39m"
read CONTINUE
if [ "$CONTINUE" = "c" ];then
echo "OLPC-2.6 git update failed. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
else
exit 0
fi
else
echo "Updated OLPC-2.6 git. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
fi
sync
if [ ! -d "$git_clone_aufs2" ] ; then
cd $sources
git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs2-standalone.git 2>&1
if [ $? -ne 0 ]; then
git clone git://git.c3sl.ufpr.br/aufs/aufs2-standalone.git
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to download the Aufs sources."
echo "Check the connection and try again"
echo -en "\\0033[0;39m"
echo "Aufs2 source dowanload failed. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
fi
else
echo "Downloaded Aufs2 sources. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
else
cd $git_clone_aufs2
git reset --hard HEAD@{1}
git clean -fdx
git fetch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to update the Aufs sources."
echo -e "\\0033[1;34m"
echo "Hit \"c\" and then \"enter\" to continue"
echo "with the old sources or just \"enter\" to quit,"
echo "check the connection and try latter."
echo -en "\\0033[0;39m"
read CONTINUE
if [ "$CONTINUE" = "c" ];then
echo "Aufs2 git update failed. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
else
exit 0
fi
else
echo "Updated Aufs2 git. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
fi
sync
if [ ! -d "$git_clone_aufs3" ] ; then
cd $sources
git clone git://aufs.git.sourceforge.net/gitroot/aufs/aufs3-standalone.git 2>&1
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to download the Aufs sources."
echo "Check the connection and try again"
echo -en "\\0033[0;39m"
echo "Aufs3 source dowanload failed. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Downloaded Aufs3 sources. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
else
cd $git_clone_aufs3
git reset --hard HEAD@{1}
git clean -fdx
git fetch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to update the Aufs sources."
echo -e "\\0033[1;34m"
echo "Hit \"c\" and then \"enter\" to continue"
echo "with the old sources or just \"enter\" to quit,"
echo "check the connection and try latter."
echo -en "\\0033[0;39m"
read CONTINUE
if [ "$CONTINUE" = "c" ];then
echo "Aufs git update failed. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
else
exit 0
fi
else
echo "Updated Aufs3 git. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
fi
sync
}
export -f get_sources
patch_sources()
{
output="$BASEDIR"
# Sellect kernel to build
echo
echo -e "\\0033[1;34m"
echo "To build the experimental 3.3 kernel"
echo "hit \"3\" and then \"enter\" "
echo "or just \"enter\" to build the 2.6.35 kernel"
echo -en "\\0033[0;39m"
read CONTINUE
if [ "$CONTINUE" = "3" ];then
# Point aufs git to kernel version 3.3
cd $git_clone_aufs3
git checkout origin/aufs3.3
if [ ! -d patches ] ; then
mkdir patches
mv *.patch patches/
else
mv *.patch patches/
fi
# Patch the OLPC kernel
cd $git_clone
git checkout origin/x86-3.3
sync
# Apply patches and aufs source in kernel
cp -aR $git_clone_aufs3/fs .
cp -aR $git_clone_aufs3/Documentation .
cp -a $git_clone_aufs3/include/linux/aufs_type.h include/linux/
echo "Copied Aufs-3.3 files into the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
for patch in $git_clone_aufs3/patches/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
LAYERFS="Aufs"
fi
done
# Apply config patches
for patch in $patches/3.3/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
done
echo "Building kernel 3.3 with Aufs. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
else
# Point aufs git to kernel version 2.6.35
cd $git_clone_aufs2
git checkout origin/aufs2.2-35
if [ ! -d patches ] ; then
mkdir patches
mv *.patch patches/
else
mv *.patch patches/
fi
# Patch the OLPC kernel
cd $git_clone
git checkout origin/olpc-2.6.35
sync
# Apply patches and aufs source in kernel
cp -aR $git_clone_aufs2/fs .
cp -aR $git_clone_aufs2/Documentation .
cp -a $git_clone_aufs2/include/linux/aufs_type.h include/linux/
echo "Copied Aufs-2.6.35 files into the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
for patch in $git_clone_aufs2/patches/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
LAYERFS="Aufs"
fi
done
# Apply config patches
for patch in $patches/2.6/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
done
# Patch arch/x86/include/asm/ptrace.h if we compile with gcc 4.7.x
if [ "`gcc --version | grep ' 4.7.'`" != "" ] ; then
patch -p1 < $patches/gcc47x.patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply gcc47x.patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply gcc47x.patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied gcc47x.patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
fi
echo "Building kernel 2.6.35 with Aufs. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
# Apply puppy patches
for patch in $patches/puppy/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
done
# Remove the "+" signed that is added at the end of the kernel extraversion
sed -rie 's/echo "\+"/#echo "\+"/' scripts/setlocalversion
sync
}
export -f patch_sources
make_XO1_kernel()
{
# Make output dirs
mkdir $output/XO1kernel
output_k=$output/XO1kernel
mkdir $output/boot10
# Check if a build is there
if [ -f $output/boot10/vmlinuz ] ; then
echo -e "\\0033[1;31m"
echo " An XO-1 kernel is alreday build! "
echo " Please detete or move it and run again "
echo -en "\\0033[0;39m"
xoolpcfunc
exit 0
fi
# Make XO-1 kernel
echo -e "\\0033[1;34m"
echo "Making XO-1 kernel"
echo -en "\\0033[0;39m"
KVER=`cat Makefile |grep ^VERSION | cut -f2 -d "=" | tr -d ' '`
KPATCH=`cat Makefile |grep ^PATCHLEVEL | cut -f2 -d "=" | tr -d ' '`
KSUB=`cat Makefile |grep ^SUBLEVEL | cut -f2 -d "=" | tr -d ' '`
kernextr=`cat Makefile |grep ^EXTRAVERSION | cut -f2 -d "=" | tr -d ' ' | cut -f1 -d "_"`
gitcommit=`cat .git/HEAD | awk '{print substr($0,1,7)}'`
kernel_ver=""$KVER"."$KPATCH"."$KSUB""$kernextr"_xo1-"$(date "+%Y%m%d.%H%M")".olpc."$gitcommit"_"$LAYERFS""
# Change kernel extra version
NOkernextr=`cat Makefile |grep ^EXTRAVERSION | cut -f2 -d "="`
if [ "$NOkernextr" = "" ] ; then
sed -i "s/^EXTRAVERSION =/EXTRAVERSION = "$kernextr"_xo1-"$(date "+%Y%m%d.%H%M")".olpc."$gitcommit"_"$LAYERFS"/" Makefile
else
sed -i "s/^EXTRAVERSION = [.a-zA-Z0-9_-]*/EXTRAVERSION = "$kernextr"_xo1-"$(date "+%Y%m%d.%H%M")".olpc."$gitcommit"_"$LAYERFS"/" Makefile
fi
make clean distclean
make mrproper
sync
cp arch/x86/configs/xo_1_defconfig .config
make headers_check
mkdir -p $output_k/kernel-headers-$kernel_ver/usr
make INSTALL_HDR_PATH=$output_k/kernel-headers-$kernel_ver/usr headers_install
find $output_k/kernel-headers-$kernel_ver/usr/include \( -name .install -o -name ..install.cmd \) -delete
echo "Made kernel headers. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
make -j $CPUs bzImage modules
cp .config $output/boot10/config-$kernel_ver
cp arch/x86/boot/bzImage $output/boot10/vmlinuz
make INSTALL_MOD_PATH=$output_k/ modules_install
# Pack kernel firmware with kernel headers
mkdir -p $output_k/kernel-headers-$kernel_ver/lib
mv $output_k/lib/firmware $output_k/kernel-headers-$kernel_ver/lib/
# Fix the modules.dep since without full path do not work in puppy's initrd
sed -i "s/kernel\//\/lib\/modules\/"$kernel_ver"\/kernel\//g" $output_k/lib/modules/$kernel_ver/modules.dep
# Fix symlinks
rm $output_k/lib/modules/$kernel_ver/build
rm $output_k/lib/modules/$kernel_ver/source
ln -sf /usr/src/linux $output_k/lib/modules/$kernel_ver/build
ln -sf /usr/src/linux $output_k/lib/modules/$kernel_ver/source
make clean distclean
sync
echo "Made kernel and modules. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
package_source
cd $output_k/
dir_2_pet kernel-headers-$kernel_ver/
cd $git_clone
echo "XO-1 kernel build finished. $(date "+%Y-%m-%d %H:%M") " >> $CWD/build.log
}
export -f make_XO1_kernel
make_XO15_kernel()
{
# Make output dirs
mkdir $output/XO1.5kernel
output_k=$output/XO1.5kernel
mkdir $output/boot15
# Check if a build is there
if [ -f $output/boot15/vmlinuz ] ; then
echo "\\0033[1;31m"
echo " An XO-1.5 kernel is alreday build! "
echo " Please detete or move it and run again "
echo -en "\\0033[0;39m"
xoolpcfunc
exit 0
fi
# Make XO-1.5 kernel
echo -e "\\0033[1;34m"
echo "Making XO-1.5 kernel"
echo -en "\\0033[0;39m"
KVER=`cat Makefile |grep ^VERSION | cut -f2 -d "=" | tr -d ' '`
KPATCH=`cat Makefile |grep ^PATCHLEVEL | cut -f2 -d "=" | tr -d ' '`
KSUB=`cat Makefile |grep ^SUBLEVEL | cut -f2 -d "=" | tr -d ' '`
kernextr=`cat Makefile |grep ^EXTRAVERSION | cut -f2 -d "=" | tr -d ' ' | cut -f1 -d "_"`
gitcommit=`cat .git/HEAD | awk '{print substr($0,1,7)}'`
kernel_ver=""$KVER"."$KPATCH"."$KSUB""$kernextr"_xo1.5-"$(date "+%Y%m%d.%H%M")".olpc."$gitcommit"_"$LAYERFS""
# Change kernel extra version
NOkernextr=`cat Makefile |grep ^EXTRAVERSION | cut -f2 -d "="`
if [ "$NOkernextr" = "" ] ; then
sed -i "s/^EXTRAVERSION =/EXTRAVERSION = "$kernextr"_xo1.5-"$(date "+%Y%m%d.%H%M")".olpc."$gitcommit"_"$LAYERFS"/" Makefile
else
sed -i "s/^EXTRAVERSION = [.a-zA-Z0-9_-]*/EXTRAVERSION = "$kernextr"_xo1.5-"$(date "+%Y%m%d.%H%M")".olpc."$gitcommit"_"$LAYERFS"/" Makefile
fi
make clean distclean
make mrproper
sync
cp arch/x86/configs/xo_1.5_defconfig .config
make headers_check
mkdir -p $output_k/kernel-headers-$kernel_ver/usr
make INSTALL_HDR_PATH=$output_k/kernel-headers-$kernel_ver/usr headers_install
find $output_k/kernel-headers-$kernel_ver/usr/include \( -name .install -o -name ..install.cmd \) -delete
echo "Made kernel headers. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
make -j $CPUs bzImage modules
cp .config $output/boot15/config-$kernel_ver
cp arch/x86/boot/bzImage $output/boot15/vmlinuz
make INSTALL_MOD_PATH=$output_k/ modules_install
# Pack kernel firmware with kernel headers
mkdir -p $output_k/kernel-headers-$kernel_ver/lib
mv $output_k/lib/firmware $output_k/kernel-headers-$kernel_ver/lib/
# Fix the modules.dep since without full path do not work in puppy's initrd
sed -i "s/kernel\//\/lib\/modules\/"$kernel_ver"\/kernel\//g" $output_k/lib/modules/$kernel_ver/modules.dep
# Fix symlinks
rm $output_k/lib/modules/$kernel_ver/build
rm $output_k/lib/modules/$kernel_ver/source
ln -sf /usr/src/linux $output_k/lib/modules/$kernel_ver/build
ln -sf /usr/src/linux $output_k/lib/modules/$kernel_ver/source
make clean distclean
sync
echo "Made kernel and modules. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
package_source
cd $output_k/
dir_2_pet kernel-headers-$kernel_ver/
cd $git_clone
echo "XO-1.5 kernel build finished. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
}
export -f make_XO15_kernel
build_ARM_175()
{
# Point aufs git to kernel version 3.0
cd $git_clone_aufs3
git reset --hard HEAD@{1}
git clean -fdx
git checkout origin/aufs3.0
if [ ! -d patches ] ; then
mkdir patches
mv *.patch patches/
else
mv *.patch patches/
fi
# Patch the loop.c patch for arm-3.0-wip !
patch -p1 < $patches/aufs3arm_loop.c.patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on aufs3. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Patched aufs3-loopback.patch. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
# Patch the OLPC kernel
cd $git_clone
git reset --hard HEAD@{1}
git clean -fdx
git checkout origin/arm-3.0-wip
sync
# Apply patches and aufs source in kernel
cp -aR $git_clone_aufs3/fs .
cp -aR $git_clone_aufs3/Documentation .
cp -a $git_clone_aufs3/include/linux/aufs_type.h include/linux/
echo "Copied Aufs-3.0 files into the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
for patch in $git_clone_aufs3/patches/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
LAYERFS="Aufs"
fi
done
# Apply config patches
for patch in $patches/3.arm/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
done
# Apply puppy patches
for patch in $patches/puppy/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
done
# Remove the "+" signed that is added at the end of the kernel extraversion
sed -rie 's/echo "\+"/#echo "\+"/' scripts/setlocalversion
# Cahnge "dirty" to "Aufs" in case we build in Fedora
sed -rie 's/\-dirty/\.olpc\.\"\$\(date \"+\%Y\%m\%d\.\%H\%M\"\)\"\.armv7\.Aufs/g' scripts/setlocalversion
echo "Building ARM kernel 3.0 with Aufs. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
sync
################ (cross) compile the XO-1.75 ARM kernel ####################
# Make output dirs
output="$BASEDIR"
mkdir $output/XO175kernel
output_k=$output/XO175kernel
mkdir $output/boot175
# Check if a build is there
if [ -f $output/boot175/vmlinuz ] ; then
echo -e "\\0033[1;31m"
echo " An XO-1.75 kernel is alreday build! "
echo " Please detete or move it and run again "
echo -en "\\0033[0;39m"
xoolpcfunc
exit 0
fi
# Check if we can compile in this machine
if [ "`uname -m | grep -i armv7`" = "" ] ; then
# Check if we have the armv7 cross-compile gcc
if [ ! -f /opt/crosstool/gcc-4.6.0/bin/armv7-unknown-linux-gnueabi-gcc-4.6.0 ] \
&& [ ! -f /usr/bin/arm-linux-gnu-gcc ] ; then
echo -e "\\0033[1;31m"
echo " You need to have an ARM cross compiler installed to compile the XO-1.75 ARM kernel."
echo -en "\\0033[0;39m"
if [ -f /etc/fedora-release ] && [ "`cat /etc/issue | grep -i fedora`" != "" ] ; then
echo -e "\\0033[1;34m"
echo " Pleas yum install gcc-arm-linux-gnu and run the script again."
echo -en "\\0033[0;39m"
exit 1
elif [ "`uname -m | grep x86_64`" != "" ] ; then
echo -e "\\0033[1;34m"
echo " Please download gcc-4.6.0-from-x86_64-to-armv7 from here"
echo " http://dev.laptop.org/~cjb/gcc-4.6.0-from-x86_64-to-armv7.tar.bz2"
echo " extract it in /opt/crosstool and run the script again"
echo -en "\\0033[0;39m"
exit 1
else
echo -e "\\0033[1;31m"
echo " You need to be running an x86_64 OS or a recent Fedora build"
echo " for this script to work. Exiting..."
echo -en "\\0033[0;39m"
exit 1
fi
fi
fi
# Make XO-1.75 kernel
echo -e "\\0033[1;34m"
echo "Making XO-1.75 kernel"
echo -en "\\0033[0;39m"
if [ "`uname -m | grep -i armv7`" = "" ] ; then
if [ ! -f /etc/fedora-release ] && [ "`cat /etc/issue | grep -i fedora`" = "" ] ; then
export PATH=/opt/crosstool/gcc-4.6.0/bin:$PATH
export ARCH=arm
export CROSS_COMPILE=armv7-unknown-linux-gnueabi-
else
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnu-
fi
fi
make clean distclean
make mrproper
cp arch/arm/configs/xo_175_defconfig .config
make -j $CPUs zImage modules
cp arch/arm/boot/zImage $output/boot175/vmlinuz
make INSTALL_MOD_PATH=$output_k/ modules_install
echo "Made kernel and modules. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
kernel_ver=`cat include/config/kernel.release`
cp .config $output/boot175/config-$kernel_ver
make headers_check
mkdir -p $output_k/kernel-headers-$kernel_ver/usr
make INSTALL_HDR_PATH=$output_k/kernel-headers-$kernel_ver/usr headers_install
find $output_k/kernel-headers-$kernel_ver/usr/include \( -name .install -o -name ..install.cmd \) -delete
echo "Made kernel headers. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
# Pack kernel firmware with kernel headers
mkdir -p $output_k/kernel-headers-$kernel_ver/lib
mv $output_k/lib/firmware $output_k/kernel-headers-$kernel_ver/lib/
# Fix symlinks
rm $output_k/lib/modules/$kernel_ver/build
rm $output_k/lib/modules/$kernel_ver/source
ln -sf /usr/src/linux $output_k/lib/modules/$kernel_ver/build
ln -sf /usr/src/linux $output_k/lib/modules/$kernel_ver/source
make clean distclean
sync
package_source
cd $output_k/
dir_2_pet kernel-headers-$kernel_ver/
cd $git_clone
echo "XO-1.75 kernel build finished. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
}
export -f build_ARM_175
build_ARM_4()
{
# Point aufs git to kernel version 3.0
cd $git_clone_aufs3
git reset --hard HEAD@{1}
git clean -fdx
git checkout origin/aufs3.5
if [ ! -d patches ] ; then
mkdir patches
mv *.patch patches/
else
mv *.patch patches/
fi
# Patch the OLPC kernel
cd $git_clone
git reset --hard HEAD@{1}
git clean -fdx
git checkout origin/arm-3.5
sync
# Apply patches and aufs source in kernel
cp -aR $git_clone_aufs3/fs .
cp -aR $git_clone_aufs3/Documentation .
cp -a $git_clone_aufs3/include/linux/aufs_type.h include/linux/
echo "Copied Aufs files into the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
for patch in $git_clone_aufs3/patches/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
LAYERFS="Aufs"
fi
done
# Apply config patches
for patch in $patches/3.5arm/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
done
# Apply puppy patches
for patch in $patches/puppy/*; do
echo "Applying $patch"
patch -p1 < $patch
if [ $? -ne 0 ]; then
echo -e "\\0033[1;31m"
echo "Error: failed to apply $patch on the kernel sources."
echo -en "\\0033[0;39m"
echo "Failed to apply $patch on the kernel sources. Kernel build aborted $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
exit 1
else
echo "Applied $patch on the kernel sources $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
fi
done
# Remove the "+" signed that is added at the end of the kernel extraversion
sed -rie 's/echo "\+"/#echo "\+"/' scripts/setlocalversion
# Cahnge "dirty" to "Aufs" in case we build in Fedora
sed -rie 's/\-dirty/\.olpc\.\"\$\(date \"+\%Y\%m\%d\.\%H\%M\"\)\"\.armv7\.Aufs/g' scripts/setlocalversion
echo "Building ARM kernel 3.5 with Aufs. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
sync
################ (cross) compile the XO-4 ARM kernel ####################
# Make output dirs
output="$BASEDIR"
mkdir $output/XO4kernel
output_k=$output/XO4kernel
mkdir $output/boot40
# Check if a build is there
if [ -f $output/boot40/vmlinuz ] ; then
echo -e "\\0033[1;31m"
echo " An XO-4 kernel is alreday build! "
echo " Please detete or move it and run again "
echo -en "\\0033[0;39m"
xoolpcfunc
exit 0
fi
# Check if we can compile in this machine
if [ "`uname -m | grep -i armv7`" = "" ] ; then
# Check if we have the armv7 cross-compile gcc
if [ ! -f /opt/crosstool/gcc-4.6.0/bin/armv7-unknown-linux-gnueabi-gcc-4.6.0 ] \
&& [ ! -f /usr/bin/arm-linux-gnu-gcc ] ; then
echo -e "\\0033[1;31m"
echo " You need to have an ARM cross compiler installed to compile the XO-4 ARM kernel."
echo -en "\\0033[0;39m"
if [ -f /etc/fedora-release ] && [ "`cat /etc/issue | grep -i fedora`" != "" ] ; then
echo -e "\\0033[1;34m"
echo " Pleas yum install gcc-arm-linux-gnu and run the script again."
echo -en "\\0033[0;39m"
exit 1
elif [ "`uname -m | grep x86_64`" != "" ] ; then
echo -e "\\0033[1;34m"
echo " Please download gcc-4.6.0-from-x86_64-to-armv7 from here"
echo " http://dev.laptop.org/~cjb/gcc-4.6.0-from-x86_64-to-armv7.tar.bz2"
echo " extract it in /opt/crosstool and run the script again"
echo -en "\\0033[0;39m"
exit 1
else
echo -e "\\0033[1;31m"
echo " You need to be running an x86_64 OS or a recent Fedora build"
echo " for this script to work. Exiting..."
echo -en "\\0033[0;39m"
exit 1
fi
fi
fi
# Make XO-4 kernel
echo -e "\\0033[1;34m"
echo "Making XO-4 kernel"
echo -en "\\0033[0;39m"
if [ "`uname -m | grep -i armv7`" = "" ] ; then
if [ ! -f /etc/fedora-release ] && [ "`cat /etc/issue | grep -i fedora`" = "" ] ; then
export PATH=/opt/crosstool/gcc-4.6.0/bin:$PATH
export ARCH=arm
export CROSS_COMPILE=armv7-unknown-linux-gnueabi-
else
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnu-
fi
fi
make clean distclean
make mrproper
cp arch/arm/configs/xo_4_defconfig .config
make -j $CPUs zImage modules
cp arch/arm/boot/zImage $output/boot40/vmlinuz
make INSTALL_MOD_PATH=$output_k/ modules_install
echo "Made kernel and modules. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
kernel_ver=`cat include/config/kernel.release`
cp .config $output/boot40/config-$kernel_ver
make headers_check
mkdir -p $output_k/kernel-headers-$kernel_ver/usr
make INSTALL_HDR_PATH=$output_k/kernel-headers-$kernel_ver/usr headers_install
find $output_k/kernel-headers-$kernel_ver/usr/include \( -name .install -o -name ..install.cmd \) -delete
echo "Made kernel headers. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
# Pack kernel firmware with kernel headers
mkdir -p $output_k/kernel-headers-$kernel_ver/lib
mv $output_k/lib/firmware $output_k/kernel-headers-$kernel_ver/lib/
# Fix symlinks
rm $output_k/lib/modules/$kernel_ver/build
rm $output_k/lib/modules/$kernel_ver/source
ln -sf /usr/src/linux $output_k/lib/modules/$kernel_ver/build
ln -sf /usr/src/linux $output_k/lib/modules/$kernel_ver/source
make clean distclean
sync
package_source
cd $output_k/
dir_2_pet kernel-headers-$kernel_ver/
cd $git_clone
echo "XO-4 kernel build finished. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
}
export -f build_ARM_4
package_source()
{
echo -e "\\0033[1;34m"
echo "Packing the kernel source. May take a little... "
echo -en "\\0033[0;39m"
rm -rf $output/"$kernel_ver".source
sync
mkdir -p $output/"$kernel_ver".source/usr/src/linux
tar -X */.gitignore -X */*/.gitignore -X */*/*/.gitignore \
-X */*/*/*/.gitignore -X */*/*/*/*/.gitignore olpc/.tarignore \
--exclude=.git -cf - . | tar -xf - -C $output/"$kernel_ver".source/usr/src/linux
sync
cd $output
mksquashfs "$kernel_ver".source/ $output_k/$kernel_ver.source.sfs
sync
rm -rf "$kernel_ver".source
echo "Packed the kernel source into an SFS. $(date "+%Y-%m-%d %H:%M")" >> $CWD/build.log
}
export -f package_source
dir_2_pet()
{
#Barry Kauler's dir2pet modified to work in XOpup_kernel_builder.sh mavrothal
ADIR=$1
MYPID=${$}
#split ADIR path/filename into components...
BASEPKG="`basename $ADIR`"
DIRPKG="`dirname $ADIR`"
[ "$DIRPKG" = "/" ] && DIRPKG=""
NAMEONLY="kernel-headers-$kernel_ver"
PUPMENUDESCR="kernel-headers for the $kernel_ver kernel"
PUPCATEGORY="BuildingBlock"
rm -f $DIRPKG/${BASEPKG}.tar 2>/dev/null
rm -f $DIRPKG/${BASEPKG}.tar.gz 2>/dev/null
rm -f $DIRPKG/${BASEPKG}.pet 2>/dev/null
SIZEK="`du -s -k $DIRPKG/$BASEPKG | cut -f 1`" #w476
echo ""$NAMEONLY"|"$NAMEONLY"|||"$PUPCATEGORY"|"$SIZEK"||"$NAMEONLY".pet||"$PUPMENUDESCR"||||" > $DIRPKG/$BASEPKG/pet.specs
# Add pinstall.sh
echo '#!/bin/sh' > $DIRPKG/$BASEPKG/pinstall.sh