<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 9, 2016 at 12:43 AM, Paul Eggleton <span dir="ltr"><<a href="mailto:paul.eggleton@linux.intel.com" target="_blank">paul.eggleton@linux.intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Some user-space software has specific requirements about the kernel<br>
configuration options selected. This class allows a recipe to explicitly<br>
state the kernel configuration options it needs (through a<br>
REQUIRED_KERNEL_OPTIONS variable). This is a space separated list, where<br>
each item is one of:<br>
(a) an option name (e.g. CONFIG_FHANDLE, in which case CONFIG_FHANDLE<br>
must be set to y or m to match)<br>
(b) optionname=value (e.g. CONFIG_FHANDLE=y, in which case<br>
CONFIG_FHANDLE must be set to y). If the specified value is n,<br>
it will also match if the option is not present.<br>
(c) optionname1|optionname2|... (e.g.<br>
CONFIG_EXT2_FS|CONFIG_EXT4_USE_FOR_EXT23, meaning that either<br>
CONFIG_EXT2_FS or CONFIG_EXT4_USE_FOR_EXT23 must be set to y or<br>
m to match).<br></blockquote><div><br></div><div><br></div><div>This duplicates code that is already in the kconf_check routines, which I've already</div><div>made generic (and added dependency information) for the 2.2 release ... so call</div><div>me confused that I've never heard about this until now :(</div><div><br></div><div>Bruce</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Inheriting the class will also add a dependency from do_configure on<br>
virtual/kernel:do_shared_workdir so that the kernel config is there to<br>
check. If one or more items are not matched, then a warning will be<br>
printed at do_configure time. (This is a warning rather than an error<br>
in case you are using linux-dummy with an externally built kernel).<br>
<br>
A separate function is also provided should you wish to check a config<br>
option from python code - but note you must only call this in a place<br>
where you can guarantee that the kernel config has been written to the<br>
sysroot (i.e. from a task that has virtual/kernel:do_shared_workdir in<br>
its depends varflag value).<br>
<br>
Fixes [YOCTO #5574].<br>
<br>
Signed-off-by: Paul Eggleton <<a href="mailto:paul.eggleton@linux.intel.com">paul.eggleton@linux.intel.com</a>><br>
---<br>
meta/classes/kernel-check.bbclass | 97 +++++++++++++++++++++++++++++++++++++++<br>
1 file changed, 97 insertions(+)<br>
create mode 100644 meta/classes/kernel-check.bbclass<br>
<br>
diff --git a/meta/classes/kernel-check.bbclass b/meta/classes/kernel-check.bbclass<br>
new file mode 100644<br>
index 0000000..d202f4e<br>
--- /dev/null<br>
+++ b/meta/classes/kernel-check.bbclass<br>
@@ -0,0 +1,97 @@<br>
+# Provides a means of checking within a recipe if particular kernel<br>
+# config options are enabled<br>
+#<br>
+# Copyright (C) 2016 Intel Corporation<br>
+#<br>
+# Example usage (within a recipe):<br>
+#<br>
+# inherit kernel-check<br>
+# REQUIRED_KERNEL_OPTIONS = "CONFIG_CGROUPS CONFIG_NAMESPACES"<br>
+#<br>
+# If one or more of the options aren't in the built kernel configuration<br>
+# you will get a warning at do_configure time.<br>
+#<br>
+# You can also use the check_kernel_config_options() function to do<br>
+# explicit checks yourself (and perform a different action).<br>
+<br>
+def check_kernel_config_options(options, d):<br>
+ """<br>
+ A function you can use to do explicit checks for kernel config<br>
+ options from python code<br>
+ """<br>
+<br>
+ if isinstance(options, basestring):<br>
+ required = options.split()<br>
+ else:<br>
+ required = options[:]<br>
+ missing = []<br>
+ diffvalue = []<br>
+ if required:<br>
+ with open(d.expand('${STAGING_KERNEL_BUILDDIR}/.config'), 'r') as f:<br>
+ for line in f:<br>
+ if line.startswith('#'):<br>
+ continue<br>
+ linesplit = line.rstrip().split('=', 1)<br>
+ if len(linesplit) < 2:<br>
+ continue<br>
+ linevalue = linesplit[1]<br>
+ for req in required:<br>
+ found = False<br>
+ if '|' in req:<br>
+ for reqitem in req.split('|'):<br>
+ if reqitem == linesplit[0]:<br>
+ if linevalue in ['y', 'm']:<br>
+ found = True<br>
+ break<br>
+ else:<br>
+ reqsplit = req.split('=', 1)<br>
+ # Can check for CONFIG_OPTION or CONFIG_OPTION=value<br>
+ if len(reqsplit) > 1:<br>
+ reqvalue = reqsplit[1]<br>
+ else:<br>
+ reqvalue = None<br>
+ if reqsplit[0] == linesplit[0]:<br>
+ if reqvalue is None:<br>
+ if linevalue not in ['y', 'm']:<br>
+ diffvalue.append((reqsplit[0], 'y or m', linevalue))<br>
+ elif reqvalue.strip("'\"") != linevalue.strip("'\""):<br>
+ diffvalue.append((reqsplit[0], reqvalue, linevalue))<br>
+ found = True<br>
+<br>
+ if found:<br>
+ required.remove(req)<br>
+ break<br>
+<br>
+ for req in required:<br>
+ reqsplit = req.split('=', 1)<br>
+ if len(reqsplit) > 1:<br>
+ if reqsplit[1] == 'n':<br>
+ continue<br>
+ missing.append('%s=%s' % reqsplit)<br>
+ else:<br>
+ missing.append('%s' % req)<br>
+<br>
+ return missing, diffvalue<br>
+<br>
+<br>
+python check_kernel_config() {<br>
+ pn = d.getVar('PN', True)<br>
+ required = d.getVar('REQUIRED_KERNEL_OPTIONS', True) or ''<br>
+ if ' | ' in required:<br>
+ bb.error('Invalid REQUIRED_KERNEL_OPTIONS value - cannot have spaces around |')<br>
+ if ' = ' in required:<br>
+ bb.error('Invalid REQUIRED_KERNEL_OPTIONS value - cannot have spaces around =')<br>
+ missing, diffvalue = check_kernel_config_options(required, d)<br>
+ if missing or diffvalue:<br>
+ reqstr = '\n '.join(missing + ['%s=%s (actual value %s)' % item for item in diffvalue])<br>
+ # Just warn here for cases like linux-dummy where we don't actually<br>
+ # know the final config<br>
+ bb.warn('The kernel you are building against is missing the following required configuration options:\n %s' % reqstr)<br>
+}<br>
+<br>
+python() {<br>
+ if d.getVar('REQUIRED_KERNEL_OPTIONS', True):<br>
+ d.appendVar('DEPENDS', ' virtual/kernel')<br>
+ d.appendVarFlag('do_configure', 'prefuncs', ' check_kernel_config')<br>
+ d.appendVarFlag('do_configure', 'depends', ' virtual/kernel:do_shared_workdir')<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.5<br>
<br>
--<br>
_______________________________________________<br>
Openembedded-core mailing list<br>
<a href="mailto:Openembedded-core@lists.openembedded.org">Openembedded-core@lists.openembedded.org</a><br>
<a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer" target="_blank">http://lists.openembedded.org/mailman/listinfo/openembedded-core</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">"Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end"</div>
</div></div>