Skip to content

Commit 569c7b4

Browse files
committed
samples: siwx917_ota: http/s OTAF application
This application demonstrates the support for OTA firmware upgrade. Signed-off-by: Devika Raju <[email protected]>
1 parent 8f7a3f7 commit 569c7b4

File tree

9 files changed

+1217
-0
lines changed

9 files changed

+1217
-0
lines changed

samples/siwx91x_ota/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(siwx91x_ota)
7+
8+
target_sources(app PRIVATE src/main.c)
9+
10+
# Ensure the directory for the generated file exists
11+
set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/)
12+
file(MAKE_DIRECTORY ${gen_dir})
13+
14+
# Generate the include file for the certificate
15+
generate_inc_file_for_target(
16+
app
17+
src/ca-cert.pem
18+
${gen_dir}/ca-cert.pem.inc
19+
)

samples/siwx91x_ota/Kconfig

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Config options for OTA application
2+
#
3+
# Copyright (c) 2025 Silicon Laboratories Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
menu "SiWx91x OTA application options"
7+
8+
config OTA_WIFI_SSID
9+
string "WiFi SSID"
10+
default "your_ssid"
11+
help
12+
WiFi SSID for the network to connect to.
13+
14+
config OTA_WIFI_PSK
15+
string "WiFi PSK"
16+
default "your_psk"
17+
help
18+
WiFi PSK (password) for the network to connect to.
19+
20+
config OTA_RPS_FILE
21+
string "OTA RPS file name"
22+
default "firmware.rps"
23+
help
24+
Name of the RPS file to be used for OTA.
25+
26+
config OTA_USE_DNS_RESOLVER
27+
bool "Enable DNS resolver"
28+
default n
29+
help
30+
Enable DNS resolution for hostnames.
31+
If enabled, the application will resolve hostnames to IP addresses.
32+
If disabled, direct IP address must be provided.
33+
34+
config OTA_SERVER_HOSTNAME
35+
string "OTA server hostname"
36+
default "OTA server hostname"
37+
help
38+
Hostname of the OTA server to connect to for firmware downloads.
39+
Only used when DNS resolver is enabled.
40+
41+
config OTA_HTTPS_SUPPORT
42+
bool "Enable HTTPS support"
43+
default n
44+
help
45+
Enable secure HTTPS connections for OTA updates.
46+
If disabled, HTTP will be used instead.
47+
48+
config OTA_SERVER_IP
49+
string "OTA server IP address"
50+
default "OTA server IP"
51+
depends on !OTA_USE_DNS_RESOLVER
52+
help
53+
IP address of the OTA server to connect to for firmware downloads.
54+
Only used when DNS resolver is disabled.
55+
56+
config OTA_SERVER_PORT
57+
int "OTA server port"
58+
default 8080
59+
range 1 65535
60+
help
61+
TCP port number of the OTA server.
62+
Default is 8080 for HTTP.
63+
64+
config OTA_IP_PROTOCOL_SELECTION
65+
int "IP protocol selection"
66+
default 0
67+
range 0 1
68+
help
69+
Select IP protocol for OTA connection.
70+
0: IPv4 (default)
71+
1: IPv6
72+
73+
config OTA_WIFI_SECURITY_TYPE
74+
int "WiFi security type"
75+
default 0
76+
range 0 1
77+
help
78+
WiFi security type for the network connection.
79+
0: Open (default)
80+
1: WPA2-PSK
81+
82+
endmenu
83+
84+
source "Kconfig.zephyr"

