From 9c0cbb107be87ff02529e094505032b7fca6b3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 1 Jan 2023 20:45:57 +0100 Subject: [PATCH 1/7] Add script to generate header file containing version and commit hash --- stm-firmware/create_version_header.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 stm-firmware/create_version_header.sh diff --git a/stm-firmware/create_version_header.sh b/stm-firmware/create_version_header.sh new file mode 100755 index 0000000..0f87882 --- /dev/null +++ b/stm-firmware/create_version_header.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if [[ -z $1 ]]; then + # Exit with error in case no output file is specified + exit -1 +fi + +firmware_version=`git describe --tags --always --dirty` +commit=`git rev-parse HEAD` + +echo "#ifndef _VERSION_GENERATED_H_" > $1 +echo "#define _VERSION_GENERATED_H_" >> $1 +echo "#define GIT_VERSION_STRING \"$firmware_version\"" >> $1 +echo "#define GIT_FULL_COMMIT \"$commit\"" >> $1 +echo "#endif /* _VERSION_GENERATED_H_ */" >> $1 \ No newline at end of file From 745e7db78f12f67fe94b7f8f87b93c784f5062ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 1 Jan 2023 21:02:49 +0100 Subject: [PATCH 2/7] Add version c file that includes a generated file during build --- stm-firmware/CMakeLists.txt | 17 +++++++++--- .../include/reflow-controller/version.h | 27 +++++++++++++++++++ stm-firmware/version.c | 25 +++++++++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 stm-firmware/include/reflow-controller/version.h create mode 100644 stm-firmware/version.c diff --git a/stm-firmware/CMakeLists.txt b/stm-firmware/CMakeLists.txt index 164ee2f..db8fee9 100644 --- a/stm-firmware/CMakeLists.txt +++ b/stm-firmware/CMakeLists.txt @@ -60,8 +60,7 @@ add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmayb add_compile_options(-mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -Wimplicit-fallthrough=3 -Wsign-compare) -set(GIT_DESCRIBE "${GIT_DESCRIBE}") -add_definitions(-DBASE64_LOOKUP_TABLE_SECTION=\".ccm.bss\" -DSHELLMATTA_HELP_ALIAS=\"?\" -DGIT_VER=${GIT_DESCRIBE} -DHSE_VALUE=8000000UL -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4) +add_definitions(-DBASE64_LOOKUP_TABLE_SECTION=\".ccm.bss\" -DSHELLMATTA_HELP_ALIAS=\"?\" -DHSE_VALUE=8000000UL -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4) add_subdirectory(doxygen) add_subdirectory(updater/ram-code) @@ -101,18 +100,28 @@ aux_source_directory("shellmatta/src" SHELLMATTA_SRCS) aux_source_directory("updater" UPDATER_SRCS) aux_source_directory("temp-profile" PROFILE_SRCS) +set(GEN_VERSION_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/include/generated-version") + + +add_custom_target( + generate-version-header + COMMAND mkdir -p ${GEN_VERSION_HEADER_PATH} && bash "${CMAKE_CURRENT_SOURCE_DIR}/create_version_header.sh" "${GEN_VERSION_HEADER_PATH}/version.h" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + add_executable(${ELFFILE} ${MAIN_SOURCES} ${CFG_PARSER_SRCS} ${UI_SRCS} ${FAT_SRCS} ${SDIO_SRCS} ${BOOT_SRCS} ${SETUP_SRCS} ${STM_PERIPH_SRCS} ${SETTINGS_SRCS} ${SAFETY_SRCS} ${SHELLMATTA_SRCS} ${UPDATER_SRCS} ${PROFILE_SRCS} ) -add_dependencies(${ELFFILE} updater-ram-code-header-blob) +add_dependencies(${ELFFILE} updater-ram-code-header-blob generate-version-header) + target_include_directories(${ELFFILE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/shellmatta/api ${CMAKE_CURRENT_SOURCE_DIR}/config-parser/include) target_link_options(${ELFFILE} PRIVATE -mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles -T${LINKER_SCRIPT} -Wl,--print-memory-usage) target_link_libraries(${ELFFILE} base64-lib linklist-lib) -target_include_directories(${ELFFILE} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/updater/ram-code/include/") +target_include_directories(${ELFFILE} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/updater/ram-code/include/" "${CMAKE_CURRENT_BINARY_DIR}/include/") add_custom_command( TARGET ${ELFFILE} diff --git a/stm-firmware/include/reflow-controller/version.h b/stm-firmware/include/reflow-controller/version.h new file mode 100644 index 0000000..0070e3e --- /dev/null +++ b/stm-firmware/include/reflow-controller/version.h @@ -0,0 +1,27 @@ +/* Reflow Oven Controller + * + * Copyright (C) 2022 Mario Hüttel + * + * This file is part of the Reflow Oven Controller Project. + * + * The reflow oven controller is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * The Reflow Oven Control Firmware is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with the reflow oven controller project. + * If not, see . + */ + +#ifndef _VERSION_H_ +#define _VERSION_H_ + +extern const char *git_version_string; +extern const char *git_full_commit_string; + +#endif /* _VERSION_H_ */ \ No newline at end of file diff --git a/stm-firmware/version.c b/stm-firmware/version.c new file mode 100644 index 0000000..f2e8752 --- /dev/null +++ b/stm-firmware/version.c @@ -0,0 +1,25 @@ +/* Reflow Oven Controller + * + * Copyright (C) 2022 Mario Hüttel + * + * This file is part of the Reflow Oven Controller Project. + * + * The reflow oven controller is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * The Reflow Oven Control Firmware is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with the reflow oven controller project. + * If not, see . + */ + +#include +#include + +const char *git_version_string = GIT_VERSION_STRING; +const char *git_full_commit_string = GIT_FULL_COMMIT; \ No newline at end of file From 767aa75c253a5cc206c04d7dd20dd257e8c08eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 1 Jan 2023 21:04:03 +0100 Subject: [PATCH 3/7] Make git a required build dependency --- stm-firmware/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stm-firmware/CMakeLists.txt b/stm-firmware/CMakeLists.txt index db8fee9..2fdff26 100644 --- a/stm-firmware/CMakeLists.txt +++ b/stm-firmware/CMakeLists.txt @@ -38,9 +38,8 @@ if (GIT_FOUND) ) message("${BoldGreen}Git based version number: ${GIT_DESCRIBE}${ColorReset}") else (GIT_FOUND) - set(GIT_DESCRIBE "v0.0.0-unknown") message("${BoldRed}No git installation found. It is highly recommended using git to generate the version number") - message("Version is set to: ${GIT_DESCRIBE}${ColorReset}") + message(FATAL_ERROR "Git is required") endif (GIT_FOUND) find_program(PATCHELFCRC patchelfcrc) From 2c2e4c1484dbd53bdffa844b67841c88177121e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 1 Jan 2023 21:07:10 +0100 Subject: [PATCH 4/7] Add compile date and time to version.c --- stm-firmware/include/reflow-controller/version.h | 6 ++++-- stm-firmware/version.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/stm-firmware/include/reflow-controller/version.h b/stm-firmware/include/reflow-controller/version.h index 0070e3e..96e5e6a 100644 --- a/stm-firmware/include/reflow-controller/version.h +++ b/stm-firmware/include/reflow-controller/version.h @@ -21,7 +21,9 @@ #ifndef _VERSION_H_ #define _VERSION_H_ -extern const char *git_version_string; -extern const char *git_full_commit_string; +extern const char *version_git_version_string; +extern const char *version_git_full_commit_string; +extern const char *version_compile_date; +extern const char *version_compile_time; #endif /* _VERSION_H_ */ \ No newline at end of file diff --git a/stm-firmware/version.c b/stm-firmware/version.c index f2e8752..602a0ef 100644 --- a/stm-firmware/version.c +++ b/stm-firmware/version.c @@ -21,5 +21,7 @@ #include #include -const char *git_version_string = GIT_VERSION_STRING; -const char *git_full_commit_string = GIT_FULL_COMMIT; \ No newline at end of file +const char *version_git_version_string = GIT_VERSION_STRING; +const char *version_git_full_commit_string = GIT_FULL_COMMIT; +const char *version_compile_date = __DATE__; +const char *version_compile_time = __TIME__; \ No newline at end of file From df70238b367edd5baf695753a7bcd9fa1081949c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 1 Jan 2023 21:12:00 +0100 Subject: [PATCH 5/7] Remove git_ver define from updater --- stm-firmware/updater/ram-code/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stm-firmware/updater/ram-code/CMakeLists.txt b/stm-firmware/updater/ram-code/CMakeLists.txt index ddd12a2..dc660a3 100644 --- a/stm-firmware/updater/ram-code/CMakeLists.txt +++ b/stm-firmware/updater/ram-code/CMakeLists.txt @@ -31,7 +31,7 @@ add_executable(${ELFFILE} ${SRCS} ${FATFS_SRCS} ${SDIO_SRCS} ${STM_PERIPH_SRCS} target_include_directories(${ELFFILE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ../../include ${CMAKE_CURRENT_SOURCE_DIR}/3rd-party) target_compile_options(${ELFFILE} PRIVATE -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) target_compile_options(${ELFFILE} PRIVATE -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -Wimplicit-fallthrough=3 -Wsign-compare -Os -g3) -target_compile_definitions(${ELFFILE} PRIVATE -DGIT_VER=${GIT_DESCRIBE} -DHSE_VALUE=8000000UL -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DSAFETY_MEMORY_STRIPOUT_DUMP) +target_compile_definitions(${ELFFILE} PRIVATE -DHSE_VALUE=8000000UL -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DSAFETY_MEMORY_STRIPOUT_DUMP) target_link_options(${ELFFILE} PRIVATE -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles -T${LINKER_SCRIPT} -Wl,--print-memory-usage) set(GEN_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/include/generated") set(GEN_HEADER_FILE "${GEN_HEADER_PATH}/${PROJECT_NAME}.bin.h") From 34c1c3db4e01e5a3ac477104c2016ab4022be208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 1 Jan 2023 21:12:19 +0100 Subject: [PATCH 6/7] Rework UI to use newly created version handling --- stm-firmware/ui/gui.c | 7 ++++--- stm-firmware/ui/shell.c | 10 ++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/stm-firmware/ui/gui.c b/stm-firmware/ui/gui.c index 9594941..670d363 100644 --- a/stm-firmware/ui/gui.c +++ b/stm-firmware/ui/gui.c @@ -18,6 +18,7 @@ * If not, see . */ +#include "reflow-controller/version.h" #include #include #include @@ -167,9 +168,9 @@ static void gui_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry ent break; last_page = 1; menu_lcd_output(menu, 0, "Version Number:"); - menu_lcd_outputf(menu, 1, "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER)); - if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) { - menu_lcd_outputf(menu, 2, "%s", &xstr(GIT_VER)[LCD_CHAR_WIDTH]); + menu_lcd_outputf(menu, 1, "%.*s", LCD_CHAR_WIDTH, version_git_version_string); + if (strlen(version_git_version_string) > LCD_CHAR_WIDTH) { + menu_lcd_outputf(menu, 2, "%s", &version_git_version_string[LCD_CHAR_WIDTH]); } #ifdef DEBUGBUILD menu_lcd_output(menu, 3, "Page 2/5 [DEBUG]"); diff --git a/stm-firmware/ui/shell.c b/stm-firmware/ui/shell.c index b82a42c..68fd94d 100644 --- a/stm-firmware/ui/shell.c +++ b/stm-firmware/ui/shell.c @@ -49,13 +49,10 @@ #include #include #include +#include #include -#ifndef GIT_VER -#define GIT_VER "VERSION NOT SET" -#endif - static shellmatta_instance_t shell; static char shell_buffer[512]; static char IN_SECTION(.ccm.bss) history_buffer[512]; @@ -81,8 +78,9 @@ static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle, stm_unique_id_get(&high_id, &mid_id, &low_id); stm_dev_rev_id_get(&stm_dev_id, &stm_rev_id); - shellmatta_printf(handle, "Reflow Oven Controller Firmware " xstr(GIT_VER) "\r\n" - "Compiled: " __DATE__ " at " __TIME__ "\r\n"); + shellmatta_printf(handle, "Reflow Oven Controller Firmware %s\r\n" + "Compiled: %s at %s\r\n", + version_git_version_string, version_compile_date, version_compile_time); shellmatta_printf(handle, "Serial: %08X-%08X-%08X\r\n", high_id, mid_id, low_id); pcb_rev = get_pcb_hardware_version(); From e335cb42acf6b1354e3d549e86656ee466f4314f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 1 Jan 2023 21:16:36 +0100 Subject: [PATCH 7/7] Add comment to cmake build step --- stm-firmware/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/stm-firmware/CMakeLists.txt b/stm-firmware/CMakeLists.txt index 2fdff26..1bb7ac2 100644 --- a/stm-firmware/CMakeLists.txt +++ b/stm-firmware/CMakeLists.txt @@ -106,6 +106,7 @@ add_custom_target( generate-version-header COMMAND mkdir -p ${GEN_VERSION_HEADER_PATH} && bash "${CMAKE_CURRENT_SOURCE_DIR}/create_version_header.sh" "${GEN_VERSION_HEADER_PATH}/version.h" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Generating version number using git" ) add_executable(${ELFFILE} ${MAIN_SOURCES} ${CFG_PARSER_SRCS} ${UI_SRCS}