Added option to link webpages into the main binary

pull/30/head
Jeroen Domburg 10 years ago
parent ccc179f533
commit cc90701949
  1. 21
      Makefile
  2. 1
      libesphttpd/.gitignore
  3. 12
      libesphttpd/Makefile
  4. 3
      libesphttpd/include/webpages-espfs.h
  5. 5
      user/user_main.c

@ -20,9 +20,10 @@ ESPDELAY ?= 3
ESPBAUD ?= 460800 ESPBAUD ?= 460800
#Position and maximum length of espfs in flash memory #Position and maximum length of espfs in flash memory
ESPFS_POS = 0x12000 #This can be undefined. In this case the webpages will be linked in into the
ESPFS_SIZE = 0x2E000 #file.
#ESPFS_POS = 0x12000
#ESPFS_SIZE = 0x2E000
# name for the target project # name for the target project
@ -35,12 +36,14 @@ MODULES = user
EXTRA_INCDIR = include libesphttpd/include EXTRA_INCDIR = include libesphttpd/include
# libraries used in this project, mainly provided by the SDK # libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal phy pp net80211 wpa main lwip esphttpd LIBS = c gcc hal phy pp net80211 wpa main lwip
#Add in esphttpd lib
LIBS += esphttpd
# compiler flags using during compilation of source files # compiler flags using during compilation of source files
CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \
-nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -D_STDINT_H \ -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -D_STDINT_H \
-Wno-address -DESPFS_POS=$(ESPFS_POS) -DESPFS_SIZE=$(ESPFS_SIZE) -Wno-address
# linker flags used to generate the main object file # linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
@ -97,6 +100,14 @@ ifeq ("$(USE_HEATSHRINK)","yes")
CFLAGS += -DESPFS_HEATSHRINK CFLAGS += -DESPFS_HEATSHRINK
endif endif
ifeq ("$(ESPFS_POS)","")
#No hardcoded espfs position: link it in with the binaries.
LIBS += -lwebpages-espfs
else
#Pass espfs position to rest of code
CFLAGS += -DESPFS_POS=$(ESPFS_POS) -DESPFS_SIZE=$(ESPFS_SIZE)
endif
vpath %.c $(SRC_DIR) vpath %.c $(SRC_DIR)
define compile-objects define compile-objects

@ -7,3 +7,4 @@ espfs/espfstest/*.o
espfs/espfstest/espfstest espfs/espfstest/espfstest
*.DS_Store *.DS_Store
html_compressed/ html_compressed/
libwebpages-espfs.a

@ -50,6 +50,7 @@ SDK_INCDIR = include include/json
CC := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc CC := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
AR := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-ar AR := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-ar
LD := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc LD := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
OBJCOPY := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objcopy
@ -95,7 +96,7 @@ endef
.PHONY: all checkdirs clean webpages.espfs .PHONY: all checkdirs clean webpages.espfs
all: checkdirs $(LIB) webpages.espfs all: checkdirs $(LIB) webpages.espfs libwebpages-espfs.a
$(LIB): $(OBJ) $(LIB): $(OBJ)
@ -124,8 +125,17 @@ else
$(Q) cd ../html; find | $(THISDIR)/espfs/mkespfsimage/mkespfsimage > $(THISDIR)/webpages.espfs; cd .. $(Q) cd ../html; find | $(THISDIR)/espfs/mkespfsimage/mkespfsimage > $(THISDIR)/webpages.espfs; cd ..
endif endif
libwebpages-espfs.a: webpages.espfs
$(Q) $(OBJCOPY) -I binary -O elf32-xtensa-le -B xtensa --rename-section .data=.irom0.literal \
--redefine-sym _binary_webpages_espfs_start=webpages_espfs_start \
--redefine-sym _binary_webpages_espfs_end=webpages_espfs_end \
--redefine-sym _binary_webpages_espfs_size=webpages_espfs_size \
webpages.espfs build/webpages.espfs.o
$(Q) $(AR) cru $@ build/webpages.espfs.o
espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/ espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/
$(Q) $(MAKE) -C espfs/mkespfsimage USE_HEATSHRINK="$(USE_HEATSHRINK)" GZIP_COMPRESSION="$(GZIP_COMPRESSION)" $(Q) $(MAKE) -C espfs/mkespfsimage USE_HEATSHRINK="$(USE_HEATSHRINK)" GZIP_COMPRESSION="$(GZIP_COMPRESSION)"
$(Q) $(AR) cru $@ $^
clean: clean:
$(Q) rm -f $(LIB) $(Q) rm -f $(LIB)

@ -0,0 +1,3 @@
extern char webpages_espfs_start[];
extern char webpages_espfs_end[];
extern int webpages_espfs_size;

@ -21,6 +21,7 @@
#include "auth.h" #include "auth.h"
#include "espfs.h" #include "espfs.h"
#include "captdns.h" #include "captdns.h"
#include "webpages-espfs.h"
//The example can print out the heap use every 3 seconds. You can use this to catch memory leaks. //The example can print out the heap use every 3 seconds. You can use this to catch memory leaks.
//#define SHOW_HEAP_USE //#define SHOW_HEAP_USE
@ -105,7 +106,11 @@ void user_init(void) {
// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
// where image is written in flash that is defined in Makefile. // where image is written in flash that is defined in Makefile.
#ifdef ESPFS_POS
espFsInit((void*)(0x40200000 + ESPFS_POS)); espFsInit((void*)(0x40200000 + ESPFS_POS));
#else
espFsInit((void*)(webpages_espfs_start));
#endif
httpdInit(builtInUrls, 80); httpdInit(builtInUrls, 80);
#ifdef SHOW_HEAP_USE #ifdef SHOW_HEAP_USE
os_timer_disarm(&prHeapTimer); os_timer_disarm(&prHeapTimer);

Loading…
Cancel
Save