blob: 96ea612258d9b73e5b53c90d2a8bc0632934c4af [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
Andrew Geissler635e0e42020-08-21 15:58:33 -050090
91 if [ -n "$1" ]; then
92 mode="$1"
93 else
94 mode="patch"
95 fi
96
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097 cd ${S}
98 export KMETA=${KMETA}
99
100 # if kernel tools are available in-tree, they are preferred
101 # and are placed on the path before any external tools. Unless
102 # the external tools flag is set, in that case we do nothing.
103 if [ -f "${S}/scripts/util/configme" ]; then
104 if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then
105 PATH=${S}/scripts/util:${PATH}
106 fi
107 fi
108
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 # In a similar manner to the kernel itself:
110 #
111 # defconfig: $(obj)/conf
112 # ifeq ($(KBUILD_DEFCONFIG),)
113 # $< --defconfig $(Kconfig)
114 # else
115 # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
116 # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
117 # endif
118 #
119 # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it
120 # from the source tree, into a common location and normalized "defconfig" name,
121 # where the rest of the process will include and incoroporate it into the build
122 #
123 # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI),
124 # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take
125 # precendence.
126 #
127 if [ -n "${KBUILD_DEFCONFIG}" ]; then
128 if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then
129 if [ -f "${WORKDIR}/defconfig" ]; then
Andrew Geissler635e0e42020-08-21 15:58:33 -0500130 # If the two defconfig's are different, warn that we overwrote the
131 # one already placed in WORKDIR
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500132 cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}"
133 if [ $? -ne 0 ]; then
Andrew Geissler635e0e42020-08-21 15:58:33 -0500134 bbdebug 1 "detected SRC_URI or unpatched defconfig in WORKDIR. ${KBUILD_DEFCONFIG} copied over it"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135 fi
Andrew Geissler635e0e42020-08-21 15:58:33 -0500136 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137 else
138 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500140 in_tree_defconfig="${WORKDIR}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141 else
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500142 bbfatal "A KBUILD_DEFCONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500143 fi
144 fi
145
Andrew Geissler635e0e42020-08-21 15:58:33 -0500146 if [ "$mode" = "patch" ]; then
147 # was anyone trying to patch the kernel meta data ?, we need to do
148 # this here, since the scc commands migrate the .cfg fragments to the
149 # kernel source tree, where they'll be used later.
150 check_git_config
151 patches="${@" ".join(find_patches(d,'kernel-meta'))}"
152 for p in $patches; do
153 (
154 cd ${WORKDIR}/kernel-meta
155 git am -s $p
156 )
157 done
158 fi
Brad Bishop19323692019-04-05 15:28:33 -0400159
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500160 sccs_from_src_uri="${@" ".join(find_sccs(d))}"
Brad Bishop19323692019-04-05 15:28:33 -0400161 patches="${@" ".join(find_patches(d,''))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162 feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}"
163
Andrew Geissler475cb722020-07-10 16:00:51 -0500164 # a quick check to make sure we don't have duplicate defconfigs If
165 # there's a defconfig in the SRC_URI, did we also have one from the
166 # KBUILD_DEFCONFIG processing above ?
167 src_uri_defconfig=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") != 0) { print $0 }' RS=' ')
168 # drop and defconfig's from the src_uri variable, we captured it just above here if it existed
169 sccs_from_src_uri=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") == 0) { print $0 }' RS=' ')
170
171 if [ -n "$in_tree_defconfig" ]; then
172 sccs_defconfig=$in_tree_defconfig
173 if [ -n "$src_uri_defconfig" ]; then
174 bbwarn "[NOTE]: defconfig was supplied both via KBUILD_DEFCONFIG and SRC_URI. Dropping SRC_URI defconfig"
175 fi
176 else
177 # if we didn't have an in-tree one, make our defconfig the one
178 # from the src_uri. Note: there may not have been one from the
179 # src_uri, so this can be an empty variable.
180 sccs_defconfig=$src_uri_defconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500181 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500182 sccs="$sccs_from_src_uri"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500183
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500184 # check for feature directories/repos/branches that were part of the
185 # SRC_URI. If they were supplied, we convert them into include directives
186 # for the update part of the process
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600187 for f in ${feat_dirs}; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500188 if [ -d "${WORKDIR}/$f/meta" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600189 includes="$includes -I${WORKDIR}/$f/kernel-meta"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800190 elif [ -d "${WORKDIR}/../oe-local-files/$f" ]; then
191 includes="$includes -I${WORKDIR}/../oe-local-files/$f"
Brad Bishop19323692019-04-05 15:28:33 -0400192 elif [ -d "${WORKDIR}/$f" ]; then
193 includes="$includes -I${WORKDIR}/$f"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500194 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600195 done
196 for s in ${sccs} ${patches}; do
197 sdir=$(dirname $s)
198 includes="$includes -I${sdir}"
199 # if a SRC_URI passed patch or .scc has a subdir of "kernel-meta",
200 # then we add it to the search path
201 if [ -d "${sdir}/kernel-meta" ]; then
202 includes="$includes -I${sdir}/kernel-meta"
203 fi
204 done
205
206 # expand kernel features into their full path equivalents
207 bsp_definition=$(spp ${includes} --find -DKMACHINE=${KMACHINE} -DKTYPE=${LINUX_KERNEL_TYPE})
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500208 if [ -z "$bsp_definition" ]; then
Andrew Geissler475cb722020-07-10 16:00:51 -0500209 if [ -z "$sccs_defconfig" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500210 bbfatal_log "Could not locate BSP definition for ${KMACHINE}/${LINUX_KERNEL_TYPE} and no defconfig was provided"
211 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500212 else
Andrew Geissler82c905d2020-04-13 13:39:40 -0500213 # if the bsp definition has "define KMETA_EXTERNAL_BSP t",
214 # then we need to set a flag that will instruct the next
215 # steps to use the BSP as both configuration and patches.
216 grep -q KMETA_EXTERNAL_BSP $bsp_definition
217 if [ $? -eq 0 ]; then
218 KMETA_EXTERNAL_BSPS="t"
219 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500220 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600221 meta_dir=$(kgit --meta)
222
Andrew Geissler635e0e42020-08-21 15:58:33 -0500223 KERNEL_FEATURES_FINAL=""
224 if [ -n "${KERNEL_FEATURES}" ]; then
225 for feature in ${KERNEL_FEATURES}; do
226 feature_found=f
227 for d in $includes; do
228 path_to_check=$(echo $d | sed 's/-I//g')
229 if [ "$feature_found" = "f" ] && [ -e "$path_to_check/$feature" ]; then
230 feature_found=t
231 fi
232 done
233 if [ "$feature_found" = "f" ]; then
234 if [ -n "${KERNEL_DANGLING_FEATURES_WARN_ONLY}" ]; then
235 bbwarn "Feature '$feature' not found, but KERNEL_DANGLING_FEATURES_WARN_ONLY is set"
236 bbwarn "This may cause runtime issues, dropping feature and allowing configuration to continue"
237 else
238 bberror "Feature '$feature' not found, this will cause configuration failures."
239 bberror "Check the SRC_URI for meta-data repositories or directories that may be missing"
240 bbfatal_log "Set KERNEL_DANGLING_FEATURES_WARN_ONLY to ignore this issue"
241 fi
242 else
243 KERNEL_FEATURES_FINAL="$KERNEL_FEATURES_FINAL $feature"
244 fi
245 done
246 fi
247
248 if [ "$mode" = "config" ]; then
249 # run1: pull all the configuration fragments, no matter where they come from
250 elements="`echo -n ${bsp_definition} $sccs_defconfig ${sccs} ${patches} $KERNEL_FEATURES_FINAL`"
251 if [ -n "${elements}" ]; then
252 echo "${bsp_definition}" > ${S}/${meta_dir}/bsp_definition
253 scc --force -o ${S}/${meta_dir}:cfg,merge,meta ${includes} $sccs_defconfig $bsp_definition $sccs $patches $KERNEL_FEATURES_FINAL
254 if [ $? -ne 0 ]; then
255 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
256 fi
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500257 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258 fi
259
Andrew Geissler82c905d2020-04-13 13:39:40 -0500260 # if KMETA_EXTERNAL_BSPS has been set, or it has been detected from
261 # the bsp definition, then we inject the bsp_definition into the
262 # patch phase below. we'll piggy back on the sccs variable.
263 if [ -n "${KMETA_EXTERNAL_BSPS}" ]; then
264 sccs="${bsp_definition} ${sccs}"
265 fi
266
Andrew Geissler635e0e42020-08-21 15:58:33 -0500267 if [ "$mode" = "patch" ]; then
268 # run2: only generate patches for elements that have been passed on the SRC_URI
269 elements="`echo -n ${sccs} ${patches} $KERNEL_FEATURES_FINAL`"
270 if [ -n "${elements}" ]; then
271 scc --force -o ${S}/${meta_dir}:patch --cmds patch ${includes} ${sccs} ${patches} $KERNEL_FEATURES_FINAL
272 if [ $? -ne 0 ]; then
273 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
274 fi
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500275 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500276 fi
277}
278
279do_patch() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500280 set +e
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500281 cd ${S}
282
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600283 check_git_config
284 meta_dir=$(kgit --meta)
285 (cd ${meta_dir}; ln -sf patch.queue series)
286 if [ -f "${meta_dir}/series" ]; then
287 kgit-s2q --gen -v --patches .kernel-meta/
288 if [ $? -ne 0 ]; then
289 bberror "Could not apply patches for ${KMACHINE}."
290 bbfatal_log "Patch failures can be resolved in the linux source directory ${S})"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500291 fi
292 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500293
294 if [ -f "${meta_dir}/merge.queue" ]; then
295 # we need to merge all these branches
296 for b in $(cat ${meta_dir}/merge.queue); do
297 git show-ref --verify --quiet refs/heads/${b}
298 if [ $? -eq 0 ]; then
299 bbnote "Merging branch ${b}"
300 git merge -q --no-ff -m "Merge branch ${b}" ${b}
301 else
302 bbfatal "branch ${b} does not exist, cannot merge"
303 fi
304 done
305 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306}
307
308do_kernel_checkout() {
309 set +e
310
311 source_dir=`echo ${S} | sed 's%/$%%'`
312 source_workdir="${WORKDIR}/git"
313 if [ -d "${WORKDIR}/git/" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500314 # case: git repository
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315 # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree.
316 if [ "${source_dir}" != "${source_workdir}" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500317 if [ -d "${source_workdir}/.git" ]; then
318 # regular git repository with .git
319 rm -rf ${S}
320 mv ${WORKDIR}/git ${S}
321 else
322 # create source for bare cloned git repository
323 git clone ${WORKDIR}/git ${S}
324 rm -rf ${WORKDIR}/git
325 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500326 fi
327 cd ${S}
328 else
329 # case: we have no git repository at all.
330 # To support low bandwidth options for building the kernel, we'll just
331 # convert the tree to a git repo and let the rest of the process work unchanged
332
333 # if ${S} hasn't been set to the proper subdirectory a default of "linux" is
334 # used, but we can't initialize that empty directory. So check it and throw a
335 # clear error
336
337 cd ${S}
338 if [ ! -f "Makefile" ]; then
339 bberror "S is not set to the linux source directory. Check "
340 bbfatal "the recipe and set S to the proper extracted subdirectory"
341 fi
342 rm -f .gitignore
343 git init
Brad Bishop316dfdd2018-06-25 12:45:53 -0400344 check_git_config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500345 git add .
346 git commit -q -m "baseline commit: creating repo for ${PN}-${PV}"
347 git clean -d -f
348 fi
349
350 # convert any remote branches to local tracking ones
351 for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
352 b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
353 git show-ref --quiet --verify -- "refs/heads/$b"
354 if [ $? -ne 0 ]; then
355 git branch $b $i > /dev/null
356 fi
357 done
358
359 # Create a working tree copy of the kernel by checking out a branch
360 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
361
362 # checkout and clobber any unimportant files
363 git checkout -f ${machine_branch}
364}
365do_kernel_checkout[dirs] = "${S}"
366
Andrew Geissler82c905d2020-04-13 13:39:40 -0500367addtask kernel_checkout before do_kernel_metadata after do_symlink_kernsrc
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500368addtask kernel_metadata after do_validate_branches do_unpack before do_patch
369do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500370do_validate_branches[depends] = "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500371
William A. Kennington III47649fa2018-06-28 12:34:29 -0700372do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}binutils:do_populate_sysroot"
373do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}gcc:do_populate_sysroot"
374do_kernel_configme[depends] += "bc-native:do_populate_sysroot bison-native:do_populate_sysroot"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500375do_kernel_configme[depends] += "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500376do_kernel_configme[dirs] += "${S} ${B}"
377do_kernel_configme() {
Andrew Geissler635e0e42020-08-21 15:58:33 -0500378 do_kernel_metadata config
379
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600380 # translate the kconfig_mode into something that merge_config.sh
381 # understands
382 case ${KCONFIG_MODE} in
383 *allnoconfig)
384 config_flags="-n"
385 ;;
386 *alldefconfig)
387 config_flags=""
388 ;;
389 *)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500390 if [ -f ${WORKDIR}/defconfig ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600391 config_flags="-n"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500392 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600393 ;;
394 esac
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500395
396 cd ${S}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600397
398 meta_dir=$(kgit --meta)
399 configs="$(scc --configs -o ${meta_dir})"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500400 if [ $? -ne 0 ]; then
401 bberror "${configs}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600402 bbfatal_log "Could not find configuration queue (${meta_dir}/config.queue)"
403 fi
404
Andrew Geissler82c905d2020-04-13 13:39:40 -0500405 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
406 if [ $? -ne 0 -o ! -f ${B}/.config ]; then
407 bberror "Could not generate a .config for ${KMACHINE}-${LINUX_KERNEL_TYPE}"
408 if [ ${KCONF_AUDIT_LEVEL} -gt 1 ]; then
409 bbfatal_log "`cat ${meta_dir}/cfg/merge_config_build.log`"
410 else
411 bbfatal_log "Details can be found at: ${S}/${meta_dir}/cfg/merge_config_build.log"
412 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500413 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600414
Andrew Geissler82c905d2020-04-13 13:39:40 -0500415 if [ ! -z "${LINUX_VERSION_EXTENSION}" ]; then
416 echo "# Global settings from linux recipe" >> ${B}/.config
417 echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config
418 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500419}
420
421addtask kernel_configme before do_configure after do_patch
Andrew Geissler635e0e42020-08-21 15:58:33 -0500422addtask config_analysis
423
424do_config_analysis[depends] = "virtual/kernel:do_configure"
425do_config_analysis[depends] += "kern-tools-native:do_populate_sysroot"
426
427CONFIG_AUDIT_FILE ?= "${WORKDIR}/config-audit.txt"
428CONFIG_ANALYSIS_FILE ?= "${WORKDIR}/config-analysis.txt"
429
430python do_config_analysis() {
431 import re, string, sys, subprocess
432
433 s = d.getVar('S')
434
435 env = os.environ.copy()
436 env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/")
437 env['LD'] = d.getVar('KERNEL_LD')
438 env['CC'] = d.getVar('KERNEL_CC')
439 env['ARCH'] = d.getVar('ARCH')
440 env['srctree'] = s
441
442 # read specific symbols from the kernel recipe or from local.conf
443 # i.e.: CONFIG_ANALYSIS_pn-linux-yocto-dev = 'NF_CONNTRACK LOCALVERSION'
444 config = d.getVar( 'CONFIG_ANALYSIS' )
445 if not config:
446 config = [ "" ]
447 else:
448 config = config.split()
449
450 for c in config:
451 for action in ["analysis","audit"]:
452 if action == "analysis":
453 try:
454 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--blame', c], cwd=s, env=env ).decode('utf-8')
455 except subprocess.CalledProcessError as e:
456 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
457
458 outfile = d.getVar( 'CONFIG_ANALYSIS_FILE' )
459
460 if action == "audit":
461 try:
462 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--summary', '--extended', '--sanity', c], cwd=s, env=env ).decode('utf-8')
463 except subprocess.CalledProcessError as e:
464 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
465
466 outfile = d.getVar( 'CONFIG_AUDIT_FILE' )
467
468 if c:
469 outdir = os.path.dirname( outfile )
470 outname = os.path.basename( outfile )
471 outfile = outdir + '/'+ c + '-' + outname
472
473 if config and os.path.isfile(outfile):
474 os.remove(outfile)
475
476 with open(outfile, 'w+') as f:
477 f.write( analysis )
478
479 bb.warn( "Configuration {} executed, see: {} for details".format(action,outfile ))
480 if c:
481 bb.warn( analysis )
482}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500483
484python do_kernel_configcheck() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800485 import re, string, sys, subprocess
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500486
487 # if KMETA isn't set globally by a recipe using this routine, we need to
488 # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
489 # meta-series for processing
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500490 kmeta = d.getVar("KMETA") or "meta"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500491 if not os.path.exists(kmeta):
Andrew Geissler635e0e42020-08-21 15:58:33 -0500492 kmeta = subprocess.check_output(['kgit', '--meta'], cwd=d.getVar('S')).decode('utf-8').rstrip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500493
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800494 s = d.getVar('S')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600495
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800496 env = os.environ.copy()
497 env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/")
Andrew Geissler635e0e42020-08-21 15:58:33 -0500498 env['LD'] = d.getVar('KERNEL_LD')
499 env['CC'] = d.getVar('KERNEL_CC')
500 env['ARCH'] = d.getVar('ARCH')
501 env['srctree'] = s
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600502
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800503 try:
504 configs = subprocess.check_output(['scc', '--configs', '-o', s + '/.kernel-meta'], env=env).decode('utf-8')
505 except subprocess.CalledProcessError as e:
506 bb.fatal( "Cannot gather config fragments for audit: %s" % e.output.decode("utf-8") )
507
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500508 config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0)
509 bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500510
Andrew Geissler635e0e42020-08-21 15:58:33 -0500511 # if config check visibility is "1", that's the lowest level of audit. So
512 # we add the --classify option to the run, since classification will
513 # streamline the output to only report options that could be boot issues,
514 # or are otherwise required for proper operation.
515 extra_params = ""
516 if config_check_visibility == 1:
517 extra_params = "--classify"
518
519 # category #1: mismatches
520 try:
521 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--mismatches', extra_params], cwd=s, env=env ).decode('utf-8')
522 except subprocess.CalledProcessError as e:
523 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
524
525 if analysis:
526 outfile = "{}/{}/cfg/mismatch.txt".format( s, kmeta )
527 if os.path.isfile(outfile):
528 os.remove(outfile)
529 with open(outfile, 'w+') as f:
530 f.write( analysis )
531
532 if config_check_visibility and os.stat(outfile).st_size > 0:
533 with open (outfile, "r") as myfile:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500534 results = myfile.read()
535 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 -0800536
Andrew Geissler635e0e42020-08-21 15:58:33 -0500537 # category #2: invalid fragment elements
538 extra_params = ""
539 if bsp_check_visibility > 1:
540 extra_params = "--strict"
541 try:
542 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--invalid', extra_params], cwd=s, env=env ).decode('utf-8')
543 except subprocess.CalledProcessError as e:
544 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800545
Andrew Geissler635e0e42020-08-21 15:58:33 -0500546 if analysis:
547 outfile = "{}/{}/cfg/invalid.txt".format(s,kmeta)
548 if os.path.isfile(outfile):
549 os.remove(outfile)
550 with open(outfile, 'w+') as f:
551 f.write( analysis )
552
553 if bsp_check_visibility and os.stat(outfile).st_size > 0:
554 with open (outfile, "r") as myfile:
555 results = myfile.read()
556 bb.warn( "[kernel config]: This BSP contains fragments with warnings:\n\n%s" % results)
557
558 # category #3: redefined options (this is pretty verbose and is debug only)
559 try:
560 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--sanity'], cwd=s, env=env ).decode('utf-8')
561 except subprocess.CalledProcessError as e:
562 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
563
564 if analysis:
565 outfile = "{}/{}/cfg/redefinition.txt".format(s,kmeta)
566 if os.path.isfile(outfile):
567 os.remove(outfile)
568 with open(outfile, 'w+') as f:
569 f.write( analysis )
570
571 # if the audit level is greater than two, we report if a fragment has overriden
572 # a value from a base fragment. This is really only used for new kernel introduction
573 if bsp_check_visibility > 2 and os.stat(outfile).st_size > 0:
574 with open (outfile, "r") as myfile:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800575 results = myfile.read()
576 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 -0500577}
578
579# Ensure that the branches (BSP and meta) are on the locations specified by
580# their SRCREV values. If they are NOT on the right commits, the branches
581# are corrected to the proper commit.
582do_validate_branches() {
583 set +e
584 cd ${S}
585
586 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
587 machine_srcrev="${SRCREV_machine}"
588
589 # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to
590 # check and we can exit early
591 if [ "${machine_srcrev}" = "AUTOINC" ]; then
592 bbnote "SRCREV validation is not required for AUTOREV"
593 elif [ "${machine_srcrev}" = "" ]; then
594 if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then
595 # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe
596 # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In
597 # this case, we need to reset to the give SRCREV before heading to patching
598 bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}"
599 force_srcrev="${SRCREV}"
600 fi
601 else
602 git cat-file -t ${machine_srcrev} > /dev/null
603 if [ $? -ne 0 ]; then
604 bberror "${machine_srcrev} is not a valid commit ID."
605 bbfatal_log "The kernel source tree may be out of sync"
606 fi
607 force_srcrev=${machine_srcrev}
608 fi
609
610 git checkout -q -f ${machine_branch}
611 if [ -n "${force_srcrev}" ]; then
612 # see if the branch we are about to patch has been properly reset to the defined
613 # SRCREV .. if not, we reset it.
614 branch_head=`git rev-parse HEAD`
615 if [ "${force_srcrev}" != "${branch_head}" ]; then
616 current_branch=`git rev-parse --abbrev-ref HEAD`
617 git branch "$current_branch-orig"
618 git reset --hard ${force_srcrev}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500619 # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check
620 # so the patches are applied as expected otherwise no patching
621 # would be done in some corner cases.
622 kgit-s2q --clean
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500623 fi
624 fi
625}
626
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
628KBUILD_OUTPUT = "${B}"
629
630python () {
631 # If diffconfig is available, ensure it runs after kernel_configme
632 if 'do_diffconfig' in d:
633 bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500634
635 externalsrc = d.getVar('EXTERNALSRC')
636 if externalsrc:
637 # If we deltask do_patch, do_kernel_configme is left without
638 # dependencies and runs too early
639 d.setVarFlag('do_kernel_configme', 'deps', (d.getVarFlag('do_kernel_configme', 'deps', False) or []) + ['do_unpack'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500640}
Andrew Geissler82c905d2020-04-13 13:39:40 -0500641
642# extra tasks
643addtask kernel_version_sanity_check after do_kernel_metadata do_kernel_checkout before do_compile
644addtask validate_branches before do_patch after do_kernel_checkout
645addtask kernel_configcheck after do_configure before do_compile