From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Anderson Date: Tue, 27 Oct 2020 19:55:34 -0400 Subject: [PATCH v4 15/22] cmd: log: Add commands to list categories and drivers In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-1-seanga2@gmail.com> Message-ID: <20201027235541.706077-16-seanga2@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de This allows users to query which categories and drivers are available on their system. This allows them to construct filter-add commands without (e.g.) adjusting the log format to show categories and drivers. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- (no changes since v3) Changes in v3: - Document assumption that erroneous results from log_get_cat_name begin with '<' Changes in v2: - New cmd/log.c | 35 +++++++++++++++++++++++++++++++++++ common/log.c | 1 + include/log.h | 5 +++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/cmd/log.c b/cmd/log.c index 651e50358c..8d8d8a8172 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -47,6 +47,37 @@ static int do_log_level(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } +static int do_log_categories(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + enum log_category_t cat; + const char *name; + + for (cat = LOGC_FIRST; cat < LOGC_COUNT; cat++) { + name = log_get_cat_name(cat); + /* + * Invalid category names (e.g. or ) begin + * with '<'. + */ + if (name[0] == '<') + continue; + printf("%s\n", name); + } + + return CMD_RET_SUCCESS; +} + +static int do_log_drivers(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct log_device *ldev; + + list_for_each_entry(ldev, &gd->log_head, sibling_node) + printf("%s\n", ldev->drv->name); + + return CMD_RET_SUCCESS; +} + static int do_log_format(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -123,6 +154,8 @@ static int do_log_rec(struct cmd_tbl *cmdtp, int flag, int argc, #ifdef CONFIG_SYS_LONGHELP static char log_help_text[] = "level - get/set log level\n" + "categories - list log categories\n" + "drivers - list log drivers\n" "log format - set log output format. is a string where\n" "\teach letter indicates something that should be displayed:\n" "\tc=category, l=level, F=file, L=line number, f=function, m=msg\n" @@ -134,6 +167,8 @@ static char log_help_text[] = U_BOOT_CMD_WITH_SUBCMDS(log, "log system", log_help_text, U_BOOT_SUBCMD_MKENT(level, 2, 1, do_log_level), + U_BOOT_SUBCMD_MKENT(categories, 1, 1, do_log_categories), + U_BOOT_SUBCMD_MKENT(drivers, 1, 1, do_log_drivers), U_BOOT_SUBCMD_MKENT(format, 2, 1, do_log_format), U_BOOT_SUBCMD_MKENT(rec, 7, 1, do_log_rec), ); diff --git a/common/log.c b/common/log.c index 9a79b95a95..95ba8350c6 100644 --- a/common/log.c +++ b/common/log.c @@ -41,6 +41,7 @@ static const char *const log_level_name[LOGL_COUNT] = { "IO", }; +/* All error responses MUST begin with '<' */ const char *log_get_cat_name(enum log_category_t cat) { const char *name; diff --git a/include/log.h b/include/log.h index ec2d6fdb01..7a839d55aa 100644 --- a/include/log.h +++ b/include/log.h @@ -409,8 +409,9 @@ struct log_filter { * log_get_cat_name() - Get the name of a category * * @cat: Category to look up - * @return category name (which may be a uclass driver name) if found, or - * "" if invalid, or "" if not found + * @return: category name (which may be a uclass driver name) if found, or + * "" if invalid, or "" if not found. All error + * responses begin with '<'. */ const char *log_get_cat_name(enum log_category_t cat); -- 2.28.0