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: Dominik Ermel <dominik.ermel@nordicsemi.no>
diff --git a/boot/zephyr/boot_serial_extensions.c b/boot/zephyr/boot_serial_extensions.c
index 9983f62..1fd9bdf 100644
--- a/boot/zephyr/boot_serial_extensions.c
+++ b/boot/zephyr/boot_serial_extensions.c
@@ -20,26 +20,36 @@
 int bs_peruser_system_specific(const struct nmgr_hdr *hdr, const char *buffer,
                                int len, cbor_state_t *cs)
 {
-    const struct flash_area *fa;
-    int rc = flash_area_open(FLASH_AREA_ID(storage), &fa);
+    int mgmt_rc = MGMT_ERR_ENOTSUP;
+    int rc = -ENOTSUP;
 
-    if (rc < 0) {
-        LOG_ERR("failed to open flash area");
-    } else {
-	rc = flash_area_erase(fa, 0, FLASH_AREA_SIZE(storage));
-	if (rc < 0) {
-		LOG_ERR("failed to erase flash area");
-	}
-	flash_area_close(fa);
+    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;
+
+        rc = flash_area_open(FLASH_AREA_ID(storage), &fa);
+
+        if (rc < 0) {
+            LOG_ERR("failed to open flash area");
+        } else {
+            rc = flash_area_erase(fa, 0, FLASH_AREA_SIZE(storage));
+            if (rc < 0) {
+                LOG_ERR("failed to erase flash area");
+            }
+            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;