Control: severity -1 important
Control: retitle -1  Please build and ship flasher_stubs

On Fri, Jan 03, 2020 at 10:31:25PM +0200, Faidon Liambotis wrote:
> The Debian package will require some d/rules mechanics + esptool.py
> patches to fully implement this (and on a per-chip basis), and it's
> still not going to provide a solution for the ESP32, but... progress :)
> 
> Hopefully picolibc will pass through NEW soon; as soon as that happens,
> please include support for building and shipping the stub in the Debian
> package. I'll try to provide some patches if I find the time, but please
> don't wait for me :)

Some good news: first of all, I've verified that the changes that I
pushed upstream 3 years ago (miniz etc.) continue to work. On a current
Debian system, all that it takes to build the esp8266 stub is to
  apt install gcc-xtensa-lx106 picolibc-xtensa-lx106-elf
...and then the stub will just build. (There is a tiny warning about no
debug support that is silenced by removing "-g" from CFLAGS). I've just
tested the resulting stub from a build on a sid system just now, with
the source from esptool v4.5, and it successfully flashed my esp8266.

Moreover, more good news: we can now build stubs for the RISC-V chips,
which as of now are ESP32-C3, ESP32-H2, ESP32-C2 and ESP32-C6. For this,
  apt install gcc-riscv64-unknown-elf picolibc-riscv64-unknown-elf
is required, plus:
  1. passing the right CROSS_ prefixes for every chip (configurable)
  2. passing -mabi=ilp32 to CFLAGS (upstreamable)
  3. passing -specs=picolibc.specs to CFLAGS (to use picolibc)
With these, I've successfully built a stub for a ESP32-C3, and then
subsequently used it to flash a LOLIN C3 mini with no issues.

And a small piece of bad news: we are still missing the toolchain (both
gcc and picolibc) for the ESP32, ESP32-S2 and ESP32-S3 chips. These
don't even exist upstream, and with the focus on the RISC-V chips I
doubt it'll ever happen now. We can just disable stubs for these.

I'm attaching three patches which, once applied, result into:
  make -C flasher_stub embed
to just work for all but three chips. Given this is just basic upstream
functionality that can be easily enabled in Debian, I'm also marking
this bug as important.

Best,
Faidon
>From 12348acccc020dcfc04122e7821c7bfea8adde6a Mon Sep 17 00:00:00 2001
From: Faidon Liambotis <parav...@debian.org>
Date: Tue, 21 Feb 2023 13:40:43 +0200
Subject: [PATCH 1/3] stub: Remove -g from the ESP8266 build flags

There is no debug support in the compiler. Without this, (otherwise
harmless) warnings are emitted:
  xtensa-lx106-elf-gcc: warning: target system does not support debug output
---
 flasher_stub/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flasher_stub/Makefile b/flasher_stub/Makefile
index 55b5fa9..0bbcc5f 100644
--- a/flasher_stub/Makefile
+++ b/flasher_stub/Makefile
@@ -85,7 +85,7 @@ $(BUILD_DIR):
 
 CFLAGS = -std=c99 -Wall -Werror -Os \
          -mtext-section-literals -mlongcalls -nostdlib -fno-builtin -flto \
-         -Wl,-static -g -ffunction-sections -Wl,--gc-sections -Iinclude -Lld
+         -Wl,-static -ffunction-sections -Wl,--gc-sections -Iinclude -Lld
 CFLAGS_ESPRISCV32 = -std=c99 -Wall -Werror -Os \
 		 -march=rv32imc -msmall-data-limit=0 \
          -nostdlib -fno-builtin -flto \
-- 
2.30.2

>From 28ba14a6480ca83f3a8734e06d907bbc33e85497 Mon Sep 17 00:00:00 2001
From: Faidon Liambotis <parav...@debian.org>
Date: Tue, 21 Feb 2023 13:42:03 +0200
Subject: [PATCH 2/3] stub: build with Debian's riscv64 gcc and picolibc

---
 flasher_stub/Makefile | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/flasher_stub/Makefile b/flasher_stub/Makefile
index 0bbcc5f..9c03332 100644
--- a/flasher_stub/Makefile
+++ b/flasher_stub/Makefile
@@ -36,11 +36,11 @@ CROSS_8266 ?= xtensa-lx106-elf-
 CROSS_32 ?= xtensa-esp32-elf-
 CROSS_32S2 ?= xtensa-esp32s2-elf-
 CROSS_32S3 ?= xtensa-esp32s3-elf-
