From 2e40f0cd130834d1978ba1abdb59e160c52ccfb5 Mon Sep 17 00:00:00 2001 From: Roberto Bucher Date: Fri, 11 Oct 2024 19:09:28 +0200 Subject: [PATCH] nuttx_timehook.tmf fitted to nuttx.tmf --- CodeGen/templates/nuttx_timehook.tmf | 79 +++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/CodeGen/templates/nuttx_timehook.tmf b/CodeGen/templates/nuttx_timehook.tmf index 60e1f6b..419af1e 100644 --- a/CodeGen/templates/nuttx_timehook.tmf +++ b/CodeGen/templates/nuttx_timehook.tmf @@ -1,6 +1,9 @@ MODEL = $$MODEL$$ -all: ../$(MODEL).elf ../$(MODEL) +all: ../$(MODEL).elf ../$(MODEL).bin ../$(MODEL) +# Enable or define during make invocation to embed content of the specified +# directory into ROM filesystem mounted into /etc on the target +#EMBEDROMFS = romfs PYCODEGEN = $(PYSUPSICTRL)/CodeGen MAINDIR = $(PYCODEGEN)/src @@ -9,8 +12,12 @@ INCDIR = $(PYCODEGEN)/nuttx/include NUTTX_EXPORT = $(PYCODEGEN)/nuttx/nuttx-export COMMON_INCDIR = $(PYCODEGEN)/Common/include +SHV_INC = $(PYCODEGEN)/Common/shv/include +ULUT_INC = $(PYSUPSICTRL)/ExtLibs/ulut +EXT_SHV_INC = $(PYSUPSICTRL)/ExtLibs//libshv/libshvchainpack/c/include + RM = rm -f -FILES_TO_CLEAN = *.o $(MODEL) $(MODEL).elf +FILES_TO_CLEAN = *.o $(MODEL) $(MODEL).elf $(MAIN)-builtintab.c ifndef NUTTX_EXPORT $(warning Specify NUTTX_EXPORT) @@ -33,6 +40,9 @@ NUTTX_INCLUDES = -isystem $(NUTTX_EXPORT)/include ifneq ($(filter -Wl%, $(NXFLATLDFLAGS1)$(NXFLATLDFLAGS2)),) GCC_LD_OPTION = -Wl, +LD_RAW ?= $(CROSSDEV)ld +else +LD_RAW ?= $(LD) endif ifeq ($(LDSTARTGROUP),) @@ -45,8 +55,12 @@ ELF_MODULE_LIBS = $(LDSTARTGROUP) $(EXTRA_LIBS) $(LDENDGROUP) LDFLAGS += -L $(NUTTX_EXPORT)/libs +ifneq ($(shell $(CC) --target-help | grep -e '-mlong-calls\b'),) +TARGET_ARCH_LONG_CALLS = -mlong-calls +endif + TARGET_ARCH_FLAGS ?= $(ARCHCFLAGS) $(ARCHCPUFLAGS) \ - -mlong-calls -fno-common -DWITHOUT_MLOCK + $(TARGET_ARCH_LONG_CALLS) -fno-common -DWITHOUT_MLOCK DEFAULT_OPT_OPTS ?= $(ARCHOPTIMIZATION) @@ -54,9 +68,9 @@ ifndef OPT_OPTS OPT_OPTS = $(DEFAULT_OPT_OPTS) endif -LD_SCRIPT = $(NUTTX_EXPORT)/scripts/$(LDNAME) +LD_SCRIPTS = $(LDNAME:%=$(NUTTX_EXPORT)/scripts/%) -LDFLAGS += -T $(LD_SCRIPT) +LDFLAGS_LD_SCRIPTS += $(LD_SCRIPTS:%=-T %) LDFLAGS += --entry=__start @@ -65,6 +79,41 @@ ELF_FILE_LDSCRIPT ?= $(wildcard $(NUTTX_EXPORT)/scripts/gnu-elf.ld) MAIN = nuttx_main_timehook ADD_FILES = $$ADD_FILES$$ +ifneq ($(EMBEDROMFS),) +ifeq ($(shell grep CONFIG_ETC_ROMFSMOUNTPT $(NUTTX_EXPORT)/include/nuttx/config.h),) +$(error CONFIG_ETC_ROMFS and CONFIG_ETC_ROMFSMOUNTPT are required for EMBEDROMFS) +endif +ifeq ($(wildcard $(abspath $(EMBEDROMFS))),) +EMBEDROMFS_ABS=$(abspath ../$(EMBEDROMFS)) +ifeq ($(wildcard $(EMBEDROMFS_ABS)),) +$(error Specified EMBEDROMFS=$(EMBEDROMFS) is not found) +endif +else +EMBEDROMFS_ABS=$(abspath $(EMBEDROMFS)) +endif +romfs_img_len_encode.c: Makefile + echo >$@ \ + "#include \n\ + extern uint8_t romfs_img_size[];\ + const unsigned int romfs_img_len = (uintptr_t)romfs_img_size;" +romfs_img: $(shell find "$(EMBEDROMFS_ABS)" -type f,d) Makefile + rm -f $@.tmp + genromfs -f romfs_img.tmp -V romfs -d $< + if ( [ ! -e $@ ] || ! cmp -s $@.tmp $@ ) ; then cp $@.tmp $@ ; fi +romfs_img.o: romfs_img + rm -f romfs_img.o.tmp + $(LD_RAW) -r --accept-unknown-input-arch -b binary \ + $(filter -m%,$(LDFLAGS:$(GCC_LD_OPTION)%=%)) \ + --defsym=romfs_img_size=_binary_romfs_img_size \ + --defsym=romfs_img=_binary_romfs_img_start \ + --defsym=romfs_img_start=_binary_romfs_img_start \ + --defsym=romfs_img_end=_binary_romfs_img_end \ + -o $@.tmp $< + $(OBJCOPY) --rename-section .data=.rodata,alloc,load,readonly,data,contents \ + $@.tmp $@ +ADD_FILES += romfs_img.o romfs_img_len_encode.o +endif + OBJSSTAN = $(MAIN).o $(MODEL).o $(ADD_FILES) ifeq ($(NUTTX_REGISTER_BINARIES),y) @@ -94,6 +143,15 @@ INCLUDES += -I$(INCDIR) -I$(COMMON_INCDIR) $(NUTTX_INCLUDES) CFLAGS = $(TARGET_ARCH_FLAGS) $(ARCHWARNINGS) $(OPT_OPTS) $(INCLUDES) -DMODEL=$(MODEL) +CFLAGS += -I$(SHV_INC) +ifneq ($(wildcard $(ULUT_INC)),) +ULUT_INC = $(PYSUPSICTRL)/ExtLibs/ulut +CFLAGS += -I$(ULUT_INC) +endif +ifneq ($(wildcard $(EXT_SHV_INC)),) +CFLAGS += -I$(EXT_SHV_INC) +endif + CXXFLAGS = $(TARGET_ARCH_FLAGS) $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(OPT_OPTS) $(INCLUDES) -DMODEL=$(MODEL) LIB = $(LIBDIR)/libpyblk.a @@ -108,18 +166,23 @@ $(MAIN).c: $(MAINDIR)/$(MAIN).c $(MODEL).c [ ! -e $(ELF_FILE_LDSCRIPT) ] || \ $(LD) $(LDFLAGS) $(ADDITIONAL_LDFLAGS) -o $@ \ -r -e main -T $(ELF_FILE_LDSCRIPT) \ - $(GCC_LD_OPTION)-Map $(GCC_LD_OPTION)$(1).elf.map \ + $(GCC_LD_OPTION)-Map $(GCC_LD_OPTION)$(notdir $@).map \ $(OBJSSTAN) $(LIB) $(LIBS) $(ELF_MODULE_LIBS) @echo "### Created ELF loadable file: $(MODEL).elf" ../$(MODEL): $(OBJSSTAN) $(OBJSSYSOVERRIDE) $(LIB) - $(LD) $(LDFLAGS) $(ADDITIONAL_LDFLAGS) \ - -o $@ $(OBJSSTAN) $(OBJSSYSOVERRIDE) $(LIB) $(SYSTEM_LIBS) + $(LD) $(LDFLAGS) $(ADDITIONAL_LDFLAGS) $(LDFLAGS_LD_SCRIPTS) \ + -o $@ $(HEAD_OBJ:%=$(NUTTX_EXPORT)/startup/%) \ + $(OBJSSTAN) $(OBJSSYSOVERRIDE) $(LIB) $(SYSTEM_LIBS) @echo "### Created executable: $(MODEL)" ../$(MODEL).hex : ../$(MODEL) $(OBJCOPY) $(OBJCOPYARGS) -O ihex $< $@ +../$(MODEL).bin : ../$(MODEL) + $(OBJCOPY) $(OBJCOPYARGS) -O binary $< $@ + @echo "### Created raw binary: $(MODEL).bin" + clean: @$(RM) $(FILES_TO_CLEAN) \ No newline at end of file