From patchwork Thu Dec 28 20:14:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 853547 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="EiorPK37"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z71H41Hc2z9sNx for ; Fri, 29 Dec 2017 07:17:35 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 6E525C21DB0; Thu, 28 Dec 2017 20:15:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 646FEC21DE4; Thu, 28 Dec 2017 20:14:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E5E3BC21CB1; Thu, 28 Dec 2017 20:14:38 +0000 (UTC) Received: from mail-it0-f67.google.com (mail-it0-f67.google.com [209.85.214.67]) by lists.denx.de (Postfix) with ESMTPS id 40596C21DBB for ; Thu, 28 Dec 2017 20:14:34 +0000 (UTC) Received: by mail-it0-f67.google.com with SMTP id b5so29217102itc.3 for ; Thu, 28 Dec 2017 12:14:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=5r6p/Jk0Q4niF5okb+YZ3vMjVNIO1LIy/qD4tfy8peM=; b=EiorPK37n3acH7qf6WJBmMe6qtZlU+UJpkHYSyYAp/V4aeG5TO0dEhXEOYNIqLle04 Han7IZZzqd/xb9Y/dBZIGsQ9dUE8W9+LzAchBH1LyftBT5xGpG1gqxKLjfpkWg0PJ9ZH 0KglMAlbzG+z3QAda/YXLLp28L4cAkLMd2VDMZk8Q7GQhWI9+rLvtt8f2ha/k0LgTssg k2XhLJ6raR2XlIaPCAddCa5EE5VDGqYe86AzeIQ+GesvQvOxY1Doo3Ba0UBbOPU4ENaL J1HmkTQ7ylLU3kp6Y4TbFPaIgBRegUByuIBXwmtLKE7P07ZONMSztkIvKVoJhykkpvR0 H3BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=5r6p/Jk0Q4niF5okb+YZ3vMjVNIO1LIy/qD4tfy8peM=; b=tRI/BP1hFPowKH9T77N2RArEl14NrZggeqZ3zSSnILNzHOMgC7piimM8lbdDpNKc07 tDlu5OsH42Z8Yosm8ZWqGmt5dwm/3YPiOZg5hRD70oiabEFT3JoOZok5AQ4UBkgcB8Fp U6jlHiJBXJ1LmoBWsD60SQs5XSp0cVXfizFqPQsWUM3xWF00f6ShlafUpemyXLw/48lD IJHGNrx4UbSHmB01mpcMAKeYn58UggJfRhpRjMJwC9Ua5lVbMPbyP6E379GbfVE/bIJ/ jxtB8FO4y4HVRtSKJem4xlaXi4IWs+CEqiyWtr330iz6pY4TV5DsxVkbub6iGI0wfma6 RABQ== X-Gm-Message-State: AKGB3mLguyur2CwIY+6BOozWkjZY5dPaxp6RsWW0kvjFZksz5huKA/ks yb8eV48Oc6mkrgP4wXxhkE/yLg== X-Google-Smtp-Source: ACJfBosbx5vEDOH4S6dYXMLXIfvxk8cJdIHtEgNiSoBCrYhYEWqxXTgiHvpz8nbQnD9d2sCsbiaWZg== X-Received: by 10.36.76.7 with SMTP id a7mr43554563itb.35.1514492072693; Thu, 28 Dec 2017 12:14:32 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:1dfd:6d2e:1964:8aa1]) by smtp.gmail.com with ESMTPSA id g143sm2899043iog.34.2017.12.28.12.14.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:14:28 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 2CDCE13FEAF; Thu, 28 Dec 2017 13:14:28 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 28 Dec 2017 13:14:16 -0700 Message-Id: <20171228201423.128338-3-sjg@chromium.org> X-Mailer: git-send-email 2.15.1.620.gb9897f4670-goog In-Reply-To: <20171228201423.128338-1-sjg@chromium.org> References: <20171228201423.128338-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 2/9] log: Add functions to convert IDs to/from names X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Category and level both use an enum for their ID values. Add functions to convert these IDs to strings and vice versa. This will allow the log to output the strings instead of the (inscrutable) values. At the same time, add a new 'driver-model' category, to cover core driver-model functions and fix an incorrect value for LOGL_MAX. Tests will be added with the new 'log' subcommands. Signed-off-by: Simon Glass --- common/log.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/log.h | 39 ++++++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/common/log.c b/common/log.c index 45e46dd520..5761a2ce76 100644 --- a/common/log.c +++ b/common/log.c @@ -10,9 +10,76 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; +static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { + "none", + "arch", + "board", + "core", + "driver-model", + "device-tree", +}; + +static const char *log_level_name[LOGL_COUNT] = { + "EMERG", + "ALERT", + "CRIT", + "ERR", + "WARNING", + "NOTICE", + "INFO", + "DEBUG", + "CONTENT", + "IO", +}; + +const char *log_get_cat_name(enum log_category_t cat) +{ + if (cat > LOGC_COUNT) + return "invalid"; + if (log_uc_cat(cat) >= LOGC_NONE) + return log_cat_name[cat - LOGC_NONE]; + + return uclass_get_name(log_uc_cat(cat)); +} + +enum log_category_t log_get_cat_by_name(const char *name) +{ + enum uclass_id id; + int i; + + for (i = LOGC_NONE; i < LOGC_COUNT; i++) + if (!strcmp(name, log_cat_name[i - LOGC_NONE])) + return i; + id = uclass_get_by_name(name); + if (id != UCLASS_INVALID) + return (enum log_category_t)id; + + return LOGC_NONE; +} + +const char *log_get_level_name(enum log_level_t level) +{ + if (level >= LOGL_COUNT) + return "INVALID"; + return log_level_name[level]; +} + +enum log_level_t log_get_level_by_name(const char *name) +{ + int i; + + for (i = 0; i < LOGL_COUNT; i++) { + if (!strcasecmp(log_level_name[i], name)) + return i; + } + + return LOGL_NONE; +} + static struct log_device *log_device_find_by_name(const char *drv_name) { struct log_device *ldev; diff --git a/include/log.h b/include/log.h index 8083b64831..5133213acf 100644 --- a/include/log.h +++ b/include/log.h @@ -27,8 +27,10 @@ enum log_level_t { LOGL_DEBUG_IO, /* Debug message showing hardware I/O access */ LOGL_COUNT, + LOGL_NONE, + LOGL_FIRST = LOGL_EMERG, - LOGL_MAX = LOGL_DEBUG, + LOGL_MAX = LOGL_DEBUG_IO, }; /** @@ -42,7 +44,8 @@ enum log_category_t { LOGC_ARCH, LOGC_BOARD, LOGC_CORE, - LOGC_DT, + LOGC_DM, /* Core driver-model */ + LOGC_DT, /* Device-tree */ LOGC_COUNT, LOGC_END, @@ -256,6 +259,38 @@ struct log_filter { #define LOG_DRIVER(_name) \ ll_entry_declare(struct log_driver, _name, log_driver) +/** + * 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) + */ +const char *log_get_cat_name(enum log_category_t cat); + +/** + * log_get_cat_by_name() - Look up a category by name + * + * @name: Name to look up + * @return category ID, or LOGC_NONE if not found + */ +enum log_category_t log_get_cat_by_name(const char *name); + +/** + * log_get_level_name() - Get the name of a log level + * + * @level: Log level to look up + * @return log level name (in ALL CAPS) + */ +const char *log_get_level_name(enum log_level_t level); + +/** + * log_get_level_by_name() - Look up a log level by name + * + * @name: Name to look up + * @return log level ID, or LOGL_NONE if not found + */ +enum log_level_t log_get_level_by_name(const char *name); + /* Handle the 'log test' command */ int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);