blob: 9983f62c5d45b9edde802369fae8f445055cee71 [file] [log] [blame]
Dominik Ermel3d51e432021-06-25 17:29:50 +00001/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#include <zephyr.h>
8#include <drivers/flash.h>
9#include <mgmt/mcumgr/zephyr_groups.h>
10
11#include <flash_map_backend/flash_map_backend.h>
12#include <sysflash/sysflash.h>
13
14#include "bootutil/bootutil_log.h"
15#include "../boot_serial/src/boot_serial_priv.h"
16#include "../boot_serial/src/cbor_encode.h"
17
18MCUBOOT_LOG_MODULE_DECLARE(mcuboot);
19
20int bs_peruser_system_specific(const struct nmgr_hdr *hdr, const char *buffer,
21 int len, cbor_state_t *cs)
22{
23 const struct flash_area *fa;
24 int rc = flash_area_open(FLASH_AREA_ID(storage), &fa);
25
26 if (rc < 0) {
27 LOG_ERR("failed to open flash area");
28 } else {
29 rc = flash_area_erase(fa, 0, FLASH_AREA_SIZE(storage));
30 if (rc < 0) {
31 LOG_ERR("failed to erase flash area");
32 }
33 flash_area_close(fa);
34 }
35
36 map_start_encode(cs, 10);
37 tstrx_put(cs, "rc");
38 if (rc != 0) {
39 uintx32_put(cs, MGMT_ERR_EUNKNOWN);
40 } else {
41 uintx32_put(cs, 0);
42 }
43 map_end_encode(cs, 10);
44
45 return rc;
46}