blob: 5bc627066edbb7de77490d817365bf08520d6f8b [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# remove tasks that modify the source tree in case externalsrc is inherited
Andrew Geissler82c905d2020-04-13 13:39:40 -05002SRCTREECOVEREDTASKS += "do_validate_branches do_kernel_configcheck do_kernel_checkout do_fetch do_unpack do_patch"
Patrick Williamsc0f7c042017-02-23 20:41:17 -06003PATCH_GIT_USER_EMAIL ?= "kernel-yocto@oe"
4PATCH_GIT_USER_NAME ?= "OpenEmbedded"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005
Andrew Geissler82c905d2020-04-13 13:39:40 -05006# The distro or local.conf should set this, but if nobody cares...
7LINUX_KERNEL_TYPE ??= "standard"
8
9# KMETA ?= ""
10KBRANCH ?= "master"
11KMACHINE ?= "${MACHINE}"
12SRCREV_FORMAT ?= "meta_machine"
13
14# LEVELS:
15# 0: no reporting
16# 1: report options that are specified, but not in the final config
17# 2: report options that are not hardware related, but set by a BSP
18KCONF_AUDIT_LEVEL ?= "1"
19KCONF_BSP_AUDIT_LEVEL ?= "0"
20KMETA_AUDIT ?= "yes"
21
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022# returns local (absolute) path names for all valid patches in the
23# src_uri
Brad Bishop19323692019-04-05 15:28:33 -040024def find_patches(d,subdir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025 patches = src_patches(d)
26 patch_list=[]
27 for p in patches:
Brad Bishop19323692019-04-05 15:28:33 -040028 _, _, local, _, _, parm = bb.fetch.decodeurl(p)
29 # if patchdir has been passed, we won't be able to apply it so skip
30 # the patch for now, and special processing happens later
31 patchdir = ''
32 if "patchdir" in parm:
33 patchdir = parm["patchdir"]
34 if subdir:
35 if subdir == patchdir:
36 patch_list.append(local)
37 else:
38 patch_list.append(local)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
40 return patch_list
41
42# returns all the elements from the src uri that are .scc files
43def find_sccs(d):
44 sources=src_patches(d, True)
45 sources_list=[]
46 for s in sources:
47 base, ext = os.path.splitext(os.path.basename(s))
48 if ext and ext in [".scc", ".cfg"]:
49 sources_list.append(s)
Andrew Geissler82c905d2020-04-13 13:39:40 -050050 elif base and 'defconfig' in base:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051 sources_list.append(s)
52
53 return sources_list
54
55# check the SRC_URI for "kmeta" type'd git repositories. Return the name of
56# the repository as it will be found in WORKDIR
57def find_kernel_feature_dirs(d):
58 feature_dirs=[]
59 fetch = bb.fetch2.Fetch([], d)
60 for url in fetch.urls:
61 urldata = fetch.ud[url]
62 parm = urldata.parm
63 type=""
64 if "type" in parm:
65 type = parm["type"]
66 if "destsuffix" in parm:
67 destdir = parm["destsuffix"]
68 if type == "kmeta":
69 feature_dirs.append(destdir)
70
71 return feature_dirs
72
73# find the master/machine source branch. In the same way that the fetcher proceses
74# git repositories in the SRC_URI we take the first repo found, first branch.
75def get_machine_branch(d, default):
76 fetch = bb.fetch2.Fetch([], d)
77 for url in fetch.urls:
78 urldata = fetch.ud[url]
79 parm = urldata.parm
80 if "branch" in parm:
81 branches = urldata.parm.get("branch").split(',')
Patrick Williamsf1e5d692016-03-30 15:21:19 -050082 btype = urldata.parm.get("type")
83 if btype != "kmeta":
84 return branches[0]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085
86 return default
87
88do_kernel_metadata() {
89 set +e
90 cd ${S}
91 export KMETA=${KMETA}
92
93 # if kernel tools are available in-tree, they are preferred
94 # and are placed on the path before any external tools. Unless
95 # the external tools flag is set, in that case we do nothing.
96 if [ -f "${S}/scripts/util/configme" ]; then
97 if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then
98 PATH=${S}/scripts/util:${PATH}
99 fi
100 fi
101
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102 # In a similar manner to the kernel itself:
103 #
104 # defconfig: $(obj)/conf
105 # ifeq ($(KBUILD_DEFCONFIG),)
106 # $< --defconfig $(Kconfig)
107 # else
108 # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
109 # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
110 # endif
111 #
112 # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it
113 # from the source tree, into a common location and normalized "defconfig" name,
114 # where the rest of the process will include and incoroporate it into the build
115 #
116 # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI),
117 # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take
118 # precendence.
119 #
120 if [ -n "${KBUILD_DEFCONFIG}" ]; then
121 if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then
122 if [ -f "${WORKDIR}/defconfig" ]; then
123 # If the two defconfig's are different, warn that we didn't overwrite the
124 # one already placed in WORKDIR by the fetcher.
125 cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}"
126 if [ $? -ne 0 ]; then
127 bbwarn "defconfig detected in WORKDIR. ${KBUILD_DEFCONFIG} skipped"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500128 else
129 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 fi
131 else
132 cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500133 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500134 sccs="${WORKDIR}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135 else
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500136 bbfatal "A KBUILD_DEFCONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137 fi
138 fi
139
Brad Bishop19323692019-04-05 15:28:33 -0400140 # was anyone trying to patch the kernel meta data ?, we need to do
141 # this here, since the scc commands migrate the .cfg fragments to the
142 # kernel source tree, where they'll be used later.
143 check_git_config
144 patches="${@" ".join(find_patches(d,'kernel-meta'))}"
145 for p in $patches; do
146 (
147 cd ${WORKDIR}/kernel-meta
148 git am -s $p
149 )
150 done
151
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500152 sccs_from_src_uri="${@" ".join(find_sccs(d))}"
Brad Bishop19323692019-04-05 15:28:33 -0400153 patches="${@" ".join(find_patches(d,''))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}"
155
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500156 # a quick check to make sure we don't have duplicate defconfigs
157 # If there's a defconfig in the SRC_URI, did we also have one from
158 # the KBUILD_DEFCONFIG processing above ?
159 if [ -n "$sccs" ]; then
160 # we did have a defconfig from above. remove any that might be in the src_uri
161 sccs_from_src_uri=$(echo $sccs_from_src_uri | awk '{ if ($0!="defconfig") { print $0 } }' RS=' ')
162 fi
163 sccs="$sccs $sccs_from_src_uri"
164
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165 # check for feature directories/repos/branches that were part of the
166 # SRC_URI. If they were supplied, we convert them into include directives
167 # for the update part of the process
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600168 for f in ${feat_dirs}; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500169 if [ -d "${WORKDIR}/$f/meta" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600170 includes="$includes -I${WORKDIR}/$f/kernel-meta"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800171 elif [ -d "${WORKDIR}/../oe-local-files/$f" ]; then
172 includes="$includes -I${WORKDIR}/../oe-local-files/$f"
Brad Bishop19323692019-04-05 15:28:33 -0400173 elif [ -d "${WORKDIR}/$f" ]; then
174 includes="$includes -I${WORKDIR}/$f"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600176 done
177 for s in ${sccs} ${patches}; do
178 sdir=$(dirname $s)
179 includes="$includes -I${sdir}"
180 # if a SRC_URI passed patch or .scc has a subdir of "kernel-meta",
181 # then we add it to the search path
182 if [ -d "${sdir}/kernel-meta" ]; then
183 includes="$includes -I${sdir}/kernel-meta"
184 fi
185 done
186
187 # expand kernel features into their full path equivalents
188 bsp_definition=$(spp ${includes} --find -DKMACHINE=${KMACHINE} -DKTYPE=${LINUX_KERNEL_TYPE})
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500189 if [ -z "$bsp_definition" ]; then
190 echo "$sccs" | grep -q defconfig
191 if [ $? -ne 0 ]; then
192 bbfatal_log "Could not locate BSP definition for ${KMACHINE}/${LINUX_KERNEL_TYPE} and no defconfig was provided"
193 fi
Andrew Geissler82c905d2020-04-13 13:39:40 -0500194
195 # if the bsp definition has "define KMETA_EXTERNAL_BSP t",
196 # then we need to set a flag that will instruct the next
197 # steps to use the BSP as both configuration and patches.
198 grep -q KMETA_EXTERNAL_BSP $bsp_definition
199 if [ $? -eq 0 ]; then
200 KMETA_EXTERNAL_BSPS="t"
201 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500202 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600203 meta_dir=$(kgit --meta)
204
205 # run1: pull all the configuration fragments, no matter where they come from
206 elements="`echo -n ${bsp_definition} ${sccs} ${patches} ${KERNEL_FEATURES}`"
207 if [ -n "${elements}" ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500208 echo "${bsp_definition}" > ${S}/${meta_dir}/bsp_definition
209 scc --force -o ${S}/${meta_dir}:cfg,merge,meta ${includes} ${bsp_definition} ${sccs} ${patches} ${KERNEL_FEATURES}
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500210 if [ $? -ne 0 ]; then
211 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
212 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500213 fi
214
Andrew Geissler82c905d2020-04-13 13:39:40 -0500215 # if KMETA_EXTERNAL_BSPS has been set, or it has been detected from
216 # the bsp definition, then we inject the bsp_definition into the
217 # patch phase below. we'll piggy back on the sccs variable.
218 if [ -n "${KMETA_EXTERNAL_BSPS}" ]; then
219 sccs="${bsp_definition} ${sccs}"
220 fi
221
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600222 # run2: only generate patches for elements that have been passed on the SRC_URI
223 elements="`echo -n ${sccs} ${patches} ${KERNEL_FEATURES}`"
224 if [ -n "${elements}" ]; then
225 scc --force -o ${S}/${meta_dir}:patch --cmds patch ${includes} ${sccs} ${patches} ${KERNEL_FEATURES}
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500226 if [ $? -ne 0 ]; then
227 bbfatal_log "Could not generate configuration queue for ${KMACHINE}."
228 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500229 fi
230}
231
232do_patch() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500233 set +e
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234 cd ${S}
235
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600236 check_git_config
237 meta_dir=$(kgit --meta)
238 (cd ${meta_dir}; ln -sf patch.queue series)
239 if [ -f "${meta_dir}/series" ]; then
240 kgit-s2q --gen -v --patches .kernel-meta/
241 if [ $? -ne 0 ]; then
242 bberror "Could not apply patches for ${KMACHINE}."
243 bbfatal_log "Patch failures can be resolved in the linux source directory ${S})"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 fi
245 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500246
247 if [ -f "${meta_dir}/merge.queue" ]; then
248 # we need to merge all these branches
249 for b in $(cat ${meta_dir}/merge.queue); do
250 git show-ref --verify --quiet refs/heads/${b}
251 if [ $? -eq 0 ]; then
252 bbnote "Merging branch ${b}"
253 git merge -q --no-ff -m "Merge branch ${b}" ${b}
254 else
255 bbfatal "branch ${b} does not exist, cannot merge"
256 fi
257 done
258 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500259}
260
261do_kernel_checkout() {
262 set +e
263
264 source_dir=`echo ${S} | sed 's%/$%%'`
265 source_workdir="${WORKDIR}/git"
266 if [ -d "${WORKDIR}/git/" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500267 # case: git repository
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500268 # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree.
269 if [ "${source_dir}" != "${source_workdir}" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500270 if [ -d "${source_workdir}/.git" ]; then
271 # regular git repository with .git
272 rm -rf ${S}
273 mv ${WORKDIR}/git ${S}
274 else
275 # create source for bare cloned git repository
276 git clone ${WORKDIR}/git ${S}
277 rm -rf ${WORKDIR}/git
278 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500279 fi
280 cd ${S}
281 else
282 # case: we have no git repository at all.
283 # To support low bandwidth options for building the kernel, we'll just
284 # convert the tree to a git repo and let the rest of the process work unchanged
285
286 # if ${S} hasn't been set to the proper subdirectory a default of "linux" is
287 # used, but we can't initialize that empty directory. So check it and throw a
288 # clear error
289
290 cd ${S}
291 if [ ! -f "Makefile" ]; then
292 bberror "S is not set to the linux source directory. Check "
293 bbfatal "the recipe and set S to the proper extracted subdirectory"
294 fi
295 rm -f .gitignore
296 git init
Brad Bishop316dfdd2018-06-25 12:45:53 -0400297 check_git_config
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298 git add .
299 git commit -q -m "baseline commit: creating repo for ${PN}-${PV}"
300 git clean -d -f
301 fi
302
303 # convert any remote branches to local tracking ones
304 for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
305 b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
306 git show-ref --quiet --verify -- "refs/heads/$b"
307 if [ $? -ne 0 ]; then
308 git branch $b $i > /dev/null
309 fi
310 done
311
312 # Create a working tree copy of the kernel by checking out a branch
313 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
314
315 # checkout and clobber any unimportant files
316 git checkout -f ${machine_branch}
317}
318do_kernel_checkout[dirs] = "${S}"
319
Andrew Geissler82c905d2020-04-13 13:39:40 -0500320addtask kernel_checkout before do_kernel_metadata after do_symlink_kernsrc
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500321addtask kernel_metadata after do_validate_branches do_unpack before do_patch
322do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500323do_validate_branches[depends] = "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500324
William A. Kennington III47649fa2018-06-28 12:34:29 -0700325do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}binutils:do_populate_sysroot"
326do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}gcc:do_populate_sysroot"
327do_kernel_configme[depends] += "bc-native:do_populate_sysroot bison-native:do_populate_sysroot"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500328do_kernel_configme[depends] += "kern-tools-native:do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500329do_kernel_configme[dirs] += "${S} ${B}"
330do_kernel_configme() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600331 # translate the kconfig_mode into something that merge_config.sh
332 # understands
333 case ${KCONFIG_MODE} in
334 *allnoconfig)
335 config_flags="-n"
336 ;;
337 *alldefconfig)
338 config_flags=""
339 ;;
340 *)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500341 if [ -f ${WORKDIR}/defconfig ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600342 config_flags="-n"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500343 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600344 ;;
345 esac
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500346
347 cd ${S}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600348
349 meta_dir=$(kgit --meta)
350 configs="$(scc --configs -o ${meta_dir})"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500351 if [ $? -ne 0 ]; then
352 bberror "${configs}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600353 bbfatal_log "Could not find configuration queue (${meta_dir}/config.queue)"
354 fi
355
Andrew Geissler82c905d2020-04-13 13:39:40 -0500356 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
357 if [ $? -ne 0 -o ! -f ${B}/.config ]; then
358 bberror "Could not generate a .config for ${KMACHINE}-${LINUX_KERNEL_TYPE}"
359 if [ ${KCONF_AUDIT_LEVEL} -gt 1 ]; then
360 bbfatal_log "`cat ${meta_dir}/cfg/merge_config_build.log`"
361 else
362 bbfatal_log "Details can be found at: ${S}/${meta_dir}/cfg/merge_config_build.log"
363 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500364 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600365
Andrew Geissler82c905d2020-04-13 13:39:40 -0500366 if [ ! -z "${LINUX_VERSION_EXTENSION}" ]; then
367 echo "# Global settings from linux recipe" >> ${B}/.config
368 echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config
369 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500370}
371
372addtask kernel_configme before do_configure after do_patch
373
374python do_kernel_configcheck() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800375 import re, string, sys, subprocess
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500376
377 # if KMETA isn't set globally by a recipe using this routine, we need to
378 # set the default to 'meta'. Otherwise, kconf_check is not passed a valid
379 # meta-series for processing
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500380 kmeta = d.getVar("KMETA") or "meta"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500381 if not os.path.exists(kmeta):
382 kmeta = "." + kmeta
383
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800384 s = d.getVar('S')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600385
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800386 env = os.environ.copy()
387 env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/")
Andrew Geissler82c905d2020-04-13 13:39:40 -0500388 env['LD'] = "${KERNEL_LD}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600389
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800390 try:
391 configs = subprocess.check_output(['scc', '--configs', '-o', s + '/.kernel-meta'], env=env).decode('utf-8')
392 except subprocess.CalledProcessError as e:
393 bb.fatal( "Cannot gather config fragments for audit: %s" % e.output.decode("utf-8") )
394
395 try:
396 subprocess.check_call(['kconf_check', '--report', '-o',
397 '%s/%s/cfg' % (s, kmeta), d.getVar('B') + '/.config', s, configs], cwd=s, env=env)
398 except subprocess.CalledProcessError:
399 # The configuration gathering can return different exit codes, but
400 # we interpret them based on the KCONF_AUDIT_LEVEL variable, so we catch
401 # everything here, and let the run continue.
402 pass
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500403
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500404 config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0)
405 bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500406
407 # if config check visibility is non-zero, report dropped configuration values
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600408 mismatch_file = d.expand("${S}/%s/cfg/mismatch.txt" % kmeta)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409 if os.path.exists(mismatch_file):
410 if config_check_visibility:
411 with open (mismatch_file, "r") as myfile:
412 results = myfile.read()
413 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 -0800414
415 if bsp_check_visibility:
416 invalid_file = d.expand("${S}/%s/cfg/invalid.cfg" % kmeta)
417 if os.path.exists(invalid_file) and os.stat(invalid_file).st_size > 0:
418 with open (invalid_file, "r") as myfile:
419 results = myfile.read()
420 bb.warn( "[kernel config]: This BSP sets config options that are not offered anywhere within this kernel:\n\n%s" % results)
421 errors_file = d.expand("${S}/%s/cfg/fragment_errors.txt" % kmeta)
422 if os.path.exists(errors_file) and os.stat(errors_file).st_size > 0:
423 with open (errors_file, "r") as myfile:
424 results = myfile.read()
425 bb.warn( "[kernel config]: This BSP contains fragments with errors:\n\n%s" % results)
426
427 # if the audit level is greater than two, we report if a fragment has overriden
428 # a value from a base fragment. This is really only used for new kernel introduction
429 if bsp_check_visibility > 2:
430 redefinition_file = d.expand("${S}/%s/cfg/redefinition.txt" % kmeta)
431 if os.path.exists(redefinition_file) and os.stat(redefinition_file).st_size > 0:
432 with open (redefinition_file, "r") as myfile:
433 results = myfile.read()
434 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 -0500435}
436
437# Ensure that the branches (BSP and meta) are on the locations specified by
438# their SRCREV values. If they are NOT on the right commits, the branches
439# are corrected to the proper commit.
440do_validate_branches() {
441 set +e
442 cd ${S}
443
444 machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
445 machine_srcrev="${SRCREV_machine}"
446
447 # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to
448 # check and we can exit early
449 if [ "${machine_srcrev}" = "AUTOINC" ]; then
450 bbnote "SRCREV validation is not required for AUTOREV"
451 elif [ "${machine_srcrev}" = "" ]; then
452 if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then
453 # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe
454 # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In
455 # this case, we need to reset to the give SRCREV before heading to patching
456 bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}"
457 force_srcrev="${SRCREV}"
458 fi
459 else
460 git cat-file -t ${machine_srcrev} > /dev/null
461 if [ $? -ne 0 ]; then
462 bberror "${machine_srcrev} is not a valid commit ID."
463 bbfatal_log "The kernel source tree may be out of sync"
464 fi
465 force_srcrev=${machine_srcrev}
466 fi
467
468 git checkout -q -f ${machine_branch}
469 if [ -n "${force_srcrev}" ]; then
470 # see if the branch we are about to patch has been properly reset to the defined
471 # SRCREV .. if not, we reset it.
472 branch_head=`git rev-parse HEAD`
473 if [ "${force_srcrev}" != "${branch_head}" ]; then
474 current_branch=`git rev-parse --abbrev-ref HEAD`
475 git branch "$current_branch-orig"
476 git reset --hard ${force_srcrev}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500477 # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check
478 # so the patches are applied as expected otherwise no patching
479 # would be done in some corner cases.
480 kgit-s2q --clean
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500481 fi
482 fi
483}
484
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500485OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
486KBUILD_OUTPUT = "${B}"
487
488python () {
489 # If diffconfig is available, ensure it runs after kernel_configme
490 if 'do_diffconfig' in d:
491 bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500492
493 externalsrc = d.getVar('EXTERNALSRC')
494 if externalsrc:
495 # If we deltask do_patch, do_kernel_configme is left without
496 # dependencies and runs too early
497 d.setVarFlag('do_kernel_configme', 'deps', (d.getVarFlag('do_kernel_configme', 'deps', False) or []) + ['do_unpack'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500498}
Andrew Geissler82c905d2020-04-13 13:39:40 -0500499
500# extra tasks
501addtask kernel_version_sanity_check after do_kernel_metadata do_kernel_checkout before do_compile
502addtask validate_branches before do_patch after do_kernel_checkout
503addtask kernel_configcheck after do_configure before do_compile