Skip to content

Commit 466273e

Browse files
committed
http/s otaf application
1 parent 8f7a3f7 commit 466273e

File tree

8 files changed

+1113
-0
lines changed

8 files changed

+1113
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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(siwx917_tcp_client)
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.der
18+
${gen_dir}/ca-cert.der.inc
19+
)
20+
21+
set(WISECONNECT_DIR ${ZEPHYR_HAL_SILABS_MODULE_DIR}/wiseconnect)
22+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ahb_interface/src/rsi_hal_mcu_m4_ram.c LOCATION RAM)
23+
24+
set(SERVICE_DIR ${ZEPHYR_HAL_SILABS_MODULE_DIR}/simplicity_sdk/platform/service)
25+
26+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ahb_interface/src/sl_si91x_bus.c LOCATION RAM)
27+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/src/sl_si91x_driver.c LOCATION RAM)
28+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ahb_interface/src/rsi_hal_mcu_m4_rom.c LOCATION RAM)
29+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/device/silabs/si91x/mcu/drivers/service/sleeptimer/src/sl_sleeptimer_hal_si91x_sysrtc.c LOCATION RAM)
30+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/device/silabs/si91x/mcu/drivers/peripheral_drivers/src/rsi_sysrtc.c LOCATION RAM)
31+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/src/sl_rsi_utility.c LOCATION RAM)
32+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ahb_interface/inc/sli_siwx917_soc.h LOCATION RAM)
33+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/sli_si91x_wifi_event_handler/src/sli_si91x_wifi_event_handler.c LOCATION RAM)
34+
zephyr_code_relocate(FILES ${WISECONNECT_DIR}/components/sli_wifi_command_engine/src/sli_wifi_command_engine.c LOCATION RAM)
35+
zephyr_code_relocate(FILES ${SERVICE_DIR}/sleeptimer/src/sl_sleeptimer.c LOCATION RAM)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
.. zephyr:code-sample:: siwx917_https_otaf
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 SiWx917 platform using Zephyr RTOS. It connects to a Wi-Fi network, establishes a secure HTTPS connection using a CA certificate, and downloads firmware updates from a remote server. The application showcases secure connectivity and OTA update mechanisms for IoT devices.
11+
12+
Requirements
13+
************
14+
15+
* SiWx917 development board with Wi-Fi support.
16+
* Windows PC to run HTTP server python script.
17+
18+
Configurations
19+
******************
20+
21+
The following configurations can be modified in src/app_config.h:
22+
23+
* Wi-Fi Settings
24+
* SSID - Network name
25+
* PSK - Network password
26+
* SECURITY_TYPE - wifi security type (0 - no security, 1 - WPA2-PSK security)
27+
* IP_CONFIG - Select IPv4 or IPv6
28+
29+
* HTTP/HTTPS Settings
30+
* HTTPS_SUPPORT - Enable/disable HTTPS (default: enabled)
31+
* HTTP_SERVER_ADDR - Server IP address
32+
* HTTP_URL - To select the file to download
33+
34+
* Firmware Update Settings
35+
* FW_UPDATE_TYPE - Select M4_FW_UPDATE (M4), TA_FW_UPDATE (TA) or Combined update (M4 + TA)
36+
* SECURED_IMAGE_UPDATE - Enable/disable secured image update
37+
38+
* Image File Settings
39+
* For secure updates (SECURED_IMAGE_UPDATE=1), the possible values to set HTTP_URL are:
40+
* SECURE_M4_RPS_FILE - M4 secure image file
41+
* SECURE_TA_RPS_FILE - TA secure image file
42+
* SECURE_COMBINED_RPS_FILE - Combined secure image file
43+
* For non-secure updates (SECURED_IMAGE_UPDATE=0), the possible values to set HTTP_URL are:
44+
* M4_RPS_FILE - M4 image file
45+
* TA_RPS_FILE - TA image file
46+
* COMBINED_RPS_FILE - Combined image file
47+
48+
Building and Running
49+
********************
50+
51+
1. Configure Network Settings
52+
* Update SSID, PSK and SECURITY_TYPE in and src/app_config.h
53+
* Configure server address
54+
* Set IP_CONFIG to IPV4 or IPV6 as needed
55+
56+
2. Configure Update Type
57+
* Set FW_UPDATE_TYPE to:
58+
* Enable/disable secured image update
59+
* Set Image file to download
60+
61+
3. Build and Flash
62+
.. code-block:: console
63+
64+
west build -b siwx917_rb4338a siwx917_https_otaf -p
65+
west flash
66+
67+
4. Run HTTP/HTTPS server
68+
69+
Host Server Setup
70+
****************
71+
72+
1. Python HTTPS Server
73+
.. code-block:: console
74+
75+
cd <server_directory>
76+
python <http/https server script>
77+
78+
2. Server Requirements
79+
* Python 3.13
80+
* server-cert.pem and server-key in server directory
81+
* Firmware files (.rps) in server directory
82+
83+
Test the Application
84+
********************
85+
1. After flashing the SiWx91x, the device will scan for the specified AP and attempt to connect if found.
86+
2. Once connected, the SiWx91x will initiate an HTTPS connection to the specified server and download the firmware binary.
87+
3. The OTA update process will be logged to the serial console.
88+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Network Stack Configuration
2+
CONFIG_NETWORKING=y
3+
CONFIG_NET_MGMT=y
4+
CONFIG_NET_TCP=y
5+
CONFIG_NET_BUF_POOL_USAGE=y
6+
CONFIG_NET_CONNECTION_MANAGER=y
7+
8+
# IPv4/IPv6 Support
9+
CONFIG_NET_IPV4=y
10+
CONFIG_NET_IPV6=y
11+
CONFIG_NET_ARP=y
12+
CONFIG_NET_DHCPV4=y
13+
CONFIG_NET_DHCPV6=y
14+
15+
# WiFi Configuration
16+
CONFIG_WIFI=y
17+
CONFIG_WIFI_SILABS_SIWX91X_NET_STACK_NATIVE=y
18+
19+
# Memory and Threading
20+
CONFIG_MAIN_STACK_SIZE=2048
21+
CONFIG_INIT_STACKS=y
22+
CONFIG_HEAP_MEM_POOL_SIZE=16384
23+
CONFIG_THREAD_NAME=y
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=21900
31+
CONFIG_CODE_DATA_RELOCATION_SRAM=y
32+
33+
# Socket and POSIX Support
34+
CONFIG_REQUIRES_FULL_LIBC=y
35+
CONFIG_NET_SOCKETS=y
36+
CONFIG_POSIX_API=y
37+
38+
# HTTP Client Configuration
39+
CONFIG_HTTP_CLIENT=y
40+
CONFIG_NET_MGMT_EVENT=y
41+
42+
# TLS Security Configuration
43+
CONFIG_MBEDTLS=y
44+
CONFIG_MBEDTLS_BUILTIN=y
45+
CONFIG_MBEDTLS_ENABLE_HEAP=y
46+
CONFIG_MBEDTLS_HEAP_SIZE=60000
47+
CONFIG_TLS_CREDENTIALS=y
48+
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
49+
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=8000
50+
51+
# TLS Protocol and Cipher Configuration
52+
CONFIG_MBEDTLS_TLS_VERSION_1_2=y
53+
CONFIG_MBEDTLS_SHA256=y
54+
CONFIG_MBEDTLS_CIPHER_AES_ENABLED=y
55+
CONFIG_MBEDTLS_CIPHER_ALL_ENABLED=y
56+
CONFIG_MBEDTLS_CIPHER_CHACHA20_ENABLED=y
57+
CONFIG_MBEDTLS_POLY1305=y
58+
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: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 Application state machine states
12+
*/
13+
typedef enum wlan_app_state_e {
14+
WLAN_SCAN_STATE = 0, /**< Wi-Fi scanning */
15+
WLAN_NET_UP_STATE, /**< Connect to Wi-Fi network */
16+
WLAN_IP_CONFIG_STATE, /**< Get IP configuration */
17+
HTTP_ADD_CERT_STATE, /**< Add HTTPS certificates */
18+
HTTP_CREATE_SOCKET_STATE, /**< Create socket connection */
19+
HTTP_GET_REQ_STATE, /**< Send HTTP GET requests */
20+
IDLE_STATE /**< Idle/completed state */
21+
} wlan_app_state_t;
22+
23+
/**
24+
* @brief OTA firmware update states
25+
*/
26+
typedef enum {
27+
START_IMAGE = 0, /**< Start firmware update */
28+
DOWNLOAD_IMAGE /**< Download firmware chunks */
29+
} sli_otaf_update_state_t;
30+
31+
/* General configuration */
32+
#define CMD_WAIT_TIME 180000 /**< Command timeout in milliseconds */
33+
#define MAX_RECV_BUF_LEN 1460 /**< Maximum receive buffer length */
34+
#define IPV4 1 /**< IPv4 protocol selector */
35+
#define IPV6 0 /**< IPv6 protocol selector */
36+
#define IP_CONFIG IPV4 /**< Active IP protocol selection */
37+
#define HTTP_MSG_Q_MAX_SIZE 11 /**< HTTP message queue size */
38+
#define RECV_BUFFER_SIZE 1024 /**< Network receive buffer size */
39+
#define CHUNK_SIZE (10*1024) /**< Download chunk size */
40+
#define FW_CHUNK_SIZE 1024 /**< Firmware write chunk size */
41+
42+
/* Wi-Fi and server configuration */
43+
#if (IP_CONFIG == IPV4)
44+
#define SSID "<AP-SSID>"
45+
#define PSK "<AP-PASSPHRASE>"
46+
#define SECURITY_TYPE 1
47+
#define HTTP_SERVER_ADDR "<SERVER-ADDR>"
48+
#else
49+
#define SSID "<AP-SSID>"
50+
#define PSK "<AP-PASSPHRASE>"
51+
#define HTTP_SERVER_ADDR "<SERVER-ADDR>"
52+
#endif
53+
54+
/* HTTP/HTTPS configuration */
55+
#define HTTPS_SUPPORT 0 /**< Enable HTTPS support */
56+
#if (HTTPS_SUPPORT == 0)
57+
#define HTTP_PORT 8080 /**< HTTP port number */
58+
#else
59+
#define HTTP_PORT 8443 /**< HTTPS port number */
60+
#endif
61+
62+
/* Firmware update configuration */
63+
#define M4_FW_UPDATE 0 /**< M4 core firmware update */
64+
#define TA_FW_UPDATE 1 /**< TA core firmware update */
65+
#define COMBINED_FW_UPDATE 2 /**< Combined M4+TA update */
66+
67+
/* Secured image configuration */
68+
#define SECURED_IMAGE_UPDATE 0 /**< Enable secure image update */
69+
70+
#if (SECURED_IMAGE_UPDATE)
71+
#define SECURE_M4_RPS_FILE "secure_tcp_client.rps"
72+
#define SECURE_TA_RPS_FILE "secure_SiWG917-B.2.14.5.0.0.9.rps"
73+
#define SECURE_COMBINED_RPS_FILE "secure_combined_image.rps"
74+
#else
75+
#define M4_RPS_FILE "zephyr.bin.rps"
76+
#define TA_RPS_FILE "SiWG917-B.2.14.5.0.0.10.rps"
77+
#define COMBINED_RPS_FILE "combined_image_1.rps"
78+
#endif
79+
80+
#define FW_UPDATE_TYPE TA_FW_UPDATE
81+
#define HTTP_URL TA_RPS_FILE
82+
83+
84+
#endif /* APP_CONFIG_H */
1.25 KB
Binary file not shown.
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.der.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)