AP_HAL_ChibiOS: add and use AP_BOOTLOADER_FLASHING_ENABLED

This commit is contained in:
Peter Barker 2023-04-20 09:32:32 +10:00 committed by Peter Barker
parent 401de797ed
commit 926c7d64b1
6 changed files with 31 additions and 16 deletions

View File

@ -253,9 +253,10 @@ uint64_t Util::get_hw_rtc() const
return stm32_get_utc_usec();
}
#if !defined(HAL_NO_FLASH_SUPPORT) && !defined(HAL_NO_ROMFS_SUPPORT)
#include <GCS_MAVLink/GCS.h>
#if AP_BOOTLOADER_FLASHING_ENABLED
#if HAL_GCS_ENABLED
#define Debug(fmt, args ...) do { gcs().send_text(MAV_SEVERITY_INFO, fmt, ## args); } while (0)
#endif // HAL_GCS_ENABLED
@ -264,6 +265,10 @@ uint64_t Util::get_hw_rtc() const
#define Debug(fmt, args ...) do { hal.console->printf(fmt, ## args); } while (0)
#endif
#ifdef HAL_NO_FLASH_SUPPORT
#error "Bootloader-flashing enabled but no flashing support"
#endif
Util::FlashBootloader Util::flash_bootloader()
{
uint32_t fw_size;
@ -371,7 +376,7 @@ Util::FlashBootloader Util::flash_bootloader()
AP_ROMFS::free(fw);
return FlashBootloader::FAIL;
}
#endif // !HAL_NO_FLASH_SUPPORT && !HAL_NO_ROMFS_SUPPORT
#endif // AP_BOOTLOADER_FLASHING_ENABLED
/*
display system identifer - board type and serial number

View File

@ -30,6 +30,10 @@ class ExpandingString;
#define HAL_ENABLE_SAVE_PERSISTENT_PARAMS (defined(STM32F7) || defined(STM32H7))
#endif
#ifndef AP_BOOTLOADER_FLASHING_ENABLED
#define AP_BOOTLOADER_FLASHING_ENABLED 0
#endif
class ChibiOS::Util : public AP_HAL::Util {
public:
static Util *from(AP_HAL::Util *util) {
@ -126,7 +130,7 @@ private:
get system clock in UTC microseconds
*/
uint64_t get_hw_rtc() const override;
#if !defined(HAL_NO_FLASH_SUPPORT) && !defined(HAL_NO_ROMFS_SUPPORT)
#if AP_BOOTLOADER_FLASHING_ENABLED
FlashBootloader flash_bootloader() override;
#endif

View File

@ -12,6 +12,7 @@ define AP_PERIPH_RANGEFINDER_PORT_DEFAULT 3
# we're too low on flash with old compiler for bootloader
define HAL_NO_ROMFS_SUPPORT
define AP_BOOTLOADER_FLASHING_ENABLED 0
# setup for MSP
define HAL_MSP_ENABLED 1

View File

@ -137,5 +137,6 @@ IOMCU_FW 1
MAIN_STACK 0x200
PROCESS_STACK 0x250
define HAL_DISABLE_LOOP_DELAY
define AP_BOOTLOADER_FLASHING_ENABLED 0
AUTOBUILD_TARGETS iofirmware

View File

@ -138,4 +138,6 @@ MAIN_STACK 0x200
PROCESS_STACK 0x250
define HAL_DISABLE_LOOP_DELAY
define AP_BOOTLOADER_FLASHING_ENABLED 0
AUTOBUILD_TARGETS iofirmware

View File

@ -2381,21 +2381,23 @@ def bootloader_path():
"Tools",
"bootloaders",
bootloader_filename)
if os.path.exists(bootloader_path):
return os.path.realpath(bootloader_path)
return None
return bootloader_path
def add_bootloader():
def embed_bootloader(f):
'''added bootloader to ROMFS'''
bp = bootloader_path()
if bp is not None and int(get_config('BOOTLOADER_EMBED', required=False, default='1')):
romfs["bootloader.bin"] = bp
env_vars['BOOTLOADER_EMBED'] = 1
else:
env_vars['BOOTLOADER_EMBED'] = 0
if not intdefines.get('AP_BOOTLOADER_FLASHING_ENABLED', 1):
# or, you know, not...
return
bp = bootloader_path()
if not os.path.exists(bp):
return
bp = os.path.realpath(bp)
romfs["bootloader.bin"] = bp
f.write("#define AP_BOOTLOADER_FLASHING_ENABLED 1\n")
def write_ROMFS(outdir):
@ -2559,7 +2561,7 @@ def write_hwdef_header(outfilename):
setup_apj_IDs()
write_USB_config(f)
add_bootloader()
embed_bootloader(f)
if len(romfs) > 0:
f.write('#define HAL_HAVE_AP_ROMFS_EMBEDDED_H 1\n')