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>
This commit is contained in:
Jim Mussared 2023-08-16 00:51:37 +10:00
parent aa23698119
commit ef03ca8bf2
28 changed files with 179 additions and 201 deletions

View File

@ -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
@ -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
@ -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 $<
@ -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:

View File

@ -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
------------------
@ -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__
@ -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.
@ -149,26 +152,30 @@ $ 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:
__Reduced FlashROM variants__
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.
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=GENERIC_512K
$ make BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_512K
$ make BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_1M
```
__512KB FlashROM version__
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.
First start
-----------

View File

@ -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)

View File

@ -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"
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,14 +0,0 @@
#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)

View File

@ -1,8 +0,0 @@
LD_FILES = boards/esp8266_2m.ld
MICROPY_ESPNOW ?= 1
MICROPY_PY_BTREE ?= 1
MICROPY_VFS_FAT ?= 1
MICROPY_VFS_LFS2 ?= 1
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py

View File

@ -1,16 +0,0 @@
{
"deploy": [
"../deploy.md"
],
"docs": "",
"features": [
"External Flash",
"WiFi"
],
"images": [],
"mcu": "esp8266",
"product": "ESP8266 with 1MiB flash",
"thumbnail": "",
"url": "https://www.espressif.com/en/products/modules",
"vendor": "Espressif"
}

View File

@ -1,5 +0,0 @@
The following are daily builds of the ESP8266 firmware tailored for modules with
only 1MiB of flash. This firmware uses littlefs as the filesystem.
When upgrading from older firmware that uses a FAT filesystem please backup your files
first, and either erase all flash before upgrading, or after upgrading execute
`os.VfsLfs2.mkfs(bdev)`.

View File

@ -1,17 +0,0 @@
#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_FSTRINGS (0)
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
#define MICROPY_PY_ASYNCIO (0)
#define MICROPY_PY_CRYPTOLIB (1)

View File

@ -1,5 +0,0 @@
LD_FILES = boards/esp8266_1m.ld
MICROPY_ESPNOW ?= 1
MICROPY_PY_BTREE ?= 1
MICROPY_VFS_LFS2 ?= 1

View File

@ -1,3 +0,0 @@
import gc
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)

View File

@ -1,16 +0,0 @@
{
"deploy": [
"../deploy.md"
],
"docs": "",
"features": [
"External Flash",
"WiFi"
],
"images": [],
"mcu": "esp8266",
"product": "ESP8266 with 512kiB flash",
"thumbnail": "",
"url": "https://www.espressif.com/en/products/modules",
"vendor": "Espressif"
}

View File

@ -1,3 +0,0 @@
The following are daily builds of the ESP8266 firmware tailored for modules with
only 512kiB of flash. Certain features are disabled to get the firmware down
to this size.

View File

@ -1,13 +0,0 @@
#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)

View File

@ -1,3 +0,0 @@
LD_FILES = boards/esp8266_512k.ld
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py

View File

@ -48,4 +48,4 @@ max-complexity = 40
# manifest.py files are evaluated with some global names pre-defined
"**/manifest.py" = ["F821"]
"ports/**/boards/manifest*.py" = ["F821"]
"ports/**/boards/**/manifest_*.py" = ["F821"]

View File

@ -62,7 +62,7 @@ FW_TAG="-$FW_DATE-unstable-$FW_GIT"
cd ports/cc3200
${AUTODIR}/build-cc3200-latest.sh ${FW_TAG} ${LOCAL_FIRMWARE}
cd ../esp8266
${AUTODIR}/build-esp8266-latest.sh ${FW_TAG} ${LOCAL_FIRMWARE}
build_esp8266_boards ${FW_TAG} ${LOCAL_FIRMWARE}
cd ../esp32
(source ${IDF_PATH_V50}/export.sh && build_esp32_boards ${FW_TAG} ${LOCAL_FIRMWARE})
cd ../mimxrt

View File

@ -92,6 +92,10 @@ function build_esp32_boards {
build_boards modesp32.c $1 $2 bin elf map uf2 app-bin
}
function build_esp8266_boards {
build_boards modesp.c $1 $2 bin elf map
}
function build_mimxrt_boards {
build_boards modmimxrt.c $1 $2 bin hex
}

View File

@ -1,61 +0,0 @@
#!/bin/bash
PYTHON3=python3
yaota8266=$HOME/yaota8266
# for debugging
#exec &> /tmp/esp-log-$$.txt
# function for building firmware
function do_build() {
descr=$1
board=$2
shift
shift
echo "building $descr $board"
build_dir=/tmp/esp8266-build-$board
$MICROPY_AUTOBUILD_MAKE $@ BOARD=$board BUILD=$build_dir || exit 1
mv $build_dir/firmware-combined.bin $dest_dir/$descr$fw_tag.bin
mv $build_dir/firmware.elf $dest_dir/$descr$fw_tag.elf
mv $build_dir/firmware.map $dest_dir/$descr$fw_tag.map
rm -rf $build_dir
}
function do_build_ota() {
descr=$1
board=$2
shift
shift
echo "building $descr $board"
build_dir=/tmp/esp8266-build-$board
$MICROPY_AUTOBUILD_MAKE $@ BOARD=$board BUILD=$build_dir || exit 1
cat $yaota8266/yaota8266.bin $build_dir/firmware-ota.bin > $dest_dir/$descr$fw_tag.bin
pushd $yaota8266/ota-client
$PYTHON3 ota_client.py sign $build_dir/firmware-ota.bin
popd
mv $build_dir/firmware-ota.bin.ota $dest_dir/$descr$fw_tag.ota
mv $build_dir/firmware.elf $dest_dir/$descr$fw_tag.elf
mv $build_dir/firmware.map $dest_dir/$descr$fw_tag.map
rm -rf $build_dir
}
# check/get parameters
if [ $# != 2 ]; then
echo "usage: $0 <fw-tag> <dest-dir>"
exit 1
fi
fw_tag=$1
dest_dir=$2
# check we are in the correct directory
if [ ! -r boards/esp8266_common.ld ]; then
echo "must be in esp8266 directory"
exit 1
fi
# build the versions
do_build esp8266 GENERIC
do_build esp8266-512k GENERIC_512K
do_build esp8266-1m GENERIC_1M
do_build_ota esp8266-ota GENERIC_1M ota

View File

@ -155,9 +155,9 @@ function ci_esp8266_path {
function ci_esp8266_build {
make ${MAKEOPTS} -C mpy-cross
make ${MAKEOPTS} -C ports/esp8266 submodules
make ${MAKEOPTS} -C ports/esp8266
make ${MAKEOPTS} -C ports/esp8266 BOARD=GENERIC_512K
make ${MAKEOPTS} -C ports/esp8266 BOARD=GENERIC_1M
make ${MAKEOPTS} -C ports/esp8266 BOARD=ESP8266_GENERIC
make ${MAKEOPTS} -C ports/esp8266 BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_512K
make ${MAKEOPTS} -C ports/esp8266 BOARD=ESP8266_GENERIC BOARD_VARIANT=FLASH_1M
}
########################################################################################