OVMS3-idf/examples/system/ota/otatool
He Yin Ling 6e05a79536 test: update example and unit tests with new import roles:
tiny_test_fw is a python package now. import it using normal way.
2019-12-11 15:57:49 +11:00
..
main examples: use new component registration api 2019-06-21 19:53:29 +08:00
CMakeLists.txt examples: add otatool and parttool examples 2018-11-28 17:28:20 +08:00
example_test.py test: update example and unit tests with new import roles: 2019-12-11 15:57:49 +11:00
get_running_partition.py examples: create example for both Python and CLI otatool interfaces 2019-06-11 13:17:14 +08:00
Makefile examples: add otatool and parttool examples 2018-11-28 17:28:20 +08:00
otatool_example.py examples: create example for both Python and CLI otatool interfaces 2019-06-11 13:17:14 +08:00
otatool_example.sh examples: create example for both Python and CLI otatool interfaces 2019-06-11 13:17:14 +08:00
README.md examples: create example for both Python and CLI otatool interfaces 2019-06-11 13:17:14 +08:00
sdkconfig.defaults examples: add otatool and parttool examples 2018-11-28 17:28:20 +08:00

OTA Tool Example

This example demonstrates common operations the OTA tool otatool.py allows the user to perform:

  • reading, writing and erasing OTA partitions,
  • switching boot partitions, and
  • switching to factory partition.

Users taking a look at this example should focus on the contents of the Python script otatool_example.py or shell script otatool_example.sh. The scripts contain programmatic invocation of the tool's functions via the Python API and command-line interface, respectively. Note that on Windows, the shell script example requires a POSIX-compatible environment via MSYS2/Git Bash/WSL etc.

The built application in this example outputs the currently running partition, whose output is used to verify if the tool switched OTA partitions succesfully. The built application binary is written to all OTA partitions at the start of the example to be able to determine the running partition for all switches performed.

How to use example

Build and Flash

Before running either of the example scripts, it is necessary to build and flash the firmware using the usual means:

Make:

make build flash

CMake:

idf.py build flash

Running otatool_example.py

The example can be executed by running the script otatool_example.py or otatool_example.sh.

Python script:

python otatool_example.py

Shell script:

./otatool_example.sh

The script searches for valid target devices connected to the host and performs the operations on the first one it finds. This could present problems if there are multiple viable target devices attached to the host. To perform the operations on a specific device, specify the port it is attached to during script invocation ("/dev/ttyUSB2" for example):

Python script:

python otatool_example.py --port /dev/ttyUSB2

Shell script:

./otatool_example.sh /dev/ttyUSB2

Example output

Running the script produces the following output:

Writing factory firmware to ota_0
Writing factory firmware to ota_1
Switching to factory app
Switching to OTA slot 0
Switching to OTA slot 1 (twice in a row)
Switching to OTA slot 0 (twice in a row)
Switching to factory app
Switching to OTA slot 1

Partition tool operations performed successfully