Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/818790/?format=api
{ "id": 818790, "url": "http://patchwork.ozlabs.org/api/patches/818790/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20170926192142.42308-8-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": "<20170926192142.42308-8-sjg@chromium.org>", "list_archive_url": null, "date": "2017-09-26T19:21:35", "name": "[U-Boot,v2,07/14] log: Add an implemention of logging", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "7621f48a5120f0a1666d2d8dfd3d59e2380d59f0", "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/20170926192142.42308-8-sjg@chromium.org/mbox/", "series": [ { "id": 5217, "url": "http://patchwork.ozlabs.org/api/series/5217/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=5217", "date": "2017-09-26T19:21:28", "name": "log: Add a new logging feature", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/5217/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/818790/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/818790/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=\"efHcDu9u\"; dkim-atps=neutral" ], "Received": [ "from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3y1rVZ6XQxz9t2Q\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 27 Sep 2017 05:24:22 +1000 (AEST)", "by lists.denx.de (Postfix, from userid 105)\n\tid 601F5C21F6C; Tue, 26 Sep 2017 19:22:53 +0000 (UTC)", "from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 9A65BC21E72;\n\tTue, 26 Sep 2017 19:22:38 +0000 (UTC)", "by lists.denx.de (Postfix, from userid 105)\n\tid E8E0DC21F38; Tue, 26 Sep 2017 19:22:23 +0000 (UTC)", "from mail-oi0-f44.google.com (mail-oi0-f44.google.com\n\t[209.85.218.44])\n\tby lists.denx.de (Postfix) with ESMTPS id E0158C21F3C\n\tfor <u-boot@lists.denx.de>; Tue, 26 Sep 2017 19:22:19 +0000 (UTC)", "by mail-oi0-f44.google.com with SMTP id l74so13524775oih.1\n\tfor <u-boot@lists.denx.de>; Tue, 26 Sep 2017 12:22:19 -0700 (PDT)", "from kiwi.bld.corp.google.com ([2620:0:10f2:0:c194:3fa6:8abc:2569])\n\tby smtp.gmail.com with ESMTPSA id\n\tk144sm9072316oih.45.2017.09.26.12.22.17\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tTue, 26 Sep 2017 12:22:17 -0700 (PDT)", "by kiwi.bld.corp.google.com (Postfix, from userid 121222)\n\tid 7C81C140B5C; Tue, 26 Sep 2017 13:22:16 -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_H2,\n\tT_DKIM_INVALID autolearn=unavailable autolearn_force=no\n\tversion=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=cCnFNLrHPlXSq/Y5oQfMt0WnbXS34rkJ5WAFZFO7Jxs=;\n\tb=efHcDu9uVBNC3l6n6Ae30Ac0UOql343NCJgPUeBIeYTl6D+CIsO06xUhFYtQZbV2pr\n\t9snt1pGy10CZxhk7YlEoGQLfZRO0jyjkEyF5zDn/SMsAf7GFvI2xhuoCVhnTWIGSTJ1c\n\teLIQ3UzMfEv0wixUV0Qw7JWxd0dQ9nyghMQKCREa62xvFRIREw1jCt2w3IMsJflXc8Jp\n\tZPv828ZJ80NXt1A9FNUGPDVsZJOyeliCbT1cQRxwQLh4WWa2LZ5Bm42tbWugKAkA+OOI\n\t2zWrIpGFn2HirpHVNfxRf/9YmQhBfOjvlgLtMQBBn5MvuUHEbOXAMD5ul5+P7g+X6dyQ\n\tGFMA==", "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=cCnFNLrHPlXSq/Y5oQfMt0WnbXS34rkJ5WAFZFO7Jxs=;\n\tb=SHHhgD0/SNnVDDlGS81AVTfPXlyojcoWR6E44rMs9mQ97ZVcXUIpTxq5TWRrF32DW/\n\tJZp0qyPxmFSVOqR4nPdAywdyrd2y0FdJQhQ5OSMTAW3jNVdjTRA8n764HeB7OykrU+5N\n\tdy0p0TbHlms3n6KqEyegjpD3njtrHU/Ym3Mj/musKTYPx4uwKHD56Bi8Uqiml3EQE07w\n\tt9KWIegPJZGRg/HRBXx8rASyB9vTUK5JbKhiHPn0FAKdvqv6CDICQXdXsLBVxiW3v8eU\n\t2TlEq6nIHsfGeSJhPCLvsMN7eQgVnioKuOeCIjhdcXIsa12XTfrPzTfLhNjjNRQoW2QM\n\tKKUQ==", "X-Gm-Message-State": "AHPjjUjaxRZuR1htvBhbiZoHc+8YFozk4uJkrcwJTyxPT2Gq87ecjqVZ\n\tJuq+6WpUFAt4kNTp9+iipwRz0Q==", "X-Google-Smtp-Source": "AOwi7QC3MF55ClMxXOhSJWdG3WZ735g9WcSv5N9CCrTyeEeTRP+q/z/pMarcDO6wb/1ZzyrVHkTtrg==", "X-Received": "by 10.202.221.2 with SMTP id u2mr13407060oig.290.1506453738131; \n\tTue, 26 Sep 2017 12:22:18 -0700 (PDT)", "From": "Simon Glass <sjg@chromium.org>", "To": "U-Boot Mailing List <u-boot@lists.denx.de>", "Date": "Tue, 26 Sep 2017 13:21:35 -0600", "Message-Id": "<20170926192142.42308-8-sjg@chromium.org>", "X-Mailer": "git-send-email 2.14.1.992.g2c7b836f3a-goog", "In-Reply-To": "<20170926192142.42308-1-sjg@chromium.org>", "References": "<20170926192142.42308-1-sjg@chromium.org>", "Cc": "Tom Rini <trini@konsulko.com>", "Subject": "[U-Boot] [PATCH v2 07/14] 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\nChanges in v2:\n- Add a comment as to why CONFIG_LOG_MAX_LEVEL is not defined\n- Drop MAINTAINERS entries for files not added by this patch\n- Drop the use of 'continue' in the macro\n- Fix LOG_SPL_MAX_LEVEL typo (should be SPL_LOG_MAX_LEVEL)\n- Fix up bad use of #if CONFIG_VAL() - use #ifdef instead\n- Line up log levels with Linux\n\n MAINTAINERS | 7 ++\n common/Kconfig | 56 +++++++++\n common/Makefile | 1 +\n common/log.c | 244 ++++++++++++++++++++++++++++++++++++\n include/asm-generic/global_data.h | 5 +\n include/log.h | 252 ++++++++++++++++++++++++++++++++++++--\n 6 files changed, 556 insertions(+), 9 deletions(-)\n create mode 100644 common/log.c", "diff": "diff --git a/MAINTAINERS b/MAINTAINERS\nindex 04acf2b89d..3ef97783c0 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -290,6 +290,13 @@ 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+\n MICROBLAZE\n M:\tMichal Simek <monstr@monstr.eu>\n S:\tMaintained\ndiff --git a/common/Kconfig b/common/Kconfig\nindex 540cc9999b..ca4a0f7f9b 100644\n--- a/common/Kconfig\n+++ b/common/Kconfig\n@@ -382,6 +382,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 SPL_LOG_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 801ea3191f..9d52c9623c 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..a7d9a548f2\n--- /dev/null\n+++ b/common/log.c\n@@ -0,0 +1,244 @@\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+\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->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..9488adc8cb 100644\n--- a/include/log.h\n+++ b/include/log.h\n@@ -10,6 +10,87 @@\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_EMERG = 0,\t\t/*U-Boot is unstable */\n+\tLOGL_ALERT,\t\t/* Action must be taken immediately */\n+\tLOGL_CRIT,\t\t/* Critical conditions */\n+\tLOGL_ERR,\t\t/* Error that prevents something from working */\n+\tLOGL_WARNING,\t\t/* Warning may prevent optimial operation */\n+\tLOGL_NOTICE,\t\t/* Normal but significant condition, printf() */\n+\tLOGL_INFO,\t\t/* General information message */\n+\tLOGL_DEBUG,\t\t/* Basic debug-level message */\n+\tLOGL_DEBUG_CONTENT,\t/* Debug message showing full message content */\n+\tLOGL_DEBUG_IO,\t\t/* Debug message showing hardware I/O access */\n+\n+\tLOGL_COUNT,\n+\tLOGL_FIRST = LOGL_EMERG,\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+/*\n+ * This header may be including when CONFIG_LOG is disabled, in which case\n+ * CONFIG_LOG_MAX_LEVEL is not defined. Add a check for this.\n+ */\n+#if CONFIG_IS_ENABLED(LOG)\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\t_log(_cat, _l, __FILE__, __LINE__, __func__, \\\n+\t\t pr_fmt(_fmt), ##_args); \\\n+\t})\n+\n #ifdef DEBUG\n #define _DEBUG\t1\n #else\n@@ -22,10 +103,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 +128,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 +158,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 +168,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", "v2", "07/14" ] }