From f2c17121d2dd45ed743fc33a39cabd9dbafd957d Mon Sep 17 00:00:00 2001 From: M4x1m3 Date: Sat, 26 Feb 2022 13:36:54 +0100 Subject: [PATCH] [bootloader] Added trampolines --- bootloader/Makefile | 1 + bootloader/trampoline.cpp | 33 ++++++++++++++++++++++++++ bootloader/trampoline.h | 12 ++++++++++ build/targets.device.n0110.mak | 2 +- ion/src/device/n0110/drivers/power.h | 1 + ion/src/device/n0110/internal_flash.ld | 6 +++++ 6 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 bootloader/trampoline.cpp create mode 100644 bootloader/trampoline.h diff --git a/bootloader/Makefile b/bootloader/Makefile index 948599786..8a4a0b0c6 100644 --- a/bootloader/Makefile +++ b/bootloader/Makefile @@ -4,6 +4,7 @@ bootloader_src += $(addprefix bootloader/,\ slot.cpp \ interface.cpp \ jump_to_firmware.s \ + trampoline.cpp \ ) bootloader_images = $(addprefix bootloader/, \ diff --git a/bootloader/trampoline.cpp b/bootloader/trampoline.cpp new file mode 100644 index 000000000..b69a79f18 --- /dev/null +++ b/bootloader/trampoline.cpp @@ -0,0 +1,33 @@ +#include + +#include +#include + +#include "trampoline.h" + +namespace Bootloader { + +void __attribute__((noinline)) suspend() { + Ion::Device::Power::internalFlashSuspend(true); +} + +void* Trampolines[TRAMPOLINES_COUNT] + __attribute__((section(".trampolines_table"))) + __attribute__((used)) + = { + (void*) Bootloader::suspend, // Suspend + (void*) Ion::Device::Flash::EraseSector, // External erase + (void*) Ion::Device::Flash::WriteMemory, // External write + (void*) memcmp, + (void*) memcpy, + (void*) memmove, + (void*) memset, + (void*) strchr, + (void*) strcmp, + (void*) strlcat, + (void*) strlcpy, + (void*) strlen, + (void*) strncmp +}; + +} \ No newline at end of file diff --git a/bootloader/trampoline.h b/bootloader/trampoline.h new file mode 100644 index 000000000..49df37b6f --- /dev/null +++ b/bootloader/trampoline.h @@ -0,0 +1,12 @@ +#ifndef BOOTLOADER_TRAMPOLINE_H +#define BOOTLOADER_TRAMPOLINE_H + +namespace Bootloader { + +#define TRAMPOLINES_COUNT 13 + +extern void* Trampolines[TRAMPOLINES_COUNT]; + +} + +#endif \ No newline at end of file diff --git a/build/targets.device.n0110.mak b/build/targets.device.n0110.mak index d5e7dd30e..3199293f9 100644 --- a/build/targets.device.n0110.mak +++ b/build/targets.device.n0110.mak @@ -7,7 +7,7 @@ $(BUILD_DIR)/test.external_flash.write.$(EXE): $(BUILD_DIR)/quiz/src/test_ion_ex $(BUILD_DIR)/bootloader.$(EXE): $(call flavored_object_for,$(bootloader_src),usbxip) -$(BUILD_DIR)/bootloader.$(EXE): LDSCRIPT = ion/test/device/n0110/external_flash_tests.ld +$(BUILD_DIR)/bootloader.$(EXE): LDSCRIPT = ion/src/device/n0110/internal_flash.ld .PHONY: %_flash %_flash: $(BUILD_DIR)/%.dfu diff --git a/ion/src/device/n0110/drivers/power.h b/ion/src/device/n0110/drivers/power.h index a3d142bc1..1fbc55acf 100644 --- a/ion/src/device/n0110/drivers/power.h +++ b/ion/src/device/n0110/drivers/power.h @@ -8,6 +8,7 @@ namespace Device { namespace Power { void standbyConfiguration(); +void internalFlashSuspend(bool isLEDActive); } } diff --git a/ion/src/device/n0110/internal_flash.ld b/ion/src/device/n0110/internal_flash.ld index 76089e337..9eb193676 100644 --- a/ion/src/device/n0110/internal_flash.ld +++ b/ion/src/device/n0110/internal_flash.ld @@ -6,6 +6,7 @@ MEMORY { } STACK_SIZE = 32K; +TRAMPOLINES_OFFSET = 0xE000; SECTIONS { .isr_vector_table ORIGIN(INTERNAL_FLASH) : { @@ -69,6 +70,11 @@ SECTIONS { _data_section_end_ram = .; } >SRAM AT> INTERNAL_FLASH + .trampolines_table : { + . = ORIGIN(INTERNAL_FLASH) + TRAMPOLINES_OFFSET; + KEEP(*(.trampolines_table)); + } > INTERNAL_FLASH + .bss : { /* The bss section contains data for all uninitialized variables * So like the .data section, it will go in RAM, but unlike the data section