From d5a98d1905883bfb20592701ad0b756b78ee7b1f Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 5 Jul 2025 18:51:14 -0500 Subject: [PATCH] bricks/ev3: use .elf instead of uImage Replace creating a uImage with using the .elf file directly for the EV3 firmware. This simplifies the build process and avoids the need for u-boot-tools. U-Boot already knows how to load the .elf file, so we can use it directly by using `bootelf` instead of `bootm` (this change was made in the pybricks/v2.0.0 release of u-boot). In order to keep the size of the .elf file small, we do not enable `-ffunction-sections` and `-fdata-sections` for the EV3 firmware. This avoids the large tables of section names that are generated by these flags, which would otherwise increase the size of the .elf file by nearly 200 kB. The .elf file is still a bit larger than the uImage because of a bit more overhead, but only by less than 4kB. --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/stats.yml | 2 +- bricks/_common/arm_none_eabi.mk | 23 +++++++++++++---------- bricks/ev3/README.md | 6 ------ 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c8f27a4ae..6342fd25e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -93,7 +93,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Install cross-compiler - run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi u-boot-tools + run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi - name: Checkout repo uses: actions/checkout@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 33380d842..8070672b8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Install cross-compiler - run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi u-boot-tools + run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi - name: Checkout code uses: actions/checkout@v4 with: diff --git a/.github/workflows/stats.yml b/.github/workflows/stats.yml index 47206ffeb..cb2738cb1 100644 --- a/.github/workflows/stats.yml +++ b/.github/workflows/stats.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Install cross-compiler - run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi u-boot-tools + run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi - name: Checkout code uses: actions/checkout@v4 with: diff --git a/bricks/_common/arm_none_eabi.mk b/bricks/_common/arm_none_eabi.mk index 3361facb9..e698d5df1 100644 --- a/bricks/_common/arm_none_eabi.mk +++ b/bricks/_common/arm_none_eabi.mk @@ -160,7 +160,7 @@ ifeq ($(PB_MCU_FAMILY),AT91SAM7) CFLAGS_MCU = -mthumb -mthumb-interwork -mtune=arm7tdmi -mcpu=arm7tdmi -msoft-float else ifeq ($(PB_MCU_FAMILY),TIAM1808) -CFLAGS_MCU = -mcpu=arm926ej-s -Dgcc -Dam1808 # -c -g -fdata-sections -ffunction-sections -Wall -Dgcc -Dam1808 -O0 +CFLAGS_MCU = -mcpu=arm926ej-s -Dgcc -Dam1808 else $(error unsupported PB_MCU_FAMILY) endif @@ -196,8 +196,13 @@ else ifeq ($(DEBUG), 2) CFLAGS += -Os -DNDEBUG -flto=auto else CFLAGS += -Os -DNDEBUG -flto=auto +ifneq ($(PB_MCU_FAMILY),TIAM1808) +# This is used for trimming unused code on smaller platforms, but on EV3 we +# don't want to enable these flags in order to keep the size of the .elf file +# small by avoiding huge tables of section names. CFLAGS += -fdata-sections -ffunction-sections endif +endif ifeq ($(PB_MCU_FAMILY),STM32) # Required for STM32 library @@ -623,6 +628,10 @@ $(BUILD)/firmware.elf: $(LD_FILES) $(OBJ) $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(Q)$(SIZE) -A $@ +$(BUILD)/firmware.stripped.elf: $(BUILD)/firmware.elf + $(ECHO) "STRIP $@" + $(Q)$(STRIP) $< -o $@ + # firmware blob without checksum $(BUILD)/firmware-obj.bin: $(BUILD)/firmware.elf $(ECHO) "BIN creating firmware base file" @@ -635,13 +644,13 @@ ifeq ($(PB_MCU_FAMILY),TIAM1808) $(BUILD)/u-boot.bin: $(ECHO) "Downloading u-boot.bin" $(Q)mkdir -p $(dir $@) - $(Q)curl -sL -o $@ https://github.com/pybricks/u-boot/releases/download/pybricks/v1.0.2/u-boot.bin - $(Q)echo "62fe9df8138a4676d61b72c6844f9e7c3cbfd85470b9cea1418abec4f79228ac $@" | sha256sum -c --strict + $(Q)curl -sL -o $@ https://github.com/pybricks/u-boot/releases/download/pybricks/v2.0.0/u-boot.bin + $(Q)echo "570e079870ddc1deb2ce40d7a4d6785c151883a65e273ce6e33643152df90efb $@" | sha256sum -c --strict MAKE_BOOTABLE_IMAGE = $(PBTOP)/bricks/ev3/make_bootable_image.py # For EV3, merge firmware blob with u-boot to create a bootable image. -$(BUILD)/firmware-base.bin: $(MAKE_BOOTABLE_IMAGE) $(BUILD)/u-boot.bin $(BUILD)/uImage +$(BUILD)/firmware-base.bin: $(MAKE_BOOTABLE_IMAGE) $(BUILD)/u-boot.bin $(BUILD)/firmware.stripped.elf $(Q)$^ $@ else @@ -664,12 +673,6 @@ $(BUILD)/firmware.zip: $(ZIP_FILES) $(ECHO) "ZIP creating firmware package" $(Q)$(ZIP) -j $@ $^ -# firmware in uImage format (for EV3) -$(BUILD)/uImage: $(BUILD)/firmware-obj.bin $(BUILD)/firmware.elf - $(eval LOAD_ADDR := $(shell $(CROSS_COMPILE)readelf -l $(BUILD)/firmware.elf | grep "LOAD" | awk '{print $$4}')) - $(eval ENTRY_POINT := $(shell $(CROSS_COMPILE)readelf -h $(BUILD)/firmware.elf | grep "Entry point" | cut -d: -f2)) - mkimage -C none -A arm -T standalone -O u-boot -a $(LOAD_ADDR) -e $(ENTRY_POINT) -d $< $@ - # PRU firmware $(BUILD)/pru_suart.bin.o: $(PBTOP)/lib/pbio/drv/uart/uart_ev3_pru_lib/pru_suart.bin $(Q)$(OBJCOPY) -I binary -O elf32-littlearm -B arm \ diff --git a/bricks/ev3/README.md b/bricks/ev3/README.md index a49e38786..29ec49282 100644 --- a/bricks/ev3/README.md +++ b/bricks/ev3/README.md @@ -24,12 +24,6 @@ firmware for one of the other targets, such as the SPIKE Prime Hub, as explained [here](../../CONTRIBUTING.md). Make sure that `pybricksdev` is installed. -Install the following additional tools: - -``` -sudo apt install u-boot-tools -``` - Unlike most other alternative EV3 firmware solutions, Pybricks does not require using a microSD card. Instead, Pybricks is installed as a firmware update.