From e276031faae42d6c075913fc8ff810dd3b384997 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 23 Oct 2019 20:54:10 +1100 Subject: [PATCH] HAL_ChibiOS: support uncompressed bootloader on f103-periph this allows update with very low memory --- libraries/AP_HAL_ChibiOS/Util.cpp | 10 +++++----- libraries/AP_HAL_ChibiOS/hwdef/f103-periph/hwdef.dat | 4 ++++ .../AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py | 2 ++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/Util.cpp b/libraries/AP_HAL_ChibiOS/Util.cpp index 2e6c39f969..11b6b2abd9 100644 --- a/libraries/AP_HAL_ChibiOS/Util.cpp +++ b/libraries/AP_HAL_ChibiOS/Util.cpp @@ -233,7 +233,7 @@ bool Util::flash_bootloader() EXPECT_DELAY_MS(11000); - uint8_t *fw = AP_ROMFS::find_decompress(fw_name, fw_size); + const uint8_t *fw = AP_ROMFS::find_decompress(fw_name, fw_size); if (!fw) { hal.console->printf("failed to find %s\n", fw_name); return false; @@ -245,14 +245,14 @@ bool Util::flash_bootloader() const uint32_t addr = hal.flash->getpageaddr(0); if (!memcmp(fw, (const void*)addr, fw_size)) { hal.console->printf("Bootloader up-to-date\n"); - free(fw); + AP_ROMFS::free(fw); return true; } hal.console->printf("Erasing\n"); if (!hal.flash->erasepage(0)) { hal.console->printf("Erase failed\n"); - free(fw); + AP_ROMFS::free(fw); return false; } hal.console->printf("Flashing %s @%08x\n", fw_name, (unsigned int)addr); @@ -267,12 +267,12 @@ bool Util::flash_bootloader() continue; } hal.console->printf("Flash OK\n"); - free(fw); + AP_ROMFS::free(fw); return true; } hal.console->printf("Flash failed after %u attempts\n", max_attempts); - free(fw); + AP_ROMFS::free(fw); return false; } #endif // !HAL_NO_FLASH_SUPPORT && !HAL_NO_ROMFS_SUPPORT diff --git a/libraries/AP_HAL_ChibiOS/hwdef/f103-periph/hwdef.dat b/libraries/AP_HAL_ChibiOS/hwdef/f103-periph/hwdef.dat index ce3fc3bba6..2b3bc6999b 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/f103-periph/hwdef.dat +++ b/libraries/AP_HAL_ChibiOS/hwdef/f103-periph/hwdef.dat @@ -146,3 +146,7 @@ env APP_DESCRIPTOR MissionPlanner RAM_RESERVE_START 256 # define CH_DBG_ENABLE_STACK_CHECK TRUE + +# keep ROMFS uncompressed as we don't have enough RAM +# to uncompress the bootloader at runtime +env ROMFS_UNCOMPRESSED True diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index dd5fddda32..bdf4edbc0e 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -673,6 +673,8 @@ def write_mcu_config(f): #define HAL_USE_I2C FALSE #define HAL_USE_PWM FALSE ''') + if env_vars.get('ROMFS_UNCOMPRESSED', False): + f.write('#define HAL_ROMFS_UNCOMPRESSED\n') def write_ldscript(fname): '''write ldscript.ld for this board'''