Skip to content

Commit b9f8a68

Browse files
committed
platform: rename mender-ota to mender-flash and cleanup of the apis
1 parent d4c354e commit b9f8a68

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

main/main.c

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
#include <freertos/task.h>
3636
#include "mender-client.h"
3737
#include "mender-configure.h"
38+
#include "mender-flash.h"
3839
#include "mender-inventory.h"
39-
#include "mender-ota.h"
4040
#include "mender-troubleshoot.h"
4141
#include <nvs_flash.h>
4242
#include <protocol_examples_common.h>
@@ -89,7 +89,7 @@ authentication_success_cb(void) {
8989
/* Validate the image if it is still pending */
9090
/* Note it is possible to do multiple diagnosic tests before validating the image */
9191
/* In this example, authentication success with the mender-server is enough */
92-
if (MENDER_OK != (ret = mender_ota_mark_app_valid_cancel_rollback())) {
92+
if (MENDER_OK != (ret = mender_flash_confirm_image())) {
9393
ESP_LOGE(TAG, "Unable to validate the image");
9494
return ret;
9595
}
@@ -104,24 +104,22 @@ authentication_success_cb(void) {
104104
static mender_err_t
105105
authentication_failure_cb(void) {
106106

107-
static int tries = 0;
108-
mender_err_t ret = MENDER_OK;
107+
static int tries = 0;
108+
109+
/* Check if confirmation of the image is still pending */
110+
if (true == mender_flash_is_image_confirmed()) {
111+
ESP_LOGE(TAG, "Mender client authentication failed");
112+
return MENDER_OK;
113+
}
109114

110115
/* Increment number of failures */
111116
tries++;
112-
ESP_LOGI(TAG, "Mender client authentication failed (%d/%d)", tries, CONFIG_EXAMPLE_AUTHENTICATION_FAILS_MAX_TRIES);
113-
114-
/* Invalidate the image if it is still pending */
115-
/* Note it is possible to invalid the image later to permit clean closure before reboot */
116-
/* In this example, several authentication failures with the mender-server is enough */
117-
if (tries >= CONFIG_EXAMPLE_AUTHENTICATION_FAILS_MAX_TRIES) {
118-
if (MENDER_OK != (ret = mender_ota_mark_app_invalid_rollback_and_reboot())) {
119-
ESP_LOGE(TAG, "Unable to invalidate the image");
120-
return ret;
121-
}
122-
}
117+
ESP_LOGE(TAG, "Mender client authentication failed (%d/%d)", tries, CONFIG_EXAMPLE_AUTHENTICATION_FAILS_MAX_TRIES);
123118

124-
return ret;
119+
/* Restart the application after several authentication failures with the mender-server */
120+
/* The image has not been confirmed and the bootloader will now rollback to the previous working image */
121+
/* Note it is possible to customize this depending of the wanted behavior */
122+
return (tries >= CONFIG_EXAMPLE_AUTHENTICATION_FAILS_MAX_TRIES) ? MENDER_FAIL : MENDER_OK;
125123
}
126124

127125
/**
@@ -417,15 +415,15 @@ app_main(void) {
417415
.authentication_poll_interval = 0,
418416
.update_poll_interval = 0,
419417
.recommissioning = false };
420-
mender_client_callbacks_t mender_client_callbacks = { .authentication_success = authentication_success_cb,
421-
.authentication_failure = authentication_failure_cb,
422-
.deployment_status = deployment_status_cb,
423-
.ota_begin = mender_ota_begin,
424-
.ota_write = mender_ota_write,
425-
.ota_abort = mender_ota_abort,
426-
.ota_end = mender_ota_end,
427-
.ota_set_boot_partition = mender_ota_set_boot_partition,
428-
.restart = restart_cb };
418+
mender_client_callbacks_t mender_client_callbacks = { .authentication_success = authentication_success_cb,
419+
.authentication_failure = authentication_failure_cb,
420+
.deployment_status = deployment_status_cb,
421+
.flash.open = mender_flash_open,
422+
.flash.write = mender_flash_write,
423+
.flash.close = mender_flash_close,
424+
.flash.set_pending_image = mender_flash_set_pending_image,
425+
.flash.abort_deployment = mender_flash_abort_deployment,
426+
.restart = restart_cb };
429427
ESP_ERROR_CHECK(mender_client_init(&mender_client_config, &mender_client_callbacks));
430428
ESP_LOGI(TAG, "Mender client initialized");
431429

0 commit comments

Comments
 (0)