forked from rancher/os-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-common
131 lines (106 loc) · 3.36 KB
/
build-common
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
#!/bin/bash
set -e
if [[ "$KERNEL_TAG" == "" ]]; then
echo "ERROR: Please set the KERNEL_TAG (the mainline KERNEL version is also the git tag) you're building"
echo " e.g., KERNEL_TAG=4.9.10 make release"
exit 1
fi
: ${ARTIFACTS:=$(pwd)/assets}
: ${BUILD:=/usr/src}
: ${CONFIG:=$(pwd)/config}
: ${DIST:=$(pwd)/dist}
: ${PATCHES:=$(pwd)/patches}
mkdir -p ${DIST}/kernel
list_build_files() {
find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl
find $(find ./arch/${SRCARCH} -name include -o -name scripts -type d) ./include ./scripts -type f
find ./arch/${SRCARCH} -name module.lds -o -name Kbuild.platforms -o -name Platform
find . -name Module.symvers -type f
find . -name objtool -type f
}
create_firmware_tar() {
local list=$1
local temp=firmware-temp
rm -rf $temp
mkdir -p $temp
tar xf linux*.tar -C $temp
if [ ! -e linux-firmware ]; then
git clone git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git
fi
(
cd linux-firmware
git rev-parse HEAD > .git-commit
)
echo .git-commit > files
for i in $(<$list); do
if [ ! -e $temp/lib/firmware/$i ]; then
if [ -e linux-firmware/$i ]; then
echo Found $i
echo $i >> files
else
echo WARNING: Firmware listed in $list Not found $i
fi
fi
done
tar cf firmware.tar --transform 's,^,lib/firmware/,' -C linux-firmware $(<files)
for i in $(<files); do
if [ -e linux-firmware/$i ]; then
rm linux-firmware/$i
fi
done
tar cf firmware-extra.tar --transform 's,^./,lib/firmware/,' -C linux-firmware --exclude .git .
}
move_files() {
local module_list=$1
local target=$2
for i in $(<$module_list); do
if [ ! -e $i ]; then
echo "WARNING move_files into $target, $i does not exist"
continue
fi
for j in $i ${DEPS[$i]}; do
if [ -e $j ]; then
dest=$(readlink -f $j | sed 's!/build/!/'$target'/!')
mkdir -p $(dirname $dest)
mv -f $j $dest
echo $j >> ${DIST}/kernel/modules-${target}.list
fi
done
done
}
declare -A DEPS
build_deps() {
while read LINE; do
DEPS[${LINE%%:*}]="${LINE##*:}"
done < <(cat modules.dep)
}
split_tar() {
local archive=$1
local module_list=$2
local module_extra_list=$3
rm -rf tar
mkdir -p tar/{build,main,extra}
echo Extracting $archive
tar xf $archive -C tar/build
/sbin/depmod -b tar/build $(basename tar/build/lib/modules/*)
cd tar/build/lib/modules/*/kernel/..
build_deps
echo Separating modules
move_files $module_list main
move_files $module_extra_list extra
if [ $(find kernel -type f | wc -l) -gt 0 ]; then
echo Invalid files in $(pwd)
find kernel -type f
echo
echo ERROR: Extra files in $(pwd)
echo ERROR: You may need to either remove some modules from your kernel .config, or
echo ERROR: add these files to $module_list or $module_extra_list
exit 1
fi
rm -rf kernel
mv $(pwd | sed 's!/build/!/main/!')/kernel .
echo Creating base.tar
tar cf ../../../../../base.tar -C ../../.. .
echo Creating extra.tar
tar cf ../../../../../extra.tar -C ../../../../extra .
}