From patchwork Thu Dec 28 20:14:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 853546 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="EToc6NZE"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z71FS1swJz9sNx for ; Fri, 29 Dec 2017 07:16:12 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id E9923C21DF1; Thu, 28 Dec 2017 20:14:52 +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_H2, 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 47309C21DB0; Thu, 28 Dec 2017 20:14:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D9C8DC21C34; Thu, 28 Dec 2017 20:14:30 +0000 (UTC) Received: from mail-io0-f193.google.com (mail-io0-f193.google.com [209.85.223.193]) by lists.denx.de (Postfix) with ESMTPS id 448A2C21C8F for ; Thu, 28 Dec 2017 20:14:30 +0000 (UTC) Received: by mail-io0-f193.google.com with SMTP id i143so19240734ioa.3 for ; Thu, 28 Dec 2017 12:14:30 -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=13I87py1rqaYzEE/gKlEJOtE8wV+OchjENnf5oSLBPA=; b=EToc6NZEEHJl9SSTLh57VJKsQzb6pFyTr9VzbO0KWYmXveBgBRniwTGtgjyhHaG5hn aa81cnShnZeAll+Jes0xGY/CKa6F6sqPnUA34YgTPRyN4banBkJ8BEyBhTIFNz47t30L DKg3nha818Jw26zDmYXO8yhl/DDNgv/tz2f3z9dkxHfhXR0GFmesygWhc10TtKSVFXvM F6ihDVBtvgU95NWvLKWkOMqwZn5rLIq1RiqNYwFYx143RZ2DWoFWqGGL8SHlkkX6AOmI fhVC95VahhyCfi95yfcpqkv+pjc+rkZUcH9WEBb3wZ0g8HTTRYRDAyJnek6Tt7cO+Ukv Sg8A== 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=13I87py1rqaYzEE/gKlEJOtE8wV+OchjENnf5oSLBPA=; b=JjCzn6M+YDGI0c7IFJmngOkt8od72Mxtm7Y6JXJvUmupDVTdPMO8VVXpHMhPNB+psC v1B27oh0g12momyBgxitXlbwoqV7+zHBOMLyYqSIFFC1ODzImzaxEiFeMlhofnyRO9Hs 9FRMKa4TDQlnpREJyD7FMdA3OBLhyMkRmJ9mBMI58DzzhgwV551/TfWyhL9N5rLsywK4 CEsP7mtkbR1EO1zY6SBvLGmY/jUkfmuejM/8dQPZ+cw/GtlZNMNo/oTCXze4HC+FufAK VC4M/MxvpcYLYMx8NWUEwWCxfSFV+zpG8nY5UjoK2doWLF+qb5A5NUNTDqXprSe8xIup 5u3g== X-Gm-Message-State: AKGB3mIrcpCkI0jl2LBR8yvhDECFhul92I00I2qUFZHl09EsKL6lah4g /FkvJJvg3wrIoQXTvA9tqvgX1w== X-Google-Smtp-Source: ACJfBovx664VPslTTElShb2AJdQLs2oAJ7pti1ez2fP/gXoHkjm7OxSBBIVq7ZBVKEOYROr8iDtvlQ== X-Received: by 10.107.157.82 with SMTP id g79mr42347550ioe.296.1514492068660; Thu, 28 Dec 2017 12:14:28 -0800 (PST) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id z130sm13278990ioz.16.2017.12.28.12.14.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:14:27 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 429B31414D5; Thu, 28 Dec 2017 13:14:27 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 28 Dec 2017 13:14:15 -0700 Message-Id: <20171228201423.128338-2-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 1/9] dm: core: Add a function to look up a uclass by name 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" Each uclass has a driver name which we can use to look up the uclass. This is useful for logging, where the uclass ID is used as the category. Add a function to handle this, as well as a test. Signed-off-by: Simon Glass --- drivers/core/uclass.c | 14 ++++++++++++++ include/dm/uclass.h | 8 ++++++++ test/dm/core.c | 9 +++++++++ 3 files changed, 31 insertions(+) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index f5e4067922..1aedaa08f0 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -158,6 +158,20 @@ const char *uclass_get_name(enum uclass_id id) return uc->uc_drv->name; } +enum uclass_id uclass_get_by_name(const char *name) +{ + int i; + + for (i = 0; i < UCLASS_COUNT; i++) { + struct uclass_driver *uc_drv = lists_uclass_lookup(i); + + if (uc_drv && !strcmp(uc_drv->name, name)) + return i; + } + + return UCLASS_INVALID; +} + int uclass_find_device(enum uclass_id id, int index, struct udevice **devp) { struct uclass *uc; diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 18188497c2..88f6ef4ed5 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -127,6 +127,14 @@ int uclass_get(enum uclass_id key, struct uclass **ucp); */ const char *uclass_get_name(enum uclass_id id); +/** + * uclass_get_by_name() - Look up a uclass by its driver name + * + * @name: Name to look up + * @returns the associated uclass ID, or UCLASS_INVALID if not found + */ +enum uclass_id uclass_get_by_name(const char *name); + /** * uclass_get_device() - Get a uclass device based on an ID and index * diff --git a/test/dm/core.c b/test/dm/core.c index 50ee41b9e2..052bf8fffb 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -862,3 +862,12 @@ static int dm_test_device_get_uclass_id(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_device_get_uclass_id, DM_TESTF_SCAN_PDATA); + +static int dm_test_uclass_names(struct unit_test_state *uts) +{ + ut_asserteq_str("test", uclass_get_name(UCLASS_TEST)); + ut_asserteq(UCLASS_TEST, uclass_get_by_name("test")); + + return 0; +} +DM_TEST(dm_test_uclass_names, DM_TESTF_SCAN_PDATA); 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[]); From patchwork Thu Dec 28 20:14:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 853550 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="dyoLg3rP"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z71J34fmZz9sNx for ; Fri, 29 Dec 2017 07:18:27 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id E9EB9C21DB0; Thu, 28 Dec 2017 20:15:12 +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 13073C21DE6; Thu, 28 Dec 2017 20:14:46 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7C852C21CB1; Thu, 28 Dec 2017 20:14:38 +0000 (UTC) Received: from mail-it0-f65.google.com (mail-it0-f65.google.com [209.85.214.65]) by lists.denx.de (Postfix) with ESMTPS id E1968C21DE5 for ; Thu, 28 Dec 2017 20:14:34 +0000 (UTC) Received: by mail-it0-f65.google.com with SMTP id d16so29762698itj.1 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=W34mZS3jqDLNDQmuevsJHSVRBDJZwLBjTIauh7ArKKU=; b=dyoLg3rPdzaoKKzRsb+dpHoe4ICpdtz0lW+1idSO97mxxAEvfADvJktRtVLB00eP0z 4eL0bVojNmZTp4akYbeH2tkSnOV1s83S/53oIBL2URIPeC5gSMDMqztJfZ8aQEnSDwZ9 IrUxz0BvfSxo6JGq0QtXzwL2qbfIfgXGIafov9Sp6vCfVRpejfwwBtcHWlE9DpPV47OS m9s763z74NnfsMjXXTbh+d3dIkDN1hCAZeytn+XfCTawqWGOeU9D3/qv91PmT2AmyKZ2 K7QsNdhTKHMyQVOWE+2FFpgO+RTD9F08ZYULmAEQ0WfnTzXQelZehxX07n71RlQd1K3J NWYw== 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=W34mZS3jqDLNDQmuevsJHSVRBDJZwLBjTIauh7ArKKU=; b=L+ZDFpDhRBlyWAxtQuQfw0vNO+BBjNzNZUm/ZHXMHytRov/hFCioelVXR4bKCFl/T/ bjE6mljHZCAr/MBp208ezNi1olUyHVsLzkoBCF5CHcJuT2CgXPJhhXOxe5g2oqqRnywx TAmBS5EziB66tHLQkDMFqpf/uQfaIiFTj7oGnCRMjN3g2IvyNJGlPCwOOhRJK5mBnN2c /zYt+wa5OeeNU/qyVLE6r56htskWFW1fx3W1oup2Ba+nF7c6f+/qI229B3nBEoj9tjjl 1h8c8TkfROaFj3aAtZE5wy+2xHYokj0RykBZrlep1O/AuRzo9ydeEVF68zqyDliGHkTD LWIw== X-Gm-Message-State: AKGB3mJY13xY8gUrivcyI2G1SGucgxPbzeV3WsLueJhr/X8bVUMn/dqm pyNJqyllIfkOTkpDLE+I+pdelg== X-Google-Smtp-Source: ACJfBosclONCsAaIDcFr44FEXmwFlPMArViEgnBe2JqT4wKCIKSrouM/jSRJbNBPrJeLQ6disWz2ig== X-Received: by 10.36.120.11 with SMTP id p11mr42748663itc.10.1514492073454; Thu, 28 Dec 2017 12:14:33 -0800 (PST) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id 126sm18961096iov.21.2017.12.28.12.14.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:14:32 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 425471414D5; Thu, 28 Dec 2017 13:14:29 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 28 Dec 2017 13:14:17 -0700 Message-Id: <20171228201423.128338-4-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 , Andy Yan Subject: [U-Boot] [PATCH 3/9] log: Add control over log formatting 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" It is useful to be able to control the output format of log records on the console. As a starting point, add definitions for controlling which elements of the log record are displayed. Use function and message as the default, since these are the most useful fields. Signed-off-by: Simon Glass --- common/log.c | 1 + include/asm-generic/global_data.h | 1 + include/log.h | 14 ++++++++++++++ 3 files changed, 16 insertions(+) diff --git a/common/log.c b/common/log.c index 5761a2ce76..7559d74e90 100644 --- a/common/log.c +++ b/common/log.c @@ -307,6 +307,7 @@ int log_init(void) } gd->flags |= GD_FLG_LOG_READY; gd->default_log_level = LOGL_INFO; + gd->log_fmt = LOGF_DEFAULT; return 0; } diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 73e036d6fd..f1c21dfd20 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -118,6 +118,7 @@ typedef struct global_data { int log_drop_count; /* Number of dropped log messages */ int default_log_level; /* For devices with no filters */ struct list_head log_head; /* List of struct log_device */ + int log_fmt; /* Mask containing log format info */ #endif } gd_t; #endif diff --git a/include/log.h b/include/log.h index 5133213acf..828919a409 100644 --- a/include/log.h +++ b/include/log.h @@ -291,6 +291,20 @@ const char *log_get_level_name(enum log_level_t level); */ enum log_level_t log_get_level_by_name(const char *name); +/* Log format flags (bit numbers) for gd->log_fmt. See log_fmt_chars */ +enum log_fmt { + LOGF_CAT = 0, + LOGF_LEVEL, + LOGF_FILE, + LOGF_LINE, + LOGF_FUNC, + LOGF_MSG, + + LOGF_COUNT, + LOGF_DEFAULT = (1 << LOGF_FUNC) | (1 << LOGF_MSG), + LOGF_ALL = 0x3f, +}; + /* Handle the 'log test' command */ int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]); From patchwork Thu Dec 28 20:14:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 853552 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="hQ4WiK44"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z71K45YNsz9sRg for ; Fri, 29 Dec 2017 07:19:20 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5CAD5C21DB2; Thu, 28 Dec 2017 20:16:24 +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_H2, 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 BFD80C21DF4; Thu, 28 Dec 2017 20:15:03 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 03690C21E0A; Thu, 28 Dec 2017 20:14:39 +0000 (UTC) Received: from mail-io0-f195.google.com (mail-io0-f195.google.com [209.85.223.195]) by lists.denx.de (Postfix) with ESMTPS id DAA5DC21DC1 for ; Thu, 28 Dec 2017 20:14:35 +0000 (UTC) Received: by mail-io0-f195.google.com with SMTP id k202so31094108ioe.10 for ; Thu, 28 Dec 2017 12:14:35 -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=UiS8HIkSeBwJ+ULRNTgL3jWZTSkuG4fn9/FAJNIol/M=; b=hQ4WiK44H7njMi6ELFF86ZP4/O+2NNAy1i99fPN3E5xqZvkxitJSDM7U5yGzPPfhLQ Ay8pHbS3Jz0vDSS+LsmeeTxW2lV1cJqW7UA2VBKxMG6GKVCIsLcEWZpkFtsLyfwhVDFw W4Lgm+WAlIJ/tXBRRZtTD53DkoOEAOZVlS/jFnzupjnf7ozQ8+FwnZjDak8iIa8vUgfn wL50ysMIqhQSnaKHbpOMvHkyIVnuB0koPha2U58THBMc8Uh3xaCsYjUurpTJ4SGtYEbO F6QjEQ6kPT9wp2lybmP0/G2YTcXbiJEzi9OgJIiYOE2vstOey5uif2oSgtpvB4wLcsax cyVA== 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=UiS8HIkSeBwJ+ULRNTgL3jWZTSkuG4fn9/FAJNIol/M=; b=rBdQM1eqZvCcwFXfDReT7BYZgYcwbm3zup8BKq7IcW1l7RUNsr2FigaQNZNzpNoDrU sFXKeYZHsLK3RuoyPDEaMqpnAzOAKqXUMXJsRJSUl9kD5lFRxKOBLTlQ0ZMPK31la+DZ oq5eayhZqzKxHW0x0ZS3ffqXWXDpw6By0ZsIP337HUMDroXfY4JAyiTlH9dAH3Vg7skk Zduot3OjnxgZLHbovqbSdMbiM5Gg29Ut+abtBUeiogwVHZgUcxT0XyjdIxWQfUtZ54NF WOi21iMczQ+eM/E9WMhcKIaoZ4widcU54h5a+02mgS85+db+Ldut86laNlCJ2J1NHPLM OmdQ== X-Gm-Message-State: AKGB3mJTUZRS2HBmSeZpGHeQBvuKr1BcCtirkrpkpw7HW42HO4EYkt8r sGAIzCJMN2X1QZZFiOPHxPCRow== X-Google-Smtp-Source: ACJfBos3L3yinPc4YZcyOUkFYqGZZKyolqX2VS4wLr+Saqb5a3npie2LXLCu/p1KqLOf8gjWM3UoCQ== X-Received: by 10.107.149.133 with SMTP id x127mr43317845iod.286.1514492074330; Thu, 28 Dec 2017 12:14:34 -0800 (PST) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id l15sm5332721iog.56.2017.12.28.12.14.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:14:32 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 86927142506; Thu, 28 Dec 2017 13:14:30 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 28 Dec 2017 13:14:18 -0700 Message-Id: <20171228201423.128338-5-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 4/9] log: Update log_console to honour the log format 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" At present this just outputs the message. Update it to output whatever the format requests. Signed-off-by: Simon Glass --- common/log_console.c | 27 ++++++++++++++++++++++++++- test/py/tests/test_log.py | 4 ++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/common/log_console.c b/common/log_console.c index 5af73bd8be..2902733078 100644 --- a/common/log_console.c +++ b/common/log_console.c @@ -10,9 +10,34 @@ #include #include +DECLARE_GLOBAL_DATA_PTR; + static int log_console_emit(struct log_device *ldev, struct log_rec *rec) { - puts(rec->msg); + int fmt = gd->log_fmt; + + /* + * The output format is designed to give someone a fighting chance of + * figuring out which field is which: + * - level is in CAPS + * - cat is lower case and ends with comma + * - file normally has a .c extension and ends with a colon + * - line is integer and ends with a - + * - function is an identifier and ends with () + * - message has a space before it unless it is on its own + */ + if (fmt & (1 << LOGF_LEVEL)) + printf("%s.", log_get_level_name(rec->level)); + if (fmt & (1 << LOGF_CAT)) + printf("%s,", log_get_cat_name(rec->cat)); + if (fmt & (1 << LOGF_FILE)) + printf("%s:", rec->file); + if (fmt & (1 << LOGF_LINE)) + printf("%d-", rec->line); + if (fmt & (1 << LOGF_FUNC)) + printf("%s()", rec->func); + if (fmt & (1 << LOGF_MSG)) + printf("%s%s", fmt != (1 << LOGF_MSG) ? " " : "", rec->msg); return 0; } diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py index fa9a25e8dc..517f415143 100644 --- a/test/py/tests/test_log.py +++ b/test/py/tests/test_log.py @@ -28,9 +28,9 @@ def test_log(u_boot_console): """ for i in range(max_level): if mask & 1: - assert 'log %d' % i == lines.next() + assert 'log_run() log %d' % i == lines.next() if mask & 3: - assert '_log %d' % i == lines.next() + assert 'func() _log %d' % i == lines.next() def run_test(testnum): """Run a particular test number (the 'log test' command) From patchwork Thu Dec 28 20:14:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 853553 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="dkNoBet3"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z71K63rj5z9sRg for ; Fri, 29 Dec 2017 07:19:22 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 2C93BC21DCE; Thu, 28 Dec 2017 20:16:41 +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 0A9B1C21DA9; Thu, 28 Dec 2017 20:15:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 053F9C21DDF; Thu, 28 Dec 2017 20:14:40 +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 88348C21DF1 for ; Thu, 28 Dec 2017 20:14:36 +0000 (UTC) Received: by mail-it0-f67.google.com with SMTP id u62so29205999ita.2 for ; Thu, 28 Dec 2017 12:14:36 -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=CVw/BZqdoE4DrMPUqAK0NKp7pr/NHvea/42bMmtheaA=; b=dkNoBet3RhLfTOsXBzSOsUX14l3/vdJqaqwg6sXMwkrrew15pBmuAN6h6tqYzjEHKt 3SP++FHcuo9CG1jWIWieLM11u88uUws3yoXQesrGOUJkMDIspQILleSfQEnTichvnU6/ NedPCFrnmOQZQ7eIcON4etLnhoNegEMKjB8ti5vSIL0AT0hIVbUYaFBTMHnJsnARonhy 4ACt4jZrWAzTLxVf6avLQOcX5j0bBaGnbmCzK6qMue1h8fGfGOc0BIx+dVdDYS0NDOwK z3O5txXh4DVykO4OPs/BY4TpYwCaF0oRP7ibw17+EpFzTLW9Qvz4FgqlkqGvqDiuCkGm yadg== 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=CVw/BZqdoE4DrMPUqAK0NKp7pr/NHvea/42bMmtheaA=; b=SHR/9ix576V+os9rcXZBwKc43aXh+IkpSCXCBwPrZ0uabLTS3DtH13nCNOKDww9dns +i+eOQ276u5zYvvOI9vEsf7F5Du2BrKj5l3igJ/F0MsVIiL4ijAXTjTJHbJqjvS/eWlE AiQhoPYkTelrH48rN3bLxeXsYhjHFcm036mGg2nSnSuFQJ/CqBZPfsPOkz8YuVWkBoqQ vTrZtlx7DgUZFfdKJa4BWQJVngWbLxotNH+ij6MZSG6KA2vKQCVGeZAyvH1GhCG3yrHk /3TRRfD1Zv0gOnRFNvvAZg+XejmLmVnbgEi7CnZykjxNc7O97ld05VkwYxySeyb/NTns jixQ== X-Gm-Message-State: AKGB3mJ7HXwDeN68KrNEBWWKZAtLuuPzCcb8mPhC7vAG4u6XUJCBPIL3 eBQaInz+SG3Xrbluav1SaqfzxQ== X-Google-Smtp-Source: ACJfBossuoeTHkQrdI+VGh71lBOCNGlnxa2SKhq08qTFv1+OqjtNk+Tn8AtVEtyUUk6tnJ6Fko43Yg== X-Received: by 10.36.225.136 with SMTP id n130mr42061267ith.146.1514492075137; Thu, 28 Dec 2017 12:14:35 -0800 (PST) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id w68sm20378144iow.18.2017.12.28.12.14.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:14:32 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id BB67C14251F; Thu, 28 Dec 2017 13:14:31 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 28 Dec 2017 13:14:19 -0700 Message-Id: <20171228201423.128338-6-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 5/9] log: Add a command to control the log output format 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" Add a 'log format' command which can display or change the log output format. This is useful for changing how much information is displayed. The ordering of the fields is fixed. Signed-off-by: Simon Glass --- cmd/log.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cmd/log.c b/cmd/log.c index abc523b497..e038bc3269 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -10,6 +10,8 @@ #include #include +static char log_fmt_chars[LOGF_COUNT] = "clFLfm"; + static int do_log_level(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -21,11 +23,48 @@ static int do_log_level(cmd_tbl_t *cmdtp, int flag, int argc, return 0; } +static int do_log_format(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + int i; + + if (argc > 1) { + const char *str = argv[1]; + + if (!strcmp(str, "default")) { + gd->log_fmt = LOGF_DEFAULT; + } else if (!strcmp(str, "all")) { + gd->log_fmt = LOGF_ALL; + } else { + gd->log_fmt = 0; + for (; *str; str++) { + char *ptr = strchr(log_fmt_chars, *str); + + if (!ptr) { + printf("Invalid log char '%c'\n", *str); + return CMD_RET_FAILURE; + } + gd->log_fmt |= 1 << (ptr - log_fmt_chars); + } + } + } else { + printf("Log format: "); + for (i = 0; i < LOGF_COUNT; i++) { + if (gd->log_fmt & (1 << i)) + printf("%c", log_fmt_chars[i]); + } + printf("\n"); + } + + return 0; +} + static cmd_tbl_t log_sub[] = { U_BOOT_CMD_MKENT(level, CONFIG_SYS_MAXARGS, 1, do_log_level, "", ""), #ifdef CONFIG_LOG_TEST U_BOOT_CMD_MKENT(test, 2, 1, do_log_test, "", ""), #endif + U_BOOT_CMD_MKENT(format, CONFIG_SYS_MAXARGS, 1, do_log_format, "", ""), }; static int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) @@ -52,6 +91,10 @@ static char log_help_text[] = #ifdef CONFIG_LOG_TEST "log test - run log tests\n" #endif + "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" + "\tor 'default', equivalent to 'fm', or 'all' for all" ; #endif From patchwork Thu Dec 28 20:14:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 853548 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="fBrUT6++"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z71HY1ck9z9sNx for ; Fri, 29 Dec 2017 07:18:01 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id EB78CC21DE5; Thu, 28 Dec 2017 20:16:06 +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_H2, 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 A58D9C21D9F; Thu, 28 Dec 2017 20:15:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 13A48C21D5D; Thu, 28 Dec 2017 20:14:41 +0000 (UTC) Received: from mail-io0-f195.google.com (mail-io0-f195.google.com [209.85.223.195]) by lists.denx.de (Postfix) with ESMTPS id 06B71C21DED for ; Thu, 28 Dec 2017 20:14:38 +0000 (UTC) Received: by mail-io0-f195.google.com with SMTP id x67so33210583ioi.9 for ; Thu, 28 Dec 2017 12:14:37 -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=gRDfz6AQ1+iyndBdsEW8Mf29XkFSKbal4pNfcj2GUew=; b=fBrUT6++uBGcclYql3NZYjlDmTW8SMnNZbBCVBMMB113PsW9PcJqWfGGnMngLObWFU 1b3UOUgq+B01sZVSpOUolmr4N91dh6bpoXP2rqMgmlINui9a431uQZ2jJ0qt5dL4JcfU SwV686Wn3IKyUTs9jrvBZNFmMjSeEnQpzZvHB+R10tmzxUL4h3VZ2Dj+wbM9HcFIqHoF H2pi0Xi5XefO7iP5/yOG2GW1CYLL15urHtyuLlGVVTYalzzpNSgUf2oC4Ta4YnBuUH6Y srqXlOoZ9B+BvLMW9VHC41G6PzHpP+t7WBitU4yZBmEytatwlMeGz30vlVX9cdCpq+tV 5+pw== 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=gRDfz6AQ1+iyndBdsEW8Mf29XkFSKbal4pNfcj2GUew=; b=X1SpKPzvcb/AolncAxjB6tbir7HFNtZ0DS5tC1a2wDLl5jeqt8hKOtt4n+Um9GhFsF 6ZQBN4ZWsz/lzeek5UhFkWlDz+aVBO/e1WO/XLVDim4jePAPHdEiRVqr65euzJzhGbHE cByxZV/+Xwzjzhdd3DN4lMMYwLIj0wWinyZXqR9Bh0UyG40TewUPKFu7EEhnFIuL3ZPP QtXTx2fFbIFTEdIPt4hUBuBe9MctNdmDdsdnqz4JeNiXYhGeqTBjKS/zt36wd8Zr+t3W qeu6fu1nyI34hhXEOHNSKSsncaWWJhGMxqjskhSTYkgso3CaFmE+3sRFI3mYqvGAI9tY e+0A== X-Gm-Message-State: AKGB3mIvoQOLMlWJKQQgP3NF00p1eND7V0BK5VFS79VTmTiP8I3JJLBQ A8lkS85sSETkYhl3X/5vj6Kg6g== X-Google-Smtp-Source: ACJfBosWfx/zGxytULPm6fJbrM3h++QsFHPSnBgEd1CpMdeqw+UneKFqB8mPX48gPfzMWCZqRpVRXQ== X-Received: by 10.107.70.16 with SMTP id t16mr11741990ioa.298.1514492076471; Thu, 28 Dec 2017 12:14:36 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:1dfd:6d2e:1964:8aa1]) by smtp.gmail.com with ESMTPSA id v65sm12177179itb.30.2017.12.28.12.14.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:14:35 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id D2DD213FEAF; Thu, 28 Dec 2017 13:14:32 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 28 Dec 2017 13:14:20 -0700 Message-Id: <20171228201423.128338-7-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 6/9] log: Add a command to output a log record 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" Add a 'log rec' command which allows a log record to be manually output. This is useful for scripts which want full control over what is logged. It also permits easy testing of the log system. Signed-off-by: Simon Glass --- cmd/log.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/cmd/log.c b/cmd/log.c index e038bc3269..12bac0e03c 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -59,12 +59,49 @@ static int do_log_format(cmd_tbl_t *cmdtp, int flag, int argc, return 0; } +static int do_log_rec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + enum log_category_t cat; + enum log_level_t level; + const char *file; + uint line; + const char *func; + const char *msg; + char *end; + + if (argc < 7) + return CMD_RET_USAGE; + cat = log_get_cat_by_name(argv[1]); + level = simple_strtoul(argv[2], &end, 10); + if (end == argv[2]) { + level = log_get_level_by_name(argv[2]); + + if (level == LOGL_NONE) { + printf("Invalid log level '%s'\n", argv[2]); + return CMD_RET_USAGE; + } + } + if (level >= LOGL_MAX) { + printf("Invalid log level %u\n", level); + return CMD_RET_USAGE; + } + file = argv[3]; + line = simple_strtoul(argv[4], NULL, 10); + func = argv[5]; + msg = argv[6]; + if (_log(cat, level, file, line, func, "%s\n", msg)) + return CMD_RET_FAILURE; + + return 0; +} + static cmd_tbl_t log_sub[] = { U_BOOT_CMD_MKENT(level, CONFIG_SYS_MAXARGS, 1, do_log_level, "", ""), #ifdef CONFIG_LOG_TEST U_BOOT_CMD_MKENT(test, 2, 1, do_log_test, "", ""), #endif U_BOOT_CMD_MKENT(format, CONFIG_SYS_MAXARGS, 1, do_log_format, "", ""), + U_BOOT_CMD_MKENT(rec, CONFIG_SYS_MAXARGS, 1, do_log_rec, "", ""), }; static int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) @@ -94,7 +131,9 @@ static char log_help_text[] = "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" - "\tor 'default', equivalent to 'fm', or 'all' for all" + "\tor 'default', equivalent to 'fm', or 'all' for all\n" + "log rec - " + "output a log record" ; #endif From patchwork Thu Dec 28 20:14:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 853551 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="u6AeVBVT"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z71J54Vrjz9sNx for ; Fri, 29 Dec 2017 07:18:29 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5A48EC21DDA; Thu, 28 Dec 2017 20:15:47 +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 64DBBC21DD0; Thu, 28 Dec 2017 20:14:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A2788C21DDF; Thu, 28 Dec 2017 20:14:42 +0000 (UTC) Received: from mail-it0-f68.google.com (mail-it0-f68.google.com [209.85.214.68]) by lists.denx.de (Postfix) with ESMTPS id 659EDC21E06 for ; Thu, 28 Dec 2017 20:14:38 +0000 (UTC) Received: by mail-it0-f68.google.com with SMTP id d16so29762888itj.1 for ; Thu, 28 Dec 2017 12:14:38 -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=eTiEebHENYdhbLKJuSca8a8xw52AiUXERD4dBB1DiLk=; b=u6AeVBVTo3e2+aIypPXF/LSXdEtT+ESbhWTdAAk5VW8Zr0df18PN5Pu3yUog76DNm0 of6cULeYO7JkXzyKpur2KRQpGYpr4B/EdnuIBRsv069GHtGGwvp1uTeXspe6IzzppIaU QSBAdQ2v2aBG20U7WzqIBeZWZpiQG0jNXuBUSlFxoxb06zE5mQ3zOYbQ4mWKRDpEUj3S 8hFsFTsZz0zRBtB3kX8qr7mqEiMQESR1GNJYPeoRYgYXA1KwTt5G4OZyz6jfN2GKr8+m oPsgEaZQ6fFaMMD3CjUSw9rYUNBr8p41D1HUaygbFZPyFi8OPVfHeBvf9MPZoXIGk6/q ovhQ== 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=eTiEebHENYdhbLKJuSca8a8xw52AiUXERD4dBB1DiLk=; b=OfpeKhx049w7J3xSq9fhzqwSJsRdIycqyceW0QJ9Laa8fOwSBfxmzqIEb4ZlChOdf4 ISSMs5PuHgw5Jc/VeD7KXbqo7dGAsIUHSunTQBt3I4+WZnp+snbhw6ZL4aftg1cxF2pR Z5tF9gm6gb3441klh/jI8XBrcQqB5c2KFHbP0OVQBIOlM1glT8TBq4+Yy6A7H7le5pQP dXwsJYH9jKBtF3gtYvyVoLZLpjaYqWFjCMW8ujlTz4tHjEY0ryddde9BnGXfka2wAGme EEmrcrnhzkA+SXc6hvfQNkBnBYjXRKVcQNkl804ifn0xdcG6sxH9YxpSYOi0S2X80heh 6iXw== X-Gm-Message-State: AKGB3mJJLeqYWWqRbQhoJEjCWQ+M/nmep+pperpzEUVl7TKkkm3QBiZp VnT2lwdP9Hy3bv+ElPnRkSNISA== X-Google-Smtp-Source: ACJfBos5Oho/gQmxMEZxHZzpYquF2kuVmyqqpD6vSfn2egLS2bGOUli5I3Pr8kPOvxP6vj8V9PBnBg== X-Received: by 10.36.54.208 with SMTP id l199mr36697947itl.90.1514492076969; Thu, 28 Dec 2017 12:14:36 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:1dfd:6d2e:1964:8aa1]) by smtp.gmail.com with ESMTPSA id 202sm12614328ioz.51.2017.12.28.12.14.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:14:35 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 0F5F21414D5; Thu, 28 Dec 2017 13:14:34 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 28 Dec 2017 13:14:21 -0700 Message-Id: <20171228201423.128338-8-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 7/9] log: Add tests for the new log features 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" Add a test of the 'log format' and 'log rec' commands. This also covers things like log_get_cat_by_name(), since they are used by these commands. Fix a style nit in the tests also. Signed-off-by: Simon Glass --- test/py/tests/test_log.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py index 517f415143..76f9236412 100644 --- a/test/py/tests/test_log.py +++ b/test/py/tests/test_log.py @@ -40,7 +40,6 @@ def test_log(u_boot_console): Returns: iterator containing the lines output from the command """ - with cons.log.section('basic'): output = u_boot_console.run_command('log test %d' % testnum) split = output.replace('\r', '').splitlines() @@ -99,3 +98,30 @@ def test_log(u_boot_console): test7() test8() test9() + +@pytest.mark.buildconfigspec('log') +def test_log_format(u_boot_console): + """Test the 'log format' and 'log rec' commands""" + def run_with_format(fmt, expected_output): + """Set up the log format and then write a log record + + Args: + fmt: Format to use for 'log format' + expected_output: Expected output from the 'log rec' command + """ + output = cons.run_command('log format %s' % fmt) + assert output == '' + output = cons.run_command('log rec arch notice file.c 123 func msg') + assert output == expected_output + + cons = u_boot_console + with cons.log.section('format'): + run_with_format('all', 'NOTICE.arch,file.c:123-func() msg') + output = cons.run_command('log format') + assert output == 'Log format: clFLfm' + + run_with_format('fm', 'func() msg') + run_with_format('clfm', 'NOTICE.arch,func() msg') + run_with_format('FLfm', 'file.c:123-func() msg') + run_with_format('lm', 'NOTICE. msg') + run_with_format('m', 'msg') From patchwork Thu Dec 28 20:14:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 853554 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="MLd2XNmo"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z71Lz1Y9bz9sRg for ; Fri, 29 Dec 2017 07:20:58 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5CC75C21DDD; Thu, 28 Dec 2017 20:16:58 +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 8C1A6C21C59; Thu, 28 Dec 2017 20:15:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 061D2C21E0A; Thu, 28 Dec 2017 20:14:43 +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 9B593C21DD9 for ; Thu, 28 Dec 2017 20:14:39 +0000 (UTC) Received: by mail-it0-f67.google.com with SMTP id x28so29241989ita.0 for ; Thu, 28 Dec 2017 12:14:39 -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=rn7Lv/TPK1oFuDUJ6+E+4zwp2+pS8qZjCIKf3JgfkyU=; b=MLd2XNmommSfHlqyRP8LEfsU3Bu8TRTmhi2psof0HVdPBKtktDC7o8azRYQmO2+t2X n2gSZkQKESkuk4og9qYN5iX+cuceuh3l+tZhlORwbHbuOXQlnjDjt89V5vG8VBEIMFWF UYaEVsPNxCspgRXGvazTNf/iPx8Sc8vCV9Etxud5G5FGa0eK4J5ijRTuIdnv08A1kM33 yQXOg3bQ4Gea9+t2B8W2iuaXzZCoOBGJu/lumJXyWJJk0X/fC2VOKX6U4xIsLRoVA8Uc NDudkGjaScsfU8Tx5p7X8jncX3z9bp5pyhqhax1MbzJZgiPu0XlHsj4Hpqu/3DPqHjYf llyA== 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=rn7Lv/TPK1oFuDUJ6+E+4zwp2+pS8qZjCIKf3JgfkyU=; b=e8GgMoGkdwwjU9zPsE6xKTt+6gmFYYGxp3NMEZcgeb+ogKC3tuyzChw5PDjuMG1kyI RceydcC3WMPx+vGqt5RAN978TDwrPHN3NbhL74WMbKSXc6NgoVOyJ93hLJhM4n957Cw9 /F+jJa09hjzg6Izfm5VfI3b1axBrSAV4VxGTZc+8LLtKUxUoR370sJzUxTHkjsMnksjV NxHv1a5u3s5sdHLAooOUeg1jCLnM4Yc7PROmMhBaSiDeMQ+WtBcnIU/paXYn6owf7lG/ 1gYmRCzz/VI3crCqh9FGy5eUU5GWVu1/kxgQt8dhkGPn2fotSU8l1+fEcXU5SQoBqAEf l80A== X-Gm-Message-State: AKGB3mI4nFmjPDYC9U07iAt8WzGx3hBgMM94VJgNLoUJC9+FrETUYL3K Bg8nRlfc8rzapCRksymYecKJyA== X-Google-Smtp-Source: ACJfBoudzCVNEnx6iUpQZbbCEM63YMerufJLVIrmQ5Hc1QnD+iPaIf2bxR6ebH5oh8GNojeuqnm2sQ== X-Received: by 10.36.117.87 with SMTP id y84mr39908437itc.124.1514492078245; Thu, 28 Dec 2017 12:14:38 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:1dfd:6d2e:1964:8aa1]) by smtp.gmail.com with ESMTPSA id o137sm12311821ito.5.2017.12.28.12.14.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:14:36 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 4DF08142506; Thu, 28 Dec 2017 13:14:35 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 28 Dec 2017 13:14:22 -0700 Message-Id: <20171228201423.128338-9-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 8/9] log: Add documentation for commands and formatting 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" Add some notes about recent new features. Signed-off-by: Simon Glass --- doc/README.log | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/README.log b/doc/README.log index f653fe7d79..54d9a8e1b9 100644 --- a/doc/README.log +++ b/doc/README.log @@ -68,6 +68,19 @@ If CONFIG_LOG is not set, then no logging will be available. The above have SPL versions also, e.g. CONFIG_SPL_MAX_LOG_LEVEL. +Log commands +------------ + +The 'log' command provides access to several features: + + level - access the default log level + format - access the console log format + rec - output a log record + test - run tests + +Type 'help log' for details. + + Using DEBUG ----------- @@ -94,6 +107,20 @@ enabled or disabled independently: console - goes to stdout +Log format +---------- + +You can control the log format using the 'log format' command. The basic +format is: + + LEVEL.category,file.c:123-func() message + +In the above, file.c:123 is the filename where the log record was generated and +func() is the function name. By default ('log format default') only the +function name and message are displayed on the console. You can control which +fields are present, but not the field order. + + Filters ------- From patchwork Thu Dec 28 20:14:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 853549 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="fxKCkU51"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3z71Hh3lsNz9sNx for ; Fri, 29 Dec 2017 07:18:08 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 2B21DC21DE6; Thu, 28 Dec 2017 20:17:15 +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_H2, 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 0AE24C21E0C; Thu, 28 Dec 2017 20:16:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 76A69C21DA0; Thu, 28 Dec 2017 20:14:44 +0000 (UTC) Received: from mail-io0-f194.google.com (mail-io0-f194.google.com [209.85.223.194]) by lists.denx.de (Postfix) with ESMTPS id 9EA57C21D9F for ; Thu, 28 Dec 2017 20:14:40 +0000 (UTC) Received: by mail-io0-f194.google.com with SMTP id 14so32851249iou.2 for ; Thu, 28 Dec 2017 12:14:40 -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=2QNGsYB+HKhWhTUIGqwFugC39smrzvpH5FpGy+dlemU=; b=fxKCkU51wSOALEyB4AmQi7H0Fa4ZJj9sgj0i69LtN/z1hmV4weh3L5XyhqMjH+syeN +HOWFLSpMJ7Y+90OJJNQIudqgPw7Vp0V+s8dHZFOsiNIE5vZY+CKbxDa9Sj8PUtuEgcF 3EzFNBde+45W037ZLhOc/1cr2voraWLcMxfOBwX6cqfv8xR9rsebAai1z915u6emJp90 ANvR08O4q9S9QQJSFHJZ1cvbBBhVbWU/5JBJSi7p+MPV7a6eM/RCzzjuh76qbrUHuXUL g18TMs1gzDc0pjOhInML/PELMgU+4hok72S4guJjbmKpUMdnxlFDQ2htmW6h22t70o5k +HiQ== 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=2QNGsYB+HKhWhTUIGqwFugC39smrzvpH5FpGy+dlemU=; b=qTIxJUXBKIGbF7pUBlKNSEF+9L/GMlqGta6sEDkHGOJ8NOx78VKJYX691KsTgZwR3Y pH10pLtPNSIQwGFLGlw4ukAKcdIUFBCYskb4iHVqo7c5CQf6EHZRp4oRDNPzFZJSTuib eHFCs4D7VPlMrIGM7mVl8TVyNvuT+l+37JVF0HijhbJroDM5rP39W6ztxiXOXnkkTH/X vsbCYrneny04Uz+axgwOGiw845huaVQUMjGP5efTNi1jsqDzdHKMXfRPveP4eby36Zid ZvGjNOD/myqlrVLH9NEkycTkTV+8zHKnpClqmX96Wx9ThK7vT/4xvrhl8GD9nMZDSjUL 6xlg== X-Gm-Message-State: AKGB3mI/q6w3DxhWsSfQv8+Ns+PrOqwxWrz7ZJSUq/mpQMzpsXoRCDhQ eaDT2loPd8A+xB9vOGX7GeMzhg== X-Google-Smtp-Source: ACJfBouth+4/eJCMGMFk2OVn4i1vYjXjEtg+WDcY+vwOAVV4+OQKy03cM6F2lzItH6MM+By0PQheHw== X-Received: by 10.107.174.198 with SMTP id n67mr43231314ioo.18.1514492079153; Thu, 28 Dec 2017 12:14:39 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:1dfd:6d2e:1964:8aa1]) by smtp.gmail.com with ESMTPSA id 72sm14145221iol.64.2017.12.28.12.14.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:14:38 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 869BD14251F; Thu, 28 Dec 2017 13:14:36 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Thu, 28 Dec 2017 13:14:23 -0700 Message-Id: <20171228201423.128338-10-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 , Maxime Ripard Subject: [U-Boot] [PATCH 9/9] log: Add a way to log error-return values 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" When functions return an error it propagates up the stack to the point where it is reported. Often the error code provides enough information about the root cause of the error that this is obvious what went wrong. However in some cases the error may be hard to trace. For example if a driver uses several devices to perform an operation, it may not be obvious which one failed. Add a log_ret() macro to help with this. This can be used to wrap any error-return value. The logging system will then output a log record when the original error is generated, making it easy to trace the call stack of the error. This macro can significantly impact code size, so its use is controlled by a Kconfig option, which is enabled for sandbox. Signed-off-by: Simon Glass --- common/Kconfig | 13 +++++++++++++ configs/sandbox_defconfig | 1 + doc/README.log | 8 ++++++++ include/log.h | 11 +++++++++++ 4 files changed, 33 insertions(+) diff --git a/common/Kconfig b/common/Kconfig index 4da095a4fd..c9833b3226 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -504,6 +504,19 @@ config LOG_TEST in various different ways to test that the logging system works correctly with varoius settings. +config LOG_ERROR_RETURN + bool "Log all functions which return an error" + depends on LOG + help + When an error is returned in U-Boot it is sometimes difficult to + figure out the root cause. For eaxmple, reading from SPI flash may + fail due to a problem in the SPI controller or due to the flash part + not returning the expected information. This option changes + log_ret() to log any errors it sees. With this option disabled, + log_ret() is a nop. + + You can add log_ret() to all functions which return an error code. + endmenu config DEFAULT_FDT_FILE diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 7efb4ebf11..41a2e34235 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -18,6 +18,7 @@ CONFIG_PRE_CONSOLE_BUFFER=y CONFIG_PRE_CON_BUF_ADDR=0x100000 CONFIG_LOG=y CONFIG_LOG_MAX_LEVEL=6 +CONFIG_LOG_ERROR_RETURN=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y diff --git a/doc/README.log b/doc/README.log index 54d9a8e1b9..2abaee0c10 100644 --- a/doc/README.log +++ b/doc/README.log @@ -148,6 +148,14 @@ Also debug() and error() will generate log records - these use LOG_CATEGORY as the category, so you should #define this right at the top of the source file to ensure the category is correct. +You can also define CONFIG_LOG_ERROR_RETURN to enable the log_ret() macro. This +can be used whenever your function returns an error value: + + return log_ret(uclass_first_device(UCLASS_MMC, &dev)); + +This will write a log record when an error code is detected (a value < 0). This +can make it easier to trace errors that are generated deep in the call stack. + Code size --------- diff --git a/include/log.h b/include/log.h index 828919a409..68368d5cf1 100644 --- a/include/log.h +++ b/include/log.h @@ -159,6 +159,17 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line, ({ if (!(x) && _DEBUG) \ __assert_fail(#x, __FILE__, __LINE__, __func__); }) +#ifdef CONFIG_LOG_ERROR_RETURN +#define log_ret(_ret) ({ \ + int __ret = (_ret); \ + if (__ret < 0) \ + log(LOG_CATEGORY, LOGL_ERR, "returning err=%d\n", __ret); \ + __ret; \ + }) +#else +#define log_ret(_ret) (_ret) +#endif + /** * struct log_rec - a single log record *