From b6d5bda1201df61ce1075a3e24d181aa0d1c89a0 Mon Sep 17 00:00:00 2001 From: Yaya-Cout Date: Sun, 29 Dec 2024 11:57:44 +0100 Subject: [PATCH] [platformInfo] Hardcode recovery boot address to fix build on GCC 13+ --- bootloader/slots/userland_header.cpp | 2 +- ion/src/device/bootloader/boot/rt0.cpp | 6 +++--- ion/src/device/bootloader/bootloader_common.ld | 4 +--- ion/src/device/bootloader/platform_info.cpp | 13 +++++++++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bootloader/slots/userland_header.cpp b/bootloader/slots/userland_header.cpp index d32649f9d..80769e02a 100644 --- a/bootloader/slots/userland_header.cpp +++ b/bootloader/slots/userland_header.cpp @@ -44,7 +44,7 @@ const bool UserlandHeader::hasUpsilonExtras() const { return m_upsilonExtraMagicHeader == UpsilonExtraMagic && m_upsilonExtraMagicFooter == UpsilonExtraMagic; } -const uint16_t UserlandHeader::getExtraVersion() const { +const uint32_t UserlandHeader::getExtraVersion() const { return m_extraVersion; } diff --git a/ion/src/device/bootloader/boot/rt0.cpp b/ion/src/device/bootloader/boot/rt0.cpp index 02dcc5a19..90b634861 100644 --- a/ion/src/device/bootloader/boot/rt0.cpp +++ b/ion/src/device/bootloader/boot/rt0.cpp @@ -138,7 +138,7 @@ void __attribute__((noinline)) start() { void __attribute__((noinline)) __attribute__((section(".recovery_boot"))) __attribute__((used)) recovery_start() { // Here we are in the recovery boot. Ion::Device::Board::initFPU(); - + bool is_recoverying = Ion::Device::BootloaderSharedData::sharedBootloaderData()->storageAddress() != 0; if (is_recoverying) { @@ -146,7 +146,7 @@ void __attribute__((noinline)) __attribute__((section(".recovery_boot"))) __attr uint32_t size = Ion::Device::BootloaderSharedData::sharedBootloaderData()->storageSize(); size_t storageSize = (&_static_storage_end - &_static_storage_start); - + memcpy(&_static_storage_start, (void*)address, size); size_t dataSectionLength = (&_data_section_end_ram - &_data_section_start_ram); @@ -160,7 +160,7 @@ void __attribute__((noinline)) __attribute__((section(".recovery_boot"))) __attr size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram); memset(&_bss_section_start_ram, 0, bssSectionLength); } - + if (&_init_array_start != &_init_array_end) { abort(); } diff --git a/ion/src/device/bootloader/bootloader_common.ld b/ion/src/device/bootloader/bootloader_common.ld index 816e51bcc..f34094672 100644 --- a/ion/src/device/bootloader/bootloader_common.ld +++ b/ion/src/device/bootloader/bootloader_common.ld @@ -58,10 +58,8 @@ SECTIONS { } > FLASH .recovery_boot : { - . = ALIGN(4); - _recovery_boot_start = .; + . = ORIGIN(FLASH) + USERLAND_OFFSET + 0x100; KEEP(*(.recovery_boot)); - _recovery_boot_end = .; } >FLASH .text : { diff --git a/ion/src/device/bootloader/platform_info.cpp b/ion/src/device/bootloader/platform_info.cpp index 8396ca2d6..00d02b451 100644 --- a/ion/src/device/bootloader/platform_info.cpp +++ b/ion/src/device/bootloader/platform_info.cpp @@ -18,7 +18,7 @@ #endif extern "C" { - extern char _recovery_boot_start; + extern void recovery_start(); } namespace Ion { extern char staticStorageArea[]; @@ -77,7 +77,16 @@ public: m_osType(OSType), m_upsilonMagicFooter(UpsilonMagic), m_upsilonExtraMagicHeader(UpsilonExtraMagic), - m_recoveryAddress(((uint32_t)&_recovery_boot_start) + 1), + // FIXME: Since GCC 13, we can't longer store a pointer to a function in the + // class initialization. I don't know if it's a problem in GCC or our code, + // but it's a bit suspicious as the whole class is blank (0x00) in the + // binary with the data available nowhere else (searching for the username + // returns nothing). + // As a workaround, we fixed the address of recovery_start in flash using + // LD script (ion/src/device/bootloader/bootloader_common.ld). + // This line works on GCC 12 + // m_recoveryAddress((uint32_t)recovery_start + 1), + m_recoveryAddress(0x90010080 + 1), m_extraVersion(1), m_upsilonExtraMagicFooter(UpsilonExtraMagic) { }