Skip to content

Commit 2d8e634

Browse files
feat: support Zephyr 4.2.0
* replace deprecated swap mode option From https://docs.zephyrproject.org/latest/releases/migration-guide-4.1.html: ``` The Kconfig ``SB_CONFIG_MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH`` has been deprecated and replaced with ``SB_CONFIG_MCUBOOT_MODE_SWAP_USING_MOVE``, applications should be updated to select this new symbol if they were selecting the old symbol. ``` Note that this will still allow us to build with older versions, as the MCUboot options set in mender-mcu's Kconfig are merely there for verbosity * return int in response callbacks This is needed in order to use Zephyr 4.2.0 From https://docs.zephyrproject.org/latest/releases/migration-guide-4.2.html: ``` The http_response_cb_t HTTP client response callback signature has changed. The callback function now returns int instead of void. This allows the application to abort the HTTP connection. Existing applications need to update their response callback implementations. To retain current behavior, simply return 0 from the callback. ``` In order to not break backwards compatibility we use Zephyr's `ZEPHYR_VERSION` and `ZEPHYR_VERSION_CODE` to define macros that return void on versions below 4.2.0 and int on newer versions. Ticket: MEN-8638 Changelog: Title Signed-off-by: Daniel Skinstad Drabitzius <daniel.drabitzius@northern.tech>
1 parent 5a79399 commit 2d8e634

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ here for more in-depth information.
5151
### Compatibility
5252
| Zephyr OS version |
5353
|-------------------|
54-
| v4.0.0 |
54+
| v4.2.0 |
5555

5656
### Boards
5757
The reference board for `mender-mcu` is the [ESP32-S3-DevKitC](https://docs.zephyrproject.org/latest/boards/espressif/esp32s3_devkitc/doc/index.html).
@@ -151,7 +151,8 @@ MCUboot. The following link will filter the officially supported boards that als
151151
The Update Module requires a swap algorithm in order to allow rollbacks to revert to the previous image.
152152
The [MCUboot documentation](https://docs.mcuboot.com/readme-zephyr.html) recommends against using the
153153
`swap-using-scratch algorithm`, which also requires its own `scratch_partition`. We therefore require
154-
`MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH` to be enabled in order to use the Update Module.
154+
`MCUBOOT_MODE_SWAP_USING_MOVE` (`MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH` for Zephyr versions below 4.1) to be
155+
enabled in order to use the Update Module.
155156

156157
#### Update Modules State Machine
157158

src/platform/net/zephyr/http.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727

2828
#include "net.h"
2929

30+
/* Zephyr versions 4.2.0 and above return int, versions below 4.2.0 return void */
31+
#if (ZEPHYR_VERSION_CODE < ZEPHYR_VERSION(4, 2, 0))
32+
#define HTTP_CALLBACK_RETURN_VALUE
33+
#define HTTP_CALLBACK_RETURN_TYPE void
34+
#else
35+
#define HTTP_CALLBACK_RETURN_VALUE 0
36+
#define HTTP_CALLBACK_RETURN_TYPE int
37+
#endif
38+
3039
/**
3140
* @brief HTTP User-Agent
3241
*/
@@ -58,16 +67,18 @@ static mender_http_config_t http_config;
5867
* @param response HTTP response structure
5968
* @param final_call Indicate final call
6069
* @param user_data User data, used to retrieve request context data
70+
* @return HTTP_CALLBACK_RETURN_VALUE, 0 if Zephyr >= 4.2.0, void otherwise
6171
*/
62-
static void http_response_cb(struct http_response *response, enum http_final_call final_call, void *user_data);
72+
static HTTP_CALLBACK_RETURN_TYPE http_response_cb(struct http_response *response, enum http_final_call final_call, void *user_data);
6373

6474
/**
6575
* @brief HTTP artifact response callback, invoked to handle data received
6676
* @param response HTTP response structure
6777
* @param final_call Indicate final call
6878
* @param user_data User data, used to retrieve request context data
79+
* @return HTTP_CALLBACK_RETURN_VALUE, 0 if Zephyr >= 4.2.0, void otherwise
6980
*/
70-
static void artifact_response_cb(struct http_response *response, enum http_final_call final_call, void *user_data);
81+
static HTTP_CALLBACK_RETURN_TYPE artifact_response_cb(struct http_response *response, enum http_final_call final_call, void *user_data);
7182

7283
/**
7384
* @brief Convert mender HTTP method to Zephyr HTTP client method
@@ -352,7 +363,7 @@ mender_http_exit(void) {
352363
return MENDER_OK;
353364
}
354365

355-
static void
366+
static HTTP_CALLBACK_RETURN_TYPE
356367
http_response_cb(struct http_response *response, MENDER_ARG_UNUSED enum http_final_call final_call, void *user_data) {
357368
assert(NULL != response);
358369
assert(NULL != user_data);
@@ -370,9 +381,10 @@ http_response_cb(struct http_response *response, MENDER_ARG_UNUSED enum http_fin
370381
mender_log_error("An error occurred, stop reading data");
371382
}
372383
}
384+
return HTTP_CALLBACK_RETURN_VALUE;
373385
}
374386

375-
static void
387+
static HTTP_CALLBACK_RETURN_TYPE
376388
artifact_response_cb(struct http_response *response, MENDER_ARG_UNUSED enum http_final_call final_call, void *user_data) {
377389

378390
assert(NULL != response);
@@ -390,6 +402,7 @@ artifact_response_cb(struct http_response *response, MENDER_ARG_UNUSED enum http
390402
mender_log_error("An error occurred, stop reading data");
391403
}
392404
}
405+
return HTTP_CALLBACK_RETURN_VALUE;
393406
}
394407

395408
static enum http_method

target/zephyr/Kconfig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ if MENDER_MCU_CLIENT
159159
# The MCUboot options here do not
160160
# affect the MCUboot configuration
161161
select BOOTLOADER_MCUBOOT
162-
select MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH
162+
select MCUBOOT_MODE_SWAP_USING_MOVE
163163
select IMG_ENABLE_IMAGE_CHECK
164164
select IMG_ERASE_PROGRESSIVELY
165165
select IMG_MANAGER
@@ -168,8 +168,9 @@ if MENDER_MCU_CLIENT
168168
The default zephyr-image update module handles full Zephyr images on MCUboot-based devices.
169169
The MCUboot options selected here do not actually modify the behavior of the bootloader
170170
since it's built separately from the Mender MCU client. `BOOTLOADER_MCUBOOT`
171-
and `MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH` (or another swap algorithm) must be enabled in
172-
the bootloader configuration, e.g. `sysbuild.conf` if you're using sysbuild.
171+
and `MCUBOOT_MODE_SWAP_USING_MOVE (`MCUBOOT_MODE_SWAP_WITHOUT_SCRATCH` for Zephyr versions below 4.1)`
172+
(or another swap algorithm) must be enabled in the bootloader configuration, e.g. `sysbuild.conf`
173+
if you're using sysbuild.
173174
endmenu
174175

175176
menuconfig MENDER_ARTIFACT_GENERATE

0 commit comments

Comments
 (0)