Skip to content

Commit

Permalink
Merge pull request tock#4169 from tock/kernel-linker-apps2
Browse files Browse the repository at this point in the history
boards: linker: do not load .apps section by default
  • Loading branch information
ppannuto authored Sep 25, 2024
2 parents fe99a8a + d6ae7fa commit b6a54d4
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 140 deletions.
2 changes: 1 addition & 1 deletion boards/esp32-c3-devkitM-1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ flash-app: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
ifeq ($(APP),)
$(error "Please specify an APP to be flashed")
endif
$(RISC_PREFIX)-objcopy --update-section .apps=$(APP) $^ $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.elf
$(RISC_PREFIX)-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $^ $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.elf
esptool.py --port /dev/ttyUSB0 --chip esp32c3 elf2image --use_segments --output binary.hex $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.elf --dont-append-digest
esptool.py --port /dev/ttyUSB0 --chip esp32c3 write_flash --flash_mode dio --flash_size detect --flash_freq 80m 0x0 binary.hex

Expand Down
2 changes: 1 addition & 1 deletion boards/imxrt1050-evkb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
.PHONY: flash-app
flash-app: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
@: $(if $(value APP),,$(error Please set APP to the path of a TBF file to program applications))
arm-none-eabi-objcopy --update-section .apps=$(APP) $< \
arm-none-eabi-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $< \
$(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-apps.elf
crt_emu_cm_redlink \
--flash-load-exec "$(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-apps.elf" \
Expand Down
1 change: 1 addition & 0 deletions boards/imxrt1050-evkb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ with your app(s) included.

```bash
$ arm-none-eabi-objcopy \
--set-section-flags .apps=LOAD \
--update-section .apps=../../../libtock-c/examples/c_hello/build/cortex-m7/cortex-m7.tbf \
target/thumbv7em-none-eabi/debug/imxrt1050-evkb.elf \
target/thumbv7em-none-eabi/debug/imxrt1050-evkb-app.axf
Expand Down
8 changes: 6 additions & 2 deletions boards/kernel_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,13 @@ SECTIONS
* This section is put into the "prog" memory, which is reserved for
* applications. This section is not used for the kernel, but including it
* in the .elf file allows for concatenating application binaries with the
* kernel.
* kernel. By default the loader will not include this section in the
* flashed binary. For boards that wish to use this section, it can be set
* to load with `objcopy` similar to:
*
* arm-none-eabi-objcopy --set-section-flags .apps=LOAD <elf>
*/
.apps :
.apps (NOLOAD) :
{
/* _sapps symbol used by Tock to look for first application. */
. = ALIGN(4);
Expand Down
6 changes: 3 additions & 3 deletions boards/nano_rp2040_connect/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
.PHONY: flash-app
flash-app: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
ifeq ($(APP),)
$(error Please define the APP variable with the TBF file to flash an application)
endif
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(error Please define the APP variable with the TBF file to flash an application)
endif
arm-none-eabi-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
elf2uf2-rs $(KERNEL_WITH_APP) $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2
@if [ -d $(BOOTSEL_FOLDER) ]; then cp $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2 "$(BOOTSEL_FOLDER)"; else echo; echo Please edit the BOOTSEL_FOLDER variable to point to you Nano RP2040 Flash Drive Folder; fi

Expand Down
3 changes: 2 additions & 1 deletion boards/nucleo_f429zi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ apps included.

```bash
$ arm-none-eabi-objcopy \
--set-section-flags .apps=LOAD \
--update-section .apps=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf \
target/thumbv7em-none-eabi/debug/nucleo_f429zi.elf \
target/thumbv7em-none-eabi/debug/nucleo_f429zi-app.elf
Expand All @@ -44,7 +45,7 @@ KERNEL_WITH_APP=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/debug/$(PLATFORM)-app.el
.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).elf
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
arm-none-eabi-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(KERNEL_WITH_APP); verify_image $(KERNEL_WITH_APP); reset; shutdown"
```

Expand Down
3 changes: 2 additions & 1 deletion boards/nucleo_f446re/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ apps included.

```bash
$ arm-none-eabi-objcopy \
--set-section-flags .apps=LOAD \
--update-section .apps=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf \
target/thumbv7em-none-eabi/debug/nucleo_f446re.elf \
target/thumbv7em-none-eabi/debug/nucleo_f446re-app.elf
Expand All @@ -44,7 +45,7 @@ KERNEL_WITH_APP=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/debug/$(PLATFORM)-app.el
.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).elf
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
arm-none-eabi-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(KERNEL_WITH_APP); verify_image $(KERNEL_WITH_APP); reset; shutdown"
```

Expand Down
4 changes: 2 additions & 2 deletions boards/opentitan/earlgrey-cw310/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
$(OPENTITAN_TREE)/bazel-bin/sw/host/opentitantool/opentitantool.runfiles/lowrisc_opentitan/sw/host/opentitantool/opentitantool --interface=cw310 bootstrap $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin

flash-app: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
$(RISC_PREFIX)-objcopy --update-section .apps=$(APP) $^ $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.elf
$(RISC_PREFIX)-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $^ $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.elf
$(RISC_PREFIX)-objcopy --output-target=binary $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.elf $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.bin
$(OPENTITAN_TREE)/bazel-bin/sw/host/opentitantool/opentitantool.runfiles/lowrisc_opentitan/sw/host/opentitantool/opentitantool --interface=cw310 bootstrap $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.bin

Expand All @@ -91,7 +91,7 @@ verilator: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
$(RISC_PREFIX)-objcopy $^ $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_verilator.elf
ifneq ($(APP),)
$(info [CW-130: Verilator]: Linking App)
$(RISC_PREFIX)-objcopy --update-section .apps=$(APP) $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_verilator.elf $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_verilator.elf
$(RISC_PREFIX)-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_verilator.elf $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_verilator.elf
endif
$(info [CW-130: Verilator]: Starting)
$(RISC_PREFIX)-objcopy --output-target=binary $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_verilator.elf $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)_verilator.bin
Expand Down
6 changes: 3 additions & 3 deletions boards/pico_explorer_base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ flash: $(KERNEL)
.PHONY: program
program: $(KERNEL)
ifeq ($(APP),)
$(error Please define the APP variable with the TBF file to flash an application)
endif
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(error Please define the APP variable with the TBF file to flash an application)
endif
arm-none-eabi-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
elf2uf2-rs $(KERNEL_WITH_APP) $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2
@if [ -d $(BOOTSEL_FOLDER) ]; then cp $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2 "$(BOOTSEL_FOLDER)"; else echo; echo Please edit the BOOTSEL_FOLDER variable to point to you Raspberry Pi Pico Flash Drive Folder; echo You can download and flash $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2; fi

6 changes: 3 additions & 3 deletions boards/raspberry_pi_pico/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ flash: $(KERNEL)
.PHONY: program
program: $(KERNEL)
ifeq ($(APP),)
$(error Please define the APP variable with the TBF file to flash an application)
endif
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(error Please define the APP variable with the TBF file to flash an application)
endif
arm-none-eabi-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
elf2uf2-rs $(KERNEL_WITH_APP) $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2
@if [ -d $(BOOTSEL_FOLDER) ]; then cp $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2 "$(BOOTSEL_FOLDER)"; else echo; echo Please edit the BOOTSEL_FOLDER variable to point to you Raspberry Pi Pico Flash Drive Folder; echo You can download and flash $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-app.uf2; fi

40 changes: 0 additions & 40 deletions boards/stm32f3discovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,3 @@ $ make flash

$ make flash-debug
```

