mgmt: mcumgr: Add logging output
Adds logging to mcumgr commands for debug and error reporting Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
parent
50446afe6c
commit
df0fa6d965
13 changed files with 64 additions and 13 deletions
|
@ -161,4 +161,8 @@ config MCUMGR_GRP_FS_FILE_ACCESS_HOOK
|
|||
Note that this will be called multiple times for each file read and
|
||||
write due to mcumgr's method of stateless operation.
|
||||
|
||||
module = MCUMGR_GRP_FS
|
||||
module-str = mcumgr_grp_fs
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
endif
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
@ -55,9 +56,7 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#define LOG_LEVEL CONFIG_MCUMGR_LOG_LEVEL
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(fs_mgmt);
|
||||
LOG_MODULE_REGISTER(mcumgr_fs_grp, CONFIG_MCUMGR_GRP_FS_LOG_LEVEL);
|
||||
|
||||
#define HASH_CHECKSUM_TYPE_SIZE 8
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ config MCUMGR_GRP_IMG_STATUS_HOOKS
|
|||
or prevent it, CONFIG_MCUMGR_GRP_IMG_UPLOAD_CHECK_HOOK must be used.
|
||||
|
||||
module = MCUMGR_GRP_IMG
|
||||
module-str = mcumgr_img_mgmt
|
||||
module-str = mcumgr_grp_img
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
endif
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <zephyr/toolchain.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include <zcbor_common.h>
|
||||
#include <zcbor_decode.h>
|
||||
|
@ -34,8 +35,7 @@
|
|||
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>
|
||||
#endif
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_DECLARE(mcumgr_img_mgmt, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
|
||||
LOG_MODULE_REGISTER(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
|
||||
|
||||
struct img_mgmt_state g_img_mgmt_state;
|
||||
|
||||
|
@ -428,6 +428,7 @@ img_mgmt_upload(struct smp_streamer *ctxt)
|
|||
#endif
|
||||
|
||||
MGMT_CTXT_SET_RC_RSN(ctxt, IMG_MGMT_UPLOAD_ACTION_RC_RSN(&action));
|
||||
LOG_ERR("Image upload inspect failed: %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -546,6 +547,8 @@ img_mgmt_upload(struct smp_streamer *ctxt)
|
|||
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(&action,
|
||||
img_mgmt_err_str_flash_write_failed);
|
||||
|
||||
LOG_ERR("Irrecoverable error: flash write failed: %d", rc);
|
||||
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,15 +4,13 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(mcumgr_img_mgmt, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/drivers/flash.h>
|
||||
#include <zephyr/storage/flash_map.h>
|
||||
#include <zephyr/dfu/mcuboot.h>
|
||||
#include <zephyr/dfu/flash_img.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <bootutil/bootutil_public.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
@ -23,6 +21,8 @@ LOG_MODULE_REGISTER(mcumgr_img_mgmt, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
|
|||
#include <mgmt/mcumgr/grp/img_mgmt/img_mgmt_impl.h>
|
||||
#include <mgmt/mcumgr/grp/img_mgmt/img_mgmt_priv.h>
|
||||
|
||||
LOG_MODULE_DECLARE(mcumgr_img_grp, CONFIG_MCUMGR_GRP_IMG_LOG_LEVEL);
|
||||
|
||||
#define SLOT0_PARTITION slot0_partition
|
||||
#define SLOT1_PARTITION slot1_partition
|
||||
#define SLOT2_PARTITION slot2_partition
|
||||
|
@ -107,6 +107,7 @@ static int img_mgmt_flash_check_empty_inner(const struct flash_area *fa)
|
|||
|
||||
rc = flash_area_read(fa, addr, data, bytes_to_read);
|
||||
if (rc < 0) {
|
||||
LOG_ERR("Failed to read data from flash area: %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -137,6 +138,8 @@ static int img_mgmt_flash_check_empty(uint8_t fa_id)
|
|||
rc = img_mgmt_flash_check_empty_inner(fa);
|
||||
|
||||
flash_area_close(fa);
|
||||
} else {
|
||||
LOG_ERR("Failed to open flash area ID %u: %d", fa_id, rc);
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
@ -294,6 +297,7 @@ img_mgmt_erase_slot(int slot)
|
|||
rc = flash_area_open(area_id, &fa);
|
||||
|
||||
if (rc < 0) {
|
||||
LOG_ERR("Failed to open flash area ID %u: %d", area_id, rc);
|
||||
return MGMT_ERR_EUNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -301,6 +305,10 @@ img_mgmt_erase_slot(int slot)
|
|||
|
||||
if (rc == 0) {
|
||||
rc = flash_area_erase(fa, 0, fa->fa_size);
|
||||
|
||||
if (rc != 0) {
|
||||
LOG_ERR("Failed to erase flash area: %d", rc);
|
||||
}
|
||||
}
|
||||
|
||||
flash_area_close(fa);
|
||||
|
@ -319,6 +327,7 @@ img_mgmt_write_pending(int slot, bool permanent)
|
|||
|
||||
rc = boot_request_upgrade_multi(img_mgmt_slot_to_image(slot), permanent);
|
||||
if (rc != 0) {
|
||||
LOG_ERR("Failed to write pending flag for slot %d: %d", slot, rc);
|
||||
return MGMT_ERR_EUNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -332,6 +341,7 @@ img_mgmt_write_confirmed(void)
|
|||
|
||||
rc = boot_write_img_confirmed();
|
||||
if (rc != 0) {
|
||||
LOG_ERR("Failed to write confirmed flag: %d", rc);
|
||||
return MGMT_ERR_EUNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -351,6 +361,7 @@ img_mgmt_read(int slot, unsigned int offset, void *dst, unsigned int num_bytes)
|
|||
|
||||
rc = flash_area_open(area_id, &fa);
|
||||
if (rc != 0) {
|
||||
LOG_ERR("Failed to open flash area ID %u: %d", area_id, rc);
|
||||
return MGMT_ERR_EUNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -358,6 +369,7 @@ img_mgmt_read(int slot, unsigned int offset, void *dst, unsigned int num_bytes)
|
|||
flash_area_close(fa);
|
||||
|
||||
if (rc != 0) {
|
||||
LOG_ERR("Failed to read data from flash: %d", rc);
|
||||
return MGMT_ERR_EUNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -616,6 +628,8 @@ img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
|
|||
if (rc) {
|
||||
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action,
|
||||
img_mgmt_err_str_flash_open_failed);
|
||||
LOG_ERR("Failed to open flash area ID %u: %d", action->area_id,
|
||||
rc);
|
||||
return MGMT_ERR_EUNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -689,6 +703,7 @@ img_mgmt_erased_val(int slot, uint8_t *erased_val)
|
|||
|
||||
rc = flash_area_open(area_id, &fa);
|
||||
if (rc != 0) {
|
||||
LOG_ERR("Failed to open flash area ID %u: %d", area_id, rc);
|
||||
return MGMT_ERR_EUNKNOWN;
|
||||
}
|
||||
|
||||
|
|
|
@ -168,4 +168,8 @@ config MCUMGR_GRP_OS_INFO_BUILD_DATE_TIME
|
|||
|
||||
endif
|
||||
|
||||
module = MCUMGR_GRP_OS
|
||||
module-str = mcumgr_grp_os
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
endif
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <zephyr/mgmt/mcumgr/smp/smp.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
@ -41,6 +42,8 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
LOG_MODULE_REGISTER(mcumgr_os_grp, CONFIG_MCUMGR_GRP_OS_LOG_LEVEL);
|
||||
|
||||
#ifdef CONFIG_REBOOT
|
||||
static void os_mgmt_reset_work_handler(struct k_work *work);
|
||||
static void os_mgmt_reset_cb(struct k_timer *timer);
|
||||
|
@ -288,6 +291,10 @@ static int os_mgmt_taskstat_read(struct smp_streamer *ctxt)
|
|||
/* Iterate the list of tasks, encoding each. */
|
||||
k_thread_foreach(os_mgmt_taskstat_encode_one, (void *)&iterator_ctx);
|
||||
|
||||
if (!iterator_ctx.ok) {
|
||||
LOG_ERR("Task iterator status is not OK");
|
||||
}
|
||||
|
||||
if (!iterator_ctx.ok ||
|
||||
!zcbor_map_end_encode(zse, CONFIG_MCUMGR_GRP_OS_TASKSTAT_MAX_NUM_THREADS)) {
|
||||
return MGMT_ERR_EMSGSIZE;
|
||||
|
|
|
@ -50,4 +50,8 @@ config MCUMGR_GRP_SHELL_LEGACY_RC_RETURN_CODE
|
|||
shell command exit code, and rc will be used for SMP processing
|
||||
error codes.
|
||||
|
||||
module = MCUMGR_GRP_SHELL
|
||||
module-str = mcumgr_grp_shell
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
endif # MCUMGR_GRP_SHELL
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <zephyr/sys/util.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/shell/shell_dummy.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
|
@ -17,6 +18,8 @@
|
|||
#include <zcbor_encode.h>
|
||||
#include <zcbor_decode.h>
|
||||
|
||||
LOG_MODULE_REGISTER(mcumgr_shell_grp, CONFIG_MCUMGR_GRP_SHELL_LOG_LEVEL);
|
||||
|
||||
static int
|
||||
shell_exec(const char *line)
|
||||
{
|
||||
|
@ -101,6 +104,7 @@ shell_mgmt_exec(struct smp_streamer *ctxt)
|
|||
/* Failed to compose command line? */
|
||||
if (len == 0) {
|
||||
/* We do not bother to close decoder */
|
||||
LOG_ERR("Failed to compose command line");
|
||||
return MGMT_ERR_EINVAL;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ menuconfig MCUMGR_GRP_STAT
|
|||
help
|
||||
Enables mcumgr handlers for statistics management.
|
||||
|
||||
if MCUMGR_GRP_STAT
|
||||
|
||||
config MCUMGR_GRP_STAT_MAX_NAME_LEN
|
||||
int "Maximum stat group name length"
|
||||
default 32
|
||||
|
@ -28,3 +30,9 @@ config MCUMGR_GRP_STAT_MAX_NAME_LEN
|
|||
A buffer of this size gets allocated on the stack during handling of all
|
||||
stat read commands. If a stat group's name exceeds this limit, it will
|
||||
be impossible to retrieve its values with a stat show command.
|
||||
|
||||
module = MCUMGR_GRP_STAT
|
||||
module-str = mcumgr_grp_stat
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
endif # MCUMGR_GRP_STAT
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <zephyr/sys/util.h>
|
||||
#include <zephyr/stats/stats.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -18,6 +19,8 @@
|
|||
#include <zephyr/mgmt/mcumgr/smp/smp.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/stat_mgmt/stat_mgmt.h>
|
||||
|
||||
LOG_MODULE_REGISTER(mcumgr_stat_grp, CONFIG_MCUMGR_GRP_STAT_LOG_LEVEL);
|
||||
|
||||
static struct mgmt_handler stat_mgmt_handlers[];
|
||||
|
||||
typedef int stat_mgmt_foreach_entry_fn(zcbor_state_t *zse, struct stat_mgmt_entry *entry);
|
||||
|
@ -153,6 +156,7 @@ stat_mgmt_show(struct smp_streamer *ctxt)
|
|||
stat_name[value.len] = '\0';
|
||||
|
||||
if (stat_mgmt_count(stat_name, &counter) != 0) {
|
||||
LOG_ERR("Invalid stat name: %s", stat_name);
|
||||
return MGMT_ERR_EUNKNOWN;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,8 @@ config MCUMGR_GRP_ZBASIC_STORAGE_ERASE
|
|||
help
|
||||
Enables command that allows to erase storage partition.
|
||||
|
||||
module=MCUMGR_GRP_ZBASIC
|
||||
module-dep=LOG
|
||||
module-str=mcumgr_grp_zbasic
|
||||
module = MCUMGR_GRP_ZBASIC
|
||||
module-str = mcumgr_grp_zbasic
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
||||
endif
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
|
||||
#include <zephyr/mgmt/mcumgr/grp/zephyr/zephyr_basic.h>
|
||||
|
||||
LOG_MODULE_REGISTER(mcumgr_zephyr_grp);
|
||||
LOG_MODULE_REGISTER(mcumgr_zbasic_grp, CONFIG_MCUMGR_GRP_ZBASIC_LOG_LEVEL);
|
||||
|
||||
#define ERASE_TARGET storage_partition
|
||||
#define ERASE_TARGET_ID FIXED_PARTITION_ID(ERASE_TARGET)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue