How do I access VERSION file parameters from prj.conf?

Hi, basically I want to expose my firmware's version through the GATT DIS (Device Information Service) to client applications.

I have gone through:

  1. the VERSION file documentation
  2. the peripheral_dis sample

And they were both useful: I have a DIS service up and running but I wish to generate the Firmware Revision String characteristics's value from the VERSION file. The documentation says for use in kconfig files, the following variables are available:

My question is: can I use these in the prj.conf file (since it is a Kconfig fragment), where I already have the configuration options for DIS:

CONFIG_BT_DIS=y
CONFIG_BT_DIS_SETTINGS=y
CONFIG_BT_DIS_STR_MAX=21

CONFIG_BT_DIS_PNP=n
CONFIG_BT_DIS_MODEL="TODO"
CONFIG_BT_DIS_MANUF="TODO"
CONFIG_BT_DIS_SERIAL_NUMBER=y
CONFIG_BT_DIS_FW_REV=y
CONFIG_BT_DIS_HW_REV=y
CONFIG_BT_DIS_SERIAL_NUMBER_STR="TODO"
CONFIG_BT_DIS_FW_REV_STR=$(VERSION_MAJOR).$(VERSION_MINOR)
CONFIG_BT_DIS_HW_REV_STR="TODO"

As per my requirments, I can only provide a major.minor version string but the above causes a build time failure. Can Kconfig variables be used in prj.conf files? If I can somehow use these variables in my prj.conf I can populate my DIS's  firmware string revision characteristic using my VERSION file which would be very convenient.

Parents Reply Children
  • Hi Simon, thanks a lot. I missed the Kconfig file in my project directory completely, or maybe I thought it would be best to not mess with it. In the meantime, I found a workaround by loading the version string at runtime using:

    #include "app_version.h"
    
    /* Runtime settings override. */
    static int settings_runtime_load(void)
    {
    #if defined(CONFIG_BT_DIS_FW_REV)
    	settings_runtime_set("bt/dis/fw", APP_VERSION_STRING , sizeof(APP_VERSION_STRING));
    #endif
    	return 0;
    }
    
    ...
    settings_runtime_load(); /* call later inside main() */
    
    

    But I will definitely be considering the solution you have provided (best to keep configuration stuff like this outside of app code I believe).

    I believe I don't need to do anything involving the macros:  CONFIG_FW_INFO_FIRMWARE_VERSION and CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION for this right?

  • Hi

    Correct! Let me know if any follow-ups come up or if we can close this case now.

    Best of luck and regards,

    Simon

  • one last follow up: does the VERSION file have anything to do with git tags ? What I mean for example is: is it common practice to somehow derive the VERSION file's contents from the latest tag like "v1.0.0" (using a script or a git hook perhaps leveraging git describe)? It would be nice to use git tags to mark stable releases in my repo but if it's too much of a hassle I won't bother.

    Currently, it seems that there is a macro APP_BUILD_VERSION but it does not use anything from the VERSION file and only uses the output from a git describe command. 

Related