Skip to content

Commit ef03ca8

Browse files
committed
esp8266: Add board variant support.
This merges the existing GENERIC, GENERIC_1M, and GENERIC_512k boards into variants of the new ESP8266_GENERIC board (renamed from GENERIC so as not to clash with other ports). Also moves the generation of the "OTA" variant (previously generated by autobuild/build-esp8266-latest.sh) into the variant. Following the convention established for the WEACTSTUDIO rp2 board, the names of the variants are FLASH_1M and FLASH_512K (but rename the .ld files to use MiB and kiB). Updates autobuild to build esp8266 firmware the same way as other ports. This requires renaming the output from firmware-combined.bin to just firmware.bin. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent aa23698 commit ef03ca8

28 files changed

Lines changed: 179 additions & 201 deletions

ports/esp8266/Makefile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ ifdef BOARD_DIR
44
# the path as the board name.
55
BOARD ?= $(notdir $(BOARD_DIR:/=))
66
else
7-
# If not given on the command line, then default to GENERIC.
8-
BOARD ?= GENERIC
7+
# If not given on the command line, then default to ESP8266_GENERIC.
8+
BOARD ?= ESP8266_GENERIC
99
BOARD_DIR ?= boards/$(BOARD)
1010
endif
1111

1212
ifeq ($(wildcard $(BOARD_DIR)/.),)
13+
ifeq ($(findstring boards/GENERIC,$(BOARD_DIR)),boards/GENERIC)
14+
$(warning The GENERIC* boards have been renamed to ESP8266_GENERIC)
15+
endif
1316
$(error Invalid BOARD specified: $(BOARD_DIR))
1417
endif
1518

16-
# If the build directory is not given, make it reflect the board name.
19+
# If the build directory is not given, make it reflect the board name (and
20+
# optionally the board variant).
21+
ifneq ($(BOARD_VARIANT),)
22+
BUILD ?= build-$(BOARD)-$(BOARD_VARIANT)
23+
else
1724
BUILD ?= build-$(BOARD)
25+
endif
1826

1927
include ../../py/mkenv.mk
2028

@@ -40,7 +48,7 @@ include $(TOP)/extmod/extmod.mk
4048

4149
GIT_SUBMODULES += lib/axtls lib/berkeley-db-1.xx
4250

43-
FWBIN = $(BUILD)/firmware-combined.bin
51+
FWBIN = $(BUILD)/firmware.bin
4452
PORT ?= /dev/ttyACM0
4553
BAUD ?= 115200
4654
FLASH_MODE ?= qio
@@ -202,7 +210,7 @@ FROZEN_EXTRA_DEPS = $(CONFVARS_FILE)
202210

203211
.PHONY: deploy
204212

205-
deploy: $(BUILD)/firmware-combined.bin
213+
deploy: $(FWBIN)
206214
$(ECHO) "Writing $< to the board"
207215
$(Q)esptool.py --port $(PORT) --baud $(BAUD) write_flash --verify --flash_size=$(FLASH_SIZE) --flash_mode=$(FLASH_MODE) 0 $<
208216

@@ -213,20 +221,26 @@ erase:
213221
reset:
214222
echo -e "\r\nimport machine; machine.reset()\r\n" >$(PORT)
215223

224+
ifeq ($(BOARD_VARIANT),OTA)
225+
$(FWBIN): $(BUILD)/firmware.elf
226+
$(ECHO) "Create $@"
227+
$(Q)esptool.py elf2image $^
228+
$(Q)$(PYTHON) makeimg.py $(BUILD)/firmware.elf-0x00000.bin $(BUILD)/firmware.elf-0x[0-5][1-f]000.bin $(BUILD)/firmware-ota.bin
229+
230+
$(Q)cat $(YAOTA8266)/yaota8266.bin $(BUILD)/firmware-ota.bin > $@
231+
$(Q)$(PYTHON) $(YAOTA8266)/ota-client/ota_client.py sign $@
232+
else
216233
$(FWBIN): $(BUILD)/firmware.elf
217234
$(ECHO) "Create $@"
218235
$(Q)esptool.py elf2image $^
219236
$(Q)$(PYTHON) makeimg.py $(BUILD)/firmware.elf-0x00000.bin $(BUILD)/firmware.elf-0x[0-5][1-f]000.bin $@
237+
endif
220238

221239
$(BUILD)/firmware.elf: $(OBJ)
222240
$(ECHO) "LINK $@"
223241
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
224242
$(Q)$(SIZE) $@
225243

226-
ota:
227-
rm -f $(BUILD)/firmware.elf $(BUILD)/firmware.elf*.bin
228-
$(MAKE) LD_FILES=boards/esp8266_ota.ld FWBIN=$(BUILD)/firmware-ota.bin
229-
230244
include $(TOP)/py/mkrules.mk
231245

