Skip to content

Commit 8060a4f

Browse files
andreagilardonipennam
authored andcommitted
adjusting OTA.h
1 parent e616374 commit 8060a4f

File tree

3 files changed

+135
-24
lines changed

3 files changed

+135
-24
lines changed

src/utility/ota/OTA.h renamed to src/ota/OTA.h

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,49 @@
1212
#include "AIoTC_Config.h"
1313
#if OTA_ENABLED
1414

15+
#include "OTAConfig.h"
1516
#ifdef ARDUINO_ARCH_SAMD
16-
#include "OTASamd.h"
17+
18+
#include "implementation/OTASamd.h"
1719
using OTACloudProcess = SAMDOTACloudProcess;
1820

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+
1925
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
20-
#include "OTANanoRP2040.h"
26+
#include "implementation/OTANanoRP2040.h"
2127
using OTACloudProcess = NANO_RP2040OTACloudProcess;
2228

29+
// TODO Check if a macro already exist
30+
constexpr uint32_t OtaMagicNumber = 0x2341005E; // TODO check this value is correct
31+
2332
#elif defined(BOARD_STM32H7)
24-
#include "OTAPortentaH7.h"
33+
#include "implementation/OTASTM32H7.h"
2534
using OTACloudProcess = STM32H7OTACloudProcess;
2635

36+
constexpr uint32_t OtaMagicNumber = ARDUINO_PORTENTA_OTA_MAGIC;
37+
2738
#elif defined(ARDUINO_ARCH_ESP32)
28-
#include "OTAEsp32.h"
39+
#include "implementation/OTAEsp32.h"
2940
using OTACloudProcess = ESP32OTACloudProcess;
3041

31-
3242
#if defined (ARDUINO_NANO_ESP32)
3343
constexpr uint32_t OtaMagicNumber = 0x23410070;
3444
#else
3545
constexpr uint32_t OtaMagicNumber = 0x45535033;
3646
#endif
3747

3848
#elif defined(ARDUINO_UNOR4_WIFI)
39-
#include "OTAUnoR4.h"
49+
50+
#include "implementation/OTAUnoR4.h"
4051
using OTACloudProcess = UNOR4OTACloudProcess;
4152

53+
// TODO Check if a macro already exist
54+
constexpr uint32_t OtaMagicNumber = 0x234110020; // TODO check this value is correct
55+
4256
#else
4357
#error "This Board doesn't support OTA"
4458
#endif
4559

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

0 commit comments

Comments
 (0)