Skip to content

Conversation

@Devika-Raju-Z
Copy link

Updating the SiWx917 device's firmware including NWP, M4, and the combined M4 + TA images using an HTTP or HTTPS server. It supports both secure and non-secure firmware updates for all three types: NWP, M4, and the combined image.

@Devika-Raju-Z Devika-Raju-Z force-pushed the https_otaf branch 24 times, most recently from 569c7b4 to dd7f3de Compare September 25, 2025 17:03
@jhedberg jhedberg changed the title http/s otaf application samples: siwx917_ota: http/s OTAF application Sep 26, 2025
@jhedberg
Copy link
Contributor

Please rebase this on the latest main branch to see if the Compliance failure gets resolved

@Devika-Raju-Z Devika-Raju-Z force-pushed the https_otaf branch 7 times, most recently from 6025ad2 to 8cc35e9 Compare October 1, 2025 09:07
/* Message for HTTP data */
typedef struct {
uint32_t length;
uint8_t buffer[RECV_BUFFER_SIZE];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RECV_BUFFER_SIZE is an arbitrary value and used only once. Drop the symbols and replace it the value.

if (app_ctx_st->http_response_error) {
printf("Error occurred during HTTP download, skipping processing\n");
return -EPROTO;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably handled by the caller.

@Devika-Raju-Z Devika-Raju-Z requested a review from a team as a code owner October 8, 2025 04:59
@Devika-Raju-Z Devika-Raju-Z force-pushed the https_otaf branch 6 times, most recently from 9c620ad to 7fe97ff Compare October 14, 2025 09:48
@Devika-Raju-Z Devika-Raju-Z force-pushed the https_otaf branch 5 times, most recently from c3b2473 to 4bf41dc Compare October 21, 2025 09:50
Copy link
Contributor

@jerome-pouiller jerome-pouiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stop here for today.


config OTA_UPDATE_URL
string "OTA update URL"
default "http://example.com:8080/firmware.rps"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation talks about HTTPS, but the default value doesn't use it.


Application demonstrates how to perform HTTP/HTTPS OTA firmware updates on the
SiWx917 platform using Zephyr RTOS. It connects to a Wi-Fi network, establishes
a secure HTTPS connection using a CA certificate, and downloads firmware
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a secure HTTPS connection using a CA certificate

In simple words: an HTTPS connection.

@Devika-Raju-Z Devika-Raju-Z force-pushed the https_otaf branch 2 times, most recently from 1b8ada9 to a13421c Compare October 29, 2025 11:54

error:
if (ctx->sock < 0) {
zsock_close(ctx->sock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hu? probably you mean if (ctx->sock >= 0)?

In fact, even this test is useless since zsock_close() on negative value will properly catch the error.

ret = zsock_connect(ctx->sock, res->ai_addr, res->ai_addrlen);
if (ret < 0) {
printf("Connection failed (%d): %s\n", -errno, strerror(errno));
ctx->sock = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hu? you leak the socket ressource.


ret = zsock_getaddrinfo(http_parse_data_info.host, http_parse_data_info.port, NULL, &res);
if (ret != 0) {
printf("Address resolution failed: %s\n", zsock_gai_strerror(ret));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the host and the port are easily reachable and provide a useful information, you can provide them:

	printf("Cannot resolve %s:%s: %s\n",
               http_parse_data_info.host, http_parse_data_info.port,
               zsock_gai_strerror(ret));

*/
static int ota_connect_to_server(struct app_ctx *ctx)
{
struct http_parse_data http_parse_data_info = ctx->http_parse_data_info;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data and info are redundant. BTW, why don't you get a pointer rather than duplicating this structure?

 struct url_data *url_data = &ctx->url_data;

This application demonstrates the support for OTA
firmware upgrade.

Signed-off-by: Devika Raju <[email protected]>
CONFIG_NET_TCP_MAX_RECV_WINDOW_SIZE=10240

# Socket Support
CONFIG_REQUIRES_FULL_LIBC=y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you required this parameter?

# TLS Security Configuration
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_HEAP_SIZE=60000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required?

CONFIG_REBOOT=y

CONFIG_OTA_WIFI_SSID="<AP-SSID>"
CONFIG_OTA_WIFI_PSK="<AP-PASSWORD>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You provide samples values in Kconfig and sample values in prj.conf. We probably want to keep them in only one place. I suggest to remove default attribute in Kconfig and add a default value for OTA_UPDATE_URL in prj.conf

sample.net.http_otaf:
harness: net
platform_allow:
- siwx917_rb4338a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test also work with siwx917_rb4342a and dh2605a.
Maybe:

filter: CONFIG_SOC_FAMILY_SILABS_SIWX91X

};

struct http_parse_data {
char *schema;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have keep is_tls_enabled and removed schema. But it's not a big deal.

}
if (ctx->http_status_code == 301) {
ret = -EPROTO;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it useful to return a different errno? the caller does make the difference anyway.

ctx->ota_range_start_byte, ctx->ota_range_end_byte);

/* Send request */
ret = http_client_req(ctx->sock, &req, 30000, ctx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30 seconds is huge. Does it make sense to not return an error earlier?

return ret;
}

static bool ota_update_http_range_header(struct app_ctx *ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be uniform, return an errno.


static bool ota_update_http_range_header(struct app_ctx *ctx)
{
ctx->ota_range_start_byte = ctx->ota_range_end_byte + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably unnecessary twisted. ctx->ota_range_start_byte += sizeof(ctx->flash_buffer); is easier to understand (sizeof(...) is a constant data while ctx->ota_range_end_byte may have been updated somewhere in the algorithm)

if (!ota_handle_retry(ctx, operation, true)) {
ctx->retry_count++;
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this is not correct. If sl_si91x_fwup_load() return an error, you have to properly restart the download from the beginning (because we wrote corrupted data). Currently, it will never recover the error.

Globally, the error management is difficult to review. I suggest to clean it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants