22
22
#include < SPIFFS.h>
23
23
#include < Arduino_ESP32_OTA.h>
24
24
#include " OTA.h"
25
+ #include " BossaUnoR4WiFi.h"
26
+
27
+ #include " FS.h"
28
+ #include " SPIFFS.h"
29
+ #include " at_handler.h"
25
30
26
31
/* *****************************************************************************
27
32
PUBLIC MEMBER FUNCTIONS
28
33
******************************************************************************/
29
34
30
- Arduino_ESP32_OTA::Error Arduino_UNOWIFIR4_OTA::begin (const char * file_path, uint32_t magic)
31
- {
32
- /* initialize private variables */
33
- otaInit ();
35
+ Arduino_UNOWIFIR4_OTA::Arduino_UNOWIFIR4_OTA ()
36
+ : _updating_renesas(true ) {
34
37
35
- /* ... initialize CRC ... */
36
- crc32Init ();
38
+ }
37
39
40
+ Arduino_UNOWIFIR4_OTA::~Arduino_UNOWIFIR4_OTA () {
41
+ closeStorage ();
42
+ }
43
+
44
+ Arduino_ESP32_OTA::Error Arduino_UNOWIFIR4_OTA::begin (const char * file_path, uint32_t magic)
45
+ {
38
46
/* ... configure board Magic number */
39
47
setMagic (magic);
40
48
@@ -47,23 +55,22 @@ Arduino_ESP32_OTA::Error Arduino_UNOWIFIR4_OTA::begin(const char* file_path, uin
47
55
SPIFFS.remove (file_path);
48
56
}
49
57
50
- _spiffs = true ;
58
+ _updating_renesas = true ;
51
59
52
60
SPIFFS.end ();
53
61
return Error::None;
54
62
}
55
63
56
64
void Arduino_UNOWIFIR4_OTA::write_byte_to_flash (uint8_t data)
57
65
{
58
- if (_spiffs ) {
66
+ if (_updating_renesas ) {
59
67
int ret = fwrite (&data, sizeof (data), 1 , _file);
60
68
} else {
61
69
Arduino_ESP32_OTA::write_byte_to_flash (data);
62
70
}
63
71
}
64
72
65
- int Arduino_UNOWIFIR4_OTA::download (const char * ota_url, const char * file_path)
66
- {
73
+ int Arduino_UNOWIFIR4_OTA::initStorage (const char * file_path) {
67
74
if (!SPIFFS.begin ()) {
68
75
DEBUG_ERROR (" %s: failed to initialize SPIFFS" , __FUNCTION__);
69
76
return static_cast <int >(Error::OtaStorageInit);
@@ -76,33 +83,66 @@ int Arduino_UNOWIFIR4_OTA::download(const char * ota_url, const char* file_path)
76
83
DEBUG_ERROR (" %s: failed to write SPIFFS" , __FUNCTION__);
77
84
return static_cast <int >(Error::OtaStorageInit);
78
85
}
86
+ return static_cast <int >(Error::None);
87
+ }
79
88
80
- /* Download and decode OTA file */
81
- size_t size = download (ota_url);
89
+ int Arduino_UNOWIFIR4_OTA::closeStorage () {
90
+ int res = 0 ;
91
+ if (_file != nullptr ) {
92
+ res = fclose (_file);
93
+ _file = nullptr ;
94
+ }
82
95
83
- fclose (_file);
84
- _file = nullptr ;
85
96
SPIFFS.end ();
86
- return size ;
97
+ return res ;
87
98
}
88
99
89
- Arduino_ESP32_OTA::Error Arduino_UNOWIFIR4_OTA::verify ( )
100
+ int Arduino_UNOWIFIR4_OTA::download ( const char * ota_url, const char * file_path )
90
101
{
91
- /* ... then finalize ... */
92
- crc32Finalize ();
102
+ int res = initStorage (file_path);
93
103
94
- if (!crc32Verify ()) {
95
- DEBUG_ERROR (" %s: CRC32 mismatch" , __FUNCTION__);
96
- return Error::OtaHeaderCrc;
104
+ if (res < 0 ) {
105
+ return res;
97
106
}
98
- return Error::None;
107
+
108
+ /* Download and decode OTA file */
109
+ res = download (ota_url);
110
+
111
+ closeStorage ();
112
+
113
+ return res;
99
114
}
100
115
101
- Arduino_ESP32_OTA::Error Arduino_UNOWIFIR4_OTA::update ( )
116
+ int Arduino_UNOWIFIR4_OTA::startDownload ( const char * ota_url, const char * file_path )
102
117
{
103
- if (!Update.end (true )) {
104
- DEBUG_ERROR (" %s: Failure to apply OTA update. Error: %s" , __FUNCTION__, Update.errorString ());
105
- return Error::OtaStorageEnd;
118
+ int res = initStorage (file_path);
119
+
120
+ if (res < 0 ) {
121
+ return res;
106
122
}
107
- return Error::None;
123
+
124
+ /* Download and decode OTA file */
125
+ res = startDownload (ota_url);
126
+
127
+ if (res < 0 ) {
128
+ closeStorage ();
129
+ }
130
+
131
+ return res;
132
+ }
133
+
134
+ int Arduino_UNOWIFIR4_OTA::downloadPoll ()
135
+ {
136
+ auto res = Arduino_ESP32_OTA::downloadPoll ();
137
+
138
+ if (_updating_renesas && res != 0 ) {
139
+ closeStorage ();
140
+ }
141
+
142
+ return res;
143
+ }
144
+
145
+ int Arduino_UNOWIFIR4_OTA::update (const char * file_path)
146
+ {
147
+ return BOSSA.program (file_path, Serial, GPIO_BOOT, GPIO_RST);
108
148
}
0 commit comments