232246
clean-modules:

ports/esp8266/README.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Supported features include:
2323

2424
Documentation is available at http://docs.micropython.org/en/latest/esp8266/quickref.html.
2525

26+
The default build requires a 2MiB flash chip, but see below for support for
27+
1MiB and 512kiB options.
28+
2629
Build instructions
2730
------------------
2831

@@ -67,10 +70,10 @@ Then to compile the ESP8266 firmware:
6770

6871
```
6972
$ cd ports/esp8266
70-
$ docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -j BOARD=GENERIC
73+
$ docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -j BOARD=ESP8266_GENERIC
7174
```
7275

73-
This will produce binary images in the `build-GENERIC/` subdirectory.
76+
This will produce binary images in the `build-ESP8266_GENERIC/` subdirectory.
7477
Substitute the board for whichever board you're using.
7578

7679
__Building with a local toolchain__
@@ -106,10 +109,10 @@ Then to compile the ESP8266 firmware:
106109

107110
```
108111
$ cd ports/esp8266
109-
$ make -j BOARD=GENERIC
112+
$ make -j BOARD=ESP8266_GENERIC
110113
```
111114

112-
This will produce binary images in the `build-GENERIC/` subdirectory.
115+
This will produce binary images in the `build-ESP8266_GENERIC/` subdirectory.
113116
Substitute the board for whichever board you're using.
114117

115118

@@ -149,25 +152,29 @@ $ make PORT=/dev/ttyUSB0 FLASH_MODE=qio FLASH_SIZE=32m deploy
149152
(note that flash size is in megabits)
150153

151154
If you want to flash manually using `esptool.py` directly, the image produced is
152-
`build-GENERIC/firmware-combined.bin`, to be flashed at 0x00000.
155+
`build-ESP8266_GENERIC/firmware.bin`, to be flashed at 0x00000.
153156

154-
The default board definition is the directory `boards/GENERIC`.
157+
The default board definition is the directory `boards/ESP8266_GENERIC`.
155158
For a custom configuration you can define your own board in the directory `boards/`.
156159

157-
The `BOARD` variable can be set on the make command line, for example:
158-
```bash
159-
$ make BOARD=GENERIC_512K
160-
```
160+
__Reduced FlashROM variants__
161161

162-
__512KB FlashROM version__
162+
The normal build described above requires modules with at least 2MiB of
163+
FlashROM onboard. There's a special configuration for 512kiB modules, which can
164+
be built with the `FLASH_512K` variant. This configuration is highly limited,
165+
lacks filesystem support, WebREPL, and has many other features disabled. It's
166+
mostly suitable for advanced users who are interested to fine-tune options to
167+
achieve a required setup. If you are an end user, please consider using a
168+
module with at least 2MiB of FlashROM.
163169

164-
The normal build described above requires modules with at least 1MB of FlashROM
165-
onboard. There's a special configuration for 512KB modules, which can be
166-
built with `make BOARD=GENERIC_512K`. This configuration is highly limited, lacks
167-
filesystem support, WebREPL, and has many other features disabled. It's mostly
168-
suitable for advanced users who are interested to fine-tune options to achieve a
169-
required setup. If you are an end user, please consider using a module with at
170-
least 1MB of FlashROM.
170+
A variant is also provided for 1MiB modules which just lacks the included
171+
micropython-lib packages.
172+
173+
The variant can be set on the make command line, for example:
174+
```bash
175+
$ make BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_512K
176+
$ make BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_1M
177+
```
171178

172179
First start
173180
-----------
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Minimal _boot.py for the 512kiB variant. Does not set up a block device or
2+
# filesystem. Other variants use esp8266/modules/_boot.py.
3+
4+
import gc
5+
6+
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)

ports/esp8266/boards/GENERIC/board.json renamed to ports/esp8266/boards/ESP8266_GENERIC/board.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
],
1010
"images": [],
1111
"mcu": "esp8266",
12-
"product": "ESP8266 with 2MiB+ flash",
12+
"product": "ESP8266",
1313
"thumbnail": "",
1414
"url": "https://www.espressif.com/en/products/modules",
1515
"variants": {
16-
"ota": "OTA compatible"
16+
"OTA": "OTA compatible",
17+
"FLASH_1M": "1MiB flash",
18+
"FLASH_512K": "512kiB flash"
1719
},
1820
"vendor": "Espressif"
1921
}

