From e200de1f573d00dd3957e13d9240fd05d4951e08 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 9 Jul 2018 16:47:35 +1000 Subject: [PATCH] AP_IOMCU: use compressed interface for IO fw upload --- libraries/AP_IOMCU/AP_IOMCU.cpp | 11 ++++++++--- libraries/AP_IOMCU/AP_IOMCU.h | 5 +++-- libraries/AP_IOMCU/fw_uploader.cpp | 5 +---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libraries/AP_IOMCU/AP_IOMCU.cpp b/libraries/AP_IOMCU/AP_IOMCU.cpp index b13829a35d..6fd357bf83 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.cpp +++ b/libraries/AP_IOMCU/AP_IOMCU.cpp @@ -643,9 +643,8 @@ bool AP_IOMCU::check_crc(void) { // flash size minus 4k bootloader const uint32_t flash_size = 0x10000 - 0x1000; - uint32_t fw_size; - fw = AP_ROMFS::find_file(fw_name, fw_size); + fw = AP_ROMFS::find_decompress(fw_name, fw_size); if (!fw) { hal.console->printf("failed to find %s\n", fw_name); return false; @@ -664,16 +663,22 @@ bool AP_IOMCU::check_crc(void) io_crc == crc) { hal.console->printf("IOMCU: CRC ok\n"); crc_is_ok = true; + free(fw); + fw = nullptr; return true; } const uint16_t magic = REBOOT_BL_MAGIC; write_registers(PAGE_SETUP, PAGE_REG_SETUP_REBOOT_BL, 1, &magic); - if (!upload_fw(fw_name)) { + if (!upload_fw()) { + free(fw); + fw = nullptr; AP_BoardConfig::sensor_config_error("Failed to update IO firmware"); } + free(fw); + fw = nullptr; return false; } diff --git a/libraries/AP_IOMCU/AP_IOMCU.h b/libraries/AP_IOMCU/AP_IOMCU.h index 69c76df29b..1216404909 100644 --- a/libraries/AP_IOMCU/AP_IOMCU.h +++ b/libraries/AP_IOMCU/AP_IOMCU.h @@ -211,9 +211,10 @@ private: // firmware upload const char *fw_name = "io_firmware.bin"; - const uint8_t *fw; + uint8_t *fw; + uint32_t fw_size; - bool upload_fw(const char *filename); + bool upload_fw(void); bool recv_byte_with_timeout(uint8_t *c, uint32_t timeout_ms); bool recv_bytes(uint8_t *p, uint32_t count); void drain(void); diff --git a/libraries/AP_IOMCU/fw_uploader.cpp b/libraries/AP_IOMCU/fw_uploader.cpp index c548a11985..f2013ccbca 100644 --- a/libraries/AP_IOMCU/fw_uploader.cpp +++ b/libraries/AP_IOMCU/fw_uploader.cpp @@ -63,11 +63,8 @@ extern const AP_HAL::HAL &hal; /* upload a firmware to the IOMCU */ -bool AP_IOMCU::upload_fw(const char *filename) +bool AP_IOMCU::upload_fw(void) { - uint32_t fw_size; - fw = AP_ROMFS::find_file(filename, fw_size); - // set baudrate for bootloader uart.begin(115200, 256, 256);