mapping kernel config variables to modules - linux

In general, how do I know what set of kernel config options are necessary to have some .ko file built?
For example, I need 'xt_conntrack.ko'. What resources are there that let me know whether or not enabling CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m in my kernel config is necessary or even sufficient to result in my built .ko file? How do I find the full set of kconfig options required to yield a kernel module?
http://cateee.net/lkddb/web-lkddb/NETFILTER_XT_MATCH_CONNTRACK.html indicates it will build "xt_conntrack", but I am not seeing it when I =m it and all of its dependencies.
On the other side, there is no set of kconfig flags visible here (http://modules.libres.ch/browse/linux/v3.0/x86_64/xt_conntrack/)

How do I find the full set of kconfig options required to yield a kernel module?
In general, determining set of options for building a kernel module is complex process. Steps described below may guide in that process.
1. Find a Makefile
Find a Makefile which builds a kernel module. This file is located in the same directory, where .ko file is produced; this directory usually coincides with a directory of module's source files. This Makefile contains a line which builds a module:
obj-${CONFIG_...} := <module_name>.o
Example:
A module xt_conntrack.ko is built by the line
obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o
in file net/netfilter/Makefile.
2. Determine final option
There are several ways how configuration options may affect on building a module.
The option is used directly in the line, produced the module:
obj-${CONFIG_X} := <module_name>.o
means that option CONFIG_X should be set for the module to be built.
Given Makefile is conditionally included into the upper one:
obj-${CONFIG_Y} := <dir>/
The line produced the module is guarded by "if" clause:
ifeq ($(CONFIG_F),y)
obj-m := <module_name>.o
endif
Alternatively, guard may protect inclusion of the Makefile from the upper one:
ifeq ($(CONFIG_F),y)
obj-m := <dir>/
endif
Example:
A module xt_conntrack depends by rule 1 from CONFIG_NETFILTER_XT_MATCH_CONNTRACK option.
Also it depends by rule 2 from CONFIG_NETFILTER option, because outer net/Makefile includes net/netfilter/Makefile via
obj-$(CONFIG_NETFILTER) += netfilter/
3. Find definition of the option and determine its availability
Note: This is the most complicated step, mainly because availability of the option is expressed in terms of other options. It is recommended to use ready-made tools for that. E.g., make menuconfig tool may search options and show their definition.
Every configuration option is defined in one of Kconfig files.
Definition determines:
availability of the option (when the option can be used),
possible values of the option (y/n - boolean, y/m/n - tristate, etc.),
whether the option can be set by a user.
Example:
Option NETFILTER_XT_MATCH_CONNTRACK is defined in net/netfilter/Kconfig as
config NETFILTER_XT_MATCH_CONNTRACK
tristate '"conntrack" connection tracking match support'
depends on NF_CONNTRACK
default m if NETFILTER_ADVANCED=n
help
This is a general conntrack match module, a superset of the state match.
It allows matching on additional conntrack information, which is
useful in complex configurations, such as NAT gateways with multiple
internet links or tunnels.
To compile it as a module, choose M here. If unsure, say N.
That is, the option is available (can be set) only when NF_CONNTRACK option is set.
Documentation for format of Kconfig files is located at Documentation/kbuild/kconfig-language.txt.

Related

Yocto Dunfell how to set Compiler Flags to '-Os' Globally

I have a working Linux system image being produced for my ARM board with Yocto ( Dunfell branch ).
Space occupied by the rootfs is a premium and I am working on shrinking the image.
I want to experiment with the GCC '-Os' flag, to optimize for space. I would like to set this globally for my experiment. I found the following information in a presentation ( https://pretalx.com/yocto-project-summit-2020/talk/AY37HF/ ):
I added the following to my image_0.1.bb file. However, I do not see the '-Os' optimization flag being used in any package.
# Disabled until the option works properly -feliminate-dwarf2-dups
FULL_OPTIMIZATION = "-Os -pipe ${DEBUG_FLAGS}"
DEBUG_OPTIMIZATION = "-Og ${DEBUG_FLAGS} -pipe"
SELECTED_OPTIMIZATION = "${#d.getVar(oe.utils.vartrue('DEBUG_BUILD', 'DEBUG_OPTIMIZATION', 'FULL_OPTIMIZATION', d))}"
Is the code correct and, if so, where should I put this code? If not correct, how can I globally add the '-Os' compiler optimization flag to my project?
Global options must be added to one of the global configuration files.
For testing things this would typically be conf/local.conf.
You only need to add the variables you actually change as bitbake uses lazy evaluation of variables values.
Variables in recipe files only affect the tasks for that recipe. This means that nothing you do in the image recipe can affect how tasks in other recipes are done.

linux kernel make tag variable

Linux kernel source can use make tags to get the tag for editor.
In scripts/tags.sh, line7 and line8 say that "Uses the following environment variables: ARCH, SUBARCH, SRCARCH, srctree, src, obj"
I want to ask What are these variable meaning?
I already read this article,but it just mention the two vairables, SRCARCH and SUBARCH.
Variables you should use
Next variables can be passed to tags.sh (actually you should pass them to make tags cscope command, and Makefile will pass them to tags.sh for you).
ARCH: which architecture to index. You can see all architectures list just by doing ls -l arch/ in your kernel source tree.
SUBARCH: the meaning of this variable depends on your architecture:
if ARCH=arm, SUBARCH will be used to determine arch/arm/mach-* and arch/arm/plat-* directories, and these directories will be indexed
if ARCH=um, use SUBARCH to specify which architecture you actually want to use in your User-Mode Linux (like SUBARCH=arm or SUBARCH=x86)
for the rest of architectures, you can omit this variable
ALLSOURCE_ARCHS: use this to index more than one architecture. Like ALLSOURCE_ARCHS="x86 mips arm" or ALLSOURCE_ARCHS="all". If you only want to index one architecture, omit this variable and use ARCH instead.
COMPILED_SOURCE: set this variable to 1 if you want to index only actually compiled source files. If you want to index all source files, omit setting this variable.
O= (this is actually Makefile parameter): use absolute paths (useful if you want to load created cscope/ctags index files outside of kernel directory, e.g. for development of out-of-tree kernel modules). If you want to use relative paths (i.e. you're gonna do development only in kernel dir), just omit that parameter.
Variables you don't need to touch
SRCARCH: being set from ARCH variable in Makefile and then passed to script. You probably don't need to mess with it, just set ARCH variable correctly
srctree: kernel source tree path. This variable will be passed from Makefile automatically if you're using this script via make cscope tags.
src and obj variables: those are not used by scripts/tags.sh anymore. It was replaced by utilizing KBUILD_SRC variable, which is provided from Makefile automatically, when you provide O=... parameter to it.
Usage
Basically, I'd recommend to only use scripts/tags.sh via make invocation. Example:
$ make O=. ARCH=arm SUBARCH=omap2 COMPILED_SOURCE=1 cscope tags
or
$ make ARCH=x86 cscope tags

in a makefile, declaring a phony target as a wildcard

I want to declare my wildcard target as phony, but phony doesn't support wildcards:
My makefile:
%.config:
gcc <<compile>>
I want the user to be able to use my makefile to compile the project, using a specific configuration file:
make something.config
make something_else.config
obviously, I need my target to be phony, becuase the target files exist, but simply writing:
.PHONY: %.config
doesn't work.
I've seen here that makeapp supports another syntax, that would help:
$(phony %.config): ...
but I can only use make, and not makeapp.
Is there any way to do it with make?
These are conflicting aims. A phony target is one that doesn't correspond to a real file. In your case, the file exists, but it's not really a target.
I would suggest not using the name of the config file as the target. Instead, construct a system based on one of the following:
make something_else
make CONFIG=something_else.config

How do I ignore a system file picked up by `configure' generated from AC_CHECK_HEADERS

We using an automated build system which downloads and compiles source. The only interface I have to control the behaviour of the compilation is by setting ENV VARs and the arguments given to `./configure'.
The issue is that the 'configure' script (of the particular source I'm compiling) checks for a system header file, which if found, adversely affects the compilation process. (the compilation process will avoid compiling libraries which it believes are already installed on the local system when the above mentioned system header file is found.)
Since this is an automated process, I cannot modify the 'configure' script in anyway, and as mentioned can only specify the environment variables and arguments passed to `configure'. The configure script uses the AC_CHECK_HEADERS macro to generate the code to do the check for the system file. Is there anyway to avoid a check of a specific system file from the configure arguments?
The troublesome header file is in the path /usr/include/pcap/.
Thanks
Well there's a few things you could try:
remove foo.h from AC_CHECK_HEADERS and always build the library
use AC_CHECK_HEADER for foo.h and check for /usr/include/pcap/foo.h and don't AC_DEFINE(HAVE_FOO_H) if /usr/include/pcap/foo.h is there.
you could use AC_ARG_ENABLE or AC_ARG_WITH to turn off the offending test on a host-by-host basis via arguments to configure. So the answer to that question is yes.
All of these assume you can modify configure.ac and regenerate configure. If you can't do that you might have to modify configure (in an automated fashion, of course).

Platform builder and compiling options and flags

I'm new to platform builder, this might be obvious..
I'm working on wince6.0.
I've looked everywhere, didn't find how to add flags to the compilation of the image.
I've noticed there are many flags which are specific to ARM:
http://207.46.16.248/en-us/library/ee479941%28WinEmbedded.60%29.aspx
/QRArch
/QRimplicit-import-
/QRinterwork-return
/QRxscale
/QRxscalesched
/QRthumb
How do I add them to the build and which ones take parameters (and what are they)?
Are there any general flags too? what are they?
Thank you
Apparently, you need to do two things:
Go to project properties
Add environment variable named "cl" with value such as the following or a subset of them:
/QRArch
/QRimplicit-import-
/QRinterwork-return
/QRxscale
/QRxscalesched
/QRthumb
Afterwards, you edit the sources.cmn located in the BSP folder, adding:
CDEFINES=$(CDEFINES) <the flags you picked above>
For example if I wanted to use /QRArch4 and /QRimplicit-import-
The cl variable value would be /QRArch4 /QRimplicit-import-
and the line added to the sources is:
CDEFINES=$(CDEFINES) /QRArch4 /QRimplicit-import-

Resources