ports/esp8266/boards/GENERIC/board.md renamed to ports/esp8266/boards/ESP8266_GENERIC/board.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
The following are daily builds of the ESP8266 firmware for boards with at
2-
least 2MiB of flash. They have the latest features and bug fixes, WebREPL is
3-
not automatically started, and debugging is enabled by default.
1+
The following are daily builds of the ESP8266 firmware. This will work on
2+
boards with at least 2MiB of flash. They have the latest features and bug
3+
fixes, WebREPL is not automatically started, and debugging is enabled by
4+
default.
5+
6+
For boards with 1MiB or 512kiB of flash, two variants are provided with reduced
7+
functionality. The 1MiB variant removes asyncio and FAT-filesystem support as
8+
well as some modules from micropython-lib. The 512kiB variant further removes
9+
all filesystem support, as well as framebuffer support, some Python language
10+
features, and has less detailed error messages.
411

512
Note: v1.12-334 and newer (including v1.13) require an ESP8266 module with
613
2MiB of flash or more, and use littlefs as the filesystem by default. When
File renamed without changes.
File renamed without changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#if defined(MICROPY_ESP8266_2M)
2+
3+
#define MICROPY_HW_BOARD_NAME "ESP module"
4+
#define MICROPY_HW_MCU_NAME "ESP8266"
5+
6+
#define MICROPY_PERSISTENT_CODE_LOAD (1)
7+
#define MICROPY_EMIT_XTENSA (1)
8+
#define MICROPY_EMIT_INLINE_XTENSA (1)
9+
10+
#define MICROPY_DEBUG_PRINTERS (1)
11+
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
12+
13+
#define MICROPY_READER_VFS (MICROPY_VFS)
14+
#define MICROPY_VFS (1)
15+
16+
#define MICROPY_PY_CRYPTOLIB (1)
17+
18+
#elif defined(MICROPY_ESP8266_1M)
19+
20+
#define MICROPY_HW_BOARD_NAME "ESP module (1M)"
21+
#define MICROPY_HW_MCU_NAME "ESP8266"
22+
23+
#define MICROPY_PERSISTENT_CODE_LOAD (1)
24+
#define MICROPY_EMIT_XTENSA (1)
25+
#define MICROPY_EMIT_INLINE_XTENSA (1)
26+
27+
#define MICROPY_DEBUG_PRINTERS (1)
28+
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
29+
30+
#define MICROPY_READER_VFS (MICROPY_VFS)
31+
#define MICROPY_VFS (1)
32+
33+
34+
#define MICROPY_PY_CRYPTOLIB (1)
35+
36+
#elif defined(MICROPY_ESP8266_512K)
37+
38+
#define MICROPY_HW_BOARD_NAME "ESP module (512K)"
39+
#define MICROPY_HW_MCU_NAME "ESP8266"
40+
41+
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
42+
43+
#define MICROPY_PY_FSTRINGS (0)
44+
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
45+
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
46+
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
47+
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
48+
#define MICROPY_PY_ASYNCIO (0)
49+
#define MICROPY_PY_RE_SUB (0)
50+
#define MICROPY_PY_FRAMEBUF (0)
51+
52+
#endif
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
ifeq ($(BOARD_VARIANT),)
2+
LD_FILES = boards/esp8266_2MiB.ld
3+
4+
MICROPY_ESPNOW ?= 1
5+
MICROPY_PY_BTREE ?= 1
6+
MICROPY_VFS_FAT ?= 1
7+
MICROPY_VFS_LFS2 ?= 1
8+
9+
# Add asyncio and extra micropython-lib packages (in addition to the port manifest).
10+
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest_2MiB.py
11+
12+
# Configure mpconfigboard.h.
13+
CFLAGS += -DMICROPY_ESP8266_2M
14+
endif
15+
16+
ifeq ($(BOARD_VARIANT),FLASH_1M)
17+
LD_FILES = boards/esp8266_1MiB.ld
18+
19+
MICROPY_ESPNOW ?= 1
20+
MICROPY_PY_BTREE ?= 1
21+
MICROPY_VFS_LFS2 ?= 1
22+
23+
# Note: Implicitly uses the port manifest.
24+
25+
# Configure mpconfigboard.h.
26+
CFLAGS += -DMICROPY_ESP8266_1M
27+
endif
28+
29+
ifeq ($(BOARD_VARIANT),OTA)
30+
LD_FILES = boards/esp8266_ota.ld
31+
32+
MICROPY_ESPNOW ?= 1
33+
MICROPY_PY_BTREE ?= 1
34+
MICROPY_VFS_LFS2 ?= 1
35+
36+
# Note: Implicitly uses the port manifest.
37+
38+
# Configure mpconfigboard.h.
39+
CFLAGS += -DMICROPY_ESP8266_1M
40+
endif
41+
42+
ifeq ($(BOARD_VARIANT),FLASH_512K)
43+
LD_FILES = boards/esp8266_512kiB.ld
44+
45+
# Note: Use the minimal manifest.py.
46+
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest_512kiB.py
47+
48+
# Configure mpconfigboard.h.
49+
CFLAGS += -DMICROPY_ESP8266_512K
50+
endif

ports/esp8266/boards/GENERIC/mpconfigboard.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)