From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68B4AC43334 for ; Tue, 7 Jun 2022 08:54:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AC988842A6; Tue, 7 Jun 2022 10:54:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Rp9JtTe4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CE40D83C61; Tue, 7 Jun 2022 10:54:14 +0200 (CEST) Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4EEAA842E0 for ; Tue, 7 Jun 2022 10:54:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x32b.google.com with SMTP id 67-20020a1c1946000000b00397382b44f4so9153041wmz.2 for ; Tue, 07 Jun 2022 01:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9wLCcylrFcFSaanRQ1Nx8dBneOsPHy8Max/kcscc57Q=; b=Rp9JtTe4MDLtHVdDc8Mo4rXOHjrp3CAqXNmKt/k2DVd06CmclJKBsH5LzF8omK/Pyv OKnbwnJ9K5BO6efcukIBqQ6NqGrlDdL2JDkict+Ia1h9u8za8CivVTII8qKO8SiSVpDG h6qSIJeXWxTrlaJrYHQbZbOT03OfrsIlZoBKuTrHt69KiL0828AQxps0AjIAwZOXgcW9 VX9rs4fkf5l+MCMosgA8fIoIE0R24jn+vbTj/PDongosyy4u0W2tS4uZrYPzcoz5Dk8s iZ+E39lpk4C6W0G7ljiZCUe+HLPZ3siz4YqfNPIdQ6voT1mwFmv0a7xNyY8rugPiitvX BKsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9wLCcylrFcFSaanRQ1Nx8dBneOsPHy8Max/kcscc57Q=; b=EEe+qP8H/H+3JTBA9NROv9K8rM9eShw8mxJsWkK4uCt0mOKvpSWvqgOEu+PYsAzLHJ vAmlQ3tJDIBAnXR+6Nvl3VopfbmsVzXWqOpYRqDoyaW1wOFtgF9yFVD2tecD4NvG2L9x Jo3xq1m0e7kekS01o4NY/4W/Sb3MmqePVlkzStEDhb5L1uBe9PwLiEcLm2CxtDch6bze KW4nBSJx+/PqDm6g/2qrzfVi/js47r2s9pHfkp3zRC7EUy+CcxJeHCsIoTPq1pE9FoRZ EuS3bJ/EVgdIV98zVlejBZaClaU+eIi6fIeYPIbuhy55evaUvLZDEB4bc7hI78pbfxTe qAuA== X-Gm-Message-State: AOAM532hixqWO6AGBThKXcW2j+WJ+rffvhKo3Ke/wB5A4CuiHU7TpxcB hyGNhCUjd0xIFwTVPNFuBdyaXA== X-Google-Smtp-Source: ABdhPJwrLu+LR85a0c0vJRCI347I3c2dFymOW9/SSFmsxfMvfT+a4ijR3Yb54O8SlIa+D3KaLLbKQw== X-Received: by 2002:a7b:cd83:0:b0:39c:46d2:6ebb with SMTP id y3-20020a7bcd83000000b0039c46d26ebbmr16754315wmj.187.1654592050893; Tue, 07 Jun 2022 01:54:10 -0700 (PDT) Received: from hera (ppp089210241233.access.hol.gr. [89.210.241.233]) by smtp.gmail.com with ESMTPSA id l14-20020adfe58e000000b002117ef160fbsm17143051wrm.21.2022.06.07.01.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 01:54:10 -0700 (PDT) Date: Tue, 7 Jun 2022 11:54:08 +0300 From: Ilias Apalodimas To: Simon Glass Cc: U-Boot Mailing List Subject: Re: [PATCH 7/8] tpm: Implement state command for Cr50 Message-ID: References: <20220301001125.1554442-1-sjg@chromium.org> <20220301001125.1554442-8-sjg@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220301001125.1554442-8-sjg@chromium.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On Mon, Feb 28, 2022 at 05:11:24PM -0700, Simon Glass wrote: > Add a vendor-specific TPM2 command for this and implement it for Cr50. > > Signed-off-by: Simon Glass > --- > > drivers/tpm/cr50_i2c.c | 117 +++++++++++++++++++++++++++++++++++++++++ > include/tpm-v2.h | 54 +++++++++++++++++++ > lib/tpm-v2.c | 24 +++++++++ > 3 files changed, 195 insertions(+) > > diff --git a/drivers/tpm/cr50_i2c.c b/drivers/tpm/cr50_i2c.c > index f8c3087894..dabf617be0 100644 > --- a/drivers/tpm/cr50_i2c.c > +++ b/drivers/tpm/cr50_i2c.c > @@ -13,11 +13,13 @@ > #include > #include > #include > +#include > #include > #include > #include > #include > #include > +#include > #include > #include > > @@ -54,6 +56,41 @@ struct cr50_priv { > bool use_irq; > }; > > +/* > + * The below structure represents the body of the response to the 'report tpm > + * state' vendor command. > + * > + * It is transferred over the wire, so it needs to be serialized/deserialized, > + * and it is likely to change, so its contents must be versioned. > + */ > +#define TPM_STATE_VERSION 1 > +struct tpm_vendor_state { > + u32 version; > + /* > + * The following three fields are set by the TPM in case of an assert. > + * There is no other processing than setting the source code line > + * number, error code and the first 4 characters of the function name. > + * > + * We don't expect this happening, but it is included in the report > + * just in case. > + */ > + u32 fail_line; /* s_failLIne */ > + u32 fail_code; /* s_failCode */ > + char func_name[4]; /* s_failFunction, limited to 4 chars */ > + > + /* > + * The following two fields are the current time filtered value of the > + * 'failed tries' TPM counter, and the maximum allowed value of the > + * counter. > + * > + * failed_tries == max_tries is the definition of the TPM lockout > + * condition. > + */ > + u32 failed_tries; /* gp.failedTries */ > + u32 max_tries; /* gp.maxTries */ > + /* The below fields are present in version 2 and above */ > +}; > + > /* Wait for interrupt to indicate TPM is ready */ > static int cr50_i2c_wait_tpm_ready(struct udevice *dev) > { > @@ -573,6 +610,85 @@ static int cr50_i2c_get_desc(struct udevice *dev, char *buf, int size) > return len; > } > > +static int stringify_state(char *buf, int len, char *str, size_t max_size) > +{ > + struct tpm_vendor_state state; > + size_t text_size = 0; > + > + state.version = get_unaligned_be32(buf + > + offsetof(struct tpm_vendor_state, version)); > + state.fail_line = get_unaligned_be32(buf + > + offsetof(struct tpm_vendor_state, fail_line)); > + state.fail_code = get_unaligned_be32(buf + > + offsetof(struct tpm_vendor_state, fail_code)); > + memcpy(state.func_name, > + buf + offsetof(struct tpm_vendor_state, func_name), > + sizeof(state.func_name)); > + state.failed_tries = get_unaligned_be32(buf + > + offsetof(struct tpm_vendor_state, failed_tries)); > + state.max_tries = get_unaligned_be32(buf + > + offsetof(struct tpm_vendor_state, max_tries)); > + > + text_size += snprintf(str + text_size, max_size - text_size, > + "v=%d", state.version); > + if (text_size >= max_size) > + return -ENOSPC; > + > + if (state.version > TPM_STATE_VERSION) > + text_size += snprintf(str + text_size, > + max_size - text_size, > + " not fully supported\n"); > + if (text_size >= max_size) > + return -ENOSPC; > + > + if (state.version == 0) > + return -EINVAL; /* This should never happen */ > + > + text_size += snprintf(str + text_size, > + max_size - text_size, > + " failed_tries=%d max_tries=%d\n", > + state.failed_tries, state.max_tries); > + if (text_size >= max_size) > + return -ENOSPC; > + > + if (state.fail_line) { > + /* make sure function name is zero terminated. */ > + char func_name[sizeof(state.func_name) + 1]; > + > + memcpy(func_name, state.func_name, sizeof(state.func_name)); > + func_name[sizeof(state.func_name)] = '\0'; > + > + text_size += snprintf(str + text_size, > + max_size - text_size, > + "tpm failed: f %s line %d code %d", > + func_name, > + state.fail_line, > + state.fail_code); > + if (text_size >= max_size) > + return -ENOSPC; > + } > + > + return 0; > +} Is this error state described in the TCG TIS specs ? If so we should plug this into the generic TPM API and the driver should only define cr50_i2c_report_state() etc > + > +static int cr50_i2c_report_state(struct udevice *dev, char *str, int str_max) > +{ > + char buf[50]; > + int buf_size = sizeof(buf); > + int ret; > + > + ret = tpm2_cr50_report_state(dev, buf, &buf_size); > + if (ret) > + return ret; > + > + /* TPM responded as expected */ > + ret = stringify_state(buf, buf_size, str, str_max); > + if (ret) > + return ret; > + > + return 0; > +} > + [...] Thanks /Ilias