Search code examples
cmakefilepreprocessoru-boot

How to inject variables into u-boot build at build time


I am a u-boot newbie.

I want to be able to make u-boot with a different build option at build time. E.g. I might have a build.sh like this:

source /path/to/target-toolchain

make distclean
make MyHardware_defconfig
make V=1

or even better:

make distclean
make MyHardware_defconfig
make CONFIG_ENABLE_CONSOLE=1 V=1

In MyHardware.c:

#if !defined CONFIG_ENABLE_CONSOLE
  #error CONFIG_ENABLE_CONSOLE not defined!!!!!
#endif

I tried adding CONFIG_ENABLE_CONSOLE=1 to MyHardware_defconfig but when build get error line

I also tried make CONFIG_ENABLE_CONSOLE=1 V=1 but also same as above error.

How can I setup my project so I can build for both console enabled and disabled? Without having to hard code in the u-boot source code.


Solution

  • The uboot makefile has:

    # Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
    KBUILD_CPPFLAGS += $(KCPPFLAGS)
    KBUILD_AFLAGS += $(KAFLAGS)
    KBUILD_CFLAGS += $(KCFLAGS)
    

    So this works from a build script:

    export KCPPFLAGS+=" -DCONFIG_ENABLE_CONSOLE"
    

    then run make

    or :

    make KCPPFLAGS+=" -DCONFIG_ENABLE_CONSOLE"