Skip to content

Commit

Permalink
Merge pull request #76 from ppisa/nuttx-embedromfs
Browse files Browse the repository at this point in the history
CodeGen/nuttx: optional ROMFS content can be mounted into /etc on target
  • Loading branch information
robertobucher authored Apr 20, 2024
2 parents b3f9221 + a7d5a36 commit e6c2d6f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions CodeGen/templates/nuttx.tmf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
MODEL = $$MODEL$$
all: ../$(MODEL).elf ../$(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 Down Expand Up @@ -37,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 Down Expand Up @@ -73,6 +79,41 @@ ELF_FILE_LDSCRIPT ?= $(wildcard $(NUTTX_EXPORT)/scripts/gnu-elf.ld)
MAIN = nuttx_main
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

0 comments on commit e6c2d6f

Please sign in to comment.