|
33 | 33 | #include "tls/utility/CryptoUtil.h" |
34 | 34 | #endif |
35 | 35 |
|
36 | | -#if defined(ARDUINO_PORTENTA_H7_M7) |
| 36 | +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) |
| 37 | +# include <algorithm> |
37 | 38 | # include "tls/utility/SHA256.h" |
38 | 39 | # include <stm32h7xx_hal_rtc_ex.h> |
39 | 40 | #endif |
|
45 | 46 |
|
46 | 47 | #include "utility/watchdog/Watchdog.h" |
47 | 48 |
|
| 49 | + |
48 | 50 | /****************************************************************************** |
49 | 51 | * EXTERN |
50 | 52 | ******************************************************************************/ |
@@ -579,83 +581,15 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l |
579 | 581 | #if OTA_ENABLED |
580 | 582 | void ArduinoIoTCloudTCP::onOTARequest() |
581 | 583 | { |
582 | | -#ifdef ARDUINO_ARCH_SAMD |
583 | | - samd_watchdog_reset(); |
584 | | -#endif /* ARDUINO_ARCH_SAMD */ |
585 | | - |
586 | 584 | DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s _ota_url = %s", __FUNCTION__, _ota_url.c_str()); |
587 | 585 |
|
588 | | -#if OTA_STORAGE_SNU |
589 | | - /* Just to be safe delete any remains from previous updates. */ |
590 | | - WiFiStorage.remove("/fs/UPDATE.BIN.LZSS"); |
591 | | - WiFiStorage.remove("/fs/UPDATE.BIN.LZSS.TMP"); |
592 | | - |
593 | 586 | #ifdef ARDUINO_ARCH_SAMD |
594 | | - samd_watchdog_reset(); |
595 | | -#endif /* ARDUINO_ARCH_SAMD */ |
596 | | - |
597 | | - /* Trigger direct download to nina module. */ |
598 | | - uint8_t nina_ota_err_code = 0; |
599 | | - if (!WiFiStorage.downloadOTA(_ota_url.c_str(), &nina_ota_err_code)) |
600 | | - { |
601 | | - DEBUG_ERROR("ArduinoIoTCloudTCP::%s error download to nina: %d", __FUNCTION__, nina_ota_err_code); |
602 | | - _ota_error = static_cast<int>(OTAError::DownloadFailed); |
603 | | - return; |
604 | | - } |
605 | | - |
606 | | - /* Perform the reset to reboot to SxU. */ |
607 | | - NVIC_SystemReset(); |
608 | | -#endif /* OTA_STORAGE_SNU */ |
609 | | - |
610 | | -#if OTA_STORAGE_PORTENTA_QSPI |
611 | | - mbed_watchdog_reset(); |
612 | | - |
613 | | - Arduino_Portenta_OTA::Error ota_portenta_err = Arduino_Portenta_OTA::Error::None; |
614 | | - /* Use 2nd partition of QSPI (1st partition contains WiFi firmware) */ |
615 | | - Arduino_Portenta_OTA_QSPI ota_portenta_qspi(QSPI_FLASH_FATFS_MBR, 2); |
616 | | - |
617 | | - mbed_watchdog_reset(); |
618 | | - |
619 | | - /* Initialize the QSPI memory for OTA handling. */ |
620 | | - if((ota_portenta_err = ota_portenta_qspi.begin()) != Arduino_Portenta_OTA::Error::None) { |
621 | | - DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::begin() failed with %d", static_cast<int>(ota_portenta_err)); |
622 | | - return; |
623 | | - } |
624 | | - |
625 | | - mbed_watchdog_reset(); |
626 | | - |
627 | | - /* Just to be safe delete any remains from previous updates. */ |
628 | | - remove("/fs/UPDATE.BIN"); |
629 | | - remove("/fs/UPDATE.BIN.LZSS"); |
630 | | - |
631 | | - mbed_watchdog_reset(); |
632 | | - |
633 | | - /* Download the OTA file from the web storage location. */ |
634 | | - int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download((char*)(_ota_url.c_str()), true /* is_https */); |
635 | | - DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::download(%s) returns %d", _ota_url.c_str(), ota_portenta_qspi_download_ret_code); |
636 | | - |
637 | | - mbed_watchdog_reset(); |
638 | | - |
639 | | - /* Decompress the LZSS compressed OTA file. */ |
640 | | - int const ota_portenta_qspi_decompress_ret_code = ota_portenta_qspi.decompress(); |
641 | | - DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::decompress() returns %d", ota_portenta_qspi_decompress_ret_code); |
642 | | - if (ota_portenta_qspi_decompress_ret_code < 0) |
643 | | - { |
644 | | - DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::decompress() failed with %d", ota_portenta_qspi_decompress_ret_code); |
645 | | - return; |
646 | | - } |
647 | | - |
648 | | - mbed_watchdog_reset(); |
649 | | - |
650 | | - /* Schedule the firmware update. */ |
651 | | - if((ota_portenta_err = ota_portenta_qspi.update()) != Arduino_Portenta_OTA::Error::None) { |
652 | | - DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::update() failed with %d", static_cast<int>(ota_portenta_err)); |
653 | | - return; |
654 | | - } |
| 587 | + _ota_error = samd_onOTARequest(_ota_url.c_str()); |
| 588 | +#endif |
655 | 589 |
|
656 | | - /* Perform the reset to reboot - then the bootloader performs the actual application update. */ |
657 | | - NVIC_SystemReset(); |
658 | | -#endif /* OTA_STORAGE_PORTENTA_QSPI */ |
| 590 | +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) |
| 591 | + _ota_error = portenta_h7_onOTARequest(_ota_url.c_str()); |
| 592 | +#endif |
659 | 593 | } |
660 | 594 | #endif |
661 | 595 |
|
|
0 commit comments