[PATCH v3 2/3] kconfig: Add support for conditional values

Simon Glass sjg at chromium.org
Sat Jan 15 16:55:33 CET 2022


+U-Boot Mailing List to update patchwork so 'patman status' works

On Fri, 14 Jan 2022 at 21:52, Rasmus Villemoes
<rasmus.villemoes at prevas.dk> wrote:
>
> (Sorry for formatting, on phone)
>
> At present if an optional Kconfig value needs to be used it must be
> bracketed by #ifdef. For example, with this Kconfig setup:
>
> config WIBBLE
>         bool "Support wibbles, the world needs more wibbles"
>
> config WIBBLE_ADDR
>         hex "Address of the wibble"
>         depends on WIBBLE
>
> then the following code must be used:
>
>  #ifdef CONFIG_WIBBLE
>  static void handle_wibble(void)
>  {
>          int val = CONFIG_WIBBLE_ADDR;
>
>         ...
>  }
>  #endif
>
>  static void init_machine()
>  {
>  ...
>  #ifdef CONFIG_WIBBLE
>         handle_wibble();
>  #endif
>  }
>
> Add a new IF_ENABLED_INT() to help with this. So now it is possible to
> write, without #ifdefs:
>
>  static void handle_wibble(void)
>  {
>         int val = IF_ENABLED_INT(CONFIG_WIBBLE, CONFIG_WIBBLE_ADDR);
>
>         ...
>  }
>
>  static void init_machine()
>  {
>  ...
>  if (IS_ENABLED(CONFIG_WIBBLE))
>         handle_wibble();
>  }
>
> The value will be 0 if CONFIG_WIBBLE is not defined, and
> CONFIG_WIBBLE_ADDR if it is.
>
This is stale, please update.
>
>
> This allows us
> +/* Evaluates to 0 if option is not defined, int_option if it is defined */
>

Stale.
>
> +#define IF_ENABLED_INT(option, int_option) \
> +       config_opt_enabled(option, int_option, invalid_use_of_IF_ENABLED_INT())
> +#endif
> +
>

Should we add a three-arg form of IS_ENABLED so this can also be a
trivial wrapper?
>
>
>  /*
>   * Count number of arguments to a variadic macro. Currently only need
>   * it for 1, 2 or 3 arguments.
> @@ -113,5 +133,17 @@
>  #define CONFIG_IS_ENABLED(option, ...)                                  \
>          __concat(__CONFIG_IS_ENABLED_, __count_args(option, ##__VA_ARGS__)) (option, ##__VA_ARGS__)
>
> +#ifndef __ASSEMBLY__
>

Why prevent use from asm? Sure, if it expands to the function call
that gives a syntax error and not a link error, but it will still
serve its purpose. Of course the declaration of the function must be
guarded, but not the macro definition.
>
>
> Rasmus
>


More information about the U-Boot mailing list