Skip to content

Commit

Permalink
Add ESP32-S3 bootloader stub
Browse files Browse the repository at this point in the history
  • Loading branch information
duncandrennan committed Jun 14, 2022
1 parent 26e6a2c commit 0f391ce
Show file tree
Hide file tree
Showing 20 changed files with 538 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ deps: vendor/modules.txt
genstub-%:
cli/flash/$*/stub/genstub.sh

genstubs: genstub-esp32 genstub-esp32c3 genstub-esp8266
genstubs: genstub-esp32 genstub-esp32c3 genstub-esp32s3 genstub-esp8266

# Build the flasher stubs
# E.g.:
Expand Down
3 changes: 3 additions & 0 deletions cli/flash/esp/esp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
ChipESP8266 ChipType = iota
ChipESP32
ChipESP32C3
ChipESP32S3
)

type FlashOpts struct {
Expand Down Expand Up @@ -59,6 +60,8 @@ func (ct ChipType) String() string {
return "ESP32"
case ChipESP32C3:
return "ESP32-C3"
case ChipESP32S3:
return "ESP32-S3"
case ChipESP8266:
return "ESP8266"
default:
Expand Down
8 changes: 8 additions & 0 deletions cli/flash/esp/flasher/flash_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func getFlashSizeId(ct esp.ChipType, s string) int {
case esp.ChipESP32:
fallthrough
case esp.ChipESP32C3:
fallthrough
case esp.ChipESP32S3:
return esp32.FlashSizeToId[s] - 1
}
return -1
Expand All @@ -71,6 +73,8 @@ func getFlashSize(ct esp.ChipType, sizeId int) int {
case esp.ChipESP32:
fallthrough
case esp.ChipESP32C3:
fallthrough
case esp.ChipESP32S3:
return esp32.FlashSizes[sizeId]
case esp.ChipESP8266:
return esp8266.FlashSizes[sizeId]
Expand Down Expand Up @@ -169,6 +173,8 @@ func (fp *flashParams) SetSize(size int) error {
case esp.ChipESP32:
fallthrough
case esp.ChipESP32C3:
fallthrough
case esp.ChipESP32S3:
flashSizes = esp32.FlashSizes
case esp.ChipESP8266:
flashSizes = esp8266.FlashSizes
Expand Down Expand Up @@ -209,6 +215,8 @@ func (fp flashParams) String() string {
case esp.ChipESP32:
fallthrough
case esp.ChipESP32C3:
fallthrough
case esp.ChipESP32S3:
flashSizeToId = esp32.FlashSizeToId
case esp.ChipESP8266:
flashSizeToId = esp8266.FlashSizeToId
Expand Down
3 changes: 3 additions & 0 deletions cli/flash/esp/flasher/flasher_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/mongoose-os/mos/cli/flash/esp/rom_client"
"github.com/mongoose-os/mos/cli/flash/esp32"
"github.com/mongoose-os/mos/cli/flash/esp32c3"
"github.com/mongoose-os/mos/cli/flash/esp32s3"
"github.com/mongoose-os/mos/cli/flash/esp8266"
)

Expand Down Expand Up @@ -97,6 +98,8 @@ func (fc *FlasherClient) connect(romBaudRate, baudRate uint) error {
switch fc.ct {
case esp.ChipESP32:
stubJSON = esp32.MustAsset("stub/stub.json")
case esp.ChipESP32S3:
stubJSON = esp32s3.MustAsset("stub/stub.json")
case esp.ChipESP32C3:
stubJSON = esp32c3.MustAsset("stub/stub.json")
case esp.ChipESP8266:
Expand Down
3 changes: 3 additions & 0 deletions cli/flash/esp/rom_client/rom_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/mongoose-os/mos/cli/flash/esp"
"github.com/mongoose-os/mos/cli/flash/esp32"
"github.com/mongoose-os/mos/cli/flash/esp32c3"
"github.com/mongoose-os/mos/cli/flash/esp32s3"
"github.com/mongoose-os/mos/cli/flash/esp8266"
glog "k8s.io/klog/v2"
)
Expand Down Expand Up @@ -187,6 +188,8 @@ func (rc *ROMClient) GetChipDescr() (string, error) {
switch rc.ct {
case esp.ChipESP32:
return esp32.GetChipDescr(rc)
case esp.ChipESP32S3:
return esp32s3.GetChipDescr(rc)
case esp.ChipESP32C3:
return esp32c3.GetChipDescr(rc)
case esp.ChipESP8266:
Expand Down
219 changes: 219 additions & 0 deletions cli/flash/esp32s3/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions cli/flash/esp32s3/esp32s3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Copyright (c) 2014-2019 Cesanta Software Limited
// All rights reserved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate go-bindata -pkg esp32s3 -nocompress -modtime 1 -mode 420 stub/stub.json

package esp32s3

import (
"fmt"

"github.com/juju/errors"
"github.com/mongoose-os/mos/cli/flash/esp"
)

const (
EFUSE_BASE = 0x60007000
)

func GetChipDescr(rr esp.RegReader) (string, error) {
efuse_rd_mac_spi_sys_3_reg, err := rr.ReadReg(EFUSE_BASE + 0x50)
if err != nil {
return "", errors.Annotatef(err, "failed to read eFuse reg")
}
chip_pkg := (efuse_rd_mac_spi_sys_3_reg >> 21) & 0x7
var chip_pkg_str string
switch chip_pkg {
case 0:
chip_pkg_str = "ESP32-S3"
default:
chip_pkg_str = fmt.Sprintf("?(%d", chip_pkg)
}
chip_rev := (efuse_rd_mac_spi_sys_3_reg >> 18) & 0x7
return fmt.Sprintf("%s R%d", chip_pkg_str, chip_rev), nil
}
34 changes: 34 additions & 0 deletions cli/flash/esp32s3/stub/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2015 Cesanta Software Limited
# All rights reserved
#

STUB ?= stub.json
COMMON_STUB_DIR = ../../esp/stub
SDK ?= docker.io/mgos/esp32-build:4.4.1-r2
LIBS ?=

SRCS = $(LIBS) $(COMMON_STUB_DIR)/stub_flasher.c $(COMMON_STUB_DIR)/slip.c

.PHONY: all

all: $(STUB)

$(STUB): $(SRCS) $(COMMON_STUB_DIR)/wrap_stub.py
@echo " $(SRCS) -> $@"
docker run --rm -i -v '$(CURDIR)/../..:/src' $(SDK) /bin/bash -c \
"cd /src/esp32s3/stub && \
xtensa-esp32s3-elf-gcc -std=c99 -Wall -Werror -Os -DESP32S3 \
-mtext-section-literals -mlongcalls -nostdlib -fno-builtin -ggdb \
-DCONFIG_IDF_TARGET_ESP32S3 -DCONFIG_IDF_TARGET_ARCH_XTENSA \
-I/src/esp32s3/stub \
-I/opt/Espressif/esp-idf/components/esp_common/include \
-I/opt/Espressif/esp-idf/components/esp_rom/include \
-I/opt/Espressif/esp-idf/components/soc/include \
-I/opt/Espressif/esp-idf/components/soc/esp32s3/include \
-I/opt/Espressif/esp-idf/components/spi_flash/include \
-I/opt/Espressif/esp-idf/components/xtensa/include \
-L/opt/Espressif/esp-idf \
-ffunction-sections -Wl,-static -Wl,--gc-sections \
-Tstub.ld -o /tmp/stub.elf $(SRCS) && \
$(COMMON_STUB_DIR)/wrap_stub.py --output=$@ /tmp/stub.elf"
Loading

0 comments on commit 0f391ce

Please sign in to comment.