blob: 15c8dbb81f7765e6c1541acf7c01a31aee13c337 [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"
Andrew Geisslerc9f78652020-09-18 14:11:35 -050021KMETA_AUDIT_WERROR ?= ""
Andrew Geissler82c905d2020-04-13 13:39:40 -050022
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023# returns local (absolute) path names for all valid patches in the
24# src_uri
Brad Bishop19323692019-04-05 15:28:33 -040025def find_patches(d,subdir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026 patches = src_patches(d)
27 patch_list=[]
28 for p in patches:
Brad Bishop19323692019-04-05 15:28:33 -040029 _, _, local, _, _, parm = bb.fetch.decodeurl(p)
30 # if patchdir has been passed, we won't be able to apply it so skip
31 # the patch for now, and special processing happens later
32 patchdir = ''
33 if "patchdir" in parm:
34 patchdir = parm["patchdir"]
35 if subdir:
36 if subdir == patchdir:
37 patch_list.append(local)
38 else:
39 patch_list.append(local)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040
41 return patch_list
42
43# returns all the elements from the src uri that are .scc files
44def find_sccs(d):
45 sources=src_patches(d, True)
46 sources_list=[]
47 for s in sources:
48 base, ext = os.path.splitext(os.path.basename(s))
49 if ext and ext in [".scc", ".cfg"]:
50 sources_list.append(s)
Andrew Geissler82c905d2020-04-13 13:39:40 -050051 elif base and 'defconfig' in base:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 sources_list.append(s)
53
54 return sources_list
55
56# check the SRC_URI for "kmeta" type'd git repositories. Return the name of
57# the repository as it will be found in WORKDIR
58def find_kernel_feature_dirs(d):
59 feature_dirs=[]
60 fetch = bb.fetch2.Fetch([], d)
61 for url in fetch.urls:
62 urldata = fetch.ud[url]
63 parm = urldata.parm
64 type=""
65 if "type" in parm:
66 type = parm["type"]
67 if "destsuffix" in parm:
68 destdir = parm["destsuffix"]
69 if type == "kmeta":
70 feature_dirs.append(destdir)
71
72 return feature_dirs
73
74# find the master/machine source branch. In the same way that the fetcher proceses
75# git repositories in the SRC_URI we take the first repo found, first branch.
76def get_machine_branch(d, default):
77 fetch = bb.fetch2.Fetch([], d)
78 for url in fetch.urls:
79 urldata = fetch.ud[url]
80 parm = urldata.parm
81 if "branch" in parm:
82 branches = urldata.parm.get("branch").split(',')
Patrick Williamsf1e5d692016-03-30 15:21:19 -050083 btype = urldata.parm.get("type")
84 if btype != "kmeta":
85 return branches[0]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086
87 return default
88
Andrew Geisslerc9f78652020-09-18 14:11:35 -050089# returns a list of all directories that are on FILESEXTRAPATHS (and
90# hence available to the build) that contain .scc or .cfg files
91def get_dirs_with_fragments(d):
92 extrapaths = []
93 extrafiles = []
94 extrapathsvalue = (d.getVar("FILESEXTRAPATHS") or "")
95 # Remove default flag which was used for checking
96 extrapathsvalue = extrapathsvalue.replace("__default:", "")
97 extrapaths = extrapathsvalue.split(":")
98 for path in extrapaths:
99 if path + ":True" not in extrafiles:
100 extrafiles.append(path + ":" + str(os.path.exists(path)))
101
102 return " ".join(extrafiles)
103
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104do_kernel_metadata() {
105 set +e
Andrew Geissler635e0e42020-08-21 15:58:33 -0500106
107 if [ -n "$1" ]; then
108 mode="$1"
109 else
110 mode="patch"
111 fi
112
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113 cd ${S}
114 export KMETA=${KMETA}
115
116 # if kernel tools are available in-tree, they are preferred
117 # and are placed on the path before any external tools. Unless
118 # the external tools flag is set, in that case we do nothing.
119 if [ -f "${S}/scripts/util/configme" ]; then
120 if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then
121 PATH=${S}/scripts/util:${PATH}
122 fi
123 fi
124
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 # In a similar manner to the kernel itself:
126 #
127 # defconfig: $(obj)/conf
128 # ifeq ($(KBUILD_DEFCONFIG),)
129 # $< --defconfig $(Kconfig)
130 # else
131 # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
132 # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
133 # endif
134 #
135 # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it
136 # from the source tree, into a common location and normalized "defconfig" name,
137 # where the rest of the process will include and incoroporate it into the build
138 #
139 # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI),
140 # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take
141 # precendence.
142 #
143 if [ -n "${KBUILD_DEFCONFIG}" ]; then
144 if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then
145 if [ -f "${WORKDIR}/defconfig" ]; then
Andrew Geissler635e0e42020-08-21 15:58:33 -0500146 # If the two defconfig's are different, warn that we overwrote the
147 # one already placed in WORKDIR
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148 cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}"
149 if [ $? -ne 0 ]; then
Andrew Geissler635e0e42020-08-21 15:58:33 -0500150 bbdebug 1 "detected SRC_URI or unpatched defconfig in WORKDIR. ${KBUILD_DEFCONFIG} copied over it"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151 fi
Andrew Geissler635e0e42020-08-21 15:58:33 -0500152 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153 else
154 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500156 in_tree_defconfig="${WORKDIR}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 else
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500158 bbfatal "A KBUILD_DEFCONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree (${S}/arch/${ARCH}/configs/)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159 fi
160 fi
161
Andrew Geissler635e0e42020-08-21 15:58:33 -0500162 if [ "$mode" = "patch" ]; then
163 # was anyone trying to patch the kernel meta data ?, we need to do
164 # this here, since the scc commands migrate the .cfg fragments to the
165 # kernel source tree, where they'll be used later.
166 check_git_config
167 patches="${@" ".join(find_patches(d,'kernel-meta'))}"
168 for p in $patches; do
169 (
170 cd ${WORKDIR}/kernel-meta
171 git am -s $p
172 )
173 done
174 fi
Brad Bishop19323692019-04-05 15:28:33 -0400175
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500176 sccs_from_src_uri="${@" ".join(find_sccs(d))}"
Brad Bishop19323692019-04-05 15:28:33 -0400177 patches="${@" ".join(find_patches(d,''))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178 feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}"
179
Andrew Geissler475cb722020-07-10 16:00:51 -0500180 # a quick check to make sure we don't have duplicate defconfigs If
181 # there's a defconfig in the SRC_URI, did we also have one from the
182 # KBUILD_DEFCONFIG processing above ?
183 src_uri_defconfig=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") != 0) { print $0 }' RS=' ')
184 # drop and defconfig's from the src_uri variable, we captured it just above here if it existed
185 sccs_from_src_uri=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") == 0) { print $0 }' RS=' ')
186
187 if [ -n "$in_tree_defconfig" ]; then
188 sccs_defconfig=$in_tree_defconfig
189 if [ -n "$src_uri_defconfig" ]; then
190 bbwarn "[NOTE]: defconfig was supplied both via KBUILD_DEFCONFIG and SRC_URI. Dropping SRC_URI defconfig"
191 fi
192 else
193 # if we didn't have an in-tree one, make our defconfig the one
194 # from the src_uri. Note: there may not have been one from the
195 # src_uri, so this can be an empty variable.
196 sccs_defconfig=$src_uri_defconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500197 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500198 sccs="$sccs_from_src_uri"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500199
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 # check for feature directories/repos/branches that were part of the
201 # SRC_URI. If they were supplied, we convert them into include directives
202 # for the update part of the process
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600203 for f in ${feat_dirs}; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500204 if [ -d "${WORKDIR}/$f/meta" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600205 includes="$includes -I${WORKDIR}/$f/kernel-meta"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800206 elif [ -d "${WORKDIR}/../oe-local-files/$f" ]; then
207 includes="$includes -I${WORKDIR}/../oe-local-files/$f"
Brad Bishop19323692019-04-05 15:28:33 -0400208 elif [ -d "${WORKDIR}/$f" ]; then
209 includes="$includes -I${WORKDIR}/$f"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600211 done
212 for s in ${sccs} ${patches}; do
213 sdir=$(dirname $s)
214 includes="$includes -I${sdir}"
215 # if a SRC_URI passed patch or .scc has a subdir of "kernel-meta",
216 # then we add it to the search path
217 if [ -d "${sdir}/kernel-meta" ]; then
218 includes="$includes -I${sdir}/kernel-meta"
219 fi
220 done
221
222 # expand kernel features into their full path equivalents
223 bsp_definition=$(spp ${includes} --find -DKMACHINE=${KMACHINE} -DKTYPE=${LINUX_KERNEL_TYPE})
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500224 if [ -z "$bsp_definition" ]; then
Andrew Geissler475cb722020-07-10 16:00:51 -0500225 if [ -z "$sccs_defconfig" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500226 bbfatal_log "Could not locate BSP definition for ${KMACHINE}/${LINUX_KERNEL_TYPE} and no defconfig was provided"
227 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500228 else
Andrew Geissler82c905d2020-04-13 13:39:40 -0500229 # if the bsp definition has "define KMETA_EXTERNAL_BSP t",
230 # then we need to set a flag that will instruct the next
231 # steps to use the BSP as both configuration and patches.
232 grep -q KMETA_EXTERNAL_BSP $bsp_definition
233 if [ $? -eq 0 ]; then
234 KMETA_EXTERNAL_BSPS="t"
235 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500236 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600237 meta_dir=$(kgit --meta)
238
Andrew Geissler635e0e42020-08-21 15:58:33 -0500239 KERNEL_FEATURES_FINAL=""
240 if [ -n "${KERNEL_FEATURES}" ]; then
241 for feature in ${KERNEL_FEATURES}; do
242 feature_found=f
243 for d in $includes; do
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500244 path_to_check=$(echo $d | sed 's/^-I//')
Andrew Geissler635e0e42020-08-21 15:58:33 -0500245 if [ "$feature_found" = "f" ] && [ -e "$path_to_check/$feature" ]; then
246 feature_found=t
247 fi
248 done
249 if [ "$feature_found" = "f" ]; then
250 if [ -n "${KERNEL_DANGLING_FEATURES_WARN_ONLY}" ]; then
251 bbwarn "Feature '$feature' not found, but KERNEL_DANGLING_FEATURES_WARN_ONLY is set"
252 bbwarn "This may cause runtime issues, dropping feature and allowing configuration to continue"
253 else
254 bberror "Feature '$feature' not found, this will cause configuration failures."
255 bberror "Check the SRC_URI for meta-data repositories or directories that may be missing"
256 bbfatal_log "Set KERNEL_DANGLING_FEATURES_WARN_ONLY to ignore this issue"
257 fi
258 else
259 KERNEL_FEATURES_FINAL="$KERNEL_FEATURES_FINAL $feature"
260 fi
261 done
262 fi
263
264 if [ "$mode" = "config" ]; then
265 # run1: pull all the configuration fragments, no matter where they come from
266 elements="`echo -n ${bsp_definition} $sccs_defconfig ${sccs} ${patches} $KERNEL_FEATURES_FINAL`"
267 if [ -n "${elements}" ]; then
268 echo "${bsp_definition}" > ${S}/${meta_dir}/bsp_definition
269 scc --force -o ${S}/${meta_dir}:cfg,merge,meta ${includes} $sccs_defconfig $bsp_definition $sccs $patches $KERNEL_FEATURES_FINAL
270 if [ $? -ne 0 ]; then
271 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
272 fi
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500273 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500274 fi
275
Andrew Geissler82c905d2020-04-13 13:39:40 -0500276 # if KMETA_EXTERNAL_BSPS has been set, or it has been detected from
277 # the bsp definition, then we inject the bsp_definition into the
278 # patch phase below. we'll piggy back on the sccs variable.
279 if [ -n "${KMETA_EXTERNAL_BSPS}" ]; then
280 sccs="${bsp_definition} ${sccs}"
281 fi
282
Andrew Geissler635e0e42020-08-21 15:58:33 -0500283 if [ "$mode" = "patch" ]; then
284 # run2: only generate patches for elements that have been passed on the SRC_URI
285 elements="`echo -n ${sccs} ${patches} $KERNEL_FEATURES_FINAL`"
286 if [ -n "${elements}" ]; then
287 scc --force -o ${S}/${meta_dir}:patch --cmds patch ${includes} ${sccs} ${patches} $KERNEL_FEATURES_FINAL
288 if [ $? -ne 0 ]; then
289 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
290 fi
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500291 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292 fi
293}
294
295do_patch() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500296 set +e
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500297 cd ${S}
298
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600299 check_git_config
300 meta_dir=$(kgit --meta)
301 (cd ${meta_dir}; ln -sf patch.queue series)
302 if [ -f "${meta_dir}/series" ]; then
303 kgit-s2q --gen -v --patches .kernel-meta/
304 if [ $? -ne 0 ]; then
305 bberror "Could not apply patches for ${KMACHINE}."
306 bbfatal_log "Patch failures can be resolved in the linux source directory ${S})"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500307 fi
308 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500309
310 if [ -f "${meta_dir}/merge.queue" ]; then
311 # we need to merge all these branches
312 for b in $(cat ${meta_dir}/merge.queue); do
313 git show-ref --verify --quiet refs/heads/${b}
314 if [ $? -eq 0 ]; then
315 bbnote "Merging branch ${b}"
316 git merge -q --no-ff -m "Merge branch ${b}" ${b}
317 else
318 bbfatal "branch ${b} does not exist, cannot merge"
319 fi
320 done
321 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500322}
323
324do_kernel_checkout() {
325 set +e
326
327 source_dir=`echo ${S} | sed 's%/$%%'`
328 source_workdir="${WORKDIR}/git"
329 if [ -d "${WORKDIR}/git/" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500330 # case: git repository
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331 # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree.
332 if [ "${source_dir}" != "${source_workdir}" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500333 if [ -d "${source_workdir}/.git" ]; then
334 # regular git repository with .git
335 rm -rf ${S}
336 mv ${WORKDIR}/git ${S}
337 else
338 # create source for bare cloned git repository
339 git clone ${WORKDIR}/git ${S}
340 rm -rf ${WORKDIR}/git
341 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500342 fi
343 cd ${S}
344 else
345 # case: we have no git repository at all.
346 # To support low bandwidth options for building the kernel, we'll just
347 # convert the tree to a git repo and let the rest of the process work unchanged
348
349 # if ${S} hasn't been set to the proper subdirectory a default of "linux" is
350 # used, but we can't initialize that empty directory. So check it and throw a
351 # clear error
352
353 cd ${S}
354 if [ ! -f "Makefile" ]; then
355 bberror "S is not set to the linux source directory. Check "
356 bbfatal "the recipe and set S to the proper extracted subdirectory"
357 fi
358 rm -f .gitignore
359 git init
Brad Bishop316dfdd2018-06-25 12:45:53 -0400360 check_git_config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500361 git add .
362 git commit -q -m "baseline commit: creating repo for ${PN}-${PV}"
363 git clean -d -f
364 fi
365
366 # convert any remote branches to local tracking ones
367 for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
368 b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
369 git show-ref --quiet --verify -- "refs/heads/$b"
370 if [ $? -ne 0 ]; then
371 git branch $b $i > /dev/null
372 fi
373 done
374
375 # Create a working tree copy of the kernel by checking out a branch
376 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
377
378 # checkout and clobber any unimportant files
379 git checkout -f ${machine_branch}
380}
381do_kernel_checkout[dirs] = "${S}"
382
Andrew Geissler82c905d2020-04-13 13:39:40 -0500383addtask kernel_checkout before do_kernel_metadata after do_symlink_kernsrc
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500384addtask kernel_metadata after do_validate_branches do_unpack before do_patch
385do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500386do_kernel_metadata[file-checksums] = " ${@get_dirs_with_fragments(d)}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500387do_validate_branches[depends] = "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500388
William A. Kennington III47649fa2018-06-28 12:34:29 -0700389do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}binutils:do_populate_sysroot"
390do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}gcc:do_populate_sysroot"
391do_kernel_configme[depends] += "bc-native:do_populate_sysroot bison-native:do_populate_sysroot"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500392do_kernel_configme[depends] += "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500393do_kernel_configme[dirs] += "${S} ${B}"
394do_kernel_configme() {
Andrew Geissler635e0e42020-08-21 15:58:33 -0500395 do_kernel_metadata config
396
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600397 # translate the kconfig_mode into something that merge_config.sh
398 # understands
399 case ${KCONFIG_MODE} in
400 *allnoconfig)
401 config_flags="-n"
402 ;;
403 *alldefconfig)
404 config_flags=""
405 ;;
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500406 *)
407 if [ -f ${WORKDIR}/defconfig ]; then
408 config_flags="-n"
409 fi
410 ;;
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600411 esac
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500412
413 cd ${S}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600414
415 meta_dir=$(kgit --meta)
416 configs="$(scc --configs -o ${meta_dir})"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500417 if [ $? -ne 0 ]; then
418 bberror "${configs}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600419 bbfatal_log "Could not find configuration queue (${meta_dir}/config.queue)"
420 fi
421
Andrew Geissler82c905d2020-04-13 13:39:40 -0500422 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
423 if [ $? -ne 0 -o ! -f ${B}/.config ]; then
424 bberror "Could not generate a .config for ${KMACHINE}-${LINUX_KERNEL_TYPE}"
425 if [ ${KCONF_AUDIT_LEVEL} -gt 1 ]; then
426 bbfatal_log "`cat ${meta_dir}/cfg/merge_config_build.log`"
427 else
428 bbfatal_log "Details can be found at: ${S}/${meta_dir}/cfg/merge_config_build.log"
429 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500430 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600431
Andrew Geissler82c905d2020-04-13 13:39:40 -0500432 if [ ! -z "${LINUX_VERSION_EXTENSION}" ]; then
433 echo "# Global settings from linux recipe" >> ${B}/.config
434 echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config
435 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500436}
437
438addtask kernel_configme before do_configure after do_patch
Andrew Geissler635e0e42020-08-21 15:58:33 -0500439addtask config_analysis
440
441do_config_analysis[depends] = "virtual/kernel:do_configure"
442do_config_analysis[depends] += "kern-tools-native:do_populate_sysroot"
443
444CONFIG_AUDIT_FILE ?= "${WORKDIR}/config-audit.txt"
445CONFIG_ANALYSIS_FILE ?= "${WORKDIR}/config-analysis.txt"
446
447python do_config_analysis() {
448 import re, string, sys, subprocess
449
450 s = d.getVar('S')
451
452 env = os.environ.copy()
453 env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/")
454 env['LD'] = d.getVar('KERNEL_LD')
455 env['CC'] = d.getVar('KERNEL_CC')
456 env['ARCH'] = d.getVar('ARCH')
457 env['srctree'] = s
458
459 # read specific symbols from the kernel recipe or from local.conf
460 # i.e.: CONFIG_ANALYSIS_pn-linux-yocto-dev = 'NF_CONNTRACK LOCALVERSION'
461 config = d.getVar( 'CONFIG_ANALYSIS' )
462 if not config:
463 config = [ "" ]
464 else:
465 config = config.split()
466
467 for c in config:
468 for action in ["analysis","audit"]:
469 if action == "analysis":
470 try:
471 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--blame', c], cwd=s, env=env ).decode('utf-8')
472 except subprocess.CalledProcessError as e:
473 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
474
475 outfile = d.getVar( 'CONFIG_ANALYSIS_FILE' )
476
477 if action == "audit":
478 try:
479 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--summary', '--extended', '--sanity', c], cwd=s, env=env ).decode('utf-8')
480 except subprocess.CalledProcessError as e:
481 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
482
483 outfile = d.getVar( 'CONFIG_AUDIT_FILE' )
484
485 if c:
486 outdir = os.path.dirname( outfile )
487 outname = os.path.basename( outfile )
488 outfile = outdir + '/'+ c + '-' + outname
489
490 if config and os.path.isfile(outfile):
491 os.remove(outfile)
492
493 with open(outfile, 'w+') as f:
494 f.write( analysis )
495
496 bb.warn( "Configuration {} executed, see: {} for details".format(action,outfile ))
497 if c:
498 bb.warn( analysis )
499}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500500
501python do_kernel_configcheck() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800502 import re, string, sys, subprocess
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500503
504 # if KMETA isn't set globally by a recipe using this routine, we need to
505 # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
506 # meta-series for processing
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500507 kmeta = d.getVar("KMETA") or "meta"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500508 if not os.path.exists(kmeta):
Andrew Geissler635e0e42020-08-21 15:58:33 -0500509 kmeta = subprocess.check_output(['kgit', '--meta'], cwd=d.getVar('S')).decode('utf-8').rstrip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500510
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800511 s = d.getVar('S')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600512
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800513 env = os.environ.copy()
514 env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/")
Andrew Geissler635e0e42020-08-21 15:58:33 -0500515 env['LD'] = d.getVar('KERNEL_LD')
516 env['CC'] = d.getVar('KERNEL_CC')
517 env['ARCH'] = d.getVar('ARCH')
518 env['srctree'] = s
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600519
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800520 try:
521 configs = subprocess.check_output(['scc', '--configs', '-o', s + '/.kernel-meta'], env=env).decode('utf-8')
522 except subprocess.CalledProcessError as e:
523 bb.fatal( "Cannot gather config fragments for audit: %s" % e.output.decode("utf-8") )
524
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500525 config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0)
526 bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0)
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500527 kmeta_audit_werror = d.getVar("KMETA_AUDIT_WERROR") or ""
528 warnings_detected = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500529
Andrew Geissler635e0e42020-08-21 15:58:33 -0500530 # if config check visibility is "1", that's the lowest level of audit. So
531 # we add the --classify option to the run, since classification will
532 # streamline the output to only report options that could be boot issues,
533 # or are otherwise required for proper operation.
534 extra_params = ""
535 if config_check_visibility == 1:
536 extra_params = "--classify"
537
538 # category #1: mismatches
539 try:
540 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--mismatches', extra_params], cwd=s, env=env ).decode('utf-8')
541 except subprocess.CalledProcessError as e:
542 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
543
544 if analysis:
545 outfile = "{}/{}/cfg/mismatch.txt".format( s, kmeta )
546 if os.path.isfile(outfile):
547 os.remove(outfile)
548 with open(outfile, 'w+') as f:
549 f.write( analysis )
550
551 if config_check_visibility and os.stat(outfile).st_size > 0:
552 with open (outfile, "r") as myfile:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500553 results = myfile.read()
554 bb.warn( "[kernel config]: specified values did not make it into the kernel's final configuration:\n\n%s" % results)
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500555 warnings_detected = True
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800556
Andrew Geissler635e0e42020-08-21 15:58:33 -0500557 # category #2: invalid fragment elements
558 extra_params = ""
559 if bsp_check_visibility > 1:
560 extra_params = "--strict"
561 try:
562 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--invalid', extra_params], cwd=s, env=env ).decode('utf-8')
563 except subprocess.CalledProcessError as e:
564 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800565
Andrew Geissler635e0e42020-08-21 15:58:33 -0500566 if analysis:
567 outfile = "{}/{}/cfg/invalid.txt".format(s,kmeta)
568 if os.path.isfile(outfile):
569 os.remove(outfile)
570 with open(outfile, 'w+') as f:
571 f.write( analysis )
572
573 if bsp_check_visibility and os.stat(outfile).st_size > 0:
574 with open (outfile, "r") as myfile:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500575 results = myfile.read()
576 bb.warn( "[kernel config]: This BSP contains fragments with warnings:\n\n%s" % results)
577 warnings_detected = True
Andrew Geissler635e0e42020-08-21 15:58:33 -0500578
579 # category #3: redefined options (this is pretty verbose and is debug only)
580 try:
581 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--sanity'], cwd=s, env=env ).decode('utf-8')
582 except subprocess.CalledProcessError as e:
583 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
584
585 if analysis:
586 outfile = "{}/{}/cfg/redefinition.txt".format(s,kmeta)
587 if os.path.isfile(outfile):
588 os.remove(outfile)
589 with open(outfile, 'w+') as f:
590 f.write( analysis )
591
592 # if the audit level is greater than two, we report if a fragment has overriden
593 # a value from a base fragment. This is really only used for new kernel introduction
594 if bsp_check_visibility > 2 and os.stat(outfile).st_size > 0:
595 with open (outfile, "r") as myfile:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800596 results = myfile.read()
597 bb.warn( "[kernel config]: This BSP has configuration options defined in more than one config, with differing values:\n\n%s" % results)
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500598 warnings_detected = True
599
600 if warnings_detected and kmeta_audit_werror:
601 bb.fatal( "configuration warnings detected, werror is set, promoting to fatal" )
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500602}
603
604# Ensure that the branches (BSP and meta) are on the locations specified by
605# their SRCREV values. If they are NOT on the right commits, the branches
606# are corrected to the proper commit.
607do_validate_branches() {
608 set +e
609 cd ${S}
610
611 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
612 machine_srcrev="${SRCREV_machine}"
613
614 # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to
615 # check and we can exit early
616 if [ "${machine_srcrev}" = "AUTOINC" ]; then
617 bbnote "SRCREV validation is not required for AUTOREV"
618 elif [ "${machine_srcrev}" = "" ]; then
619 if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then
620 # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe
621 # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In
622 # this case, we need to reset to the give SRCREV before heading to patching
623 bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}"
624 force_srcrev="${SRCREV}"
625 fi
626 else
627 git cat-file -t ${machine_srcrev} > /dev/null
628 if [ $? -ne 0 ]; then
629 bberror "${machine_srcrev} is not a valid commit ID."
630 bbfatal_log "The kernel source tree may be out of sync"
631 fi
632 force_srcrev=${machine_srcrev}
633 fi
634
635 git checkout -q -f ${machine_branch}
636 if [ -n "${force_srcrev}" ]; then
637 # see if the branch we are about to patch has been properly reset to the defined
638 # SRCREV .. if not, we reset it.
639 branch_head=`git rev-parse HEAD`
640 if [ "${force_srcrev}" != "${branch_head}" ]; then
641 current_branch=`git rev-parse --abbrev-ref HEAD`
642 git branch "$current_branch-orig"
643 git reset --hard ${force_srcrev}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500644 # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check
645 # so the patches are applied as expected otherwise no patching
646 # would be done in some corner cases.
647 kgit-s2q --clean
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500648 fi
649 fi
650}
651
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500652OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
653KBUILD_OUTPUT = "${B}"
654
655python () {
656 # If diffconfig is available, ensure it runs after kernel_configme
657 if 'do_diffconfig' in d:
658 bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500659
660 externalsrc = d.getVar('EXTERNALSRC')
661 if externalsrc:
662 # If we deltask do_patch, do_kernel_configme is left without
663 # dependencies and runs too early
664 d.setVarFlag('do_kernel_configme', 'deps', (d.getVarFlag('do_kernel_configme', 'deps', False) or []) + ['do_unpack'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500665}
Andrew Geissler82c905d2020-04-13 13:39:40 -0500666
667# extra tasks
668addtask kernel_version_sanity_check after do_kernel_metadata do_kernel_checkout before do_compile
669addtask validate_branches before do_patch after do_kernel_checkout
670addtask kernel_configcheck after do_configure before do_compile