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 <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2019-02-10 11:45:38 -05:00 committed by Kumar Gala
commit 5c6efa011a
4 changed files with 62 additions and 1 deletions

View file

@ -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)

View file

@ -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

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2019 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <shell/shell.h>
#include <init.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <flash_map.h>
#include <logging/log.h>
#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);