Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/814558/?format=api
{ "id": 814558, "url": "http://patchwork.ozlabs.org/api/patches/814558/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20170916212331.170463-7-sjg@chromium.org/", "project": { "id": 18, "url": "http://patchwork.ozlabs.org/api/projects/18/?format=api", "name": "U-Boot", "link_name": "uboot", "list_id": "u-boot.lists.denx.de", "list_email": "u-boot@lists.denx.de", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20170916212331.170463-7-sjg@chromium.org>", "list_archive_url": null, "date": "2017-09-16T21:23:19", "name": "[U-Boot,06/13] log: Add an implemention of logging", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "a96f67956489adba0cece9a6862a3e6d25b8e75f", "submitter": { "id": 6170, "url": "http://patchwork.ozlabs.org/api/people/6170/?format=api", "name": "Simon Glass", "email": "sjg@chromium.org" }, "delegate": { "id": 3184, "url": "http://patchwork.ozlabs.org/api/users/3184/?format=api", "username": "sjg", "first_name": "Simon", "last_name": "Glass", "email": "sjg@chromium.org" }, "mbox": "http://patchwork.ozlabs.org/project/uboot/patch/20170916212331.170463-7-sjg@chromium.org/mbox/", "series": [ { "id": 3473, "url": "http://patchwork.ozlabs.org/api/series/3473/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=3473", "date": "2017-09-16T21:23:14", "name": "log: Add a new logging feature", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/3473/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/814558/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/814558/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<u-boot-bounces@lists.denx.de>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": [ "ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)", "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"fDTe/SFq\"; dkim-atps=neutral" ], "Received": [ "from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xvllN6BDNz9sPr\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun, 17 Sep 2017 07:29:20 +1000 (AEST)", "by lists.denx.de (Postfix, from userid 105)\n\tid 8E64DC21E48; Sat, 16 Sep 2017 21:26:06 +0000 (UTC)", "from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id F40D0C21DC3;\n\tSat, 16 Sep 2017 21:24:40 +0000 (UTC)", "by lists.denx.de (Postfix, from userid 105)\n\tid 02D3FC21C26; Sat, 16 Sep 2017 21:24:09 +0000 (UTC)", "from mail-oi0-f46.google.com (mail-oi0-f46.google.com\n\t[209.85.218.46])\n\tby lists.denx.de (Postfix) with ESMTPS id 659B5C21DB1\n\tfor <u-boot@lists.denx.de>; Sat, 16 Sep 2017 21:24:04 +0000 (UTC)", "by mail-oi0-f46.google.com with SMTP id 199so2375645oii.11\n\tfor <u-boot@lists.denx.de>; Sat, 16 Sep 2017 14:24:04 -0700 (PDT)", "from kiwi.bld.corp.google.com ([100.101.164.89])\n\tby smtp.gmail.com with ESMTPSA id\n\ty192sm4425016oie.36.2017.09.16.14.24.01\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tSat, 16 Sep 2017 14:24:01 -0700 (PDT)", "by kiwi.bld.corp.google.com (Postfix, from userid 121222)\n\tid 5E9B3140A54; Sat, 16 Sep 2017 15:24:01 -0600 (MDT)" ], "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_NONE,\n\tRCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID autolearn=unavailable\n\tautolearn_force=no version=3.4.0", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n\ts=20161025; \n\th=sender:from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=dSavDsJ92og3CmC2A0amaPFMOfSkUDBIL70VT8ozyGs=;\n\tb=fDTe/SFq9A7PAlQx//8ws//2WOO31eDaQd31jvoxL75MNEbyTSONJhFDAsu7WPyMiv\n\tywC+2/kL59ecn9VZAoLmG0bSuT8pSnShwaDXIGtG4eN9cQuippFgytg9tkH8JVRLnykb\n\tpunNMANpNq6vWmWZZ93OcFMFbXvHB0gR1Dn6fTXpF9IoIBiOHyQ4Dx8lLwQGXuWhBgMs\n\tQ1I1diSUcjUZgJGs/wpfxt+rH9DRt4uMlKD0wXXIsaA8oVQ2HT3lx+da+HqYLW2OSBH7\n\tKLXvaK4yqFkEkbNvBgnJj7669djr0wAIolZI2GmNnl9RdmikaED27SY1oCKD7BTO3y8L\n\tS23w==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:sender:from:to:cc:subject:date:message-id\n\t:in-reply-to:references;\n\tbh=dSavDsJ92og3CmC2A0amaPFMOfSkUDBIL70VT8ozyGs=;\n\tb=FaAKecbm1BvY0v+D1tDdEUS2mqrVT9sOuySDeN+LlrD3uMIk7ekbQt2YPujhKhwdYk\n\tUySFBBdiETMa3sPmH9hB0nTvVeRIjWRQ7Dh2t2ddB3DVRnYQcJqn+p0xU2AMX1B4LHUR\n\tacba22bHDRV490TcqBFdJ97R6LPO6Rugf0j6SfMEKQX49Z6TFuN+D6rtoPZW656WasZ5\n\tnNImWXbb9g0Pg2ylwTxpVhpSCrnrf0IPlVAOdBFkOlQnrCF9cXcNzLUAH3C3I1lY8Acc\n\tidpLbF500tuLMa8YlDlrjLxKP+IygtzoJ5emGOA4zpe8takLD6UOxseJAniMhMTNHuwM\n\t2dBg==", "X-Gm-Message-State": "AHPjjUiHVoApaZ65NaLK4+WvZT7hPbZe9V4zObqM157vY52Hmjww8/W6\n\t+GDbury/uHK0h/GA", "X-Google-Smtp-Source": "AOwi7QAS7KruEgoW0/N1GkVk0JoA6Vl0MQrtz/a1aePg/E/7F5FIoT6UK+ijvMfpjB0cweOfji+5HA==", "X-Received": "by 10.202.171.142 with SMTP id u136mr2915746oie.0.1505597042660; \n\tSat, 16 Sep 2017 14:24:02 -0700 (PDT)", "From": "Simon Glass <sjg@chromium.org>", "To": "U-Boot Mailing List <u-boot@lists.denx.de>", "Date": "Sat, 16 Sep 2017 15:23:19 -0600", "Message-Id": "<20170916212331.170463-7-sjg@chromium.org>", "X-Mailer": "git-send-email 2.14.1.690.gbb1197296e-goog", "In-Reply-To": "<20170916212331.170463-1-sjg@chromium.org>", "References": "<20170916212331.170463-1-sjg@chromium.org>", "Cc": "Tom Rini <trini@konsulko.com>, Andy Shevchenko\n\t<andriy.shevchenko@linux.intel.com>, =?utf-8?q?=C5=81ukasz_Majewski?=\n\t<l.majewski@samsung.com>, Andy Yan <andy.yan@rock-chips.com>,\n\tMaxime Ripard\n\t<maxime.ripard@free-electrons.com>, Stefan Roese <sr@denx.de>,\n\tFranklin <fcooper@ti.com>", "Subject": "[U-Boot] [PATCH 06/13] log: Add an implemention of logging", "X-BeenThere": "u-boot@lists.denx.de", "X-Mailman-Version": "2.1.18", "Precedence": "list", "List-Id": "U-Boot discussion <u-boot.lists.denx.de>", "List-Unsubscribe": "<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>", "List-Archive": "<http://lists.denx.de/pipermail/u-boot/>", "List-Post": "<mailto:u-boot@lists.denx.de>", "List-Help": "<mailto:u-boot-request@lists.denx.de?subject=help>", "List-Subscribe": "<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "base64", "Errors-To": "u-boot-bounces@lists.denx.de", "Sender": "\"U-Boot\" <u-boot-bounces@lists.denx.de>" }, "content": "Add the logging header file and implementation with some configuration\noptions to control it.\n\nSigned-off-by: Simon Glass <sjg@chromium.org>\n---\n\n MAINTAINERS | 9 ++\n common/Kconfig | 56 +++++++++\n common/Makefile | 1 +\n common/log.c | 246 +++++++++++++++++++++++++++++++++++++\n include/asm-generic/global_data.h | 5 +\n include/log.h | 247 ++++++++++++++++++++++++++++++++++++--\n 6 files changed, 555 insertions(+), 9 deletions(-)\n create mode 100644 common/log.c", "diff": "diff --git a/MAINTAINERS b/MAINTAINERS\nindex 04acf2b89d..eb420afa8d 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -290,6 +290,15 @@ S:\tMaintained\n T:\tgit git://git.denx.de/u-boot-i2c.git\n F:\tdrivers/i2c/\n \n+LOGGING\n+M:\tSimon Glass <sjg@chromium.org>\n+S:\tMaintained\n+T:\tgit git://git.denx.de/u-boot.git\n+F:\tcommon/log.c\n+F:\tcmd/log.c\n+F:\ttest/log/log_test.c\n+F:\ttest/py/tests/test_log.py\n+\n MICROBLAZE\n M:\tMichal Simek <monstr@monstr.eu>\n S:\tMaintained\ndiff --git a/common/Kconfig b/common/Kconfig\nindex 4d8cae9610..cbccc8ae26 100644\n--- a/common/Kconfig\n+++ b/common/Kconfig\n@@ -384,6 +384,62 @@ config SYS_STDIO_DEREGISTER\n \n endmenu\n \n+menu \"Logging\"\n+\n+config LOG\n+\tbool \"Enable logging support\"\n+\thelp\n+\t This enables support for logging of status and debug messages. These\n+\t can be displayed on the console, recorded in a memory buffer, or\n+\t discarded if not needed. Logging supports various categories and\n+\t levels of severity.\n+\n+config SPL_LOG\n+\tbool \"Enable logging support in SPL\"\n+\thelp\n+\t This enables support for logging of status and debug messages. These\n+\t can be displayed on the console, recorded in a memory buffer, or\n+\t discarded if not needed. Logging supports various categories and\n+\t levels of severity.\n+\n+config LOG_MAX_LEVEL\n+\tint \"Maximum log level to record\"\n+\tdepends on LOG\n+\tdefault 5\n+\thelp\n+\t This selects the maximum log level that will be recorded. Any value\n+\t higher than this will be ignored. If possible log statements below\n+\t this level will be discarded at build time. Levels:\n+\n+\t 0 - panic\n+\t 1 - critical\n+\t 2 - error\n+\t 3 - warning\n+\t 4 - note\n+\t 5 - info\n+\t 6 - detail\n+\t 7 - debug\n+\n+config LOG_SPL_MAX_LEVEL\n+\tint \"Maximum log level to record in SPL\"\n+\tdepends on SPL_LOG\n+\tdefault 3\n+\thelp\n+\t This selects the maximum log level that will be recorded. Any value\n+\t higher than this will be ignored. If possible log statements below\n+\t this level will be discarded at build time. Levels:\n+\n+\t 0 - panic\n+\t 1 - critical\n+\t 2 - error\n+\t 3 - warning\n+\t 4 - note\n+\t 5 - info\n+\t 6 - detail\n+\t 7 - debug\n+\n+endmenu\n+\n config DTB_RESELECT\n \tbool \"Support swapping dtbs at a later point in boot\"\n \tdepends on FIT_EMBED\ndiff --git a/common/Makefile b/common/Makefile\nindex 1b56cf9a70..d37c8d5636 100644\n--- a/common/Makefile\n+++ b/common/Makefile\n@@ -128,5 +128,6 @@ obj-y += cli.o\n obj-$(CONFIG_FSL_DDR_INTERACTIVE) += cli_simple.o cli_readline.o\n obj-$(CONFIG_CMD_DFU) += dfu.o\n obj-y += command.o\n+obj-$(CONFIG_$(SPL_)LOG) += log.o\n obj-y += s_record.o\n obj-y += xyzModem.o\ndiff --git a/common/log.c b/common/log.c\nnew file mode 100644\nindex 0000000000..6bf2219d38\n--- /dev/null\n+++ b/common/log.c\n@@ -0,0 +1,246 @@\n+/*\n+ * Logging support\n+ *\n+ * Copyright (c) 2017 Google, Inc\n+ * Written by Simon Glass <sjg@chromium.org>\n+ *\n+ * SPDX-License-Identifier:\tGPL-2.0+\n+ */\n+\n+#include <common.h>\n+#include <log.h>\n+#include <malloc.h>\n+\n+DECLARE_GLOBAL_DATA_PTR;\n+\n+static struct log_device *log_device_find_by_name(const char *drv_name)\n+{\n+\tstruct log_device *ldev;\n+\n+\tlist_for_each_entry(ldev, &gd->log_head, sibling_node) {\n+\t\tif (!strcmp(drv_name, ldev->drv->name))\n+\t\t\treturn ldev;\n+\t}\n+\n+\treturn NULL;\n+}\n+\n+/**\n+ * log_has_cat() - check if a log category exists within a list\n+ *\n+ * @cat_list: List of categories to check, at most LOGF_MAX_CATEGORIES entries\n+ *\tlong, terminated by LC_END if fewer\n+ * @cat: Category to search for\n+ * @return true if @cat is in @cat_list, else false\n+ */\n+static bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i < LOGF_MAX_CATEGORIES && cat_list[i] != LOGC_END; i++) {\n+\t\tif (cat_list[i] == cat)\n+\t\t\treturn true;\n+\t}\n+\n+\treturn false;\n+}\n+\n+/**\n+ * log_has_file() - check if a file is with a list\n+ *\n+ * @file_list: List of files to check, separated by comma\n+ * @file: File to check for. This string is matched against the end of each\n+ *\tfile in the list, i.e. ignoring any preceeding path. The list is\n+ *\tintended to consist of relative pathnames, e.g. common/main.c,cmd/log.c\n+ * @return true if @file is in @file_list, else false\n+ */\n+static bool log_has_file(const char *file_list, const char *file)\n+{\n+\tint file_len = strlen(file);\n+\tconst char *s, *p;\n+\tint substr_len;\n+\n+\tfor (s = file_list; *s; s = p + (*p != '\\0')) {\n+\t\tp = strchrnul(s, ',');\n+\t\tsubstr_len = p - s;\n+\t\tif (file_len >= substr_len &&\n+\t\t !strncmp(file + file_len - substr_len, s, substr_len))\n+\t\t\treturn true;\n+\t}\n+\n+\treturn false;\n+}\n+\n+/**\n+ * log_passes_filters() - check if a log record passes the filters for a device\n+ *\n+ * @ldev: Log device to check\n+ * @rec: Log record to check\n+ * @return true if @rec is not blocked by the filters in @ldev, false if it is\n+ */\n+static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec)\n+{\n+\tstruct log_filter *filt;\n+\n+\t/* If there are no filters, filter on the default log level */\n+\tif (list_empty(&ldev->filter_head)) {\n+\t\tif (rec->level > gd->default_log_level)\n+\t\t\treturn false;\n+\t\treturn true;\n+\t}\n+\n+\tlist_for_each_entry(filt, &ldev->filter_head, sibling_node) {\n+\t\tif (rec->level > filt->max_level)\n+\t\t\tcontinue;\n+\t\tif ((filt->flags & LOGFF_HAS_CAT) &&\n+\t\t !log_has_cat(filt->cat_list, rec->cat))\n+\t\t\tcontinue;\n+\t\tif (filt->file_list &&\n+\t\t !log_has_file(filt->file_list, rec->file))\n+\t\t\tcontinue;\n+\t\treturn true;\n+\t}\n+\n+\treturn false;\n+}\n+\n+/**\n+ * log_dispatch() - Send a log record to all log devices for processing\n+ *\n+ * The log record is sent to each log device in turn, skipping those which have\n+ * filters which block the record\n+ *\n+ * @rec: Log record to dispatch\n+ * @return 0 (meaning success)\n+ */\n+static int log_dispatch(struct log_rec *rec)\n+{\n+\tstruct log_device *ldev;\n+\n+\tlist_for_each_entry(ldev, &gd->log_head, sibling_node) {\n+\t\tif (log_passes_filters(ldev, rec))\n+\t\t\tldev->drv->emit(ldev, rec);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int _log(enum log_category_t cat, enum log_level_t level, const char *file,\n+\t int line, const char *func, const char *fmt, ...)\n+{\n+\tchar buf[CONFIG_SYS_CBSIZE];\n+\tstruct log_rec rec;\n+\tva_list args;\n+\n+\trec.cat = cat;\n+\trec.level = level;\n+\trec.file = file;\n+\trec.line = line;\n+\trec.func = func;\n+\tva_start(args, fmt);\n+\tvsnprintf(buf, sizeof(buf), fmt, args);\n+\tva_end(args);\n+\trec.msg = buf;\n+\tif (!gd || !(gd->flags & GD_FLG_LOG_READY)) {\n+\t\tif (gd)\n+\t\t\tgd->log_drop_count++;\n+\t\treturn -ENOSYS;\n+\t}\n+\tlog_dispatch(&rec);\n+\n+\treturn 0;\n+}\n+\n+int log_add_filter(const char *drv_name, enum log_category_t cat_list[],\n+\t\t enum log_level_t max_level, const char *file_list)\n+{\n+\tstruct log_filter *filt;\n+\tstruct log_device *ldev;\n+\tint i;\n+\n+\tldev = log_device_find_by_name(drv_name);\n+\tif (!ldev)\n+\t\treturn -ENOENT;\n+\tfilt = (struct log_filter *)calloc(1, sizeof(*filt));\n+\tif (!filt)\n+\t\treturn -ENOMEM;\n+\n+\tif (cat_list) {\n+\t\tfilt->flags |= LOGFF_HAS_CAT;\n+\t\tfor (i = 0; ; i++) {\n+\t\t\tif (i == ARRAY_SIZE(filt->cat_list))\n+\t\t\t\treturn -ENOSPC;\n+\t\t\tfilt->cat_list[i] = cat_list[i];\n+\t\t\tif (cat_list[i] == LOGC_END)\n+\t\t\t\tbreak;\n+\t\t}\n+\t}\n+\tfilt->max_level = max_level;\n+\tif (file_list) {\n+\t\tfilt->file_list = strdup(file_list);\n+\t\tif (!filt->file_list)\n+\t\t\tgoto nomem;\n+\t}\n+\tfilt->filter_num = ldev->next_filter_num++;\n+\tINIT_LIST_HEAD(&filt->sibling_node);\n+\tlist_add_tail(&filt->sibling_node, &ldev->filter_head);\n+\n+\treturn filt->filter_num;\n+\n+nomem:\n+\tfree(filt);\n+\treturn -ENOMEM;\n+}\n+\n+int log_remove_filter(const char *drv_name, int filter_num)\n+{\n+\tstruct log_filter *filt;\n+\tstruct log_device *ldev;\n+\n+\tldev = log_device_find_by_name(drv_name);\n+\tif (!ldev)\n+\t\treturn -ENOENT;\n+\n+\tlist_for_each_entry(filt, &ldev->filter_head, sibling_node) {\n+\t\tif (filt->filter_num == filter_num) {\n+\t\t\tlist_del(&filt->sibling_node);\n+\t\t\tfree(filt);\n+\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\treturn -ENOENT;\n+}\n+\n+int log_init(void)\n+{\n+\tstruct log_driver *drv = ll_entry_start(struct log_driver, log_driver);\n+\tconst int count = ll_entry_count(struct log_driver, log_driver);\n+\tstruct log_driver *end = drv + count;\n+\n+\t/*\n+\t * We cannot add runtime data to the driver since it is likely stored\n+\t * in rodata. Instead, set up a 'device' corresponding to each driver.\n+\t * We only support having a single device.\n+\t */\n+\tINIT_LIST_HEAD((struct list_head *)&gd->log_head);\n+\twhile (drv < end) {\n+\t\tstruct log_device *ldev;\n+\n+\t\tldev = calloc(1, sizeof(*ldev));\n+\t\tif (!ldev) {\n+\t\t\tdebug(\"%s: Cannot allocate memory\\n\", __func__);\n+\t\t\treturn -ENOMEM;\n+\t\t}\n+\t\tINIT_LIST_HEAD(&ldev->sibling_node);\n+\t\tINIT_LIST_HEAD(&ldev->filter_head);\n+\t\tldev->drv = drv;\n+\t\tlist_add_tail(&ldev->sibling_node,\n+\t\t\t (struct list_head *)&gd->log_head);\n+\t\tdrv++;\n+\t}\n+\tgd->default_log_level = LOGL_INFO;\n+\n+\treturn 0;\n+}\ndiff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h\nindex 79197acfa4..77755dbb06 100644\n--- a/include/asm-generic/global_data.h\n+++ b/include/asm-generic/global_data.h\n@@ -114,6 +114,11 @@ typedef struct global_data {\n \tstruct bootstage_data *bootstage;\t/* Bootstage information */\n \tstruct bootstage_data *new_bootstage;\t/* Relocated bootstage info */\n #endif\n+#ifdef CONFIG_LOG\n+\tint log_drop_count;\t\t/* Number of dropped log messages */\n+\tint default_log_level;\t\t/* For devices with no filters */\n+\tstruct list_head log_head;\t/* List of struct log_device */\n+#endif\n } gd_t;\n #endif\n \ndiff --git a/include/log.h b/include/log.h\nindex 4101a74161..fb6a196202 100644\n--- a/include/log.h\n+++ b/include/log.h\n@@ -10,6 +10,82 @@\n #ifndef __LOG_H\n #define __LOG_H\n \n+#include <dm/uclass-id.h>\n+#include <linux/list.h>\n+\n+/** Log levels supported, ranging from most to least important */\n+enum log_level_t {\n+\tLOGL_PANIC = 0,\n+\tLOGL_CRIT,\n+\tLOGL_ERR,\n+\tLOGL_WARN,\n+\tLOGL_NOTE,\n+\tLOGL_INFO,\n+\tLOGL_DETAIL,\n+\tLOGL_DEBUG,\n+\n+\tLOGL_COUNT,\n+\tLOGL_FIRST = LOGL_PANIC,\n+\tLOGL_MAX = LOGL_DEBUG,\n+};\n+\n+/**\n+ * Log categories supported. Most of these correspond to uclasses (i.e.\n+ * enum uclass_id) but there are also some more generic categories\n+ */\n+enum log_category_t {\n+\tLOGC_FIRST = 0,\t/* First part mirrors UCLASS_... */\n+\n+\tLOGC_NONE = UCLASS_COUNT,\n+\tLOGC_ARCH,\n+\tLOGC_BOARD,\n+\tLOGC_CORE,\n+\tLOGC_DT,\n+\n+\tLOGC_COUNT,\n+\tLOGC_END,\n+};\n+\n+/**\n+ * _log() - Internal function to emit a new log record\n+ *\n+ * @cat: Category of log record (indicating which subsystem generated it)\n+ * @level: Level of log record (indicating its severity)\n+ * @file: File name of file where log record was generated\n+ * @line: Line number in file where log record was generated\n+ * @func: Function where log record was generated\n+ * @fmt: printf() format string for log record\n+ * @...: Optional parameters, according to the format string @fmt\n+ * @return 0 if log record was emitted, -ve on error\n+ */\n+int _log(enum log_category_t cat, enum log_level_t level, const char *file,\n+\t int line, const char *func, const char *fmt, ...);\n+\n+/* Define this at the top of a file to add a prefix to debug messages */\n+#ifndef pr_fmt\n+#define pr_fmt(fmt) fmt\n+#endif\n+\n+/* Use a default category if this file does not supply one */\n+#ifndef LOG_CATEGORY\n+#define LOG_CATEGORY LOGC_NONE\n+#endif\n+\n+#if CONFIG_VAL(LOG_MAX_LEVEL)\n+#define _LOG_MAX_LEVEL CONFIG_VAL(LOG_MAX_LEVEL)\n+#else\n+#define _LOG_MAX_LEVEL LOGL_INFO\n+#endif\n+\n+/* Emit a log record if the level is less that the maximum */\n+#define log(_cat, _level, _fmt, _args...) ({ \\\n+\tint _l = _level; \\\n+\tif (_l > _LOG_MAX_LEVEL) \\\n+\t\tcontinue; \\\n+\t_log(_cat, _l, __FILE__, __LINE__, __func__, \\\n+\t pr_fmt(_fmt), ##_args); \\\n+\t})\n+\n #ifdef DEBUG\n #define _DEBUG\t1\n #else\n@@ -22,10 +98,19 @@\n #define _SPL_BUILD\t0\n #endif\n \n-/* Define this at the top of a file to add a prefix to debug messages */\n-#ifndef pr_fmt\n-#define pr_fmt(fmt) fmt\n-#endif\n+#if !_DEBUG && CONFIG_IS_ENABLED(LOG)\n+\n+#define debug_cond(cond, fmt, args...)\t\t\t\\\n+\tdo {\t\t\t\t\t\t\\\n+\t\tif (1)\t\t\t\t\\\n+\t\t\tlog(LOG_CATEGORY, LOGL_DEBUG, fmt, ##args); \\\n+\t} while (0)\n+\n+#define error(fmt, args...) do {\t\t\t\t\t\\\n+\t\tlog(LOG_CATEGORY, LOGL_ERR, fmt, ##args); \\\n+} while (0)\n+\n+#else /* _DEBUG */\n \n /*\n * Output a debug text when condition \"cond\" is met. The \"cond\" should be\n@@ -38,6 +123,13 @@\n \t\t\tprintf(pr_fmt(fmt), ##args);\t\\\n \t} while (0)\n \n+#define error(fmt, args...) do {\t\t\t\t\t\\\n+\t\tprintf(\"ERROR: \" pr_fmt(fmt) \"\\nat %s:%d/%s()\\n\",\t\\\n+\t\t\t##args, __FILE__, __LINE__, __func__);\t\t\\\n+} while (0)\n+\n+#endif /* _DEBUG */\n+\n /* Show a message if DEBUG is defined in a file */\n #define debug(fmt, args...)\t\t\t\\\n \tdebug_cond(_DEBUG, fmt, ##args)\n@@ -61,11 +153,6 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,\n \t({ if (!(x) && _DEBUG) \\\n \t\t__assert_fail(#x, __FILE__, __LINE__, __func__); })\n \n-#define error(fmt, args...) do { \\\n-\t\tprintf(\"ERROR: \" pr_fmt(fmt) \"\\nat %s:%d/%s()\\n\", \\\n-\t\t\t##args, __FILE__, __LINE__, __func__); \\\n-} while (0)\n-\n #ifndef BUG\n #define BUG() do { \\\n \tprintf(\"BUG: failure at %s:%d/%s()!\\n\", __FILE__, __LINE__, \\\n@@ -76,4 +163,146 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,\n \t\twhile (0)\n #endif /* BUG */\n \n+/**\n+ * struct log_rec - a single log record\n+ *\n+ * Holds information about a single record in the log\n+ *\n+ * Members marked as 'not allocated' are stored as pointers and the caller is\n+ * responsible for making sure that the data pointed to is not overwritten.\n+ * Memebers marked as 'allocated' are allocated (e.g. via strdup()) by the log\n+ * system.\n+ *\n+ * @cat: Category, representing a uclass or part of U-Boot\n+ * @level: Severity level, less severe is higher\n+ * @file: Name of file where the log record was generated (not allocated)\n+ * @line: Line number where the log record was generated\n+ * @func: Function where the log record was generated (not allocated)\n+ * @msg: Log message (allocated)\n+ */\n+struct log_rec {\n+\tenum log_category_t cat;\n+\tenum log_level_t level;\n+\tconst char *file;\n+\tint line;\n+\tconst char *func;\n+\tconst char *msg;\n+};\n+\n+struct log_device;\n+\n+/**\n+ * struct log_driver - a driver which accepts and processes log records\n+ *\n+ * @name: Name of driver\n+ */\n+struct log_driver {\n+\tconst char *name;\n+\t/**\n+\t * emit() - emit a log record\n+\t *\n+\t * Called by the log system to pass a log record to a particular driver\n+\t * for processing. The filter is checked before calling this function.\n+\t */\n+\tint (*emit)(struct log_device *ldev, struct log_rec *rec);\n+};\n+\n+/**\n+ * struct log_device - an instance of a log driver\n+ *\n+ * Since drivers are set up at build-time we need to have a separate device for\n+ * the run-time aspects of drivers (currently just a list of filters to apply\n+ * to records send to this device).\n+ *\n+ * @next_filter_num: Seqence number of next filter filter added (0=no filters\n+ *\tyet). This increments with each new filter on the device, but never\n+ *\tdecrements\n+ * @drv: Pointer to driver for this device\n+ * @filter_head: List of filters for this device\n+ * @sibling_node: Next device in the list of all devices\n+ */\n+struct log_device {\n+\tint next_filter_num;\n+\tstruct log_driver *drv;\n+\tstruct list_head filter_head;\n+\tstruct list_head sibling_node;\n+};\n+\n+enum {\n+\tLOGF_MAX_CATEGORIES = 5,\t/* maximum categories per filter */\n+};\n+\n+enum log_filter_flags {\n+\tLOGFF_HAS_CAT\t\t= 1 << 0,\t/* Filter has a category list */\n+};\n+\n+/**\n+ * struct log_filter - criterial to filter out log messages\n+ *\n+ * @filter_num: Sequence number of this filter. This is returned when adding a\n+ *\tnew filter, and must be provided when removing a previously added\n+ *\tfilter.\n+ * @flags: Flags for this filter (LOGFF_...)\n+ * @cat_list: List of categories to allow (terminated by LOGC_none). If empty\n+ *\tthen all categories are permitted. Up to LOGF_MAX_CATEGORIES entries\n+ *\tcan be provided\n+ * @max_level: Maximum log level to allow\n+ * @file_list: List of files to allow, separated by comma. If NULL then all\n+ *\tfiles are permitted\n+ * @sibling_node: Next filter in the list of filters for this log device\n+ */\n+struct log_filter {\n+\tint filter_num;\n+\tint flags;\n+\tenum log_category_t cat_list[LOGF_MAX_CATEGORIES];\n+\tenum log_level_t max_level;\n+\tconst char *file_list;\n+\tstruct list_head sibling_node;\n+};\n+\n+#define LOG_DRIVER(_name) \\\n+\tll_entry_declare(struct log_driver, _name, log_driver)\n+\n+/**\n+ * log_add_filter() - Add a new filter to a log device\n+ *\n+ * @drv_name: Driver name to add the filter to (since each driver only has a\n+ *\tsingle device)\n+ * @cat_list: List of categories to allow (terminated by LOGC_none). If empty\n+ *\tthen all categories are permitted. Up to LOGF_MAX_CATEGORIES entries\n+ *\tcan be provided\n+ * @max_level: Maximum log level to allow\n+ * @file_list: List of files to allow, separated by comma. If NULL then all\n+ *\tfiles are permitted\n+ * @return the sequence number of the new filter (>=0) if the filter was added,\n+ *\tor a -ve value on error\n+ */\n+int log_add_filter(const char *drv_name, enum log_category_t cat_list[],\n+\t\t enum log_level_t max_level, const char *file_list);\n+\n+/**\n+ * log_remove_filter() - Remove a filter from a log device\n+ *\n+ * @drv_name: Driver name to remove the filter from (since each driver only has\n+ *\ta single device)\n+ * @filter_num: Filter number to remove (as returned by log_add_filter())\n+ * @return 0 if the filter was removed, -ENOENT if either the driver or the\n+ *\tfilter number was not found\n+ */\n+int log_remove_filter(const char *drv_name, int filter_num);\n+\n+#if CONFIG_IS_ENABLED(LOG)\n+/**\n+ * log_init() - Set up the log system ready for use\n+ *\n+ * @return 0 if OK, -ENOMEM if out of memory\n+ */\n+int log_init(void);\n+#else\n+static inline int log_init(void)\n+{\n+\treturn 0;\n+}\n+#endif\n+\n #endif\n", "prefixes": [ "U-Boot", "06/13" ] }