[U-Boot] should more use be made of "CONFIG_IS_ENABLED()" macro?
Robert P. J. Day
rpjday at crashcourse.ca
Thu May 19 12:01:52 CEST 2016
two questions.
first, was perusing include/image.h, familiar with snippets like
this:
#define IMAGE_ENABLE_FIT CONFIG_IS_ENABLED(FIT)
#define IMAGE_ENABLE_OF_LIBFDT CONFIG_IS_ENABLED(OF_LIBFDT)
but further down the same file, seems like more content could be
rewritten that way:
#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
# define IMAGE_ENABLE_RAMDISK_HIGH 1
#else
# define IMAGE_ENABLE_RAMDISK_HIGH 0
#endif
#ifdef CONFIG_SYS_BOOT_GET_CMDLINE
# define IMAGE_BOOT_GET_CMDLINE 1
#else
# define IMAGE_BOOT_GET_CMDLINE 0
#endif
... etc etc ...
isn't that amenable to the same rewriting?
and, second, from include/linux/kconfig.h, what is the difference
between IS_ENABLED() and CONFIG_IS_ENABLED():
/*
* IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
* 0 otherwise.
*
*/
#define IS_ENABLED(option) \
(config_enabled(option) || config_enabled(option##_MODULE))
... snip ...
/*
* CONFIG_IS_ENABLED(FOO) evaluates to
* 1 if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y' or 'm',
* 1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y' or 'm',
* 0 otherwise.
*/
#define CONFIG_IS_ENABLED(option) \
(config_enabled(CONFIG_VAL(option)) || \
config_enabled(CONFIG_VAL(option##_MODULE)))
i'm sure if i kept reading, i'd understand the difference, but the
comment above that second #define doesn't seem to clarify it, since it
refers to "CONFIG_SPL_*" while the definition mentions nothing about
SPL. perhaps a more expansive comment would make things clearer in
terms of where to use one rather than the other.
rday
p.s. there is some potentially confusing usage of that macro, like
this within the same source file drivers/core/device.c:
$ grep -r IS_ENABLED drivers/core/device.c
if (CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(DM_SEQ_ALIAS)) {
if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
#if CONFIG_IS_ENABLED(OF_CONTROL)
if (CONFIG_IS_ENABLED(OF_TRANSLATE)) {
if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) {
#if CONFIG_IS_ENABLED(OF_CONTROL)
$
so within the same source file, CONFIG_IS_ENABLED() is being used
for both compile-time *and* run-time testing. um, yuck. IMHO, the
compile-time testing should use the standard test of:
#ifdef CONFIG_OF_CONTROL
for consistency. it just seems messy to be bouncing back and forth
between the two usages.
rday
--
========================================================================
Robert P. J. Day Ottawa, Ontario, CANADA
http://crashcourse.ca
Twitter: http://twitter.com/rpjday
LinkedIn: http://ca.linkedin.com/in/rpjday
========================================================================
More information about the U-Boot
mailing list