Skip to content

Commit

Permalink
nuttx_timehook.tmf fitted to nuttx.tmf
Browse files Browse the repository at this point in the history
  • Loading branch information
robertobucher committed Oct 11, 2024
1 parent 2c35228 commit 2e40f0c
Showing 1 changed file with 71 additions and 8 deletions.
79 changes: 71 additions & 8 deletions CodeGen/templates/nuttx_timehook.tmf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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),)
Expand All @@ -45,18 +55,22 @@ 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)

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

Expand All @@ -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 <stdint.h>\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 [email protected]
genromfs -f romfs_img.tmp -V romfs -d $<
if ( [ ! -e $@ ] || ! cmp -s [email protected] $@ ) ; then cp [email protected] $@ ; 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 [email protected] $<
$(OBJCOPY) --rename-section .data=.rodata,alloc,load,readonly,data,contents \
[email protected] $@
ADD_FILES += romfs_img.o romfs_img_len_encode.o
endif

OBJSSTAN = $(MAIN).o $(MODEL).o $(ADD_FILES)

ifeq ($(NUTTX_REGISTER_BINARIES),y)
Expand Down Expand Up @@ -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
Expand All @@ -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)

0 comments on commit 2e40f0c

Please sign in to comment.