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
+
11
+ #include < AIoTC_Config.h>
12
+
1
13
#if defined(ARDUINO_ARCH_SAMD) && OTA_ENABLED
2
14
#include " OTASamd.h"
3
15
16
+ #include < Arduino_DebugUtils.h>
17
+ #if OTA_STORAGE_SNU
18
+ # include < SNU.h>
19
+ # include < WiFiNINA.h> /* WiFiStorage */
20
+ #endif
21
+
22
+ SAMDOTACloudProcess::SAMDOTACloudProcess (MessageStream *ms)
23
+ : OTACloudProcessInterface(ms){
24
+
25
+ }
26
+
27
+ OTACloudProcessInterface::State SAMDOTACloudProcess::resume (Message* msg) {
28
+ return OtaBegin;
29
+ }
30
+
31
+ OTACloudProcessInterface::State SAMDOTACloudProcess::startOTA () {
32
+ reset ();
33
+ return Fetch;
34
+ }
35
+
36
+ OTACloudProcessInterface::State SAMDOTACloudProcess::fetch () {
37
+ #if OTA_STORAGE_SNU
38
+ uint8_t nina_ota_err_code = 0 ;
39
+ if (!WiFiStorage.downloadOTA (this ->context ->url , &nina_ota_err_code)) {
40
+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s error download to nina: %d" , __FUNCTION__, nina_ota_err_code);
41
+ switch (static_cast <ninaOTAError>(nina_ota_err_code)) {
42
+ case ninaOTAError::Open:
43
+ return ErrorOpenUpdateFileFail;
44
+ case ninaOTAError::Length:
45
+ return OtaDownloadFail;
46
+ case ninaOTAError::CRC:
47
+ return OtaHeaderCrcFail;
48
+ case ninaOTAError::Rename:
49
+ return ErrorRenameFail;
50
+ default :
51
+ return OtaDownloadFail;
52
+ }
53
+ }
54
+ #endif // OTA_STORAGE_SNU
55
+
56
+ return FlashOTA;
57
+ }
58
+
59
+ OTACloudProcessInterface::State SAMDOTACloudProcess::flashOTA () {
60
+ return Reboot;
61
+ }
62
+
63
+ OTACloudProcessInterface::State SAMDOTACloudProcess::reboot () {
64
+ NVIC_SystemReset ();
65
+ }
66
+
67
+ void SAMDOTACloudProcess::reset () {
68
+ #if OTA_STORAGE_SNU
69
+ WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS" );
70
+ WiFiStorage.remove (" /fs/UPDATE.BIN.LZSS.TMP" );
71
+ #endif // OTA_STORAGE_SNU
72
+ }
73
+
74
+ bool SAMDOTACloudProcess::isOtaCapable () {
75
+ #if OTA_STORAGE_SNU
76
+ if (strcmp (WiFi.firmwareVersion (), " 1.4.1" ) < 0 ) {
77
+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, NINA firmware needs to be >= 1.4.1, current %s" , __FUNCTION__, WiFi.firmwareVersion ());
78
+ return false ;
79
+ } else {
80
+ return true ;
81
+ }
82
+ #endif
83
+ return false ;
84
+ }
85
+
86
+ extern void * __text_start__;
87
+ extern void * __etext;
88
+ extern void * __data_end__;
89
+ extern void * __data_start__;
90
+
91
+ void * SAMDOTACloudProcess::appStartAddress () { return &__text_start__; }
92
+
93
+ uint32_t SAMDOTACloudProcess::appSize () {
94
+ return ((&__etext - &__text_start__) + (&__data_end__ - &__data_start__))*sizeof (void *);
95
+ }
96
+
4
97
#endif // defined(ARDUINO_ARCH_SAMD) && OTA_ENABLED
0 commit comments