blob: 3311f6e84e99b0e39456b8421d76893ce1367242 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# remove tasks that modify the source tree in case externalsrc is inherited
Andrew Geissler82c905d2020-04-13 13:39:40 -05002SRCTREECOVEREDTASKS += "do_validate_branches do_kernel_configcheck do_kernel_checkout do_fetch do_unpack do_patch"
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003PATCH_GIT_USER_EMAIL ?= "kernel-yocto@oe"
4PATCH_GIT_USER_NAME ?= "OpenEmbedded"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005
Andrew Geissler82c905d2020-04-13 13:39:40 -05006# The distro or local.conf should set this, but if nobody cares...
7LINUX_KERNEL_TYPE ??= "standard"
8
9# KMETA ?= ""
10KBRANCH ?= "master"
11KMACHINE ?= "${MACHINE}"
12SRCREV_FORMAT ?= "meta_machine"
13
14# LEVELS:
15# 0: no reporting
16# 1: report options that are specified, but not in the final config
17# 2: report options that are not hardware related, but set by a BSP
18KCONF_AUDIT_LEVEL ?= "1"
19KCONF_BSP_AUDIT_LEVEL ?= "0"
20KMETA_AUDIT ?= "yes"
21
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022# returns local (absolute) path names for all valid patches in the
23# src_uri
Brad Bishop19323692019-04-05 15:28:33 -040024def find_patches(d,subdir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025 patches = src_patches(d)
26 patch_list=[]
27 for p in patches:
Brad Bishop19323692019-04-05 15:28:33 -040028 _, _, local, _, _, parm = bb.fetch.decodeurl(p)
29 # if patchdir has been passed, we won't be able to apply it so skip
30 # the patch for now, and special processing happens later
31 patchdir = ''
32 if "patchdir" in parm:
33 patchdir = parm["patchdir"]
34 if subdir:
35 if subdir == patchdir:
36 patch_list.append(local)
37 else:
38 patch_list.append(local)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
40 return patch_list
41
42# returns all the elements from the src uri that are .scc files
43def find_sccs(d):
44 sources=src_patches(d, True)
45 sources_list=[]
46 for s in sources:
47 base, ext = os.path.splitext(os.path.basename(s))
48 if ext and ext in [".scc", ".cfg"]:
49 sources_list.append(s)
Andrew Geissler82c905d2020-04-13 13:39:40 -050050 elif base and 'defconfig' in base:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 sources_list.append(s)
52
53 return sources_list
54
55# check the SRC_URI for "kmeta" type'd git repositories. Return the name of
56# the repository as it will be found in WORKDIR
57def find_kernel_feature_dirs(d):
58 feature_dirs=[]
59 fetch = bb.fetch2.Fetch([], d)
60 for url in fetch.urls:
61 urldata = fetch.ud[url]
62 parm = urldata.parm
63 type=""
64 if "type" in parm:
65 type = parm["type"]
66 if "destsuffix" in parm:
67 destdir = parm["destsuffix"]
68 if type == "kmeta":
69 feature_dirs.append(destdir)
70
71 return feature_dirs
72
73# find the master/machine source branch. In the same way that the fetcher proceses
74# git repositories in the SRC_URI we take the first repo found, first branch.
75def get_machine_branch(d, default):
76 fetch = bb.fetch2.Fetch([], d)
77 for url in fetch.urls:
78 urldata = fetch.ud[url]
79 parm = urldata.parm
80 if "branch" in parm:
81 branches = urldata.parm.get("branch").split(',')
Patrick Williamsf1e5d692016-03-30 15:21:19 -050082 btype = urldata.parm.get("type")
83 if btype != "kmeta":
84 return branches[0]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085
86 return default
87
88do_kernel_metadata() {
89 set +e
90 cd ${S}
91 export KMETA=${KMETA}
92
93 # if kernel tools are available in-tree, they are preferred
94 # and are placed on the path before any external tools. Unless
95 # the external tools flag is set, in that case we do nothing.
96 if [ -f "${S}/scripts/util/configme" ]; then
97 if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then
98 PATH=${S}/scripts/util:${PATH}
99 fi
100 fi
101
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102 # In a similar manner to the kernel itself:
103 #
104 # defconfig: $(obj)/conf
105 # ifeq ($(KBUILD_DEFCONFIG),)
106 # $< --defconfig $(Kconfig)
107 # else
108 # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
109 # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
110 # endif
111 #
112 # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it
113 # from the source tree, into a common location and normalized "defconfig" name,
114 # where the rest of the process will include and incoroporate it into the build
115 #
116 # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI),
117 # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take
118 # precendence.
119 #
120 if [ -n "${KBUILD_DEFCONFIG}" ]; then
121 if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then
122 if [ -f "${WORKDIR}/defconfig" ]; then
123 # If the two defconfig's are different, warn that we didn't overwrite the
124 # one already placed in WORKDIR by the fetcher.
125 cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}"
126 if [ $? -ne 0 ]; then
127 bbwarn "defconfig detected in WORKDIR. ${KBUILD_DEFCONFIG} skipped"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500128 else
129 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 fi
131 else
132 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500133 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500134 in_tree_defconfig="${WORKDIR}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135 else
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500136 bbfatal "A KBUILD_DEFCONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137 fi
138 fi
139
Brad Bishop19323692019-04-05 15:28:33 -0400140 # was anyone trying to patch the kernel meta data ?, we need to do
141 # this here, since the scc commands migrate the .cfg fragments to the
142 # kernel source tree, where they'll be used later.
143 check_git_config
144 patches="${@" ".join(find_patches(d,'kernel-meta'))}"
145 for p in $patches; do
146 (
147 cd ${WORKDIR}/kernel-meta
148 git am -s $p
149 )
150 done
151
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500152 sccs_from_src_uri="${@" ".join(find_sccs(d))}"
Brad Bishop19323692019-04-05 15:28:33 -0400153 patches="${@" ".join(find_patches(d,''))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}"
155
Andrew Geissler475cb722020-07-10 16:00:51 -0500156 # a quick check to make sure we don't have duplicate defconfigs If
157 # there's a defconfig in the SRC_URI, did we also have one from the
158 # KBUILD_DEFCONFIG processing above ?
159 src_uri_defconfig=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") != 0) { print $0 }' RS=' ')
160 # drop and defconfig's from the src_uri variable, we captured it just above here if it existed
161 sccs_from_src_uri=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") == 0) { print $0 }' RS=' ')
162
163 if [ -n "$in_tree_defconfig" ]; then
164 sccs_defconfig=$in_tree_defconfig
165 if [ -n "$src_uri_defconfig" ]; then
166 bbwarn "[NOTE]: defconfig was supplied both via KBUILD_DEFCONFIG and SRC_URI. Dropping SRC_URI defconfig"
167 fi
168 else
169 # if we didn't have an in-tree one, make our defconfig the one
170 # from the src_uri. Note: there may not have been one from the
171 # src_uri, so this can be an empty variable.
172 sccs_defconfig=$src_uri_defconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500173 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500174 sccs="$sccs_from_src_uri"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500175
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176 # check for feature directories/repos/branches that were part of the
177 # SRC_URI. If they were supplied, we convert them into include directives
178 # for the update part of the process
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600179 for f in ${feat_dirs}; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500180 if [ -d "${WORKDIR}/$f/meta" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600181 includes="$includes -I${WORKDIR}/$f/kernel-meta"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800182 elif [ -d "${WORKDIR}/../oe-local-files/$f" ]; then
183 includes="$includes -I${WORKDIR}/../oe-local-files/$f"
Brad Bishop19323692019-04-05 15:28:33 -0400184 elif [ -d "${WORKDIR}/$f" ]; then
185 includes="$includes -I${WORKDIR}/$f"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600187 done
188 for s in ${sccs} ${patches}; do
189 sdir=$(dirname $s)
190 includes="$includes -I${sdir}"
191 # if a SRC_URI passed patch or .scc has a subdir of "kernel-meta",
192 # then we add it to the search path
193 if [ -d "${sdir}/kernel-meta" ]; then
194 includes="$includes -I${sdir}/kernel-meta"
195 fi
196 done
197
198 # expand kernel features into their full path equivalents
199 bsp_definition=$(spp ${includes} --find -DKMACHINE=${KMACHINE} -DKTYPE=${LINUX_KERNEL_TYPE})
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500200 if [ -z "$bsp_definition" ]; then
Andrew Geissler475cb722020-07-10 16:00:51 -0500201 if [ -z "$sccs_defconfig" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500202 bbfatal_log "Could not locate BSP definition for ${KMACHINE}/${LINUX_KERNEL_TYPE} and no defconfig was provided"
203 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500204 else
Andrew Geissler82c905d2020-04-13 13:39:40 -0500205 # if the bsp definition has "define KMETA_EXTERNAL_BSP t",
206 # then we need to set a flag that will instruct the next
207 # steps to use the BSP as both configuration and patches.
208 grep -q KMETA_EXTERNAL_BSP $bsp_definition
209 if [ $? -eq 0 ]; then
210 KMETA_EXTERNAL_BSPS="t"
211 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500212 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600213 meta_dir=$(kgit --meta)
214
215 # run1: pull all the configuration fragments, no matter where they come from
Andrew Geisslerb7d28612020-07-24 16:15:54 -0500216 elements="`echo -n ${bsp_definition} $sccs_defconfig ${sccs} ${patches} ${KERNEL_FEATURES}`"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600217 if [ -n "${elements}" ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500218 echo "${bsp_definition}" > ${S}/${meta_dir}/bsp_definition
Andrew Geissler475cb722020-07-10 16:00:51 -0500219 scc --force -o ${S}/${meta_dir}:cfg,merge,meta ${includes} $sccs_defconfig $bsp_definition $sccs $patches ${KERNEL_FEATURES}
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500220 if [ $? -ne 0 ]; then
221 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
222 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223 fi
224
Andrew Geissler82c905d2020-04-13 13:39:40 -0500225 # if KMETA_EXTERNAL_BSPS has been set, or it has been detected from
226 # the bsp definition, then we inject the bsp_definition into the
227 # patch phase below. we'll piggy back on the sccs variable.
228 if [ -n "${KMETA_EXTERNAL_BSPS}" ]; then
229 sccs="${bsp_definition} ${sccs}"
230 fi
231
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600232 # run2: only generate patches for elements that have been passed on the SRC_URI
233 elements="`echo -n ${sccs} ${patches} ${KERNEL_FEATURES}`"
234 if [ -n "${elements}" ]; then
235 scc --force -o ${S}/${meta_dir}:patch --cmds patch ${includes} ${sccs} ${patches} ${KERNEL_FEATURES}
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500236 if [ $? -ne 0 ]; then
237 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
238 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239 fi
240}
241
242do_patch() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500243 set +e
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 cd ${S}
245
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600246 check_git_config
247 meta_dir=$(kgit --meta)
248 (cd ${meta_dir}; ln -sf patch.queue series)
249 if [ -f "${meta_dir}/series" ]; then
250 kgit-s2q --gen -v --patches .kernel-meta/
251 if [ $? -ne 0 ]; then
252 bberror "Could not apply patches for ${KMACHINE}."
253 bbfatal_log "Patch failures can be resolved in the linux source directory ${S})"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254 fi
255 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500256
257 if [ -f "${meta_dir}/merge.queue" ]; then
258 # we need to merge all these branches
259 for b in $(cat ${meta_dir}/merge.queue); do
260 git show-ref --verify --quiet refs/heads/${b}
261 if [ $? -eq 0 ]; then
262 bbnote "Merging branch ${b}"
263 git merge -q --no-ff -m "Merge branch ${b}" ${b}
264 else
265 bbfatal "branch ${b} does not exist, cannot merge"
266 fi
267 done
268 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500269}
270
271do_kernel_checkout() {
272 set +e
273
274 source_dir=`echo ${S} | sed 's%/$%%'`
275 source_workdir="${WORKDIR}/git"
276 if [ -d "${WORKDIR}/git/" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500277 # case: git repository
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree.
279 if [ "${source_dir}" != "${source_workdir}" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500280 if [ -d "${source_workdir}/.git" ]; then
281 # regular git repository with .git
282 rm -rf ${S}
283 mv ${WORKDIR}/git ${S}
284 else
285 # create source for bare cloned git repository
286 git clone ${WORKDIR}/git ${S}
287 rm -rf ${WORKDIR}/git
288 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500289 fi
290 cd ${S}
291 else
292 # case: we have no git repository at all.
293 # To support low bandwidth options for building the kernel, we'll just
294 # convert the tree to a git repo and let the rest of the process work unchanged
295
296 # if ${S} hasn't been set to the proper subdirectory a default of "linux" is
297 # used, but we can't initialize that empty directory. So check it and throw a
298 # clear error
299
300 cd ${S}
301 if [ ! -f "Makefile" ]; then
302 bberror "S is not set to the linux source directory. Check "
303 bbfatal "the recipe and set S to the proper extracted subdirectory"
304 fi
305 rm -f .gitignore
306 git init
Brad Bishop316dfdd2018-06-25 12:45:53 -0400307 check_git_config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500308 git add .
309 git commit -q -m "baseline commit: creating repo for ${PN}-${PV}"
310 git clean -d -f
311 fi
312
313 # convert any remote branches to local tracking ones
314 for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
315 b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
316 git show-ref --quiet --verify -- "refs/heads/$b"
317 if [ $? -ne 0 ]; then
318 git branch $b $i > /dev/null
319 fi
320 done
321
322 # Create a working tree copy of the kernel by checking out a branch
323 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
324
325 # checkout and clobber any unimportant files
326 git checkout -f ${machine_branch}
327}
328do_kernel_checkout[dirs] = "${S}"
329
Andrew Geissler82c905d2020-04-13 13:39:40 -0500330addtask kernel_checkout before do_kernel_metadata after do_symlink_kernsrc
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331addtask kernel_metadata after do_validate_branches do_unpack before do_patch
332do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500333do_validate_branches[depends] = "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500334
William A. Kennington III47649fa2018-06-28 12:34:29 -0700335do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}binutils:do_populate_sysroot"
336do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}gcc:do_populate_sysroot"
337do_kernel_configme[depends] += "bc-native:do_populate_sysroot bison-native:do_populate_sysroot"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500338do_kernel_configme[depends] += "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500339do_kernel_configme[dirs] += "${S} ${B}"
340do_kernel_configme() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600341 # translate the kconfig_mode into something that merge_config.sh
342 # understands
343 case ${KCONFIG_MODE} in
344 *allnoconfig)
345 config_flags="-n"
346 ;;
347 *alldefconfig)
348 config_flags=""
349 ;;
350 *)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351 if [ -f ${WORKDIR}/defconfig ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600352 config_flags="-n"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500353 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600354 ;;
355 esac
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500356
357 cd ${S}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600358
359 meta_dir=$(kgit --meta)
360 configs="$(scc --configs -o ${meta_dir})"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500361 if [ $? -ne 0 ]; then
362 bberror "${configs}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600363 bbfatal_log "Could not find configuration queue (${meta_dir}/config.queue)"
364 fi
365
Andrew Geissler82c905d2020-04-13 13:39:40 -0500366 CFLAGS="${CFLAGS} ${TOOLCHAIN_OPTIONS}" HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}" CC="${KERNEL_CC}" LD="${KERNEL_LD}" ARCH=${ARCH} merge_config.sh -O ${B} ${config_flags} ${configs} > ${meta_dir}/cfg/merge_config_build.log 2>&1
367 if [ $? -ne 0 -o ! -f ${B}/.config ]; then
368 bberror "Could not generate a .config for ${KMACHINE}-${LINUX_KERNEL_TYPE}"
369 if [ ${KCONF_AUDIT_LEVEL} -gt 1 ]; then
370 bbfatal_log "`cat ${meta_dir}/cfg/merge_config_build.log`"
371 else
372 bbfatal_log "Details can be found at: ${S}/${meta_dir}/cfg/merge_config_build.log"
373 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500374 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600375
Andrew Geissler82c905d2020-04-13 13:39:40 -0500376 if [ ! -z "${LINUX_VERSION_EXTENSION}" ]; then
377 echo "# Global settings from linux recipe" >> ${B}/.config
378 echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config
379 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500380}
381
382addtask kernel_configme before do_configure after do_patch
383
384python do_kernel_configcheck() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800385 import re, string, sys, subprocess
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500386
387 # if KMETA isn't set globally by a recipe using this routine, we need to
388 # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
389 # meta-series for processing
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500390 kmeta = d.getVar("KMETA") or "meta"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500391 if not os.path.exists(kmeta):
392 kmeta = "." + kmeta
393
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800394 s = d.getVar('S')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600395
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800396 env = os.environ.copy()
397 env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/")
Andrew Geissler82c905d2020-04-13 13:39:40 -0500398 env['LD'] = "${KERNEL_LD}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600399
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800400 try:
401 configs = subprocess.check_output(['scc', '--configs', '-o', s + '/.kernel-meta'], env=env).decode('utf-8')
402 except subprocess.CalledProcessError as e:
403 bb.fatal( "Cannot gather config fragments for audit: %s" % e.output.decode("utf-8") )
404
405 try:
406 subprocess.check_call(['kconf_check', '--report', '-o',
407 '%s/%s/cfg' % (s, kmeta), d.getVar('B') + '/.config', s, configs], cwd=s, env=env)
408 except subprocess.CalledProcessError:
409 # The configuration gathering can return different exit codes, but
410 # we interpret them based on the KCONF_AUDIT_LEVEL variable, so we catch
411 # everything here, and let the run continue.
412 pass
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500413
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500414 config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0)
415 bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500416
417 # if config check visibility is non-zero, report dropped configuration values
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600418 mismatch_file = d.expand("${S}/%s/cfg/mismatch.txt" % kmeta)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500419 if os.path.exists(mismatch_file):
420 if config_check_visibility:
421 with open (mismatch_file, "r") as myfile:
422 results = myfile.read()
423 bb.warn( "[kernel config]: specified values did not make it into the kernel's final configuration:\n\n%s" % results)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800424
425 if bsp_check_visibility:
426 invalid_file = d.expand("${S}/%s/cfg/invalid.cfg" % kmeta)
427 if os.path.exists(invalid_file) and os.stat(invalid_file).st_size > 0:
428 with open (invalid_file, "r") as myfile:
429 results = myfile.read()
430 bb.warn( "[kernel config]: This BSP sets config options that are not offered anywhere within this kernel:\n\n%s" % results)
431 errors_file = d.expand("${S}/%s/cfg/fragment_errors.txt" % kmeta)
432 if os.path.exists(errors_file) and os.stat(errors_file).st_size > 0:
433 with open (errors_file, "r") as myfile:
434 results = myfile.read()
435 bb.warn( "[kernel config]: This BSP contains fragments with errors:\n\n%s" % results)
436
437 # if the audit level is greater than two, we report if a fragment has overriden
438 # a value from a base fragment. This is really only used for new kernel introduction
439 if bsp_check_visibility > 2:
440 redefinition_file = d.expand("${S}/%s/cfg/redefinition.txt" % kmeta)
441 if os.path.exists(redefinition_file) and os.stat(redefinition_file).st_size > 0:
442 with open (redefinition_file, "r") as myfile:
443 results = myfile.read()
444 bb.warn( "[kernel config]: This BSP has configuration options defined in more than one config, with differing values:\n\n%s" % results)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500445}
446
447# Ensure that the branches (BSP and meta) are on the locations specified by
448# their SRCREV values. If they are NOT on the right commits, the branches
449# are corrected to the proper commit.
450do_validate_branches() {
451 set +e
452 cd ${S}
453
454 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
455 machine_srcrev="${SRCREV_machine}"
456
457 # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to
458 # check and we can exit early
459 if [ "${machine_srcrev}" = "AUTOINC" ]; then
460 bbnote "SRCREV validation is not required for AUTOREV"
461 elif [ "${machine_srcrev}" = "" ]; then
462 if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then
463 # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe
464 # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In
465 # this case, we need to reset to the give SRCREV before heading to patching
466 bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}"
467 force_srcrev="${SRCREV}"
468 fi
469 else
470 git cat-file -t ${machine_srcrev} > /dev/null
471 if [ $? -ne 0 ]; then
472 bberror "${machine_srcrev} is not a valid commit ID."
473 bbfatal_log "The kernel source tree may be out of sync"
474 fi
475 force_srcrev=${machine_srcrev}
476 fi
477
478 git checkout -q -f ${machine_branch}
479 if [ -n "${force_srcrev}" ]; then
480 # see if the branch we are about to patch has been properly reset to the defined
481 # SRCREV .. if not, we reset it.
482 branch_head=`git rev-parse HEAD`
483 if [ "${force_srcrev}" != "${branch_head}" ]; then
484 current_branch=`git rev-parse --abbrev-ref HEAD`
485 git branch "$current_branch-orig"
486 git reset --hard ${force_srcrev}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500487 # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check
488 # so the patches are applied as expected otherwise no patching
489 # would be done in some corner cases.
490 kgit-s2q --clean
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500491 fi
492 fi
493}
494
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500495OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
496KBUILD_OUTPUT = "${B}"
497
498python () {
499 # If diffconfig is available, ensure it runs after kernel_configme
500 if 'do_diffconfig' in d:
501 bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500502
503 externalsrc = d.getVar('EXTERNALSRC')
504 if externalsrc:
505 # If we deltask do_patch, do_kernel_configme is left without
506 # dependencies and runs too early
507 d.setVarFlag('do_kernel_configme', 'deps', (d.getVarFlag('do_kernel_configme', 'deps', False) or []) + ['do_unpack'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500508}
Andrew Geissler82c905d2020-04-13 13:39:40 -0500509
510# extra tasks
511addtask kernel_version_sanity_check after do_kernel_metadata do_kernel_checkout before do_compile
512addtask validate_branches before do_patch after do_kernel_checkout
513addtask kernel_configcheck after do_configure before do_compile