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 0BAECC28D13 for ; Mon, 22 Aug 2022 06:00:48 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 626D984133; Mon, 22 Aug 2022 08:00:46 +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="YyMN4rmj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F23ED841D7; Mon, 22 Aug 2022 08:00:44 +0200 (CEST) Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) (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 D3AE38410A for ; Mon, 22 Aug 2022 08:00:41 +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-yw1-x1132.google.com with SMTP id 00721157ae682-33365a01f29so264881727b3.2 for ; Sun, 21 Aug 2022 23:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=NzPdx22x0ZUXyWBoNysqlEXxsu/gTmmv02gp0hSpLwo=; b=YyMN4rmjkBryi2PLCw6aJaLA4YlDu26Jl9ZoUWtna4IcS2CxhXS0xdDb/O60lrG2H+ YJAIz/8vByMbK1AYk5EL59HpkYGh3ynK2OjD8WK9icBys5fOp+NBBVOT2A4842Jq9idC owv0n9b5TKEI5Q8GFU31ZyDh4+DaEkZr4wO7lGWJxW1M0mbXLRQ61CTdZWseyaeKIqzo 8i+iP2LKP3p8s/w/YsX5QB66VImu1uFAnIC26QSCgxZ7Mvv1VCCt8VAUoBlFd6ByvSTr cxVwrbrGiSWLuL9+wy2l8WDT2lkdcLsbOqw+N9YswTRYk9Q1CgqKnFG7Q1FcP/ffwSx8 hxAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=NzPdx22x0ZUXyWBoNysqlEXxsu/gTmmv02gp0hSpLwo=; b=sf0NxLTfuofnC5RqgBtAmINeqsOtg0yg+RaDMLboh/4wLM/3q9Nvof7Wx8OawgiL8X Z3Fohy4jNRR29f/LrFoxcISVaYv3CPEhR3yoAKX8CRiDKxXkc0GWMXHDYG2/JWt3Yetv Siz7zeZS7Swx+bDTkP40n+cBRTkfY3bn9jpHCk3qJ/5fBHbCHWHwnHguIgKGBXe74+qV K/NUqvlqyhrqyb+TmQwMO2A6S41cL7IFGoJoOZkR4pBAv1CiIC8SO3+CSC2LspzJJvZi a2P1uwIElGmxtUudpVULFYG9wktEpgFHEqD4xcmdkmIaMeeneZA6hGBt2eXGmGJsDe34 xUyA== X-Gm-Message-State: ACgBeo0gAmUzW8kQLu0nvuQ64lOPqsrHi7wUfjzBsDUbhtwccWiUSkzb itwKMn/iHIq3YXX/aUAGYqnT0LjP61MgkLzBR+TFtQ== X-Google-Smtp-Source: AA6agR5J6Rz4pFv1XmKsjKrcmOugpWfjJqB8tstqtJn4JOVha6zsr1wS0BefSRMDGl+dgZO50C7jxnWARvvmnf0j/sk= X-Received: by 2002:a25:b44a:0:b0:695:bd50:9c2d with SMTP id c10-20020a25b44a000000b00695bd509c2dmr2038072ybg.495.1661148040295; Sun, 21 Aug 2022 23:00:40 -0700 (PDT) MIME-Version: 1.0 References: <20220813195639.1824765-1-sjg@chromium.org> <20220813195639.1824765-7-sjg@chromium.org> In-Reply-To: From: Ilias Apalodimas Date: Mon, 22 Aug 2022 09:00:03 +0300 Message-ID: Subject: Re: [PATCH v2 6/7] tpm: Implement state command for Cr50 To: Simon Glass Cc: U-Boot Mailing List , Heinrich Schuchardt , Masahisa Kojima , Ruchika Gupta Content-Type: text/plain; charset="UTF-8" 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.6 at phobos.denx.de X-Virus-Status: Clean Hi Simon, On Fri, 19 Aug 2022 at 16:47, Simon Glass wrote: > > Hi Ilias, > > On Thu, 18 Aug 2022 at 01:29, Ilias Apalodimas > wrote: > > > > Hi Simon, > > > > On Wed, 17 Aug 2022 at 21:54, Simon Glass wrote: > > > > > > Hi Ilias, > > > > > > On Tue, 16 Aug 2022 at 06:43, Ilias Apalodimas > > > wrote: > > > > > > > > Hi Simon, > > > > > > > > I know little of this device and the whole patch seems fine apart from > > > > the definitions and declarations of the state functions. > > > > > > > > > > > > On Sat, 13 Aug 2022 at 22:56, Simon Glass wrote: > > > > > > > > > > > > > > > > > > > drivers/tpm/cr50_i2c.c | 117 +++++++++++++++++++++++++++++++++++++++++ > > > > > include/tpm-v2.h | 54 +++++++++++++++++++ > > > > > lib/tpm-v2.c | 24 +++++++++ > > > > > > > > [...] > > > > > > > > > diff --git a/include/tpm-v2.h b/include/tpm-v2.h > > > > > index e79c90b9395..8e90a616220 100644 > > > > > --- a/include/tpm-v2.h > > > > > +++ b/include/tpm-v2.h > > > > > @@ -419,6 +419,50 @@ enum { > > > > > HR_NV_INDEX = TPM_HT_NV_INDEX << HR_SHIFT, > > > > > }; > > > > > > > > > > +/* > > > > > + * Operations specific to the Cr50 TPM used on Chromium OS and Android devices > > > > > + * > > > > > + * FIXME: below is not enough to differentiate between vendors commands > > > > > + * of numerous devices. However, the current tpm2 APIs aren't very amenable > > > > > + * to extending generically because the marshaling code is assuming all > > > > > + * knowledge of all commands. > > > > > + */ > > > > > +#define TPM2_CC_VENDOR_BIT_MASK 0x20000000 > > > > > + > > > > > +#define TPM2_CR50_VENDOR_COMMAND (TPM2_CC_VENDOR_BIT_MASK | 0) > > > > > +#define TPM2_CR50_SUB_CMD_IMMEDIATE_RESET 19 > > > > > +#define TPM2_CR50_SUB_CMD_NVMEM_ENABLE_COMMITS 21 > > > > > +#define TPM2_CR50_SUB_CMD_REPORT_TPM_STATE 23 > > > > > +#define TPM2_CR50_SUB_CMD_TURN_UPDATE_ON 24 > > > > > +#define TPM2_CR50_SUB_CMD_GET_REC_BTN 29 > > > > > +#define TPM2_CR50_SUB_CMD_TPM_MODE 40 > > > > > +#define TPM2_CR50_SUB_CMD_GET_BOOT_MODE 52 > > > > > +#define TPM2_CR50_SUB_CMD_RESET_EC 53 > > > > > + > > > > > +/* Cr50 vendor-specific error codes. */ > > > > > +#define VENDOR_RC_ERR 0x00000500 > > > > > +enum cr50_vendor_rc { > > > > > + VENDOR_RC_INTERNAL_ERROR = (VENDOR_RC_ERR | 6), > > > > > + VENDOR_RC_NO_SUCH_SUBCOMMAND = (VENDOR_RC_ERR | 8), > > > > > + VENDOR_RC_NO_SUCH_COMMAND = (VENDOR_RC_ERR | 127), > > > > > +}; > > > > > + > > > > > +enum cr50_tpm_mode { > > > > > + /* > > > > > + * Default state: TPM is enabled, and may be set to either > > > > > + * TPM_MODE_ENABLED or TPM_MODE_DISABLED. > > > > > + */ > > > > > + TPM_MODE_ENABLED_TENTATIVE = 0, > > > > > + > > > > > + /* TPM is enabled, and mode may not be changed. */ > > > > > + TPM_MODE_ENABLED = 1, > > > > > + > > > > > + /* TPM is disabled, and mode may not be changed. */ > > > > > + TPM_MODE_DISABLED = 2, > > > > > + > > > > > + TPM_MODE_INVALID, > > > > > +}; > > > > > + > > > > > /** > > > > > * Issue a TPM2_Startup command. > > > > > * > > > > > @@ -658,4 +702,14 @@ u32 tpm2_disable_platform_hierarchy(struct udevice *dev); > > > > > u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, > > > > > u8 *recvbuf, size_t *recv_size); > > > > > > > > > > +/** > > > > > + * tpm_cr50_report_state() - Report the Cr50 internal state > > > > > + * > > > > > + * @dev: TPM device > > > > > + * @recvbuf: Buffer to save the response to > > > > > + * @recv_size: Pointer to the size of the response buffer > > > > > + * Return: result of the operation > > > > > + */ > > > > > +u32 tpm2_cr50_report_state(struct udevice *dev, u8 *recvbuf, size_t *recv_size); > > > > > + > > > > > > > > I think we should keep the generic include files clean for hardware > > > > specific details. > > > > > > > > > #endif /* __TPM_V2_H */ > > > > > diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c > > > > > index 3e240bb4c67..3de4841974a 100644 > > > > > --- a/lib/tpm-v2.c > > > > > +++ b/lib/tpm-v2.c > > > > > @@ -679,3 +679,27 @@ u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, > > > > > { > > > > > return tpm_sendrecv_command(dev, sendbuf, recvbuf, recv_size); > > > > > } > > > > > + > > > > > +u32 tpm2_cr50_report_state(struct udevice *dev, u8 *recvbuf, size_t *recv_size) > > > > > +{ > > > > > + u8 command_v2[COMMAND_BUFFER_SIZE] = { > > > > > + /* header 10 bytes */ > > > > > + tpm_u16(TPM2_ST_NO_SESSIONS), /* TAG */ > > > > > + tpm_u32(10 + 2), /* Length */ > > > > > + tpm_u32(TPM2_CR50_VENDOR_COMMAND), /* Command code */ > > > > > + > > > > > + tpm_u16(TPM2_CR50_SUB_CMD_REPORT_TPM_STATE), > > > > > + }; > > > > > + int ret; > > > > > + > > > > > + ret = tpm_sendrecv_command(dev, command_v2, recvbuf, recv_size); > > > > > + log_debug("ret=%s, %x\n", dev->name, ret); > > > > > + if (ret) > > > > > + return ret; > > > > > + if (*recv_size < 12) > > > > > + return -ENODATA; > > > > > + *recv_size -= 12; > > > > > + memcpy(recvbuf, recvbuf + 12, *recv_size); > > > > > + > > > > > + return 0; > > > > > +} > > > > > > > > Same here, this functions seems ok but shouldn't land in the generic TPM API > > > > > > So shall I create a new tpm_cr50.h header file? What about the C file? > > > > Yea the header file seems fine (I assume in drivers/tpm?) > > > > About the C file, tpm2_cr50_report_state() is called by > > cr50_i2c_report_state() which is static in the drivers. Can't we just > > move the function there? > > Just digging into this but I think you have the wrong end of the stick. > > I have added a new TPM method to the uclass for this. We cannot call > functions 'sideways' of that mechanism as it violates how driver model > works. > I am not sure I am following here. I saw the uclass patches and they seem fine. The only thing that needs to be changed is move the cr50* generic functions outside the lib/tpm-v2.c API. This seems doable and the only thing that prevents us from doing it is some definitions in lib/tpm-utils.h which the new functions need. I'll go reply on the new patchset. Thanks /Ilias > The feature is implemented for cr50 and sandbox. It could be > implemented for other TPMs if they have any info that can usefully be > provided, such as the state of the PCRs or something else useful or > important. > > So I think my patches are already doing all this correctly. Can you > please take another look? I'll send v3 as Heinrich had a minor comment > on a function comment. Also one of your changes. > > Regards, > Simon