> **Note:** Unlike other Tock platforms, the default kernel image for this
> board will clear flashed apps when the kernel is loaded. This is to support
> the non-tockloader based app flash procedure below. To preserve loaded apps,
> comment out the `APP_HACK` variable in `src/main.rs`.
## Flashing app

Apps are built out-of-tree. Once an app is built, you can use
`arm-none-eabi-objcopy` with `--update-section` to create an ELF image with the
apps included.

```bash
$ arm-none-eabi-objcopy \
--update-section .apps=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf \
target/thumbv7em-none-eabi/release/stm32f3discovery.elf \
target/thumbv7em-none-eabi/release/stm32f3discovery-app.elf
```

For example, you can update `Makefile` as follows.

```
APP=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf
KERNEL=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/release/$(PLATFORM).elf
KERNEL_WITH_APP=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/release/$(PLATFORM)-app.elf
.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(KERNEL_WITH_APP); verify_image $(KERNEL_WITH_APP); reset; shutdown"
```

After setting `APP`, `KERNEL`, `KERNEL_WITH_APP`, and `program` target
dependency, you can do

```bash
$ make program
```

to flash the image.
40 changes: 0 additions & 40 deletions boards/stm32f412gdiscovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,6 @@ $ make flash
$ make flash-debug
```

> **Note:** Unlike other Tock platforms, the default kernel image for this
> board will clear flashed apps when the kernel is loaded. This is to support
> the non-tockloader based app flash procedure below. To preserve loaded apps,
> comment out the `APP_HACK` variable in `src/main.rs`.
## Flashing app

Apps are built out-of-tree. Once an app is built, you can use
`arm-none-eabi-objcopy` with `--update-section` to create an ELF image with the
apps included.

```bash
$ arm-none-eabi-objcopy \
--update-section .apps=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf \
target/thumbv7em-none-eabi/release/discovery_f412g.elf \
target/thumbv7em-none-eabi/release/discovery_f412g-app.elf
```

For example, you can update `Makefile` as follows.

```
APP=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf
KERNEL=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/release/$(PLATFORM).elf
KERNEL_WITH_APP=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/release/$(PLATFORM)-app.elf
.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(KERNEL_WITH_APP); verify_image $(KERNEL_WITH_APP); reset; shutdown"
```

After setting `APP`, `KERNEL`, `KERNEL_WITH_APP`, and `program` target
dependency, you can do

```bash
$ make program
```

to flash the image.

## OpenOCD Note
The release version of openocd does not fully support stm32412g discovery kit. Uploading seems to work
with the setup for nucelo429zi. The openocd.cfg file contains both setups, one being commented.
Expand Down
40 changes: 0 additions & 40 deletions boards/stm32f429idiscovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,3 @@ $ make flash

$ make flash-debug
```

