Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2230151/?format=api
{ "id": 2230151, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2230151/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20260429134142.3.db7fbeb8b6e8499f4d031c04cb5cd8175873b643@changeid/", "project": { "id": 18, "url": "http://patchwork.ozlabs.org/api/1.1/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 }, "msgid": "<20260429134142.3.db7fbeb8b6e8499f4d031c04cb5cd8175873b643@changeid>", "date": "2026-04-29T11:41:43", "name": "[3/3] tpm: allocate tpm event log if missing", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "4593464a8b59a7a31ec6d09583019ac7e2fdae24", "submitter": { "id": 90265, "url": "http://patchwork.ozlabs.org/api/1.1/people/90265/?format=api", "name": "Ludwig Nussel", "email": "ludwig.nussel@siemens.com" }, "delegate": { "id": 96103, "url": "http://patchwork.ozlabs.org/api/1.1/users/96103/?format=api", "username": "apalos", "first_name": "Ilias", "last_name": "Apalodimas", "email": "apalos@gmail.com" }, "mbox": "http://patchwork.ozlabs.org/project/uboot/patch/20260429134142.3.db7fbeb8b6e8499f4d031c04cb5cd8175873b643@changeid/mbox/", "series": [ { "id": 502040, "url": "http://patchwork.ozlabs.org/api/1.1/series/502040/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=502040", "date": "2026-04-29T11:41:40", "name": "Improve U-Boot's TPM handling in the non-EFI case", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/502040/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2230151/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2230151/checks/", "tags": {}, "headers": { "Return-Path": "<u-boot-bounces@lists.denx.de>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=siemens.com header.i=ludwig.nussel@siemens.com\n header.a=rsa-sha256 header.s=fm2 header.b=lXbzWWul;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=85.214.62.61; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)", "phobos.denx.de;\n dmarc=pass (p=reject dis=none) header.from=siemens.com", "phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de", "phobos.denx.de;\n\tdkim=pass (2048-bit key;\n secure) header.d=siemens.com header.i=ludwig.nussel@siemens.com\n header.b=\"lXbzWWul\";\n\tdkim-atps=neutral", "phobos.denx.de;\n dmarc=pass (p=reject dis=none) header.from=siemens.com", "phobos.denx.de;\n spf=pass smtp.mailfrom=ludwig.nussel@siemens.com" ], "Received": [ "from phobos.denx.de (phobos.denx.de [85.214.62.61])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g5Fn14CtMz1yHX\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 21:43:33 +1000 (AEST)", "from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id 8B42884837;\n\tWed, 29 Apr 2026 13:43:18 +0200 (CEST)", "by phobos.denx.de (Postfix, from userid 109)\n id A214284849; Wed, 29 Apr 2026 13:43:15 +0200 (CEST)", "from mta-64-226.siemens.flowmailer.net\n (mta-64-226.siemens.flowmailer.net [185.136.64.226])\n (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 47F658483A\n for <u-boot@lists.denx.de>; Wed, 29 Apr 2026 13:43:13 +0200 (CEST)", "by mta-64-226.siemens.flowmailer.net with ESMTPSA id\n 20260429114313079ee54053000207db for <u-boot@lists.denx.de>;\n Wed, 29 Apr 2026 13:43:13 +0200" ], "X-Spam-Checker-Version": "SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de", "X-Spam-Level": "", "X-Spam-Status": "No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED,\n DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,\n RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,\n SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.2", "DKIM-Signature": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm2;\n d=siemens.com; i=ludwig.nussel@siemens.com;\n h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To;\n bh=aBPoPLzIxCJlV/gVXzT4T8wgDJj+kcxBlRbOjAUB5rU=;\n b=lXbzWWullAiNd9ePRAWSrowUjoVYC+Yb26DGU6xF4tNeh1y7teQ1xAsrMNRF1efckgL23c\n XNsvmlD1cOwWgAsKccEf2xXiSG0SY9YNyfnK4niXpiplcTnd9oe802cEAVAKQ/06TN2HLtSN\n XVKnSG42WsGJOXC5ZRe909KRQIOAt30Jm3rM/OY6R2Lv53l0DDyEn9yTaAx+Hg+zwAe6+nTE\n 842plpSHs/OnLQQ942CSMB76ulsb9HeDwqnr8ETXlD0CsO6Kwkf/2J1JvDfmpV0ROf8cq8M2\n VhgsCZnK0Tc8+wxNjyPZZztUSmIkc+i5YxOtbEZlb9PiK7KlpRJ3PveQ==;", "From": "Ludwig Nussel <ludwig.nussel@siemens.com>", "To": "u-boot@lists.denx.de", "Cc": "Ludwig Nussel <ludwig.nussel@siemens.com>, Anshul Dalal <anshuld@ti.com>,\n Aristo Chen <jj251510319013@gmail.com>, Benjamin ROBIN <dev@benjarobin.fr>,\n George Chan <gchan9527@gmail.com>, Heiko Schocher <hs@nabladev.com>,\n Heinrich Schuchardt <xypron.glpk@gmx.de>,\n Ilias Apalodimas <ilias.apalodimas@linaro.org>, =?utf-8?q?Jo=C3=A3o_Paulo_G?=\n\t=?utf-8?q?on=C3=A7alves?= <joao.goncalves@toradex.com>,\n \"Kory Maincent (TI.com)\" <kory.maincent@bootlin.com>,\n Marek Vasut <marek.vasut+renesas@mailbox.org>,\n Martin Schwan <m.schwan@phytec.de>,\n Mattijs Korpershoek <mkorpershoek@kernel.org>, Peng Fan <peng.fan@nxp.com>,\n Quentin Schulz <quentin.schulz@cherry.de>, Simon Glass <sjg@chromium.org>,\n Sughosh Ganu <sughosh.ganu@arm.com>, Tom Rini <trini@konsulko.com>", "Subject": "[PATCH 3/3] tpm: allocate tpm event log if missing", "Date": "Wed, 29 Apr 2026 13:41:43 +0200", "Message-ID": "\n <20260429134142.3.db7fbeb8b6e8499f4d031c04cb5cd8175873b643@changeid>", "In-Reply-To": "<20260429114250.791663-1-ludwig.nussel@siemens.com>", "References": "<20260429114250.791663-1-ludwig.nussel@siemens.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-Flowmailer-Platform": "Siemens", "Feedback-ID": "519:519-1328817:519-21489:flowmailer", "X-BeenThere": "u-boot@lists.denx.de", "X-Mailman-Version": "2.1.39", "Precedence": "list", "List-Id": "U-Boot discussion <u-boot.lists.denx.de>", "List-Unsubscribe": "<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>", "List-Archive": "<https://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 <mailto:u-boot-request@lists.denx.de?subject=subscribe>", "Errors-To": "u-boot-bounces@lists.denx.de", "Sender": "\"U-Boot\" <u-boot-bounces@lists.denx.de>", "X-Virus-Scanned": "clamav-milter 0.103.8 at phobos.denx.de", "X-Virus-Status": "Clean" }, "content": "Allocate and attach the TPM event log to the TPM device if not\ninitialized yet. The address is copied into the device tree for the\nkernel so the event log is accessible from Linux userspace too.\n\nSigned-off-by: Ludwig Nussel <ludwig.nussel@siemens.com>\n\n---\n\n boot/Kconfig | 1 +\n boot/bootm.c | 18 +++-----\n boot/image-fdt.c | 67 ++++++++++++++++++++++++++++\n include/tpm-common.h | 1 +\n include/tpm_tcg2.h | 9 ++--\n lib/tpm_tcg2.c | 101 +++++++++++++++++++++++++++++++++----------\n 6 files changed, 160 insertions(+), 37 deletions(-)", "diff": "diff --git a/boot/Kconfig b/boot/Kconfig\nindex ae6f09a6ede..a4e23f9c78a 100644\n--- a/boot/Kconfig\n+++ b/boot/Kconfig\n@@ -1041,6 +1041,7 @@ config MEASURED_BOOT\n \tselect SHA384\n \tselect SHA512\n \tselect SM3\n+\tselect DEVRES\n \thelp\n \t This option enables measurement of the boot process when booting\n \t without UEFI . Measurement involves creating cryptographic hashes\ndiff --git a/boot/bootm.c b/boot/bootm.c\nindex 4836d6b2d41..701ec010e01 100644\n--- a/boot/bootm.c\n+++ b/boot/bootm.c\n@@ -921,23 +921,19 @@ int bootm_measure(struct bootm_headers *images)\n \t\treturn ret;\n \n \tif (IS_ENABLED(CONFIG_MEASURED_BOOT)) {\n-\t\tstruct tcg2_event_log elog;\n \t\tstruct udevice *dev;\n \t\tvoid *initrd_buf;\n \t\tvoid *image_buf;\n \t\tconst char *s;\n \t\tu32 rd_len;\n-\t\tbool ign;\n \n-\t\telog.log_size = 0;\n-\t\tign = IS_ENABLED(CONFIG_MEASURE_IGNORE_LOG);\n-\t\tret = tcg2_measurement_init(&dev, &elog, ign);\n-\t\tif (ret)\n+\t\tret = tcg2_measurement_init(&dev, NULL);\n+\t\tif (ret && ret != -EEXIST)\n \t\t\treturn ret;\n \n \t\timage_buf = map_sysmem(images->os.image_start,\n \t\t\t\t images->os.image_len);\n-\t\tret = tcg2_measure_data(dev, &elog, 8, images->os.image_len,\n+\t\tret = tcg2_measure_data(dev, NULL, 8, images->os.image_len,\n \t\t\t\t\timage_buf, EV_COMPACT_HASH,\n \t\t\t\t\tstrlen(\"linux\") + 1, (u8 *)\"linux\");\n \t\tif (ret)\n@@ -945,14 +941,14 @@ int bootm_measure(struct bootm_headers *images)\n \n \t\trd_len = images->rd_end - images->rd_start;\n \t\tinitrd_buf = map_sysmem(images->rd_start, rd_len);\n-\t\tret = tcg2_measure_data(dev, &elog, 9, rd_len, initrd_buf,\n+\t\tret = tcg2_measure_data(dev, NULL, 9, rd_len, initrd_buf,\n \t\t\t\t\tEV_COMPACT_HASH, strlen(\"initrd\") + 1,\n \t\t\t\t\t(u8 *)\"initrd\");\n \t\tif (ret)\n \t\t\tgoto unmap_initrd;\n \n \t\tif (IS_ENABLED(CONFIG_MEASURE_DEVICETREE)) {\n-\t\t\tret = tcg2_measure_data(dev, &elog, 1, images->ft_len,\n+\t\t\tret = tcg2_measure_data(dev, NULL, 1, images->ft_len,\n \t\t\t\t\t\t(u8 *)images->ft_addr,\n \t\t\t\t\t\tEV_TABLE_OF_DEVICES,\n \t\t\t\t\t\tstrlen(\"dts\") + 1,\n@@ -964,7 +960,7 @@ int bootm_measure(struct bootm_headers *images)\n \t\ts = env_get(\"bootargs\");\n \t\tif (!s)\n \t\t\ts = \"\";\n-\t\tret = tcg2_measure_data(dev, &elog, 1, strlen(s) + 1, (u8 *)s,\n+\t\tret = tcg2_measure_data(dev, NULL, 1, strlen(s) + 1, (u8 *)s,\n \t\t\t\t\tEV_PLATFORM_CONFIG_FLAGS,\n \t\t\t\t\tstrlen(s) + 1, (u8 *)s);\n \n@@ -973,7 +969,7 @@ unmap_initrd:\n \n unmap_image:\n \t\tunmap_sysmem(image_buf);\n-\t\ttcg2_measurement_term(dev, &elog, ret != 0);\n+\t\ttcg2_measurement_term(dev, NULL, ret != 0);\n \t}\n \n \treturn ret;\ndiff --git a/boot/image-fdt.c b/boot/image-fdt.c\nindex a3a4fb8b558..f9cab464452 100644\n--- a/boot/image-fdt.c\n+++ b/boot/image-fdt.c\n@@ -24,6 +24,10 @@\n #include <asm/io.h>\n #include <dm/ofnode.h>\n #include <tee/optee.h>\n+#if defined(CONFIG_MEASURED_BOOT)\n+#include <tpm_tcg2.h>\n+#include <dm/device.h>\n+#endif\n \n DECLARE_GLOBAL_DATA_PTR;\n \n@@ -589,6 +593,67 @@ __weak int arch_fixup_fdt(void *blob)\n \treturn 0;\n }\n \n+static int copy_tpm_event_log(void *blob)\n+{\n+#if defined(CONFIG_MEASURED_BOOT)\n+\tint rc;\n+\tstruct udevice *dev;\n+\tofnode node;\n+\tchar path[256];\n+\tchar *end;\n+\tstruct tcg2_event_log *log;\n+\n+\trc = tcg2_platform_get_tpm2(&dev);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tlog = tcg2_platform_get_dev_log(dev);\n+\n+\tif (!log || !log->allocated) {\n+\t\tlog_debug(\"tpm event log not allocated\\n\");\n+\t\treturn -ENOENT;\n+\t}\n+\n+\tnode = dev_ofnode(dev);\n+\tif (!ofnode_valid(node)) {\n+\t\tlog_err(\"tpm %p has no device tree representation\\n\", dev);\n+\t\treturn -ENOENT;\n+\t}\n+\n+\trc = ofnode_get_path(node, path, sizeof(path));\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tif (fdt_path_offset(blob, path) < 0) {\n+\t\tlog_warning(\"kernel device tree lacks %s\\n\", path);\n+\t\treturn 0;\n+\t}\n+\n+\tstrlcat(path, \"/linux,sml-base\", sizeof(path));\n+\tif (fdt_path_offset(blob, path) >= 0) {\n+\t\tlog_warning(\"kernel dt already defines an event log address at %s\\n\", path);\n+\t\treturn 0;\n+\t}\n+\tend = strrchr(path, '/');\n+\t*end = 0;\n+\n+\tfdt64_t a = cpu_to_fdt64((u64)virt_to_phys(log->log));\n+\tfdt32_t s = cpu_to_fdt32((u32)log->log_position);\n+\n+\trc = fdt_find_and_setprop(blob, path, \"linux,sml-base\", &a, sizeof(a), 1);\n+\tif (rc) {\n+\t\tlog_err(\"failed to set sml-base: %d\\n\", rc);\n+\t\treturn rc;\n+\t}\n+\trc = fdt_find_and_setprop(blob, path, \"linux,sml-size\", &s, sizeof(s), 1);\n+\tif (rc) {\n+\t\tlog_err(\"failed to set sml-size: %d\\n\", rc);\n+\t\treturn rc;\n+\t}\n+#endif\n+\treturn 0;\n+}\n+\n int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb)\n {\n \tulong *initrd_start = &images->initrd_start;\n@@ -631,6 +696,8 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb)\n \t\tgoto err;\n \t}\n \n+\tcopy_tpm_event_log(blob);\n+\n \t/* Store name of configuration node as u-boot,bootconf in /chosen node */\n \tif (images->fit_uname_cfg)\n \t\tfdt_find_and_setprop(blob, \"/chosen\", \"u-boot,bootconf\",\ndiff --git a/include/tpm-common.h b/include/tpm-common.h\nindex bfb84a931d1..f02dae679bd 100644\n--- a/include/tpm-common.h\n+++ b/include/tpm-common.h\n@@ -83,6 +83,7 @@ struct tpm_chip_priv {\n \tu32 active_banks[TPM2_NUM_PCR_BANKS];\n #endif\n \tbool plat_hier_disabled;\n+\tvoid *log; /* struct tcg2_event_log */\n };\n \n /**\ndiff --git a/include/tpm_tcg2.h b/include/tpm_tcg2.h\nindex eb6afe49e77..db3f6f486e9 100644\n--- a/include/tpm_tcg2.h\n+++ b/include/tpm_tcg2.h\n@@ -162,12 +162,14 @@ struct tcg_efi_spec_id_event {\n * @log_position:\tCurrent entry position\n * @log_size:\t\tLog space available\n * @found:\t\tBoolean indicating if an existing log was discovered\n+ * @allocated:\t\tBoolean indicating that the log was allocated by u-boot\n */\n struct tcg2_event_log {\n \tu8 *log;\n \tu32 log_position;\n \tu32 log_size;\n \tbool found;\n+\tbool allocated;\n };\n \n /**\n@@ -291,13 +293,10 @@ int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,\n *\t\t\tmemory region, in which case any existing log\n *\t\t\tdiscovered will be copied to the specified memory\n *\t\t\tregion.\n- * @ignore_existing_log Boolean to indicate whether or not to ignore an\n- *\t\t\texisting platform log in memory\n *\n * Return: zero on success, negative errno otherwise\n */\n-int tcg2_measurement_init(struct udevice **dev, struct tcg2_event_log *elog,\n-\t\t\t bool ignore_existing_log);\n+int tcg2_measurement_init(struct udevice **dev, struct tcg2_event_log *elog);\n \n /**\n * Stop measurements and record separator events.\n@@ -345,4 +344,6 @@ void tcg2_platform_startup_error(struct udevice *dev, int rc);\n */\n u32 tcg2_algorithm_to_mask(enum tpm2_algorithms);\n \n+struct tcg2_event_log *tcg2_platform_get_dev_log(struct udevice *dev);\n+\n #endif /* __TPM_TCG_V2_H */\ndiff --git a/lib/tpm_tcg2.c b/lib/tpm_tcg2.c\nindex d41228f75a9..4ea4b6d992f 100644\n--- a/lib/tpm_tcg2.c\n+++ b/lib/tpm_tcg2.c\n@@ -21,6 +21,7 @@\n #include <linux/unaligned/le_byteshift.h>\n #include \"tpm-utils.h\"\n #include <bloblist.h>\n+#include <dm/devres.h>\n \n int tcg2_get_pcr_info(struct udevice *dev, u32 *supported_bank, u32 *active_bank,\n \t\t u32 *bank_num)\n@@ -212,6 +213,9 @@ static int tcg2_log_append_check(struct tcg2_event_log *elog, u32 pcr_index,\n \tu32 event_size;\n \tu8 *log;\n \n+\tif (!elog->log_size)\n+\t\treturn 0;\n+\n \tevent_size = size + tcg2_event_get_size(digest_list);\n \tif (elog->log_position + event_size > elog->log_size) {\n \t\tprintf(\"%s: log too large: %u + %u > %u\\n\", __func__,\n@@ -542,6 +546,14 @@ int tcg2_measure_data(struct udevice *dev, struct tcg2_event_log *elog,\n \tstruct tpml_digest_values digest_list;\n \tint rc;\n \n+\tif (!elog)\n+\t\telog = tcg2_platform_get_dev_log(dev);\n+\n+\tif (!elog) {\n+\t\tlog_err(\"no event log allocated\");\n+\t\treturn -ENOENT;\n+\t}\n+\n \tif (data)\n \t\trc = tcg2_create_digest(dev, data, size, &digest_list);\n \telse\n@@ -564,11 +576,29 @@ int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,\n \tint rc;\n \tu32 log_active = 0;\n \n-\telog->log_position = 0;\n-\telog->found = false;\n+\tif (elog) {\n+\t\telog->log_position = 0;\n+\t\telog->found = false;\n+\t\telog->allocated = false;\n+\t} else if (tcg2_platform_get_dev_log(dev)) {\n+\t\treturn -EEXIST;\n+\t}\n \n \trc = tcg2_platform_get_log(dev, (void **)&log.log, &log.log_size);\n-\tif (!rc) {\n+\t/* no existing event log found and none allocated yet */\n+\tif (rc && !elog) {\n+\t\t/* magic size value. Same as in acpi_table.c */\n+\t\tlog.log_size = 0x10000;\n+\t\tlog.log = devm_kzalloc(dev, log.log_size, 0);\n+\t\tif (log.log) {\n+\t\t\tlog.allocated = true;\n+\t\t\tignore_existing_log = true;\n+\t\t} else {\n+\t\t\tlog_err(\"Failed to allocate %u bytes event log\\n\", log.log_size);\n+\t\t}\n+\t}\n+\n+\tif (log.log) {\n \t\tlog.log_position = 0;\n \t\tlog.found = false;\n \n@@ -580,26 +610,40 @@ int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,\n \t\t\t\treturn rc;\n \t\t}\n \n-\t\tif (elog->log_size) {\n-\t\t\tif (log.found) {\n-\t\t\t\tif (elog->log_size < log.log_position)\n-\t\t\t\t\treturn -ENOBUFS;\n-\n-\t\t\t\t/*\n-\t\t\t\t * Copy the discovered log into the user buffer\n-\t\t\t\t * if there's enough space.\n-\t\t\t\t */\n-\t\t\t\tmemcpy(elog->log, log.log, log.log_position);\n+\t\tif (elog) {\n+\t\t\tif (elog->log_size) {\n+\t\t\t\tif (log.found) {\n+\t\t\t\t\tif (elog->log_size < log.log_position)\n+\t\t\t\t\t\treturn -ENOBUFS;\n+\n+\t\t\t\t\t/*\n+\t\t\t\t\t * Copy the discovered log into the user buffer\n+\t\t\t\t\t * if there's enough space.\n+\t\t\t\t\t */\n+\t\t\t\t\tmemcpy(elog->log, log.log, log.log_position);\n+\t\t\t\t}\n+\n+\t\t\t\tunmap_physmem(log.log, MAP_NOCACHE);\n+\t\t\t} else {\n+\t\t\t\telog->log = log.log;\n+\t\t\t\telog->log_size = log.log_size;\n \t\t\t}\n \n-\t\t\tunmap_physmem(log.log, MAP_NOCACHE);\n+\t\t\telog->log_position = log.log_position;\n+\t\t\telog->found = log.found;\n \t\t} else {\n+\t\t\tstruct tpm_chip_priv *priv = dev_get_uclass_priv(dev);\n+\n+\t\t\telog = devm_kzalloc(dev, sizeof(struct tcg2_event_log), 0);\n+\n \t\t\telog->log = log.log;\n \t\t\telog->log_size = log.log_size;\n-\t\t}\n+\t\t\telog->log_position = log.log_position;\n+\t\t\telog->found = log.found;\n+\t\t\telog->allocated = log.allocated;\n \n-\t\telog->log_position = log.log_position;\n-\t\telog->found = log.found;\n+\t\t\tpriv->log = elog;\n+\t\t}\n \t}\n \n pcr_allocate:\n@@ -612,14 +656,15 @@ pcr_allocate:\n \t * valid. User's can pass in their own buffer as a fallback if no\n \t * memory region is found.\n \t */\n-\tif (!elog->found && elog->log_size)\n-\t\trc = tcg2_log_init(dev, elog);\n+\tif (elog) {\n+\t\tif (!elog->found && elog->log_size)\n+\t\t\trc = tcg2_log_init(dev, elog);\n+\t}\n \n \treturn rc;\n }\n \n-int tcg2_measurement_init(struct udevice **dev, struct tcg2_event_log *elog,\n-\t\t\t bool ignore_existing_log)\n+int tcg2_measurement_init(struct udevice **dev, struct tcg2_event_log *elog)\n {\n \tint rc;\n \n@@ -627,11 +672,14 @@ int tcg2_measurement_init(struct udevice **dev, struct tcg2_event_log *elog,\n \tif (rc)\n \t\treturn rc;\n \n+\tif (!elog && tcg2_platform_get_dev_log(*dev))\n+\t\treturn -EEXIST;\n+\n \trc = tpm_auto_start(*dev);\n \tif (rc)\n \t\treturn rc;\n \n-\trc = tcg2_log_prepare_buffer(*dev, elog, ignore_existing_log);\n+\trc = tcg2_log_prepare_buffer(*dev, elog, IS_ENABLED(CONFIG_MEASURE_IGNORE_LOG));\n \tif (rc) {\n \t\ttcg2_measurement_term(*dev, elog, true);\n \t\treturn rc;\n@@ -662,6 +710,15 @@ void tcg2_measurement_term(struct udevice *dev, struct tcg2_event_log *elog,\n \t\tunmap_physmem(elog->log, MAP_NOCACHE);\n }\n \n+struct tcg2_event_log *tcg2_platform_get_dev_log(struct udevice *dev)\n+{\n+\tstruct tpm_chip_priv *priv;\n+\n+\tpriv = dev_get_uclass_priv(dev);\n+\n+\treturn priv->log;\n+}\n+\n __weak int tcg2_platform_get_log(struct udevice *dev, void **addr, u32 *size)\n {\n \tconst __be32 *addr_prop = NULL;\n", "prefixes": [ "3/3" ] }