[U-Boot] [RFC PATCH v2 01/15] Implement autoconf header file

Simon Glass sjg at chromium.org
Tue Feb 26 06:22:50 CET 2013


Hi Joe,

On Sun, Feb 24, 2013 at 11:50 AM, Joe Hershberger
<joe.hershberger at gmail.com> wrote:
> Hi Simon,
>
> On Sun, Feb 24, 2013 at 11:25 AM, Simon Glass <sjg at chromium.org> wrote:
>> Add support for generating an autoconf.h header file that can be used in
>> the source instead of #ifdef.
>>
>> For example, instead of:
>>
>>  #ifdef CONFIG_VERSION_VARIABLE
>>         setenv("ver", version_string);  /* set version variable */
>>  #endif
>>
>> you can do:
>>
>>         if (autoconf_version_variable())
>>                 setenv("ver", version_string);  /* set version variable */
>
> You are changing the meaning between these two examples.  The old code
> was #ifDEF, which means the new example needs to be autoconf_HAS_*.
> Is there a reason to muddy the waters by recommending people use this
> automatic value of 0 instead of using the "has" function?  Any more
> than without this patch we should go change most all the #ifdef to
> #if?
>
>> The compiler will ensure that the dead code is eliminated, so the result
>> is the same.
>>
>> Where the value of the CONFIG define is 0, you can use the autoconf_has...()
>> form. For example CONFIG_BOOTDELAY can be -ve, 0 or +ve, but if it is
>> defined at all, it affects behaviour:
>>
>>  #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
>>         s = getenv ("bootdelay");
>>  #endif
>>
>> So we use:
>>
>>         if (autoconf_has_bootdelay() && autoconf_bootdelay() >= 0)
>>                 s = getenv ("bootdelay");
>>
>> This later form should only be used for such 'difficult' defines where a
>> zero value still means that the CONFIG should be considered to be defined.
>>
>> Signed-off-by: Simon Glass <sjg at chromium.org>
>> ---
>> Changes in v2:
>> - Split out changes to main.c into separate patches
>> - Fix up a few errors and comments in the original RFC
>> - Use autoconf_...() instead of config_...()
>> - Use autoconf_has_...() instead of config_..._enabled()
>> - Add a grep to the sed/sort pipe to speed up processing
>>
>>  Makefile                      | 42 ++++++++++++++++++++-
>>  README                        | 87 +++++++++++++++++++++++++++++++++++++++++--
>>  include/common.h              |  3 ++
>>  include/config_drop.h         | 17 +++++++++
>>  tools/scripts/define2conf.sed | 37 ++++++++++++++++++
>>  tools/scripts/define2list.sed | 31 +++++++++++++++
>>  6 files changed, 213 insertions(+), 4 deletions(-)
>>  create mode 100644 include/config_drop.h
>>  create mode 100644 tools/scripts/define2conf.sed
>>  create mode 100644 tools/scripts/define2list.sed
>>
>> diff --git a/Makefile b/Makefile
>> index fc18dd4..9f4f55d 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -614,6 +614,7 @@ updater:
>>  # parallel sub-makes creating .depend files simultaneously.
>>  depend dep:    $(TIMESTAMP_FILE) $(VERSION_FILE) \
>>                 $(obj)include/autoconf.mk \
>> +               $(obj)include/generated/autoconf.h \
>>                 $(obj)include/generated/generic-asm-offsets.h \
>>                 $(obj)include/generated/asm-offsets.h
>>                 for dir in $(SUBDIRS) $(CPUDIR) $(LDSCRIPT_MAKEFILE_DIR) ; do \
>> @@ -688,6 +689,44 @@ $(obj)include/autoconf.mk: $(obj)include/config.h
>>                 sed -n -f tools/scripts/define2mk.sed > $@.tmp && \
>>         mv $@.tmp $@
>>
>> +# Create a C header file where every '#define CONFIG_XXX value' becomes
>> +# '#define config_xxx() value', or '#define config_xxx() 0' where the CONFIG
>> +# is not used by this board configuration. This allows C code to do things
>> +# like 'if (config_xxx())' and have the compiler remove the dead code,
>> +# instead of using '#ifdef CONFIG_XXX...#endif'. Note that in most cases
>> +# if the config_...() returns 0 then the option is not enabled. In some rare
>> +# cases such as CONFIG_BOOTDELAY, the config can be enabled but still have a
>> +# a value of 0. So in addition we a #define config_xxx_enabled(), setting the
>
> You forgot to update this comment when changing to autoconf_has.  Grep perhaps?
>
>> +# value to 0 if the option is disabled, 1 if enabled. This last feature will
>> +# hopefully be deprecated soon.
>> +# The file is regenerated when any U-Boot header file changes.
>> +$(obj)include/generated/autoconf.h: $(obj)include/config.h
>> +       @$(XECHO) Generating $@ ; \
>> +       set -e ; \
>> +       : Extract the config macros to a C header file ; \
>> +       $(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | \
>> +               sed -n -f tools/scripts/define2conf.sed > $@.tmp; \
>> +       : Regenerate our list of all config macros if neeed ; \
>> +       if [ ! -f $@-all.tmp ] || \
>> +               find $(src) -name '*.h' -type f -newer $@-all.tmp | \
>> +                       egrep -qv 'include/(autoconf.h|generated|config.h)'; \
>> +                       then \
>> +               : Extract all config macros from all C header files ; \
>> +               : We can grep for CONFIG since the value will be dropped ; \
>> +               ( \
>> +                       find ${src} -name "*.h" -type f | xargs \
>> +                       cat | grep CONFIG | \
>> +                       sed -n -f tools/scripts/define2list.sed \
>> +               ) | sort | uniq > $@-all.tmp; \
>> +       fi; \
>> +       : Extract the enabled config macros to a C header file ; \
>> +       $(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | \
>> +               sed -n -f tools/scripts/define2list.sed | sort > $@-enabled.tmp; \
>
> From looking at define2list.sed (its name is confusing so sorry if I'm
> interpreting wrong) it lists all things NOT enabled.  But I guess you
> are wanting exact text with which to prune the -all.tmp.  Could you
> craft it such that you can use .tmp directly to prune -all.tmp instead
> of having to generate this -enable.tmp file (which is misleading and
> potentially a waste of sed time)?  Please rename define2list.sed and
> define2conf.sed to something which has meaning.  This is quite hard to
> read as it.

As I mentioned in the previous email, define2list.sed doesn't filter
out enabled configs - it just converts every CONFIG it sees to an
autoconf() defined to 0.

I'm not entirely sure what you are looking for, and in so far as I
understand it I'm not entirely sure how to do it. Let me explain a bit
and then you can tell me where you are coming from.

I create two lists using this define2list.sed script:

- all CONFIGs found in all headers, let's call it A for all
- only the enabled CONFIGs, let's call it E for enabled

Then by using comm, I work out which ones must be disabled D = A - E.
In other words the output of comm is a list of disabled CONFIGs.
Conveniently the sed script defines these to 0.

The other side (defining the things that are enabled, to their actual
values), is handled by define2conf.sed.

Regarding wasting sed's time, how can I avoid running sed on all
CONFIGs and enabled CONFIGs in order to get the disabled CONFIGs? Yes
it is a waste of time calculating E, since it is thrown away, but it
seems to be the only way to calculate D.

Re the rename, I will try define2zero.sed and define2autoconf.sed -
how does that sound?

[snip]

>> diff --git a/include/common.h b/include/common.h
>> index 4ad17ea..491783b 100644
>> --- a/include/common.h
>> +++ b/include/common.h
>> @@ -35,6 +35,9 @@ typedef volatile unsigned short vu_short;
>>  typedef volatile unsigned char vu_char;
>>
>>  #include <config.h>
>> +#ifndef DO_DEPS_ONLY
>> +#include <generated/autoconf.h>
>> +#endif
>>  #include <asm-offsets.h>
>>  #include <linux/bitops.h>
>>  #include <linux/types.h>
>> diff --git a/include/config_drop.h b/include/config_drop.h
>> new file mode 100644
>> index 0000000..bf2beaa
>> --- /dev/null
>> +++ b/include/config_drop.h
>> @@ -0,0 +1,17 @@
>> +/*
>> + * Copyright 2013 Google, Inc
>> + *
>> + * This file is licensed under the terms of the GNU General Public
>> + * License Version 2. This file is licensed "as is" without any
>> + * warranty of any kind, whether express or implied.
>> + */
>> +
>> +#ifndef _CONFIG_DROP_H
>> +#define _CONFIG_DROP_H
>> +
>> +/* Options which don't seem to be referred to anywhere in U-Boot */
>
> You mean not referred to by any config header?

Yes, will fix.

Regards,
Simon


More information about the U-Boot mailing list