From patchwork Fri Jul 16 05:55:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiaWei Wang X-Patchwork-Id: 478355 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1035513jao; Thu, 15 Jul 2021 22:56:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5ruvyym3/LAZd1SJbwqbKs054hOb/JuJMStIv9fJ8seQJRO98M9BtL0aigl5uVScF12eO X-Received: by 2002:aa7:c550:: with SMTP id s16mr12185284edr.130.1626415003774; Thu, 15 Jul 2021 22:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626415003; cv=none; d=google.com; s=arc-20160816; b=T3INXEv/vYU+wt6ikeEq0STXImonJ10sTfE3sOH499wOiKcrZ5bvBvkSM524D5RT7n MiFcZTO23XcIsh0BkRo9D/fqfK2UQafVl/KAd0+ldvK2IecTJdcaGQ+bNGspC1B0z0iE Ky6zebpSlXb3dQrtH1WO248K3LNd63840SRYDTeyZdGjdzVcql53yldtAAaUlYp7g3Os dmO+B4YUUwOUlwH04YBrX1mKBiBoZ+cxqRiSvQxLjwFMxM5BfHDsDYsC3QEBpP3gAGS0 lk8wsGjEh9Do+s3Uf4CrpnzTax5vOuuW+ds9iw2uCCFPNeVOC2ym5s4ZQzKXzqqKlUI5 wLOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=WIzbJ1F4j4niM9YHvIakuiMIjGj9mROphRB55ASHg5U=; b=sZ7a1xd3Yd1VjBWpSFOCP/gdycmlic6wzHvV/hlcPB6ZMCtzJ/5M7XWoKJfYqRy5lD Feedl6su62G74ax0AGujlnsvroFj6CK/wuS2vYt2x64wJvS28V98qFwqBgy+ba+/sHh4 Mi66vG+I9Z0fJ2BbVvyzaqwatRBG25d8pGINvSG0GZxlFclYO8Kt4yKKRYbq5Ph3pczr 1KfWKKIphxMV3DmpoO5vXZ6DI1DJ1SYgCW4rlhjKxKyPQChu54N2IcZnLrgUDTa2xe04 9/p1t/NxvKQGY2kyNjkW92yk/MdazOYHXQwcG8H6cRILRiSlBHnuF85tvg+dt/kA+C+B Yncw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a20si11076379edm.350.2021.07.15.22.56.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 22:56:43 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AD09582C40; Fri, 16 Jul 2021 07:56:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id DC74082C3A; Fri, 16 Jul 2021 07:56:27 +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=-1.9 required=5.0 tests=BAYES_00, T_SPF_HELO_TEMPERROR autolearn=unavailable autolearn_force=no version=3.4.2 Received: from twspam01.aspeedtech.com (twspam01.aspeedtech.com [211.20.114.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 64BF580082 for ; Fri, 16 Jul 2021 07:56:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=chiawei_wang@aspeedtech.com Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 16G5dfKn005066; Fri, 16 Jul 2021 13:39:41 +0800 (GMT-8) (envelope-from chiawei_wang@aspeedtech.com) Received: from ChiaWeiWang-PC.aspeed.com (192.168.2.66) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 13:55:50 +0800 From: Chia-Wei Wang To: , , , CC: , Subject: [PATCH v2 02/14] clk: ast2600: Add YCLK control for HACE Date: Fri, 16 Jul 2021 13:55:34 +0800 Message-ID: <20210716055546.1619-3-chiawei_wang@aspeedtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> References: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> MIME-Version: 1.0 X-Originating-IP: [192.168.2.66] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 16G5dfKn005066 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 From: Joel Stanley Add YCLK enable for HACE, the HW hash engine of ASPEED AST2600 SoCs. Signed-off-by: Joel Stanley Signed-off-by: Chia-Wei Wang --- .../arm/include/asm/arch-aspeed/scu_ast2600.h | 5 +++-- drivers/clk/aspeed/clk_ast2600.c | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h index a205fb1f76..d7b500f656 100644 --- a/arch/arm/include/asm/arch-aspeed/scu_ast2600.h +++ b/arch/arm/include/asm/arch-aspeed/scu_ast2600.h @@ -10,8 +10,9 @@ #define SCU_CLKGATE1_EMMC BIT(27) #define SCU_CLKGATE1_MAC2 BIT(21) #define SCU_CLKGATE1_MAC1 BIT(20) -#define SCU_CLKGATE1_USB_HUB BIT(14) -#define SCU_CLKGATE1_USB_HOST2 BIT(7) +#define SCU_CLKGATE1_USB_HUB BIT(14) +#define SCU_CLKGATE1_HACE BIT(13) +#define SCU_CLKGATE1_USB_HOST2 BIT(7) #define SCU_CLKGATE2_FSI BIT(30) #define SCU_CLKGATE2_MAC4 BIT(21) diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c index 3a92739f5c..69128fd3c4 100644 --- a/drivers/clk/aspeed/clk_ast2600.c +++ b/drivers/clk/aspeed/clk_ast2600.c @@ -1013,6 +1013,23 @@ static ulong ast2600_enable_usbbhclk(struct ast2600_scu *scu) return 0; } +static ulong ast2600_enable_haceclk(struct ast2600_scu *scu) +{ + uint32_t reset_bit; + uint32_t clkgate_bit; + + reset_bit = BIT(ASPEED_RESET_HACE); + clkgate_bit = SCU_CLKGATE1_HACE; + + writel(reset_bit, &scu->modrst_ctrl1); + udelay(100); + writel(clkgate_bit, &scu->clkgate_clr1); + mdelay(20); + writel(reset_bit, &scu->modrst_clr1); + + return 0; +} + static int ast2600_clk_enable(struct clk *clk) { struct ast2600_clk_priv *priv = dev_get_priv(clk->dev); @@ -1051,6 +1068,9 @@ static int ast2600_clk_enable(struct clk *clk) case ASPEED_CLK_GATE_USBPORT2CLK: ast2600_enable_usbbhclk(priv->scu); break; + case ASPEED_CLK_GATE_YCLK: + ast2600_enable_haceclk(priv->scu); + break; default: pr_err("can't enable clk\n"); return -ENOENT; From patchwork Fri Jul 16 05:55:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiaWei Wang X-Patchwork-Id: 478356 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1035662jao; Thu, 15 Jul 2021 22:56:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyat/MTOhNvdiPlcH8IV6t3qHHMPCEksk9EEldaFj1aVvT9pfBfJyYtfgkMEBebNHAMDmDW X-Received: by 2002:a05:6402:17d3:: with SMTP id s19mr12148810edy.49.1626415014575; Thu, 15 Jul 2021 22:56:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626415014; cv=none; d=google.com; s=arc-20160816; b=rEnWrw/1EXMDk9oZSE7CyHS1gk2he4/RqCachRDXjhbKALvdsrsxHp7UYLE9tvC2wv QcWRVUI9wR/GsKyX+YTLkGBznd3MlHroIlgDZ/pAeHc25bU8kAJlNaAik0Be4Pa4iX/A BDAqhKP1FnFB9ToV8I9hiHBnp9Nhe7Cq0mJPx7PFL+tLB6ziUV5QCM84R8saSl7rlti4 n82+UnFTXe2uS3WVTvYrav8k11pf29DewTJMm6mZUHMs+1vbDJZrMARpAy73ib8wMrzT hFiQ6QVndwXvIVR4VLq9Ap/IzWQQHZ28m5oRkRB0IBHpso4r2hqW/GR5ea9zhegtrmso D+7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=OB5BnGS9VWp7TwdKhwmEAPyuqydxQenaL8J5b/0BFPM=; b=HMnQwSPGUSh6zhOU/aBTwYWn/5cXDoW632yEog47e73ZuDSi36wJx4sv73yOwBRT1I l/gn67uabtQfA9EQ4T5LG/fcozBq8p1GO10Rwd6iYEX1lVD2iv2SMNJYEQ6oGkM71AzC YhRTmNJ3lyOyfFdlVF2HPmxmPVZZqc7Lzc1tkv0uUgi6ElosLQfBMMo39gdkMlyizXUx JgxjdADVYl+pVF3KMFj+p/tXSVdFav+7VeV7M6H/hcfNFqBsq5dUwobNF8pUIUXs/urU jRfxgxi/YY8x5Z6x4TC4yqw80Eu9mRwjtIF7R6XZpeSIhpe4KEkb+/EQZbydDnqNrjt3 kxCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id m1si11249528ejj.616.2021.07.15.22.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 22:56:54 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D324982E88; Fri, 16 Jul 2021 07:56:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id EE6FB82C18; Fri, 16 Jul 2021 07:56:26 +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=-1.9 required=5.0 tests=BAYES_00, T_SPF_HELO_TEMPERROR autolearn=unavailable autolearn_force=no version=3.4.2 Received: from twspam01.aspeedtech.com (twspam01.aspeedtech.com [211.20.114.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 44DBC82999 for ; Fri, 16 Jul 2021 07:56:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=chiawei_wang@aspeedtech.com Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 16G5df5x005067; Fri, 16 Jul 2021 13:39:41 +0800 (GMT-8) (envelope-from chiawei_wang@aspeedtech.com) Received: from ChiaWeiWang-PC.aspeed.com (192.168.2.66) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 13:55:50 +0800 From: Chia-Wei Wang To: , , , CC: , Subject: [PATCH v2 03/14] crypto: aspeed: Add AST2600 HACE support Date: Fri, 16 Jul 2021 13:55:35 +0800 Message-ID: <20210716055546.1619-4-chiawei_wang@aspeedtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> References: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> MIME-Version: 1.0 X-Originating-IP: [192.168.2.66] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 16G5df5x005067 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 From: Joel Stanley Hash and Crypto Engine (HACE) is designed to accelerate the throughput of hash data digest, and symmetric-key encryption. Signed-off-by: Joel Stanley Signed-off-by: Chia-Wei Wang --- drivers/crypto/Kconfig | 2 + drivers/crypto/Makefile | 1 + drivers/crypto/aspeed/Kconfig | 12 ++ drivers/crypto/aspeed/Makefile | 1 + drivers/crypto/aspeed/aspeed_hace.c | 288 ++++++++++++++++++++++++++++ 5 files changed, 304 insertions(+) create mode 100644 drivers/crypto/aspeed/Kconfig create mode 100644 drivers/crypto/aspeed/Makefile create mode 100644 drivers/crypto/aspeed/aspeed_hace.c -- 2.17.1 diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index 1ea116be75..422d01403e 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -2,4 +2,6 @@ menu "Hardware crypto devices" source drivers/crypto/fsl/Kconfig +source drivers/crypto/aspeed/Kconfig + endmenu diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile index efbd1d3fca..0442067e5e 100644 --- a/drivers/crypto/Makefile +++ b/drivers/crypto/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_EXYNOS_ACE_SHA) += ace_sha.o obj-y += rsa_mod_exp/ obj-y += fsl/ +obj-y += aspeed/ diff --git a/drivers/crypto/aspeed/Kconfig b/drivers/crypto/aspeed/Kconfig new file mode 100644 index 0000000000..299efc223f --- /dev/null +++ b/drivers/crypto/aspeed/Kconfig @@ -0,0 +1,12 @@ +config ASPEED_HACE + bool "ASPEED Hash and Crypto Engine" + depends on ASPEED_AST2600 + imply SHA_HW_ACCEL + imply SHA_PROG_HW_ACCEL + imply CMD_HASH + help + Select this option to enable a driver for using the SHA engine in + the ASPEED BMC SoCs. + + Enabling this allows the use of SHA operations in hardware without requiring the + SHA software implementations. It also improves performance and saves code size. diff --git a/drivers/crypto/aspeed/Makefile b/drivers/crypto/aspeed/Makefile new file mode 100644 index 0000000000..84e6bfe82a --- /dev/null +++ b/drivers/crypto/aspeed/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_ASPEED_HACE) += aspeed_hace.o diff --git a/drivers/crypto/aspeed/aspeed_hace.c b/drivers/crypto/aspeed/aspeed_hace.c new file mode 100644 index 0000000000..34e68c07f4 --- /dev/null +++ b/drivers/crypto/aspeed/aspeed_hace.c @@ -0,0 +1,288 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright 2021 IBM Corp. + * Copyright 2021 ASPEED Technology Inc. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* register offsets*/ +#define HACE_STS 0x1C +#define HACE_HASH_INT BIT(9) +#define HACE_HASH_BUSY BIT(0) +#define HACE_HASH_DATA 0x20 +#define HACE_HASH_DIGEST 0x24 +#define HACE_HASH_HMAC_KEY 0x28 +#define HACE_HASH_DATA_LEN 0x2C +#define HACE_SG_LAST BIT(31) +#define HACE_HASH_CMD 0x30 +#define HACE_SG_EN BIT(18) +#define HACE_ALGO_SHA384 (BIT(10) | BIT(6) | BIT(5)) +#define HACE_ALGO_SHA512 (BIT(6) | BIT(5)) +#define HACE_ALGO_SHA256 (BIT(6) | BIT(4)) +#define HACE_ALGO_SHA224 BIT(6) +#define HACE_ALGO_SHA1 BIT(5) +#define HACE_SHA_BE_EN BIT(3) +#define HACE_MD5_LE_EN BIT(2) + +#define HACE_MAX_SG 32 + +struct aspeed_sg { + u32 len; + u32 addr; +}; + +struct aspeed_hash_ctx { + u32 method; + u32 digest_size; + u32 len; + u32 count; + struct aspeed_sg list[HACE_MAX_SG]; /* Must be 8 byte aligned */ +}; + +struct aspeed_hace { + phys_addr_t base; + struct clk clk; +}; + +static phys_addr_t aspeed_hace_get_base(void) +{ + int rc; + struct udevice *dev; + struct aspeed_hace *hace; + + rc = uclass_get_device_by_driver(UCLASS_MISC, + DM_DRIVER_GET(aspeed_hace), + &dev); + if (rc) { + printf("Cannot get HACE device, rc=%d\n", rc); + return 0; + } + + hace = dev_get_priv(dev); + + return hace->base; +} + +static int aspeed_hace_wait_completion(u32 reg, u32 flag, int timeout_us) +{ + u32 val; + + return readl_poll_timeout(reg, val, (val & flag) == flag, timeout_us); +} + +static int digest_object(const void *data, unsigned int length, void *digest, + u32 method) +{ + phys_addr_t base = aspeed_hace_get_base(); + + if (!((u32)data & BIT(31))) { + debug("HACE src out of bounds: can only copy from SDRAM\n"); + return -EINVAL; + } + + if (!((u32)digest & BIT(31))) { + debug("HACE dst out of bounds: can only copy to SDRAM\n"); + return -EINVAL; + } + + if ((u32)digest & 0x7) { + debug("HACE dst alignment incorrect: %p\n", digest); + return -EINVAL; + } + + if (readl(base + HACE_STS) & HACE_HASH_BUSY) { + debug("HACE error: engine busy\n"); + return -EBUSY; + } + + /* Clear pending completion status */ + writel(HACE_HASH_INT, base + HACE_STS); + writel((u32)data, base + HACE_HASH_DATA); + writel((u32)digest, base + HACE_HASH_DIGEST); + writel(length, base + HACE_HASH_DATA_LEN); + writel(HACE_SHA_BE_EN | method, base + HACE_HASH_CMD); + + /* SHA512 hashing appears to have a througput of about 12MB/s */ + return aspeed_hace_wait_completion(base + HACE_STS, + HACE_HASH_INT, + 1000 + (length >> 3)); +} + +void hw_sha1(const unsigned char *pbuf, unsigned int buf_len, + unsigned char *pout, unsigned int chunk_size) +{ + int rc; + + rc = digest_object(pbuf, buf_len, pout, HACE_ALGO_SHA1); + if (rc) + debug("HACE failure: %d\n", rc); +} + +void hw_sha256(const unsigned char *pbuf, unsigned int buf_len, + unsigned char *pout, unsigned int chunk_size) +{ + int rc; + + rc = digest_object(pbuf, buf_len, pout, HACE_ALGO_SHA256); + if (rc) + debug("HACE failure: %d\n", rc); +} + +void hw_sha384(const unsigned char *pbuf, unsigned int buf_len, + unsigned char *pout, unsigned int chunk_size) +{ + int rc; + + rc = digest_object(pbuf, buf_len, pout, HACE_ALGO_SHA384); + if (rc) + debug("HACE failure: %d\n", rc); +} + +void hw_sha512(const unsigned char *pbuf, unsigned int buf_len, + unsigned char *pout, unsigned int chunk_size) +{ + int rc; + + rc = digest_object(pbuf, buf_len, pout, HACE_ALGO_SHA512); + if (rc) + debug("HACE failure: %d\n", rc); +} + +int hw_sha_init(struct hash_algo *algo, void **ctxp) +{ + struct aspeed_hash_ctx *ctx; + u32 method; + + if (!strcmp(algo->name, "sha1")) + method = HACE_ALGO_SHA1; + else if (!strcmp(algo->name, "sha256")) + method = HACE_ALGO_SHA256; + else if (!strcmp(algo->name, "sha384")) + method = HACE_ALGO_SHA384; + else if (!strcmp(algo->name, "sha512")) + method = HACE_ALGO_SHA512; + else + return -ENOTSUPP; + + ctx = memalign(8, sizeof(*ctx)); + if (!ctx) { + debug("HACE error: Cannot allocate memory for context\n"); + return -ENOMEM; + } + + memset(ctx, '\0', sizeof(*ctx)); + + if (((uintptr_t)ctx->list & 0x3) != 0) { + printf("HACE error: Invalid alignment for input data\n"); + return -EINVAL; + } + + ctx->method = method | HACE_SG_EN; + ctx->digest_size = algo->digest_size; + + *ctxp = ctx; + + return 0; +} + +int hw_sha_update(struct hash_algo *algo, void *hash_ctx, const void *buf, + unsigned int size, int is_last) +{ + struct aspeed_hash_ctx *ctx = hash_ctx; + struct aspeed_sg *sg = &ctx->list[ctx->count]; + + if (ctx->count >= ARRAY_SIZE(ctx->list)) { + debug("HACE error: Reached maximum number of hash segments\n"); + free(ctx); + return -EINVAL; + } + + sg->addr = (u32)buf; + sg->len = size; + + if (is_last) + sg->len |= HACE_SG_LAST; + + ctx->count++; + ctx->len += size; + + return 0; +} + +int hw_sha_finish(struct hash_algo *algo, void *hash_ctx, void *dest_buf, int size) +{ + struct aspeed_hash_ctx *ctx = hash_ctx; + int rc; + + if (size < ctx->digest_size) { + debug("HACE error: insufficient size on destination buffer\n"); + free(ctx); + return -EINVAL; + } + + rc = digest_object(ctx->list, ctx->len, dest_buf, ctx->method); + if (rc) + debug("HACE Scatter-Gather failure\n"); + + free(ctx); + + return rc; +} + +static int aspeed_hace_probe(struct udevice *dev) +{ + struct aspeed_hace *hace = dev_get_priv(dev); + int ret; + + ret = clk_get_by_index(dev, 0, &hace->clk); + if (ret < 0) { + debug("Can't get clock for %s: %d\n", dev->name, ret); + return ret; + } + + ret = clk_enable(&hace->clk); + if (ret) { + debug("Failed to enable fsi clock (%d)\n", ret); + return ret; + } + + hace->base = devfdt_get_addr(dev); + + return ret; +} + +static int aspeed_hace_remove(struct udevice *dev) +{ + struct aspeed_hace *hace = dev_get_priv(dev); + + clk_disable(&hace->clk); + + return 0; +} + +static const struct udevice_id aspeed_hace_ids[] = { + { .compatible = "aspeed,ast2600-hace" }, + { } +}; + +U_BOOT_DRIVER(aspeed_hace) = { + .name = "aspeed_hace", + .id = UCLASS_MISC, + .of_match = aspeed_hace_ids, + .probe = aspeed_hace_probe, + .remove = aspeed_hace_remove, + .priv_auto = sizeof(struct aspeed_hace), + .flags = DM_FLAG_PRE_RELOC, +}; From patchwork Fri Jul 16 05:55:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiaWei Wang X-Patchwork-Id: 478354 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1035333jao; Thu, 15 Jul 2021 22:56:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhNjsLF6wNiqqPxML50KxpH3U7yu+DX+1x93Wwm4IuB5j9q7Vz9+tZgi+AFEDWeYdz8OFu X-Received: by 2002:a17:906:6d0a:: with SMTP id m10mr10116279ejr.106.1626414992521; Thu, 15 Jul 2021 22:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626414992; cv=none; d=google.com; s=arc-20160816; b=IXC8zCnnWlmolmEChkDlMBUtx1ZvqDDRYtm13sK86uLXkaEEpTp7Q8YLiRT1XfAzB+ 4AJ2AcrLze7eXuOmCQlQ89PkNkt06r/bewW5b/MCnMhMn/ueKnPujwqBlG/J2Q8UU7NS wvTdxjAN+FJO7XesOcycwrx5A13hvLBcmsjHt5b7xm23aRlfGYrcs707dTeiCJHBn5Lt jyXjwWIF1+7V4fQNQpfeW7YV3Mfu8N1AyDqos5IqERuBPrslojW6HgR4JmojJhAXPzXr HyYZoWUO5cTbU5awJAHDRH3Hujr/d3t9NTsdkZsXUrPlGiKR4s9mJZmQYiC7MJFTsdjw 9hww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=7FPHxGULImJapf2j0NYdSpTM1MJZ3obV2EZ/LYt8wHQ=; b=kcTj1ti62JRh6MbgJUDtOslwSdMlpD1Ddo1JK2vBMvE5jgjypOEtCTOVADcz7up4DV eAUaQUfb0dbAdStN0mIp6oBkDwYZbMXaJtoL1wHeaLuO1oLFiqx9g21ttd5/g1LDB9dr WJ3/QZyYMNqUzlbPF5dTYTS7r2UiSGDPsaaggwSNwIwNIlW3z0PGvHTTM8D8EAc3hzx8 pADORwIBvwY5HmynpD9MA+ZBaqAhFiW4WZ41KDzQ5Th0wC8t4G6B/jSxS1kbatY81TVD UDAb+9pT+DxcTTcyF6CkyJuWhAsbPLJMPGSZPRfmEaTOsoKkIJMHnBKOQlHe9PvNa890 J0+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id f21si9634606ejj.567.2021.07.15.22.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 22:56:32 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AF5598297D; Fri, 16 Jul 2021 07:56:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 6028A8296A; Fri, 16 Jul 2021 07:56:16 +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=-1.9 required=5.0 tests=BAYES_00, T_SPF_HELO_TEMPERROR autolearn=unavailable autolearn_force=no version=3.4.2 Received: from twspam01.aspeedtech.com (twspam01.aspeedtech.com [211.20.114.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2D26682999 for ; Fri, 16 Jul 2021 07:56:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=chiawei_wang@aspeedtech.com Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 16G5dfTp005068; Fri, 16 Jul 2021 13:39:41 +0800 (GMT-8) (envelope-from chiawei_wang@aspeedtech.com) Received: from ChiaWeiWang-PC.aspeed.com (192.168.2.66) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 13:55:51 +0800 From: Chia-Wei Wang To: , , , CC: , Subject: [PATCH v2 04/14] ast2600: spl: Add HACE probing Date: Fri, 16 Jul 2021 13:55:36 +0800 Message-ID: <20210716055546.1619-5-chiawei_wang@aspeedtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> References: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> MIME-Version: 1.0 X-Originating-IP: [192.168.2.66] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 16G5dfTp005068 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 From: Joel Stanley Probe HACE driver in SPL board init if enabled. Signed-off-by: Joel Stanley Signed-off-by: Chia-Wei Wang --- arch/arm/mach-aspeed/ast2600/spl.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.17.1 diff --git a/arch/arm/mach-aspeed/ast2600/spl.c b/arch/arm/mach-aspeed/ast2600/spl.c index 0d8cb29678..a0fc420ff1 100644 --- a/arch/arm/mach-aspeed/ast2600/spl.c +++ b/arch/arm/mach-aspeed/ast2600/spl.c @@ -38,6 +38,20 @@ struct image_header *spl_get_load_buffer(ssize_t offset, size_t size) return (struct image_header *)(CONFIG_SYS_TEXT_BASE); } +#ifdef CONFIG_SPL_BOARD_INIT +void spl_board_init(void) +{ + int rc; + struct udevice *dev; + + rc = uclass_get_device_by_driver(UCLASS_MISC, + DM_DRIVER_GET(aspeed_hace), + &dev); + if (rc) + debug("HACE initialization failure, rc=%d\n", rc); +} +#endif + #ifdef CONFIG_SPL_OS_BOOT int spl_start_uboot(void) { From patchwork Fri Jul 16 05:55:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiaWei Wang X-Patchwork-Id: 478358 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1036681jao; Thu, 15 Jul 2021 22:58:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnBLNRaW7w7zp/86oVCYl9FL0k6fx6elHBrXRzCVsOlfR0/uaJCWPyydoxPvIWbQjMX5zP X-Received: by 2002:a17:906:c13:: with SMTP id s19mr9996225ejf.439.1626415104088; Thu, 15 Jul 2021 22:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626415104; cv=none; d=google.com; s=arc-20160816; b=hm+ukqRqC5IViOTIUfwFihJVeqJW04PLIb6mIIn9MSv4t7MnagsXia47qyRqVUnP39 bsRNV3K216dFxrdHjVPgRFOH/FkI+wFZdZE5uYP2jEc1WOFo2+rFejZBc+KaT0L87UCA ugMngvQD5Dya+7BfJ/RZPUOeqGqsmgKLbR/4pHwfw62Jj18zLNczmZnHhoRv60tgpU3P /8mWIygTxqT1O6K7j4VZul0Ej/ffZGAOAM/zjsqD5CDMrAq/5EW72z9jV6P/RzIG1AMl P/x1CUWflK5lZhJXgM5pRdybRO10hG2HK87rK+pzsRIchtqUk8TJ1BY9a33PNwGGcYvS gtbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=qt2puGHybWP8iTVicF6ZmWP3UaJlQB/6E9qOBtG28+8=; b=moeRLx6wTKT5pHZzLvduRoO4tGZtExP/odiKm3biU2z/icNm0LA1k7tuwcgjUHETaX mFyNea6t0PvGFH7hFqx9DVmeKdb/pZ+yTmxkPdJBbfkzo4CyTW2ENBoj5JFn5XojjMMu SuqWuyMSC1x2RyE8GcyqsjocKMEWZ+VcFW8GDNdHfyCAfYs5lACsJGD/Y5lPWCW93Fd8 G19+5y64b2tLfThiUEzRz0GXbrD5FotuCb5A1jTLaWEFNLcAfyNSrEXptO56xuaYPHWe +LCbY/6dMrCM1H+VZ4LsDtw6WbbW1ovhgKb5P4Cmqpw1M8PFPT/r2cuCEYRd9+QXnBjb k9Hg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id j26si9554777edt.98.2021.07.15.22.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 22:58:24 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F3D4082EB7; Fri, 16 Jul 2021 07:57:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 6C0AA80223; Fri, 16 Jul 2021 07:56:52 +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=-1.9 required=5.0 tests=BAYES_00, T_SPF_HELO_TEMPERROR autolearn=unavailable autolearn_force=no version=3.4.2 Received: from twspam01.aspeedtech.com (twspam01.aspeedtech.com [211.20.114.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6C796828BC for ; Fri, 16 Jul 2021 07:56:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=chiawei_wang@aspeedtech.com Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 16G5dgnT005069; Fri, 16 Jul 2021 13:39:42 +0800 (GMT-8) (envelope-from chiawei_wang@aspeedtech.com) Received: from ChiaWeiWang-PC.aspeed.com (192.168.2.66) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 13:55:51 +0800 From: Chia-Wei Wang To: , , , CC: , Subject: [PATCH v2 05/14] ARM: dts: ast2600: Add HACE to device tree Date: Fri, 16 Jul 2021 13:55:37 +0800 Message-ID: <20210716055546.1619-6-chiawei_wang@aspeedtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> References: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> MIME-Version: 1.0 X-Originating-IP: [192.168.2.66] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 16G5dgnT005069 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 From: Joel Stanley Add HACE DTS node and enable it for AST2600 EVB. Signed-off-by: Joel Stanley Signed-off-by: Chia-Wei Wang --- arch/arm/dts/ast2600-evb.dts | 5 +++++ arch/arm/dts/ast2600.dtsi | 8 ++++++++ 2 files changed, 13 insertions(+) -- 2.17.1 diff --git a/arch/arm/dts/ast2600-evb.dts b/arch/arm/dts/ast2600-evb.dts index 2abd31341c..adb80a30ef 100644 --- a/arch/arm/dts/ast2600-evb.dts +++ b/arch/arm/dts/ast2600-evb.dts @@ -177,3 +177,8 @@ 0x08 0x04 0x08 0x04>; }; + +&hace { + u-boot,dm-pre-reloc; + status = "okay"; +}; diff --git a/arch/arm/dts/ast2600.dtsi b/arch/arm/dts/ast2600.dtsi index ac0f08b7ea..642206fb77 100644 --- a/arch/arm/dts/ast2600.dtsi +++ b/arch/arm/dts/ast2600.dtsi @@ -187,6 +187,14 @@ }; }; + hace: hace@1e6d0000 { + compatible = "aspeed,ast2600-hace"; + reg = <0x1e6d0000 0x200>; + interrupts = ; + clocks = <&scu ASPEED_CLK_GATE_YCLK>; + status = "disabled"; + }; + edac: sdram@1e6e0000 { compatible = "aspeed,ast2600-sdram-edac"; reg = <0x1e6e0000 0x174>; From patchwork Fri Jul 16 05:55:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChiaWei Wang X-Patchwork-Id: 478357 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1036545jao; Thu, 15 Jul 2021 22:58:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygEyhlK5/uUj9TAf/2R9ryVYzDZTgl3Huav/1BFoRLprLAHicRblwJDTJIiR8k123DhlsO X-Received: by 2002:a05:6402:31bb:: with SMTP id dj27mr11805272edb.375.1626415092822; Thu, 15 Jul 2021 22:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626415092; cv=none; d=google.com; s=arc-20160816; b=SVlkgbksV0Urv+eDbPWoUDgSOEo2nct1kIeHw5Ks8pCF1EVH7CMlDvO6175I/aNmRr caZ1ZZcQYjDBqlz0RfTkMP0EhM8hya8Y6zg9oR6QkFZv9La2OWp9csu7gygzPxzRYhki q4g66OwujdafqA/faGDcIuD268Kl8evfug05sHiNnKqPQ3Uj7P4MQOqyOtlTqi47R3AD Ubbks6NoufyaodVIG4OlZmSGJ0Tw6apDSIzwAxHBmPyWwWQjYtFZgfn+HdCQItK1VjR9 styB9B7wO86XZG22vfFme8yw6MXjTeq6hccjPNJSgVGYqpBHP4xb4WzES9R/LLSJDqr0 NolA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=ARthw3mW/dMnAPs+OytOHSZiC158rh2+OeOPaQkzkIQ=; b=He4cDp/h5osoZtQlFe5lyMA1DwyI9sqAVCCNLCIY1SJnMVniI9MlvblSiUHNLtBF+T UqsnoGyBWVLQg0eQ4l53uqtXZqCaZcd7V6rnI+LbNNHJUx21T9TK/TY5FGY9jQQpp8lo kVedinFDmqWLn5E8gm147QAYpjKSoDx++1ADp6XUnDu1LUQp6H1vKC9NcPv3dAbcN88v pGS28V6kyoP8YlCnf2OZg/jc9AcqMQzllNG+TjFiKjGQSBAGcVPeNVLw7oFbkHpPQBSy yocsLcZztJvXNzv+nC1/CXquqhl8tMDKi91gdM5dwGFLHdPc4pymF2uQOfa8COAWOlmW fuhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id x4si10266095edq.317.2021.07.15.22.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 22:58:12 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9F5E882F12; Fri, 16 Jul 2021 07:57:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 7E7FA829CA; Fri, 16 Jul 2021 07:56:51 +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=-1.9 required=5.0 tests=BAYES_00, T_SPF_HELO_TEMPERROR autolearn=unavailable autolearn_force=no version=3.4.2 Received: from twspam01.aspeedtech.com (twspam01.aspeedtech.com [211.20.114.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3DCB9829D4 for ; Fri, 16 Jul 2021 07:56:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=aspeedtech.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=chiawei_wang@aspeedtech.com Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 16G5dgos005070; Fri, 16 Jul 2021 13:39:42 +0800 (GMT-8) (envelope-from chiawei_wang@aspeedtech.com) Received: from ChiaWeiWang-PC.aspeed.com (192.168.2.66) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 13:55:51 +0800 From: Chia-Wei Wang To: , , , CC: , Subject: [PATCH v2 06/14] common: fit: Use hash.c to call CRC/SHA function Date: Fri, 16 Jul 2021 13:55:38 +0800 Message-ID: <20210716055546.1619-7-chiawei_wang@aspeedtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> References: <20210716055546.1619-1-chiawei_wang@aspeedtech.com> MIME-Version: 1.0 X-Originating-IP: [192.168.2.66] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 16G5dgos005070 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 From: Joel Stanley Currently the FIT verification calls directly into SW implemented functions to get a CRC/SHA/MD5 hash. This patch removes duplcated algorithm lookup and use hash_lookup_algo to get the hashing function with HW accelearation supported if configured. The MD5 direct call remains as it is not included in the hash lookup table of hash.c. Signed-off-by: Joel Stanley Signed-off-by: Chia-Wei Wang --- common/image-fit.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) -- 2.17.1 diff --git a/common/image-fit.c b/common/image-fit.c index 0c5a05948d..e52ff47bc3 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1196,7 +1196,7 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) * calculate_hash - calculate and return hash for provided input data * @data: pointer to the input data * @data_len: data length - * @algo: requested hash algorithm + * @algo_name: requested hash algorithm * @value: pointer to the char, will hold hash value data (caller must * allocate enough free space) * value_len: length of the calculated hash @@ -1210,37 +1210,22 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) * 0, on success * -1, when algo is unsupported */ -int calculate_hash(const void *data, int data_len, const char *algo, - uint8_t *value, int *value_len) +int calculate_hash(const void *data, int data_len, const char *algo_name, + uint8_t *value, int *value_len) { - if (IMAGE_ENABLE_CRC32 && strcmp(algo, "crc32") == 0) { - *((uint32_t *)value) = crc32_wd(0, data, data_len, - CHUNKSZ_CRC32); - *((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value)); - *value_len = 4; - } else if (IMAGE_ENABLE_SHA1 && strcmp(algo, "sha1") == 0) { - sha1_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA1); - *value_len = 20; - } else if (IMAGE_ENABLE_SHA256 && strcmp(algo, "sha256") == 0) { - sha256_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA256); - *value_len = SHA256_SUM_LEN; - } else if (IMAGE_ENABLE_SHA384 && strcmp(algo, "sha384") == 0) { - sha384_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA384); - *value_len = SHA384_SUM_LEN; - } else if (IMAGE_ENABLE_SHA512 && strcmp(algo, "sha512") == 0) { - sha512_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA512); - *value_len = SHA512_SUM_LEN; - } else if (IMAGE_ENABLE_MD5 && strcmp(algo, "md5") == 0) { + struct hash_algo *algo; + + if (IMAGE_ENABLE_MD5 && strcmp(algo_name, "md5") == 0) { md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5); *value_len = 16; + } else if (hash_lookup_algo(algo_name, &algo) == 0) { + algo->hash_func_ws(data, data_len, value, algo->chunk_size); + *value_len = algo->digest_size; } else { debug("Unsupported hash alogrithm\n"); return -1; } + return 0; }