-
Notifications
You must be signed in to change notification settings - Fork 23
samples: siwx917_ota: http/s OTAF application #111
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
base: main
Are you sure you want to change the base?
Conversation
466273e to
6a581ad
Compare
569c7b4 to
dd7f3de
Compare
|
Please rebase this on the latest |
6025ad2 to
8cc35e9
Compare
samples/siwx91x_ota/src/main.c
Outdated
| /* Message for HTTP data */ | ||
| typedef struct { | ||
| uint32_t length; | ||
| uint8_t buffer[RECV_BUFFER_SIZE]; |
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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.
8cc35e9 to
00eb379
Compare
9c620ad to
7fe97ff
Compare
c3b2473 to
4bf41dc
Compare
There was a problem hiding this 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.
samples/siwx91x_ota/Kconfig
Outdated
|
|
||
| config OTA_UPDATE_URL | ||
| string "OTA update URL" | ||
| default "http://example.com:8080/firmware.rps" |
There was a problem hiding this comment.
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.
samples/siwx91x_ota/README.rst
Outdated
|
|
||
| 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 |
There was a problem hiding this comment.
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.
1b8ada9 to
a13421c
Compare
|
|
||
| error: | ||
| if (ctx->sock < 0) { | ||
| zsock_close(ctx->sock); |
There was a problem hiding this comment.
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.
samples/siwx91x_ota/src/main.c
Outdated
| 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; |
There was a problem hiding this comment.
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.
samples/siwx91x_ota/src/main.c
Outdated
|
|
||
| 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)); |
There was a problem hiding this comment.
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));
samples/siwx91x_ota/src/main.c
Outdated
| */ | ||
| static int ota_connect_to_server(struct app_ctx *ctx) | ||
| { | ||
| struct http_parse_data http_parse_data_info = ctx->http_parse_data_info; |
There was a problem hiding this comment.
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;
a13421c to
b2555db
Compare
This application demonstrates the support for OTA firmware upgrade. Signed-off-by: Devika Raju <[email protected]>
b2555db to
4ad0105
Compare
| CONFIG_NET_TCP_MAX_RECV_WINDOW_SIZE=10240 | ||
|
|
||
| # Socket Support | ||
| CONFIG_REQUIRES_FULL_LIBC=y |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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.
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.