blob: a60327a07e50a5741b0b84cf13493b602e1e49df [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# remove tasks that modify the source tree in case externalsrc is inherited
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002SRCTREECOVEREDTASKS += "do_kernel_configme do_validate_branches do_kernel_configcheck do_kernel_checkout do_fetch do_unpack do_patch"
3PATCH_GIT_USER_EMAIL ?= "kernel-yocto@oe"
4PATCH_GIT_USER_NAME ?= "OpenEmbedded"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005
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 type=""
39 if "type" in parm:
40 type = parm["type"]
41 if "destsuffix" in parm:
42 destdir = parm["destsuffix"]
43 if type == "kmeta":
44 feature_dirs.append(destdir)
45
46 return feature_dirs
47
48# find the master/machine source branch. In the same way that the fetcher proceses
49# git repositories in the SRC_URI we take the first repo found, first branch.
50def get_machine_branch(d, default):
51 fetch = bb.fetch2.Fetch([], d)
52 for url in fetch.urls:
53 urldata = fetch.ud[url]
54 parm = urldata.parm
55 if "branch" in parm:
56 branches = urldata.parm.get("branch").split(',')
Patrick Williamsf1e5d692016-03-30 15:21:19 -050057 btype = urldata.parm.get("type")
58 if btype != "kmeta":
59 return branches[0]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060
61 return default
62
63do_kernel_metadata() {
64 set +e
65 cd ${S}
66 export KMETA=${KMETA}
67
68 # if kernel tools are available in-tree, they are preferred
69 # and are placed on the path before any external tools. Unless
70 # the external tools flag is set, in that case we do nothing.
71 if [ -f "${S}/scripts/util/configme" ]; then
72 if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then
73 PATH=${S}/scripts/util:${PATH}
74 fi
75 fi
76
77 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
78 machine_srcrev="${SRCREV_machine}"
79 if [ -z "${machine_srcrev}" ]; then
80 # fallback to SRCREV if a non machine_meta tree is being built
81 machine_srcrev="${SRCREV}"
82 fi
83
84 # In a similar manner to the kernel itself:
85 #
86 # defconfig: $(obj)/conf
87 # ifeq ($(KBUILD_DEFCONFIG),)
88 # $< --defconfig $(Kconfig)
89 # else
90 # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
91 # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
92 # endif
93 #
94 # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it
95 # from the source tree, into a common location and normalized "defconfig" name,
96 # where the rest of the process will include and incoroporate it into the build
97 #
98 # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI),
99 # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take
100 # precendence.
101 #
102 if [ -n "${KBUILD_DEFCONFIG}" ]; then
103 if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then
104 if [ -f "${WORKDIR}/defconfig" ]; then
105 # If the two defconfig's are different, warn that we didn't overwrite the
106 # one already placed in WORKDIR by the fetcher.
107 cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}"
108 if [ $? -ne 0 ]; then
109 bbwarn "defconfig detected in WORKDIR. ${KBUILD_DEFCONFIG} skipped"
110 fi
111 else
112 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
113 sccs="${WORKDIR}/defconfig"
114 fi
115 else
116 bbfatal "A KBUILD_DECONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree"
117 fi
118 fi
119
120 sccs="$sccs ${@" ".join(find_sccs(d))}"
121 patches="${@" ".join(find_patches(d))}"
122 feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}"
123
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500124 # check for feature directories/repos/branches that were part of the
125 # SRC_URI. If they were supplied, we convert them into include directives
126 # for the update part of the process
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600127 for f in ${feat_dirs}; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 if [ -d "${WORKDIR}/$f/meta" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600129 includes="$includes -I${WORKDIR}/$f/kernel-meta"
130 elif [ -d "${WORKDIR}/$f" ]; then
131 includes="$includes -I${WORKDIR}/$f"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500132 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600133 done
134 for s in ${sccs} ${patches}; do
135 sdir=$(dirname $s)
136 includes="$includes -I${sdir}"
137 # if a SRC_URI passed patch or .scc has a subdir of "kernel-meta",
138 # then we add it to the search path
139 if [ -d "${sdir}/kernel-meta" ]; then
140 includes="$includes -I${sdir}/kernel-meta"
141 fi
142 done
143
144 # expand kernel features into their full path equivalents
145 bsp_definition=$(spp ${includes} --find -DKMACHINE=${KMACHINE} -DKTYPE=${LINUX_KERNEL_TYPE})
146 meta_dir=$(kgit --meta)
147
148 # run1: pull all the configuration fragments, no matter where they come from
149 elements="`echo -n ${bsp_definition} ${sccs} ${patches} ${KERNEL_FEATURES}`"
150 if [ -n "${elements}" ]; then
151 scc --force -o ${S}/${meta_dir}:cfg,meta ${includes} ${bsp_definition} ${sccs} ${patches} ${KERNEL_FEATURES}
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500152 if [ $? -ne 0 ]; then
153 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
154 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155 fi
156
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600157 # run2: only generate patches for elements that have been passed on the SRC_URI
158 elements="`echo -n ${sccs} ${patches} ${KERNEL_FEATURES}`"
159 if [ -n "${elements}" ]; then
160 scc --force -o ${S}/${meta_dir}:patch --cmds patch ${includes} ${sccs} ${patches} ${KERNEL_FEATURES}
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500161 if [ $? -ne 0 ]; then
162 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
163 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164 fi
165}
166
167do_patch() {
168 cd ${S}
169
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600170 check_git_config
171 meta_dir=$(kgit --meta)
172 (cd ${meta_dir}; ln -sf patch.queue series)
173 if [ -f "${meta_dir}/series" ]; then
174 kgit-s2q --gen -v --patches .kernel-meta/
175 if [ $? -ne 0 ]; then
176 bberror "Could not apply patches for ${KMACHINE}."
177 bbfatal_log "Patch failures can be resolved in the linux source directory ${S})"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178 fi
179 fi
180}
181
182do_kernel_checkout() {
183 set +e
184
185 source_dir=`echo ${S} | sed 's%/$%%'`
186 source_workdir="${WORKDIR}/git"
187 if [ -d "${WORKDIR}/git/" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500188 # case: git repository
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189 # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree.
190 if [ "${source_dir}" != "${source_workdir}" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500191 if [ -d "${source_workdir}/.git" ]; then
192 # regular git repository with .git
193 rm -rf ${S}
194 mv ${WORKDIR}/git ${S}
195 else
196 # create source for bare cloned git repository
197 git clone ${WORKDIR}/git ${S}
198 rm -rf ${WORKDIR}/git
199 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 fi
201 cd ${S}
202 else
203 # case: we have no git repository at all.
204 # To support low bandwidth options for building the kernel, we'll just
205 # convert the tree to a git repo and let the rest of the process work unchanged
206
207 # if ${S} hasn't been set to the proper subdirectory a default of "linux" is
208 # used, but we can't initialize that empty directory. So check it and throw a
209 # clear error
210
211 cd ${S}
212 if [ ! -f "Makefile" ]; then
213 bberror "S is not set to the linux source directory. Check "
214 bbfatal "the recipe and set S to the proper extracted subdirectory"
215 fi
216 rm -f .gitignore
217 git init
218 git add .
219 git commit -q -m "baseline commit: creating repo for ${PN}-${PV}"
220 git clean -d -f
221 fi
222
223 # convert any remote branches to local tracking ones
224 for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
225 b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
226 git show-ref --quiet --verify -- "refs/heads/$b"
227 if [ $? -ne 0 ]; then
228 git branch $b $i > /dev/null
229 fi
230 done
231
232 # Create a working tree copy of the kernel by checking out a branch
233 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
234
235 # checkout and clobber any unimportant files
236 git checkout -f ${machine_branch}
237}
238do_kernel_checkout[dirs] = "${S}"
239
240addtask kernel_checkout before do_kernel_metadata after do_unpack
241addtask kernel_metadata after do_validate_branches do_unpack before do_patch
242do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot"
243
244do_kernel_configme[dirs] += "${S} ${B}"
245do_kernel_configme() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600246 set +e
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600248 # translate the kconfig_mode into something that merge_config.sh
249 # understands
250 case ${KCONFIG_MODE} in
251 *allnoconfig)
252 config_flags="-n"
253 ;;
254 *alldefconfig)
255 config_flags=""
256 ;;
257 *)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258 if [ -f ${WORKDIR}/defconfig ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600259 config_flags="-n"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500260 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600261 ;;
262 esac
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500263
264 cd ${S}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600265
266 meta_dir=$(kgit --meta)
267 configs="$(scc --configs -o ${meta_dir})"
268 if [ -z "${configs}" ]; then
269 bbfatal_log "Could not find configuration queue (${meta_dir}/config.queue)"
270 fi
271
272 CFLAGS="${CFLAGS} ${TOOLCHAIN_OPTIONS}" ARCH=${ARCH} merge_config.sh -O ${B} ${config_flags} ${configs} > ${meta_dir}/cfg/merge_config_build.log 2>&1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500273 if [ $? -ne 0 ]; then
274 bbfatal_log "Could not configure ${KMACHINE}-${LINUX_KERNEL_TYPE}"
275 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600276
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500277 echo "# Global settings from linux recipe" >> ${B}/.config
278 echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config
279}
280
281addtask kernel_configme before do_configure after do_patch
282
283python do_kernel_configcheck() {
284 import re, string, sys
285
286 # if KMETA isn't set globally by a recipe using this routine, we need to
287 # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
288 # meta-series for processing
289 kmeta = d.getVar( "KMETA", True ) or "meta"
290 if not os.path.exists(kmeta):
291 kmeta = "." + kmeta
292
293 pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH', True), "${S}/scripts/util/")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600294
295 cmd = d.expand("scc --configs -o ${S}/.kernel-meta")
296 ret, configs = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd))
297
298 cmd = d.expand("cd ${S}; kconf_check --report -o ${S}/%s/cfg/ ${B}/.config ${S} %s" % (kmeta,configs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500299 ret, result = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd))
300
301 config_check_visibility = int(d.getVar( "KCONF_AUDIT_LEVEL", True ) or 0)
302 bsp_check_visibility = int(d.getVar( "KCONF_BSP_AUDIT_LEVEL", True ) or 0)
303
304 # if config check visibility is non-zero, report dropped configuration values
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600305 mismatch_file = d.expand("${S}/%s/cfg/mismatch.txt" % kmeta)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306 if os.path.exists(mismatch_file):
307 if config_check_visibility:
308 with open (mismatch_file, "r") as myfile:
309 results = myfile.read()
310 bb.warn( "[kernel config]: specified values did not make it into the kernel's final configuration:\n\n%s" % results)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500311}
312
313# Ensure that the branches (BSP and meta) are on the locations specified by
314# their SRCREV values. If they are NOT on the right commits, the branches
315# are corrected to the proper commit.
316do_validate_branches() {
317 set +e
318 cd ${S}
319
320 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
321 machine_srcrev="${SRCREV_machine}"
322
323 # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to
324 # check and we can exit early
325 if [ "${machine_srcrev}" = "AUTOINC" ]; then
326 bbnote "SRCREV validation is not required for AUTOREV"
327 elif [ "${machine_srcrev}" = "" ]; then
328 if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then
329 # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe
330 # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In
331 # this case, we need to reset to the give SRCREV before heading to patching
332 bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}"
333 force_srcrev="${SRCREV}"
334 fi
335 else
336 git cat-file -t ${machine_srcrev} > /dev/null
337 if [ $? -ne 0 ]; then
338 bberror "${machine_srcrev} is not a valid commit ID."
339 bbfatal_log "The kernel source tree may be out of sync"
340 fi
341 force_srcrev=${machine_srcrev}
342 fi
343
344 git checkout -q -f ${machine_branch}
345 if [ -n "${force_srcrev}" ]; then
346 # see if the branch we are about to patch has been properly reset to the defined
347 # SRCREV .. if not, we reset it.
348 branch_head=`git rev-parse HEAD`
349 if [ "${force_srcrev}" != "${branch_head}" ]; then
350 current_branch=`git rev-parse --abbrev-ref HEAD`
351 git branch "$current_branch-orig"
352 git reset --hard ${force_srcrev}
353 fi
354 fi
355}
356
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
358KBUILD_OUTPUT = "${B}"
359
360python () {
361 # If diffconfig is available, ensure it runs after kernel_configme
362 if 'do_diffconfig' in d:
363 bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d)
364}