summaryrefslogtreecommitdiffstats
path: root/meta/classes/kernel-yocto.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/kernel-yocto.bbclass')
-rw-r--r--meta/classes/kernel-yocto.bbclass416
1 files changed, 416 insertions, 0 deletions
diff --git a/meta/classes/kernel-yocto.bbclass b/meta/classes/kernel-yocto.bbclass
new file mode 100644
index 0000000000..53bc6d443c
--- /dev/null
+++ b/meta/classes/kernel-yocto.bbclass
@@ -0,0 +1,416 @@
1S = "${WORKDIR}/linux"
2
3# remove tasks that modify the source tree in case externalsrc is inherited
4SRCTREECOVEREDTASKS += "do_kernel_link_vmlinux do_kernel_configme do_validate_branches do_kernel_configcheck do_kernel_checkout do_patch"
5
6# returns local (absolute) path names for all valid patches in the
7# src_uri
8def find_patches(d):
9 patches = src_patches(d)
10 patch_list=[]
11 for p in patches:
12 _, _, local, _, _, _ = bb.fetch.decodeurl(p)
13 patch_list.append(local)
14
15 return patch_list
16
17# returns all the elements from the src uri that are .scc files
18def find_sccs(d):
19 sources=src_patches(d, True)
20 sources_list=[]
21 for s in sources:
22 base, ext = os.path.splitext(os.path.basename(s))
23 if ext and ext in [".scc", ".cfg"]:
24 sources_list.append(s)
25 elif base and base in 'defconfig':
26 sources_list.append(s)
27
28 return sources_list
29
30# check the SRC_URI for "kmeta" type'd git repositories. Return the name of
31# the repository as it will be found in WORKDIR
32def find_kernel_feature_dirs(d):
33 feature_dirs=[]
34 fetch = bb.fetch2.Fetch([], d)
35 for url in fetch.urls:
36 urldata = fetch.ud[url]
37 parm = urldata.parm
38 if "type" in parm:
39 type = parm["type"]
40 if "destsuffix" in parm:
41 destdir = parm["destsuffix"]
42 if type == "kmeta":
43 feature_dirs.append(destdir)
44
45 return feature_dirs
46
47# find the master/machine source branch. In the same way that the fetcher proceses
48# git repositories in the SRC_URI we take the first repo found, first branch.
49def get_machine_branch(d, default):
50 fetch = bb.fetch2.Fetch([], d)
51 for url in fetch.urls:
52 urldata = fetch.ud[url]
53 parm = urldata.parm
54 if "branch" in parm:
55 branches = urldata.parm.get("branch").split(',')
56 return branches[0]
57
58 return default
59
60do_patch() {
61 cd ${S}
62 export KMETA=${KMETA}
63
64 # if kernel tools are available in-tree, they are preferred
65 # and are placed on the path before any external tools. Unless
66 # the external tools flag is set, in that case we do nothing.
67 if [ -f "${S}/scripts/util/configme" ]; then
68 if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then
69 PATH=${S}/scripts/util:${PATH}
70 fi
71 fi
72
73 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
74
75 # if we have a defined/set meta branch we should not be generating
76 # any meta data. The passed branch has what we need.
77 if [ -n "${KMETA}" ]; then
78 createme_flags="--disable-meta-gen --meta ${KMETA}"
79 fi
80
81 createme ${createme_flags} ${ARCH} ${machine_branch}
82 if [ $? -ne 0 ]; then
83 echo "ERROR. Could not create ${machine_branch}"
84 exit 1
85 fi
86
87 sccs="${@" ".join(find_sccs(d))}"
88 patches="${@" ".join(find_patches(d))}"
89 feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}"
90
91 set +e
92 # add any explicitly referenced features onto the end of the feature
93 # list that is passed to the kernel build scripts.
94 if [ -n "${KERNEL_FEATURES}" ]; then
95 for feat in ${KERNEL_FEATURES}; do
96 addon_features="$addon_features --feature $feat"
97 done
98 fi
99
100 # check for feature directories/repos/branches that were part of the
101 # SRC_URI. If they were supplied, we convert them into include directives
102 # for the update part of the process
103 if [ -n "${feat_dirs}" ]; then
104 for f in ${feat_dirs}; do
105 if [ -d "${WORKDIR}/$f/meta" ]; then
106 includes="$includes -I${WORKDIR}/$f/meta"
107 elif [ -d "${WORKDIR}/$f" ]; then
108 includes="$includes -I${WORKDIR}/$f"
109 fi
110 done
111 fi
112
113 if [ "${machine_branch}" != "${KBRANCH_DEFAULT}" ]; then
114 updateme_flags="--branch ${machine_branch}"
115 fi
116
117 # updates or generates the target description
118 updateme ${updateme_flags} -DKDESC=${KMACHINE}:${LINUX_KERNEL_TYPE} \
119 ${includes} ${addon_features} ${ARCH} ${KMACHINE} ${sccs} ${patches}
120 if [ $? -ne 0 ]; then
121 echo "ERROR. Could not update ${machine_branch}"
122 exit 1
123 fi
124
125 # executes and modifies the source tree as required
126 patchme ${KMACHINE}
127 if [ $? -ne 0 ]; then
128 echo "ERROR. Could not apply patches for ${KMACHINE}."
129 echo " Patch failures can be resolved in the devshell (bitbake -c devshell ${PN})"
130 exit 1
131 fi
132
133 # Perform a final check. If something other than the default kernel
134 # branch was requested, and that's not where we ended up, then we
135 # should thrown an error, since we aren't building what was expected
136 final_branch="$(git symbolic-ref HEAD 2>/dev/null)"
137 final_branch=${final_branch##refs/heads/}
138 if [ "${machine_branch}" != "${KBRANCH_DEFAULT}" ] &&
139 [ "${final_branch}" != "${machine_branch}" ]; then
140 echo "ERROR: branch ${machine_branch} was requested, but was not properly"
141 echo " configured to be built. The current branch is ${final_branch}"
142 exit 1
143 fi
144}
145
146do_kernel_checkout() {
147 set +e
148
149 # A linux yocto SRC_URI should use the bareclone option. That
150 # ensures that all the branches are available in the WORKDIR version
151 # of the repository.
152 source_dir=`echo ${S} | sed 's%/$%%'`
153 source_workdir="${WORKDIR}/git"
154 if [ -d "${WORKDIR}/git/" ] && [ -d "${WORKDIR}/git/.git" ]; then
155 # case2: the repository is a non-bare clone
156
157 # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree.
158 if [ "${source_dir}" != "${source_workdir}" ]; then
159 rm -rf ${S}
160 mv ${WORKDIR}/git ${S}
161 fi
162 cd ${S}
163 elif [ -d "${WORKDIR}/git/" ] && [ ! -d "${WORKDIR}/git/.git" ]; then
164 # case2: the repository is a bare clone
165
166 # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree.
167 if [ "${source_dir}" != "${source_workdir}" ]; then
168 rm -rf ${S}
169 mkdir -p ${S}/.git
170 mv ${WORKDIR}/git/* ${S}/.git
171 rm -rf ${WORKDIR}/git/
172 fi
173 cd ${S}
174 git config core.bare false
175 else
176 # case 3: we have no git repository at all.
177 # To support low bandwidth options for building the kernel, we'll just
178 # convert the tree to a git repo and let the rest of the process work unchanged
179
180 # if ${S} hasn't been set to the proper subdirectory a default of "linux" is
181 # used, but we can't initialize that empty directory. So check it and throw a
182 # clear error
183
184 cd ${S}
185 if [ ! -f "Makefile" ]; then
186 echo "[ERROR]: S is not set to the linux source directory. Check "
187 echo " the recipe and set S to the proper extracted subdirectory"
188 exit 1
189 fi
190 git init
191 git add .
192 git commit -q -m "baseline commit: creating repo for ${PN}-${PV}"
193 fi
194 # end debare
195
196 # If KMETA is defined, the branch must exist, but a machine branch
197 # can be missing since it may be created later by the tools.
198 if [ -n "${KMETA}" ]; then
199 git branch -a --no-color | grep -q ${KMETA}
200 if [ $? -ne 0 ]; then
201 echo "ERROR. The branch '${KMETA}' is required and was not"
202 echo "found. Ensure that the SRC_URI points to a valid linux-yocto"
203 echo "kernel repository"
204 exit 1
205 fi
206 fi
207
208 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
209
210 if [ "${KBRANCH}" != "${machine_branch}" ]; then
211 echo "WARNING: The SRC_URI machine branch and KBRANCH are not the same."
212 echo " KBRANCH will be adjusted to match, but this typically is a"
213 echo " misconfiguration and should be checked."
214 fi
215
216 # convert any remote branches to local tracking ones
217 for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
218 b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
219 git show-ref --quiet --verify -- "refs/heads/$b"
220 if [ $? -ne 0 ]; then
221 git branch $b $i > /dev/null
222 fi
223 done
224
225 # Create a working tree copy of the kernel by checking out a branch
226 git show-ref --quiet --verify -- "refs/heads/${machine_branch}"
227 if [ $? -eq 0 ]; then
228 # checkout and clobber any unimportant files
229 git checkout -f ${machine_branch}
230 else
231 echo "Not checking out ${machine_branch}, it will be created later"
232 git checkout -f master
233 fi
234}
235do_kernel_checkout[dirs] = "${S}"
236
237addtask kernel_checkout before do_patch after do_unpack
238
239do_kernel_configme[dirs] += "${S} ${B}"
240do_kernel_configme() {
241 echo "[INFO] doing kernel configme"
242 export KMETA=${KMETA}
243
244 if [ -n ${KCONFIG_MODE} ]; then
245 configmeflags=${KCONFIG_MODE}
246 else
247 # If a defconfig was passed, use =n as the baseline, which is achieved
248 # via --allnoconfig
249 if [ -f ${WORKDIR}/defconfig ]; then
250 configmeflags="--allnoconfig"
251 fi
252 fi
253
254 cd ${S}
255 PATH=${PATH}:${S}/scripts/util
256 configme ${configmeflags} --reconfig --output ${B} ${LINUX_KERNEL_TYPE} ${KMACHINE}
257 if [ $? -ne 0 ]; then
258 echo "ERROR. Could not configure ${KMACHINE}-${LINUX_KERNEL_TYPE}"
259 exit 1
260 fi
261
262 echo "# Global settings from linux recipe" >> ${B}/.config
263 echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config
264}
265
266addtask kernel_configme after do_patch
267
268python do_kernel_configcheck() {
269 import re, string, sys
270
271 bb.plain("NOTE: validating kernel config, see log.do_kernel_configcheck for details")
272
273 # if KMETA isn't set globally by a recipe using this routine, we need to
274 # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
275 # meta-series for processing
276 kmeta = d.getVar( "KMETA", True ) or "meta"
277 if not os.path.exists(kmeta):
278 kmeta = "." + kmeta
279
280 pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH', True), "${S}/scripts/util/")
281 cmd = d.expand("cd ${S}; kconf_check -config- %s/meta-series ${S} ${B}" % kmeta)
282 ret, result = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd))
283
284 config_check_visibility = d.getVar( "KCONF_AUDIT_LEVEL", True ) or 1
285 if config_check_visibility == 1:
286 bb.debug( 1, "%s" % result )
287 else:
288 bb.note( "%s" % result )
289}
290
291# Ensure that the branches (BSP and meta) are on the locations specified by
292# their SRCREV values. If they are NOT on the right commits, the branches
293# are corrected to the proper commit.
294do_validate_branches() {
295 cd ${S}
296 export KMETA=${KMETA}
297
298 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
299
300 set +e
301 # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to
302 # check and we can exit early
303 if [ "${SRCREV_machine}" = "AUTOINC" ] || [ "${SRCREV_machine}" = "INVALID" ] ||
304 [ "${SRCREV_machine}" = "" ]; then
305 return
306 fi
307
308 # If something other than the default branch was requested, it must
309 # exist in the tree, and it's a hard error if it wasn't
310 git show-ref --quiet --verify -- "refs/heads/${machine_branch}"
311 if [ $? -eq 1 ]; then
312 if [ -n "${KBRANCH_DEFAULT}" ] &&
313 [ "${machine_branch}" != "${KBRANCH_DEFAULT}" ]; then
314 echo "ERROR: branch ${machine_branch} was set for kernel compilation, "
315 echo " but it does not exist in the kernel repository."
316 echo " Check the value of KBRANCH and ensure that it describes"
317 echo " a valid banch in the source kernel repository"
318 exit 1
319 fi
320 fi
321
322 if [ -z "${SRCREV_machine}" ]; then
323 target_branch_head="${SRCREV}"
324 else
325 target_branch_head="${SRCREV_machine}"
326 fi
327
328 # $SRCREV could have also been AUTOINC, so check again
329 if [ "${target_branch_head}" = "AUTOINC" ]; then
330 return
331 fi
332
333 ref=`git show ${target_branch_head} 2>&1 | head -n1 || true`
334 if [ "$ref" = "fatal: bad object ${target_meta_head}" ]; then
335 echo "ERROR ${target_branch_head} is not a valid commit ID."
336 echo "The kernel source tree may be out of sync"
337 exit 1
338 fi
339
340 containing_branches=`git branch --contains $target_branch_head | sed 's/^..//'`
341 if [ -z "$containing_branches" ]; then
342 echo "ERROR: SRCREV was set to \"$target_branch_head\", but no branches"
343 echo " contain this commit"
344 exit 1
345 fi
346
347 # force the SRCREV in each branch that contains the specified
348 # SRCREV (if it isn't the current HEAD of that branch)
349 git checkout -q master
350 for b in $containing_branches; do
351 branch_head=`git show-ref -s --heads ${b}`
352 if [ "$branch_head" != "$target_branch_head" ]; then
353 echo "[INFO] Setting branch $b to ${target_branch_head}"
354 if [ "$b" = "master" ]; then
355 git reset --hard $target_branch_head > /dev/null
356 else
357 git branch -D $b > /dev/null
358 git branch $b $target_branch_head > /dev/null
359 fi
360 fi
361 done
362
363 ## KMETA branch validation.
364 ## We do validation if the meta branch exists, and AUTOREV hasn't been set
365 meta_head=`git show-ref -s --heads ${KMETA}`
366 target_meta_head="${SRCREV_meta}"
367 git show-ref --quiet --verify -- "refs/heads/${KMETA}"
368 if [ $? -eq 0 ] && [ "${target_meta_head}" != "AUTOINC" ]; then
369 if [ "$meta_head" != "$target_meta_head" ]; then
370 ref=`git show ${target_meta_head} 2>&1 | head -n1 || true`
371 if [ "$ref" = "fatal: bad object ${target_meta_head}" ]; then
372 echo "ERROR ${target_meta_head} is not a valid commit ID"
373 echo "The kernel source tree may be out of sync"
374 exit 1
375 else
376 echo "[INFO] Setting branch ${KMETA} to ${target_meta_head}"
377 git branch -m ${KMETA} ${KMETA}-orig
378 git checkout -q -b ${KMETA} ${target_meta_head}
379 if [ $? -ne 0 ];then
380 echo "ERROR: could not checkout ${KMETA} branch from known hash ${target_meta_head}"
381 exit 1
382 fi
383 fi
384 fi
385 fi
386
387 git show-ref --quiet --verify -- "refs/heads/${machine_branch}"
388 if [ $? -eq 0 ]; then
389 # restore the branch for builds
390 git checkout -q -f ${machine_branch}
391 else
392 git checkout -q master
393 fi
394}
395
396# Many scripts want to look in arch/$arch/boot for the bootable
397# image. This poses a problem for vmlinux based booting. This
398# task arranges to have vmlinux appear in the normalized directory
399# location.
400do_kernel_link_vmlinux() {
401 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
402 mkdir ${B}/arch/${ARCH}/boot
403 fi
404 cd ${B}/arch/${ARCH}/boot
405 ln -sf ../../../vmlinux
406}
407
408OE_TERMINAL_EXPORTS += "GUILT_BASE KBUILD_OUTPUT"
409GUILT_BASE = "meta"
410KBUILD_OUTPUT = "${B}"
411
412python () {
413 # If diffconfig is available, ensure it runs after kernel_configme
414 if 'do_diffconfig' in d:
415 bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d)
416}