diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:38:32 +0100 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:50:20 +0100 |
commit | e2e6f6fe07049f33cb6348780fa975162752e421 (patch) | |
tree | b1813295411235d1297a0ed642b1346b24fdfb12 /meta/classes/kernel-yocto.bbclass | |
download | poky-e2e6f6fe07049f33cb6348780fa975162752e421.tar.gz |
initial commit of Enea Linux 3.1
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'meta/classes/kernel-yocto.bbclass')
-rw-r--r-- | meta/classes/kernel-yocto.bbclass | 413 |
1 files changed, 413 insertions, 0 deletions
diff --git a/meta/classes/kernel-yocto.bbclass b/meta/classes/kernel-yocto.bbclass new file mode 100644 index 0000000000..8f79932438 --- /dev/null +++ b/meta/classes/kernel-yocto.bbclass | |||
@@ -0,0 +1,413 @@ | |||
1 | S = "${WORKDIR}/linux" | ||
2 | |||
3 | # remove tasks that modify the source tree in case externalsrc is inherited | ||
4 | SRCTREECOVEREDTASKS += "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 | ||
8 | def 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 | ||
18 | def 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 | ||
32 | def 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. | ||
49 | def 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 | |||
60 | do_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 | |||
146 | do_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 | 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 | 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 | } | ||
235 | do_kernel_checkout[dirs] = "${S}" | ||
236 | |||
237 | addtask kernel_checkout before do_patch after do_unpack | ||
238 | |||
239 | do_kernel_configme[dirs] = "${S} ${B}" | ||
240 | do_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 | |||
266 | python do_kernel_configcheck() { | ||
267 | import re, string, sys | ||
268 | |||
269 | bb.plain("NOTE: validating kernel config, see log.do_kernel_configcheck for details") | ||
270 | |||
271 | # if KMETA isn't set globally by a recipe using this routine, we need to | ||
272 | # set the default to 'meta'. Otherwise, kconf_check is not passed a valid | ||
273 | # meta-series for processing | ||
274 | kmeta = d.getVar( "KMETA", True ) or "meta" | ||
275 | if not os.path.exists(kmeta): | ||
276 | kmeta = "." + kmeta | ||
277 | |||
278 | pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH', True), "${S}/scripts/util/") | ||
279 | cmd = d.expand("cd ${S}; kconf_check -config- %s/meta-series ${S} ${B}" % kmeta) | ||
280 | ret, result = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd)) | ||
281 | |||
282 | config_check_visibility = d.getVar( "KCONF_AUDIT_LEVEL", True ) or 1 | ||
283 | if config_check_visibility == 1: | ||
284 | bb.debug( 1, "%s" % result ) | ||
285 | else: | ||
286 | bb.note( "%s" % result ) | ||
287 | } | ||
288 | |||
289 | # Ensure that the branches (BSP and meta) are on the locations specified by | ||
290 | # their SRCREV values. If they are NOT on the right commits, the branches | ||
291 | # are corrected to the proper commit. | ||
292 | do_validate_branches() { | ||
293 | cd ${S} | ||
294 | export KMETA=${KMETA} | ||
295 | |||
296 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" | ||
297 | |||
298 | set +e | ||
299 | # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to | ||
300 | # check and we can exit early | ||
301 | if [ "${SRCREV_machine}" = "AUTOINC" ] || [ "${SRCREV_machine}" = "INVALID" ] || | ||
302 | [ "${SRCREV_machine}" = "" ]; then | ||
303 | return | ||
304 | fi | ||
305 | |||
306 | # If something other than the default branch was requested, it must | ||
307 | # exist in the tree, and it's a hard error if it wasn't | ||
308 | git show-ref --quiet --verify -- "refs/heads/${machine_branch}" | ||
309 | if [ $? -eq 1 ]; then | ||
310 | if [ -n "${KBRANCH_DEFAULT}" ] && | ||
311 | [ "${machine_branch}" != "${KBRANCH_DEFAULT}" ]; then | ||
312 | echo "ERROR: branch ${machine_branch} was set for kernel compilation, " | ||
313 | echo " but it does not exist in the kernel repository." | ||
314 | echo " Check the value of KBRANCH and ensure that it describes" | ||
315 | echo " a valid banch in the source kernel repository" | ||
316 | exit 1 | ||
317 | fi | ||
318 | fi | ||
319 | |||
320 | if [ -z "${SRCREV_machine}" ]; then | ||
321 | target_branch_head="${SRCREV}" | ||
322 | else | ||
323 | target_branch_head="${SRCREV_machine}" | ||
324 | fi | ||
325 | |||
326 | # $SRCREV could have also been AUTOINC, so check again | ||
327 | if [ "${target_branch_head}" = "AUTOINC" ]; then | ||
328 | return | ||
329 | fi | ||
330 | |||
331 | ref=`git show ${target_branch_head} 2>&1 | head -n1 || true` | ||
332 | if [ "$ref" = "fatal: bad object ${target_meta_head}" ]; then | ||
333 | echo "ERROR ${target_branch_head} is not a valid commit ID." | ||
334 | echo "The kernel source tree may be out of sync" | ||
335 | exit 1 | ||
336 | fi | ||
337 | |||
338 | containing_branches=`git branch --contains $target_branch_head | sed 's/^..//'` | ||
339 | if [ -z "$containing_branches" ]; then | ||
340 | echo "ERROR: SRCREV was set to \"$target_branch_head\", but no branches" | ||
341 | echo " contain this commit" | ||
342 | exit 1 | ||
343 | fi | ||
344 | |||
345 | # force the SRCREV in each branch that contains the specified | ||
346 | # SRCREV (if it isn't the current HEAD of that branch) | ||
347 | git checkout -q master | ||
348 | for b in $containing_branches; do | ||
349 | branch_head=`git show-ref -s --heads ${b}` | ||
350 | if [ "$branch_head" != "$target_branch_head" ]; then | ||
351 | echo "[INFO] Setting branch $b to ${target_branch_head}" | ||
352 | if [ "$b" = "master" ]; then | ||
353 | git reset --hard $target_branch_head > /dev/null | ||
354 | else | ||
355 | git branch -D $b > /dev/null | ||
356 | git branch $b $target_branch_head > /dev/null | ||
357 | fi | ||
358 | fi | ||
359 | done | ||
360 | |||
361 | ## KMETA branch validation | ||
362 | meta_head=`git show-ref -s --heads ${KMETA}` | ||
363 | target_meta_head="${SRCREV_meta}" | ||
364 | git show-ref --quiet --verify -- "refs/heads/${KMETA}" | ||
365 | if [ $? -eq 1 ]; then | ||
366 | return | ||
367 | fi | ||
368 | |||
369 | if [ "${target_meta_head}" = "AUTOINC" ]; then | ||
370 | return | ||
371 | fi | ||
372 | |||
373 | if [ "$meta_head" != "$target_meta_head" ]; then | ||
374 | ref=`git show ${target_meta_head} 2>&1 | head -n1 || true` | ||
375 | if [ "$ref" = "fatal: bad object ${target_meta_head}" ]; then | ||
376 | echo "ERROR ${target_meta_head} is not a valid commit ID" | ||
377 | echo "The kernel source tree may be out of sync" | ||
378 | exit 1 | ||
379 | else | ||
380 | echo "[INFO] Setting branch ${KMETA} to ${target_meta_head}" | ||
381 | git branch -m ${KMETA} ${KMETA}-orig | ||
382 | git checkout -q -b ${KMETA} ${target_meta_head} | ||
383 | if [ $? -ne 0 ];then | ||
384 | echo "ERROR: could not checkout ${KMETA} branch from known hash ${target_meta_head}" | ||
385 | exit 1 | ||
386 | fi | ||
387 | fi | ||
388 | fi | ||
389 | |||
390 | git show-ref --quiet --verify -- "refs/heads/${machine_branch}" | ||
391 | if [ $? -eq 0 ]; then | ||
392 | # restore the branch for builds | ||
393 | git checkout -q -f ${machine_branch} | ||
394 | else | ||
395 | git checkout -q master | ||
396 | fi | ||
397 | } | ||
398 | |||
399 | # Many scripts want to look in arch/$arch/boot for the bootable | ||
400 | # image. This poses a problem for vmlinux based booting. This | ||
401 | # task arranges to have vmlinux appear in the normalized directory | ||
402 | # location. | ||
403 | do_kernel_link_vmlinux() { | ||
404 | if [ ! -d "${B}/arch/${ARCH}/boot" ]; then | ||
405 | mkdir ${B}/arch/${ARCH}/boot | ||
406 | fi | ||
407 | cd ${B}/arch/${ARCH}/boot | ||
408 | ln -sf ../../../vmlinux | ||
409 | } | ||
410 | |||
411 | OE_TERMINAL_EXPORTS += "GUILT_BASE KBUILD_OUTPUT" | ||
412 | GUILT_BASE = "meta" | ||
413 | KBUILD_OUTPUT = "${B}" | ||