Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder Arduino Nano RP2040 OTA error codes #390

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions src/utility/ota/OTA-nano-rp2040.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,48 @@
a commercial license, send an email to license@arduino.cc.
*/

#if defined(ARDUINO_NANO_RP2040_CONNECT)
#ifdef ARDUINO_NANO_RP2040_CONNECT

/******************************************************************************
* INCLUDE
******************************************************************************/

#include "OTA.h"

#include "../watchdog/Watchdog.h"

#include <Arduino_DebugUtils.h>

#include <SFU.h>

#include "mbed.h"
#include "FATFileSystem.h"
#include "FlashIAPBlockDevice.h"
#include "utility/ota/FlashSHA256.h"

#include "../watchdog/Watchdog.h"

#include <Arduino_DebugUtils.h>

/******************************************************************************
* DEFINES
******************************************************************************/

#define RP2040_OTA_ERROR_BASE (-100)

/******************************************************************************
* TYPEDEF
******************************************************************************/

enum class rp2040OTAError : int
{
None = 0,
OtaStorageInit = RP2040_OTA_ERROR_BASE - 3,
ParseHttpHeader = RP2040_OTA_ERROR_BASE - 8,
UrlParse = RP2040_OTA_ERROR_BASE - 9,
ServerConnect = RP2040_OTA_ERROR_BASE - 10,
HttpHeader = RP2040_OTA_ERROR_BASE - 11,
HttpData = RP2040_OTA_ERROR_BASE - 12,
OpenUpdateFile = RP2040_OTA_ERROR_BASE - 19,
WriteUpdateFile = RP2040_OTA_ERROR_BASE - 20,
Reformat = RP2040_OTA_ERROR_BASE - 21,
Unmount = RP2040_OTA_ERROR_BASE - 22,
};

/******************************************************************************
* FUNCTION DEFINITION
******************************************************************************/
Expand Down Expand Up @@ -92,7 +115,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
if ((err = flash.init()) < 0)
{
DEBUG_ERROR("%s: flash.init() failed with %d", __FUNCTION__, err);
return static_cast<int>(OTAError::RP2040_ErrorFlashInit);
return static_cast<int>(rp2040OTAError::OtaStorageInit);
}

watchdog_reset();
Expand All @@ -105,7 +128,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
if ((err = fs.reformat(&flash)) != 0)
{
DEBUG_ERROR("%s: fs.reformat() failed with %d", __FUNCTION__, err);
return static_cast<int>(OTAError::RP2040_ErrorReformat);
return static_cast<int>(rp2040OTAError::Reformat);
}

watchdog_reset();
Expand All @@ -115,7 +138,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
{
DEBUG_ERROR("%s: fopen() failed", __FUNCTION__);
fclose(file);
return static_cast<int>(OTAError::RP2040_ErrorOpenUpdateFile);
return static_cast<int>(rp2040OTAError::OpenUpdateFile);
}

watchdog_reset();
Expand All @@ -133,7 +156,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
} else {
DEBUG_ERROR("%s: Failed to parse OTA URL %s", __FUNCTION__, ota_url);
fclose(file);
return static_cast<int>(OTAError::RP2040_UrlParseError);
return static_cast<int>(rp2040OTAError::UrlParse);
}

watchdog_reset();
Expand All @@ -142,7 +165,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
{
DEBUG_ERROR("%s: Connection failure with OTA storage server %s", __FUNCTION__, url.host_.c_str());
fclose(file);
return static_cast<int>(OTAError::RP2040_ServerConnectError);
return static_cast<int>(rp2040OTAError::ServerConnect);
}

watchdog_reset();
Expand Down Expand Up @@ -179,7 +202,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
{
DEBUG_ERROR("%s: Error receiving HTTP header %s", __FUNCTION__, is_http_header_timeout ? "(timeout)":"");
fclose(file);
return static_cast<int>(OTAError::RP2040_HttpHeaderError);
return static_cast<int>(rp2040OTAError::HttpHeader);
}

/* Extract concent length from HTTP header. A typical entry looks like
Expand All @@ -190,7 +213,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
{
DEBUG_ERROR("%s: Failure to extract content length from http header", __FUNCTION__);
fclose(file);
return static_cast<int>(OTAError::RP2040_ErrorParseHttpHeader);
return static_cast<int>(rp2040OTAError::ParseHttpHeader);
}
/* Find start of numerical value. */
char * ptr = const_cast<char *>(content_length_ptr);
Expand Down Expand Up @@ -219,7 +242,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
{
DEBUG_ERROR("%s: Writing of firmware image to flash failed", __FUNCTION__);
fclose(file);
return static_cast<int>(OTAError::RP2040_ErrorWriteUpdateFile);
return static_cast<int>(rp2040OTAError::WriteUpdateFile);
}

bytes_received++;
Expand All @@ -229,7 +252,7 @@ int rp2040_connect_onOTARequest(char const * ota_url)
if (bytes_received != content_length_val) {
DEBUG_ERROR("%s: Error receiving HTTP data %s (%d bytes received, %d expected)", __FUNCTION__, is_http_data_timeout ? "(timeout)":"", bytes_received, content_length_val);
fclose(file);
return static_cast<int>(OTAError::RP2040_HttpDataError);
return static_cast<int>(rp2040OTAError::HttpData);
}

DEBUG_INFO("%s: %d bytes received", __FUNCTION__, ftell(file));
Expand All @@ -239,15 +262,15 @@ int rp2040_connect_onOTARequest(char const * ota_url)
if ((err = fs.unmount()) != 0)
{
DEBUG_ERROR("%s: fs.unmount() failed with %d", __FUNCTION__, err);
return static_cast<int>(OTAError::RP2040_ErrorUnmount);
return static_cast<int>(rp2040OTAError::Unmount);
}

/* Perform the reset to reboot to SFU. */
mbed_watchdog_trigger_reset();
/* If watchdog is enabled we should not reach this point */
NVIC_SystemReset();

return static_cast<int>(OTAError::None);
return static_cast<int>(rp2040OTAError::None);
}

String rp2040_connect_getOTAImageSHA256()
Expand Down
16 changes: 0 additions & 16 deletions src/utility/ota/OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
#include <Arduino.h>
#include <Arduino_ConnectionHandler.h>

/******************************************************************************
* DEFINES
******************************************************************************/

#define RP2040_OTA_ERROR_BASE (-100)

/******************************************************************************
* TYPEDEF
******************************************************************************/
Expand All @@ -42,16 +36,6 @@ enum class OTAError : int
{
None = 0,
DownloadFailed = 1,
RP2040_UrlParseError = RP2040_OTA_ERROR_BASE - 0,
RP2040_ServerConnectError = RP2040_OTA_ERROR_BASE - 1,
RP2040_HttpHeaderError = RP2040_OTA_ERROR_BASE - 2,
RP2040_HttpDataError = RP2040_OTA_ERROR_BASE - 3,
RP2040_ErrorOpenUpdateFile = RP2040_OTA_ERROR_BASE - 4,
RP2040_ErrorWriteUpdateFile = RP2040_OTA_ERROR_BASE - 5,
RP2040_ErrorParseHttpHeader = RP2040_OTA_ERROR_BASE - 6,
RP2040_ErrorFlashInit = RP2040_OTA_ERROR_BASE - 7,
RP2040_ErrorReformat = RP2040_OTA_ERROR_BASE - 8,
RP2040_ErrorUnmount = RP2040_OTA_ERROR_BASE - 9,
};

/******************************************************************************
Expand Down
Loading