diff --git a/subsys/storage/flash_map/CMakeLists.txt b/subsys/storage/flash_map/CMakeLists.txt index ff71e8768b8..715410c07e4 100644 --- a/subsys/storage/flash_map/CMakeLists.txt +++ b/subsys/storage/flash_map/CMakeLists.txt @@ -2,4 +2,5 @@ zephyr_sources(flash_map.c) zephyr_sources_ifndef(CONFIG_FLASH_MAP_CUSTOM flash_map_default.c) +zephyr_sources_ifdef(CONFIG_FLASH_MAP_SHELL flash_map_shell.c) diff --git a/subsys/storage/flash_map/Kconfig b/subsys/storage/flash_map/Kconfig index c339f9d3228..6295a9d4c85 100644 --- a/subsys/storage/flash_map/Kconfig +++ b/subsys/storage/flash_map/Kconfig @@ -15,10 +15,19 @@ menuconfig FLASH_MAP help Enable support of flash map abstraction. +if FLASH_MAP + +config FLASH_MAP_SHELL + bool "Enable flash map shell interface" + depends on SHELL + help + This enables shell commands to list and test flash maps. + config FLASH_MAP_CUSTOM bool "Custom flash map description" - depends on FLASH_MAP help This option enables custom flash map description. User must provide such a description in place of default on if had enabled this option. + +endif diff --git a/subsys/storage/flash_map/flash_map_shell.c b/subsys/storage/flash_map/flash_map_shell.c new file mode 100644 index 00000000000..27b83801bd0 --- /dev/null +++ b/subsys/storage/flash_map/flash_map_shell.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL + +LOG_MODULE_REGISTER(flash_map_shell); + +extern const struct flash_area *flash_map; + +static void fa_cb(const struct flash_area *fa, void *user_data) +{ + struct shell *shell = user_data; + + shell_print(shell, "%-4d %-8d %-20s 0x%-10x 0x%-12x", + fa->fa_id, fa->fa_device_id, fa->fa_dev_name, + fa->fa_off, fa->fa_size); +} + +static int cmd_flash_map_list(const struct shell *shell, size_t argc, + char **argv) +{ + shell_print(shell, "ID | Device | Device Name" + " | Offset | Size"); + shell_print(shell, "-------------------------" + "------------------------------"); + flash_area_foreach(fa_cb, (struct shell *)shell); + return 0; +} + +SHELL_STATIC_SUBCMD_SET_CREATE(sub_flash_map, + /* Alphabetically sorted. */ + SHELL_CMD(list, NULL, "List flash areas", cmd_flash_map_list), + SHELL_SUBCMD_SET_END /* Array terminated. */ +); + +SHELL_CMD_REGISTER(flash_map, &sub_flash_map, "Flash map commands", NULL); diff --git a/tests/boards/board_shell/prj.conf b/tests/boards/board_shell/prj.conf index 5719b845c44..28913fc602c 100644 --- a/tests/boards/board_shell/prj.conf +++ b/tests/boards/board_shell/prj.conf @@ -15,3 +15,6 @@ CONFIG_GPIO=y CONFIG_FLASH=y CONFIG_FLASH_SHELL=y CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_FLASH_MAP=y +CONFIG_FLASH_MAP_SHELL=y +