| 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 overriden 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 = stub_flasher |
| 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 = ../esptool/targets/stub_flasher |
| 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_32H2 = $(BUILD_DIR)/$(STUB)_32h2.elf |
| 72 |
STUB_ELF_32P4 = $(BUILD_DIR)/$(STUB)_32p4.elf |
| 73 |
|
| 74 |
STUBS_ELF = |
| 75 |
ifneq ($(WITHOUT_ESP8266),1) |
| 76 |
STUBS_ELF += \ |
| 77 |
$(STUB_ELF_8266) |
| 78 |
endif |
| 79 |
|
| 80 |
ifneq ($(WITHOUT_ESP32_XTENSA),1) |
| 81 |
STUBS_ELF += \ |
| 82 |
$(STUB_ELF_32) \ |
| 83 |
$(STUB_ELF_32S2) \ |
| 84 |
$(STUB_ELF_32S3_BETA_2) \ |
| 85 |
$(STUB_ELF_32S3) |
| 86 |
endif |
| 87 |
|
| 88 |
ifneq ($(WITHOUT_ESP32_RISCV32),1) |
| 89 |
STUBS_ELF += \ |
| 90 |
$(STUB_ELF_32C3) \ |
| 91 |
$(STUB_ELF_32C6BETA) \ |
| 92 |
$(STUB_ELF_32H2_BETA_1) \ |
| 93 |
$(STUB_ELF_32H2_BETA_2) \ |
| 94 |
$(STUB_ELF_32C2) \ |
| 95 |
$(STUB_ELF_32C6) \ |
| 96 |
$(STUB_ELF_32H2) \ |
| 97 |
$(STUB_ELF_32P4) |
| 98 |
endif |
| 99 |
|
| 100 |
.PHONY: all clean install |
| 101 |
|
| 102 |
all: $(STUBS_ELF:.elf=.json) |
| 103 |
|
| 104 |
install: $(patsubst $(BUILD_DIR)/%.elf,$(ESPTOOL_STUBS_DIR)/%.json,$(STUBS_ELF)) |
| 105 |
|
| 106 |
$(BUILD_DIR): |
| 107 |
$(Q) mkdir $@ |
| 108 |
|
| 109 |
$(BUILD_DIR)/%.json: $(BUILD_DIR)/%.elf |
| 110 |
@echo " WRAP $^ -> $(BUILD_DIR)" |
| 111 |
$(Q) $(WRAP_STUB) $^ |
| 112 |
|
| 113 |
$(ESPTOOL_STUBS_DIR)/%.json: $(BUILD_DIR)/%.json |
| 114 |
@echo " INSTALL $^ -> $@" |
| 115 |
$(Q) cp $^ $@ |
| 116 |
|
| 117 |
CFLAGS = -std=c99 -Wall -Werror -Os \ |
| 118 |
-mtext-section-literals -mlongcalls -nostdlib -fno-builtin -flto \ |
| 119 |
-Wl,-static -g -ffunction-sections -Wl,--gc-sections -Iinclude -Lld \ |
| 120 |
$(EXTRA_CFLAGS) |
| 121 |
CFLAGS_ESPRISCV32 = -std=c99 -Wall -Werror -Os \ |
| 122 |
-march=rv32imc -mabi=ilp32 -msmall-data-limit=0 \ |
| 123 |
-nostdlib -fno-builtin -flto \ |
| 124 |
-Wl,-static -g -ffunction-sections -Wl,--gc-sections -Iinclude -Lld \ |
| 125 |
$(EXTRA_CFLAGS_ESPRISCV32) |
| 126 |
LDLIBS = -lgcc |
| 127 |
|
| 128 |
$(STUB_ELF_8266): $(SRCS) $(SRCS_8266) $(BUILD_DIR) ld/stub_8266.ld | Makefile |
| 129 |
@echo " CC(8266) $^ -> $@" |
| 130 |
$(Q) $(CROSS_8266)gcc $(CFLAGS) -DESP8266=1 -Tstub_8266.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 131 |
|
| 132 |
$(STUB_ELF_32): $(SRCS) $(BUILD_DIR) ld/stub_32.ld | Makefile |
| 133 |
@echo " CC(32) $^ -> $@" |
| 134 |
$(Q) $(CROSS_32)gcc $(CFLAGS) -DESP32=1 -Tstub_32.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 135 |
|
| 136 |
$(STUB_ELF_32S2): $(SRCS) $(BUILD_DIR) ld/stub_32s2.ld |
| 137 |
@echo " CC(32S2) $^ -> $@" |
| 138 |
$(Q) $(CROSS_32S2)gcc $(CFLAGS) -DESP32S2=1 -Tstub_32s2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 139 |
|
| 140 |
$(STUB_ELF_32S3_BETA_2): $(SRCS) $(BUILD_DIR) ld/stub_32s3_beta_2.ld |
| 141 |
@echo " CC(32S3) $^ -> $@" |
| 142 |
$(Q) $(CROSS_32S3)gcc $(CFLAGS) -DESP32S3BETA2=1 -Tstub_32s3_beta_2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 143 |
|
| 144 |
$(STUB_ELF_32S3): $(SRCS) $(BUILD_DIR) ld/stub_32s3.ld |
| 145 |
@echo " CC(32S3) $^ -> $@" |
| 146 |
$(Q) $(CROSS_32S3)gcc $(CFLAGS) -DESP32S3=1 -Tstub_32s3.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 147 |
|
| 148 |
$(STUB_ELF_32C3): $(SRCS) $(BUILD_DIR) ld/stub_32c3.ld |
| 149 |
@echo " CC(32C3) $^ -> $@" |
| 150 |
$(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C3=1 -Tstub_32c3.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 151 |
|
| 152 |
$(STUB_ELF_32C6BETA): $(SRCS) $(BUILD_DIR) ld/stub_32c6_beta.ld |
| 153 |
@echo " CC(32C6BETA) $^ -> $@" |
| 154 |
$(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C6BETA=1 -Tstub_32c6_beta.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 155 |
|
| 156 |
$(STUB_ELF_32H2_BETA_1): $(SRCS) $(BUILD_DIR) ld/stub_32h2_beta_1.ld |
| 157 |
@echo " CC(32H2BETA1) $^ -> $@" |
| 158 |
$(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32H2BETA1=1 -Tstub_32h2_beta_1.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 159 |
|
| 160 |
$(STUB_ELF_32H2_BETA_2): $(SRCS) $(BUILD_DIR) ld/stub_32h2_beta_2.ld |
| 161 |
@echo " CC(32H2BETA2) $^ -> $@" |
| 162 |
$(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32H2BETA2=1 -Tstub_32h2_beta_2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 163 |
|
| 164 |
$(STUB_ELF_32C2): $(SRCS) $(BUILD_DIR) ld/stub_32c2.ld |
| 165 |
@echo " CC(32C2) $^ -> $@" |
| 166 |
$(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C2=1 -Tstub_32c2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 167 |
|
| 168 |
$(STUB_ELF_32C6): $(SRCS) $(BUILD_DIR) ld/stub_32c6.ld |
| 169 |
@echo " CC(32C6) $^ -> $@" |
| 170 |
$(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32C6=1 -Tstub_32c6.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 171 |
|
| 172 |
$(STUB_ELF_32H2): $(SRCS) $(BUILD_DIR) ld/stub_32h2.ld |
| 173 |
@echo " CC(32H2) $^ -> $@" |
| 174 |
$(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32H2=1 -Tstub_32h2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 175 |
|
| 176 |
$(STUB_ELF_32P4): $(SRCS) $(BUILD_DIR) ld/stub_32p4.ld |
| 177 |
@echo " CC(32P4) $^ -> $@" |
| 178 |
$(Q) $(CROSS_ESPRISCV32)gcc $(CFLAGS_ESPRISCV32) -DESP32P4=1 -Tstub_32p4.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS) |
| 179 |
|
| 180 |
clean: |
| 181 |
$(Q) rm -rf $(BUILD_DIR) |