Skip to content

Commit 2c7a38e

Browse files
committed
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.
1 parent 52a2c62 commit 2c7a38e

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
runs-on: ubuntu-22.04
9494
steps:
9595
- name: Install cross-compiler
96-
run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi u-boot-tools
96+
run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi
9797
- name: Checkout repo
9898
uses: actions/checkout@v4
9999
with:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-22.04
1818
steps:
1919
- name: Install cross-compiler
20-
run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi u-boot-tools
20+
run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi
2121
- name: Checkout code
2222
uses: actions/checkout@v4
2323
with:

.github/workflows/stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-22.04
1414
steps:
1515
- name: Install cross-compiler
16-
run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi u-boot-tools
16+
run: sudo apt-get update && sudo apt-get install --yes gcc-arm-none-eabi
1717
- name: Checkout code
1818
uses: actions/checkout@v4
1919
with:

bricks/_common/arm_none_eabi.mk

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ ifeq ($(PB_MCU_FAMILY),AT91SAM7)
160160
CFLAGS_MCU = -mthumb -mthumb-interwork -mtune=arm7tdmi -mcpu=arm7tdmi -msoft-float
161161
else
162162
ifeq ($(PB_MCU_FAMILY),TIAM1808)
163-
CFLAGS_MCU = -mcpu=arm926ej-s -Dgcc -Dam1808 # -c -g -fdata-sections -ffunction-sections -Wall -Dgcc -Dam1808 -O0
163+
CFLAGS_MCU = -mcpu=arm926ej-s -Dgcc -Dam1808
164164
else
165165
$(error unsupported PB_MCU_FAMILY)
166166
endif
@@ -196,8 +196,13 @@ else ifeq ($(DEBUG), 2)
196196
CFLAGS += -Os -DNDEBUG -flto=auto
197197
else
198198
CFLAGS += -Os -DNDEBUG -flto=auto
199+
ifneq ($(PB_MCU_FAMILY),TIAM1808)
200+
# This is used for trimming unused code on smaller platforms, but on EV3 we
201+
# don't want to enable these flags in order to keep the size of the .elf file
202+
# small by avoiding huge tables of section names.
199203
CFLAGS += -fdata-sections -ffunction-sections
200204
endif
205+
endif
201206

202207
ifeq ($(PB_MCU_FAMILY),STM32)
203208
# Required for STM32 library
@@ -623,6 +628,10 @@ $(BUILD)/firmware.elf: $(LD_FILES) $(OBJ)
623628
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
624629
$(Q)$(SIZE) -A $@
625630

631+
$(BUILD)/firmware.stripped.elf: $(BUILD)/firmware.elf
632+
$(ECHO) "STRIP $@"
633+
$(Q)$(STRIP) $< -o $@
634+
626635
# firmware blob without checksum
627636
$(BUILD)/firmware-obj.bin: $(BUILD)/firmware.elf
628637
$(ECHO) "BIN creating firmware base file"
@@ -635,13 +644,13 @@ ifeq ($(PB_MCU_FAMILY),TIAM1808)
635644
$(BUILD)/u-boot.bin:
636645
$(ECHO) "Downloading u-boot.bin"
637646
$(Q)mkdir -p $(dir $@)
638-
$(Q)curl -sL -o $@ https://github.com/pybricks/u-boot/releases/download/pybricks/v1.0.2/u-boot.bin
639-
$(Q)echo "62fe9df8138a4676d61b72c6844f9e7c3cbfd85470b9cea1418abec4f79228ac $@" | sha256sum -c --strict
647+
$(Q)curl -sL -o $@ https://github.com/pybricks/u-boot/releases/download/pybricks/v2.0.0/u-boot.bin
648+
$(Q)echo "570e079870ddc1deb2ce40d7a4d6785c151883a65e273ce6e33643152df90efb $@" | sha256sum -c --strict
640649

641650
MAKE_BOOTABLE_IMAGE = $(PBTOP)/bricks/ev3/make_bootable_image.py
642651

643652
# For EV3, merge firmware blob with u-boot to create a bootable image.
644-
$(BUILD)/firmware-base.bin: $(MAKE_BOOTABLE_IMAGE) $(BUILD)/u-boot.bin $(BUILD)/uImage
653+
$(BUILD)/firmware-base.bin: $(MAKE_BOOTABLE_IMAGE) $(BUILD)/u-boot.bin $(BUILD)/firmware.stripped.elf
645654
$(Q)$^ $@
646655

647656
else
@@ -664,12 +673,6 @@ $(BUILD)/firmware.zip: $(ZIP_FILES)
664673
$(ECHO) "ZIP creating firmware package"
665674
$(Q)$(ZIP) -j $@ $^
666675

667-
# firmware in uImage format (for EV3)
668-
$(BUILD)/uImage: $(BUILD)/firmware-obj.bin $(BUILD)/firmware.elf
669-
$(eval LOAD_ADDR := $(shell $(CROSS_COMPILE)readelf -l $(BUILD)/firmware.elf | grep "LOAD" | awk '{print $$4}'))
670-
$(eval ENTRY_POINT := $(shell $(CROSS_COMPILE)readelf -h $(BUILD)/firmware.elf | grep "Entry point" | cut -d: -f2))
671-
mkimage -C none -A arm -T standalone -O u-boot -a $(LOAD_ADDR) -e $(ENTRY_POINT) -d $< $@
672-
673676
# PRU firmware
674677
$(BUILD)/pru_suart.bin.o: $(PBTOP)/lib/pbio/drv/uart/uart_ev3_pru_lib/pru_suart.bin
675678
$(Q)$(OBJCOPY) -I binary -O elf32-littlearm -B arm \

bricks/ev3/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ firmware for one of the other targets, such as the SPIKE Prime Hub, as
2424
explained [here](../../CONTRIBUTING.md). Make sure that `pybricksdev` is
2525
installed.
2626

27-
Install the following additional tools:
28-
29-
```
30-
sudo apt install u-boot-tools
31-
```
32-
3327
Unlike most other alternative EV3 firmware solutions, Pybricks does not require
3428
using a microSD card. Instead, Pybricks is installed as a firmware update.
3529

0 commit comments

Comments
 (0)