SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32

Auto generate build/version number

Does anyone know of a way to auto generate an incrementing firmware build or version number in System Workbench?


You may, for example, create a file named makefile.targets at the root of your project, with the following content:
all: ../build_number.h

		if [ ! -r ../build.number ]; then \
			echo build_number=1 > ../build.number; \

		source ../build.number; \
		echo "build_number=$$((build_number + 1))" > ../build.number

.PHONY: bump.build.number
post-build: bump.build.number

../build_number.h: ../build.number
		source ../build.number; \
		echo "#define BUILD_NUMBER $$build_number" > $@
Be careful: the backslashes at the end of some lines must really be the last character of the line, with no spaces after, or this will not work (you can also put everything on one line but it’s far less readable).

Then include build_number.h in the file in which you need the build number; this file will define a macro named BUILD_NUMBER which will be bumped at each successful build.

Beware that each time you will launch a build, even if nothing else has changed, the program will be updated as th ebuild number has changed... Only bumping the build number when something has effectively changed (and not for each successful build) will need quite a few more logic...

Also you may have to slightly edit this makefile fragment if you want the generated files elsewhere in your project (although makefile.targets must stay at the root of the project).

Note also that this will only work if you use the external builder (make), not the internal one.This is one of the advantages of the external builder.

Bernard (Ac6)


I can’t make it to work with my project.
After I have the project built the console log shows:

source ../build.number; \
echo “#define BUILD_NUMBER $build_number” > ../build_number.h
/bin/sh: 1: source: not found

However, I see 2 new files - build.number and build_number.h
build.number contains: build_number=1
build_number.h contains: #define BUILD_NUMBER (with no build.number value)

Will you please help me to resolve the issue?
I use AC6 sw-stm32.


I am answering myself because I found a solution.
On Windows dautrevaux’s code works flawlessly.
On Linux you have to swap “source” with “.”.

source ../build.number; \ -----> . ../build.number; \


I know it is very old topic, but I would like to make it works in my project, could be very usefull. The problem is my knoledge about makefiles is zero :-)

I import this script and it works ony first time, create files build.number and build.number.h, but every next build those files stay the smae, I am using STM32CubeIDE, latest version.

Could you please help me?

Best regards.

Thanks, I will give this a try.

One other question - what do I need to do if I want to reset the build number?

So does the build number just get stored in the .h file, so it could be edited there?

I tried adding this to my project. Initially there was an issue because the editor converted the tabs to spaces. I fixed that and have copied your sample code verbatim, but I am getting an error:

make all 
if [ ! -r ../build.number ]; then \
			echo build_number=1 > ../build.number; \
! was unexpected at this time.
make: *** [../build.number] Error 255


To reset the build number you should just have to delete the build.number file at the top of your project.

Regarding the error you have, could you check there is spaces around the brackets and exclamation marks? Also why are you using the ‘-r’ option when starting make?

Which version of System Workbench for STM32 are you using?

I’ve tested this on a v2.0 install and it works correctly.

Bernard (Ac6)


I was using 1.13 so I upgraded to 2.1. The build number generation now works.

I use the make -r option to speed up the build time. I am building the project from a network drive, so the file I/O is slower. If I do a build with no changes, it takes 40 seconds to respond with the nothing to do message without the -r option. With the -r option it completes in 2 seconds.

However, since upgrading to 2.1, now every time I do a build it first says it is generating the make files for all the source folders before starting the build. This takes more than 60 seconds before it even starts the build. Do you know why this is?