|
| 1 | +# Makefile to compile the flasher stub program |
| 2 | +# |
| 3 | +# Note that YOU DO NOT NEED TO COMPILE THIS IN ORDER TO JUST USE |
| 4 | +# esptool.py - a precompiled version is included in esptool.py, |
| 5 | +# so if you don't want to modify the stub code then you are good to go. |
| 6 | +# |
| 7 | +# See the comments in the top of the Makefile for parameters that |
| 8 | +# you probably want to override. |
| 9 | +# |
| 10 | +# Copyright (c) 2016 Cesanta Software Limited & Angus Gratton |
| 11 | +# All rights reserved |
| 12 | +# |
| 13 | +# |
| 14 | +# This program is free software; you can redistribute it and/or modify it under |
| 15 | +# the terms of the GNU General Public License as published by the Free Software |
| 16 | +# Foundation; either version 2 of the License, or (at your option) any later version. |
| 17 | +# |
| 18 | +# This program is distributed in the hope that it will be useful, but WITHOUT |
| 19 | +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 20 | +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 21 | +# |
| 22 | +# You should have received a copy of the GNU General Public License along with |
| 23 | +# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin |
| 24 | +# Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 25 | + |
| 26 | +# Adapted from Cesanta's original Makefile at |
| 27 | +# https://github.com/cesanta/fnc/tree/master/common/platforms/esp8266/stubs |
| 28 | + |
| 29 | +# Override these variables on the command line |
| 30 | +# or set them in a local.mk |
| 31 | +-include local.mk |
| 32 | + |
| 33 | +# Prefix for each cross compiler (can include a directory path) |
| 34 | +# These can be overridden via environment variables or on the make command line |
| 35 | +CROSS_8266 ?= xtensa-lx106-elf- |
| 36 | +CROSS_32 ?= xtensa-esp32-elf- |
| 37 | +CROSS_32S2 ?= xtensa-esp32s2-elf- |
| 38 | +CROSS_32S3 ?= xtensa-esp32s3-elf- |
| 39 | +CROSS_ESPRISCV32 ?= riscv32-esp-elf- |
| 40 | + |
| 41 | +# extra CFLAGS to be passed on the compiler, in addition to the stock ones |
| 42 | +EXTRA_CFLAGS ?= |
| 43 | +EXTRA_CFLAGS_ESPRISCV32 ?= |
| 44 | + |
| 45 | +# Python command to invoke wrap_stub.py |
| 46 | +WRAP_STUB ?= ./wrap_stub.py |
| 47 | + |
| 48 | +# Pass V=1 to see the commands being executed by make |
| 49 | +ifneq ("$(V)","1") |
| 50 | +Q = @ |
| 51 | +endif |
| 52 | + |
| 53 | +STUB = esp |
| 54 | +SRCS = stub_flasher.c slip.c stub_commands.c stub_write_flash.c stub_io.c |
| 55 | +SRCS_8266 = miniz.c |
| 56 | + |
| 57 | +BUILD_DIR = build |
| 58 | +ESPTOOL_STUBS_DIR = .. |
| 59 | + |
| 60 | +STUB_ELF_8266 = $(BUILD_DIR)/$(STUB)8266.elf |
| 61 | +STUB_ELF_32 = $(BUILD_DIR)/$(STUB)32.elf |
| 62 | +STUB_ELF_32S2 = $(BUILD_DIR)/$(STUB)32s2.elf |
| 63 | +STUB_ELF_32S3_BETA_2 = $(BUILD_DIR)/$(STUB)32s3beta2.elf |
| 64 | +STUB_ELF_32S3 = $(BUILD_DIR)/$(STUB)32s3.elf |
| 65 | +STUB_ELF_32C3 = $(BUILD_DIR)/$(STUB)32c3.elf |
| 66 | +STUB_ELF_32C6BETA = $(BUILD_DIR)/$(STUB)32c6beta.elf |
| 67 | +STUB_ELF_32H2_BETA_1 = $(BUILD_DIR)/$(STUB)32h2beta1.elf |
| 68 | +STUB_ELF_32H2_BETA_2 = $(BUILD_DIR)/$(STUB)32h2beta2.elf |
| 69 | +STUB_ELF_32C2 = $(BUILD_DIR)/$(STUB)32c2.elf |
| 70 | +STUB_ELF_32C6 = $(BUILD_DIR)/$(STUB)32c6.elf |
| 71 | +STUB_ELF_32C61 = $(BUILD_DIR)/$(STUB)32c61.elf |
| 72 | +STUB_ELF_32C5 = $(BUILD_DIR)/$(STUB)32c5.elf |
| 73 | +STUB_ELF_32C5_BETA_3 = $(BUILD_DIR)/$(STUB)32c5beta3.elf |
| 74 | +STUB_ELF_32H2 = $(BUILD_DIR)/$(STUB)32h2.elf |
| 75 | +STUB_ELF_32P4 = $(BUILD_DIR)/$(STUB)32p4.elf |
| 76 | + |
| 77 | +STUBS_ELF = |
| 78 | +ifneq ($(WITHOUT_ESP8266),1) |
| 79 | +STUBS_ELF += \ |
| 80 | + $(STUB_ELF_8266) |
| 81 | +endif |
| 82 | + |
| 83 | +ifneq ($(WITHOUT_ESP32_XTENSA),1) |
| 84 | +STUBS_ELF += \ |
| 85 | + $(STUB_ELF_32) \ |
| 86 | + $(STUB_ELF_32S2) \ |
| 87 | + $(STUB_ELF_32S3_BETA_2) \ |
| 88 | + $(STUB_ELF_32S3) |
| 89 | +endif |
| 90 | + |
| 91 | +ifneq ($(WITHOUT_ESP32_RISCV32),1) |
| 92 | +STUBS_ELF += \ |
| 93 | + $(STUB_ELF_32C3) \ |
| 94 | + $(STUB_ELF_32C6BETA) \ |
| 95 | + $(STUB_ELF_32H2_BETA_1) \ |
| 96 | + $(STUB_ELF_32H2_BETA_2) \ |
| 97 | + $(STUB_ELF_32C2) \ |
| 98 | + $(STUB_ELF_32C6) \ |
| 99 | + $(STUB_ELF_32C61) \ |
| 100 | + $(STUB_ELF_32C5) \ |
| 101 | + $(STUB_ELF_32C5_BETA_3) \ |
| 102 | + $(STUB_ELF_32H2) \ |
| 103 | + $(STUB_ELF_32P4) |
| 104 | +endif |
| 105 | + |
| 106 | +.PHONY: all clean install |
| 107 | + |
| 108 | +all: $(STUBS_ELF:.elf=.json) |
| 109 | + |
| 110 | +install: $(patsubst $(BUILD_DIR)/%.elf,$(ESPTOOL_STUBS_DIR)/%.json,$(STUBS_ELF)) |
| 111 | + |
| 112 | +$(BUILD_DIR): |
| 113 | + $(Q) mkdir $@ |
| 114 | + |
| 115 | +$(BUILD_DIR)/%.json: $(BUILD_DIR)/%.elf |
| 116 | + @echo " WRAP $^ -> $(BUILD_DIR)" |
| 117 | + $(Q) $(WRAP_STUB) $^ |
| 118 | + |
| 119 | +$(ESPTOOL_STUBS_DIR)/%.json: $(BUILD_DIR)/%.json |
| 120 | + @echo " INSTALL $^ -> $@" |
| 121 | + $(Q) cp $^ $@ |
| 122 | + |
| 123 | +CFLAGS = -std=c99 -Wall -Werror -Os \ |
| 124 | + -mtext-section-literals -mlongcalls -nostdlib -fno-builtin -flto \ |
| 125 | + -Wl,-static -g -ffunction-sections -Wl,--gc-sections -Iinclude -Lld \ |
| 126 | + $(EXTRA_CFLAGS) |
| 127 | +CFLAGS_ESPRISCV32 = -std=c99 -Wall -Werror -Os \ |
| 128 | + -march=rv32imc -mabi=ilp32 -msmall-data-limit=0 \ |
| 129 | + -nostdlib -fno-builtin -flto \ |
| 130 | + -Wl,-static -g -ffunction-sections -Wl,--gc-sections -Iinclude -Lld \ |
| 131 | + $(EXTRA_CFLAGS_ESPRISCV32) |
| 132 | +LDLIBS = -lgcc |
| 133 | + |
| 134 | +$(STUB_ELF_8266): $(SRCS) $(SRCS_8266) $(BUILD_DIR) ld/stub_8266.ld | Makefile |
| 135 | + @echo " CC(8266) $^ -> $@" |
| 136 | + $(Q) $(CROSS_8266)gcc $(CFLAGS) -DESP8266=1 -Tstub_8266.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 137 | + |
| 138 | +$(STUB_ELF_32): $(SRCS) $(BUILD_DIR) ld/stub_32.ld | Makefile |
| 139 | + @echo " CC(32) $^ -> $@" |
| 140 | + $(Q) $(CROSS_32)gcc $(CFLAGS) -DESP32=1 -Tstub_32.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 141 | + |
| 142 | +$(STUB_ELF_32S2): $(SRCS) $(BUILD_DIR) ld/stub_32s2.ld |
| 143 | + @echo " CC(32S2) $^ -> $@" |
| 144 | + $(Q) $(CROSS_32S2)gcc $(CFLAGS) -DESP32S2=1 -Tstub_32s2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 145 | + |
| 146 | +$(STUB_ELF_32S3_BETA_2): $(SRCS) $(BUILD_DIR) ld/stub_32s3_beta_2.ld |
| 147 | + @echo " CC(32S3) $^ -> $@" |
| 148 | + $(Q) $(CROSS_32S3)gcc $(CFLAGS) -DESP32S3BETA2=1 -Tstub_32s3_beta_2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 149 | + |
| 150 | +$(STUB_ELF_32S3): $(SRCS) $(BUILD_DIR) ld/stub_32s3.ld |
| 151 | + @echo " CC(32S3) $^ -> $@" |
| 152 | + $(Q) $(CROSS_32S3)gcc $(CFLAGS) -DESP32S3=1 -Tstub_32s3.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 153 | + |
| 154 | +$(STUB_ELF_32C3): $(SRCS) $(BUILD_DIR) ld/stub_32c3.ld |
| 155 | + @echo " CC(32C3) $^ -> $@" |
| 156 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C3=1 -Tstub_32c3.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 157 | + |
| 158 | +$(STUB_ELF_32C6BETA): $(SRCS) $(BUILD_DIR) ld/stub_32c6_beta.ld |
| 159 | + @echo " CC(32C6BETA) $^ -> $@" |
| 160 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C6BETA=1 -Tstub_32c6_beta.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 161 | + |
| 162 | +$(STUB_ELF_32H2_BETA_1): $(SRCS) $(BUILD_DIR) ld/stub_32h2_beta_1.ld |
| 163 | + @echo " CC(32H2BETA1) $^ -> $@" |
| 164 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32H2BETA1=1 -Tstub_32h2_beta_1.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 165 | + |
| 166 | +$(STUB_ELF_32H2_BETA_2): $(SRCS) $(BUILD_DIR) ld/stub_32h2_beta_2.ld |
| 167 | + @echo " CC(32H2BETA2) $^ -> $@" |
| 168 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32H2BETA2=1 -Tstub_32h2_beta_2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 169 | + |
| 170 | +$(STUB_ELF_32C2): $(SRCS) $(BUILD_DIR) ld/stub_32c2.ld |
| 171 | + @echo " CC(32C2) $^ -> $@" |
| 172 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C2=1 -Tstub_32c2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 173 | + |
| 174 | +$(STUB_ELF_32C6): $(SRCS) $(BUILD_DIR) ld/stub_32c6.ld |
| 175 | + @echo " CC(32C6) $^ -> $@" |
| 176 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C6=1 -Tstub_32c6.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 177 | + |
| 178 | +$(STUB_ELF_32C61): $(SRCS) $(BUILD_DIR) ld/stub_32c61.ld |
| 179 | + @echo " CC(32C61) $^ -> $@" |
| 180 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C61=1 -Tstub_32c61.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 181 | + |
| 182 | +$(STUB_ELF_32C5): $(SRCS) $(BUILD_DIR) ld/stub_32c5.ld |
| 183 | + @echo " CC(32C5) $^ -> $@" |
| 184 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C5=1 -Tstub_32c5.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 185 | + |
| 186 | +$(STUB_ELF_32C5_BETA_3): $(SRCS) $(BUILD_DIR) ld/stub_32c5_beta_3.ld |
| 187 | + @echo " CC(32C5BETA3) $^ -> $@" |
| 188 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C5BETA3=1 -Tstub_32c5_beta_3.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 189 | + |
| 190 | +$(STUB_ELF_32H2): $(SRCS) $(BUILD_DIR) ld/stub_32h2.ld |
| 191 | + @echo " CC(32H2) $^ -> $@" |
| 192 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32H2=1 -Tstub_32h2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 193 | + |
| 194 | +$(STUB_ELF_32P4): $(SRCS) $(BUILD_DIR) ld/stub_32p4.ld |
| 195 | + @echo " CC(32P4) $^ -> $@" |
| 196 | + $(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32P4=1 -Tstub_32p4.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 197 | + |
| 198 | +clean: |
| 199 | + $(Q) rm -rf $(BUILD_DIR) |
0 commit comments