Skip to content

Commit

Permalink
esp8266: Add board variant support.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jimmo committed Aug 23, 2023
1 parent aa23698 commit ef03ca8
Show file tree
Hide file tree
Showing 28 changed files with 179 additions and 201 deletions.
32 changes: 23 additions & 9 deletions ports/esp8266/Makefile
Expand Up @@ -4,17 +4,25 @@ ifdef BOARD_DIR
# the path as the board name.
BOARD ?= $(notdir $(BOARD_DIR:/=))
else
# If not given on the command line, then default to GENERIC.
BOARD ?= GENERIC
# If not given on the command line, then default to ESP8266_GENERIC.
BOARD ?= ESP8266_GENERIC
BOARD_DIR ?= boards/$(BOARD)
endif

ifeq ($(wildcard $(BOARD_DIR)/.),)
ifeq ($(findstring boards/GENERIC,$(BOARD_DIR)),boards/GENERIC)
$(warning The GENERIC* boards have been renamed to ESP8266_GENERIC)
endif
$(error Invalid BOARD specified: $(BOARD_DIR))
endif

# If the build directory is not given, make it reflect the board name.
# If the build directory is not given, make it reflect the board name (and
# optionally the board variant).
ifneq ($(BOARD_VARIANT),)
BUILD ?= build-$(BOARD)-$(BOARD_VARIANT)
else
BUILD ?= build-$(BOARD)
endif

include ../../py/mkenv.mk

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

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

FWBIN = $(BUILD)/firmware-combined.bin
FWBIN = $(BUILD)/firmware.bin
PORT ?= /dev/ttyACM0
BAUD ?= 115200
FLASH_MODE ?= qio
Expand Down Expand Up @@ -202,7 +210,7 @@ FROZEN_EXTRA_DEPS = $(CONFVARS_FILE)

.PHONY: deploy

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

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

ifeq ($(BOARD_VARIANT),OTA)
$(FWBIN): $(BUILD)/firmware.elf
$(ECHO) "Create $@"
$(Q)esptool.py elf2image $^
$(Q)$(PYTHON) makeimg.py $(BUILD)/firmware.elf-0x00000.bin $(BUILD)/firmware.elf-0x[0-5][1-f]000.bin $(BUILD)/firmware-ota.bin

$(Q)cat $(YAOTA8266)/yaota8266.bin $(BUILD)/firmware-ota.bin > $@
$(Q)$(PYTHON) $(YAOTA8266)/ota-client/ota_client.py sign $@
else
$(FWBIN): $(BUILD)/firmware.elf
$(ECHO) "Create $@"
$(Q)esptool.py elf2image $^
$(Q)$(PYTHON) makeimg.py $(BUILD)/firmware.elf-0x00000.bin $(BUILD)/firmware.elf-0x[0-5][1-f]000.bin $@
endif

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

ota:
rm -f $(BUILD)/firmware.elf $(BUILD)/firmware.elf*.bin
$(MAKE) LD_FILES=boards/esp8266_ota.ld FWBIN=$(BUILD)/firmware-ota.bin

include $(TOP)/py/mkrules.mk

clean-modules:
Expand Down
43 changes: 25 additions & 18 deletions ports/esp8266/README.md
Expand Up @@ -23,6 +23,9 @@ Supported features include:

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

The default build requires a 2MiB flash chip, but see below for support for
1MiB and 512kiB options.

Build instructions
------------------

Expand Down Expand Up @@ -67,10 +70,10 @@ Then to compile the ESP8266 firmware:

```
$ cd ports/esp8266
$ docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -j BOARD=GENERIC
$ docker run --rm -v $HOME:$HOME -u $UID -w $PWD larsks/esp-open-sdk make -j BOARD=ESP8266_GENERIC
```

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

__Building with a local toolchain__
Expand Down Expand Up @@ -106,10 +109,10 @@ Then to compile the ESP8266 firmware:

```
$ cd ports/esp8266
$ make -j BOARD=GENERIC
$ make -j BOARD=ESP8266_GENERIC
```

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


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

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

The default board definition is the directory `boards/GENERIC`.
The default board definition is the directory `boards/ESP8266_GENERIC`.
For a custom configuration you can define your own board in the directory `boards/`.

The `BOARD` variable can be set on the make command line, for example:
```bash
$ make BOARD=GENERIC_512K
```
__Reduced FlashROM variants__

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

The normal build described above requires modules with at least 1MB of FlashROM
onboard. There's a special configuration for 512KB modules, which can be
built with `make BOARD=GENERIC_512K`. This configuration is highly limited, lacks
filesystem support, WebREPL, and has many other features disabled. It's mostly
suitable for advanced users who are interested to fine-tune options to achieve a
required setup. If you are an end user, please consider using a module with at
least 1MB of FlashROM.
A variant is also provided for 1MiB modules which just lacks the included
micropython-lib packages.

The variant can be set on the make command line, for example:
```bash
$ make BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_512K
$ make BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_1M
```

First start
-----------
Expand Down
6 changes: 6 additions & 0 deletions ports/esp8266/boards/ESP8266_GENERIC/_boot.py
@@ -0,0 +1,6 @@
# Minimal _boot.py for the 512kiB variant. Does not set up a block device or
# filesystem. Other variants use esp8266/modules/_boot.py.

import gc

gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
Expand Up @@ -9,11 +9,13 @@
],
"images": [],
"mcu": "esp8266",
"product": "ESP8266 with 2MiB+ flash",
"product": "ESP8266",
"thumbnail": "",
"url": "https://www.espressif.com/en/products/modules",
"variants": {
"ota": "OTA compatible"
"OTA": "OTA compatible",
"FLASH_1M": "1MiB flash",
"FLASH_512K": "512kiB flash"
},
"vendor": "Espressif"
}
@@ -1,6 +1,13 @@
The following are daily builds of the ESP8266 firmware for boards with at
least 2MiB of flash. They have the latest features and bug fixes, WebREPL is
not automatically started, and debugging is enabled by default.
The following are daily builds of the ESP8266 firmware. This will work on
boards with at least 2MiB of flash. They have the latest features and bug
fixes, WebREPL is not automatically started, and debugging is enabled by
default.

