From patchwork Mon Jul 5 15:48:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1500852 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=FaH/c8Vn; 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 4GJVVb1VtZz9sX2 for ; Tue, 6 Jul 2021 01:49:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 66FCA82C0D; Mon, 5 Jul 2021 17:49:09 +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="FaH/c8Vn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E4B8082BFA; Mon, 5 Jul 2021 17:49:04 +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-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) (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 F3F3F800BF for ; Mon, 5 Jul 2021 17:48:58 +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-x334.google.com with SMTP id n99-20020a9d206c0000b029045d4f996e62so18732115ota.4 for ; Mon, 05 Jul 2021 08:48:58 -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=RmlPviFg1lBTVnn8AxsoMjyEjhZ5Ig6kLOfR7ax6QPU=; b=FaH/c8VnOCDs1GGZ9pMsstrZOY0w8OuyUCd0biIs+9jLS6QMhuvcU46ZXmzv5xxc/E WLkp7s08SiiGCx4Yho0JXanFin3GwQs+0yAjN19rIwfIN1n3C/6Gnb3SDgo6Ooh16Bhj JYH2f7rsNSFriROwfsFub7y/eHSNmjSoHAjWU= 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=RmlPviFg1lBTVnn8AxsoMjyEjhZ5Ig6kLOfR7ax6QPU=; b=S3QDqT8cINVVqRktEDap7ITK7OrBExNZBdGBk2FrAZ0epIiOBFJU+5h8WEWZjQH1ZA QLkQTKOWP/aRT/ePWF8nxZs9unUXcXrOclrPIX0K2yqcLoMhF25zstjrwLz5HpAUE8Ej q8ds2IOrT2yahBVlTE3iiCFcZ+Vi7XM0yDzc7vkBgSMvJwsz7HbJlRe6K6IrphbI8lv0 piYRHCebh3mr42zIdWg42+wX8iMhBQ97Z8j/PmIJfLrcmydKWGqGuepnfUVtIgFne2l7 LqF3Q3CLhrdY5/L3QUifcGOapPQyd99zjeotS5rYYOszNtguY0A2hw+b0oa2aLnZuynl YDcQ== X-Gm-Message-State: AOAM532wS+Z1joqLYG6DrSQtEPU+mfmtaXXQlE6nwUmEZc04Kcz7FWCf veEoUr7jRdDxAr2h7g1lSDUGRPEBwcDb/m4i X-Google-Smtp-Source: ABdhPJzhY4eub52q5qa8voGrwsItpHpmUadMKoRVVpBR8oipH0oX0b4KI+75ZMgU3mKjnpaE+pzogw== X-Received: by 2002:a05:6830:17c9:: with SMTP id p9mr11792254ota.75.1625500136982; Mon, 05 Jul 2021 08:48:56 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 08:48:56 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Thirupathaiah Annapureddy , Ilias Apalodimas , Simon Glass , Walter Lozano Subject: [PATCH 3/9] sandbox: tpm: Support the define-space command Date: Mon, 5 Jul 2021 09:48:43 -0600 Message-Id: <20210705154849.2083972-4-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 support for this command, moving away from the previous approach of hard-coding the initial data in the driver, now that the kernel-space data has to be set up by the higher-level vboot code. Signed-off-by: Simon Glass --- drivers/tpm/sandbox_common.c | 11 +++++++++++ drivers/tpm/sandbox_common.h | 12 ++++++++++++ drivers/tpm/tpm_tis_sandbox.c | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/drivers/tpm/sandbox_common.c b/drivers/tpm/sandbox_common.c index 13f5e030a5f..7e0b2502e35 100644 --- a/drivers/tpm/sandbox_common.c +++ b/drivers/tpm/sandbox_common.c @@ -64,3 +64,14 @@ void sb_tpm_write_data(struct nvdata_state nvdata[NV_SEQ_COUNT], else memcpy(&nvdata[seq].data, buf + data_ofs, length); } + +void sb_tpm_define_data(struct nvdata_state nvdata[NV_SEQ_COUNT], + enum sandbox_nv_space seq, int length) +{ + struct nvdata_state *nvd = &nvdata[seq]; + + if (length > NV_DATA_SIZE) + log_err("Invalid length %x (max %x)\n", length, NV_DATA_SIZE); + nvd->length = length; + nvd->present = true; +} diff --git a/drivers/tpm/sandbox_common.h b/drivers/tpm/sandbox_common.h index aa5292d7945..e822a200fd3 100644 --- a/drivers/tpm/sandbox_common.h +++ b/drivers/tpm/sandbox_common.h @@ -93,4 +93,16 @@ void sb_tpm_write_data(struct nvdata_state nvdata[NV_SEQ_COUNT], enum sandbox_nv_space seq, const u8 *buf, int data_ofs, int length); +/** + * sb_tpm_define_data() - Set up non-volatile data + * + * If @length is too large, an error is logged and nothing is written. + * + * @nvdata: Current nvdata state + * @seq: Sequence number to set up + * @length: Length of space in bytes + */ +void sb_tpm_define_data(struct nvdata_state nvdata[NV_SEQ_COUNT], + enum sandbox_nv_space seq, int length); + #endif diff --git a/drivers/tpm/tpm_tis_sandbox.c b/drivers/tpm/tpm_tis_sandbox.c index f22ed846f0a..85b22afa4d9 100644 --- a/drivers/tpm/tpm_tis_sandbox.c +++ b/drivers/tpm/tpm_tis_sandbox.c @@ -210,6 +210,17 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, memset(recvbuf, '\0', *recv_len); break; case TPM_CMD_NV_DEFINE_SPACE: + index = get_unaligned_be32(sendbuf + 12); + length = get_unaligned_be32(sendbuf + 77); + seq = sb_tpm_index_to_seq(index); + if (seq < 0) + return -EINVAL; + printf("tpm: define_space index=%#02x, len=%#02x, seq=%#02x\n", + index, length, seq); + sb_tpm_define_data(tpm->nvdata, seq, length); + *recv_len = 12; + memset(recvbuf, '\0', *recv_len); + break; case 0x15: /* pcr read */ case 0x5d: /* force clear */ case 0x6f: /* physical enable */