blob: 0df61cdef0c29e3b84ef1dd7767cda31aa376874 [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
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700116 bbnote "do_kernel_metadata: for summary/debug, set KCONF_AUDIT_LEVEL > 0"
117
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500118 # if kernel tools are available in-tree, they are preferred
119 # and are placed on the path before any external tools. Unless
120 # the external tools flag is set, in that case we do nothing.
121 if [ -f "${S}/scripts/util/configme" ]; then
122 if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then
123 PATH=${S}/scripts/util:${PATH}
124 fi
125 fi
126
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500127 # In a similar manner to the kernel itself:
128 #
129 # defconfig: $(obj)/conf
130 # ifeq ($(KBUILD_DEFCONFIG),)
131 # $< --defconfig $(Kconfig)
132 # else
133 # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
134 # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
135 # endif
136 #
137 # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it
138 # from the source tree, into a common location and normalized "defconfig" name,
139 # where the rest of the process will include and incoroporate it into the build
140 #
141 # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI),
142 # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take
143 # precendence.
144 #
145 if [ -n "${KBUILD_DEFCONFIG}" ]; then
146 if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then
147 if [ -f "${WORKDIR}/defconfig" ]; then
Andrew Geissler635e0e42020-08-21 15:58:33 -0500148 # If the two defconfig's are different, warn that we overwrote the
149 # one already placed in WORKDIR
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}"
151 if [ $? -ne 0 ]; then
Andrew Geissler635e0e42020-08-21 15:58:33 -0500152 bbdebug 1 "detected SRC_URI or unpatched defconfig in WORKDIR. ${KBUILD_DEFCONFIG} copied over it"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153 fi
Andrew Geissler635e0e42020-08-21 15:58:33 -0500154 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155 else
156 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500158 in_tree_defconfig="${WORKDIR}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159 else
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500160 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 -0500161 fi
162 fi
163
Andrew Geissler635e0e42020-08-21 15:58:33 -0500164 if [ "$mode" = "patch" ]; then
165 # was anyone trying to patch the kernel meta data ?, we need to do
166 # this here, since the scc commands migrate the .cfg fragments to the
167 # kernel source tree, where they'll be used later.
168 check_git_config
169 patches="${@" ".join(find_patches(d,'kernel-meta'))}"
170 for p in $patches; do
171 (
172 cd ${WORKDIR}/kernel-meta
173 git am -s $p
174 )
175 done
176 fi
Brad Bishop19323692019-04-05 15:28:33 -0400177
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500178 sccs_from_src_uri="${@" ".join(find_sccs(d))}"
Brad Bishop19323692019-04-05 15:28:33 -0400179 patches="${@" ".join(find_patches(d,''))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500180 feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}"
181
Andrew Geissler475cb722020-07-10 16:00:51 -0500182 # a quick check to make sure we don't have duplicate defconfigs If
183 # there's a defconfig in the SRC_URI, did we also have one from the
184 # KBUILD_DEFCONFIG processing above ?
185 src_uri_defconfig=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") != 0) { print $0 }' RS=' ')
186 # drop and defconfig's from the src_uri variable, we captured it just above here if it existed
187 sccs_from_src_uri=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") == 0) { print $0 }' RS=' ')
188
189 if [ -n "$in_tree_defconfig" ]; then
190 sccs_defconfig=$in_tree_defconfig
191 if [ -n "$src_uri_defconfig" ]; then
192 bbwarn "[NOTE]: defconfig was supplied both via KBUILD_DEFCONFIG and SRC_URI. Dropping SRC_URI defconfig"
193 fi
194 else
195 # if we didn't have an in-tree one, make our defconfig the one
196 # from the src_uri. Note: there may not have been one from the
197 # src_uri, so this can be an empty variable.
198 sccs_defconfig=$src_uri_defconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500199 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500200 sccs="$sccs_from_src_uri"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500201
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 # check for feature directories/repos/branches that were part of the
203 # SRC_URI. If they were supplied, we convert them into include directives
204 # for the update part of the process
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600205 for f in ${feat_dirs}; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 if [ -d "${WORKDIR}/$f/meta" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600207 includes="$includes -I${WORKDIR}/$f/kernel-meta"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800208 elif [ -d "${WORKDIR}/../oe-local-files/$f" ]; then
209 includes="$includes -I${WORKDIR}/../oe-local-files/$f"
Brad Bishop19323692019-04-05 15:28:33 -0400210 elif [ -d "${WORKDIR}/$f" ]; then
211 includes="$includes -I${WORKDIR}/$f"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500212 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600213 done
214 for s in ${sccs} ${patches}; do
215 sdir=$(dirname $s)
216 includes="$includes -I${sdir}"
217 # if a SRC_URI passed patch or .scc has a subdir of "kernel-meta",
218 # then we add it to the search path
219 if [ -d "${sdir}/kernel-meta" ]; then
220 includes="$includes -I${sdir}/kernel-meta"
221 fi
222 done
223
224 # expand kernel features into their full path equivalents
225 bsp_definition=$(spp ${includes} --find -DKMACHINE=${KMACHINE} -DKTYPE=${LINUX_KERNEL_TYPE})
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500226 if [ -z "$bsp_definition" ]; then
Andrew Geissler475cb722020-07-10 16:00:51 -0500227 if [ -z "$sccs_defconfig" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500228 bbfatal_log "Could not locate BSP definition for ${KMACHINE}/${LINUX_KERNEL_TYPE} and no defconfig was provided"
229 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500230 else
Andrew Geissler82c905d2020-04-13 13:39:40 -0500231 # if the bsp definition has "define KMETA_EXTERNAL_BSP t",
232 # then we need to set a flag that will instruct the next
233 # steps to use the BSP as both configuration and patches.
234 grep -q KMETA_EXTERNAL_BSP $bsp_definition
235 if [ $? -eq 0 ]; then
236 KMETA_EXTERNAL_BSPS="t"
237 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500238 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600239 meta_dir=$(kgit --meta)
240
Andrew Geissler635e0e42020-08-21 15:58:33 -0500241 KERNEL_FEATURES_FINAL=""
242 if [ -n "${KERNEL_FEATURES}" ]; then
243 for feature in ${KERNEL_FEATURES}; do
244 feature_found=f
245 for d in $includes; do
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500246 path_to_check=$(echo $d | sed 's/^-I//')
Andrew Geissler635e0e42020-08-21 15:58:33 -0500247 if [ "$feature_found" = "f" ] && [ -e "$path_to_check/$feature" ]; then
248 feature_found=t
249 fi
250 done
251 if [ "$feature_found" = "f" ]; then
252 if [ -n "${KERNEL_DANGLING_FEATURES_WARN_ONLY}" ]; then
253 bbwarn "Feature '$feature' not found, but KERNEL_DANGLING_FEATURES_WARN_ONLY is set"
254 bbwarn "This may cause runtime issues, dropping feature and allowing configuration to continue"
255 else
256 bberror "Feature '$feature' not found, this will cause configuration failures."
257 bberror "Check the SRC_URI for meta-data repositories or directories that may be missing"
258 bbfatal_log "Set KERNEL_DANGLING_FEATURES_WARN_ONLY to ignore this issue"
259 fi
260 else
261 KERNEL_FEATURES_FINAL="$KERNEL_FEATURES_FINAL $feature"
262 fi
263 done
264 fi
265
266 if [ "$mode" = "config" ]; then
267 # run1: pull all the configuration fragments, no matter where they come from
268 elements="`echo -n ${bsp_definition} $sccs_defconfig ${sccs} ${patches} $KERNEL_FEATURES_FINAL`"
269 if [ -n "${elements}" ]; then
270 echo "${bsp_definition}" > ${S}/${meta_dir}/bsp_definition
271 scc --force -o ${S}/${meta_dir}:cfg,merge,meta ${includes} $sccs_defconfig $bsp_definition $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
Andrew Geissler82c905d2020-04-13 13:39:40 -0500278 # if KMETA_EXTERNAL_BSPS has been set, or it has been detected from
279 # the bsp definition, then we inject the bsp_definition into the
280 # patch phase below. we'll piggy back on the sccs variable.
281 if [ -n "${KMETA_EXTERNAL_BSPS}" ]; then
282 sccs="${bsp_definition} ${sccs}"
283 fi
284
Andrew Geissler635e0e42020-08-21 15:58:33 -0500285 if [ "$mode" = "patch" ]; then
286 # run2: only generate patches for elements that have been passed on the SRC_URI
287 elements="`echo -n ${sccs} ${patches} $KERNEL_FEATURES_FINAL`"
288 if [ -n "${elements}" ]; then
289 scc --force -o ${S}/${meta_dir}:patch --cmds patch ${includes} ${sccs} ${patches} $KERNEL_FEATURES_FINAL
290 if [ $? -ne 0 ]; then
291 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
292 fi
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500293 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500294 fi
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700295
296 if [ ${KCONF_AUDIT_LEVEL} -gt 0 ]; then
297 bbnote "kernel meta data summary for ${KMACHINE} (${LINUX_KERNEL_TYPE}):"
298 bbnote "======================================================================"
299 if [ -n "${KMETA_EXTERNAL_BSPS}" ]; then
300 bbnote "Non kernel-cache (external) bsp"
301 fi
302 bbnote "BSP entry point / definition: $bsp_definition"
303 if [ -n "$in_tree_defconfig" ]; then
304 bbnote "KBUILD_DEFCONFIG: ${KBUILD_DEFCONFIG}"
305 fi
306 bbnote "Fragments from SRC_URI: $sccs_from_src_uri"
307 bbnote "KERNEL_FEATURES: $KERNEL_FEATURES_FINAL"
308 bbnote "Final scc/cfg list: $sccs_defconfig $bsp_definition $sccs $KERNEL_FEATURES_FINAL"
309 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310}
311
312do_patch() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500313 set +e
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500314 cd ${S}
315
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600316 check_git_config
317 meta_dir=$(kgit --meta)
318 (cd ${meta_dir}; ln -sf patch.queue series)
319 if [ -f "${meta_dir}/series" ]; then
320 kgit-s2q --gen -v --patches .kernel-meta/
321 if [ $? -ne 0 ]; then
322 bberror "Could not apply patches for ${KMACHINE}."
323 bbfatal_log "Patch failures can be resolved in the linux source directory ${S})"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500324 fi
325 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500326
327 if [ -f "${meta_dir}/merge.queue" ]; then
328 # we need to merge all these branches
329 for b in $(cat ${meta_dir}/merge.queue); do
330 git show-ref --verify --quiet refs/heads/${b}
331 if [ $? -eq 0 ]; then
332 bbnote "Merging branch ${b}"
333 git merge -q --no-ff -m "Merge branch ${b}" ${b}
334 else
335 bbfatal "branch ${b} does not exist, cannot merge"
336 fi
337 done
338 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500339}
340
341do_kernel_checkout() {
342 set +e
343
344 source_dir=`echo ${S} | sed 's%/$%%'`
345 source_workdir="${WORKDIR}/git"
346 if [ -d "${WORKDIR}/git/" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500347 # case: git repository
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500348 # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree.
349 if [ "${source_dir}" != "${source_workdir}" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500350 if [ -d "${source_workdir}/.git" ]; then
351 # regular git repository with .git
352 rm -rf ${S}
353 mv ${WORKDIR}/git ${S}
354 else
355 # create source for bare cloned git repository
356 git clone ${WORKDIR}/git ${S}
357 rm -rf ${WORKDIR}/git
358 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500359 fi
360 cd ${S}
361 else
362 # case: we have no git repository at all.
363 # To support low bandwidth options for building the kernel, we'll just
364 # convert the tree to a git repo and let the rest of the process work unchanged
365
366 # if ${S} hasn't been set to the proper subdirectory a default of "linux" is
367 # used, but we can't initialize that empty directory. So check it and throw a
368 # clear error
369
370 cd ${S}
371 if [ ! -f "Makefile" ]; then
372 bberror "S is not set to the linux source directory. Check "
373 bbfatal "the recipe and set S to the proper extracted subdirectory"
374 fi
375 rm -f .gitignore
376 git init
Brad Bishop316dfdd2018-06-25 12:45:53 -0400377 check_git_config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378 git add .
379 git commit -q -m "baseline commit: creating repo for ${PN}-${PV}"
380 git clean -d -f
381 fi
382
383 # convert any remote branches to local tracking ones
384 for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
385 b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
386 git show-ref --quiet --verify -- "refs/heads/$b"
387 if [ $? -ne 0 ]; then
388 git branch $b $i > /dev/null
389 fi
390 done
391
392 # Create a working tree copy of the kernel by checking out a branch
393 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
394
395 # checkout and clobber any unimportant files
396 git checkout -f ${machine_branch}
397}
Andrew Geisslerc926e172021-05-07 16:11:35 -0500398do_kernel_checkout[dirs] = "${S} ${WORKDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500399
Andrew Geissler82c905d2020-04-13 13:39:40 -0500400addtask kernel_checkout before do_kernel_metadata after do_symlink_kernsrc
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500401addtask kernel_metadata after do_validate_branches do_unpack before do_patch
402do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500403do_kernel_metadata[file-checksums] = " ${@get_dirs_with_fragments(d)}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500404do_validate_branches[depends] = "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500405
William A. Kennington III47649fa2018-06-28 12:34:29 -0700406do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}binutils:do_populate_sysroot"
407do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}gcc:do_populate_sysroot"
408do_kernel_configme[depends] += "bc-native:do_populate_sysroot bison-native:do_populate_sysroot"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500409do_kernel_configme[depends] += "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500410do_kernel_configme[dirs] += "${S} ${B}"
411do_kernel_configme() {
Andrew Geissler635e0e42020-08-21 15:58:33 -0500412 do_kernel_metadata config
413
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600414 # translate the kconfig_mode into something that merge_config.sh
415 # understands
416 case ${KCONFIG_MODE} in
417 *allnoconfig)
418 config_flags="-n"
419 ;;
420 *alldefconfig)
421 config_flags=""
422 ;;
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500423 *)
424 if [ -f ${WORKDIR}/defconfig ]; then
425 config_flags="-n"
426 fi
427 ;;
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600428 esac
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500429
430 cd ${S}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600431
432 meta_dir=$(kgit --meta)
433 configs="$(scc --configs -o ${meta_dir})"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500434 if [ $? -ne 0 ]; then
435 bberror "${configs}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600436 bbfatal_log "Could not find configuration queue (${meta_dir}/config.queue)"
437 fi
438
Andrew Geissler82c905d2020-04-13 13:39:40 -0500439 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
440 if [ $? -ne 0 -o ! -f ${B}/.config ]; then
441 bberror "Could not generate a .config for ${KMACHINE}-${LINUX_KERNEL_TYPE}"
442 if [ ${KCONF_AUDIT_LEVEL} -gt 1 ]; then
443 bbfatal_log "`cat ${meta_dir}/cfg/merge_config_build.log`"
444 else
445 bbfatal_log "Details can be found at: ${S}/${meta_dir}/cfg/merge_config_build.log"
446 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500447 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600448
Andrew Geissler82c905d2020-04-13 13:39:40 -0500449 if [ ! -z "${LINUX_VERSION_EXTENSION}" ]; then
450 echo "# Global settings from linux recipe" >> ${B}/.config
451 echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config
452 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500453}
454
455addtask kernel_configme before do_configure after do_patch
Andrew Geissler635e0e42020-08-21 15:58:33 -0500456addtask config_analysis
457
458do_config_analysis[depends] = "virtual/kernel:do_configure"
459do_config_analysis[depends] += "kern-tools-native:do_populate_sysroot"
460
461CONFIG_AUDIT_FILE ?= "${WORKDIR}/config-audit.txt"
462CONFIG_ANALYSIS_FILE ?= "${WORKDIR}/config-analysis.txt"
463
464python do_config_analysis() {
465 import re, string, sys, subprocess
466
467 s = d.getVar('S')
468
469 env = os.environ.copy()
470 env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/")
471 env['LD'] = d.getVar('KERNEL_LD')
472 env['CC'] = d.getVar('KERNEL_CC')
473 env['ARCH'] = d.getVar('ARCH')
474 env['srctree'] = s
475
476 # read specific symbols from the kernel recipe or from local.conf
477 # i.e.: CONFIG_ANALYSIS_pn-linux-yocto-dev = 'NF_CONNTRACK LOCALVERSION'
478 config = d.getVar( 'CONFIG_ANALYSIS' )
479 if not config:
480 config = [ "" ]
481 else:
482 config = config.split()
483
484 for c in config:
485 for action in ["analysis","audit"]:
486 if action == "analysis":
487 try:
488 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--blame', c], cwd=s, env=env ).decode('utf-8')
489 except subprocess.CalledProcessError as e:
490 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
491
492 outfile = d.getVar( 'CONFIG_ANALYSIS_FILE' )
493
494 if action == "audit":
495 try:
496 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--summary', '--extended', '--sanity', c], cwd=s, env=env ).decode('utf-8')
497 except subprocess.CalledProcessError as e:
498 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
499
500 outfile = d.getVar( 'CONFIG_AUDIT_FILE' )
501
502 if c:
503 outdir = os.path.dirname( outfile )
504 outname = os.path.basename( outfile )
505 outfile = outdir + '/'+ c + '-' + outname
506
507 if config and os.path.isfile(outfile):
508 os.remove(outfile)
509
510 with open(outfile, 'w+') as f:
511 f.write( analysis )
512
513 bb.warn( "Configuration {} executed, see: {} for details".format(action,outfile ))
514 if c:
515 bb.warn( analysis )
516}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500517
518python do_kernel_configcheck() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800519 import re, string, sys, subprocess
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500520
521 # if KMETA isn't set globally by a recipe using this routine, we need to
522 # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
523 # meta-series for processing
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500524 kmeta = d.getVar("KMETA") or "meta"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500525 if not os.path.exists(kmeta):
Andrew Geissler635e0e42020-08-21 15:58:33 -0500526 kmeta = subprocess.check_output(['kgit', '--meta'], cwd=d.getVar('S')).decode('utf-8').rstrip()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500527
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800528 s = d.getVar('S')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600529
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800530 env = os.environ.copy()
531 env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/")
Andrew Geissler635e0e42020-08-21 15:58:33 -0500532 env['LD'] = d.getVar('KERNEL_LD')
533 env['CC'] = d.getVar('KERNEL_CC')
534 env['ARCH'] = d.getVar('ARCH')
535 env['srctree'] = s
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600536
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800537 try:
538 configs = subprocess.check_output(['scc', '--configs', '-o', s + '/.kernel-meta'], env=env).decode('utf-8')
539 except subprocess.CalledProcessError as e:
540 bb.fatal( "Cannot gather config fragments for audit: %s" % e.output.decode("utf-8") )
541
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500542 config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0)
543 bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0)
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500544 kmeta_audit_werror = d.getVar("KMETA_AUDIT_WERROR") or ""
545 warnings_detected = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500546
Andrew Geissler635e0e42020-08-21 15:58:33 -0500547 # if config check visibility is "1", that's the lowest level of audit. So
548 # we add the --classify option to the run, since classification will
549 # streamline the output to only report options that could be boot issues,
550 # or are otherwise required for proper operation.
551 extra_params = ""
552 if config_check_visibility == 1:
553 extra_params = "--classify"
554
555 # category #1: mismatches
556 try:
557 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--mismatches', extra_params], cwd=s, env=env ).decode('utf-8')
558 except subprocess.CalledProcessError as e:
559 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
560
561 if analysis:
562 outfile = "{}/{}/cfg/mismatch.txt".format( s, kmeta )
563 if os.path.isfile(outfile):
564 os.remove(outfile)
565 with open(outfile, 'w+') as f:
566 f.write( analysis )
567
568 if config_check_visibility and os.stat(outfile).st_size > 0:
569 with open (outfile, "r") as myfile:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500570 results = myfile.read()
571 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 -0500572 warnings_detected = True
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800573
Andrew Geissler635e0e42020-08-21 15:58:33 -0500574 # category #2: invalid fragment elements
575 extra_params = ""
576 if bsp_check_visibility > 1:
577 extra_params = "--strict"
578 try:
579 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--invalid', extra_params], cwd=s, env=env ).decode('utf-8')
580 except subprocess.CalledProcessError as e:
581 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800582
Andrew Geissler635e0e42020-08-21 15:58:33 -0500583 if analysis:
584 outfile = "{}/{}/cfg/invalid.txt".format(s,kmeta)
585 if os.path.isfile(outfile):
586 os.remove(outfile)
587 with open(outfile, 'w+') as f:
588 f.write( analysis )
589
590 if bsp_check_visibility and os.stat(outfile).st_size > 0:
591 with open (outfile, "r") as myfile:
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500592 results = myfile.read()
593 bb.warn( "[kernel config]: This BSP contains fragments with warnings:\n\n%s" % results)
594 warnings_detected = True
Andrew Geissler635e0e42020-08-21 15:58:33 -0500595
596 # category #3: redefined options (this is pretty verbose and is debug only)
597 try:
598 analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--sanity'], cwd=s, env=env ).decode('utf-8')
599 except subprocess.CalledProcessError as e:
600 bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8'))
601
602 if analysis:
603 outfile = "{}/{}/cfg/redefinition.txt".format(s,kmeta)
604 if os.path.isfile(outfile):
605 os.remove(outfile)
606 with open(outfile, 'w+') as f:
607 f.write( analysis )
608
609 # if the audit level is greater than two, we report if a fragment has overriden
610 # a value from a base fragment. This is really only used for new kernel introduction
611 if bsp_check_visibility > 2 and os.stat(outfile).st_size > 0:
612 with open (outfile, "r") as myfile:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800613 results = myfile.read()
614 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 -0500615 warnings_detected = True
616
617 if warnings_detected and kmeta_audit_werror:
618 bb.fatal( "configuration warnings detected, werror is set, promoting to fatal" )
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500619}
620
621# Ensure that the branches (BSP and meta) are on the locations specified by
622# their SRCREV values. If they are NOT on the right commits, the branches
623# are corrected to the proper commit.
624do_validate_branches() {
625 set +e
626 cd ${S}
627
628 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
629 machine_srcrev="${SRCREV_machine}"
630
631 # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to
632 # check and we can exit early
633 if [ "${machine_srcrev}" = "AUTOINC" ]; then
Andrew Geissler09036742021-06-25 14:25:14 -0500634 linux_yocto_dev='${@oe.utils.conditional("PREFERRED_PROVIDER_virtual/kernel", "linux-yocto-dev", "1", "", d)}'
635 if [ -n "$linux_yocto_dev" ]; then
636 git checkout -q -f ${machine_branch}
637 ver=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
638 patchlevel=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
639 sublevel=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
640 kver="$ver.$patchlevel"
641 bbnote "dev kernel: performing version -> branch -> SRCREV validation"
642 bbnote "dev kernel: recipe version ${LINUX_VERSION}, src version: $kver"
643 echo "${LINUX_VERSION}" | grep -q $kver
644 if [ $? -ne 0 ]; then
645 version="$(echo ${LINUX_VERSION} | sed 's/\+.*$//g')"
646 versioned_branch="v$version/$machine_branch"
647
648 machine_branch=$versioned_branch
649 force_srcrev="$(git rev-parse $machine_branch 2> /dev/null)"
650 if [ $? -ne 0 ]; then
651 bbfatal "kernel version mismatch detected, and no valid branch $machine_branch detected"
652 fi
653
654 bbnote "dev kernel: adjusting branch to $machine_branch, srcrev to: $force_srcrev"
655 fi
656 else
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500657 bbnote "SRCREV validation is not required for AUTOREV"
Andrew Geissler09036742021-06-25 14:25:14 -0500658 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500659 elif [ "${machine_srcrev}" = "" ]; then
660 if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then
661 # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe
662 # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In
663 # this case, we need to reset to the give SRCREV before heading to patching
664 bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}"
665 force_srcrev="${SRCREV}"
666 fi
667 else
668 git cat-file -t ${machine_srcrev} > /dev/null
669 if [ $? -ne 0 ]; then
670 bberror "${machine_srcrev} is not a valid commit ID."
671 bbfatal_log "The kernel source tree may be out of sync"
672 fi
673 force_srcrev=${machine_srcrev}
674 fi
675
676 git checkout -q -f ${machine_branch}
677 if [ -n "${force_srcrev}" ]; then
678 # see if the branch we are about to patch has been properly reset to the defined
679 # SRCREV .. if not, we reset it.
680 branch_head=`git rev-parse HEAD`
681 if [ "${force_srcrev}" != "${branch_head}" ]; then
682 current_branch=`git rev-parse --abbrev-ref HEAD`
683 git branch "$current_branch-orig"
684 git reset --hard ${force_srcrev}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500685 # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check
686 # so the patches are applied as expected otherwise no patching
687 # would be done in some corner cases.
688 kgit-s2q --clean
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500689 fi
690 fi
691}
692
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
694KBUILD_OUTPUT = "${B}"
695
696python () {
697 # If diffconfig is available, ensure it runs after kernel_configme
698 if 'do_diffconfig' in d:
699 bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500700
701 externalsrc = d.getVar('EXTERNALSRC')
702 if externalsrc:
703 # If we deltask do_patch, do_kernel_configme is left without
704 # dependencies and runs too early
705 d.setVarFlag('do_kernel_configme', 'deps', (d.getVarFlag('do_kernel_configme', 'deps', False) or []) + ['do_unpack'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500706}
Andrew Geissler82c905d2020-04-13 13:39:40 -0500707
708# extra tasks
709addtask kernel_version_sanity_check after do_kernel_metadata do_kernel_checkout before do_compile
710addtask validate_branches before do_patch after do_kernel_checkout
711addtask kernel_configcheck after do_configure before do_compile