From patchwork Tue May 15 09:57:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 913538 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40lYC13pxSz9ry1 for ; Tue, 15 May 2018 20:07:09 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2A80BC21D56; Tue, 15 May 2018 10:05:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D65A3C21F5E; Tue, 15 May 2018 09:57:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DF81BC21F3B; Tue, 15 May 2018 09:57:41 +0000 (UTC) Received: from mail.bootlin.com (mail.bootlin.com [62.4.15.54]) by lists.denx.de (Postfix) with ESMTP id A2038C21DFF for ; Tue, 15 May 2018 09:57:35 +0000 (UTC) Received: by mail.bootlin.com (Postfix, from userid 110) id 69810208BC; Tue, 15 May 2018 11:57:34 +0200 (CEST) Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.bootlin.com (Postfix) with ESMTPSA id 2DEFB20750; Tue, 15 May 2018 11:57:34 +0200 (CEST) From: Miquel Raynal To: Tom Rini , Simon Glass Date: Tue, 15 May 2018 11:57:09 +0200 Message-Id: <20180515095728.16572-14-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180515095728.16572-1-miquel.raynal@bootlin.com> References: <20180515095728.16572-1-miquel.raynal@bootlin.com> Cc: u-boot@lists.denx.de, Bastian Fraune Subject: [U-Boot] [PATCH v4 13/32] tpm: add macros to enhance TPM commands readability X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" TPM commands are much easier to read/write with these macros that will transform words or integers into byte strings. This way, there is no need to call pack_byte_string() while all variable length in a command are known (and at must 4 bytes, which is a lot of them). Signed-off-by: Miquel Raynal Reviewed-by: Simon Glass Reviewed-by: Tom Rini --- lib/tpm-utils.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/tpm-utils.h b/lib/tpm-utils.h index 429da46232..9c875e6fa7 100644 --- a/lib/tpm-utils.h +++ b/lib/tpm-utils.h @@ -13,6 +13,12 @@ /* Internal error of TPM command library */ #define TPM_LIB_ERROR ((u32)~0u) +/* To make strings of commands more easily */ +#define __MSB(x) ((x) >> 8) +#define __LSB(x) ((x) & 0xFF) +#define tpm_u16(x) __MSB(x), __LSB(x) +#define tpm_u32(x) tpm_u16((x) >> 16), tpm_u16((x) & 0xFFFF) + /** * tpm_open() - Request access to locality 0 for the caller *