Skip to content

Commit fe02f27

Browse files
andreagilardonipennam
authored andcommitted
adjusting OTA.h
1 parent 3602a13 commit fe02f27

File tree

4 files changed

+185
-64
lines changed

4 files changed

+185
-64
lines changed

src/ota/OTA.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
#pragma once
12+
#include "AIoTC_Config.h"
13+
#if OTA_ENABLED
14+
15+
#include "OTAConfig.h"
16+
#ifdef ARDUINO_ARCH_SAMD
17+
18+
#include "implementation/OTASamd.h"
19+
using ArduinoCloudOTA = SAMDOTACloudProcess;
20+
21+
// TODO Check if a macro already exist
22+
// constexpr uint32_t OtaMagicNumber = 0x23418054; // MKR_WIFI_1010
23+
constexpr uint32_t OtaMagicNumber = 0x23418057; // NANO_33_IOT
24+
25+
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
26+
#include "implementation/OTANanoRP2040.h"
27+
using ArduinoCloudOTA = NANO_RP2040OTACloudProcess;
28+
29+
// TODO Check if a macro already exist
30+
constexpr uint32_t OtaMagicNumber = 0x2341005E; // TODO check this value is correct
31+
32+
#elif defined(BOARD_STM32H7)
33+
#include "implementation/OTASTM32H7.h"
34+
using ArduinoCloudOTA = STM32H7OTACloudProcess;
35+
36+
constexpr uint32_t OtaMagicNumber = ARDUINO_PORTENTA_OTA_MAGIC;
37+
38+
#elif defined(ARDUINO_ARCH_ESP32)
39+
#include "implementation/OTAEsp32.h"
40+
using ArduinoCloudOTA = ESP32OTACloudProcess;
41+
42+
#if defined (ARDUINO_NANO_ESP32)
43+
constexpr uint32_t OtaMagicNumber = 0x23410070;
44+
#else
45+
constexpr uint32_t OtaMagicNumber = 0x45535033;
46+
#endif
47+
48+
#elif defined(ARDUINO_UNOR4_WIFI)
49+
50+
#include "implementation/OTAUnoR4.h"
51+
using ArduinoCloudOTA = UNOR4OTACloudProcess;
52+
53+
// TODO Check if a macro already exist
54+
constexpr uint32_t OtaMagicNumber = 0x234110020; // TODO check this value is correct
55+
56+
#else
57+
#error "This Board doesn't support OTA"
58+
#endif
59+
60+
#endif // OTA_ENABLED

src/ota/OTAConfig.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
#pragma once
12+
13+
#ifdef ARDUINO_ARCH_SAMD
14+
#define OFFLOADED_DOWNLOAD
15+
16+
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
17+
18+
#elif defined(BOARD_STM32H7)
19+
20+
#if defined(ARDUINO_PORTENTA_H7_M7)
21+
#define ARDUINO_PORTENTA_OTA_MAGIC 0x2341025b
22+
#define ARDUINO_PORTENTA_OTA_SDMMC_SUPPORT
23+
#define ARDUINO_PORTENTA_OTA_QSPI_SUPPORT
24+
#endif
25+
26+
#if defined(ARDUINO_NICLA_VISION)
27+
#define ARDUINO_PORTENTA_OTA_MAGIC 0x2341025f
28+
#define ARDUINO_PORTENTA_OTA_QSPI_SUPPORT
29+
#endif
30+
31+
#if defined(ARDUINO_OPTA)
32+
#define ARDUINO_PORTENTA_OTA_MAGIC 0x23410064
33+
#define ARDUINO_PORTENTA_OTA_QSPI_SUPPORT
34+
#endif
35+
36+
#if defined(ARDUINO_GIGA)
37+
#define ARDUINO_PORTENTA_OTA_MAGIC 0x23410266
38+
#define ARDUINO_PORTENTA_OTA_QSPI_SUPPORT
39+
#endif
40+
41+
42+
#elif defined(ARDUINO_ARCH_ESP32)
43+
#define OTA_BASIC_AUTH
44+
45+
#elif defined(ARDUINO_UNOR4_WIFI)
46+
#define OFFLOADED_DOWNLOAD
47+
#endif

src/ota/OTATypes.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
#pragma once
12+
13+
#include "AIoTC_Config.h"
14+
15+
#if OTA_ENABLED
16+
#include <stdint.h>
17+
18+
namespace ota {
19+
enum class OTAError : int16_t {
20+
None = 0,
21+
NoCapableBootloader = -1,
22+
NoOtaStorage = -2,
23+
OtaStorageInit = -3,
24+
OtaStorageOpen = -4,
25+
OtaHeaderLength = -5,
26+
OtaHeaderCrc = -6,
27+
OtaHeaterMagicNumber = -7,
28+
ParseHttpHeader = -8,
29+
UrlParseError = -9,
30+
ServerConnectError = -10,
31+
HttpHeaderError = -11,
32+
OtaDownload = -12,
33+
OtaHeaderTimeout = -13,
34+
HttpResponse = -14,
35+
OtaStorageEnd = -15,
36+
StorageConfig = -16,
37+
Library = -17,
38+
Modem = -18,
39+
ErrorOpenUpdateFile = -19,
40+
ErrorWriteUpdateFile = -20,
41+
ErrorReformat = -21,
42+
ErrorUnmount = -22,
43+
ErrorRename = -23,
44+
CaStorageInit = -24,
45+
CaStorageOpen = -25,
46+
};
47+
48+
#ifndef OFFLOADED_DOWNLOAD
49+
union HeaderVersion {
50+
struct __attribute__((packed)) {
51+
uint32_t header_version : 6;
52+
uint32_t compression : 1;
53+
uint32_t signature : 1;
54+
uint32_t spare : 4;
55+
uint32_t payload_target : 4;
56+
uint32_t payload_major : 8;
57+
uint32_t payload_minor : 8;
58+
uint32_t payload_patch : 8;
59+
uint32_t payload_build_num : 24;
60+
} field;
61+
uint8_t buf[sizeof(field)];
62+
static_assert(sizeof(buf) == 8, "Error: sizeof(HEADER.VERSION) != 8");
63+
};
64+
65+
union OTAHeader {
66+
struct __attribute__((packed)) {
67+
uint32_t len;
68+
uint32_t crc32;
69+
uint32_t magic_number;
70+
HeaderVersion hdr_version;
71+
} header;
72+
uint8_t buf[sizeof(header)];
73+
static_assert(sizeof(buf) == 20, "Error: sizeof(HEADER) != 20");
74+
};
75+
#endif // OFFLOADED_DOWNLOAD
76+
}
77+
78+
#endif // OTA_ENABLED

src/utility/ota/OTA.h

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)