> **Note:** Unlike other Tock platforms, the default kernel image for this
> board will clear flashed apps when the kernel is loaded. This is to support
> the non-tockloader based app flash procedure below. To preserve loaded apps,
> comment out the `APP_HACK` variable in `src/main.rs`.
## Flashing app

Apps are built out-of-tree. Once an app is built, you can use
`arm-none-eabi-objcopy` with `--update-section` to create an ELF image with the
apps included.

```bash
$ arm-none-eabi-objcopy \
--update-section .apps=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf \
target/thumbv7em-none-eabi/debug/stm32f429idiscovery.elf \
target/thumbv7em-none-eabi/debug/stm32f429idiscovery-app.elf
```

For example, you can update `Makefile` as follows.

```
APP=../../../libtock-c/examples/c_hello/build/cortex-m4/cortex-m4.tbf
KERNEL=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/debug/$(PLATFORM).elf
KERNEL_WITH_APP=$(TOCK_ROOT_DIRECTORY)/target/$(TARGET)/debug/$(PLATFORM)-app.elf
.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).elf
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(KERNEL_WITH_APP); verify_image $(KERNEL_WITH_APP); reset; shutdown"
```

After setting `APP`, `KERNEL`, `KERNEL_WITH_APP`, and `program` target
dependency, you can do

```bash
$ make program
```

to flash the image.
2 changes: 1 addition & 1 deletion boards/teensy40/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).hex
.PHONY: program-app
program-app: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).elf
@: $(if $(value APP),,$(error Please set APP to the path of a TBF file to program applications))
$(Q)arm-none-eabi-objcopy --update-section .apps=$(APP) $< $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-apps.elf
$(Q)arm-none-eabi-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $< $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-apps.elf
$(Q)$(OBJCOPY) -O ihex $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-apps.elf $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-apps.hex
teensy_loader_cli --mcu=TEENSY40 -w -v $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)-apps.hex

Expand Down
3 changes: 2 additions & 1 deletion boards/teensy40/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ with the Teensy 4 Tock kernel.

```bash
$ arm-none-eabi-objcopy \
--set-section-flags .apps=LOAD \
--update-section .apps=../../../libtock-c/examples/blink/build/cortex-m7/cortex-m7.tbf \
../../target/thumbv7em-none-eabi/release/teensy40.elf \
../../target/thumbv7em-none-eabi/release/teensy40-app.elf
Expand Down Expand Up @@ -72,7 +73,7 @@ KERNEL_WITH_APP_HEX=$(TOCK_ROOT_DIRECTORY)/target/teensy40/release/teensy40-app.

.PHONY: program
program: target/thumbv7em-none-eabi/release/teensy40.elf
arm-none-eabi-objcopy --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
arm-none-eabi-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $(KERNEL) $(KERNEL_WITH_APP)
arm-none-eabi-objcopy -O ihex $(KERNEL_WITH_APP) $(KERNEL_WITH_APP_HEX)
teensy_loader_cli -w -v --mcu=TEENSY40 $(KERNEL_WITH_APP_HEX)
```
Expand Down
2 changes: 1 addition & 1 deletion boards/weact_f401ccu6/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ flash: $(KERNEL)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $<; verify_image $<; reset; shutdown"

flash-app: $(KERNEL)
arm-none-eabi-objcopy --update-section .apps=$(APP) $< $(KERNEL_WITH_APP)
arm-none-eabi-objcopy --set-section-flags .apps=LOAD --update-section .apps=$(APP) $< $(KERNEL_WITH_APP)
$(OPENOCD) $(OPENOCD_OPTIONS) -c "init; reset halt; flash write_image erase $(KERNEL_WITH_APP); verify_image $(KERNEL_WITH_APP); reset; shutdown"
1 change: 1 addition & 0 deletions boards/weact_f401ccu6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ELF image with the apps included.

```bash
$ arm-none-eabi-objcopy \
--set-section-flags .apps=LOAD \
--update-section .apps=../../../libtock-c/examples/blink/build/cortex-m4/cortex-m4.tbf \
../../target/thumbv7em-none-eabihf/release/weact-f401ccu6.elf \
../../target/thumbv7em-none-eabihf/release/weact-f401ccu6-app.elf
Expand Down

0 comments on commit b6a54d4

Please sign in to comment.