From 6f1ab3059a21a2bdfd1cc31354efc63f40c58176 Mon Sep 17 00:00:00 2001 From: con-f-use Date: Wed, 3 Aug 2016 16:27:10 +0200 Subject: [PATCH] Clean up Makefiles --- embedded8266/Makefile | 126 +++++++++++++++++++------------------- embedded8266/web/Makefile | 16 +++-- 2 files changed, 72 insertions(+), 70 deletions(-) diff --git a/embedded8266/Makefile b/embedded8266/Makefile index faab843..ad32e95 100644 --- a/embedded8266/Makefile +++ b/embedded8266/Makefile @@ -1,10 +1,29 @@ -FW_FILE_1:=0x00000.bin -FW_FILE_2:=0x40000.bin -TARGET_OUT:=image.elf -all : $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) +############################################################################### +# USER OPTIONS +############################################################################### +CHIP ?= 8266 +IP ?= 192.168.4.1 +PORT ?= /dev/ttyUSB0 +#PORT ?= /dev/ttyACM0 -SRCS:=driver/uart.c \ +ESP_ROOT ?= $(HOME)/esp8266/esp-open-sdk +GCC_VERS ?= 4.8.5 + +OPTS += -DICACHE_FLASH +#OPTS += -DFREQ=12500 + +###########################################################################VARS + +.PHONY : all clean cleanall netburn burnweb burn +uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) + +FW_FILE_1 = 0x00000.bin +FW_FILE_2 = 0x40000.bin +TARGET = image.elf + +SRCS = \ + driver/uart.c \ common/mystuff.c \ common/flash_rewriter.c \ common/http.c \ @@ -20,88 +39,67 @@ SRCS:=driver/uart.c \ user/user_main.c \ common/commonservices.c -GCC_FOLDER:=~/esp8266/esp-open-sdk/xtensa-lx106-elf -ESPTOOL_PY:=~/esp8266/esptool/esptool.py -FW_TOOL:=~/esp8266/other/esptool/esptool -SDK:=/home/cnlohr/esp8266/esp_iot_sdk_v1.5.1 -PORT:=/dev/ttyUSB0 -#PORT:=/dev/ttyACM0 +LIBS = main lwip ssl upgrade net80211 wpa net80211 phy lwip pp crypto +INCL = $(SDK)/include myclib include . -XTLIB:=$(SDK)/lib -XTGCCLIB:=$(GCC_FOLDER)/lib/gcc/xtensa-lx106-elf/4.8.2/libgcc.a -FOLDERPREFIX:=$(GCC_FOLDER)/bin -PREFIX:=$(FOLDERPREFIX)/xtensa-lx106-elf- -CC:=$(PREFIX)gcc +GCC_FOLDER = $(ESP_ROOT)/xtensa-lx106-elf +ESPTOOL_PY = $(ESP_ROOT)/esptool/esptool.py +FW_TOOL = $(ESP_ROOT)/../esptool-ck/esptool +SDK = $(ESP_ROOT)/sdk -CFLAGS:=-mlongcalls -I$(SDK)/include -Imyclib -Iinclude -Iuser -Os -I$(SDK)/include/ -I../embeddedcommon -I. -Icommon -DICACHE_FLASH +XTLIB = $(SDK)/lib +XTGCCLIB = $(GCC_FOLDER)/lib/gcc/xtensa-lx106-elf/$(GCC_VERS)/libgcc.a +PREFIX = $(GCC_FOLDER)/bin/xtensa-lx106-elf- +CC = $(PREFIX)gcc +LD = $(PREFIX)ld -#-DFREQ==12500 seems to work well. - - -LDFLAGS_CORE:=\ - -nostdlib \ - -L$(XTLIB) \ - -L$(XTGCCLIB) \ - $(SDK)/lib/libmain.a \ - $(SDK)/lib/liblwip.a \ - $(SDK)/lib/libssl.a \ - $(SDK)/lib/libupgrade.a \ - $(SDK)/lib/libnet80211.a \ - $(SDK)/lib/libwpa.a \ - $(SDK)/lib/libnet80211.a \ - $(SDK)/lib/libphy.a \ - $(SDK)/lib/liblwip.a \ - $(SDK)/lib/libpp.a \ - $(SDK)/lib/libcrypto.a \ - $(SDK)/lib/libmain.a \ - $(XTGCCLIB) \ - -T $(SDK)/ld/eagle.app.v6.ld \ - -Wl,-Map,output.map \ +CFLAGS = -mlongcalls -Os $(addprefix -I,$(INCL) $(call uniq, $(patsubst %/,%,$(dir $(SRCS))))) $(OPTS) +LDFLAGS_CORE = -nostdlib -L$(XTLIB) -L$(XTGCCLIB) \ + $(addprefix $(SDK)/lib/lib,$(addsuffix .a,$(LIBS))) \ + $(XTGCCLIB) -T $(SDK)/ld/eagle.app.v6.ld -Wl,-Map,output.map # -flto -Wl,--relax -Wl,--gc-sections +LINKFLAGS = $(LDFLAGS_CORE) -B$(XTLIB) -LINKFLAGS:= \ - $(LDFLAGS_CORE) \ - -B$(XTLIB) +##########################################################################RULES -#image.elf : $(OBJS) -# $(PREFIX)ld $^ $(LDFLAGS) -o $@ +all : $(FW_FILE_1) $(FW_FILE_2) -$(TARGET_OUT) : $(SRCS) - $(PREFIX)gcc $(CFLAGS) $^ $(LINKFLAGS) -o $@ - - - -$(FW_FILE_1): $(TARGET_OUT) +$(FW_FILE_1): $(TARGET) @echo "FW $@" - $(FW_TOOL) -eo $(TARGET_OUT) -bo $@ -bs .text -bs .data -bs .rodata -bc -ec + $(FW_TOOL) -eo $(TARGET) -bo $@ -bs .text -bs .data -bs .rodata -bc -ec -$(FW_FILE_2): $(TARGET_OUT) +$(FW_FILE_2): $(TARGET) @echo "FW $@" - $(FW_TOOL) -eo $(TARGET_OUT) -es .irom0.text $@ -ec + $(FW_TOOL) -eo $(TARGET) -es .irom0.text $@ -ec +$(TARGET) : $(SRCS) + $(CC) $(CFLAGS) $^ $(LINKFLAGS) -o $@ +# $(LD) $^ $(LDFLAGS) -o $@ + +ifeq ($(CHIP), 8285) burn : $(FW_FILE_1) $(FW_FILE_2) - #($(ESPTOOL_PY) --port $(PORT) write_flash 0x00000 0x00000.bin 0x40000 0x40000.bin)||(true) #for '8266 - ($(ESPTOOL_PY) --port $(PORT) write_flash -fs 8m -fm dout 0x00000 0x00000.bin 0x40000 0x40000.bin)||(true) #for '8285 - - + ($(ESPTOOL_PY) --port $(PORT) write_flash -fs 8m -fm dout 0x00000 0x00000.bin 0x40000 0x40000.bin)||(true) +else ifeq ($(CHIP), 8266) +burn : $(FW_FILE_1) $(FW_FILE_2) + ($(ESPTOOL_PY) --port $(PORT) write_flash 0x00000 0x00000.bin 0x40000 0x40000.bin)||(true) +else + $(error Error: Unknown chip '$(CHIP)') +endif #If you have space, MFS should live at 0x100000, if you don't it can also live at -#0x10000. But, then it is limited to 180kB. You might need to do this if you have a 512kB +#0x10000. But, then it is limited to 180kB. You might need to do this if you have a 512kB #ESP variant. burnweb : web/page.mpfs ($(ESPTOOL_PY) --port $(PORT) write_flash 0x10000 web/page.mpfs)||(true) - - -IP?=192.168.4.1 - netburn : image.elf $(FW_FILE_1) $(FW_FILE_2) web/execute_reflash $(IP) 0x00000.bin 0x40000.bin clean : - rm -rf user/*.o driver/*.o $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) - + $(RM) $(patsubst %.c,%.o,$(SRCS)) $(TARGET) +purge : clean + $(RM) $(FW_FILE_1) $(FW_FILE_2) diff --git a/embedded8266/web/Makefile b/embedded8266/web/Makefile index b46322f..af3c982 100644 --- a/embedded8266/web/Makefile +++ b/embedded8266/web/Makefile @@ -1,23 +1,27 @@ -all : execute_reflash page.mpfs push +IP ?= 192.168.4.1 -IP?=192.168.4.1 +.PHONY : all clean push + +CFLAGS = -std=gnu99 -Wall -Wextra -O2 -march=native + +all : execute_reflash page.mpfs push mfsmaker : mfsmaker.c - gcc -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ page.mpfs : mfsmaker page # cat to_compress/*.js | gzip -9 > page/compressed.js.gz ./mfsmaker page page.mpfs pushtodev : pushtodev.c - gcc -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ execute_reflash : execute_reflash.c md5.c - gcc -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ push : pushtodev page.mpfs ./pushtodev $(IP) 65536 page.mpfs # ./pushtodev $(IP) 1048576 page.mpfs clean : - rm -rf mfsmaker page.mpfs pushtodev execute_reflash + $(RM) mfsmaker page.mpfs pushtodev execute_reflash