-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Description
Is your enhancement proposal related to a problem? Please describe.
Currently, when boards have revisions like bl5340_dvk@1.2.0/nrf5340/cpuapp/ns (ref Board Porting Guide), a Kconfig configuration option CONFIG_BOARD_REVISION="1.2.0" is automatically(?) generated by the build system.
The issue with using a string for this is that the C preprocessor cannot perform conditional preprocessing based on strings.
I..e. the following causes a compilation failure.
#include <stdio.h>
#define CONFIG_BOARD_REVISION "1.2.0"
#if CONFIG_BOARD_REVISION == "1.3.0"
#error only version 1.2.0 is supported
#endif
int main()
{
return printf("CONFIG_BOARD_REVISION: %s\n", CONFIG_BOARD_REVISION);
}/tmp/blah.c:5:5: error: invalid token at start of a preprocessor expression
#if CONFIG_BOARD_REVISION == "1.3.0"
^
/tmp/blah.c:3:31: note: expanded from macro 'CONFIG_BOARD_REVISION'
#define CONFIG_BOARD_REVISION "1.2.0"
^
1 error generated.Describe the solution you'd like
Ideally, we would automatically generate a boolean, non-user-configurable, Kconfig option based on the chosen board revision.
Something of the form:
config BOARD_REVISION_1_2_0
def_bool yIt should be a very simple text translation process:
- convert lowercase characters
[a-z]to uppercase[A-Z] - replace characters outside of
[a-zA-Z0-9_]with_ - dynamically generate a file e.g.
BOARD_REVISION_CONFIG_IMPLICITbased onCONFIG_BOARD_REVISIONand merge the file beforeBOARD_REVISION_CONFIGintomerge_config_filesincmake/modules/kconfig.cmake
The BOARD_REVISION_CONFIG_IMPLICIT file should be optional and should only be generated if there is an active board revision.
This would enable us to do far more things in C like
#ifdef CONFIG_BOARD_REVISION_1_2_0
#endif
#if defined(CONFIG_BOARD_REVISION_1_2_0) || defined(CONFIG_BOARD_REVISION_1_3_0)
#endif
void foo(void)
{
if (IS_ENABLED(CONFIG_BOARD_REVISION_1_2_0)) {
} else if (IS_ENABLED(CONFIG_BOARD_REVISION_1_3_0)) {
} else {
__ASSERT(false, "not a valid board configuration");
}
}Describe alternatives you've considered
Currently, the only solution is to create a series of <revision>_defconfig files and manually add these (I believe), or adding these to Kconfig.defconfig.
E.g.
config BOARD_REVISION_1_2_0
bool
default y if "$(BOARD_REVISION)" = "1.2.0"
...
Additional context