1
+ /*
2
+ This file is part of the ArduinoIoTCloud library.
3
+
4
+ Copyright (c) 2024 Arduino SA
5
+
6
+ This Source Code Form is subject to the terms of the Mozilla Public
7
+ License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ */
10
+
1
11
#pragma once
12
+ #include " ota/interface/OTAInterfaceDefault.h"
13
+
14
+ #if defined(ARDUINO_PORTENTA_OTA_QSPI_SUPPORT)
15
+ #include < QSPIFBlockDevice.h>
16
+ #endif
17
+
18
+ #if defined(ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT)
19
+ #include < SDMMCBlockDevice.h>
20
+ #endif
2
21
3
- #include " src/ota/interface/OTAInterface.h"
22
+ #include < BlockDevice.h>
23
+ #include < MBRBlockDevice.h>
24
+ #include < FATFileSystem.h>
25
+ #include < LittleFileSystem.h>
4
26
5
- class STM32H7OTACloudProcess : public OTACloudProcessInterface {
27
+ #include " WiFi.h" /* WiFi from ArduinoCore-mbed */
28
+ #include < SocketHelpers.h>
29
+
30
+ #define APOTA_QSPI_FLASH_FLAG (1 << 2 )
31
+ #define APOTA_SDCARD_FLAG (1 << 3 )
32
+ #define APOTA_RAW_FLAG (1 << 4 )
33
+ #define APOTA_FATFS_FLAG (1 << 5 )
34
+ #define APOTA_LITTLEFS_FLAG (1 << 6 )
35
+ #define APOTA_MBR_FLAG (1 << 7 )
36
+
37
+ namespace portenta {
38
+ enum StorageType {
39
+ QSPI_FLASH_FATFS = APOTA_QSPI_FLASH_FLAG | APOTA_FATFS_FLAG,
40
+ QSPI_FLASH_FATFS_MBR = APOTA_QSPI_FLASH_FLAG | APOTA_FATFS_FLAG | APOTA_MBR_FLAG,
41
+ SD_FATFS = APOTA_SDCARD_FLAG | APOTA_FATFS_FLAG,
42
+ SD_FATFS_MBR = APOTA_SDCARD_FLAG | APOTA_FATFS_FLAG | APOTA_MBR_FLAG,
43
+ };
44
+ }
45
+
46
+ template <portenta::StorageType storage=portenta::QSPI_FLASH_FATFS_MBR, uint32_t data_offset=2 >
47
+ class STM32H7OTACloudProcess : public OTADefaultCloudProcessInterface {
6
48
public:
7
- STM32H7OTACloudProcess ();
8
- void update ();
49
+ STM32H7OTACloudProcess (MessageStream *ms, Client* client=nullptr );
50
+ ~STM32H7OTACloudProcess ();
51
+ void update () override ;
9
52
10
- // retrocompatibility functions used in old ota prtotocol based on properties
11
- int otaRequest (char const * ota_url, NetworkAdapter iface);
12
- String getOTAImageSHA256 ();
13
- bool isOTACapable ();
53
+ virtual bool isOtaCapable () override ;
14
54
protected:
15
- // we start the download and decompress process
16
- virtual State fetch (Message* msg=nullptr );
55
+ virtual OTACloudProcessInterface::State resume (Message* msg=nullptr ) override ;
56
+
57
+ // we are overriding the method of startOTA in order to open the destination file for the ota download
58
+ virtual OTACloudProcessInterface::State startOTA () override ;
17
59
18
60
// whene the download is correctly finished we set the mcu to use the newly downloaded binary
19
- virtual State flashOTA (Message* msg= nullptr ) ;
61
+ virtual OTACloudProcessInterface:: State flashOTA () override ;
20
62
21
63
// we reboot the device
22
- virtual State reboot (Message* msg=nullptr );
64
+ virtual OTACloudProcessInterface::State reboot () override ;
65
+
66
+ // write the decompressed char buffer of the incoming ota
67
+ virtual int writeFlash (uint8_t * const buffer, size_t len) override ;
68
+
69
+ virtual void reset () override ;
70
+
71
+ void * appStartAddress ();
72
+ uint32_t appSize ();
73
+ bool appFlashOpen () { return true ; };
74
+ bool appFlashClose () { return true ; };
75
+ private:
76
+ bool caStorageInit ();
77
+ bool caStorageOpen ();
78
+ bool storageInit ();
79
+ bool storageOpen ();
80
+
81
+ void storageClean ();
82
+
83
+ FILE* decompressed;
84
+ // static const char UPDATE_FILE_NAME[];
85
+ mbed::BlockDevice* _bd_raw_qspi;
86
+ uint32_t _program_length;
87
+
88
+ mbed::BlockDevice* _bd;
89
+ #ifdef ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT
90
+ SDMMCBlockDevice* _block_device;
91
+ #endif // ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT
92
+ mbed::FATFileSystem* _fs;
93
+
94
+ mbed::MBRBlockDevice* cert_bd_qspi;
95
+ mbed::FATFileSystem* cert_fs_qspi;
23
96
};
97
+
98
+ #include " OTASTM32H7.ipp"
0 commit comments