-
Notifications
You must be signed in to change notification settings - Fork 9
/
mediatree-kbuild.sh
executable file
·970 lines (851 loc) · 28.6 KB
/
mediatree-kbuild.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
#!/bin/bash
#
# Ubuntu + LinuxTV.org media tree custom kernel package builder
# This script produces installable kernel packages from
# - Ubuntu kernel sources for a specific release
# - Latest upstream LinuxTV media tree drivers
# - Minimal patches to get the above to build
# - Additional patches to enable HW and/or
# optimizations not yet upstreamed
#
# This script also:
# - A full patch series for reproduction
# - Generate latest LinuxTV driver patch set on demand
#
# Copyright (C) 2017 Brad Love <brad at nextdimension dot cc>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR #PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program.
# If not, see http://www.gnu.org/licenses/.
#
################################################
if [ -f ".user_env_file" ] ; then
. .user_env_file
fi
################################################
[ -z "${U_FULLNAME}" ] && U_FULLNAME="`git config --global user.name`"
[ -z "${U_EMAIL}" ] && U_EMAIL="`git config --global user.email`"
if [ -z "${U_FULLNAME}" -o -z "${U_EMAIL}" ] ; then
echo 'You must set git global user name and email address:'
echo ' git config --global user.name "your name"'
echo ' git config --global user.email "your email address"'
exit 251
fi
if [ -z "${KERNEL_ABI_TAG}" ] ; then
if [ -z "${DISTRO_BRANCH}" ] ; then
KERNEL_ABI_TAG="+mediatree+hauppauge"
elif [ "${DISTRO_BRANCH:0:11}" == "master-next" ] ; then
KERNEL_ABI_TAG="+mediatree+hauppauge"
elif [ "${DISTRO_BRANCH:0:4}" == "hwe-" ] ; then
KERNEL_ABI_TAG="+mediatree+hauppauge~hwe"
else
KERNEL_ABI_TAG="+mediatree+hauppauge~${DISTRO_BRANCH}"
fi
fi
if [ -z "${DISTRO_NAME}" ] ; then
if [ ! -f /etc/os-release ] ; then
echo "No /etc/os-release, cannot determine running OS..."
exit 250
fi
eval `cat /etc/os-release`
DISTRO_NAME=${ID}
fi
if [ -z "${DISTRO_CODENAME}" ] ; then
if [ ! -f /etc/os-release ] ; then
echo "No /etc/os-release, cannot determine running OS..."
exit 250
fi
eval `cat /etc/os-release`
DISTRO_CODENAME=${VERSION_CODENAME}
fi
#[ -z "${DISTRO_GIT_REVISION}" ] && DISTRO_GIT_REVISION=50aaaec159365f8f8788e054048545e7ec9734f1
################################################
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
TRY_UPDATE=NO
TIP_UBUNTU_VERSION=
export TOP_DEVDIR=`pwd`
if [ -f ".state_env_file" ] ; then
. .state_env_file
if [ -z "${DISTRO_BRANCH}" ] ; then
export KB_PATCH_DIR="${TOP_DEVDIR}/patches/${DISTRO_NAME}-${DISTRO_CODENAME}-${KVER}.${KMAJ}.0"
elif [ "${DISTRO_BRANCH:0:11}" == "master-next" ] ; then
export KB_PATCH_DIR="${TOP_DEVDIR}/patches/${DISTRO_NAME}-${DISTRO_CODENAME}-${KVER}.${KMAJ}.0"
else
export KB_PATCH_DIR="${TOP_DEVDIR}/patches/${DISTRO_NAME}-${DISTRO_CODENAME}-${DISTRO_BRANCH}-${KVER}.${KMAJ}.0"
fi
if [ ${KVER} -eq 4 -a ${KMAJ} -lt 16 ] ; then
DATE_STRING="+%Y%m%d%H%M"
else
DATE_STRING="+%y%m%d%H%M"
fi
fi
## Set env var V4L_SYNC_DATE to a specific date to override latest tarball
if [ -z "${V4L_SYNC_DATE}" -a -f "${TOP_DEVDIR}/.flag-media-tree-sync-time" ]; then
export V4L_SYNC_DATE=`cat ${TOP_DEVDIR}/.flag-media-tree-sync-time`
fi
function get_ubuntu_kver()
{
export KVER=`grep VERSION ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}/Makefile | head -n 1 | cut -d ' ' -f 3`
export KMAJ=`grep PATCHLEVEL ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}/Makefile | head -n 1 | cut -d ' ' -f 3`
export KMIN=0
export K_ABI_A=`head -n1 ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}/debian.master/changelog | cut -d'-' -f2 | cut -d'.' -f1`
export K_ABI_B=`head -n1 ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}/debian.master/changelog | cut -d'.' -f4 | cut -d')' -f1`
}
function write_state_env()
{
echo "KVER=${KVER}" > ${TOP_DEVDIR}/.state_env_file
echo "KMAJ=${KMAJ}" >> ${TOP_DEVDIR}/.state_env_file
echo "KMIN=0" >> ${TOP_DEVDIR}/.state_env_file
echo "K_ABI_A=${K_ABI_A}" >> ${TOP_DEVDIR}/.state_env_file
echo "K_ABI_B=${K_ABI_B}" >> ${TOP_DEVDIR}/.state_env_file
echo "K_ABI_MOD=${K_ABI_MOD}" >> ${TOP_DEVDIR}/.state_env_file
echo "K_BUILD_VER=${K_BUILD_VER}" >> ${TOP_DEVDIR}/.state_env_file
echo "DISTRO_GIT_REVISION=${DISTRO_GIT_REVISION}" >> ${TOP_DEVDIR}/.state_env_file
echo "" >> ${TOP_DEVDIR}/.state_env_file
}
function get_ubuntu()
{
ret_val=0
cd ${TOP_DEVDIR}
if [ -z "${1}" ]; then
TARGET_DIR=${DISTRO_NAME}-${DISTRO_CODENAME}
else
TARGET_DIR=${1}
fi
if [ ! -d "${TARGET_DIR}" -a -d ".clean-master-repo" ] ; then
cd .clean-master-repo
cd -
git clone ${TOP_DEVDIR}/.clean-master-repo ${TARGET_DIR}
elif [ ! -d "${TARGET_DIR}" ] ; then
if [ -z "${DISTRO_BRANCH}" ] ; then
if [ "${DISTRO_NAME}" == "ubuntu" ] ; then
git clone --depth 1 git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/${DISTRO_CODENAME} ${TARGET_DIR}
fi
else
if [ "${DISTRO_NAME}" == "ubuntu" ] ; then
if [ "${DISTRO_BRANCH}" == "raspi" ] ; then
git clone --depth 1 --single-branch git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux-raspi/+git/${DISTRO_CODENAME} ${TARGET_DIR}
else
git clone --depth 1 --single-branch git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/${DISTRO_CODENAME} -b "${DISTRO_BRANCH}" ${TARGET_DIR}
fi
fi
fi
fi
if [ -n "${DISTRO_GIT_REVISION}" -a "${TARGET_DIR}" != ".clean-master-repo" ] ; then
cd ${TARGET_DIR}
git fetch
if [ -n "${TIP_DISTRO_GIT_REVISION}" -a "${TIP_DISTRO_GIT_REVISION}" != "${DISTRO_GIT_REVISION}" ] ; then
git checkout ${TIP_DISTRO_GIT_REVISION}
[ -z "${1}" ] && DISTRO_GIT_REVISION=${TIP_DISTRO_GIT_REVISION}
else
git checkout ${DISTRO_GIT_REVISION}
fi
cd ..
else
cd ${TARGET_DIR}
if [ -z "${DISTRO_BRANCH}" -a "${TARGET_DIR}" != ".clean-master-repo" ] ; then
git pull
elif [ -z "${DISTRO_BRANCH}" -o "${DISTRO_NAME}" == "ubuntu" -a "${DISTRO_BRANCH}" == "raspi" ] ; then
git pull
else
echo git fetch --all
git fetch --all
echo git reset --hard HEAD
git reset --hard HEAD
echo git checkout -b tmp_branch_cleanup_asdfghjkl
git checkout -b tmp_branch_cleanup_asdfghjkl
echo git branch -D ${DISTRO_BRANCH}
git branch -D ${DISTRO_BRANCH}
echo git checkout -b ${DISTRO_BRANCH} origin/${DISTRO_BRANCH}
git checkout -b ${DISTRO_BRANCH} origin/${DISTRO_BRANCH}
echo git branch -D tmp_branch_cleanup_asdfghjkl
git branch -D tmp_branch_cleanup_asdfghjkl
fi
if [ -z "${DISTRO_BRANCH}" -o "${DISTRO_NAME}" == "ubuntu" -a "${DISTRO_BRANCH}" == "raspi" ] ; then
CUR_DISTRO_GIT_REVISION=`cat .git/refs/heads/master`
else
CUR_DISTRO_GIT_REVISION=`cat .git/refs/heads/${DISTRO_BRANCH}`
fi
if [ -n "${DISTRO_GIT_REVISION}" -a "${CUR_DISTRO_GIT_REVISION}" != "${DISTRO_GIT_REVISION}" ] ; then
echo -e "${RED}###############################################"
echo -e "${RED}###############################################"
echo -e "${RED}###############################################"
echo -e "${RED}################### ${GREEN}ATTENTION ${RED}#################"
echo -e "${RED}####### ${GREEN}Ubuntu master revision updated! ${RED}#######"
echo -e "${RED}## ${NC}${CUR_DISTRO_GIT_REVISION} ${RED}###"
echo -e "${RED}###############################################"
echo -e "${RED}### ${NC}Set env var MEDIATREE_KBUILD_UPDATE=YES ${RED}###"
echo -e "${RED}############# ${NC}to update build ${RED}#################"
echo -e "${RED}###############################################${NC}"
ret_val=1
if [ "${MEDIATREE_KBUILD_UPDATE}" == "YES" ] ; then
TIP_DISTRO_GIT_REVISION=${CUR_DISTRO_GIT_REVISION}
TRY_UPDATE=YES
fi
elif [ -z "${1}" ] ; then
DISTRO_GIT_REVISION=${CUR_DISTRO_GIT_REVISION}
fi
fi
if [ -z "${1}" ] ; then
get_ubuntu_kver
write_state_env
export KB_PATCH_DIR="${TOP_DEVDIR}/patches/${DISTRO_NAME}-${DISTRO_CODENAME}-${KVER}.${KMAJ}.0"
fi
return ${ret_val}
}
function get_media_build()
{
cd ${TOP_DEVDIR}
if [ -z "${1}" ]; then
TARGET_DIR=media_build
else
TARGET_DIR=${1}
fi
echo "Initializing/Updating media_build system"
echo ""
if [ ! -d "${TARGET_DIR}" ] ; then
git clone git://linuxtv.org/media_build.git ${TARGET_DIR}
retval=$?
else
cd ${TARGET_DIR}
git pull
retval=$?
cd ..
fi
return ${retval}
}
function download_media_tree()
{
cd ${TOP_DEVDIR}/media_build
git clean -xdf linux/
git checkout linux/
git pull
make -C linux/ download
# UTC time marker for LinuxTV media tree sync
export V4L_SYNC_DATE=`date -u +%Y-%0m-%0d-%0k-%0M`
echo ${V4L_SYNC_DATE} > ${TOP_DEVDIR}/.flag-media-tree-sync-time
# generate unpatched tarball of currentlinuxtv.org media tree
make -C linux/ untar
cd linux
# v4l2 version define, generated by make command
cp -av kernel_version.h include/linux
tar -czf ${TOP_DEVDIR}/linux-media-tree-${V4L_SYNC_DATE}.tgz drivers include sound git_log
}
function unpack_media_tree()
{
cd ${TOP_DEVDIR}/media_build
git clean -xdf linux/
git checkout linux/
cd linux
if [ -f "${TOP_DEVDIR}/linux-media-tree-${V4L_SYNC_DATE}.tgz" ] ; then
echo "############################################################"
echo "############################################################"
echo "######### Unpacking linux-media-tree-${V4L_SYNC_DATE}.tgz"
tar -xzf ${TOP_DEVDIR}/linux-media-tree-${V4L_SYNC_DATE}.tgz
echo "############################################################"
echo "############################################################"
return 0
else
echo "${TOP_DEVDIR}/linux-media-tree-${V4L_SYNC_DATE}.tgz not found"
fi
return 1
}
function gen_media_tree_tarball_patched()
{
cd ${TOP_DEVDIR}/media_build
cd linux
# linuxtv media tree syslog messages and config-compat.h generation
perl ../v4l/scripts/make_config_compat.pl ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}/ ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}/debian.master/config/config.common.ubuntu config-compat.h
perl ./version_patch.pl
# apply kernel version specific backport patches
for i in `./patches_for_kernel.pl ${KVER}.${KMAJ}.0` ; do patch -p1 < ../backports/$i; done;
# copy includes where we need them for integration
echo -e '/* STUB CONFIG-MYCOMPAT.H */\n\n' > include/media/config-mycompat.h
echo '#undef NEED_USB_SPEED_WIRELESS' >> include/media/config-mycompat.h
cp -av config-compat.h include/media
cp -v ../v4l/compat.h include/media
# tar up fully kernel specific patched media tree tarball
tar -czf ${TOP_DEVDIR}/linux-media-tree-${KVER}.${KMAJ}.${KMIN}-${V4L_SYNC_DATE}.tgz drivers include sound
}
function reset_repo_head_hard()
{
cd ${TOP_DEVDIR}
if [ -z "${1}" -o ! -d "${1}" ]; then
TARGET_DIR=${DISTRO_NAME}-${DISTRO_CODENAME}
else
TARGET_DIR=${1}
fi
[ ! -d "${TARGET_DIR}" ] && return 2
if [ "$2" == "YES" ] ; then
x=YES
else
echo "WARNING: reset to HEAD^ *and* irreversibly clear ${TARGET_DIR}? YES/NO"
read x
fi
if [ "$x" == "YES" ] ; then
cd ${TARGET_DIR}
git fetch
git reset --hard HEAD^
git clean -xdf
return 0
else
return 1
fi
}
function reset_repo_revision_hard()
{
cd ${TOP_DEVDIR}
if [ -z "${1}" -o ! -d "${1}" ]; then
TARGET_DIR=${DISTRO_NAME}-${DISTRO_CODENAME}
else
TARGET_DIR=${1}
fi
[ ! -d "${TARGET_DIR}" ] && return 2
if [ -z "${DISTRO_GIT_REVISION}" ] ; then
echo "DISTRO_GIT_REVISION cannot be empty!"
return 3
fi
echo "WARNING: reset to rev ${DISTRO_GIT_REVISION} *and* irreversibly clear ${TARGET_DIR}? YES/NO"
read x
if [ "${x}" == "YES" ] ; then
cd ${TARGET_DIR}
git fetch
git reset --hard ${DISTRO_GIT_REVISION}
git clean -xdf
return 0
else
return 1
fi
}
function apply_media_tree()
{
cd ${TOP_DEVDIR}
if [ -z "${1}" ]; then
TARGET_DIR=${DISTRO_NAME}-${DISTRO_CODENAME}
else
TARGET_DIR=${1}
fi
cd ${TARGET_DIR}
if [ -z "${V4L_SYNC_DATE}" -o ! -f "${TOP_DEVDIR}/linux-media-tree-${KVER}.${KMAJ}.${KMIN}-${V4L_SYNC_DATE}.tgz" ] ; then
LinuxTV_MT_TAR=`ls ${TOP_DEVDIR}/linux-media-tree-${KVER}.${KMAJ}.${KMIN}-*.tgz | sort | tail -n 1`
if [ -z "${LinuxTV_MT_TAR}" ] ; then
return 1
fi
echo "################# $LinuxTV_MT_TAR"
TMP_MT_DATE="`basename ${LinuxTV_MT_TAR}`"
echo "################# $TMP_MT_DATE"
TMP_MT_DATE="${TMP_MT_DATE#linux-media-tree-}"
echo "################# $TMP_MT_DATE"
export V4L_SYNC_DATE="${TMP_MT_DATE%.tgz}"
echo "################# $V4L_SYNC_DATE"
else
LinuxTV_MT_TAR="${TOP_DEVDIR}/linux-media-tree-${KVER}.${KMAJ}.${KMIN}-${V4L_SYNC_DATE}.tgz"
fi
tar -xzf ${LinuxTV_MT_TAR}
# export V4L_SYNC_DATE="${V4L_SYNC_DATE}"
# dma-buf struct changes < 4.12
if [ "${KVER}" -le 4 -a "${KMAJ}" -lt 12 ] ; then
git checkout include/linux/dma-buf.h
fi
git add --all
git commit -m "Linuxtv.org media tree sync - ${V4L_SYNC_DATE}"
git format-patch -o ../ -1 HEAD
reset_repo_head_hard ${TARGET_DIR} YES
}
function configure_repo_git()
{
cd ${TOP_DEVDIR}
if [ -z "${1}" ]; then
TARGET_DIR=${DISTRO_NAME}-${DISTRO_CODENAME}
else
TARGET_DIR=${1}
fi
[ ! -d "${TARGET_DIR}" ] && echo "configure_repo_git fail" && return 1
cd ${TARGET_DIR}
# set local repo git config
git config user.name "${U_FULLNAME}"
git config user.email "hidden@email.co"
}
function apply_patch()
{
if [ -z "${1}" -o ! -f "${1}" ] ; then
echo "Error..."
return 1
fi
patch -p1 < $1
if [ $? != 0 ] ; then
return 1
fi
return 0
}
function apply_patch_git_am()
{
if [ -z "${1}" ] ; then
echo "Error 1..."
return 1
fi
if [ -z "${2}" ] ; then
echo "Error 2..."
return 1
fi
if [ -d "${2}" ] ; then
git am --reject ${2}/*patch
else
git am --reject ${2}
fi
if [ $? != 0 ] ; then
if [ "$1" == "1" ] ; then
echo "Patch failure: ${2}"
echo " Aborting git am"
git am --abort
else
echo "You must manually fix a conflict, and then mark complete with:"
echo " git am --continue"
fi
return 1
fi
return 0
}
function apply_patches()
{
cd ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}
###################################################
########## Pure LinuxTV.org media tree ############
echo "#############################################################"
if [ -z "${V4L_SYNC_DATE}" -o ! -f "${KB_PATCH_DIR}/0001-Linuxtv.org-media-tree-sync-${V4L_SYNC_DATE}.patch" ] ; then
LinuxTV_MT_PATCH=`ls ${KB_PATCH_DIR}/0001-Linuxtv.org-media-tree-*.patch | sort | tail -n 1`
if [ -z "${LinuxTV_MT_PATCH}" ] ; then
echo "Missing Linuxtv.org-media-tree patch"
return 1
fi
else
LinuxTV_MT_PATCH="${KB_PATCH_DIR}/0001-Linuxtv.org-media-tree-sync-${V4L_SYNC_DATE}.patch"
fi
apply_patch_git_am 1 ${LinuxTV_MT_PATCH}
[ $? != 0 ] && echo "patch failure, exiting" && return 1
###################################################
########## Add build system changelog #############
if [ -z "${DISTRO_BRANCH}" ] ; then
deb_branch=master
else
deb_branch=${DISTRO_BRANCH}
fi
echo "#############################################################"
if [ "${UPDATE_MT_KBUILD_VER}" == "YES" ] ; then
if [ -n "${KBUILD_DATE_OVERRIDE}" ] ; then
regen_changelog "`date -d \"${KBUILD_DATE_OVERRIDE}\" ${DATE_STRING}`"
else
regen_changelog "`date ${DATE_STRING}`"
fi
git add debian.${deb_branch}/changelog
git commit -m 'Changelog'
unset UPDATE_MT_KBUILD_VER
else
apply_patch_git_am 1 ${KB_PATCH_DIR}/0002-Changelog.patch
if [ $? != 0 ] ; then
echo "Changelog patch failure, regenerating..."
regen_changelog "`date ${DATE_STRING}`"
git add debian.${deb_branch}/changelog
git commit -m 'Changelog'
fi
fi
for i in ${KB_PATCH_DIR}/000[3456789]*patch ; do
echo "#############################################################"
apply_patch_git_am 1 "$i"
[ $? != 0 ] && echo "patch failure, exiting" && return 1
done
update_identity
return 0
}
function apply_extra_patches()
{
cd ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}
for i in `ls -d ${KB_PATCH_DIR}/../mainline-extra/${KVER}.${KMAJ}.0/* | sort` ; do
echo "#############################################################"
echo "#############################################################"
echo "### `basename $i` ###"
echo "#############################################################"
apply_patch_git_am 1 $i
[ $? != 0 ] && echo "patch [${i}] failure, exiting" && return 1
done
return 0
}
function generate_patch_set()
{
if [ -z "${DISTRO_GIT_REVISION}" ] ; then
echo "DISTRO_GIT_REVISION cannot be empty!"
return 3
fi
cd ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}
# git format-patch -# HEAD
# Generate all patches after checkout revision
git format-patch ${DISTRO_GIT_REVISION}
}
function update_identity()
{
cd ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}
if [ -z "${DISTRO_BRANCH}" ] ; then
deb_branch=master
elif [ "${DISTRO_BRANCH:0:11}" == "master-next" ] ; then
deb_branch=master
else
deb_branch=${DISTRO_BRANCH}
fi
sed -i "s/Fake User <hidden@email.co>/${U_FULLNAME} <${U_EMAIL}>/" debian.${deb_branch}/control.stub.in
sed -i "s/Fake User <hidden@email.co>/${U_FULLNAME} <${U_EMAIL}>/" debian.${deb_branch}/changelog
}
function regen_changelog()
{
if [ -z "${DISTRO_GIT_REVISION}" ] ; then
echo "DISTRO_GIT_REVISION cannot be empty!"
return 3
fi
cd ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}
[ -z "${1}" ] && echo "error..." && return 1
if [ -z "${DISTRO_BRANCH}" ] ; then
deb_branch=master
deb_package=linux
elif [ "${DISTRO_BRANCH:0:11}" == "master-next" ] ; then
deb_branch=master
deb_package=linux
elif [ "${DISTRO_BRANCH:0:4}" == "hwe-" ] ; then
deb_branch=${DISTRO_BRANCH}
deb_package=linux-hwe
else
deb_branch=${DISTRO_BRANCH}
deb_package=linux-${deb_branch}
fi
git checkout ${DISTRO_GIT_REVISION} debian.${deb_branch}/changelog
get_ubuntu_kver
cp debian.${deb_branch}/changelog /tmp/tmpkrn_changelog.orig
# old version check
if [ "${1}" == "${K_BUILD_VER}" ]; then
export K_ABI_MOD=$(( ${K_ABI_MOD} + 1 ))
else
export K_BUILD_VER=${1}
export K_ABI_MOD=0
fi
if [ -n "${KBUILD_DATE_OVERRIDE}" ] ; then
K_BUILD_TIME="${KBUILD_DATE_OVERRIDE}"
unset KBUILD_DATE_OVERRIDE
else
K_BUILD_TIME=`date -R`
fi
echo "${deb_package} (${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}${K_BUILD_VER}.${K_ABI_MOD}${KERNEL_ABI_TAG}) ${DISTRO_CODENAME}; urgency=low" > /tmp/tmpkrn_changelog.mod
echo "" >> /tmp/tmpkrn_changelog.mod
echo " * Ubuntu-${deb_branch} kernel git clone">> /tmp/tmpkrn_changelog.mod
echo " - ${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}.${K_ABI_B} rev ${DISTRO_GIT_REVISION}">> /tmp/tmpkrn_changelog.mod
echo "" >> /tmp/tmpkrn_changelog.mod
echo " * LinuxTV.org media tree slipstream + build fixes" >> /tmp/tmpkrn_changelog.mod
if [ -z "${V4L_SYNC_DATE}" -o ! -f "${KB_PATCH_DIR}/0001-Linuxtv.org-media-tree-sync-${V4L_SYNC_DATE}.patch" ] ; then
LinuxTV_MT_PATCH=`ls ${KB_PATCH_DIR}/0001-Linuxtv.org-media-tree-*.patch | sort | tail -n 1`
if [ -z "${LinuxTV_MT_PATCH}" ] ; then
echo "Missing Linuxtv.org-media-tree patch"
return 1
fi
else
LinuxTV_MT_PATCH="${KB_PATCH_DIR}/0001-Linuxtv.org-media-tree-sync-${V4L_SYNC_DATE}.patch"
fi
echo " - `basename ${LinuxTV_MT_PATCH}`" >> /tmp/tmpkrn_changelog.mod
echo " - 0002-Changelog.patch" >> /tmp/tmpkrn_changelog.mod
for i in `ls ${KB_PATCH_DIR}/000[3456789]*.patch | sort` ; do
echo " - `basename $i`" >> /tmp/tmpkrn_changelog.mod
done
echo "" >> /tmp/tmpkrn_changelog.mod
echo " * Additional patches" >> /tmp/tmpkrn_changelog.mod
for i in `ls -d ${KB_PATCH_DIR}/../mainline-extra/${KVER}.${KMAJ}.0/*/ | sort` ; do
echo " - `basename $i`" >> /tmp/tmpkrn_changelog.mod
for j in `ls $i/*.patch | sort` ; do
echo " --- `basename $j`" >> /tmp/tmpkrn_changelog.mod
done
done
echo "" >> /tmp/tmpkrn_changelog.mod
echo " -- Fake User <hidden@email.co> ${K_BUILD_TIME}" >> /tmp/tmpkrn_changelog.mod
echo "" >> /tmp/tmpkrn_changelog.mod
cat /tmp/tmpkrn_changelog.mod /tmp/tmpkrn_changelog.orig > debian.${deb_branch}/changelog
write_state_env
}
function clean_kernel()
{
cd ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}
fakeroot debian/rules clean
return 0
}
function generate_new_kernel_version()
{
cd ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}
regen_changelog "`date ${DATE_STRING}`"
update_identity
clean_kernel
return 0
}
function generate_virtual_package()
{
cd ${TOP_DEVDIR}
if [ ! -f "${DISTRO_NAME}-${DISTRO_CODENAME}/debian/changelog" ] ; then
echo "Error, you must 'clean'/regenerate build data first"
return 1
fi
if [ -z "${DISTRO_BRANCH}" ] ; then
deb_branch=""
elif [ "${DISTRO_BRANCH:0:11}" == "master-next" ] ; then
deb_branch=""
elif [ "${DISTRO_BRANCH:0:4}" == "hwe-" ] ; then
deb_branch=-hwe
else
deb_branch="-${DISTRO_BRANCH}"
fi
if [ ${KVER} -eq 4 -a ${KMAJ} -lt 16 ] ; then
LAST_KBUILD_VER=`head -n 1 ${DISTRO_NAME}-${DISTRO_CODENAME}/debian/changelog | egrep -o '202[0-9][[:digit:]]{8}\.[0-9]'`
else
LAST_KBUILD_VER=`head -n 1 ${DISTRO_NAME}-${DISTRO_CODENAME}/debian/changelog | egrep -o '2[0-9][[:digit:]]{8}\.[0-9]'`
fi
LAST_KBUILD_VER="${LAST_KBUILD_VER::-2}"
VPACKAGE_VER=`head -n 1 changelog`
cd .vpackage_tmp
rm -rf linux-mediatree-*/
rm -rf linux-hwe-mediatree-*/
rm -f *
if [ -n "${KBUILD_DATE_OVERRIDE}" ] ; then
VP_BUILD_TIME="${KBUILD_DATE_OVERRIDE}"
unset KBUILD_DATE_OVERRIDE
else
VP_BUILD_TIME=`date -R`
fi
cp ../linux-mediatree.control ./ns_control
echo "linux${deb_branch}-mediatree (${VPACKAGE_VER}+${DISTRO_CODENAME}) ${DISTRO_CODENAME}; urgency=low" > changelog
git log --pretty=format:" * %h %s" -n 13 >> changelog
echo "" >> changelog
echo "" >> changelog
echo " -- ${U_FULLNAME} <${U_EMAIL}> ${VP_BUILD_TIME}" >> changelog
echo "" >> changelog
cat ../changelog >> changelog
sed -i "s/__LINUX_KBUILD_PKG_SRC_NAME__/linux${deb_branch}-mediatree/g" ns_control
sed -i "s/__MAINTAINER_INFO__/${U_FULLNAME} <${U_EMAIL}>/" ns_control
sed -i "s/__LINUX_HEADER_PACKAGE__/linux-headers-${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}${LAST_KBUILD_VER}-generic/" ns_control
sed -i "s/__LINUX_IMAGE_PACKAGES__/linux-image-${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}${LAST_KBUILD_VER}-generic, linux-modules-${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}${LAST_KBUILD_VER}-generic, linux-modules-extra-${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}${LAST_KBUILD_VER}-generic/" ns_control
echo "#########################################"
echo "#########################################"
echo "Building virtual package that depends on:"
echo " linux-headers-${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}${LAST_KBUILD_VER}-generic"
echo " linux-image-${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}${LAST_KBUILD_VER}-generic"
echo " linux-modules-${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}${LAST_KBUILD_VER}-generic"
echo " linux-modules-extra-${KVER}.${KMAJ}.${KMIN}-${K_ABI_A}${LAST_KBUILD_VER}-generic"
echo "#########################################"
echo "#########################################"
equivs-build --full ns_control
if [ ! -f "linux${deb_branch}-mediatree_${VPACKAGE_VER}+${DISTRO_CODENAME}.dsc" ] ; then
echo "Missing linux${deb_branch}-mediatree_${VPACKAGE_VER}+${DISTRO_CODENAME}.dsc"
return 1
fi
dpkg-source -x linux${deb_branch}-mediatree_${VPACKAGE_VER}+${DISTRO_CODENAME}.dsc
[ $? -ne 0 ] && return 1
cd linux${deb_branch}-mediatree-${VPACKAGE_VER}+${DISTRO_CODENAME}
debuild -us -uc -S
cd ..
cp linux${deb_branch}-mediatree*.tar.gz ..
cp linux${deb_branch}-mediatree*.dsc ..
cp linux${deb_branch}-mediatree*_source.changes ..
cp linux${deb_branch}-mediatree*_source.buildinfo .. 2>/dev/null
return 0
}
function build_kernel_bin()
{
cd ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}
if [ "$1" == "debug" ] ; then
time fakeroot debian/rules binary-headers binary-generic binary-perarch skipdbg=false
#skipmodule=true skipabi=true
elif [ "$1" == "full" ] ; then
time fakeroot debian/rules binary
else
time fakeroot debian/rules binary-headers binary-generic binary-perarch
#skipmodule=true skipabi=true
fi
}
function generate_ppa_data()
{
if [ "$1" == "kernel" -o "$1" == "all" ] ; then
echo "This should only be executed in a completely clean state"
echo "For example, after:"
echo " ./mediatree.sh -r -p -x -c"
echo "Continue?"
read x
[ "${x}" != "YES" ] && return 1
cd ${TOP_DEVDIR}/${DISTRO_NAME}-${DISTRO_CODENAME}
debuild -d -us -uc -S
fi
if [ "$1" == "virtual" -o "$1" == "all" ] ; then
generate_virtual_package
fi
}
function init_mediatree_builder()
{
ret_val=0
# Saves time by keeping clean local master (also takes up space)
cd ${TOP_DEVDIR}
if [ "${MEDIATREE_KBUILD_USE_CLEAN_MASTER}" == "1" ] ; then
echo "Initializing/Updating clean master repo"
get_ubuntu .clean-master-repo
ret_val=${?}
echo ""
fi
cd ${TOP_DEVDIR}
echo "Initializing/Updating clean patch gen repo"
get_ubuntu .media-tree-clean-patch-repo
configure_repo_git .media-tree-clean-patch-repo
echo ""
cd ${TOP_DEVDIR}
if [ ! -d "${DISTRO_NAME}-${DISTRO_CODENAME}" ] ; then
echo "Initializing Ubuntu work repo"
get_ubuntu
configure_repo_git
echo ""
elif [ "${TRY_UPDATE}" == "YES" ] ; then
echo "Attempting to update Ubuntu work repo (should already be reset with -r)"
get_ubuntu
echo ""
fi
cd ${TOP_DEVDIR}
if [ ! -d media_build ] ; then
get_media_build
fi
return ${ret_val}
}
function usage()
{
echo "Usage:"
echo " ${0} [-i|-m|-s|-p|-x|-c|-r|-g|-b|-h]"
echo " -i : Initialize/update all git repositories"
echo " -m : Download and generate latest LinuxTV.org media tree tarballs"
echo " -s : Generate a vanilla media tree kernel patch from a tarball"
echo " -p : Apply mediatree kbuild system patches"
echo " -x : Apply extra patches"
echo " -c : Make new kernel build data and clean build system"
echo " -r : Hard reset build directory (wipes build dir clean!)"
echo " -g : Generate full patchset since original revision"
echo " -b : Build kernel (requires clean first unless build error)"
echo " -h : This help"
echo ""
}
if [ -z "$1" ]; then
usage
exit 0
fi
# patch makefile to turn these on by default !
# skipmodule=true skipabi=true
while getopts ":iI:mMrxCcgbB:spV:" o; do
case "${o}" in
I|i)
if [ "${OPTARG}" == "media_build" ] ; then
get_media_build
elif [ "${OPTARG}" == "all" ] ; then
init_mediatree_builder
[ $? != 0 ] && exit 133
get_media_build
else
init_mediatree_builder
fi
[ $? != 0 ] && exit 133
;;
m)
## App operation: get latest drivers and make patched tarball for a particular kernel
#
download_media_tree
gen_media_tree_tarball_patched # generate patched tarball
[ $? != 0 ] && exit 1
;;
M)
## App operation: App operation: unpack previous linuxtv.org tarball and patch for a particular kernel
#
unpack_media_tree
[ $? != 0 ] && exit 1
gen_media_tree_tarball_patched # generate patched tarball
[ $? != 0 ] && exit 1
;;
s)
## App operation: Make a patch with the latest tarball applied
apply_media_tree .media-tree-clean-patch-repo
[ $? != 0 ] && exit 1
;;
r)
## App operation: Reset to original commit main kernel build directory
#
# resets kernel git back to original commit package is based on
# suitable for re applying updated patchset
# WARNING: irreversibly wipes out all files and resets to original state!!!
echo "!!! Requesting hard reset of ${DISTRO_NAME}-${DISTRO_CODENAME}"
echo "!!! This will irrerversibly wipe out the entire directory and restore it to original state"
echo "!!! Any changes you have made will be lost."
reset_repo_revision_hard
[ $? != 0 ] && exit 1
;;
p)
## App operation: Apply all patches to main kernel build directory
#
# requires main kernel build repo reset
#
apply_patches
[ $? != 0 ] && exit 1
;;
x)
## App operation: Apply all extra patches to main kernel build directory
#
apply_extra_patches
[ $? != 0 ] && exit 1
;;
c)
## App operation: Update changelog with ABI, build tag, maintainer, and patch list
generate_new_kernel_version
[ $? != 0 ] && exit 1
;;
C)
## App operation: clean kernel
clean_kernel
[ $? != 0 ] && exit 1
;;
g)
## App operation: Make patch set from original commit to build this kernel
generate_patch_set
[ $? != 0 ] && exit 1
;;
b)
## App operation: Build kernel
#
# Add dbg to build debug versions
#
build_kernel_bin
[ $? != 0 ] && exit 1
;;
B)
## App operation: Build kernel either min (default), full, or dbg
#
if [ "${OPTARG}" != "min" -a "${OPTARG}" != "full" -a "${OPTARG}" != "debug" ] ; then
echo " -B [min|full|debug]"
exit 1
fi
build_kernel_bin ${OPTARG}
[ $? != 0 ] && exit 1
;;
V)
## App operation: build PPA decriptors
if [ "${OPTARG}" == "all" -o "${OPTARG}" == "kernel" -o "${OPTARG}" == "virtual" ] ; then
generate_ppa_data ${OPTARG}
[ $? != 0 ] && exit 133
fi
;;
h|*)
usage
exit 0
;;
esac
done
shift $((OPTIND-1))