|
1 | | -# Application interface for interactions with the bootloader |
| 1 | +# Application Interface for wolfBoot |
2 | 2 |
|
3 | | -wolfBoot offers a small interface to interact with the images stored in the partition, |
4 | | -explicitly initiate an update and confirm the success of a previously scheduled update. |
| 3 | +wolfBoot provides an API through libwolfboot that allows applications to: |
| 4 | +- Query firmware versions in both BOOT and UPDATE partitions |
| 5 | +- Initiate firmware updates |
| 6 | +- Confirm successful firmware boots |
| 7 | +- Access partition states |
5 | 8 |
|
6 | | -## Compiling and linking with libwolfboot |
| 9 | +## Compiling and Linking with libwolfboot |
7 | 10 |
|
8 | | -An application that requires interactions with wolfBoot must include the header file: |
| 11 | +Applications using wolfBoot functionality must: |
9 | 12 |
|
10 | | -`#include <wolfboot/wolfboot.h>` |
| 13 | +1. Include the wolfBoot header: |
| 14 | + ```c |
| 15 | + #include <wolfboot/wolfboot.h>` |
| 16 | + ``` |
11 | 17 |
|
12 | | -This exports the API function declarations, and the predefined values for the flags |
13 | | -and tags stored together with the firmware images in the two partitions. |
| 18 | +2. Link against libwolfboot library |
14 | 19 |
|
15 | | -For more information about flash partitions, flags and states see [Flash partitions](flash_partitions.md). |
| 20 | +The header provides: |
| 21 | +- API function declarations |
| 22 | +- Predefined partition flag values |
| 23 | +- Image tag definitions |
| 24 | +- Partition state constants |
16 | 25 |
|
17 | | -## API |
| 26 | +For details about flash partitions, flags and states see [Flash partitions](flash_partitions.md). |
18 | 27 |
|
19 | | -libwolfboot provides low-level access interface to flash partition states. The state |
20 | | -of each partition can be retrieved and altered by the application. |
| 28 | +## Core API Functions |
21 | 29 |
|
22 | | -Basic interaction from the application is provided via the following high-level function calls: |
| 30 | +libwolfboot provides both high-level and low-level interfaces to manage firmware updates: |
23 | 31 |
|
24 | | -`uint32_t wolfBoot_get_image_version(uint8_t part)` |
| 32 | +### High-Level Functions |
25 | 33 |
|
26 | | -`void wolfBoot_update_trigger(void)` |
| 34 | +```c |
| 35 | +uint32_t wolfBoot_get_image_version(uint8_t part) |
| 36 | +void wolfBoot_update_trigger(void) |
| 37 | +void wolfBoot_success(void) |
| 38 | +``` |
27 | 39 |
|
28 | | -`void wolfBoot_success(void)` |
| 40 | +### Version Management Functions |
29 | 41 |
|
30 | | -### Firmware version |
| 42 | +#### Get Image Version |
| 43 | +```c |
| 44 | +uint32_t wolfBoot_get_image_version(uint8_t part) |
| 45 | +``` |
| 46 | +Retrieves the version number of the firmware in the specified partition. |
31 | 47 |
|
32 | | -Current (boot) firmware and update firmware versions can be retrieved from the application using: |
| 48 | +Parameters: |
| 49 | +- `part`: Partition ID (PART_BOOT or PART_UPDATE) |
33 | 50 |
|
34 | | -`uint32_t wolfBoot_get_image_version(uint8_t part)` |
| 51 | +Returns: |
| 52 | +- Version number of the firmware in the specified partition |
| 53 | +- 0 if no valid firmware exists in the partition |
35 | 54 |
|
36 | | -Or via the shortcut macros: |
| 55 | +#### Convenience Macros |
| 56 | +```c |
| 57 | +wolfBoot_current_firmware_version() // Get version of firmware in BOOT partition |
| 58 | +wolfBoot_update_firmware_version() // Get version of firmware in UPDATE partition |
| 59 | +``` |
37 | 60 |
|
38 | | -`wolfBoot_current_firmware_version()` |
| 61 | +### Update Management Functions |
39 | 62 |
|
40 | | -and |
| 63 | +#### Trigger Update |
| 64 | +```c |
| 65 | +void wolfBoot_update_trigger(void) |
| 66 | +``` |
| 67 | +Initiates the firmware update process for the next boot. |
41 | 68 |
|
42 | | -`wolfBoot_update_firmware_version()` |
| 69 | +Operation: |
| 70 | +1. Sets UPDATE partition state to `STATE_UPDATING` |
| 71 | +2. On next boot, wolfBoot will: |
| 72 | + - Verify the update image signature |
| 73 | + - Swap BOOT and UPDATE partition contents using SWAP space |
| 74 | + - Set new firmware state to `STATE_TESTING` |
| 75 | + - Boot into new firmware |
43 | 76 |
|
44 | | -### Trigger an update |
| 77 | +Note: The update image must be stored in the UPDATE partition before calling this function. |
45 | 78 |
|
46 | | - - `wolfBoot_update_trigger()` is used to trigger an update upon the next reboot, and it is normally used by |
47 | | -an update application that has retrieved a new version of the running firmware, and has |
48 | | -stored it in the UPDATE partition on the flash. This function will set the state of the UPDATE partition |
49 | | -to `STATE_UPDATING`, instructing the bootloader to perform the update upon the next execution (after reboot). |
| 79 | +### Boot Confirmation Functions |
50 | 80 |
|
51 | | -wolfBoot update process swaps the contents of the UPDATE and the BOOT partitions, using a temporary |
52 | | -single-block SWAP space. |
| 81 | +#### Confirm Successful Boot |
| 82 | +```c |
| 83 | +void wolfBoot_success(void) |
| 84 | +``` |
| 85 | +Confirms successful boot of the current firmware. |
53 | 86 |
|
54 | | -### Confirm current image |
| 87 | +Operation: |
| 88 | +1. Marks current firmware in BOOT partition as `STATE_SUCCESS` |
| 89 | +2. Prevents automatic rollback on next boot |
55 | 90 |
|
56 | | -- `wolfBoot_success()` indicates a successful boot of a new firmware. This can be called by the application |
57 | | -at any time, but it will only be effective to mark the current firmware (in the BOOT partition) with the state |
58 | | -`STATE_SUCCESS`, indicating that no roll-back is required. An application should typically call `wolfBoot_success()` |
59 | | -only after verifying that the basic system features are up and running, including the possibility to retrieve |
60 | | -a new firmware for the next upgrade. |
| 91 | +Important: |
| 92 | +- Should be called only after verifying critical system functionality |
| 93 | +- Recommended to verify: |
| 94 | + - Core system features work correctly |
| 95 | + - Update capability is functional |
| 96 | + - Any required peripherals are accessible |
61 | 97 |
|
62 | | -If after an upgrade and reboot wolfBoot detects that the active firmware is still in `STATE_TESTING` state, it means that |
63 | | -a successful boot has not been confirmed for the application, and will attempt to revert the update by swapping |
64 | | -the two images again. |
| 98 | +Rollback Behavior: |
| 99 | +- If firmware remains in `STATE_TESTING` state after reboot |
| 100 | +- wolfBoot will automatically rollback to previous version |
| 101 | +- Accomplished by re-swapping BOOT and UPDATE partitions |
65 | 102 |
|
66 | | -For more information about the update process, see [Firmware Update](firmware_update.md) |
67 | | - |
68 | | -For the image format, see [Firmware Image](firmware_image.md) |
| 103 | +Related Documentation: |
| 104 | +- [Firmware Update Process](firmware_update.md) |
| 105 | +- [Firmware Image Format](firmware_image.md) |
0 commit comments