|
7 | 7 |
|
8 | 8 | include ../Makefile.common |
9 | 9 |
|
10 | | -OPENOCD=openocd |
11 | | -OPENOCD_OPTIONS=-f interface/stlink.cfg -f target/stm32u5x.cfg |
| 10 | +# Toolchain Variables |
| 11 | +PROBE_RS ?= probe-rs |
| 12 | +CHIP = STM32U545RETx |
| 13 | +OBJCOPY ?= arm-none-eabi-objcopy |
| 14 | + |
| 15 | +# NOTE: STM32U5 Metadata Stripping |
| 16 | +# The standard ELF file produced by the compiler contains metadata sections |
| 17 | +# (like .ARM.attributes) that sometimes point to System Memory addresses |
| 18 | +# (e.g., 0x0BFA0000). Many flashing tools, including probe-rs, will attempt |
| 19 | +# to write to these addresses, which are protected on the STM32U5, causing |
| 20 | +# the flash process to crash. |
| 21 | +# |
| 22 | +# We use 'objcopy -j' to extract ONLY the sections that belong |
| 23 | +# in the physical Flash memory (0x0C000000). This ensures a clean, |
| 24 | +# safe deployment to the hardware. |
12 | 25 |
|
13 | 26 | # Default target for installing the kernel. |
14 | 27 | .PHONY: install |
15 | 28 | install: flash |
16 | 29 |
|
17 | 30 | .PHONY: flash-debug |
18 | 31 | flash-debug: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).elf |
19 | | - $(OPENOCD) $(OPENOCD_OPTIONS) -c "init; halt; stm32l4x mass_erase 0; program $< verify reset exit" |
| 32 | + @echo "--- Preparing Clean Debug Kernel ELF ---" |
| 33 | + $(OBJCOPY) -j .text -j .ARM.exidx -j .storage -j .relocate $< $<.clean |
| 34 | + @echo "--- Flashing Debug Kernel via probe-rs ---" |
| 35 | + $(PROBE_RS) download --chip $(CHIP) --allow-erase-all $<.clean |
| 36 | + $(PROBE_RS) reset --chip $(CHIP) |
20 | 37 |
|
21 | 38 | .PHONY: flash |
22 | 39 | flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf |
23 | | - $(OPENOCD) $(OPENOCD_OPTIONS) -c "init; halt; stm32l4x mass_erase 0; program $< verify reset exit" |
| 40 | + @echo "--- Preparing Clean Release Kernel ELF ---" |
| 41 | + $(OBJCOPY) -j .text -j .ARM.exidx -j .storage -j .relocate $< $<.clean |
| 42 | + @echo "--- Flashing Release Kernel via probe-rs ---" |
| 43 | + $(PROBE_RS) download --chip $(CHIP) --allow-erase-all $<.clean |
| 44 | + $(PROBE_RS) reset --chip $(CHIP) |
24 | 45 |
|
25 | 46 | .PHONY: program |
26 | 47 | program: |
27 | | - tockloader install --openocd --board nucleo_u545re_q $(APP) |
| 48 | + # Note: tockloader does not natively wrap probe-rs yet. |
| 49 | + # The --openocd flag was removed; tockloader will use its default method (usually serial/jlink). |
| 50 | + tockloader install --board nucleo_u545re_q $(APP) |
0 commit comments