[U-Boot] [RFC PATCH 2/2] linux/kconfig.h: add C macros useful for per-image config options
Tom Rini
trini at konsulko.com
Mon Jul 27 17:08:44 CEST 2015
On Thu, Jul 23, 2015 at 08:31:56PM +0900, Masahiro Yamada wrote:
> The previous commit introduced a useful macro used in makefiles,
> which references to different variables (CONFIG_ or CONFIG_SPL_
> prefixed), in order to enable/disable features independently
> for each of images.
>
> Per-image config option control is a PITA in C sources, too.
> So, introduce some macros useful in C/CPP expressions.
>
> CONFIG_IS_ENABLED(FOO) is a shorthand for
>
> (!defined(CONFIG_SPL_BUILD) && defined(CONFIG_FOO)) || \
> (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_FOO))
>
> For example, it is useful to describe C code as follows,
>
> #if CONFIG_IS_ENABLED(OF_CONTROL)
> (device tree code)
> #else
> (board file code)
> #endif
>
> The ifdef conditional above is switched by CONFIG_OF_CONTROL during
> the U-Boot proper building (CONFIG_SPL_BUILD is not defined), and by
> CONFIG_SPL_OF_CONTROL during SPL building (CONFIG_SPL_BUILD is
> defined).
>
> The macro can be used in C context as well, so you can also write the
> equivalent code as follows:
>
> if (CONFIG_IS_ENABLED(OF_CONTROL)) {
> (device tree code)
> } else {
> (board file code)
> }
>
> Another useful macro is CONFIG_VALUE().
> CONFIG_VALUE(FOO) is expanded into CONFIG_FOO during the main build,
> and into CONFIG_SPL_FOO during SPL build.
>
> You can write as follows:
>
> text_base = CONFIG_VALUE(TEXT_BASE);
>
> instead of:
>
> #ifdef CONFIG_SPL_BUILD
> text_base = CONFIG_SPL_TEXT_BASE;
> #else
> text_base = CONFIG_TEXT_BASE;
> #endif
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro at socionext.com>
Reviewed-by: Tom Rini <trini at konsulko.com>
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150727/ac716fe5/attachment.sig>
More information about the U-Boot
mailing list