-CROSS_32C3 ?= riscv32-esp-elf-
-CROSS_32C6BETA ?= riscv32-esp-elf-
-CROSS_32H2 ?= riscv32-esp-elf-
-CROSS_32C2 ?= riscv32-esp-elf-
-CROSS_32C6 ?= riscv32-esp-elf-
+CROSS_32C3 ?= riscv64-unknown-elf-
+CROSS_32C6BETA ?= riscv64-unknown-elf-
+CROSS_32H2 ?= riscv64-unknown-elf-
+CROSS_32C2 ?= riscv64-unknown-elf-
+CROSS_32C6 ?= riscv64-unknown-elf-
 
 # Python command to invoke wrap_stub.py
 WRAP_STUB ?= ./wrap_stub.py
@@ -87,7 +87,8 @@ CFLAGS = -std=c99 -Wall -Werror -Os \
          -mtext-section-literals -mlongcalls -nostdlib -fno-builtin -flto \
          -Wl,-static -ffunction-sections -Wl,--gc-sections -Iinclude -Lld
 CFLAGS_ESPRISCV32 = -std=c99 -Wall -Werror -Os \
-		 -march=rv32imc -msmall-data-limit=0 \
+		 -march=rv32imc -mabi=ilp32 -msmall-data-limit=0 \
+         -specs=picolibc.specs \
          -nostdlib -fno-builtin -flto \
          -Wl,-static -g -ffunction-sections -Wl,--gc-sections -Iinclude -Lld
 LDLIBS = -lgcc
-- 
2.30.2

>From 9c5e618ffc2dee30ca659871247355a8ad1fb0e2 Mon Sep 17 00:00:00 2001
From: Faidon Liambotis <parav...@debian.org>
Date: Tue, 21 Feb 2023 13:40:09 +0200
Subject: [PATCH 3/3] stub: disable ESP32 chips

We don't have a working compiler and toolchain for those.
---
 flasher_stub/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flasher_stub/Makefile b/flasher_stub/Makefile
index 9c03332..728e0cb 100644
--- a/flasher_stub/Makefile
+++ b/flasher_stub/Makefile
@@ -72,7 +72,7 @@ STUB_ELF_32H2 = $(BUILD_DIR)/$(STUB)_32h2.elf
 
 .PHONY: all esp32 clean embed embed_esp32
 
-all: $(STUB_ELF_8266) $(STUB_ELF_32) $(STUB_ELF_32S2) $(STUB_ELF_32S3_BETA_2) $(STUB_ELF_32S3) $(STUB_ELF_32C3) $(STUB_ELF_32C6BETA) $(STUB_ELF_32H2_BETA_1) $(STUB_ELF_32H2_BETA_2) $(STUB_ELF_32C2) $(STUB_ELF_32C6) $(STUB_ELF_32H2)
+all: $(STUB_ELF_8266) $(STUB_ELF_32C3) $(STUB_ELF_32C6BETA) $(STUB_ELF_32H2_BETA_1) $(STUB_ELF_32H2_BETA_2) $(STUB_ELF_32C2) $(STUB_ELF_32C6) $(STUB_ELF_32H2)
 	@echo "  WRAP $^ -> $(BUILD_DIR)"
 	$(Q) $(WRAP_STUB) $^
 
@@ -141,7 +141,7 @@ $(STUB_ELF_32H2): $(SRCS) $(BUILD_DIR) ld/stub_32h2.ld
 	@echo "  CC(32H2)   $^ -> $@"
 	$(Q) $(CROSS_32H2)gcc $(CFLAGS_ESPRISCV32) -DESP32H2=1 -Tstub_32h2.ld -Wl,-Map=$(@:.elf=.map) -o $@ $(filter %.c, $^) $(LDLIBS)
 
-embed: $(STUB_ELF_8266) $(STUB_ELF_32) $(STUB_ELF_32S2) $(STUB_ELF_32S3_BETA_2) $(STUB_ELF_32S3) $(STUB_ELF_32C3) $(STUB_ELF_32C6BETA) $(STUB_ELF_32H2_BETA_1) $(STUB_ELF_32H2_BETA_2) $(STUB_ELF_32C2) $(STUB_ELF_32C6) $(STUB_ELF_32H2)
+embed: $(STUB_ELF_8266) $(STUB_ELF_32C3) $(STUB_ELF_32C6BETA) $(STUB_ELF_32H2_BETA_1) $(STUB_ELF_32H2_BETA_2) $(STUB_ELF_32C2) $(STUB_ELF_32C6) $(STUB_ELF_32H2)
 	@echo "  WRAP $^ -> $(ESPTOOL_STUBS_DIR)"
 	$(Q) $(WRAP_STUB) --embed $^
 
-- 
2.30.2

Reply via email to