preetam
preetam

Reputation: 1587

Providing assignments to variables from makefiles/kconfig

I have an unsigned long which needs to get a platform specific variable.

I do not wish to use boot parameters as this driver will go into products and vendors are reluctant to change boot parameters.

I would like to know if this variable can be initialized from Makefile or from Kconfig.

I remember that the serial port address for early printk is provided in the Kconfig when I used the menuconfig long back to set it. But I never understood how that worked.

Upvotes: 1

Views: 2264

Answers (2)

mahendiran.b
mahendiran.b

Reputation: 1323

Find the C file and Makefile implementation in below to meet your requirements

foo.c

 main ()
    {
        int a = MAKE_DEFINE;
        printf ("MAKE_DEFINE value:%d\n", a);
    }

Makefile

all:
    gcc -DMAKE_DEFINE=11 foo.c

MAKE_DEFINE is a define, which is enabled through Makefile

Upvotes: 1

Santosh A
Santosh A

Reputation: 5351

You can pass that value from Kconfig file in that directory of the program file,
You can set the Kconfig to value of the variable which is needed.
Like for example, in the Kconfig, add below configuration for the variable

config  MY_VALUE_LONG          // config keyword
     hex "MY VALUE IS"         //What you see in the menuconfig
     default 0xAB123           //unsigned long value in hex

In the above Kconfig, MY_VALUE_LONG will hold you long value in the hex format, MY VALUE IS is what that will be displayed when $ make menuconfig is called, and the default value set using the default variable will be passed to the program.

In Program (where the variable value is required), use the config variable CONFIG_MY_VALUE_LONG to obtain the value in hexadecimal

Like for example,

unsigned long value = CONFIG_MY_VALUE_LONG

Upvotes: 2

Related Questions