For boards with 1MiB or 512kiB of flash, two variants are provided with reduced
functionality. The 1MiB variant removes asyncio and FAT-filesystem support as
well as some modules from micropython-lib. The 512kiB variant further removes
all filesystem support, as well as framebuffer support, some Python language
features, and has less detailed error messages.

Note: v1.12-334 and newer (including v1.13) require an ESP8266 module with
2MiB of flash or more, and use littlefs as the filesystem by default. When
Expand Down
File renamed without changes.
52 changes: 52 additions & 0 deletions ports/esp8266/boards/ESP8266_GENERIC/mpconfigboard.h
@@ -0,0 +1,52 @@
#if defined(MICROPY_ESP8266_2M)

#define MICROPY_HW_BOARD_NAME "ESP module"
#define MICROPY_HW_MCU_NAME "ESP8266"

#define MICROPY_PERSISTENT_CODE_LOAD (1)
#define MICROPY_EMIT_XTENSA (1)
#define MICROPY_EMIT_INLINE_XTENSA (1)

#define MICROPY_DEBUG_PRINTERS (1)
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)

#define MICROPY_READER_VFS (MICROPY_VFS)
#define MICROPY_VFS (1)

#define MICROPY_PY_CRYPTOLIB (1)

#elif defined(MICROPY_ESP8266_1M)

#define MICROPY_HW_BOARD_NAME "ESP module (1M)"
#define MICROPY_HW_MCU_NAME "ESP8266"

#define MICROPY_PERSISTENT_CODE_LOAD (1)
#define MICROPY_EMIT_XTENSA (1)
#define MICROPY_EMIT_INLINE_XTENSA (1)

#define MICROPY_DEBUG_PRINTERS (1)
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)

#define MICROPY_READER_VFS (MICROPY_VFS)
#define MICROPY_VFS (1)


#define MICROPY_PY_CRYPTOLIB (1)

#elif defined(MICROPY_ESP8266_512K)

#define MICROPY_HW_BOARD_NAME "ESP module (512K)"
#define MICROPY_HW_MCU_NAME "ESP8266"

#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)

#define MICROPY_PY_FSTRINGS (0)
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
#define MICROPY_PY_ASYNCIO (0)
#define MICROPY_PY_RE_SUB (0)
#define MICROPY_PY_FRAMEBUF (0)

#endif
50 changes: 50 additions & 0 deletions ports/esp8266/boards/ESP8266_GENERIC/mpconfigboard.mk
@@ -0,0 +1,50 @@
ifeq ($(BOARD_VARIANT),)
LD_FILES = boards/esp8266_2MiB.ld

MICROPY_ESPNOW ?= 1
MICROPY_PY_BTREE ?= 1
MICROPY_VFS_FAT ?= 1
MICROPY_VFS_LFS2 ?= 1

# Add asyncio and extra micropython-lib packages (in addition to the port manifest).
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest_2MiB.py

# Configure mpconfigboard.h.
CFLAGS += -DMICROPY_ESP8266_2M
endif

ifeq ($(BOARD_VARIANT),FLASH_1M)
LD_FILES = boards/esp8266_1MiB.ld

MICROPY_ESPNOW ?= 1
MICROPY_PY_BTREE ?= 1
MICROPY_VFS_LFS2 ?= 1

# Note: Implicitly uses the port manifest.

# Configure mpconfigboard.h.
CFLAGS += -DMICROPY_ESP8266_1M
endif

ifeq ($(BOARD_VARIANT),OTA)
LD_FILES = boards/esp8266_ota.ld

MICROPY_ESPNOW ?= 1
MICROPY_PY_BTREE ?= 1
MICROPY_VFS_LFS2 ?= 1

# Note: Implicitly uses the port manifest.

# Configure mpconfigboard.h.
CFLAGS += -DMICROPY_ESP8266_1M
endif

ifeq ($(BOARD_VARIANT),FLASH_512K)
LD_FILES = boards/esp8266_512kiB.ld

# Note: Use the minimal manifest.py.
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest_512kiB.py

# Configure mpconfigboard.h.
CFLAGS += -DMICROPY_ESP8266_512K
endif
14 changes: 0 additions & 14 deletions ports/esp8266/boards/GENERIC/mpconfigboard.h

This file was deleted.

8 changes: 0 additions & 8 deletions ports/esp8266/boards/GENERIC/mpconfigboard.mk

This file was deleted.

16 changes: 0 additions & 16 deletions ports/esp8266/boards/GENERIC_1M/board.json

This file was deleted.

5 changes: 0 additions & 5 deletions ports/esp8266/boards/GENERIC_1M/board.md

This file was deleted.

17 changes: 0 additions & 17 deletions ports/esp8266/boards/GENERIC_1M/mpconfigboard.h

This file was deleted.

5 changes: 0 additions & 5 deletions ports/esp8266/boards/GENERIC_1M/mpconfigboard.mk

This file was deleted.

3 changes: 0 additions & 3 deletions ports/esp8266/boards/GENERIC_512K/_boot.py

This file was deleted.

16 changes: 0 additions & 16 deletions ports/esp8266/boards/GENERIC_512K/board.json

This file was deleted.

3 changes: 0 additions & 3 deletions ports/esp8266/boards/GENERIC_512K/board.md

This file was deleted.

0 comments on commit ef03ca8

Please sign in to comment.