Skip to content

Commit 5c6efa0

Browse files
nashifgalak
authored andcommitted
flash_map: add shell interface
Add shell for flash_map currently supporting listing the configurated flash_map for a device. Signed-off-by: Anas Nashif <[email protected]>
1 parent 1e5d02f commit 5c6efa0

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

subsys/storage/flash_map/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
zephyr_sources(flash_map.c)
44
zephyr_sources_ifndef(CONFIG_FLASH_MAP_CUSTOM flash_map_default.c)
5+
zephyr_sources_ifdef(CONFIG_FLASH_MAP_SHELL flash_map_shell.c)
56

subsys/storage/flash_map/Kconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ menuconfig FLASH_MAP
1515
help
1616
Enable support of flash map abstraction.
1717

18+
if FLASH_MAP
19+
20+
config FLASH_MAP_SHELL
21+
bool "Enable flash map shell interface"
22+
depends on SHELL
23+
help
24+
This enables shell commands to list and test flash maps.
25+
1826
config FLASH_MAP_CUSTOM
1927
bool "Custom flash map description"
20-
depends on FLASH_MAP
2128
help
2229
This option enables custom flash map description.
2330
User must provide such a description in place of default on
2431
if had enabled this option.
32+
33+
endif
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2019 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <shell/shell.h>
8+
#include <init.h>
9+
#include <string.h>
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
#include <ctype.h>
13+
#include <flash_map.h>
14+
#include <logging/log.h>
15+
16+
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
17+
18+
LOG_MODULE_REGISTER(flash_map_shell);
19+
20+
extern const struct flash_area *flash_map;
21+
22+
static void fa_cb(const struct flash_area *fa, void *user_data)
23+
{
24+
struct shell *shell = user_data;
25+
26+
shell_print(shell, "%-4d %-8d %-20s 0x%-10x 0x%-12x",
27+
fa->fa_id, fa->fa_device_id, fa->fa_dev_name,
28+
fa->fa_off, fa->fa_size);
29+
}
30+
31+
static int cmd_flash_map_list(const struct shell *shell, size_t argc,
32+
char **argv)
33+
{
34+
shell_print(shell, "ID | Device | Device Name"
35+
" | Offset | Size");
36+
shell_print(shell, "-------------------------"
37+
"------------------------------");
38+
flash_area_foreach(fa_cb, (struct shell *)shell);
39+
return 0;
40+
}
41+
42+
SHELL_STATIC_SUBCMD_SET_CREATE(sub_flash_map,
43+
/* Alphabetically sorted. */
44+
SHELL_CMD(list, NULL, "List flash areas", cmd_flash_map_list),
45+
SHELL_SUBCMD_SET_END /* Array terminated. */
46+
);
47+
48+
SHELL_CMD_REGISTER(flash_map, &sub_flash_map, "Flash map commands", NULL);

tests/boards/board_shell/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ CONFIG_GPIO=y
1515
CONFIG_FLASH=y
1616
CONFIG_FLASH_SHELL=y
1717
CONFIG_FLASH_PAGE_LAYOUT=y
18+
CONFIG_FLASH_MAP=y
19+
CONFIG_FLASH_MAP_SHELL=y
20+

0 commit comments

Comments
 (0)