samples/siwx91x_ota/README.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
.. zephyr:code-sample:: siwx91x_ota
2+
:name: HTTP OTA Firmware Update on SiWx917
3+
:relevant-api: wifi
4+
5+
Demonstrates HTTP/HTTPS OTA firmware update using SiWx917 on Zephyr.
6+
7+
Overview
8+
********
9+
10+
Application demonstrates how to perform HTTP/HTTPS OTA firmware updates on the
11+
SiWx917 platform using Zephyr RTOS. It connects to a Wi-Fi network, establishes
12+
a secure HTTPS connection using a CA certificate, and downloads firmware
13+
updates from a remote server. The application showcases secure connectivity and
14+
OTA update mechanisms for IoT devices.
15+
16+
Requirements
17+
************
18+
19+
* SiWx917 development board with Wi-Fi support
20+
* HTTP server
21+
22+
Configurations
23+
**************
24+
25+
The following configurations can be modified in ``prj.conf``:
26+
27+
* Wi-Fi Settings
28+
* ``CONFIG_OTA_WIFI_SSID`` - Network name
29+
* ``CONFIG_OTA_WIFI_PSK`` - Network password
30+
* ``CONFIG_OTA_WIFI_SECURITY_TYPE`` - wifi security type (0 - no security, 1 - WPA2-PSK security)
31+
* ``CONFIG_OTA_IP_PROTOCOL_SELECTION`` - Select IPv4 or IPv6
32+
33+
* OTA Server Settings
34+
* ``CONFIG_OTA_SERVER_IP`` or ``CONFIG_OTA_SERVER_HOSTNAME`` - Server address
35+
* ``CONFIG_OTA_SERVER_PORT`` - Server port
36+
* ``CONFIG_OTA_RPS_FILE`` - Firmware file on server
37+
* ``CONFIG_OTA_HTTPS_SUPPORT`` - Enable HTTPS (default: disabled)
38+
* ``CONFIG_OTA_USE_DNS_RESOLVER`` - Enable DNS resolution (set to 1 to use
39+
``CONFIG_OTA_SERVER_HOSTNAME``)
40+
41+
.. _signed image generation:
42+
https://docs.zephyrproject.org/latest/kconfig.html#CONFIG_SIWX91X_SIGN_KEY
43+
44+
Building and Running
45+
********************
46+
47+
1. Configure required settings
48+
2. Build and Flash
49+
50+
.. code-block:: console
51+
52+
west build -b siwx917_rb4338a siwx917_ota -p
53+
west flash
54+
55+
3. Run HTTP/HTTPS server
56+
57+
Host Server Setup
58+
*****************
59+
60+
1. Python HTTPS Server
61+
62+
.. code-block:: console
63+
64+
cd <server_directory>
65+
python <http/https server script>
66+
67+
2. Server Requirements
68+
69+
* Python 3.13
70+
* server-cert.pem and server-key in server directory
71+
* Firmware files (.rps) in server directory
72+
73+
Test the Application
74+
********************
75+
76+
1. After flashing the SiWx91x, the device will scan for the specified AP and
77+
attempt to connect if found.
78+
2. Once connected, the SiWx91x will initiate an HTTP/S connection to the specified
79+
server and download the firmware binary.
80+
3. The OTA update process will be logged to the serial console.
81+
82+
Note
83+
****
84+
85+
This application is not for production.

samples/siwx91x_ota/prj.conf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Network Stack Configuration
2+
CONFIG_NETWORKING=y
3+
CONFIG_NET_MGMT=y
4+
CONFIG_NET_TCP=y
5+
CONFIG_NET_CONNECTION_MANAGER=y
6+
7+
# IPv4/IPv6 Support
8+
CONFIG_NET_IPV4=y
9+
CONFIG_NET_IPV6=y
10+
CONFIG_NET_ARP=y
11+
CONFIG_NET_DHCPV4=y
12+
CONFIG_NET_DHCPV6=n
13+
14+
# WiFi Configuration
15+
CONFIG_WIFI=y
16+
17+
# Memory and Threading
18+
CONFIG_MAIN_STACK_SIZE=2048
19+
CONFIG_INIT_STACKS=y
20+
CONFIG_HEAP_MEM_POOL_SIZE=8192
21+
22+
# CMSIS Configuration
23+
CONFIG_CMSIS_V2_MUTEX_MAX_COUNT=10
24+
CONFIG_CMSIS_V2_EVT_FLAGS_MAX_COUNT=10
25+
26+
# Network Parameters
27+
CONFIG_NET_TCP_MAX_RECV_WINDOW_SIZE=10240
28+
29+
# Socket Support
30+
CONFIG_REQUIRES_FULL_LIBC=y
31+
CONFIG_NET_SOCKETS=y
32+
33+
# HTTP Client Configuration
34+
CONFIG_HTTP_CLIENT=y
35+
CONFIG_NET_MGMT_EVENT=y
36+
37+
# TLS Security Configuration
38+
CONFIG_MBEDTLS=y
39+
CONFIG_MBEDTLS_BUILTIN=y
40+
CONFIG_MBEDTLS_ENABLE_HEAP=y
41+
CONFIG_MBEDTLS_HEAP_SIZE=60000
42+
CONFIG_TLS_CREDENTIALS=y
43+
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
44+
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=8000
45+
46+
# TLS Protocol and Cipher Configuration
47+
CONFIG_MBEDTLS_TLS_VERSION_1_2=y
48+
CONFIG_MBEDTLS_SHA256=y
49+
CONFIG_MBEDTLS_CIPHER_AES_ENABLED=y
50+
CONFIG_MBEDTLS_CIPHER_ALL_ENABLED=y
51+
CONFIG_MBEDTLS_CIPHER_CHACHA20_ENABLED=y
52+
CONFIG_MBEDTLS_POLY1305=y
53+
54+
# DNS configuration
55+
CONFIG_DNS_RESOLVER=y
56+
57+
# for SLAAC configuration
58+
CONFIG_NET_IPV6_ND=y
59+
CONFIG_NET_IPV6_RA_RDNSS=y
60+
CONFIG_NET_IPV6_NBR_CACHE=y
61+
CONFIG_NET_IPV6_MLD=y
62+
CONFIG_NET_IPV6_DAD=y
63+
64+
# OTA Configuration

