Commit 97b4c795 authored by Dominik Ermel's avatar Dominik Ermel Committed by Andrzej Puzdrowski
Browse files

zephyr: Add processing of PERUSER mgmt group for serial recovery



The commit adds Zephyr specific function for processing commands
from PERUSER and above groups; current addition is command
that allows to erase storage partition.

Signed-off-by: default avatarDominik Ermel <dominik.ermel@nordicsemi.no>
parent 3d51e430
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ zephyr_library_sources(
  flash_map_extended.c
  os.c
  keys.c
  boot_serial_extensions.c
  )

if(NOT DEFINED CONFIG_FLASH_PAGE_LAYOUT)
+1 −1
Original line number Diff line number Diff line
@@ -553,7 +553,7 @@ config RECOVERY_UART_DEV_NAME
	  serial recovery.

config ENABLE_MGMT_PERUSER
	bool "Enables system specific mcumgr commands"
	bool "Enable system specific mcumgr commands"
	depends on BOOT_SERIAL_UART
	help
	  The option enables processing of system specific mcumgr commands;
+26 −16
Original line number Diff line number Diff line
@@ -20,8 +20,16 @@ MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
int bs_peruser_system_specific(const struct nmgr_hdr *hdr, const char *buffer,
                               int len, cbor_state_t *cs)
{
    int mgmt_rc = MGMT_ERR_ENOTSUP;
    int rc = -ENOTSUP;

    if (hdr->nh_group == ZEPHYR_MGMT_GRP_BASE &&
        hdr->nh_id == ZEPHYR_MGMT_GRP_BASIC_CMD_ERASE_STORAGE &&
        hdr->nh_op == NMGR_OP_WRITE) {

        const struct flash_area *fa;
    int rc = flash_area_open(FLASH_AREA_ID(storage), &fa);

        rc = flash_area_open(FLASH_AREA_ID(storage), &fa);

        if (rc < 0) {
            LOG_ERR("failed to open flash area");
@@ -32,14 +40,16 @@ int bs_peruser_system_specific(const struct nmgr_hdr *hdr, const char *buffer,
            }
            flash_area_close(fa);
        }
        if (rc == 0) {
            mgmt_rc = MGMT_ERR_OK;
        } else {
            mgmt_rc = MGMT_ERR_EUNKNOWN;
        }
    }

    map_start_encode(cs, 10);
    tstrx_put(cs, "rc");
    if (rc != 0) {
        uintx32_put(cs, MGMT_ERR_EUNKNOWN);
    } else {
        uintx32_put(cs, 0);
    }
    uintx32_put(cs, mgmt_rc);
    map_end_encode(cs, 10);

    return rc;
+6 −0
Original line number Diff line number Diff line
@@ -145,6 +145,12 @@
#define MCUBOOT_FIH_PROFILE_HIGH
#endif

#ifdef CONFIG_ENABLE_MGMT_PERUSER
#define MCUBOOT_PERUSER_MGMT_GROUP_ENABLED 1
#else
#define MCUBOOT_PERUSER_MGMT_GROUP_ENABLED 0
#endif

/*
 * Enabling this option uses newer flash map APIs. This saves RAM and
 * avoids deprecated API usage.