-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add function to erase all settings
Added a zmk_settings_erase() function to clear all saved settings. This does not go through Zephyr's settings subsystem, but instead directly clears the data from the setting storage backend, so a reboot is needed for it to take effect.
- Loading branch information
1 parent
78fa1e7
commit d6f6fe7
Showing
7 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2023 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
/** | ||
* Erases all saved settings. | ||
* | ||
* @note This does not automatically update any code using Zephyr's settings | ||
* subsystem. This should typically be followed by a call to sys_reboot(). | ||
*/ | ||
int zmk_settings_erase(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) 2023 The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
target_sources_ifdef(CONFIG_SETTINGS_NONE app PRIVATE reset_settings_none.c) | ||
target_sources_ifdef(CONFIG_SETTINGS_FCB app PRIVATE reset_settings_fcb.c) | ||
target_sources_ifdef(CONFIG_SETTINGS_FILE app PRIVATE reset_settings_file.c) | ||
target_sources_ifdef(CONFIG_SETTINGS_NVS app PRIVATE reset_settings_nvs.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2023 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <zmk/settings.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
int zmk_settings_erase(void) { | ||
LOG_ERR("Settings reset is not implemented for deprecated FCB backend."); | ||
return -ENOSYS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2023 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <zephyr/fs/fs.h> | ||
|
||
#include <zmk/settings.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
int zmk_settings_erase(void) { | ||
LOG_INF("Erasing settings file"); | ||
|
||
int rc = fs_unlink(CONFIG_SETTINGS_FS_FILE); | ||
if (rc) { | ||
LOG_ERR("Failed to unlink '%s': %d", CONFIG_SETTINGS_FS_FILE, rc); | ||
} | ||
|
||
return rc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (c) 2023 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <zmk/settings.h> | ||
|
||
int zmk_settings_erase(void) { | ||
// No storage backend; nothing to do | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2023 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <zephyr/device.h> | ||
#include <zephyr/devicetree.h> | ||
#include <zephyr/storage/flash_map.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
// SETTINGS_PARTITION must match settings_nvs.c | ||
#if DT_HAS_CHOSEN(zephyr_settings_partition) | ||
#define SETTINGS_PARTITION DT_FIXED_PARTITION_ID(DT_CHOSEN(zephyr_settings_partition)) | ||
#else | ||
#define SETTINGS_PARTITION FIXED_PARTITION_ID(storage_partition) | ||
#endif | ||
|
||
int zmk_settings_erase(void) { | ||
LOG_INF("Erasing settings flash partition"); | ||
|
||
const struct flash_area *fa; | ||
int rc = flash_area_open(SETTINGS_PARTITION, &fa); | ||
if (rc) { | ||
LOG_ERR("Failed to open settings flash: %d", rc); | ||
return rc; | ||
} | ||
|
||
rc = flash_area_erase(fa, 0, fa->fa_size); | ||
if (rc) { | ||
LOG_ERR("Failed to erase settings flash: %d", rc); | ||
} | ||
|
||
flash_area_close(fa); | ||
|
||
return rc; | ||
} |