samples/siwx91x_ota/sample.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sample:
2+
name: HTTP/HTTPS OTAF
3+
description: HTTP/HTTPS OTA firmware update application for SiWx917
4+
tests:
5+
sample.net.http_otaf:
6+
harness: net
7+
platform_allow:
8+
- siwx917_rb4338a
9+
tags:
10+
- net
11+
- wifi
12+
- http
13+
- tls
14+
- ota
15+
integration_platforms:
16+
- siwx917_rb4338a
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2025 Silicon Laboratories Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef APP_CONFIG_H
8+
#define APP_CONFIG_H
9+
10+
/**
11+
* @brief OTA update state machine states
12+
*/
13+
enum ota_state {
14+
OTA_STATE_INIT, /**< Initial state */
15+
OTA_STATE_SCAN, /**< Wi-Fi scanning */
16+
OTA_STATE_CONNECT, /**< Connect to Wi-Fi network */
17+
OTA_STATE_IP_CONFIG, /**< Get IP configuration */
18+
OTA_STATE_SERVER_CONNECT, /**< Connect to OTA server */
19+
OTA_STATE_DOWNLOAD, /**< Download firmware image */
20+
OTA_STATE_PROCESS, /**< Process downloaded firmware */
21+
};
22+
23+
#endif /* APP_CONFIG_H */
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-----BEGIN CERTIFICATE-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5ejVoYGapIGXMIGUMQswCQYD
18+
VQQGEwJVUzEQMA4GA1UECAwHTW9udGFuYTEQMA4GA1UEBwwHQm96ZW1hbjERMA8G
19+
A1UECgwIU2F3dG9vdGgxEzARBgNVBAsMCkNvbnN1bHRpbmcxGDAWBgNVBAMMD3d3
20+
dy53b2xmc3NsLmNvbTEfMB0GCSqGSIb3DQEJARYQaW5mb0B3b2xmc3NsLmNvbYIU
21+
a5twxvGjlGUZoQhY76eNK3qDwdowDAYDVR0TBAUwAwEB/zAcBgNVHREEFTATggtl
22+
eGFtcGxlLmNvbYcEfwAAATAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIw
23+
DQYJKoZIhvcNAQELBQADggEBAHc7PWZ0vJf+QBbmuqXV0YQIiWlPiA1Xqe+Mw5dS
24+
yL2Lokk7t/ddHtYUf7KAM9qgitPhL9W8M5/qWnIk5fi4S7PfYpA7qCHvJ0J1vGAC
25+
jjc1meujKPJlTP96+I7MI23lav4iWtmyT0fH4K6Y75Sstk9hgSmO4XksRvzpGsOW
26+
HxmTZC6fN3LF5JNOYV84jq7oORnml6iR1CN+HtLQU+zMrKAd0LfdsbcBLpbNhSfg
27+
50fiwcEA9pTfd+f6xu+KwHxnvP+gfJQ7fYZCrz2DMe4qO3vwLJ5v6cQHgSTaBXBN
28+
3QmunnK4IQ6MsquqTEkQ93b5tQ1sINPfegYyjSkfKB2NJjM=
29+
-----END CERTIFICATE-----
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025 Silicon Laboratories Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef __CA_CERTIFICATE_H__
8+
#define __CA_CERTIFICATE_H__
9+
10+
/* Certificate tags */
11+
#define CA_CERTIFICATE_TAG 1
12+
13+
/* CA Certificate data */
14+
static const unsigned char ca_certificate[] = {
15+
#include "ca-cert.pem.inc"
16+
};
17+
18+
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
19+
#include CONFIG_NET_SAMPLE_PSK_HEADER_FILE
20+
#endif
21+
22+
#endif /* __CA_CERTIFICATE_H__ */

0 commit comments

Comments
 (0)