Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4C40C433EF for ; Thu, 16 Sep 2021 16:00:13 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id DD53D6120E for ; Thu, 16 Sep 2021 16:00:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DD53D6120E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D5C2982DB3; Thu, 16 Sep 2021 18:00:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="GzBrZcGX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 94E6682E03; Thu, 16 Sep 2021 18:00:07 +0200 (CEST) Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) (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 D5794829FC for ; Thu, 16 Sep 2021 18:00:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.nuke.me@gmail.com Received: by mail-oi1-x235.google.com with SMTP id w19so9662944oik.10 for ; Thu, 16 Sep 2021 09:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=4IVMPibg+54LrxzAH1leA7dCPkkpXdmOTMr5wI5ZYlw=; b=GzBrZcGXHXLEiIi+UNWdqUFklCeckNxczY6bg/sujeqEBxYKjTeKpReBw72xjJbXjw EJ8PdxWwMBJ400jJOcvucfRuQd7duniGmTu7BLWCvE/7+A5gDoIgRa5FyCWm6cxcxXLd S3xTwNeacgbPAcRXH/janfsvFqSB1f500gKAsDr3fZ4YfNZsZBU+0BTGIvO5KwZuoxGQ zVwAP6LCG6ljcI5cxNWc+cueW93aRm6JFGbYTztWDm/JfPYVQ95ysCvtShg+5aMalDof nr4P4E8VPfARgXfihxGc6vgg2RRQ+MuGz7FbC4007ey3eVWpvPGjbxZhMjB0vAeChQa8 pI9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=4IVMPibg+54LrxzAH1leA7dCPkkpXdmOTMr5wI5ZYlw=; b=JvEQO/bKxlA2vTlCP0vnLdZid4g0/CXBvCOo8U8jjsfDWteg3eZIPAi/V79zoUOI3K sBqsAVz5qXZbB9MZZ5xh5XCl/QprFhWX2C8y4Em7o8fOtpQieUKnmSL5v0HtAqy5po3l W++FetHGIXPZKXAoCsjo2CAypNtrFRulYA9M2aU12srcM1cM7smb5ZXvPzFf4TESgFYi eqyPevLDRtfT9Nvvtfw5PVZx0XQ/n12aFxctlh+pi7YpzpuyrZpPFqH7v3HMtnDaXiNd OcvCMDyI3E4GfTK97+FNf3EoFj4LPkhc5B7IdaeXyP2Wrz9GuBCneCV3w/qWI+/DLi0a IcDg== X-Gm-Message-State: AOAM531vONc54XO2UDsovfrVqflY8/Iz77vAM5FS3Kaf2HPjn1GGKu07 sifg5E3+nJXeTThcFi0x0mW7DwRZQXA= X-Google-Smtp-Source: ABdhPJy/t1ToLCwYND7F1kajQvUgNlOgr4m51/xWc8fQThobwElrAKaw6pH7v4RGQxhvggnIdOZhrg== X-Received: by 2002:a05:6808:1481:: with SMTP id e1mr390910oiw.5.1631807998707; Thu, 16 Sep 2021 08:59:58 -0700 (PDT) Received: from nuclearis3.gtech (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id bc27sm7985oib.5.2021.09.16.08.59.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Sep 2021 08:59:58 -0700 (PDT) Subject: Re: [PATCH 4/4] fit: Use DM hash driver if supported To: Chia-Wei Wang , sjg@chromium.org, trini@konsulko.com, u-boot@lists.denx.de References: <20210730010805.17845-1-chiawei_wang@aspeedtech.com> <20210730010805.17845-5-chiawei_wang@aspeedtech.com> From: "Alex G." Message-ID: <38c2e694-364a-1fa3-5769-7f0c6be79708@gmail.com> Date: Thu, 16 Sep 2021 10:59:57 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210730010805.17845-5-chiawei_wang@aspeedtech.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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 On 7/29/21 8:08 PM, Chia-Wei Wang wrote: > Calculate hash using DM driver if supported. > For backward compatibility, the call to legacy > hash functions is reserved. > > Signed-off-by: Chia-Wei Wang > --- > common/image-fit.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/common/image-fit.c b/common/image-fit.c > index d6b2c3c7ec..ec2e526356 100644 > --- a/common/image-fit.c > +++ b/common/image-fit.c > @@ -25,6 +25,10 @@ > #include > #include > #include > +#ifdef CONFIG_DM_HASH > +#include > +#include > +#endif > DECLARE_GLOBAL_DATA_PTR; > #endif /* !USE_HOSTCC*/ > > @@ -1214,6 +1218,31 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) > int calculate_hash(const void *data, int data_len, const char *algo, > uint8_t *value, int *value_len) > { > +#if !defined(USE_HOSTCC) && defined(CONFIG_DM_HASH) This file is shared in its entirety with host tools. There isn't a huge opportunity for using a DM-type approach here without #ifndef USE_HOSTCC. Alex > + int rc; > + enum HASH_ALGO hash_algo; > + struct udevice *dev; > + > + rc = uclass_get_device(UCLASS_HASH, 0, &dev); > + if (rc) { > + debug("failed to get hash device, rc=%d\n", rc); > + return -1; > + } > + > + hash_algo = hash_algo_lookup_by_name(algo); > + if (hash_algo == HASH_ALGO_INVALID) { > + debug("Unsupported hash algorithm\n"); > + return -1; > + }; > + > + rc = hash_digest_wd(dev, hash_algo, data, data_len, value, CHUNKSZ); > + if (rc) { > + debug("failed to get hash value, rc=%d\n", rc); > + return -1; > + } > + > + *value_len = hash_algo_digest_size(hash_algo); > +#else > if (IMAGE_ENABLE_CRC32 && strcmp(algo, "crc32") == 0) { > *((uint32_t *)value) = crc32_wd(0, data, data_len, > CHUNKSZ_CRC32); > @@ -1242,6 +1271,7 @@ int calculate_hash(const void *data, int data_len, const char *algo, > debug("Unsupported hash alogrithm\n"); > return -1; > } > +#endif > return 0; > } > >