mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-17 20:50:48 +01:00
make, tmpl/tagged: Add basic microcontroller support
Add support for building the firmware of the Cortex M3 ST-NUCLEO-F103RB development board with an STM32 microcontroller. This commit add some hooks, notably support for tagged templates, but adds lots of crap, too, notably makefiles and variables that should have different names and / or functionality. New makefiles are: Mcu-defs.mk mcu-exe.mk mcu-flash.mk mcu-tags.mk mcu-topdir.mk tagged-tmpl.mk, a new directory is tmpl/tagged. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
7e03b8c90a
commit
df6c1ef9a1
12 changed files with 682 additions and 22 deletions
|
|
@ -6,6 +6,8 @@
|
|||
# endif
|
||||
#endef
|
||||
|
||||
include $(MODDIR)/make/mcu-tags.mk
|
||||
|
||||
ifeq ($(MCU_BOARD_MODEL),)
|
||||
error MCU_BOARD_MODEL not specified
|
||||
endif
|
||||
|
|
@ -18,6 +20,8 @@ ifeq ($(MCU_FLASH_SIZE),)
|
|||
error MCU_FLASH_SIZE not specified
|
||||
endif
|
||||
|
||||
MCU_PRODUCT_TMPL_DIR ?= $(MODDIR)/tmpl/products
|
||||
|
||||
MCU_BOARD_MODEL_LC ?= $(shell echo $(MCU_BOARD_MODEL) | tr '[A-Z]' '[a-z]')
|
||||
MCU_BOARD ?= $(MCU_BOARD_MODEL)
|
||||
MCU_BOARD_LC ?= $(shell echo $(MCU_BOARD) | tr '[A-Z]' '[a-z]')
|
||||
|
|
|
|||
22
make/mcu-exe.mk
Normal file
22
make/mcu-exe.mk
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
DIR_BASENAME = $(notdir $(CWD))
|
||||
|
||||
ifeq ($(EXE_BASENAME),)
|
||||
ifneq ($(DIR_BASENAME),test)
|
||||
EXE_BASENAME = $(DIR_BASENAME).elf
|
||||
else
|
||||
EXE_BASENAME = test-$(notdir $(shell cd ..; $(PWD))).elf
|
||||
endif
|
||||
endif
|
||||
|
||||
MCU_FLASH_PUSH_FILE_HEX ?= $(patsubst %.elf,%.hex,$(EXE_BASENAME))
|
||||
EXE_MAP ?= $(patsubst %.elf,%.map,$(EXE_BASENAME))
|
||||
PROJECT_LDFLAGS += -static
|
||||
LD_DEFINE_SYMBOLS += _sbrk
|
||||
|
||||
PROJECT_LDFLAGS += $(addprefix -u ,$(LD_DEFINE_SYMBOLS))
|
||||
|
||||
include $(MODDIR)/make/mcu-defs.mk
|
||||
include $(MODDIR)/make/exe.mk
|
||||
include $(MODDIR)/make/mcu-flash.mk
|
||||
|
||||
all: $(MCU_FLASH_PUSH_FILE_HEX)
|
||||
27
make/mcu-flash.mk
Normal file
27
make/mcu-flash.mk
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
.PHONY: flash-fetch flash-push flash-clean-fetch flash-clean-push
|
||||
|
||||
all:
|
||||
|
||||
flash-fetch: $(MCU_FLASH_FETCH_FILE_HEX)
|
||||
clean: flash-clean-fetch
|
||||
flash-clean-fetch:
|
||||
rm -f $(MCU_FLASH_FETCH_FILE_BIN) $(MCU_FLASH_FETCH_FILE_HEX) *.tmp
|
||||
flash-clean-push:
|
||||
rm -f $(MCU_FLASH_PUSH_FILE_BIN) $(MCU_FLASH_PUSH_FILE_HEX) *.tmp
|
||||
$(MCU_FLASH_FETCH_FILE_BIN):
|
||||
$(MCU_OPENOCD) -c "init" -c "reset init" -c "flash read_bank $(MCU_FLASH_FETCH_BANK) $@.tmp $(MCU_FLASH_FETCH_OFFSET) $(MCU_FLASH_FETCH_SIZE)" -c "exit"
|
||||
mv $@.tmp $@
|
||||
%.hex: %.elf
|
||||
$(MCU_OBJCOPY) -O ihex $< $@.tmp
|
||||
mv $@.tmp $@
|
||||
clean: flash-clean-hex
|
||||
flash-clean-hex:
|
||||
rm -rf $(MCU_FLASH_PUSH_FILE_HEX)
|
||||
%.hex: %.bin
|
||||
$(MCU_OBJCOPY) $(MCU_OBJCOPY_FETCH_OPTS) -I binary -O ihex $< $@.tmp
|
||||
mv $@.tmp $@
|
||||
flash-push:
|
||||
# see http://openocd.org/doc/html/Flash-Programming.html
|
||||
$(MCU_OPENOCD) -c "program $(MCU_FLASH_PUSH_FILE_HEX) verify reset exit $(MCU_FLASH_PUSH_OFFSET)"
|
||||
%-flash-push:
|
||||
MCU_FLASH_PUSH_FILE_HEX=$* make flash-push
|
||||
56
make/mcu-tags.mk
Normal file
56
make/mcu-tags.mk
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# ----- product specific part
|
||||
|
||||
ifneq ($(findstring cortex-m3,$(TAGGED_TMPL_TAGS)),)
|
||||
|
||||
# -- set jw-build mcu choices
|
||||
MCU_CPU ?= cortex-m3
|
||||
|
||||
# -- set flags
|
||||
|
||||
# don't wrap error message lines
|
||||
#PROJECT_LDFLAGS += -fmessage-length=0
|
||||
|
||||
# don't know what kind of optimization that is
|
||||
#PROJECT_LDFLAGS += -Og
|
||||
|
||||
# stick with what janware code tends to expect
|
||||
PROJECT_LDFLAGS += -fsigned-char
|
||||
|
||||
# I have no clue which part would evaluate these names
|
||||
PROJECT_LDFLAGS += -ffunction-sections
|
||||
PROJECT_LDFLAGS += -fdata-sections
|
||||
PROJECT_LDFLAGS += -ffreestanding
|
||||
PROJECT_LDFLAGS += -fno-move-loop-invariants
|
||||
|
||||
# skip any automatic initialization
|
||||
PROJECT_LDFLAGS += -nostartfiles
|
||||
|
||||
# garbage collect unused input sections
|
||||
PROJECT_LDFLAGS += -Xlinker --gc-sections
|
||||
|
||||
# create map file
|
||||
PROJECT_LDFLAGS += -Wl,-Map,"$(EXE_MAP)"
|
||||
|
||||
# use newlib-nano (TODO: No -Wl necessary?)
|
||||
PROJECT_LDFLAGS += --specs=nano.specs
|
||||
|
||||
endif
|
||||
|
||||
# ----- build options based on product choices
|
||||
|
||||
ifneq ($(findstring $(MCU_CPU),cortex-m3),)
|
||||
|
||||
PROJECT_LDFLAGS += -mcpu=cortex-m3
|
||||
PROJECT_LDFLAGS += -mthumb
|
||||
|
||||
endif
|
||||
|
||||
# ----- tagged templates
|
||||
#MCU_LD_DIR = $(wildcard $(firstword $(call $(TAGGED_TMPL_DIRS),ld)))
|
||||
#MCU_LD_DIR = $(firstword $(foreach tag,$(TAGGED_TMPL_TAGS),$(foreach repo,$(TOPDIR)/tmpl/tagged $(MODDIR)/tmpl/tagged,$(wildcard $(repo)/$(tag)/ld))))
|
||||
#MCU_LD_DIR = $(firstword $(wildcard $(foreach tag,$(TAGGED_TMPL_TAGS),$(foreach repo,$(TOPDIR)/tmpl/tagged $(MODDIR)/tmpl/tagged,$(repo)/$(tag)/ld))))
|
||||
MCU_LD_CHECK_DIRS = $(foreach tag,$(TAGGED_TMPL_TAGS),$(foreach repo,$(TOPDIR)/tmpl/tagged $(MODDIR)/tmpl/tagged,$(repo)/$(tag)/ld))
|
||||
MCU_LD_DIRS = $(wildcard $(MCU_LD_CHECK_DIRS))
|
||||
MCU_LD_DIR = $(firstword $(MCU_LD_DIRS))
|
||||
|
||||
PROJECT_LDFLAGS += -L$(MCU_LD_DIR) $(addprefix -T ,$(sort $(notdir $(wildcard $(MCU_LD_DIR)/*.ld))))
|
||||
|
|
@ -1,24 +1,3 @@
|
|||
include $(MODDIR)/make/mcu-defs.mk
|
||||
include $(MODDIR)/make/topdir.mk
|
||||
|
||||
.PHONY: flash-fetch flash-push flash-clean-fetch flash-clean-push
|
||||
|
||||
all:
|
||||
|
||||
flash-fetch: $(MCU_FLASH_FETCH_FILE_HEX)
|
||||
clean: flash-clean-fetch
|
||||
flash-clean-fetch:
|
||||
rm -f $(MCU_FLASH_FETCH_FILE_BIN) $(MCU_FLASH_FETCH_FILE_HEX) *.tmp
|
||||
flash-clean-push:
|
||||
rm -f $(MCU_FLASH_PUSH_FILE_BIN) $(MCU_FLASH_PUSH_FILE_HEX) *.tmp
|
||||
$(MCU_FLASH_FETCH_FILE_BIN):
|
||||
$(MCU_OPENOCD) -c "init" -c "reset init" -c "flash read_bank $(MCU_FLASH_FETCH_BANK) $@.tmp $(MCU_FLASH_FETCH_OFFSET) $(MCU_FLASH_FETCH_SIZE)" -c "exit"
|
||||
mv $@.tmp $@
|
||||
%.hex: %.bin
|
||||
$(MCU_OBJCOPY) $(MCU_OBJCOPY_FETCH_OPTS) -I binary -O ihex $< $@.tmp
|
||||
mv $@.tmp $@
|
||||
flash-push:
|
||||
# see http://openocd.org/doc/html/Flash-Programming.html
|
||||
$(MCU_OPENOCD) -c "program $(MCU_FLASH_PUSH_FILE_HEX) verify reset exit $(MCU_FLASH_PUSH_OFFSET)"
|
||||
%-flash-push:
|
||||
MCU_FLASH_PUSH_FILE_HEX=$* make flash-push
|
||||
include $(MODDIR)/make/mcu-flash.mk
|
||||
|
|
|
|||
5
make/tagged-tmpl-repo.mk
Normal file
5
make/tagged-tmpl-repo.mk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
TAGGED_TMPL_TAG ?= $(notdir $(CWD))
|
||||
TAGGED_TMPL_EXTS ?= $(TAGGED_TMPL_TAG)
|
||||
LOCAL_TMPL += $(foreach e,$(TAGGED_TMPL_EXTS),$(wildcard *.$(TAGGED_TMPL_EXTS)))
|
||||
|
||||
include $(MODDIR)/make/tmpl.mk
|
||||
23
make/tagged-tmpl.mk
Normal file
23
make/tagged-tmpl.mk
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#TAGGED_TMPL_TMPLS ?= $(wildcard $(addprefix $(TAGGED_TMPL_REPO_DIR)/ld/,$(TAGGED_TMPL_TAGS)/*.ld))
|
||||
TAGGED_TMPL_TYPE ?= $(notdir $(CWD))
|
||||
TAGGED_TMPL_EXTS ?= $(TAGGED_TMPL_TYPE)
|
||||
TAGGED_TMPL_TAG_DIR ?= $(TAGGED_TMPL_REPO_DIR)/$(1)/$2 # call with repodir, tag and type arguments
|
||||
TAGGED_TMPL_TAG_DIRS ?= $(foreach tag,$(TAGGED_TMPL_TAGS),$(wildcard $(call $(TAGGED_TMPL_TAG_DIR),$(tag),$(1)))) # call with repodir + type argument
|
||||
TAGGED_TMPL_FIRST_DIR ?= $(firstword $(call $(TAGGED_TMPL_TAG_DIRS),$(1))) # call with repodir + type argument
|
||||
|
||||
#TAGGED_TMPL_ORIGIN ?= $(foreach tag,$(TAGGED_TMPL_TAGS),$(foreach e,$(TAGGED_TMPL_EXTS),$(wildcard $(call $(TAGGED_TMPL_TAG_DIR),$(tag))/*.$(e))))
|
||||
#TAGGED_TMPL_LOCAL = $(notdir $(TAGGED_TMPL_ORIGIN))
|
||||
#TAGGED_TMPL_GENERATED = $(patsubst %.tmpl,%,$(TAGGED_TMPL_LOCAL))
|
||||
|
||||
#TAGGED_TMPL_UNTEMPLATE = cat
|
||||
|
||||
include $(MODDIR)/make/defs.mk
|
||||
|
||||
#all: $(TAGGED_TMPL_GENERATED)
|
||||
#clean: tmpl.clean
|
||||
#
|
||||
#tmpl.clean:
|
||||
# /bin/bash $(MOD_SCRIPT_DIR)/scm.sh -f $(TAGGED_TMPL_GENERATED)
|
||||
#
|
||||
#%: %.tmpl
|
||||
# cat %< | $(TAGGED_TMPL_UNTEMPLATE) > $@.tmp
|
||||
Loading…
Add table
Add a link
Reference in a new issue