Skip to content

Commit 7f41008

Browse files
committed
DEBUG: test scenario for confirm image after an OTA - THIS COMMIT WILL BE DELETED
Signed-off-by: Almir Okato <almir.okato@espressif.com>
1 parent 3e4561a commit 7f41008

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
&flash0 {
2+
write-block-size = <32>;
3+
};
4+

samples/subsys/mgmt/mcumgr/smp_svr/overlay-bt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CONFIG_MCUMGR_TRANSPORT_BT_CONN_PARAM_CONTROL=y
1414
# Enable the Shell mcumgr transport.
1515
CONFIG_BASE64=y
1616
CONFIG_CRC=y
17-
CONFIG_SHELL=y
17+
# CONFIG_SHELL=y
1818
CONFIG_SHELL_BACKEND_SERIAL=y
1919
CONFIG_MCUMGR_TRANSPORT_SHELL=y
2020

samples/subsys/mgmt/mcumgr/smp_svr/prj.conf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CONFIG_FLASH_MAP=y
88

99
# Some command handlers require a large stack.
1010
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
11-
CONFIG_MAIN_STACK_SIZE=2048
11+
CONFIG_MAIN_STACK_SIZE=8192
1212

1313
# Ensure an MCUboot-compatible binary is generated.
1414
CONFIG_BOOTLOADER_MCUBOOT=y
@@ -35,7 +35,15 @@ CONFIG_MCUMGR_GRP_STAT=y
3535

3636
# Enable logging
3737
CONFIG_LOG=y
38-
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y
38+
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_INF=y
39+
CONFIG_LOG_MODE_IMMEDIATE=y
40+
# CONFIG_LOG_BUFFER_SIZE=4096
3941

4042
# Disable debug logging
4143
CONFIG_LOG_MAX_LEVEL=3
44+
45+
CONFIG_REBOOT=y
46+
47+
# Ensure asset is aligned and padded correctly for flash encryption.
48+
CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS="--align 32 --max-align 32 --pad --pad-sig"
49+
CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE=y

samples/subsys/mgmt/mcumgr/smp_svr/src/main.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <zephyr/kernel.h>
99
#include <zephyr/stats/stats.h>
1010
#include <zephyr/usb/usb_device.h>
11+
#include <zephyr/dfu/mcuboot.h>
1112

1213
#ifdef CONFIG_MCUMGR_GRP_FS
1314
#include <zephyr/device.h>
@@ -18,8 +19,14 @@
1819
#include <zephyr/mgmt/mcumgr/grp/stat_mgmt/stat_mgmt.h>
1920
#endif
2021

22+
#include <zephyr/sys/reboot.h>
23+
#include <stdlib.h>
24+
#include <stdio.h>
25+
2126
#define LOG_LEVEL LOG_LEVEL_DBG
2227
#include <zephyr/logging/log.h>
28+
#include <zephyr/logging/log_ctrl.h>
29+
2330
LOG_MODULE_REGISTER(smp_sample);
2431

2532
#include "common.h"
@@ -50,6 +57,42 @@ static struct fs_mount_t littlefs_mnt = {
5057
};
5158
#endif
5259

60+
int latch_ota_if_required()
61+
{
62+
// boot_request_upgrade(false);
63+
64+
// LOG_PANIC();
65+
// k_sleep(K_SECONDS(2));
66+
// sys_reboot(SYS_REBOOT_COLD);
67+
68+
LOG_INF("latch_ota_if_required");
69+
70+
if (boot_is_img_confirmed()) {
71+
LOG_INF("No update is currently being tested");
72+
return 0;
73+
}
74+
75+
LOG_INF("latch_ota_if_required 2");
76+
77+
int ret = boot_write_img_confirmed();
78+
if (ret) {
79+
LOG_ERR("Current image is being tested, but failed to confirm! Rollback imminent!"
80+
"(err %d)",
81+
ret);
82+
return ret;
83+
}
84+
85+
LOG_INF("boot_write_img_confirmed() appears to have been successful");
86+
87+
if (boot_is_img_confirmed()) {
88+
LOG_INF("boot_write_img_confirmed worked");
89+
} else {
90+
LOG_ERR("boot_write_img_confirmed did not work -- this shouldn't happen");
91+
}
92+
93+
return 0;
94+
}
95+
5396
int main(void)
5497
{
5598
int rc = STATS_INIT_AND_REG(smp_svr_stats, STATS_SIZE_32,
@@ -85,6 +128,8 @@ int main(void)
85128
*/
86129
LOG_INF("build time: " __DATE__ " " __TIME__);
87130

131+
latch_ota_if_required();
132+
88133
/* The system work queue handles all incoming mcumgr requests. Let the
89134
* main thread idle while the mcumgr server runs.
90135
*/

0 commit comments

Comments
 (0)