Skip to content

Commit dd7f3de

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 dd7f3de

File tree

9 files changed

+1229
-0
lines changed

9 files changed

+1229
-0
lines changed

samples/siwx91x_ota/CMakeLists.txt

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

samples/siwx91x_ota/Kconfig

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

samples/siwx91x_ota/README.rst

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

samples/siwx91x_ota/prj.conf

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

samples/siwx91x_ota/sample.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2025 Silicon Laboratories Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
sample:
5+
name: HTTP/HTTPS OTAF
6+
description: HTTP/HTTPS OTA firmware update application for SiWx917
7+
tests:
8+
sample.net.http_otaf:
9+
harness: net
10+
platform_allow:
11+
- siwx917_rb4338a
12+
tags:
13+
- net
14+
- wifi
15+
- http
16+
- tls
17+
- ota
18+
integration_platforms:
19+
- 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-----
2+
MIIE/zCCA+egAwIBAgIUa5twxvGjlGUZoQhY76eNK3qDwdowDQYJKoZIhvcNAQEL
3+
BQAwgZQxCzAJBgNVBAYTAlVTMRAwDgYDVQQIDAdNb250YW5hMRAwDgYDVQQHDAdC
4+
b3plbWFuMREwDwYDVQQKDAhTYXd0b290aDETMBEGA1UECwwKQ29uc3VsdGluZzEY
5+
MBYGA1UEAwwPd3d3LndvbGZzc2wuY29tMR8wHQYJKoZIhvcNAQkBFhBpbmZvQHdv
6+
bGZzc2wuY29tMB4XDTI0MTIxODIxMjUyOVoXDTI3MDkxNDIxMjUyOVowgZQxCzAJ
7+
BgNVBAYTAlVTMRAwDgYDVQQIDAdNb250YW5hMRAwDgYDVQQHDAdCb3plbWFuMREw
8+
DwYDVQQKDAhTYXd0b290aDETMBEGA1UECwwKQ29uc3VsdGluZzEYMBYGA1UEAwwP
9+
d3d3LndvbGZzc2wuY29tMR8wHQYJKoZIhvcNAQkBFhBpbmZvQHdvbGZzc2wuY29t
10+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvwzKLRSyHoRCW804H0ry
11+
TXUQ8bY1n9/KfQOY06zeA2buKvHYsH1uB1QLEJghTYDLEiDnzE/eRX3Jcncy6sqQ
12+
u2lSEAMvqPOVxfGLYlYb72dvpBBBla0Km+OlwLDScHZQMFuo6AgsfO2nonqNOCkc
13+
rMft8nyVsJWCfUlcOM13Je+9gHVTlDw9ymNbnxW10x0TLxnRPNt2Osy4fcnlwtfa
14+
QG/YIdxzG0ItU5z+Gvx9q3o2P5jehHwFZ85qFDiHqfGMtWjLaH9xICv1oGP1Vi+j
15+
JtK3b7FaF9c4mQj+k1hv/sMTSQgWC6dNZwBSMWcjTpjtUUUduQTZC+zYKLNLve02
16+
eQIDAQABo4IBRTCCAUEwHQYDVR0OBBYEFCeOZxF0wyYdP+0zY7Ok2B0w5ejVMIHU
17+
BgNVHSMEgcwwgcmAFCeOZxF0wyYdP+0zY7Ok2B0w5ejVoYGapIGXMIGUMQswCQYD
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)