mirror of
https://github.com/nodemcu/nodemcu-firmware.git
synced 2025-01-30 21:12:55 +08:00
f3e2a3afd9
This compiles, links, and starts the RTOS without crashing and burning. Lua environment does not yet start due to the different task architecture. Known pain points: - task implementation needs to be rewritten for RTOS (next up on my TODO) - secure espconn does not exist, all secure espconn stuff has been #if 0'd - lwip now built from within the RTOS SDK, but does not appear to include MDNS support. Investigation needed. - there is no access to FRC1 NMI, not sure if we ever actually used that however. Also #if 0'd out for now. - new timing constraints introduced by the RTOS, all use of ets_delay_us() and os_delay_us() needs to be reviewed (the tsl2561 driver in particular). - even more confusion with ets_ vs os_ vs c_ vs non-prefixed versions. In the long run everything should be switched to non-prefixed versions. - system_set_os_print() not available, needs to be reimplemented - all the RTOS rodata is loaded into RAM, as it apparently uses some constants while the flash isn't mapped, so our exception handler can't work its magic. This should be narrowed down to the minimum possible at some point. - with each task having its own stack in RTOS, we probably need change flash-page buffers from the stack to the heap in a bunch of places. A single, shared, page buffer *might* be possible if we limit ourselves to running NodeMCU in a single task. - there's a ton of junk in the sdk-overrides now; over time the core code should be updated to not need those shims
214 lines
6.5 KiB
Makefile
214 lines
6.5 KiB
Makefile
# copyright (c) 2010 Espressif System
|
|
# 2015-2016 NodeMCU team
|
|
#
|
|
.NOTPARALLEL:
|
|
|
|
# Ensure we search "our" SDK before the tool-chain's SDK (if any)
|
|
TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
|
|
SDK_DIR:=$(TOP_DIR)/rtos-sdk
|
|
|
|
# This is, sadly, the cleanest way to resolve the different non-standard
|
|
# conventions for sized integers across the various components.
|
|
BASIC_TYPES=-Du32_t=uint32_t -Du16_t=uint16_t -Du8_t=uint8_t -Duint32=uint32_t -Duint16=uint16_t -Duint8=uint8_t -Dsint32=int32_t -Dsint16=int16_t -Dsint8=int8_t
|
|
|
|
# Include dirs, ensure the overrides come first
|
|
INCLUDE_DIRS=$(TOP_DIR)/sdk-overrides/include $(SDK_DIR)/include $(SDK_DIR)/include/espressif $(SDK_DIR)/include/lwip $(SDK_DIR)/include/lwip/ipv4 $(SDK_DIR)/include/lwip/ipv6 $(SDK_DIR)/extra_include
|
|
|
|
# ... and we have to mark them all as system include dirs rather than the usual
|
|
# -I for user include dir, or the esp-open-sdk toolchain headers wreak havoc
|
|
CCFLAGS:=$(addprefix -isystem,$(INCLUDE_DIRS)) $(BASIC_TYPES)
|
|
|
|
LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -L$(SDK_DIR)/third_party/lwip/.output/eagle/debug/lib $(LDFLAGS)
|
|
|
|
|
|
#############################################################
|
|
ifndef COMPORT
|
|
ESPPORT = /dev/ttyUSB0
|
|
else
|
|
ESPPORT = $(COMPORT)
|
|
endif
|
|
CCFLAGS += -Os -ffunction-sections -fno-jump-tables -fdata-sections
|
|
AR = xtensa-lx106-elf-ar
|
|
CC = xtensa-lx106-elf-gcc
|
|
NM = xtensa-lx106-elf-nm
|
|
CPP = xtensa-lx106-elf-cpp
|
|
OBJCOPY = xtensa-lx106-elf-objcopy
|
|
FIRMWAREDIR = ../bin/
|
|
|
|
#############################################################
|
|
ESPTOOL ?= ../tools/esptool.py
|
|
|
|
|
|
CSRCS ?= $(wildcard *.c)
|
|
ASRCs ?= $(wildcard *.s)
|
|
ASRCS ?= $(wildcard *.S)
|
|
SUBDIRS ?= $(filter-out rtos-sdk, $(patsubst %/,%,$(dir $(wildcard */Makefile))))
|
|
|
|
ODIR := .output
|
|
OBJODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/obj
|
|
|
|
OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \
|
|
$(ASRCs:%.s=$(OBJODIR)/%.o) \
|
|
$(ASRCS:%.S=$(OBJODIR)/%.o)
|
|
|
|
DEPS := $(CSRCS:%.c=$(OBJODIR)/%.d) \
|
|
$(ASRCs:%.s=$(OBJODIR)/%.d) \
|
|
$(ASRCS:%.S=$(OBJODIR)/%.d)
|
|
|
|
LIBODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/lib
|
|
OLIBS := $(GEN_LIBS:%=$(LIBODIR)/%)
|
|
|
|
IMAGEODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/image
|
|
OIMAGES := $(GEN_IMAGES:%=$(IMAGEODIR)/%)
|
|
|
|
BINODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/bin
|
|
OBINS := $(GEN_BINS:%=$(BINODIR)/%)
|
|
|
|
#
|
|
# Note:
|
|
# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
|
|
# If you add global optimize options like "-O2" here
|
|
# they will override "-Os" defined above.
|
|
# "-Os" should be used to reduce code size
|
|
#
|
|
CCFLAGS += \
|
|
-g \
|
|
-Wpointer-arith \
|
|
-Wundef \
|
|
-Werror \
|
|
-Wl,-EL \
|
|
-fno-inline-functions \
|
|
-nostdlib \
|
|
-mlongcalls \
|
|
-mtext-section-literals
|
|
# -Wall
|
|
|
|
CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
|
|
DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
|
|
|
|
|
|
#############################################################
|
|
# Functions
|
|
#
|
|
|
|
define ShortcutRule
|
|
$(1): .subdirs $(2)/$(1)
|
|
endef
|
|
|
|
define MakeLibrary
|
|
DEP_LIBS_$(1) = $$(foreach lib,$$(filter %.a,$$(COMPONENTS_$(1))),$$(dir $$(lib))$$(LIBODIR)/$$(notdir $$(lib)))
|
|
DEP_OBJS_$(1) = $$(foreach obj,$$(filter %.o,$$(COMPONENTS_$(1))),$$(dir $$(obj))$$(OBJODIR)/$$(notdir $$(obj)))
|
|
$$(LIBODIR)/$(1).a: $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1)) $$(DEPENDS_$(1))
|
|
@mkdir -p $$(LIBODIR)
|
|
$$(if $$(filter %.a,$$?),mkdir -p $$(EXTRACT_DIR)_$(1))
|
|
$$(if $$(filter %.a,$$?),cd $$(EXTRACT_DIR)_$(1); $$(foreach lib,$$(filter %.a,$$?),$$(AR) xo $$(UP_EXTRACT_DIR)/$$(lib);))
|
|
$$(AR) ru $$@ $$(filter %.o,$$?) $$(if $$(filter %.a,$$?),$$(EXTRACT_DIR)_$(1)/*.o)
|
|
$$(if $$(filter %.a,$$?),$$(RM) -r $$(EXTRACT_DIR)_$(1))
|
|
endef
|
|
|
|
define MakeImage
|
|
DEP_LIBS_$(1) = $$(foreach lib,$$(filter %.a,$$(COMPONENTS_$(1))),$$(dir $$(lib))$$(LIBODIR)/$$(notdir $$(lib)))
|
|
DEP_OBJS_$(1) = $$(foreach obj,$$(filter %.o,$$(COMPONENTS_$(1))),$$(dir $$(obj))$$(OBJODIR)/$$(notdir $$(obj)))
|
|
$$(IMAGEODIR)/$(1).out: $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1)) $$(DEPENDS_$(1))
|
|
@mkdir -p $$(IMAGEODIR)
|
|
$$(CC) $$(LDFLAGS) $$(if $$(LINKFLAGS_$(1)),$$(LINKFLAGS_$(1)),$$(LINKFLAGS_DEFAULT) $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1))) -o $$@
|
|
endef
|
|
|
|
$(BINODIR)/%.bin: $(IMAGEODIR)/%.out
|
|
@mkdir -p $(BINODIR)
|
|
$(ESPTOOL) elf2image $< -o $(FIRMWAREDIR)
|
|
|
|
#############################################################
|
|
# Rules base
|
|
# Should be done in top-level makefile only
|
|
#
|
|
|
|
all: sdk_built pre_build .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS)
|
|
|
|
.PHONY: sdk_built
|
|
sdk_built:
|
|
$(MAKE) -C $(SDK_DIR)/third_party/lwip SDK_PATH=$(SDK_DIR) -j1
|
|
|
|
clean:
|
|
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;)
|
|
$(RM) -r $(ODIR)/$(TARGET)/$(FLAVOR)
|
|
$(RM) -r "$(TOP_DIR)/sdk"
|
|
|
|
clobber: $(SPECIAL_CLOBBER)
|
|
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clobber;)
|
|
$(RM) -r $(ODIR)
|
|
|
|
flash:
|
|
ifndef PDIR
|
|
$(MAKE) -C ./app flash
|
|
else
|
|
$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 $(FIRMWAREDIR)0x00000.bin 0x10000 $(FIRMWAREDIR)0x10000.bin
|
|
endif
|
|
|
|
.subdirs: | sdk_built
|
|
@set -e; $(foreach d, $(SUBDIRS), $(MAKE) -C $(d);)
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
ifneq ($(MAKECMDGOALS),clobber)
|
|
ifdef DEPS
|
|
sinclude $(DEPS)
|
|
endif
|
|
endif
|
|
endif
|
|
|
|
.PHONY: pre_build
|
|
|
|
ifneq ($(wildcard $(TOP_DIR)/server-ca.crt),)
|
|
pre_build:
|
|
python $(TOP_DIR)/tools/make_server_cert.py $(TOP_DIR)/server-ca.crt > $(TOP_DIR)/app/modules/server-ca.crt.h
|
|
DEFINES += -DHAVE_SSL_SERVER_CRT=\"server-ca.crt.h\"
|
|
else
|
|
pre_build:
|
|
@-rm -f $(TOP_DIR)/app/modules/server-ca.crt.h
|
|
endif
|
|
|
|
|
|
$(OBJODIR)/%.o: %.c
|
|
@mkdir -p $(OBJODIR);
|
|
$(CC) $(if $(findstring $<,$(DSRCS)),$(DFLAGS),$(CFLAGS)) $(COPTS_$(*F)) -o $@ -c $<
|
|
|
|
$(OBJODIR)/%.d: %.c
|
|
@mkdir -p $(OBJODIR);
|
|
@echo DEPEND: $(CC) -M $(CFLAGS) $<
|
|
@set -e; rm -f $@; \
|
|
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
|
|
sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
|
|
rm -f $@.$$$$
|
|
|
|
$(OBJODIR)/%.o: %.s
|
|
@mkdir -p $(OBJODIR);
|
|
$(CC) $(CFLAGS) -o $@ -c $<
|
|
|
|
$(OBJODIR)/%.d: %.s
|
|
@mkdir -p $(OBJODIR); \
|
|
set -e; rm -f $@; \
|
|
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
|
|
sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
|
|
rm -f $@.$$$$
|
|
|
|
$(OBJODIR)/%.o: %.S
|
|
@mkdir -p $(OBJODIR);
|
|
$(CC) $(CFLAGS) -D__ASSEMBLER__ -o $@ -c $<
|
|
|
|
$(OBJODIR)/%.d: %.S
|
|
@mkdir -p $(OBJODIR); \
|
|
set -e; rm -f $@; \
|
|
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
|
|
sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
|
|
rm -f $@.$$$$
|
|
|
|
$(foreach lib,$(GEN_LIBS),$(eval $(call ShortcutRule,$(lib),$(LIBODIR))))
|
|
|
|
$(foreach image,$(GEN_IMAGES),$(eval $(call ShortcutRule,$(image),$(IMAGEODIR))))
|
|
|
|
$(foreach bin,$(GEN_BINS),$(eval $(call ShortcutRule,$(bin),$(BINODIR))))
|
|
|
|
$(foreach lib,$(GEN_LIBS),$(eval $(call MakeLibrary,$(basename $(lib)))))
|
|
|
|
$(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image)))))
|