Skip to content

Commit 2c8fd3a

Browse files
Pico 2 W OTA Update Example (#559)
* Initial commit of OTA update example * Speedup and add hashing * Tidy up * Tidy up and use pico_use_partition_firmware function * Little extra fixes * Remove bootrom structs dependency * Update to work with latest SDK version * Move private.pem back to separate directories * Fix Risc-V alignment & stack issues * Increase partition sizes * Improve poll performance * Use CYW43_FIRMWARE_FAMILY_ID * Add example to readme * Remove poll version * Add separate README, move the python script, and add note about no_flash commented out lines * firmware -> wifi_firmware * tweak cmake guard * oops * add comment --------- Co-authored-by: Graham Sanderson <[email protected]> Co-authored-by: Graham Sanderson <[email protected]>
1 parent 6f2aac1 commit 2c8fd3a

File tree

9 files changed

+582
-2
lines changed

9 files changed

+582
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ App|Description
210210
[picow_http_client](pico_w/wifi/http_client) | Demonstrates how to make http and https requests
211211
[picow_http_client_verify](pico_w/wifi/http_client) | Demonstrates how to make a https request with server authentication
212212
[picow_mqtt_client](pico_w/wifi/mqtt) | Demonstrates how to implement a MQTT client application
213+
[picow_ota_update](pico_w/wifi/ota_update) | A minimal OTA update server (RP235x Only). See the separate [README](pico_w/wifi/ota_update/README.md) for more details.
213214

214215
#### FreeRTOS examples
215216

pico_w/wifi/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ else()
2020
add_subdirectory_exclude_platforms(http_client)
2121
add_subdirectory_exclude_platforms(mqtt)
2222

23-
if (NOT PICO_MBEDTLS_PATH)
24-
message("Skipping tls examples as PICO_MBEDTLS_PATH is not defined")
23+
if (NOT TARGET pico_mbedtls)
24+
message("Skipping tls_client and ota_update examples as Mbed TLS is not available")
2525
else()
2626
add_subdirectory_exclude_platforms(tls_client)
27+
# note ota_update doesn't use Mbed TLS, but it requires picotool with Mbed TLS, so the above check is a good proxy
28+
add_subdirectory_exclude_platforms(ota_update rp2040)
2729
endif()
2830
endif()

pico_w/wifi/ota_update/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
add_executable(picow_ota_update
2+
picow_ota_update.c
3+
)
4+
target_compile_definitions(picow_ota_update PRIVATE
5+
WIFI_SSID=\"${WIFI_SSID}\"
6+
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
7+
PICO_CRT0_IMAGE_TYPE_TBYB=1
8+
)
9+
target_include_directories(picow_ota_update PRIVATE
10+
${CMAKE_CURRENT_LIST_DIR}
11+
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts
12+
)
13+
target_link_libraries(picow_ota_update
14+
pico_cyw43_arch_lwip_threadsafe_background
15+
pico_stdlib
16+
pico_sha256
17+
boot_uf2_headers
18+
)
19+
20+
pico_use_wifi_firmware_partition(picow_ota_update)
21+
22+
pico_hash_binary(picow_ota_update)
23+
pico_sign_binary(picow_ota_update ${CMAKE_CURRENT_LIST_DIR}/private.pem)
24+
25+
# By default this example requires a partition table in flash, and will
26+
# update the partition that is not currently in use. To use it without
27+
# a partition table in flash, uncomment the following lines to make it
28+
# a no_flash binary, so it can update the currently running program.
29+
30+
# pico_set_binary_type(picow_ota_update no_flash)
31+
# pico_package_uf2_output(picow_ota_update 0x10000000)
32+
33+
pico_add_extra_outputs(picow_ota_update)

pico_w/wifi/ota_update/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
This example requires a partition table in flash. This can be loaded by creating a UF2 from the partition table JSON in this folder:
2+
```
3+
picotool partition create main.json pt.uf2
4+
```
5+
then dragging & dropping this UF2 onto the device, or loading it using `picotool` and rebooting:
6+
```
7+
picotool load pt.uf2
8+
picotool reboot -u
9+
```
10+
11+
Once the partition table is loaded, you first need to load the Wi-Fi firmware UF2 (`picow_ota_update_wifi_firmware.uf2`) followed by loading & executing the main program (`picow_ota_update.uf2`) - either by dragging and dropping them in order, or using `picotool`:
12+
```
13+
picotool load picow_ota_update_wifi_firmware.uf2
14+
picotool load -x picow_ota_update.uf2
15+
```
16+
17+
Once running, you can use [python_ota_update.py](python_ota_update.py) to upload new UF2s to it using it's IP address:
18+
```
19+
python python_ota_update.py 192.168.0.103 picow_ota_update.uf2
20+
```

pico_w/wifi/ota_update/lwipopts.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef _LWIPOPTS_H
2+
#define _LWIPOPTS_H
3+
4+
// Generally you would define your own explicit list of lwIP options
5+
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html)
6+
//
7+
// This example uses a common include to avoid repetition
8+
#include "lwipopts_examples_common.h"
9+
10+
#endif

pico_w/wifi/ota_update/main.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"version": [1, 0],
3+
"unpartitioned": {
4+
"families": ["absolute"],
5+
"permissions": {
6+
"secure": "rw",
7+
"nonsecure": "rw",
8+
"bootloader": "rw"
9+
}
10+
},
11+
"partitions": [
12+
{
13+
"name": "Main A",
14+
"id": 0,
15+
"size": "1744K",
16+
"families": ["rp2350-arm-s", "rp2350-riscv"],
17+
"permissions": {
18+
"secure": "rw",
19+
"nonsecure": "rw",
20+
"bootloader": "rw"
21+
}
22+
},
23+
{
24+
"name": "Main B",
25+
"id": 0,
26+
"size": "1744K",
27+
"families": ["rp2350-arm-s", "rp2350-riscv"],
28+
"permissions": {
29+
"secure": "rw",
30+
"nonsecure": "rw",
31+
"bootloader": "rw"
32+
},
33+
"link": ["a", 0]
34+
},
35+
{
36+
"name": "Firmware A",
37+
"id": "0x776966696669726d",
38+
"start": "3500k",
39+
"size": "256K",
40+
"families": ["cyw43-firmware"],
41+
"permissions": {
42+
"secure": "rw",
43+
"nonsecure": "rw",
44+
"bootloader": "rw"
45+
},
46+
"ignored_during_riscv_boot": true,
47+
"no_reboot_on_uf2_download": true
48+
},
49+
{
50+
"name": "Firmware B",
51+
"id": 12345,
52+
"size": "256K",
53+
"families": ["cyw43-firmware"],
54+
"permissions": {
55+
"secure": "rw",
56+
"nonsecure": "rw",
57+
"bootloader": "rw"
58+
},
59+
"link": ["a", 2],
60+
"ignored_during_riscv_boot": true,
61+
"no_reboot_on_uf2_download": true
62+
}
63+
]
64+
}

0 commit comments

Comments
 (0)