Skip to content

Commit 9adebc4

Browse files
committed
Added support for Delta OTA
1 parent 224d004 commit 9adebc4

File tree

8 files changed

+285
-14
lines changed

8 files changed

+285
-14
lines changed

components/bluetooth/ble_profiles/esp/ble_ota/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@
6767
## v0.1.12 - 2024-02-19
6868

6969
* BLE-OTA:
70-
* Add support for ESP32C2 and ESP32C6.
70+
* Add support for ESP32C2 and ESP32C6.
71+
72+
## v0.1.13 - 2024-10-21
73+
74+
* BLE-OTA:
75+
* Add support for Delta OTA.

components/bluetooth/ble_profiles/esp/ble_ota/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.1.12"
1+
version: "0.1.13"
22
targets:
33
- esp32
44
- esp32c3

components/bluetooth/ble_profiles/esp/ble_ota/src/ble_ota.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string.h>
88
#include "freertos/FreeRTOS.h"
99
#include "esp_idf_version.h"
10+
#include "freertos/semphr.h"
1011

1112
#include "esp_log.h"
1213
#include "ble_ota.h"
@@ -700,8 +701,14 @@ void esp_ble_ota_process_recv_data(esp_ble_ota_char_t ota_char, uint8_t *val, ui
700701
// Stop BLE OTA Process
701702
else if ((val[0] == 0x02) && (val[1] == 0x00)) {
702703
if (start_ota) {
704+
extern SemaphoreHandle_t notify_sem;
705+
xSemaphoreTake(notify_sem, portMAX_DELAY);
706+
703707
start_ota = false;
704708
esp_ble_ota_set_fw_length(0);
709+
710+
xSemaphoreGive(notify_sem);
711+
705712
ESP_LOGI(TAG, "recv ota stop cmd");
706713
esp_ble_ota_send_ack_data(BLE_OTA_CMD_ACK, BLE_OTA_CMD_SUCCESS, BLE_OTA_STOP_CMD);
707714

components/bluetooth/ble_profiles/esp/ble_ota/src/nimble_ota.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "services/gatt/ble_svc_gatt.h"
1717
#include "host/ble_uuid.h"
1818
#include "ble_ota.h"
19+
#include "freertos/semphr.h"
1920
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
2021
#include "esp_nimble_hci.h"
2122
#endif
@@ -375,8 +376,14 @@ ble_ota_start_write_chr(struct os_mbuf *om)
375376
ESP_LOGI(TAG, "Decryption end failed");
376377
}
377378
#endif
379+
extern SemaphoreHandle_t notify_sem;
380+
xSemaphoreTake(notify_sem, portMAX_DELAY);
381+
378382
start_ota = false;
379383
ota_total_len = 0;
384+
385+
xSemaphoreGive(notify_sem);
386+
380387
ESP_LOGD(TAG, "recv ota stop cmd");
381388
cmd_ack[2] = 0x02;
382389
cmd_ack[3] = 0x00;

examples/bluetooth/ble_ota/README.md

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ACK_Status:
6464

6565
### 4.1 OTA update ESP32-H2
6666

67-
To construct the BLE OTA demo for the ESP32-H2 device, ensure you're using ESP-IDF version 5.0 or later. Currently, the ESP32-H2 doesn't support NimBLE OTA updates, so omit the instructions in section 5. Maintain the default configuration for the Bluetooth framework, where `Bluedroid - Dual-mode` is selected. To ensure compatibility with the sample app mentioned in section 3, deactivate BLE 5.0 features by navigating to:
67+
To construct the BLE OTA demo for the ESP32-H2 device, ensure you're using ESP-IDF version 5.0 or later. If `Bluedroid - Dual-mode` is selected, to ensure compatibility with the sample app mentioned in section 3, deactivate BLE 5.0 features by navigating to:
6868

6969
1. `Component config` > `Bluetooth` > `Bluedroid Options` and deselect `Enable BLE 5.0 features`.
7070
2. `Component config` > `Bluetooth` > `Controller Options` and deselect `Enable BLE 5 feature`.
@@ -77,9 +77,11 @@ To construct the BLE OTA demo for the ESP32-H2 device, ensure you're using ESP-I
7777

7878
- Component config → Bluetooth → Bluetooth → Host → NimBLE - BLE only
7979

80-
Note: For maximum throughput, set maximum MTU using
80+
- Note: For maximum throughput, set maximum MTU using
8181

82-
- Component config → Bluetooth → NimBLE Options → Preferred MTU size in octets as 517
82+
- Component config → Bluetooth → NimBLE Options → Preferred MTU size in octets as 517
83+
84+
Ensure the image that is being transferred over BLE, should have the same FLASHSIZE ( 4MB ) as the one that is set by the ble_ota example. i.e. ensure **ESPTOOLPY_FLASHSIZE_4MB** is set.
8385

8486
### 5.1 OTA with Protocomm
8587

@@ -99,6 +101,54 @@ Note: For maximum throughput, set maximum MTU using
99101

100102
`idf.py menuconfig`
101103

102-
- If using ESP32S3 set Component config → Bluetooth → Bluetooth → NimBLE Options → NimBLE Host task stack size as 8192
104+
- If using ESP32S3 set Component config → Bluetooth → Bluetooth → NimBLE Options → NimBLE Host task stack size as 8192
103105
- Example Configuration → Type of OTA → Use Pre-Encrypted OTA
104106
- Component config → OTA Manager → Type of OTA → Enable pre encrypted OTA
107+
108+
## 6. Delta OTA
109+
110+
### 6.1 NimBLE OTA
111+
112+
`idf.py menuconfig`
113+
114+
- Component config → Bluetooth → Bluetooth → Host → NimBLE - BLE only
115+
116+
> **_NOTE:_** For maximum throughput, set maximum MTU using
117+
118+
- Component config → Bluetooth → NimBLE Options → Preferred MTU size in octets as 517
119+
120+
- Example Configuration → Type of OTA → Use Delta OTA
121+
122+
- if using ESP32H2, ESP32C6
123+
1. Component config → Bluetooth → Bluetooth → NimBLE Options → deselect `Enable BLE 5 feature`
124+
2. Example Configuration → deselect `Enable Extended Adv`
125+
126+
### 6.2 Bluedroid
127+
128+
`idf.py menuconfig`
129+
130+
- Component config → Bluetooth → Bluetooth → Host → Bluedroid - Dual-mode
131+
- Component config → Bluetooth → Bluetooth → Bluedroid Options → deselect `Enable BLE 5.0 feature`
132+
- Component config → Bluetooth → Bluetooth → Bluedroid Options → deselect `Enable BLE 4.2 feature`
133+
- Example Configuration → Type of OTA → Use Delta OTA
134+
135+
### Creating Patch
136+
137+
Now we will consider this firmware as the base firmware which we will flash into the device. We need a new firmware to which we want to upgrade to. You can try b
138+
ilding the `hello_world` example present in ESP-IDF.
139+
We need to create a patch file for this new firmware.
140+
141+
Install required packages:
142+
```
143+
pip install -r tools/requirements.txt
144+
```
145+
146+
To create a patch file, use the [python tool](./tools/esp_delta_ota_patch_gen.py)
147+
```
148+
python esp_delta_ota_patch_gen.py --chip <target> --base_binary <base_binary> --new_binary <new_binary> --patch_file_name <patch_file_name>
149+
```
150+
151+
This will generate the patch file for the new binary which needs to be hosted on the OTA update server.
152+
153+
> **_NOTE:_** Make sure that the firmware present in the device is used as `base_binary` while creating the patch file. For this purpose, user should keep backup
154+
of the firmware running in the device as it is required for creating the patch file.

examples/bluetooth/ble_ota/main/Kconfig.projbuild

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ menu "Example Configuration"
5757
depends on BT_NIMBLE_ENABLED
5858
help
5959
This enables transferring pre-encrypted file via OTA
60+
61+
config EXAMPLE_USE_DELTA_OTA
62+
bool "Use Delta OTA"
63+
help
64+
This enables transferring patch file via Delta OTA
6065
endchoice
6166

6267
config EXAMPLE_EXTENDED_ADV

0 commit comments

Comments
 (0)