From patchwork Mon Jul 5 15:48:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1500856 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=clBdoopA; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GJVWM05Vjz9sX1 for ; Tue, 6 Jul 2021 01:50:06 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D106B82C2D; Mon, 5 Jul 2021 17:49:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="clBdoopA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9E64E82BFA; Mon, 5 Jul 2021 17:49:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) (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 1977280F47 for ; Mon, 5 Jul 2021 17:49:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x32c.google.com with SMTP id o13-20020a9d404d0000b0290466630039caso18716993oti.6 for ; Mon, 05 Jul 2021 08:49:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X+P0ud5E+ooDowNhMnqAuhgL6yTEKcU77WpBLalmszQ=; b=clBdoopA4bp0bQYlJw2AHJ6GFait6HIx+pWK+RoIv5curdTG7XHKr6pnXQSxPpxR4v RaYRSNsezbXk2Lh7ladRsJ6BZWZ2HUKyc6Sx0tPLpcFCugTwBhyx7/a92xEFYDNwItdX i0eqg1+NtkF6RJ/4Z9radHGn0aUh+/Lkaext8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X+P0ud5E+ooDowNhMnqAuhgL6yTEKcU77WpBLalmszQ=; b=YW4e8Aom96P270qekAKH4hf8F4WTiH+XRdeujzQqKw148QoZLl0cIhqjiZ3S7N0O74 5DhYSnO+0mFX/Jdz34+PIBOj9/PFeT/1+JXfUudv/Jr+MU/Z9B/Kz2ScyXknHLgdR/O3 JDqg78DmQelID1SEh3JKCFK99PgEGKMOwtjG0sORw/jMLZlKynTSRPjqb/mc/pA4bjrk Mccb03jz8OhNipNrYOjReRCY7lJnc/g5hmkEwGhIJp+BziW707vvRH+y3ySyVjGK4FAD egTf7X1okE9ZgVKh8xF1mzoCBhVgigUPn5zONJvjzwPohSZmfp26gepk4aKiI37ipoaW Bozw== X-Gm-Message-State: AOAM532fjrWN7LcTfB7EB201pbntP5njrWNxKuV8Ff6tsDpOfE+pj//b +YjhbE8hbxFKUlNQ5v+1aVIHhV22JwYMLy9E X-Google-Smtp-Source: ABdhPJxE+UdunaMu+fFy4gzEEXgqc/djrcFVFb2dF6ywyJtIwgngwitADPLRgDftwSo4Fa+oShHa0g== X-Received: by 2002:a9d:4b0e:: with SMTP id q14mr1487760otf.217.1625500139618; Mon, 05 Jul 2021 08:48:59 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id n65sm2652038ota.37.2021.07.05.08.48.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 08:48:59 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Thirupathaiah Annapureddy , Ilias Apalodimas , Simon Glass , Heinrich Schuchardt Subject: [PATCH 6/9] sandbox: tpm: Track whether the state is valid Date: Mon, 5 Jul 2021 09:48:46 -0600 Message-Id: <20210705154849.2083972-7-sjg@chromium.org> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210705154849.2083972-1-sjg@chromium.org> References: <20210705154849.2083972-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean Add checking as to whether the current TPM state is valid, so we can implement reading/writing the state. Signed-off-by: Simon Glass --- drivers/tpm/tpm2_tis_sandbox.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c index 5e0bd304699..c287ca2278f 100644 --- a/drivers/tpm/tpm2_tis_sandbox.c +++ b/drivers/tpm/tpm2_tis_sandbox.c @@ -49,6 +49,7 @@ static const u8 sandbox_extended_once_pcr[] = { * Information about our TPM emulation. This is preserved in the sandbox * state file if enabled. * + * @valid: true if this is valid (only used in s_state) * @init_done: true if open() has been called * @startup_done: true if TPM2_CC_STARTUP has been processed * @tests_done: true if TPM2_CC_SELF_TEST has be processed @@ -62,6 +63,7 @@ static const u8 sandbox_extended_once_pcr[] = { * @nvdata: non-volatile data, used to store important things for the platform */ struct sandbox_tpm2 { + bool valid; /* TPM internal states */ bool init_done; bool startup_done; @@ -73,6 +75,8 @@ struct sandbox_tpm2 { u32 pcr_extensions[SANDBOX_TPM_PCR_NB]; }; +static struct sandbox_tpm2 s_state, *g_state; + /* * Check the tag validity depending on the command (authentication required or * not). If authentication is required, check it is valid. Update the auth @@ -606,11 +610,13 @@ static int sandbox_tpm2_probe(struct udevice *dev) /* Use the TPM v2 stack */ priv->version = TPM_V2; - memset(tpm, 0, sizeof(*tpm)); - priv->pcr_count = 32; priv->pcr_select_min = 2; + if (s_state.valid) + memcpy(tpm, &s_state, sizeof(*tpm)); + g_state = tpm; + return 0; }