blob: 325f94c735602feff552de8e611f8e96ddb4d8b5 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# remove tasks that modify the source tree in case externalsrc is inherited
2SRCTREECOVEREDTASKS += "do_kernel_link_vmlinux do_kernel_configme do_validate_branches do_kernel_configcheck do_kernel_checkout do_shared_workdir do_fetch do_unpack do_patch"
3
4# returns local (absolute) path names for all valid patches in the
5# src_uri
6def find_patches(d):
7 patches = src_patches(d)
8 patch_list=[]
9 for p in patches:
10 _, _, local, _, _, _ = bb.fetch.decodeurl(p)
11 patch_list.append(local)
12
13 return patch_list
14
15# returns all the elements from the src uri that are .scc files
16def find_sccs(d):
17 sources=src_patches(d, True)
18 sources_list=[]
19 for s in sources:
20 base, ext = os.path.splitext(os.path.basename(s))
21 if ext and ext in [".scc", ".cfg"]:
22 sources_list.append(s)
23 elif base and base in 'defconfig':
24 sources_list.append(s)
25
26 return sources_list
27
28# check the SRC_URI for "kmeta" type'd git repositories. Return the name of
29# the repository as it will be found in WORKDIR
30def find_kernel_feature_dirs(d):
31 feature_dirs=[]
32 fetch = bb.fetch2.Fetch([], d)
33 for url in fetch.urls:
34 urldata = fetch.ud[url]
35 parm = urldata.parm
36 type=""
37 if "type" in parm:
38 type = parm["type"]
39 if "destsuffix" in parm:
40 destdir = parm["destsuffix"]
41 if type == "kmeta":
42 feature_dirs.append(destdir)
43
44 return feature_dirs
45
46# find the master/machine source branch. In the same way that the fetcher proceses
47# git repositories in the SRC_URI we take the first repo found, first branch.
48def get_machine_branch(d, default):
49 fetch = bb.fetch2.Fetch([], d)
50 for url in fetch.urls:
51 urldata = fetch.ud[url]
52 parm = urldata.parm
53 if "branch" in parm:
54 branches = urldata.parm.get("branch").split(',')
55 return branches[0]
56
57 return default
58
59do_kernel_metadata() {
60 set +e
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 machine_srcrev="${SRCREV_machine}"
75 if [ -z "${machine_srcrev}" ]; then
76 # fallback to SRCREV if a non machine_meta tree is being built
77 machine_srcrev="${SRCREV}"
78 fi
79
80 # In a similar manner to the kernel itself:
81 #
82 # defconfig: $(obj)/conf
83 # ifeq ($(KBUILD_DEFCONFIG),)
84 # $< --defconfig $(Kconfig)
85 # else
86 # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
87 # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
88 # endif
89 #
90 # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it
91 # from the source tree, into a common location and normalized "defconfig" name,
92 # where the rest of the process will include and incoroporate it into the build
93 #
94 # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI),
95 # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take
96 # precendence.
97 #
98 if [ -n "${KBUILD_DEFCONFIG}" ]; then
99 if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then
100 if [ -f "${WORKDIR}/defconfig" ]; then
101 # If the two defconfig's are different, warn that we didn't overwrite the
102 # one already placed in WORKDIR by the fetcher.
103 cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}"
104 if [ $? -ne 0 ]; then
105 bbwarn "defconfig detected in WORKDIR. ${KBUILD_DEFCONFIG} skipped"
106 fi
107 else
108 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
109 sccs="${WORKDIR}/defconfig"
110 fi
111 else
112 bbfatal "A KBUILD_DECONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree"
113 fi
114 fi
115
116 sccs="$sccs ${@" ".join(find_sccs(d))}"
117 patches="${@" ".join(find_patches(d))}"
118 feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}"
119
120 # add any explicitly referenced features onto the end of the feature
121 # list that is passed to the kernel build scripts.
122 if [ -n "${KERNEL_FEATURES}" ]; then
123 for feat in ${KERNEL_FEATURES}; do
124 addon_features="$addon_features --feature $feat"
125 done
126 fi
127
128 # check for feature directories/repos/branches that were part of the
129 # SRC_URI. If they were supplied, we convert them into include directives
130 # for the update part of the process
131 if [ -n "${feat_dirs}" ]; then
132 for f in ${feat_dirs}; do
133 if [ -d "${WORKDIR}/$f/meta" ]; then
134 includes="$includes -I${WORKDIR}/$f/meta"
135 elif [ -d "${WORKDIR}/$f" ]; then
136 includes="$includes -I${WORKDIR}/$f"
137 fi
138 done
139 fi
140
141 # updates or generates the target description
142 updateme ${updateme_flags} -DKDESC=${KMACHINE}:${LINUX_KERNEL_TYPE} \
143 ${includes} ${addon_features} ${ARCH} ${KMACHINE} ${sccs} ${patches}
144 if [ $? -ne 0 ]; then
145 bbfatal_log "Could not update ${machine_branch}"
146 fi
147}
148
149do_patch() {
150 cd ${S}
151
152 # executes and modifies the source tree as required
153 patchme ${KMACHINE}
154 if [ $? -ne 0 ]; then
155 bberror "Could not apply patches for ${KMACHINE}."
156 bbfatal_log "Patch failures can be resolved in the linux source directory ${S})"
157 fi
158
159 # check to see if the specified SRCREV is reachable from the final branch.
160 # if it wasn't something wrong has happened, and we should error.
161 machine_srcrev="${SRCREV_machine}"
162 if [ -z "${machine_srcrev}" ]; then
163 # fallback to SRCREV if a non machine_meta tree is being built
164 machine_srcrev="${SRCREV}"
165 # if SRCREV cannot be reached something is wrong.
166 if [ -z "${machine_srcrev}" ]; then
167 bbfatal "Neither SRCREV_machine or SRCREV was specified!"
168 fi
169 fi
170
171 if [ "${machine_srcrev}" != "AUTOINC" ]; then
172 if ! [ "$(git rev-parse --verify ${machine_srcrev}~0)" = "$(git merge-base ${machine_srcrev} HEAD)" ]; then
173 bberror "SRCREV ${machine_srcrev} was specified, but is not reachable"
174 bbfatal "Check the BSP description for incorrect branch selection, or other errors."
175 fi
176 fi
177}
178
179do_kernel_checkout() {
180 set +e
181
182 source_dir=`echo ${S} | sed 's%/$%%'`
183 source_workdir="${WORKDIR}/git"
184 if [ -d "${WORKDIR}/git/" ]; then
185 # case: git repository (bare or non-bare)
186 # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree.
187 if [ "${source_dir}" != "${source_workdir}" ]; then
188 rm -rf ${S}
189 mv ${WORKDIR}/git ${S}
190 fi
191 cd ${S}
192 else
193 # case: we have no git repository at all.
194 # To support low bandwidth options for building the kernel, we'll just
195 # convert the tree to a git repo and let the rest of the process work unchanged
196
197 # if ${S} hasn't been set to the proper subdirectory a default of "linux" is
198 # used, but we can't initialize that empty directory. So check it and throw a
199 # clear error
200
201 cd ${S}
202 if [ ! -f "Makefile" ]; then
203 bberror "S is not set to the linux source directory. Check "
204 bbfatal "the recipe and set S to the proper extracted subdirectory"
205 fi
206 rm -f .gitignore
207 git init
208 git add .
209 git commit -q -m "baseline commit: creating repo for ${PN}-${PV}"
210 git clean -d -f
211 fi
212
213 # convert any remote branches to local tracking ones
214 for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
215 b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
216 git show-ref --quiet --verify -- "refs/heads/$b"
217 if [ $? -ne 0 ]; then
218 git branch $b $i > /dev/null
219 fi
220 done
221
222 # Create a working tree copy of the kernel by checking out a branch
223 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
224
225 # checkout and clobber any unimportant files
226 git checkout -f ${machine_branch}
227}
228do_kernel_checkout[dirs] = "${S}"
229
230addtask kernel_checkout before do_kernel_metadata after do_unpack
231addtask kernel_metadata after do_validate_branches do_unpack before do_patch
232do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot"
233
234do_kernel_configme[dirs] += "${S} ${B}"
235do_kernel_configme() {
236 bbnote "kernel configme"
237 export KMETA=${KMETA}
238
239 if [ -n "${KCONFIG_MODE}" ]; then
240 configmeflags=${KCONFIG_MODE}
241 else
242 # If a defconfig was passed, use =n as the baseline, which is achieved
243 # via --allnoconfig
244 if [ -f ${WORKDIR}/defconfig ]; then
245 configmeflags="--allnoconfig"
246 fi
247 fi
248
249 cd ${S}
250 PATH=${PATH}:${S}/scripts/util
251 configme ${configmeflags} --reconfig --output ${B} ${LINUX_KERNEL_TYPE} ${KMACHINE}
252 if [ $? -ne 0 ]; then
253 bbfatal_log "Could not configure ${KMACHINE}-${LINUX_KERNEL_TYPE}"
254 fi
255
256 echo "# Global settings from linux recipe" >> ${B}/.config
257 echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config
258}
259
260addtask kernel_configme before do_configure after do_patch
261
262python do_kernel_configcheck() {
263 import re, string, sys
264
265 # if KMETA isn't set globally by a recipe using this routine, we need to
266 # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
267 # meta-series for processing
268 kmeta = d.getVar( "KMETA", True ) or "meta"
269 if not os.path.exists(kmeta):
270 kmeta = "." + kmeta
271
272 pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH', True), "${S}/scripts/util/")
273 cmd = d.expand("cd ${S}; kconf_check -config %s/meta-series ${S} ${B}" % kmeta)
274 ret, result = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd))
275
276 config_check_visibility = int(d.getVar( "KCONF_AUDIT_LEVEL", True ) or 0)
277 bsp_check_visibility = int(d.getVar( "KCONF_BSP_AUDIT_LEVEL", True ) or 0)
278
279 # if config check visibility is non-zero, report dropped configuration values
280 mismatch_file = "${S}/" + kmeta + "/" + "mismatch.cfg"
281 if os.path.exists(mismatch_file):
282 if config_check_visibility:
283 with open (mismatch_file, "r") as myfile:
284 results = myfile.read()
285 bb.warn( "[kernel config]: specified values did not make it into the kernel's final configuration:\n\n%s" % results)
286
287 # if config check visibility is level 2 or higher, report non-hardware options
288 nonhw_file = "${S}/" + kmeta + "/" + "nonhw_report.cfg"
289 if os.path.exists(nonhw_file):
290 if config_check_visibility > 1:
291 with open (nonhw_file, "r") as myfile:
292 results = myfile.read()
293 bb.warn( "[kernel config]: BSP specified non-hw configuration:\n\n%s" % results)
294
295 bsp_desc = "${S}/" + kmeta + "/" + "top_tgt"
296 if os.path.exists(bsp_desc) and bsp_check_visibility > 1:
297 with open (bsp_desc, "r") as myfile:
298 bsp_tgt = myfile.read()
299 m = re.match("^(.*)scratch.obj(.*)$", bsp_tgt)
300 if not m is None:
301 bb.warn( "[kernel]: An auto generated BSP description was used, this normally indicates a misconfiguration.\n" +
302 "Check that your machine (%s) has an associated kernel description." % "${MACHINE}" )
303}
304
305# Ensure that the branches (BSP and meta) are on the locations specified by
306# their SRCREV values. If they are NOT on the right commits, the branches
307# are corrected to the proper commit.
308do_validate_branches() {
309 set +e
310 cd ${S}
311
312 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
313 machine_srcrev="${SRCREV_machine}"
314
315 # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to
316 # check and we can exit early
317 if [ "${machine_srcrev}" = "AUTOINC" ]; then
318 bbnote "SRCREV validation is not required for AUTOREV"
319 elif [ "${machine_srcrev}" = "" ]; then
320 if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then
321 # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe
322 # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In
323 # this case, we need to reset to the give SRCREV before heading to patching
324 bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}"
325 force_srcrev="${SRCREV}"
326 fi
327 else
328 git cat-file -t ${machine_srcrev} > /dev/null
329 if [ $? -ne 0 ]; then
330 bberror "${machine_srcrev} is not a valid commit ID."
331 bbfatal_log "The kernel source tree may be out of sync"
332 fi
333 force_srcrev=${machine_srcrev}
334 fi
335
336 git checkout -q -f ${machine_branch}
337 if [ -n "${force_srcrev}" ]; then
338 # see if the branch we are about to patch has been properly reset to the defined
339 # SRCREV .. if not, we reset it.
340 branch_head=`git rev-parse HEAD`
341 if [ "${force_srcrev}" != "${branch_head}" ]; then
342 current_branch=`git rev-parse --abbrev-ref HEAD`
343 git branch "$current_branch-orig"
344 git reset --hard ${force_srcrev}
345 fi
346 fi
347}
348
349# Many scripts want to look in arch/$arch/boot for the bootable
350# image. This poses a problem for vmlinux based booting. This
351# task arranges to have vmlinux appear in the normalized directory
352# location.
353do_kernel_link_vmlinux() {
354 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
355 mkdir ${B}/arch/${ARCH}/boot
356 fi
357 cd ${B}/arch/${ARCH}/boot
358 ln -sf ../../../vmlinux
359}
360
361OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
362KBUILD_OUTPUT = "${B}"
363
364python () {
365 # If diffconfig is available, ensure it runs after kernel_configme
366 if 'do_diffconfig' in d:
367 bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d)
368}