Need to get the data in macro when added option in config.in

Hi all,

I have made a package in package folder of openwrt
Also added Config.in file to select the option from menuconfig
I am successfully getting the option value in Makefile
But when I am trying to get the data in my C code as a macro but, I am Unable to get the value in the code

Below I have mentioned that which file contains what data

Config.in

config PWM_ENABLE
bool "PWM enable"
help
This makes PWM enable
default n

endmenu

outer Makefile
ifeq ($(CONFIG_PWM_ENABLE),y)
PMW_ENABLE_VAL := 1
$(info PWM val is $(PMW_ENABLE_VAL))
export PMW_ENABLE_VAL
endif

SRC folder Makefile
PMW_ENABLE_VAL_IN = $(PMW_ENABLE_VAL)
CFLAGS += -DPMW_ENABLE_VAL_IN=$(PMW_ENABLE_VAL_IN)
$(info PMW_ENABLE_VAL_IN $(PMW_ENABLE_VAL_IN))

Need to use PMW_ENABLE_VAL_IN macro in my C code
Please let me know about the same

Developer Team,

We have requirement to enable configuration like CONFIG_PWM_ENABLE which we want to utilize into our application code.

We have tried to include configuration into config.in and also checked into MAKE File of application package code which is working fine but we are not able to utilize same CONFIG_PWM_ENABLE into our application c code.

Can anyone has used like this into any of OPENWRT based application which will be helpful for us to move further?

Regards,
Ritesh Prajapati

@developers ,

Can anyone help here like how to use CONFIG_XXXX into application c code because we have tried multiple ways to use into application c code but didn't get any success yet?

We have already configured into config.in file like below

config PWM_ENABLE
bool "PWM enable"
help
This makes PWM enable
default n

endmenu

And we are targeting to use CONFIG_PWM_ENABLE into application c code but somehow it is not accessible to application c code.

So, Let me know if anyone has created and used CONFIG Macro like we want to use so that it will be helpful for us to move further for application development perspective

Regards,
Ritesh Prajapati

@developers ,

Any update regarding couple of last queries which I have sent as per query which we have?

We are looking for close solution to use into our application or process which is running into OpenWRT build.

Let us know if anyone has any idea or clue for the same which will be helpful for us to move further

Regards,
Ritesh Prajapati

If I'm not mistaken (and understand you correctly) there is no full direct access to kernel config parameters at package configuration stage (make menuconfig).
But there exist some partial preset from generic + each target (e.g. generic).
And these presets are visible as CONFIG_KERLNEL_XXX instead of CONFIG_XXX. Kernel config parameters which are set form the same make menuconfig may be visible too.

@123serge123 ,

Thanks for your prompt response.

Actually our requirement is to use CONFIG_XXXX Macro into application c code instead of any kernel driver.

So, We want to enable MACRO using make menuconfig into openWRT build which should be accessible into Application C Code which is enabled and cross compiled into OpenWRT Build.

Hope now you are clear like what i want to do. Still feel free to ask anything if you have any questions for the same.

So you means CONFIG_XXX as parameter of your package only. Not kernel?
In this case there exist good example - package/utils/busybox package which may be highly customizable. Or package/libs/wolfssl

@123serge123 ,

Yes. Now you understood what we want like we want to check CONFIG_XXX parameter into package only.

FYI, Package is not part of busybox but it is our application package from which process will be created and we are running that process.

We will check both examples which you have provided as example and will let you know if any further query for the same.

But I think my colleague has already verified few other examples and implemented like that way but we are

Regards,
Ritesh Prajapati

Example only.
"Programming by example" is very powerful skill. :slight_smile: And I hope that it help you.

@123serge123 ,

Thanks for your prompt response.

We will check it and let you know if any other help is required for the same

Regards,
Ritesh Prajapati

@dhawal ,

Can you please share details over like we have did into our project? so that it will be helpful for others as well

Regards,
Ritesh

Hi all,

The solution for the thread is as follows,

In outer Makefile

ifeq ($(CONFIG_XXX_NONE),y)
    VALUE := 0
    $(info AES_0 encryption $(VALUE))
    export VALUE
endif

Above changes can be made as per our requirement.

In inner Makefile add the details as mentioned below

AES_VAL = $(VALUE)
CFLAGS += -DAES_VAL=$(AES_VAL)
$(info AES_VAL $(AES_VAL))

While using it in the code declare the macros as mentioned below

#define str(x) 				#x
#define RECEIVED_VAL(FW_VERSION_STR) 	""str(FW_VERSION_STR)""

Use of macro in the code
---> RECEIVED_VAL(AES_VAL)
When the above macros is called then the MACRO value is read and we can receive it as string and we can use it in the C file as mention below
printf("AES VALUS Is : %s\n", RECEIVED_VAL(AES_VAL));

Above is the solution of of getting macro from config.in file

@dhawal , Thanks for providing solution with details.

@Developer,

Is there any chance to utilize direct MACRO into application without using Makefile?

For Example -

  • Define CONFIG_PWM_ENABLE option into config.in with some selection to enable or disable using Kconfig
  • Enable or Disable CONFIG_PWM_ENABLE Macro using make menuconfig
  • Use CONFIG_PWM_ENABLE MACRO into Application code like
 #ifdef CONFIG_PWM_ENABLE
            Do PWM related operations
  #else
           Do Non PWM related operations
  #endif

Let us know if anyone has solution regarding that to use it as per above steps into OpenWRT.

Regards,
Ritesh Prajapati

@Developer,

Any update from anyone as per last query with details which I have shared?

Regards,
Ritesh Prajapati

Hi all,

As we have already given the solution above, but there is one more way to get the option in Macro

Config.in and outer Makefile remains as same as show above.
Just need to modify values in inner Makefile as shown below

VAR += -DPWM=$(PWM)

Get the data directly in the Variable (VAR) and then include it while compilation as shown below

TEST.o: TEST.c
	$(CC) $(VAR ) -c TEST.c

The you can get the value in Macro directly in your C code (TEST.c) and you can use it as given below

 #ifdef PWM
            Do PWM related operations
  #else
           Do Non PWM related operations
  #endif

Now we can get the values directly in the Macros declared in C code.