This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to inject SW. Version into binary file as part of build process

Hi

I would like the Software Version of my application to be updated inside my code and be visible in a designated location in the binary file, i.e in the last 4 bytes.

It should be something like [assembly: AssemblyVersion("2.7.*.*")] in Visual Studio, but in Code Composer.

Should it be a linker comment? or definition in the DATA Segment ?

I would like to open the Binary file on a PC using somthing like fopen function and read the last 4 bytes injected by gmake/ CCS.

Thanks,

Roee

  • There are multiple ways to solve this problem.  I'll show you one I think is straightforward.

    I presume you are building for an ARM Cortex-M3 device, and that you use the new application binary interface (ABI) called EABI.  

    In your C code, you could have something very similar to ...

    #define STR(s)  #s
    #define XSTR(s) STR(s)
    
    #pragma RETAIN(version_info_c_string);
    char version_info_c_string[] =
        "Version Info: " 
        __DATE__ 
        " "
        XSTR(VERSION_INFO_FROM_CMD_LINE);
    

    Lines 1 and 2 are about converting the command line #define symbol VERSION_INFO_FROM_CMD_LINE to a quoted string.  See this FAQ about that.

    Line 4 uses the RETAIN pragma to instruct the tools to not remove this symbol from the application, even though there are no references to it.

    Lines 5-9 form the version string.  Line 6 is a fixed string you use later to find the version information.  Line 7 supplies the date.  Line 8 is the space between the date and the version number.  Line 9 creates a string out of the command line #define symbol VERSION_INFO_FROM_CMD_LINE.  All of the strings on lines 6-9 are automatically concatenated together to form one string.  

    The build command for this file looks like ...

    % armcl -mv7m3 -D VERSION_INFO_FROM_CMD_LINE=1.2.3 <other options> file.c
    

    The version assigned here is 1.2.3.  This can be customized however you like.

    I presume file.obj is combined together with many other object files and libraries to form a final executable image called image.out.  You can see the version string embedded in this image with this Unix command ...

    % strings image.out | fgrep 'Version Info'
    Version Info: Nov 25 2014 1.2.3
    

    The command strings lists out all of the fixed strings it finds in a binary file.  The command fgrep filters that output to show you the string which contains Version Info.

    If you are on a Windows system which does not have those Unix commands, I recommend you install the Cygwin package to get them.

    Thanks and regards,

    -George

  • Hi,

    I'm actually building for TI multicore DSP C6657 and not arm.

    I do work on windows.

    Will this solution work also for this case?

    Thanks

  • Roee Cohen said:
    Will this solution work also for this case?

    Yes.

    Roee Cohen said:
    'm actually building for TI multicore DSP C6657 and not arm.

    Then substitute cl6x for armcl. You still need the -D option.  The -mv option is different.

    Roee Cohen said:
    I do work on windows.

    Then I recommend you install Cygwin to get the strings and fgrep commands.

    Thanks and regards,

    -George