From 289f49204d4d8333552620542e434b31e6a34085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 21 Mar 2021 22:38:22 +0100 Subject: [PATCH 1/3] fisr draft of cmake buidl system. Update generation still missing --- stm-firmware/CMakeLists.txt | 73 ++++++++++++++++++++++++++++ stm-firmware/arm-none-eabi-gcc.cmake | 28 +++++++++++ 2 files changed, 101 insertions(+) create mode 100644 stm-firmware/CMakeLists.txt create mode 100644 stm-firmware/arm-none-eabi-gcc.cmake diff --git a/stm-firmware/CMakeLists.txt b/stm-firmware/CMakeLists.txt new file mode 100644 index 0000000..607aa62 --- /dev/null +++ b/stm-firmware/CMakeLists.txt @@ -0,0 +1,73 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_CROSSCOMPILING 1) +cmake_minimum_required(VERSION 3.0) + +set(CMAKE_TOOLCHAIN_FILE "arm-none-eabi-gcc.cmake") + +project(reflow-controller) + +if(NOT WIN32) + string(ASCII 27 Esc) + set(ColorReset "${Esc}[m") + set(ColorBold "${Esc}[1m") + set(Red "${Esc}[31m") + set(Green "${Esc}[32m") + set(Yellow "${Esc}[33m") + set(Blue "${Esc}[34m") + set(Magenta "${Esc}[35m") + set(Cyan "${Esc}[36m") + set(White "${Esc}[37m") + set(BoldRed "${Esc}[1;31m") + set(BoldGreen "${Esc}[1;32m") + set(BoldYellow "${Esc}[1;33m") + set(BoldBlue "${Esc}[1;34m") + set(BoldMagenta "${Esc}[1;35m") + set(BoldCyan "${Esc}[1;36m") + set(BoldWhite "${Esc}[1;37m") +endif() + +set(ELFFILE ${PROJECT_NAME}.elf) +set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/stm32f407vet6_flash.ld) + +add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) +add_compile_options(-mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -Wimplicit-fallthrough=3 -Wsign-compare) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) + +add_definitions(-DBASE64_LOOKUP_TABLE_SECTION=\".ccm.bss\" -DSHELLMATTA_HELP_ALIAS=\"?\" -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DHSE_VALUE=8000000UL) + + +add_subdirectory(base64-lib) + + +IF(CMAKE_BUILD_TYPE STREQUAL "Debug") +add_definitions(-DDEBUGBUILD) +add_compile_options(-O0 -g) +ELSE() +add_definitions(-DDEBUGBUILD) +add_compile_options(-O3 -g) +add_link_options(-Wl,--gc-sections) +ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") + +aux_source_directory("." MAIN_SOURCES) +aux_source_directory("config-parser" CFG_PARSER_SRCS) +aux_source_directory("ui" UI_SRCS) +aux_source_directory("fatfs" FAT_SRCS) +aux_source_directory("fatfs/shimatta_sdio_driver" SDIO_SRCS) +aux_source_directory("boot" BOOT_SRCS) +aux_source_directory("setup" SETUP_SRCS) +aux_source_directory("stm-periph" STM_PERIPH_SRCS) +aux_source_directory("settings" SETTINGS_SRCS) +aux_source_directory("safety" SAFETY_SRCS) +aux_source_directory("shellmatta/src" SHELLMATTA_SRCS) +aux_source_directory("updater" UPDATER_SRCS) + +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}) + +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 -mthumb-interwork -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) + diff --git a/stm-firmware/arm-none-eabi-gcc.cmake b/stm-firmware/arm-none-eabi-gcc.cmake new file mode 100644 index 0000000..d15757e --- /dev/null +++ b/stm-firmware/arm-none-eabi-gcc.cmake @@ -0,0 +1,28 @@ +if(MINGW OR CYGWIN OR WIN32) + set(UTIL_SEARCH_CMD where) +elseif(UNIX OR APPLE) + set(UTIL_SEARCH_CMD which) +endif() + +set(TOOLCHAIN_PREFIX arm-none-eabi-) + +execute_process( + COMMAND ${UTIL_SEARCH_CMD} ${TOOLCHAIN_PREFIX}gcc + OUTPUT_VARIABLE BINUTILS_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +get_filename_component(ARM_TOOLCHAIN_DIR ${BINUTILS_PATH} DIRECTORY) +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) +set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) + +set(CMAKE_OBJCOPY ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}objcopy CACHE INTERNAL "objcopy tool") +set(CMAKE_SIZE_UTIL ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}size CACHE INTERNAL "size tool") + +set(CMAKE_FIND_ROOT_PATH ${BINUTILS_PATH}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) From 4c3574c2e29135a932aeb0ffe53ae92687ef4b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 23 Mar 2021 22:15:11 +0100 Subject: [PATCH 2/3] Make project Cmake ready --- stm-firmware/CMakeLists.txt | 25 ++- stm-firmware/Makefile | 224 ------------------- stm-firmware/obj/.gitignore | 3 - stm-firmware/updater/ram-code/CMakeLists.txt | 46 ++++ stm-firmware/updater/ram-code/Makefile | 82 ------- stm-firmware/updater/ram-code/bin2carray.py | 3 +- stm-firmware/updater/updater.c | 2 +- 7 files changed, 68 insertions(+), 317 deletions(-) delete mode 100644 stm-firmware/Makefile delete mode 100644 stm-firmware/obj/.gitignore create mode 100644 stm-firmware/updater/ram-code/CMakeLists.txt delete mode 100644 stm-firmware/updater/ram-code/Makefile diff --git a/stm-firmware/CMakeLists.txt b/stm-firmware/CMakeLists.txt index 607aa62..5c82698 100644 --- a/stm-firmware/CMakeLists.txt +++ b/stm-firmware/CMakeLists.txt @@ -27,19 +27,25 @@ if(NOT WIN32) set(BoldWhite "${Esc}[1;37m") endif() +execute_process(COMMAND bash -c "echo -n $(git describe --always --tags --dirty)" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_DESCRIBE) + set(ELFFILE ${PROJECT_NAME}.elf) set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/stm32f407vet6_flash.ld) add_compile_options(-Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter) add_compile_options(-mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -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_subdirectory(updater/ram-code) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) -add_definitions(-DBASE64_LOOKUP_TABLE_SECTION=\".ccm.bss\" -DSHELLMATTA_HELP_ALIAS=\"?\" -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DHSE_VALUE=8000000UL) - - -add_subdirectory(base64-lib) - +message("${BoldGreen}Version: ${GIT_DESCRIBE}${ColorReset}") IF(CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-DDEBUGBUILD) @@ -50,6 +56,9 @@ add_compile_options(-O3 -g) add_link_options(-Wl,--gc-sections) ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") +add_subdirectory(base64-lib) + + aux_source_directory("." MAIN_SOURCES) aux_source_directory("config-parser" CFG_PARSER_SRCS) aux_source_directory("ui" UI_SRCS) @@ -65,9 +74,13 @@ aux_source_directory("updater" UPDATER_SRCS) 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}) + ${STM_PERIPH_SRCS} ${SETTINGS_SRCS} ${SAFETY_SRCS} ${SHELLMATTA_SRCS} ${UPDATER_SRCS} + ) + +add_dependencies(${ELFFILE} updater-ram-code-header-blob) 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 -mthumb-interwork -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) +target_include_directories(${ELFFILE} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/updater/ram-code/include/") diff --git a/stm-firmware/Makefile b/stm-firmware/Makefile deleted file mode 100644 index 99985fe..0000000 --- a/stm-firmware/Makefile +++ /dev/null @@ -1,224 +0,0 @@ -################################Shimatta Makefile#################################### -#CPU: STM32F407VET6 -#Compiler: arm-none-eabi -##################################################################################### -#Add Files and Folders below######################################################### -CFILES = main.c syscalls.c setup/system_stm32f4xx.c systick.c boot/startup_stm32f407vx.c -ASFILES = -INCLUDEPATH = -Iinclude - -OBJDIR_BASE = obj -TARGET_BASE = reflow-controller -LIBRARYPATH = -L. -LIBRARIES = - -DEFINES = -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4 -DHSE_VALUE=8000000UL -MAPFILE_BASE = memory-mapping -LINKER_SCRIPT=stm32f407vet6_flash.ld - -export GIT_VER = $(shell git describe --always --dirty --tags) -DEFINES += -DGIT_VER=$(GIT_VER) - -ifneq ($(VERBOSE),true) -QUIET=@ -else -QUIET= -endif - -##Custom Files### -CFILES += adc-meas.c - -# Shellmatta -CFILES += shellmatta/src/shellmatta.c shellmatta/src/shellmatta_autocomplete.c shellmatta/src/shellmatta_escape.c shellmatta/src/shellmatta_history.c shellmatta/src/shellmatta_utils.c shellmatta/src/shellmatta_opt.c shell.c -INCLUDEPATH += -Ishellmatta/api -DEFINES += -DSHELLMATTA_HELP_ALIAS=\"?\" - -# RCC Manager -CFILES += stm-periph/rcc-manager.c -CFILES += stm-periph/uart.c stm-periph/dma-ring-buffer.c stm-periph/backup-ram.c -CFILES += stm-periph/rng.c stm-periph/spi.c -CFILES += digio.c -CFILES += stm-periph/unique-id.c -CFILES += calibration.c -CFILES += temp-converter.c -CFILES += rotary-encoder.c button.c -CFILES += ui/lcd.c ui/menu.c ui/gui.c -CFILES += fatfs/diskio.c fatfs/ff.c fatfs/ffsystem.c fatfs/ffunicode.c fatfs/shimatta_sdio_driver/shimatta_sdio.c -CFILES += pid-controller.c oven-driver.c -CFILES += settings/settings.c settings/settings-sd-card.c settings/spi-eeprom.c settings/settings-eeprom.c -CFILES += stm-periph/crc-unit.c -CFILES += safety/safety-adc.c safety/safety-controller.c safety/watchdog.c safety/fault.c safety/safety-memory.c safety/stack-check.c -CFILES += hw-version-detect.c -CFILES += config-parser/config-parser.c -CFILES += updater/updater.c -INCLUDEPATH += -Iconfig-parser/include - -CFILES += base64-lib/src/base64-lib.c -INCLUDEPATH += -Ibase64-lib/include -DEFINES += -DBASE64_LOOKUP_TABLE_SECTION="\".ccm.bss\"" - - -DEBUG_DEFINES = -DDEBUGBUILD -RELEASE_DEFINES = -DUART_ON_DEBUG_HEADER - -################################################################################### -ifeq ($(CROSS_COMPILE),) -CROSS_COMPILE=arm-none-eabi- -endif - -CC=$(CROSS_COMPILE)gcc -OBJCOPY=$(CROSS_COMPILE)objcopy -OBJDUMP=$(CROSS_COMPILE)objdump -SIZE=$(CROSS_COMPILE)size - -CFLAGS_RELEASE = -O3 -g -CFLAGS_DEBUG = -O0 -g - -LFLAGS_RELEASE = -Wl,--gc-sections -LFLAGS_DEBUG = - -CFLAGS = -LFLAGS = - -ifneq ($(DEBUGBUILD),true) -DEFINES += $(RELEASE_DEFINES) -CFLAGS += $(CFLAGS_RELEASE) -LFLAGS += $(LFLAGS_RELEASE) -target = $(TARGET_BASE)-release -OBJDIR = $(OBJDIR_BASE)/release -MAPFILE = $(MAPFILE_BASE)-release -else -DEFINES += $(DEBUG_DEFINES) -target = $(TARGET_BASE)-debug -CFLAGS += $(CFLAGS_DEBUG) -LFLAGS += $(LFLAGS_DEBUG) -OBJDIR = $(OBJDIR_BASE)/debug -MAPFILE = $(MAPFILE_BASE)-debug -endif - -LFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -LFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles -LFLAGS += -T$(LINKER_SCRIPT) -Wl,-Map=$(MAPFILE).map -Wl,--print-memory-usage - -CFLAGS += -c -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -CFLAGS += -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter -Wimplicit-fallthrough=3 -Wsign-compare - -#################################################################################### - -OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o) -ASOBJ += $(ASFILES:%.S=$(OBJDIR)/%.S.o) - -default: $(target).elf - -all: debug release - -release: - $(QUIET)$(MAKE) DEBUGBUILD=false - -debug: - $(QUIET)$(MAKE) DEBUGBUILD=true - -%.bin: %.elf - $(QUIET)$(OBJCOPY) -O binary $^ $@ -%.hex: %.elf - $(QUIET)$(OBJCOPY) -O ihex $^ $@ - - -#Linking -$(target).elf: $(OBJ) $(ASOBJ) $(LINKER_SCRIPT) - @echo [LD] $@ - $(QUIET)$(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $(OBJ) $(ASOBJ) $(LIBRARIES) - $(QUIET)$(SIZE) $@ - @echo "Built Version $(GIT_VER)" - -$(OBJDIR)/updater/updater.c.o: updater/ram-code/updater-ram-code.bin.h - -#Compiling -$(OBJ): - @echo [CC] $@ - $(eval OUTPATH=$(dir $@)) - @mkdir -p $(OUTPATH) - $(QUIET)$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ $(@:$(OBJDIR)/%.c.o=%.c) -$(ASOBJ): - @echo [AS] $@ - $(eval OUTPATH=$(dir $@)) - @mkdir -p $(OUTPATH) - $(QUIET)$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ $(@:$(OBJDIR)/%.S.o=%.S) - - -.PHONY: qtproject-legacy qtproject qtproject-debug clean mrproper objcopy disassemble program program-debug updater/ram-code/updater-ram-code.bin.h - -updater/ram-code/updater-ram-code.bin.h: - $(QUIET)$(MAKE) -C updater/ram-code updater-ram-code.bin.h - -program-debug: - $(QUIET)$(MAKE) DEBUGBUILD=true program - -program: $(target).elf - ./program-device.sh $< - -disassemble: $(target).elf - $(QUIET)$(OBJDUMP) -D -s $< > $(target).lss - -objcopy: $(target).bin $(target).hex - -mrproper: clean -ifneq ($(DEBUGBUILD),true) - @echo "Purging RELEASE project files" -else - @echo "Purging DEBUG project files" -endif - $(QUIET)rm -f $(target).pro $(target).creator $(target).files $(target).cflags $(target).cxxflags $(target).includes $(target).config -ifneq ($(DEBUGBUILD),true) - $(QUIET)$(MAKE) DEBUGBUILD=true mrproper -endif - - -clean: - @echo -n "Cleaning up derived files for " -ifneq ($(DEBUGBUILD),true) - @echo "RELEASE build" -else - @echo "DEBUG build" -endif - $(QUIET)rm -f $(target).elf $(target).bin $(target).hex $(OBJ) $(ASOBJ) $(mapfile).map $(CFILES:%.c=$(OBJDIR)/%.c.d) $(ASFILES:%.S=$(OBJDIR)/%.S.d) - $(QUIET)rm -rf $(OBJDIR)/* - $(MAKE) -C updater/ram-code clean -ifneq ($(DEBUGBUILD),true) - $(QUIET)$(MAKE) DEBUGBUILD=true clean -endif - -qtproject-legacy: - echo -e "TEMPLATE = app\nCONFIG -= console app_bundle qt" > $(target).pro - echo -e "SOURCES += $(CFILES) $(ASFILES)" >> $(target).pro - echo -ne "INCLUDEPATH += " >> $(target).pro - echo "$(INCLUDEPATH)" | sed "s!-I!./!g" >> $(target).pro - echo -ne "HEADERS += " >> $(target).pro - find -name "*.h" | tr "\\n" " " >> $(target).pro - echo -ne "\nDEFINES += " >> $(target).pro - echo "$(DEFINES)" | sed "s/-D//g" >> $(target).pro - -qtproject-debug: - @echo "Generating debug build project" - $(QUIET)$(MAKE) DEBUGBUILD=true qtproject - -qtproject: - $(QUIET)rm -f $(target).files $(target).cflags $(target).config $(target).creator $(target).includes $(target).creator.user - @echo "Generating source file list" - $(QUIET)echo "$(CFILES)" | tr ' ' '\n' > $(target).files - @echo -n "Appending found header files from folders " - @echo `echo $(INCLUDEPATH) | sed "s/-I//g"` - $(QUIET)for dir in `echo $(INCLUDEPATH) | sed "s/-I//g"`; do \ - find `echo "$${dir}"` -name "*.h" >> $(target).files; \ - done - @echo "Generating $(target).cflags" - $(QUIET)echo "" > $(target).cflags - @echo "Generating $(target).includes" - $(QUIET)echo $(INCLUDEPATH) | sed "s/-I/,/g" | tr , '\n' | sed "/^$$/d" > $(target).includes; - @echo "Generating $(target).config" - $(QUIET)echo $(DEFINES) | sed "s/-D/,#define /g" | tr , '\n' | sed "/^$$/d" > $(target).config - @echo "Generating $(target).creator" - $(QUIET)echo "[GENERAL]" > $(target).creator - --include $(CFILES:%.c=$(OBJDIR)/%.c.d) $(ASFILES:%.S=$(OBJDIR)/%.S.d) diff --git a/stm-firmware/obj/.gitignore b/stm-firmware/obj/.gitignore deleted file mode 100644 index a91312f..0000000 --- a/stm-firmware/obj/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -* -*.* -!.gitignore diff --git a/stm-firmware/updater/ram-code/CMakeLists.txt b/stm-firmware/updater/ram-code/CMakeLists.txt new file mode 100644 index 0000000..ec013b7 --- /dev/null +++ b/stm-firmware/updater/ram-code/CMakeLists.txt @@ -0,0 +1,46 @@ +project(updater-ram-code) +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_CROSSCOMPILING 1) +cmake_minimum_required(VERSION 3.0) + +set(CMAKE_TOOLCHAIN_FILE "arm-none-eabi-gcc.cmake") + +set(ELFFILE ${PROJECT_NAME}.elf) +set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/ram-link.ld) + +set(ELFFILE "${PROJECT_NAME}.elf") +aux_source_directory("." SRCS) +aux_source_directory("fatfs" FATFS_SRCS) +aux_source_directory("fatfs/shimatta_sdio_driver" SDIO_SRCS) + +add_executable(${ELFFILE} ${SRCS} ${FATFS_SRCS} ${SDIO_SRCS}) + +target_include_directories(${ELFFILE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) +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 -DBASE64_LOOKUP_TABLE_SECTION=\".ccm.bss\" -DSHELLMATTA_HELP_ALIAS=\"?\" -DGIT_VER=${GIT_DESCRIBE} -DHSE_VALUE=8000000UL -DSTM32F407xx -DSTM32F4XX -DARM_MATH_CM4) +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") +target_include_directories(${ELFFILE} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/") + +set(GEN_HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/include/generated/${PROJECT_NAME}.bin.h") + +add_custom_target(updater-ram-code-header-blob DEPENDS ${GEN_HEADER_FILE}) + +add_custom_command(DEPENDS + ${ELFFILE} + OUTPUT + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin" + COMMAND + ${CMAKE_OBJCOPY} -O binary ${ELFFILE} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin" + ) + +add_custom_command(DEPENDS + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin" + OUTPUT + ${GEN_HEADER_FILE} + COMMAND + mkdir -p ${GEN_HEADER_PATH} && python "${CMAKE_CURRENT_SOURCE_DIR}/bin2carray.py" "${GEN_HEADER_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin" + ) diff --git a/stm-firmware/updater/ram-code/Makefile b/stm-firmware/updater/ram-code/Makefile deleted file mode 100644 index c4c4984..0000000 --- a/stm-firmware/updater/ram-code/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -RAM_CODE_TARGET = updater-ram-code -target = $(RAM_CODE_TARGET) -OBJDIR = obj -CFILES = main.c startup.c hex-parser.c -CFILES += fatfs/ff.c fatfs/diskio.c fatfs/ffsystem.c fatfs/ffunicode.c fatfs/shimatta_sdio_driver/shimatta_sdio.c -LINKER_SCRIPT = ram-link.ld -MAPFILE = $(RAM_CODE_TARGET) -PREFIX = arm-none-eabi- - -CC = $(PREFIX)gcc -OBJCOPY = $(PREFIX)objcopy -SIZE = $(PREFIX)size - -ifneq ($(VERBOSE),true) -QUIET=@ -else -QUIET= -endif - - -DEFINES = -DSTM32F407xx -DSTM32F4XX -DHSE_VALUE=8000000UL -INCLUDEPATH = -Iinclude - -LFLAGS = -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -LFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 --disable-newlib-supplied-syscalls -nostartfiles -LFLAGS += -T$(LINKER_SCRIPT) -Wl,-Map=$(MAPFILE).map -Wl,--print-memory-usage -g3 - -CFLAGS = -c -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -Os -g3 -CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostartfiles -CFLAGS += -Wall -Wextra -Wold-style-declaration -Wuninitialized -Wmaybe-uninitialized -Wunused-parameter -Wimplicit-fallthrough=3 -Wsign-compare - -OBJ = $(CFILES:%.c=$(OBJDIR)/%.c.o) - -default: $(RAM_CODE_TARGET).bin.h - -all: $(RAM_CODE_TARGET).bin.h - -%.bin.h: %.bin - @echo "[BIN2H] $@" - $(QUIET)python bin2carray.py $@ $^ - -$(RAM_CODE_TARGET).bin: $(RAM_CODE_TARGET).elf - @echo "[ELF2BIN] $@" - $(QUIET)$(OBJCOPY) -O binary $^ $@ - -$(RAM_CODE_TARGET).elf: $(OBJ) $(LINKER_SCRIPT) - @echo [LD] $@ - $(QUIET)$(CC) $(LFLAGS) $(LIBRARYPATH) -o $@ $(OBJ) $(ASOBJ) $(LIBRARIES) - $(QUIET)$(SIZE) $@ - -$(OBJ): - @echo [CC] $@ - $(eval OUTPATH=$(dir $@)) - @mkdir -p $(OUTPATH) - $(QUIET)$(CC) $(CFLAGS) -MMD -MT $@ $(INCLUDEPATH) $(DEFINES) -o $@ $(@:$(OBJDIR)/%.c.o=%.c) - -.PHONY: clean qtproject - -clean: - @echo [CLEAN] - $(QUIET)rm -f $(OBJ) $(MAPFILE).map $(CFILES:%.c=$(OBJDIR)/%.c.d) $(RAM_CODE_TARGET).bin $(RAM_CODE_TARGET).elf $(RAM_CODE_TARGET).bin.c - -qtproject: - $(QUIET)rm -f $(target).files $(target).cflags $(target).config $(target).creator $(target).includes $(target).creator.user - @echo "Generating source file list" - $(QUIET)echo "$(CFILES)" | tr ' ' '\n' > $(target).files - @echo -n "Appending found header files from folders " - @echo `echo $(INCLUDEPATH) | sed "s/-I//g"` - $(QUIET)for dir in `echo $(INCLUDEPATH) | sed "s/-I//g"`; do \ - find `echo "$${dir}"` -name "*.h" >> $(target).files; \ - done - @echo "Generating $(target).cflags" - $(QUIET)echo "" > $(target).cflags - @echo "Generating $(target).includes" - $(QUIET)echo $(INCLUDEPATH) | sed "s/-I/,/g" | tr , '\n' | sed "/^$$/d" > $(target).includes; - @echo "Generating $(target).config" - $(QUIET)echo $(DEFINES) | sed "s/-D/,#define /g" | tr , '\n' | sed "/^$$/d" > $(target).config - @echo "Generating $(target).creator" - $(QUIET)echo "[GENERAL]" > $(target).creator - --include $(CFILES:%.c=$(OBJDIR)/%.c.d) - diff --git a/stm-firmware/updater/ram-code/bin2carray.py b/stm-firmware/updater/ram-code/bin2carray.py index 15a658b..c0f0ca3 100755 --- a/stm-firmware/updater/ram-code/bin2carray.py +++ b/stm-firmware/updater/ram-code/bin2carray.py @@ -4,6 +4,7 @@ # bin2carray import os +import os.path import sys if len(sys.argv) < 3: @@ -18,7 +19,7 @@ with open(source_file, "rb") as src: data = src.read() with open(dest_file, "w") as dest: - header_guard = "__" + dest_file.replace('.', '_').replace('-', '_') + "_H__" + header_guard = "__" + os.path.basename(dest_file).replace('.', '_').replace('-', '_') + "_H__" dest.write("#ifndef %s\n" % (header_guard)) dest.write("#define %s\n" % (header_guard)) dest.write("static const char binary_blob[%d] = {\n" % (len(data))) diff --git a/stm-firmware/updater/updater.c b/stm-firmware/updater/updater.c index 58802bc..90a632a 100644 --- a/stm-firmware/updater/updater.c +++ b/stm-firmware/updater/updater.c @@ -20,7 +20,7 @@ #include #include -#include "ram-code/updater-ram-code.bin.h" +#include #include #include #include From df40ab1be70c21852665b88748a68905a4b1c3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 23 Mar 2021 22:19:43 +0100 Subject: [PATCH 3/3] Update base64 lib submodule --- stm-firmware/base64-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stm-firmware/base64-lib b/stm-firmware/base64-lib index 80090b4..251e90a 160000 --- a/stm-firmware/base64-lib +++ b/stm-firmware/base64-lib @@ -1 +1 @@ -Subproject commit 80090b4b20b779dd18803b3194c6d90235a1785b +Subproject commit 251e90abf349d05bdb0d63afa86c478d8b0ebb98