-
Notifications
You must be signed in to change notification settings - Fork 117
Add FOTA Service mock example #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0a08bd3
Mock: add FOTA target
11b478e
Mock: add FOTA client
9becc0e
Mock: add initial README
80461a3
Mock: setup and teardown mbed TLS
264cffa
Mock: let client disconnect after commit
e10126e
Mock: update README
fa4c20f
Mock: document helpers
8a18051
Mock: remove redundant target and client traces
e698cc2
Mock: make block device eraser non-pointer member
3351aa0
Mock: fix hash print
147074c
Mock: fix max. frag. ID off-by-one error
dc88a78
Mock: ensure delivery of final fragment
6483a25
Mock: add FOTA commit trace
f9e0602
Mock: move cordio-ll config into nRF-specific block
69175c8
Mock: add CMakeLists.txt for CLI 2 builds
73650ff
Mock: revert to old flow
73eea09
Mock: rename APP_TARGET
6e3fa78
Mock: remove redundant import
d4225bc
Mock: Update README
0f2e010
Update BLE_GattServer_FOTAService/README.md
b121924
Update BLE_GattServer_FOTAService/README.md
21bdfde
Mock: split board configs
1f69da2
Mock: print sha256 using hashlib
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ROOT=. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
scripts/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) 2020 ARM Limited. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR) | ||
|
||
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "") | ||
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "") | ||
set(APP_TARGET BLE_GattServer_FOTAService) | ||
|
||
include(${MBED_PATH}/tools/cmake/app.cmake) | ||
|
||
add_subdirectory(${MBED_PATH}) | ||
|
||
add_subdirectory(mbed-os-experimental-ble-services/services/FOTA) | ||
|
||
include_directories(mbed-os-experimental-ble-services) | ||
|
||
add_executable(${APP_TARGET}) | ||
|
||
project(${APP_TARGET}) | ||
|
||
target_sources(${APP_TARGET} | ||
PRIVATE | ||
source/main.cpp | ||
source/BlockDeviceFOTAEventHandler.h | ||
source/BlockDeviceFOTAEventHandler.cpp | ||
source/PeriodicBlockDeviceEraser.h | ||
source/PeriodicBlockDeviceEraser.cpp | ||
) | ||
|
||
target_link_libraries(${APP_TARGET} | ||
PRIVATE | ||
mbed-os | ||
mbed-events | ||
mbed-ble | ||
mbed-storage | ||
mbed-mbedtls | ||
ble-service-fota | ||
) | ||
|
||
mbed_set_post_build(${APP_TARGET}) | ||
|
||
option(VERBOSE_BUILD "Have a verbose build process") | ||
if(VERBOSE_BUILD) | ||
set(CMAKE_VERBOSE_MAKEFILE ON) | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# FOTA Service Mock Example | ||
|
||
The FOTA service, as defined in its [specification](https://github.com/ARMmbed/mbed-os-experimental-ble-services/blob/fota-service-github-ci/services/FOTA/docs/README.md) document, facilitates the transfer of firmware updates over BLE. | ||
|
||
In this demo, the FOTA service is used to transfer a binary from the host PC into the flash of the target. | ||
A basic _FOTA client_, implemented in Python using [bleak](https://pypi.org/project/bleak/), is used to read/write the binary stream, control and status characteristics. | ||
Please refer to [Section 1](https://github.com/ARMmbed/mbed-os-experimental-ble-services/tree/fota-service-github-ci/services/FOTA/docs#fota-service-structure) of the spec to learn more about these characteristics. | ||
|
||
To verify the success of the transfer, the application computes the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) of the binary and prints it to the serial port. | ||
The SHA-256 is also computed on the host using [sha256sum](https://man7.org/linux/man-pages/man1/sha256sum.1.html). | ||
The transfer is regarded as a success if the hashes are equal. | ||
|
||
## Usage | ||
|
||
### Hardware Requirements | ||
|
||
This application requires either the [DISCO_L475VG_IOT01A](https://os.mbed.com/platforms/ST-Discovery-L475E-IOT01A/) or [NRF52840_DK](https://os.mbed.com/platforms/Nordic-nRF52-DK/) platforms. | ||
|
||
To use the Python client, the host PC must have Bluetooth capabilities, either through an inbuilt chipset or an external USB adapter. | ||
|
||
### Building | ||
|
||
The application can be built and flashed onto the target using Mbed CLI 2: | ||
|
||
```shell | ||
mbed-tools deploy | ||
mbed-tools compile -t <toolchain> -m <target> -f | ||
``` | ||
|
||
A `bin` file is required for the demo. | ||
For nRF, this must be created manually from the `elf` as Mbed Tools outputs a `hex` file by default: | ||
|
||
```shell | ||
arm-none-eabi-objcopy -O binary cmake_build/NRF52840_DK/develop/<toolchain>/BLE_GattServer_FOTAService.elf cmake_build/NRF52840_DK/develop/<toolchain>/BLE_GattServer_FOTAService.bin | ||
``` | ||
|
||
Lastly, create a Python virtual environment inside the `scripts` folder and install bleak: | ||
|
||
```shell | ||
cd scripts && mkdir venv && virtualenv venv && source venv/bin/activate | ||
python -m pip install --upgrade pip && pip install bleak | ||
``` | ||
|
||
### Demonstration | ||
|
||
1. Open a serial terminal on the host PC to receive serial prints from the _FOTA target_: | ||
|
||
```shell | ||
mbed term -b 115200 | ||
``` | ||
|
||
2. In a separate window, run the test script: | ||
|
||
``` | ||
python test_fota.py | ||
``` | ||
|
||
It scans for a device named 'FOTA' and attempts to connect to it. | ||
Once connected, it asks the user to enter the path to the binary. | ||
Use the binary running on the target: | ||
|
||
``` | ||
Enter the path to the binary: ../cmake_build/<target>/develop/<toolchain>/BLE_GattServer_FOTAService.bin | ||
``` | ||
|
||
3. The client initiates the transfer once the FOTA session begins and commits the update once the entire binary has been sent. | ||
Subsequently, the target computes the SHA-256 of the binary and prints it to the serial. | ||
Verify the `<hash>` with sha256sum: | ||
|
||
```shell | ||
echo "<hash> ../cmake_build/<target>/develop/<toolchain>/BLE_GattServer_FOTAService.bin" | sha256sum --check | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
``` |
1 change: 1 addition & 0 deletions
1
BLE_GattServer_FOTAService/mbed-os-experimental-ble-services.lib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://github.com/ARMmbed/mbed-os-experimental-ble-services/#7f7ed190a4d5da02a1340aeff3ed2e7bc9ee5b64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
https://github.com/noonfom/mbed-os/#27160dbe0460ed5c898effbaf8881c39117ba505 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"target_overrides": { | ||
"*": { | ||
"platform.stdio-convert-newlines": true, | ||
"platform.stdio-baud-rate": 115200, | ||
"mbed-trace.enable": 1, | ||
"mbed-trace.max-level": "TRACE_LEVEL_INFO", | ||
"ble-api-implementation.max-characteristic-authorisation-count": 100 | ||
}, | ||
"DISCO_L475VG_IOT01A": { | ||
"target.features_add": ["BLE"], | ||
"cordio.desired-att-mtu": 200, | ||
"cordio.rx-acl-buffer-size": 204 | ||
}, | ||
"NRF52840_DK": { | ||
"target.features_add": ["BLE"], | ||
"cordio.desired-att-mtu": 200, | ||
"cordio.rx-acl-buffer-size": 204, | ||
"cordio-nordic-ll.wsf-pool-buffer-size": 8192, | ||
"cordio-ll.max-acl-size": 204 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[loggers] | ||
keys=root,logger | ||
|
||
[handlers] | ||
keys=consoleHandler | ||
|
||
[formatters] | ||
keys=simpleFormatter | ||
|
||
[logger_root] | ||
level=INFO | ||
handlers=consoleHandler | ||
|
||
[logger_logger] | ||
level=INFO | ||
handlers=consoleHandler | ||
qualname=logger | ||
propagate=0 | ||
|
||
[handler_consoleHandler] | ||
class=StreamHandler | ||
level=INFO | ||
formatter=simpleFormatter | ||
args=(sys.stdout,) | ||
|
||
[formatter_simpleFormatter] | ||
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s | ||
datefmt= |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.