From patchwork Wed May 13 14:23:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289349 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=FyCU4Rr1; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McPr36wvz9sRR for ; Thu, 14 May 2020 00:24:48 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4351281E5A; Wed, 13 May 2020 16:24:45 +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="FyCU4Rr1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B80D481DED; Wed, 13 May 2020 16:24:42 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 6342A81DED for ; Wed, 13 May 2020 16:24:39 +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-io1-xd44.google.com with SMTP id d7so18234063ioq.5 for ; Wed, 13 May 2020 07:24:39 -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=wFbO1FAoyE03vbe8jkQQ8nn4WzbVOYWnNEn2/2cZnrw=; b=FyCU4Rr1bbYB76g2ha//yxKtHzKaU46VT246NlFEAY7QTztqTFMCll8XzpW4OLJZWV hH/q6sB3tMlwBzp2mwucJ43Dno94cO7B5U3SYjGEmYuDxRG77ogTZTJQUdZfyoEyBdVp pfVD0p5nf226+IgyVFE/8nNQQ/imVdHEHqT6g= 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=wFbO1FAoyE03vbe8jkQQ8nn4WzbVOYWnNEn2/2cZnrw=; b=X3bKHghyjoXgsghhflVspU1r0mD6MzyWSrDn+ZJgyb10sTXLf28WqhujqbCID3kDKW 8OtGWCUBeCHjL6gfM+6Ii3JO2un6wAqrQuEZPVbEwwIDlkw2VGaIb2MQrKpxZnaaTRTY 8qXtl8BEm5hSgIIqtA14I2DQcqgBDihlSX60k7vEThde7nzUaa/u6/SiMUENpDbaxVaT rwDK/CzaXZLZtBJUgBsrqr02c7e2tlvn04pksRd9OFT75MGhQqGRjWBJOJ57zj3UqeY/ FmVZ7lbZrR9ZnqzIdO2g7x9hPtVRmuQL2O2eGVZ6N2GneLsJOAytsU0mriKdP7Zlugf2 uLSQ== X-Gm-Message-State: AGi0PuaKe4JjHrm9ihnQDzLi2/4NKvThYi/ZFYRbO5HLNTTho2f8QqLU MVRD3d+iGcsLm4MwiPcq30ltk3ul6FA= X-Google-Smtp-Source: APiQypIovRnGT9IdH30MxaNooRoIiWfDsTmigWlJzqjalAgWanO5J7ZaYhmijLnASqQrbzkhFRrfYw== X-Received: by 2002:a05:6602:2cc9:: with SMTP id j9mr6139005iow.181.1589379878115; Wed, 13 May 2020 07:24:38 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:37 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Stefan Reinauer Subject: [PATCH 01/13] cbfs: Rename the result variable Date: Wed, 13 May 2020 08:23:47 -0600 Message-Id: <20200513142359.147589-2-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean At present the result variable in the cbfs_priv is called 'result' as is the local variable in a few functions. Change the latter to 'ret' which is more common in U-Boot and avoids confusion. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 1aa6f8ee84..70440aa80b 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -145,18 +145,18 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, priv->file_cache = NULL; while (size >= align) { - int result; + int ret; u32 used; new_node = (struct cbfs_cachenode *) malloc(sizeof(struct cbfs_cachenode)); - result = file_cbfs_next_file(priv, start, size, align, new_node, - &used); + ret = file_cbfs_next_file(priv, start, size, align, new_node, + &used); - if (result < 0) { + if (ret < 0) { free(new_node); return; - } else if (result == 0) { + } else if (ret == 0) { free(new_node); break; } @@ -341,15 +341,15 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, align = priv->header.align; while (size >= align) { - int result; + int ret; u32 used; - result = file_cbfs_next_file(priv, start, size, align, &node, - &used); + ret = file_cbfs_next_file(priv, start, size, align, &node, + &used); - if (result < 0) + if (ret < 0) return NULL; - else if (result == 0) + else if (ret == 0) break; if (!strcmp(name, node.name)) From patchwork Wed May 13 14:23:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289350 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=IH0FS/2g; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McQ45PR0z9sRR for ; Thu, 14 May 2020 00:25:00 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8ED8A81E64; Wed, 13 May 2020 16:24:50 +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="IH0FS/2g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0297381E5A; Wed, 13 May 2020 16:24:44 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (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 9250E81DF9 for ; Wed, 13 May 2020 16:24:40 +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-il1-x142.google.com with SMTP id q10so16117015ile.0 for ; Wed, 13 May 2020 07:24:40 -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=zhOMw9KQ8wkNvZB1uYn3DY8VY7MJNYOOL7rukVjc2kk=; b=IH0FS/2gmftDxEmo/2cKgFTE7AUSO8qnV3IavbMz+k5y5m/INd7lb18gzuj5eOuCac w3NbewtDRxNKd4FsRqYIIuoPXPS5urFzYShdZjd2WWIK5J0koRISWx27zuK7mIfYvbrz EA96oJSw1beTnI/SSd1tdTqAthp66xyh8jMNk= 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=zhOMw9KQ8wkNvZB1uYn3DY8VY7MJNYOOL7rukVjc2kk=; b=Dl74DMPAiwKMXQq86h8FZLrv0wMP7anXGpvKko+sQ8jPzph6T3brEfzwi1leD/Tlwv rzCrUfXXEQckZjJ8GixCZyZfGZYPatqv5Fug1F9yzuNB1Izt4p+Xeg6jle9vpDdFXY3D Wztf9XgD6m3UYkhtUJXfuOVR/cjlRSahoUIbjMHwQMzw7hfOUJqcTg9JtqwmeTbvbEP5 jsWx6dqAPOGSVR8ex+uhmoocZtNSbUPc3IL43qRYtcHgpqzHXY70gzvzHCN/OjFwD509 5zU+Ut8JxD10Vvut7gyyucwCDC7XCXX7Re6Gxny7HabeLD0FYyIxICuY1egfFGBz022d 0WGQ== X-Gm-Message-State: AGi0PuZf+NwiwfT13Bu846IDjiF9XW5d8sbxsHqAN1qfbeIxqwKMi4ik QMkOeL5195NDzN//YfcA7kUOWEmqlFY= X-Google-Smtp-Source: APiQypKOmOPi+kAMA++DzTG7Xgl3/h2bE6ku6eLes5NOrzLrffVb7Llrcfx0aBYiX0/Zeyi5QVmnwQ== X-Received: by 2002:a92:d182:: with SMTP id z2mr24984504ilz.36.1589379879080; Wed, 13 May 2020 07:24:39 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:38 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Heinrich Schuchardt , Stefan Reinauer Subject: [PATCH 02/13] cbfs: Use ulong consistently Date: Wed, 13 May 2020 08:23:48 -0600 Message-Id: <20200513142359.147589-3-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean U-Boot uses ulong for addresses but there are a few places in this driver that don't use it. Convert this driver over to follow this convention fully. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 9 ++++----- include/cbfs.h | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 70440aa80b..846102dce3 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -170,8 +170,7 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, } /* Get the CBFS header out of the ROM and do endian conversion. */ -static int file_cbfs_load_header(uintptr_t end_of_rom, - struct cbfs_header *header) +static int file_cbfs_load_header(ulong end_of_rom, struct cbfs_header *header) { struct cbfs_header *header_in_rom; int32_t offset = *(u32 *)(end_of_rom - 3); @@ -204,7 +203,7 @@ static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base, return 0; } -static void cbfs_init(struct cbfs_priv *priv, uintptr_t end_of_rom) +static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) { u8 *start_of_rom; @@ -221,7 +220,7 @@ static void cbfs_init(struct cbfs_priv *priv, uintptr_t end_of_rom) priv->initialized = 1; } -void file_cbfs_init(uintptr_t end_of_rom) +void file_cbfs_init(ulong end_of_rom) { cbfs_init(&cbfs_s, end_of_rom); } @@ -324,7 +323,7 @@ const struct cbfs_cachenode *file_cbfs_find(const char *name) return cbfs_find_file(&cbfs_s, name); } -const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, +const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom, const char *name) { struct cbfs_priv *priv = &cbfs_s; diff --git a/include/cbfs.h b/include/cbfs.h index d915f9426d..10e951dccf 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -103,7 +103,7 @@ enum cbfs_result cbfs_get_result(void); * @end_of_rom: Points to the end of the ROM the CBFS should be read * from. */ -void file_cbfs_init(uintptr_t end_of_rom); +void file_cbfs_init(ulong end_of_rom); /** * file_cbfs_get_header() - Get the header structure for the current CBFS. @@ -172,7 +172,7 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp); * * @return A handle to the file, or NULL on error. */ -const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, +const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom, const char *name); /** From patchwork Wed May 13 14:23:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289351 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=hnxfKRUv; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McQN2Cj6z9sRR for ; Thu, 14 May 2020 00:25:16 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8CC8C81E03; Wed, 13 May 2020 16:24:53 +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="hnxfKRUv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A130381E00; Wed, 13 May 2020 16:24:46 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) (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 15B8D81E00 for ; Wed, 13 May 2020 16:24:41 +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-il1-x144.google.com with SMTP id b15so894886ilq.12 for ; Wed, 13 May 2020 07:24:41 -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=5LfzBpTT6JE3RLypBQyM9N5ECzXYmdGVdfgHvf+agCI=; b=hnxfKRUvlrv2z8fP6DcENazpmPQVVxkjwBR+gZld4mwFs3HP2sUPzGrVBCSs7d8Fkh 4qt8bCjLJugtadCgy2ZHW6QmE8aPd5z+RkzbmbKHSmvy14N+YNx8HlAPGKpddQXQkuFN sTKs/NxI4QgL7k2X+nw715IcN3XlEAloOGQYA= 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=5LfzBpTT6JE3RLypBQyM9N5ECzXYmdGVdfgHvf+agCI=; b=eaE0eXN6Gf8MNLXLK4CvuwbtxLl/166H3Z3AqIWrf+wvj07ivFNMGJgFgIhgXIFkdS gliyx0sijCvjBvuci5El+5xrpRthXr5w6m1guVZiI+4dloVgsoDHxjZk80VzeLCh+KCR B0k5+5y6ElpXqccuY1v+M+mMH8vca9cqE8QOkxhAzIBp54Pct9zEi8wNKKAhnHR/Vcky 6zR8kIL2MkyumrjCr/Y7a0/LFMm6pUpAFFBoIhMKXbi94b4xAPMgSvhEX5dHvx523LWz lbV0caQT9kjxDkwkux4iexYDCIvsHE3xKQ+3Esay11XfWb74ig4NT/0WbRJk0x1hopn0 4JpQ== X-Gm-Message-State: AGi0PuYbFKQSE6K5ewXD6QN57Hm6osnzceVMBwuEWP/s9rDG497zXeqq bB2mCdDo5b1Aq7LAWQO7sjPM5l/lNTM= X-Google-Smtp-Source: APiQypKlcLJObrD74xqpLYT1Qg/OpMabuF6aKqLh7dY5/uxueXoqQl2cTfQ8TWs9242bBRhvEuYSyg== X-Received: by 2002:a92:d846:: with SMTP id h6mr27160939ilq.196.1589379879858; Wed, 13 May 2020 07:24:39 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:39 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Heinrich Schuchardt , Stefan Reinauer Subject: [PATCH 03/13] cbfs: Use bool type for whether initialised Date: Wed, 13 May 2020 08:23:49 -0600 Message-Id: <20200513142359.147589-4-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean At present this uses an int type. U-Boot now supports bool so use this instead. Also use English spelling for initialised which we are here. Signed-off-by: Simon Glass --- fs/cbfs/cbfs.c | 28 ++++++++++++++-------------- include/cbfs.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 846102dce3..322778d1c8 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -12,7 +12,7 @@ static const u32 good_magic = 0x4f524243; static const u8 good_file_magic[] = "LARCHIVE"; struct cbfs_priv { - int initialized; + bool initialised; struct cbfs_header header; struct cbfs_cachenode *file_cache; enum cbfs_result result; @@ -25,8 +25,8 @@ const char *file_cbfs_error(void) switch (cbfs_s.result) { case CBFS_SUCCESS: return "Success"; - case CBFS_NOT_INITIALIZED: - return "CBFS not initialized"; + case CBFS_NOT_INITIALISED: + return "CBFS not initialised"; case CBFS_BAD_HEADER: return "Bad CBFS header"; case CBFS_BAD_FILE: @@ -207,7 +207,7 @@ static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) { u8 *start_of_rom; - priv->initialized = 0; + priv->initialised = false; if (file_cbfs_load_header(end_of_rom, &priv->header)) return; @@ -217,7 +217,7 @@ static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size, priv->header.align); if (priv->result == CBFS_SUCCESS) - priv->initialized = 1; + priv->initialised = true; } void file_cbfs_init(ulong end_of_rom) @@ -244,7 +244,7 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) if (priv->result != CBFS_SUCCESS) return -EINVAL; - priv->initialized = 1; + priv->initialised = true; priv = malloc(sizeof(priv_s)); if (!priv) return -ENOMEM; @@ -258,11 +258,11 @@ const struct cbfs_header *file_cbfs_get_header(void) { struct cbfs_priv *priv = &cbfs_s; - if (priv->initialized) { + if (priv->initialised) { priv->result = CBFS_SUCCESS; return &priv->header; } else { - priv->result = CBFS_NOT_INITIALIZED; + priv->result = CBFS_NOT_INITIALISED; return NULL; } } @@ -271,8 +271,8 @@ const struct cbfs_cachenode *file_cbfs_get_first(void) { struct cbfs_priv *priv = &cbfs_s; - if (!priv->initialized) { - priv->result = CBFS_NOT_INITIALIZED; + if (!priv->initialised) { + priv->result = CBFS_NOT_INITIALISED; return NULL; } else { priv->result = CBFS_SUCCESS; @@ -284,8 +284,8 @@ void file_cbfs_get_next(const struct cbfs_cachenode **file) { struct cbfs_priv *priv = &cbfs_s; - if (!priv->initialized) { - priv->result = CBFS_NOT_INITIALIZED; + if (!priv->initialised) { + priv->result = CBFS_NOT_INITIALISED; *file = NULL; return; } @@ -300,8 +300,8 @@ const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv, { struct cbfs_cachenode *cache_node = priv->file_cache; - if (!priv->initialized) { - priv->result = CBFS_NOT_INITIALIZED; + if (!priv->initialised) { + priv->result = CBFS_NOT_INITIALISED; return NULL; } diff --git a/include/cbfs.h b/include/cbfs.h index 10e951dccf..80ce539070 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -11,7 +11,7 @@ enum cbfs_result { CBFS_SUCCESS = 0, - CBFS_NOT_INITIALIZED, + CBFS_NOT_INITIALISED, CBFS_BAD_HEADER, CBFS_BAD_FILE, CBFS_FILE_NOT_FOUND From patchwork Wed May 13 14:23:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289353 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=ogQkoy85; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McQz1kZSz9sRf for ; Thu, 14 May 2020 00:25:47 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DB76181E71; Wed, 13 May 2020 16:24:57 +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="ogQkoy85"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7484381D92; Wed, 13 May 2020 16:24:47 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 0238881D92 for ; Wed, 13 May 2020 16:24:42 +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-io1-xd44.google.com with SMTP id w25so3553437iol.12 for ; Wed, 13 May 2020 07:24:41 -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=3PdRTvt3O92/5NjwPPCnWmktN8WvvYumrfJbj1ZPUzQ=; b=ogQkoy85vCLhCgToPgZ+9gTceb7EE7xm1dZDQ7x7567tx7hW37aOima+xEcfiw/iM+ 6E+BjeaZbUH+DCI51F+bRoXhVBzbt+qgEQJEJfmfaJBAT73NOYsX5KfG2KV4UNyMPmxq yRSwjd7UFZn2imD4cIL5EBs5UR1LstgUIDzPk= 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=3PdRTvt3O92/5NjwPPCnWmktN8WvvYumrfJbj1ZPUzQ=; b=Lx/G/3ZDwp4yAFEbTHljINhX5bgrfSMK3cpWPBlL8tg8SmFpgE86sBBfNnzflJs333 Ia04awXEcZKu2XwSlwOjwVV4qHz3bBAphrkOwRy4rZYYey9iuZGiHlm8pa3bgnjt0Ug/ w+hlYGhkUglV8YZBv3lawk0r4GKfD1rI5oSXNmVZ70voXeiXJWSA8LwFTKgMCQZ2Qf+W 9PUsR2mxu6NoDoskRp7hRwue3+gRZlVCPOFmuNH6gUSRalD2/K2ns9DEn5QmCaSjQlAz c0QAlzLt6NYyIl7ENc1Xzxd/CuO4yX3zM44+neG3NXGX8GABg1KgDOZXw/pHasWTICgq OEjA== X-Gm-Message-State: AGi0PuZdVxTpHNJtiN4wnQ9BjHfJZ+aABrK/iRk9p4m6RsyU/H79V0rK Bk/6yRzqhovmrmDYLBXTlyJ0JKgC6vw= X-Google-Smtp-Source: APiQypK4B2fPH9Vd4Yk08rIOVNfp0aRPzdynhMKAVr6Tm3VZBsN7M/SsREvmUmO6sI/uEJNWmeh4TA== X-Received: by 2002:a6b:f60f:: with SMTP id n15mr25871315ioh.22.1589379880596; Wed, 13 May 2020 07:24:40 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:40 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Stefan Reinauer Subject: [PATCH 04/13] cbfs: Adjust return value of file_cbfs_next_file() Date: Wed, 13 May 2020 08:23:50 -0600 Message-Id: <20200513142359.147589-5-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean At present his uses a true return to indicate it found a file. Adjust it to use 0 for this, so it is consistent with other functions. Update its callers accordingling and add a check for malloc() failure in file_cbfs_fill_cache(). Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 322778d1c8..1037d19225 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -77,11 +77,12 @@ static void swap_file_header(struct cbfs_fileheader *dest, * @param used A pointer to the count of of bytes scanned through, * including the file if one is found. * - * @return 1 if a file is found, 0 if one isn't. + * @return 0 if a file is found, -ENOENT if one isn't, -EBADF if a bad header + * is found. */ -static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, - u32 align, struct cbfs_cachenode *new_node, - u32 *used) +static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, int size, + int align, struct cbfs_cachenode *new_node, + int *used) { struct cbfs_fileheader header; @@ -105,7 +106,7 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, swap_file_header(&header, file_header); if (header.offset < sizeof(struct cbfs_fileheader)) { priv->result = CBFS_BAD_FILE; - return -1; + return -EBADF; } new_node->next = NULL; new_node->type = header.type; @@ -122,14 +123,15 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, step = step + align - step % align; *used += step; - return 1; + return 0; } - return 0; + + return -ENOENT; } /* Look through a CBFS instance and copy file metadata into regular memory. */ -static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, - u32 align) +static int file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, + u32 align) { struct cbfs_cachenode *cache_node; struct cbfs_cachenode *new_node; @@ -145,20 +147,21 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, priv->file_cache = NULL; while (size >= align) { + int used; int ret; - u32 used; new_node = (struct cbfs_cachenode *) malloc(sizeof(struct cbfs_cachenode)); + if (!new_node) + return -ENOMEM; ret = file_cbfs_next_file(priv, start, size, align, new_node, &used); if (ret < 0) { free(new_node); - return; - } else if (ret == 0) { - free(new_node); - break; + if (ret == -ENOENT) + break; + return ret; } *cache_tail = new_node; cache_tail = &new_node->next; @@ -167,6 +170,8 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, start += used; } priv->result = CBFS_SUCCESS; + + return 0; } /* Get the CBFS header out of the ROM and do endian conversion. */ @@ -341,16 +346,14 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom, while (size >= align) { int ret; - u32 used; + int used; ret = file_cbfs_next_file(priv, start, size, align, &node, &used); - - if (ret < 0) - return NULL; - else if (ret == 0) + if (ret == -ENOENT) break; - + else if (ret) + return NULL; if (!strcmp(name, node.name)) return &node; From patchwork Wed May 13 14:23:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289354 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=EJNcq0QI; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McRF3qRNz9sRR for ; Thu, 14 May 2020 00:26:01 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 81E5981E75; Wed, 13 May 2020 16:24:59 +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="EJNcq0QI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EEAF181E63; Wed, 13 May 2020 16:24:47 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) (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 9C4C981E32 for ; Wed, 13 May 2020 16:24:42 +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-il1-x143.google.com with SMTP id 17so8979959ilj.3 for ; Wed, 13 May 2020 07:24:42 -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=1uX/sK0CYyssCCIThNtvPJUAM5P7VIq6m+7wb6+1R2g=; b=EJNcq0QIDjWyYTgaGWc5H9MiSzEMxA70Uy9Wl1pnNr3mDrBE5OZQUmUk1D6xEwXrng 1PVgxl+IdFymhdy49ZyyLVgkWRDt/Fx7SL6wc/kWp1QRi0vssuxpDPSZ+GnIbZkiiHLu +eMCT9nWIo1Tpa2/MmNk1wLO5kltJOehqedK4= 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=1uX/sK0CYyssCCIThNtvPJUAM5P7VIq6m+7wb6+1R2g=; b=dGJnTXAyEnGP/8QdcStqcFy5Wor4p+qH5Hdo7e51Lfbyi6zH4TGrEK0C+vC0TfpdO0 H6HLFnTN3NrcfPrAdOO85Ydbi9U3vRuUv1scF+/DT1t1SNlRRcRzkn/+yhlDmYC5f6zv Lc0xp3l0LV3K+7g4t1LWb7NCH3S9YaQp5T6dYYw/zybmEBXqKrWRKUAFn0Hw1UZC9vdl fDTS7ZA6MUYwgR69qIVNF275s/cC+SvvSG3E4myqdZmhzhFI+kpUo2oBEvinLF/IORQl cYq+Px6OLd43a8CD7UXq4qJgeLnsdfQYgj1n8MA4/CvYoo/lXBFQbIumm4loDywo47/9 Z9OQ== X-Gm-Message-State: AOAM533RU+MYsay063Bq/ZxNZP88X179yNT4Rn6ZjXHTKBn98z6Zx1vp Sgt1cV5lQwndM1HuDfPYtZ/O6Afx1AM= X-Google-Smtp-Source: ABdhPJw+HpXlaKF9oA64Lseil9Tx0ncwHXY+sTYj22CE2ZlyzvzR0bv19X3Ys0JailMRXmIIlFtWXg== X-Received: by 2002:a92:3a8a:: with SMTP id i10mr2283233ilf.175.1589379881409; Wed, 13 May 2020 07:24:41 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:41 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Stefan Reinauer Subject: [PATCH 05/13] cbfs: Adjust file_cbfs_load_header() to use cbfs_priv Date: Wed, 13 May 2020 08:23:51 -0600 Message-Id: <20200513142359.147589-6-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean This function is strange at the moment in that it takes a header pointer but then accesses the cbfs_s global. Currently clients have their own priv pointer, so update the function to take that as a parameter instead. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 1037d19225..765e078423 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -175,8 +175,9 @@ static int file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, } /* Get the CBFS header out of the ROM and do endian conversion. */ -static int file_cbfs_load_header(ulong end_of_rom, struct cbfs_header *header) +static int file_cbfs_load_header(struct cbfs_priv *priv, ulong end_of_rom) { + struct cbfs_header *header = &priv->header; struct cbfs_header *header_in_rom; int32_t offset = *(u32 *)(end_of_rom - 3); @@ -185,7 +186,7 @@ static int file_cbfs_load_header(ulong end_of_rom, struct cbfs_header *header) if (header->magic != good_magic || header->offset > header->rom_size - header->boot_block_size) { - cbfs_s.result = CBFS_BAD_HEADER; + priv->result = CBFS_BAD_HEADER; return 1; } return 0; @@ -214,7 +215,7 @@ static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) priv->initialised = false; - if (file_cbfs_load_header(end_of_rom, &priv->header)) + if (file_cbfs_load_header(priv, end_of_rom)) return; start_of_rom = (u8 *)(end_of_rom + 1 - priv->header.rom_size); @@ -337,7 +338,7 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom, u32 align; static struct cbfs_cachenode node; - if (file_cbfs_load_header(end_of_rom, &priv->header)) + if (file_cbfs_load_header(priv, end_of_rom)) return NULL; start = (u8 *)(end_of_rom + 1 - priv->header.rom_size); From patchwork Wed May 13 14:23:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289352 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=at7xzwgx; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McQj257Pz9sRR for ; Thu, 14 May 2020 00:25:33 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4E50781E5F; Wed, 13 May 2020 16:24:55 +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="at7xzwgx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 81D6381E62; Wed, 13 May 2020 16:24:47 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) (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 5B56981E03 for ; Wed, 13 May 2020 16:24:43 +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-il1-x144.google.com with SMTP id e8so8164669ilm.7 for ; Wed, 13 May 2020 07:24:43 -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=bzL0myoQRzEaLwOAr8sBsOFV8DbbCs0JsrUxoCM6Q5Q=; b=at7xzwgxURWpLfdhfNb3LEUUVgUtmgIUjVWwjPDVpmjW2rxaaO1SRc6mLu3e1+Vgm3 yNAuPzHJD5u+vNHny9sCGCZiozFll83PjxjzkRgsQTMVm/XA63mJYmiJLjxIKMcFs1AS dKn6h8peM0JmIVuoaHgn+rd6Qnj8SgCKy3U9M= 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=bzL0myoQRzEaLwOAr8sBsOFV8DbbCs0JsrUxoCM6Q5Q=; b=BSv9VVmP4gDfoxAXnIj6jzUdlHMffsNJwWbhVFBpa79/K2uTqrvmJaewRKAELcjnjF Q7yy7O1z6wbYfguvedjGjgWR5h43/tFCtudnjPYWAt56ZrbfYZdrXvmA/KlGWtl6F6tL MsA2s2ogX/z1n9Iw3xGH1cyQ+888TmY47fRLs2+z6StoCQ0LeutKDe1+00jZqiNeI8yN y30WaRi1/USphVzcOgQDI5CkVxCWNlO5ebw36DoczgeYlXa/225Lm5aPT5xAlXaaa6Km Q2nsls6EXYUfPbPyjnbXxdjpYz7N3pLhF/mIFU+38lFohO7zodM1Dam0JVSMA7FG7xzJ BIHQ== X-Gm-Message-State: AGi0PuZIMX1QLKL8Zrfc0MiNlTkFFokAD6X0MUEcUVnScUDPaYAr/+hP uUR3uIE9Th9n3aEu/R1Q2fAOb0idXmE= X-Google-Smtp-Source: APiQypJJ5w5vQlpgENRiFu6CDOikHyJR5rGgUQvzFYLj48+Aa8VqUD0XsKEh7sdtTgHMjIV8duRosQ== X-Received: by 2002:a05:6e02:1069:: with SMTP id q9mr18920254ilj.155.1589379882131; Wed, 13 May 2020 07:24:42 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:41 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Stefan Reinauer Subject: [PATCH 06/13] cbfs: Adjust cbfs_load_header_ptr() to use cbfs_priv Date: Wed, 13 May 2020 08:23:52 -0600 Message-Id: <20200513142359.147589-7-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean This function is strange at the moment in that it takes a header pointer but then accesses the cbfs_s global. Currently clients have their own priv pointer, so update the function to take that as a parameter instead. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 765e078423..05de58cf19 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -8,6 +8,9 @@ #include #include +/* Offset of master header from the start of a coreboot ROM */ +#define MASTER_HDR_OFFSET 0x38 + static const u32 good_magic = 0x4f524243; static const u8 good_file_magic[] = "LARCHIVE"; @@ -192,9 +195,9 @@ static int file_cbfs_load_header(struct cbfs_priv *priv, ulong end_of_rom) return 0; } -static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base, - struct cbfs_header *header) +static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base) { + struct cbfs_header *header = &priv->header; struct cbfs_header *header_in_rom; header_in_rom = (struct cbfs_header *)base; @@ -241,7 +244,7 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) * valid. Assume that a master header appears at the start, at offset * 0x38. */ - ret = cbfs_load_header_ptr(priv, base + 0x38, &priv->header); + ret = cbfs_load_header_ptr(priv, base + MASTER_HDR_OFFSET); if (ret) return ret; From patchwork Wed May 13 14:23:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289355 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=gqChj/1C; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McRV4nm3z9sRf for ; Thu, 14 May 2020 00:26:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B9B4A81E7A; Wed, 13 May 2020 16:25:05 +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="gqChj/1C"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C85C081E62; Wed, 13 May 2020 16:24:48 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 9759081DB7 for ; Wed, 13 May 2020 16:24:44 +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-io1-xd44.google.com with SMTP id u11so18239702iow.4 for ; Wed, 13 May 2020 07:24:44 -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=/vgbgalZdt9d/s6UKLtoHdlrVBXTjiObb8bJA9sVqlY=; b=gqChj/1CsMnnipllXSDRiLdateJPraEG+xMUSKp4ZCPwgK0Yi0QUqJ5ua0Y6PdI5G/ 54LEbcIWygeo2SEJFTVPEWMejQmf5BwMRsYaa9bdBTa8jOP9r89xgNkOWvLQnnOHnI4W g+yLuJ5ZSRwfQdKNsl1o1DErhDQvKRetXtcmQ= 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=/vgbgalZdt9d/s6UKLtoHdlrVBXTjiObb8bJA9sVqlY=; b=ZjNDLLsI/LiGGU0GW9XK1R50rwFGQXdX80LRfzoDmg1D14fPI71OulvhMv1CYv2G/6 1ejk+hKVYMHJwBQ0nrs0BYIkcpdTkAL6htETWMNtfTZ/pT6yV8l17khW+kfCX8S64kMh Yj4WXRV3LUdqsS6ff2l9MBGo/Zmih7wgo89cK5wx0fF5Qf7VDDIUO87wRpsY6T/M4X73 s3NRqs9nV43uFKqEuTj1+1CJYXFDSBHtCUjULHpxLDU9AuURVAyXh94BvIL6iinBsi8o 61zz9oIwFaOuozvkjSkHrj7qvGRIpLoerznTlkbPwVwalud+pJeTfgG3RA88DngRDdF2 jozQ== X-Gm-Message-State: AGi0PuZUTQlLBKTJR5ZMR2gBOjwpnK6WMn9i50E2z7ZDnpzPawC81buA 1Qxu0/J+UcuElieckpeXZERXtM3LpcA= X-Google-Smtp-Source: APiQypKdvpCzBWhkgxswzvFgzhffwic7k4v8TiyamTgtBte+h1XALmGrlaBweVWFEpg1aItGSEewPw== X-Received: by 2002:a6b:3805:: with SMTP id f5mr26433741ioa.156.1589379882926; Wed, 13 May 2020 07:24:42 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:42 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Stefan Reinauer Subject: [PATCH 07/13] cbfs: Unify the two header loaders Date: Wed, 13 May 2020 08:23:53 -0600 Message-Id: <20200513142359.147589-8-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean These two functions have mostly the same code. Pull this out into a common function. Also make this function zero the private data so that callers don't have to do it. Finally, update cbfs_load_header_ptr() to take the base of the ROM as its parameter, which makes more sense than passing the address of the header within the ROM. Signed-off-by: Simon Glass --- fs/cbfs/cbfs.c | 59 +++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 05de58cf19..b4e6b959d1 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -177,47 +177,63 @@ static int file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, return 0; } -/* Get the CBFS header out of the ROM and do endian conversion. */ -static int file_cbfs_load_header(struct cbfs_priv *priv, ulong end_of_rom) +/** + * load_header() - Load the CBFS header + * + * Get the CBFS header out of the ROM and do endian conversion. + * + * @priv: Private data, which is inited by this function + * @addr: Address of CBFS header in memory-mapped SPI flash + * @return 0 if OK, -ENXIO if the header is bad + */ +static int load_header(struct cbfs_priv *priv, ulong addr) { struct cbfs_header *header = &priv->header; struct cbfs_header *header_in_rom; - int32_t offset = *(u32 *)(end_of_rom - 3); - header_in_rom = (struct cbfs_header *)(end_of_rom + offset + 1); + memset(priv, '\0', sizeof(*priv)); + header_in_rom = (struct cbfs_header *)addr; swap_header(header, header_in_rom); if (header->magic != good_magic || header->offset > header->rom_size - header->boot_block_size) { priv->result = CBFS_BAD_HEADER; - return 1; + return -ENXIO; } + return 0; } -static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base) +/** + * file_cbfs_load_header() - Get the CBFS header out of the ROM, given the end + * + * @priv: Private data, which is inited by this function + * @addr: Address of the last byte of the ROM (typically 0xffffffff) + * @return 0 if OK, -ENXIO if the header is bad + */ +static int file_cbfs_load_header(struct cbfs_priv *priv, ulong end_of_rom) { - struct cbfs_header *header = &priv->header; - struct cbfs_header *header_in_rom; - - header_in_rom = (struct cbfs_header *)base; - swap_header(header, header_in_rom); + int offset = *(u32 *)(end_of_rom - 3); - if (header->magic != good_magic || header->offset > - header->rom_size - header->boot_block_size) { - priv->result = CBFS_BAD_HEADER; - return -EFAULT; - } + return load_header(priv, end_of_rom + offset + 1); +} - return 0; +/** + * cbfs_load_header_ptr() - Get the CBFS header out of the ROM, given the base + * + * @priv: Private data, which is inited by this function + * @addr: Address of the first byte of the ROM (e.g. 0xff000000) + * @return 0 if OK, -ENXIO if the header is bad + */ +static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base) +{ + return load_header(priv, base + MASTER_HDR_OFFSET); } static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) { u8 *start_of_rom; - priv->initialised = false; - if (file_cbfs_load_header(priv, end_of_rom)) return; @@ -241,10 +257,9 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) /* * Use a local variable to start with until we know that the CBFS is - * valid. Assume that a master header appears at the start, at offset - * 0x38. + * valid. */ - ret = cbfs_load_header_ptr(priv, base + MASTER_HDR_OFFSET); + ret = cbfs_load_header_ptr(priv, base); if (ret) return ret; From patchwork Wed May 13 14:23:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289356 X-Patchwork-Delegate: bmeng.cn@gmail.com 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; dmarc=pass (p=none dis=none) header.from=chromium.org 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=Cnnx0oMu; 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49McRn38pFz9sRR for ; Thu, 14 May 2020 00:26:29 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A43DA81E72; Wed, 13 May 2020 16:25:10 +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="Cnnx0oMu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C017081E62; Wed, 13 May 2020 16:24:49 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) (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 6CF5A81E5F for ; Wed, 13 May 2020 16:24:45 +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-io1-xd41.google.com with SMTP id u11so18239752iow.4 for ; Wed, 13 May 2020 07:24:45 -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=mMXjcMSk5vX3uk2pBLfOw93Zj/Ln4HK9OIYO5VG4fqA=; b=Cnnx0oMumdW0TZbzARPKHNj4ntFql5z6SArjIVUnXK+XDZ+oUcG/04zh9OEvqxhP7r Lw+UL2tgVYzLQMbOeiSlyVO7sZtAMZu/6ZTaNf5kzsULyWS1ryjio9uQdTg0H2ffMfHe YAXcTDwyXGBE1l88Gaj2EPm8ZHoEdmCOTzAFI= 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=mMXjcMSk5vX3uk2pBLfOw93Zj/Ln4HK9OIYO5VG4fqA=; b=jVpyTXDO4QEWm8Lw1w6t0bPy5NdAF07YOEh0p4mxwJkTX7/YXTSKJ7hCeVYYfc7ZwW IUcxB0LewRCSZRv1AzO/CU/yVhtgbz3A2c+JIrIX+hoiSfuehKc6zyylnyhhGld9o2RD EGXtOaVig+RHiYwcfUIPzC1yLL5jq1Z6JAn5IwH2rM9CwdVUrNQn9zST7shoq9tPe1km qq8gxroEseAr1N6H1Ea+7dr1EenGXZOaA9kR0TaWvcg5C2xmSfS/HYpo9eRN+4RYNv96 kMid0L7sQULBZkaLzPniM/1suh8TWwaBFAIlQGIyTAaAC6IQEf/iBIx3fLgU7ZyVYGRE mC6w== X-Gm-Message-State: AGi0PuazmzeqylAZYdzApeOJJ55W3jy6RBMqRDQxIJPGjNrHheNlOsy+ ksK4emm0q2uInNvTLD5FizbSpXX1faY= X-Google-Smtp-Source: APiQypKNvR9T0MkJxC4Pqli8mVLv/3sM+qK1oLwF8eAUukCRXv/r/TlqGi1QLOFoWHVLBN7W5vmp/w== X-Received: by 2002:a6b:5c14:: with SMTP id z20mr7201913ioh.176.1589379883701; Wed, 13 May 2020 07:24:43 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:43 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Stefan Reinauer Subject: [PATCH 08/13] cbfs: Use void * for the position pointers Date: Wed, 13 May 2020 08:23:54 -0600 Message-Id: <20200513142359.147589-9-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean It doesn't make sense to use u8 * as the pointer type for accessing the CBFS since we do not access it as bytes, but via structures. Change it to void *, which allows us to avoid a cast. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index b4e6b959d1..a4f9534724 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -83,7 +83,7 @@ static void swap_file_header(struct cbfs_fileheader *dest, * @return 0 if a file is found, -ENOENT if one isn't, -EBADF if a bad header * is found. */ -static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, int size, +static int file_cbfs_next_file(struct cbfs_priv *priv, void *start, int size, int align, struct cbfs_cachenode *new_node, int *used) { @@ -92,8 +92,7 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, int size, *used = 0; while (size >= align) { - const struct cbfs_fileheader *file_header = - (const struct cbfs_fileheader *)start; + const struct cbfs_fileheader *file_header = start; u32 name_len; u32 step; @@ -133,7 +132,7 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, int size, } /* Look through a CBFS instance and copy file metadata into regular memory. */ -static int file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, +static int file_cbfs_fill_cache(struct cbfs_priv *priv, void *start, u32 size, u32 align) { struct cbfs_cachenode *cache_node; @@ -232,12 +231,12 @@ static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base) static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) { - u8 *start_of_rom; + void *start_of_rom; if (file_cbfs_load_header(priv, end_of_rom)) return; - start_of_rom = (u8 *)(end_of_rom + 1 - priv->header.rom_size); + start_of_rom = (void *)(end_of_rom + 1 - priv->header.rom_size); file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size, priv->header.align); @@ -263,7 +262,7 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) if (ret) return ret; - file_cbfs_fill_cache(priv, (u8 *)base, priv->header.rom_size, + file_cbfs_fill_cache(priv, (void *)base, priv->header.rom_size, priv->header.align); if (priv->result != CBFS_SUCCESS) return -EINVAL; @@ -351,7 +350,7 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom, const char *name) { struct cbfs_priv *priv = &cbfs_s; - u8 *start; + void *start; u32 size; u32 align; static struct cbfs_cachenode node; @@ -359,7 +358,7 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom, if (file_cbfs_load_header(priv, end_of_rom)) return NULL; - start = (u8 *)(end_of_rom + 1 - priv->header.rom_size); + start = (void *)(end_of_rom + 1 - priv->header.rom_size); size = priv->header.rom_size; align = priv->header.align; From patchwork Wed May 13 14:23:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289357 X-Patchwork-Delegate: bmeng.cn@gmail.com 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; dmarc=pass (p=none dis=none) header.from=chromium.org 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=kTyhw6yq; 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 49McRx32qtz9sSf for ; Thu, 14 May 2020 00:26:37 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2710581E81; Wed, 13 May 2020 16:25:13 +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="kTyhw6yq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A1E4B81E63; Wed, 13 May 2020 16:24:50 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) (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 E924281E66 for ; Wed, 13 May 2020 16:24:45 +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-io1-xd44.google.com with SMTP id d7so18234424ioq.5 for ; Wed, 13 May 2020 07:24:45 -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=WMRgvpIDegoRGABn+Dyo/u9DxqPrijks3t6nHBScWwU=; b=kTyhw6yqI9+BC3tlx+3aU9ewD21jJAWzUlP8aQIl2J22+vVvhDWaeNagahZSa3Jmp+ ddYKrR2IWfnVxjQPefxIlh/EykGhlPVj+2fd7xe6pi+QYFYpj9hmfuUw0QPQko1HverZ oO7eUnXgMC+t+SluOtPWIRQ8KmI1xsVIOoMlE= 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=WMRgvpIDegoRGABn+Dyo/u9DxqPrijks3t6nHBScWwU=; b=c5v8XAjbkvNPGvUlaSDmkLZ/L37KjICH1krZvA8Eow6KD3d9Dbz7PTHzmu9H9uavWG g65cpDWaecg79jNnqJa3XaHw4ysRZLf1gnXxgTp/gseMUv6wo/BRv+0hEmUz3QW/pN2l zx4wm1u18wVBGr6wqOnfvk9CY/KgwNT40eSGrAm8QCqdYhGw3+LKJAKcMl4/oPPjGcye h3pq/eZpAaSE88RgsQtScXo7OkO4h6S4/yRIv+62mK+GCSiKNMiQyxtolLqvWmlg1q/e nNqsIZsq2CHJ7/HuZkh7PbzdpXEtJ2CNIR+hiOQtRjZifgVCvBrZKmFpSC/TID2YQtV6 2yZA== X-Gm-Message-State: AGi0PubDVEtVKzJ1fDsDB2GTCUl5U/c77VgFW1v+IGhFx4EZ1VmRjgDt 4u9m1X+RJoCKXVSTPCcFrFta8NIkBMU= X-Google-Smtp-Source: APiQypJ9jLyxb03nY8I92hveyemLU3xiUaF6Vy0d0kgJGO8c3kJhC2llNRxN5piW1l4VFaLBAhNLbg== X-Received: by 2002:a5d:8914:: with SMTP id b20mr3801214ion.34.1589379884534; Wed, 13 May 2020 07:24:44 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:44 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Stefan Reinauer Subject: [PATCH 09/13] cbfs: Record the start address in cbfs_priv Date: Wed, 13 May 2020 08:23:55 -0600 Message-Id: <20200513142359.147589-10-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean The start address of the CBFS is used when scanning for files. It makes sense to put this in our cbfs_priv struct and calculate it when we read the header. Update the code accordingly. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index a4f9534724..58de258da3 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -14,8 +14,18 @@ static const u32 good_magic = 0x4f524243; static const u8 good_file_magic[] = "LARCHIVE"; +/** + * struct cbfs_priv - Private data for this driver + * + * @initialised: true if this CBFS has been inited + * @start: Start position of CBFS in memory, typically memory-mapped SPI flash + * @header: Header read from the CBFS, byte-swapped so U-Boot can access it + * @file_cache: List of file headers read from CBFS + * @result: Success/error result + */ struct cbfs_priv { bool initialised; + void *start; struct cbfs_header header; struct cbfs_cachenode *file_cache; enum cbfs_result result; @@ -132,12 +142,12 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, void *start, int size, } /* Look through a CBFS instance and copy file metadata into regular memory. */ -static int file_cbfs_fill_cache(struct cbfs_priv *priv, void *start, u32 size, - u32 align) +static int file_cbfs_fill_cache(struct cbfs_priv *priv, int size, int align) { struct cbfs_cachenode *cache_node; struct cbfs_cachenode *new_node; struct cbfs_cachenode **cache_tail = &priv->file_cache; + void *start; /* Clear out old information. */ cache_node = priv->file_cache; @@ -148,6 +158,7 @@ static int file_cbfs_fill_cache(struct cbfs_priv *priv, void *start, u32 size, } priv->file_cache = NULL; + start = priv->start; while (size >= align) { int used; int ret; @@ -213,8 +224,14 @@ static int load_header(struct cbfs_priv *priv, ulong addr) static int file_cbfs_load_header(struct cbfs_priv *priv, ulong end_of_rom) { int offset = *(u32 *)(end_of_rom - 3); + int ret; + + ret = load_header(priv, end_of_rom + offset + 1); + if (ret) + return ret; + priv->start = (void *)(end_of_rom + 1 - priv->header.rom_size); - return load_header(priv, end_of_rom + offset + 1); + return 0; } /** @@ -226,20 +243,22 @@ static int file_cbfs_load_header(struct cbfs_priv *priv, ulong end_of_rom) */ static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base) { - return load_header(priv, base + MASTER_HDR_OFFSET); + int ret; + + ret = load_header(priv, base + MASTER_HDR_OFFSET); + if (ret) + return ret; + priv->start = (void *)base; + + return 0; } static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) { - void *start_of_rom; - if (file_cbfs_load_header(priv, end_of_rom)) return; - start_of_rom = (void *)(end_of_rom + 1 - priv->header.rom_size); - - file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size, - priv->header.align); + file_cbfs_fill_cache(priv, priv->header.rom_size, priv->header.align); if (priv->result == CBFS_SUCCESS) priv->initialised = true; } @@ -262,8 +281,7 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) if (ret) return ret; - file_cbfs_fill_cache(priv, (void *)base, priv->header.rom_size, - priv->header.align); + file_cbfs_fill_cache(priv, priv->header.rom_size, priv->header.align); if (priv->result != CBFS_SUCCESS) return -EINVAL; @@ -358,7 +376,7 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom, if (file_cbfs_load_header(priv, end_of_rom)) return NULL; - start = (void *)(end_of_rom + 1 - priv->header.rom_size); + start = priv->start; size = priv->header.rom_size; align = priv->header.align; From patchwork Wed May 13 14:23:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289358 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=i7HFo9Ge; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McS81kL8z9sRR for ; Thu, 14 May 2020 00:26:48 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0DAF681E89; Wed, 13 May 2020 16:25:22 +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="i7HFo9Ge"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 37FEF81E5F; Wed, 13 May 2020 16:24: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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 394D981DF9 for ; Wed, 13 May 2020 16:24:47 +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-io1-xd42.google.com with SMTP id x5so9126789ioh.6 for ; Wed, 13 May 2020 07:24:47 -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=sBs2C2u3iMUmw4/G7Eh8KPpUxLmLoMirdxhG6phMmdc=; b=i7HFo9GejPS+UtK46lSj3ksQc13U9oBZN3tObdnBLKtwf9gZiSiGMY+XEsE7LubfBi 9nid7uvPWeTXf/7SibH1RqsTm8Z1xaDrROk13VRoHJo3J+oD8+TQsh6uyiDky2f1N+UK ZBSnWjsuyDA8wQ0kYZzLpgYG4g6gKgl+gOuPs= 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=sBs2C2u3iMUmw4/G7Eh8KPpUxLmLoMirdxhG6phMmdc=; b=dr8zipeW1eUdRFij7DoIn7qlNGEitcXDYsW2rp/r8lX+n1hlZwVhe50Ru1a0K459xy Y/UZWuVY4LMgmbshVY7lHvMZ7422VqoJDIVu9H45zplgyxsBcxa0X8mIviX94bY9fvH3 20azeRXPTXyiFbVniNjvNQY72YC+FB1XzyedWYyprO94VdhkHq804AK8eD6PDwTreMC7 M4AE44IGrP0suIQ7CnXOV4Keio51m3lNVooh5lO1LwhLayWCkHCOHM0zORzxDpUXXpUT OHKLGb8tzDs1Rs74Sbo9c2wMYi4vDXxqECM91jAgnBeEz/WyR+3OPOfszV9iyUk/Lmm6 sa0g== X-Gm-Message-State: AGi0PubRzLEZzTC0YZ3T6n/34j63I++Gdul+EWeabaIboyvtY0HzSF3E hhasdiI5eIgc6Vt/wyaiEGIgqyvUzlc= X-Google-Smtp-Source: APiQypIAi/WnumXh/wwrZjHfS1DUJu67tGbu1h242Eqn3/F3Bh0vF86WJCyhfEfbD2BMRsjb1n0cFA== X-Received: by 2002:a5e:8503:: with SMTP id i3mr25129718ioj.114.1589379885502; Wed, 13 May 2020 07:24:45 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:45 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Heinrich Schuchardt , Joe Hershberger , Stefan Reinauer Subject: [PATCH 10/13] cbfs: Return the error code from file_cbfs_init() Date: Wed, 13 May 2020 08:23:56 -0600 Message-Id: <20200513142359.147589-11-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean We may as well return the error code and use it directly in the command code. CBFS still uses its own error enum which we may be able to remove, but leave it for now. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- cmd/cbfs.c | 3 +-- fs/cbfs/cbfs.c | 23 +++++++++++++++-------- include/cbfs.h | 6 +++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cmd/cbfs.c b/cmd/cbfs.c index 98e652a4e7..83bdee6252 100644 --- a/cmd/cbfs.c +++ b/cmd/cbfs.c @@ -28,8 +28,7 @@ static int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc, return 1; } } - file_cbfs_init(end_of_rom); - if (cbfs_get_result() != CBFS_SUCCESS) { + if (file_cbfs_init(end_of_rom)) { printf("%s.\n", file_cbfs_error()); return 1; } diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 58de258da3..0db7cb9147 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -253,19 +253,26 @@ static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base) return 0; } -static void cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) +static int cbfs_init(struct cbfs_priv *priv, ulong end_of_rom) { - if (file_cbfs_load_header(priv, end_of_rom)) - return; + int ret; - file_cbfs_fill_cache(priv, priv->header.rom_size, priv->header.align); - if (priv->result == CBFS_SUCCESS) - priv->initialised = true; + ret = file_cbfs_load_header(priv, end_of_rom); + if (ret) + return ret; + + ret = file_cbfs_fill_cache(priv, priv->header.rom_size, + priv->header.align); + if (ret) + return ret; + priv->initialised = true; + + return 0; } -void file_cbfs_init(ulong end_of_rom) +int file_cbfs_init(ulong end_of_rom) { - cbfs_init(&cbfs_s, end_of_rom); + return cbfs_init(&cbfs_s, end_of_rom); } int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) diff --git a/include/cbfs.h b/include/cbfs.h index 80ce539070..5cc27d682d 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -100,10 +100,10 @@ enum cbfs_result cbfs_get_result(void); /** * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM. * - * @end_of_rom: Points to the end of the ROM the CBFS should be read - * from. + * @end_of_rom: Points to the end of the ROM the CBFS should be read from + * @return 0 if OK, -ve on error */ -void file_cbfs_init(ulong end_of_rom); +int file_cbfs_init(ulong end_of_rom); /** * file_cbfs_get_header() - Get the header structure for the current CBFS. From patchwork Wed May 13 14:23:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289359 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=glvAlPQL; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McSM3cKlz9sRR for ; Thu, 14 May 2020 00:26:59 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9A6D081E7B; Wed, 13 May 2020 16:25:40 +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="glvAlPQL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8F11781E5F; Wed, 13 May 2020 16:24: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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) (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 86F5181E03 for ; Wed, 13 May 2020 16:24:48 +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-io1-xd43.google.com with SMTP id d7so18234551ioq.5 for ; Wed, 13 May 2020 07:24:48 -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=gGs/Bf2+UohuLayNe6aK37DQZvqzk8O0VgiQjoreqsQ=; b=glvAlPQLsOAcfsLS3w8OebMkuV7F3UWT/zNeWRnHLWoqYHXqPFjzqhu8IoLgZm234K 0Z+WuK1gygBj/mkR+eFUhBNvPb+vMjskNVg9qQ6TVuNmKJ35v4xmiVpBS+Y6OO5vQQsP L90c9/SgigL1DgTS7UNU7MZK4icRNwA+NyPgs= 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=gGs/Bf2+UohuLayNe6aK37DQZvqzk8O0VgiQjoreqsQ=; b=eWySgFrp3gsJu955AA1zzP4bDLfxSMCG9iLOVSJlHyh5Gqgrn6I9rdiTwXhXK7BZAK PAY6johXcCY+j3yW4l4NUn3GvFX7Xe8M9y57Ko/Ys3SQYp5CQycbGKBqtVEOVOrh8IJw w9U5K8tF3h8HN3qNqIMYRqMJtCH7NQZIn9tr7yqo1oL1DJ5wF7wyHhPnbQkxCvtklsge ohkIHN27+k56nm4ps/wDsdN9/WmVDRtxCBLN81QZ1DhxbSBqBq7l7zEVOKsrkOyMmYv6 tT8KSyfXhJRq1T5zb+xDoklKAjzIUwjK0HPBQ+E/tx5vrEdoxD71omVDS17QaTl2E4mC fV7w== X-Gm-Message-State: AGi0PuaymYI4Q7yifnWjPPDu7f+gNh3qlpnygiFbldEBX6wfwypVYL/R JozFudc+7xSpbsqJrvF2ujW6LXPWaz8= X-Google-Smtp-Source: APiQypKZ+y/FmV9bTTWvpIbJW5TIYC/t1N784uKOFeCr3zdI8dl5SeqPugXVK049VLLzj3dC62cDtA== X-Received: by 2002:a05:6602:29cd:: with SMTP id z13mr25906819ioq.210.1589379886801; Wed, 13 May 2020 07:24:46 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:46 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Heinrich Schuchardt , Stefan Reinauer Subject: [PATCH 11/13] cbfs: Change file_cbfs_find_uncached() to return an error Date: Wed, 13 May 2020 08:23:57 -0600 Message-Id: <20200513142359.147589-12-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean This function currently returns a node pointer so there is no way to know the error code. Also it uses data in BSS which seems unnecessary since the caller might prefer to use a local variable. Update the function and split its body out into a separate function so we can use it later. Signed-off-by: Simon Glass --- fs/cbfs/cbfs.c | 48 +++++++++++++++++++++++++++--------------------- include/cbfs.h | 16 +++++++--------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 0db7cb9147..76613fa871 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -371,40 +371,46 @@ const struct cbfs_cachenode *file_cbfs_find(const char *name) return cbfs_find_file(&cbfs_s, name); } -const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom, - const char *name) +static int find_uncached(struct cbfs_priv *priv, const char *name, u8 *start, + struct cbfs_cachenode *node) { - struct cbfs_priv *priv = &cbfs_s; - void *start; - u32 size; - u32 align; - static struct cbfs_cachenode node; - - if (file_cbfs_load_header(priv, end_of_rom)) - return NULL; - - start = priv->start; - size = priv->header.rom_size; - align = priv->header.align; + int size = priv->header.rom_size; + int align = priv->header.align; while (size >= align) { - int ret; int used; + int ret; - ret = file_cbfs_next_file(priv, start, size, align, &node, + ret = file_cbfs_next_file(priv, start, size, align, node, &used); if (ret == -ENOENT) break; else if (ret) - return NULL; - if (!strcmp(name, node.name)) - return &node; + return ret; + if (!strcmp(name, node->name)) + return 0; size -= used; start += used; } - cbfs_s.result = CBFS_FILE_NOT_FOUND; - return NULL; + priv->result = CBFS_FILE_NOT_FOUND; + + return -ENOENT; +} + +int file_cbfs_find_uncached(ulong end_of_rom, const char *name, + struct cbfs_cachenode *node) +{ + struct cbfs_priv priv; + u8 *start; + int ret; + + ret = file_cbfs_load_header(&priv, end_of_rom); + if (ret) + return ret; + start = (u8 *)(end_of_rom + 1 - priv.header.rom_size); + + return find_uncached(&priv, name, start, node); } const char *file_cbfs_name(const struct cbfs_cachenode *file) diff --git a/include/cbfs.h b/include/cbfs.h index 5cc27d682d..4dd3c0795d 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -163,17 +163,15 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp); /***************************************************************************/ /** - * file_cbfs_find_uncached() - Find a file with a particular name in CBFS - * without using the heap. + * file_cbfs_find_uncached() - Find a file in CBFS without using the heap * - * @end_of_rom: Points to the end of the ROM the CBFS should be read - * from. - * @name: The name to search for. - * - * @return A handle to the file, or NULL on error. + * @end_of_rom: Points to the end of the ROM the CBFS should be read from + * @name: The name to search for + * @node: Returns the node if found + * @return 0 on success, -ENOENT if not found, -EFAULT on bad header */ -const struct cbfs_cachenode *file_cbfs_find_uncached(ulong end_of_rom, - const char *name); +int file_cbfs_find_uncached(ulong end_of_rom, const char *name, + struct cbfs_cachenode *node); /** * file_cbfs_name() - Get the name of a file in CBFS. From patchwork Wed May 13 14:23:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289361 X-Patchwork-Delegate: bmeng.cn@gmail.com 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; dmarc=pass (p=none dis=none) header.from=chromium.org 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=aEqI988M; 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 49McSp15nQz9sRR for ; Thu, 14 May 2020 00:27:22 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A95FD81E8E; Wed, 13 May 2020 16:25:44 +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="aEqI988M"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F62881E6F; Wed, 13 May 2020 16:24:53 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (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 5012681DB7 for ; Wed, 13 May 2020 16:24:49 +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-il1-x141.google.com with SMTP id j2so5342446ilr.5 for ; Wed, 13 May 2020 07:24:49 -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=nIXNrI1cSWnnb2TI8swhGiAdI69LVqfSZnZj2STdzcM=; b=aEqI988MSkVl3HFA6KOR8es0xM89MokQi6rhkY5iCvd4WXf9AIP9lEspkHgk1/hlKp fFP/pH5oCyrg6dzK0hk4dvdHbpITtKTTP2ZAnb1/OteqLuV9g8NpI92emxZpOD9XQudF cKOQZEcDkp+7im3LNEqllkHTkf6UzLu0wwPx0= 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=nIXNrI1cSWnnb2TI8swhGiAdI69LVqfSZnZj2STdzcM=; b=ubabxrEGE4nph7rfkbDg4Ze94hpV/8VIS7tjZrJiU6S/HZxNKZPkVPoD1RrxmffqBR OyqzRHd+oS/zSh6ztj9yAL1H7BCi+rEcz5t0jYDOLdy8nAG0khiJ1LcP86BgF+ues691 D5PNYYiddbpKzsmH8jCcqi5mn5AtR2e1PFFcxGdcadATPOqUkBygIbrCU4uXO0b5EJMU yQUX/N38fjzJLzRVkmngFe4kMnKQfpjOtkBG6l78hKvKqehqGRRqhW0o1mJFWcd9QLyL rbPeJ5Q1eUl53pNAJ3WNaZWgJAzkUHIPz99yxJzKk/DL/Oz5tlI1zyE932VQycXq/9V4 NDng== X-Gm-Message-State: AGi0PuY8wKrLGDZiAC4JHVXIBNImxpLmciYcuWOGaSS9hmMilxzK++ki CLut4EwI7Rh+L9wJVLOJC+8M6kZzIlk= X-Google-Smtp-Source: APiQypIRdJgaNgUVz44qXZ8PfAOVKE2xWLKyBBY2252ElIQg4Dn8mgjrVwcV5QagoZJPnTo67nJfHg== X-Received: by 2002:a92:395c:: with SMTP id g89mr9602180ila.247.1589379887626; Wed, 13 May 2020 07:24:47 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:47 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Heinrich Schuchardt , Stefan Reinauer Subject: [PATCH 12/13] cbfs: Allow reading a file from a CBFS given its base addr Date: Wed, 13 May 2020 08:23:58 -0600 Message-Id: <20200513142359.147589-13-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean Currently we support reading a file from CBFS given the address of the end of the ROM. Sometimes we only know the start of the CBFS. Add a function to find a file given that. Signed-off-by: Simon Glass --- fs/cbfs/cbfs.c | 13 +++++++++++++ include/cbfs.h | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 76613fa871..1603409a8f 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -413,6 +413,19 @@ int file_cbfs_find_uncached(ulong end_of_rom, const char *name, return find_uncached(&priv, name, start, node); } +int file_cbfs_find_uncached_base(ulong base, const char *name, + struct cbfs_cachenode *node) +{ + struct cbfs_priv priv; + int ret; + + ret = cbfs_load_header_ptr(&priv, base); + if (ret) + return ret; + + return find_uncached(&priv, name, (u8 *)base, node); +} + const char *file_cbfs_name(const struct cbfs_cachenode *file) { cbfs_s.result = CBFS_SUCCESS; diff --git a/include/cbfs.h b/include/cbfs.h index 4dd3c0795d..b1a8d2cad2 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -173,6 +173,17 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp); int file_cbfs_find_uncached(ulong end_of_rom, const char *name, struct cbfs_cachenode *node); +/** + * file_cbfs_find_uncached() - Find a file in CBFS without using the heap + * + * @base: Points to the base of the CBFS + * @name: The name to search for + * @node: Returns the node if found + * @return 0 on success, -ENOENT if not found, -EFAULT on bad header + */ +int file_cbfs_find_uncached_base(ulong base, const char *name, + struct cbfs_cachenode *node); + /** * file_cbfs_name() - Get the name of a file in CBFS. * From patchwork Wed May 13 14:23:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1289360 X-Patchwork-Delegate: bmeng.cn@gmail.com 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org 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=cc2N19vB; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 49McSb2Nsfz9sRR for ; Thu, 14 May 2020 00:27:11 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4483F81E03; Wed, 13 May 2020 16:25:43 +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="cc2N19vB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4EED481E5F; Wed, 13 May 2020 16:24:53 +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=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (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 9946981E32 for ; Wed, 13 May 2020 16:24:49 +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-il1-x141.google.com with SMTP id q10so16117636ile.0 for ; Wed, 13 May 2020 07:24:49 -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=IT19xTOLWdI63ngq1G+3CipQKRkkxTW3a9dygArz4u8=; b=cc2N19vBhz0vsbsb9uYmliK20R9uB3q7pSEXBJZWi2LVOy6sHIgt6OanTvnogNzrEk wC2sR3Y84NUMBvsH7vVubrKO/hKgWWO8phmyIeb3WxCt0ItzJXu2brMeR6+mfgDH9hgs POuj4OFFXgPqtVLvm3WDFleZEhdFVXy8R61Ck= 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=IT19xTOLWdI63ngq1G+3CipQKRkkxTW3a9dygArz4u8=; b=XialamI/ZaqFjm8wtC5yFGjvHIFvL1vbIdjTXiNxgLEb0bLwZdhvR0aoN/oByfKu+m qjVfbz7/ooKreLOGUGd3dvOgze88pSPtCKoaLR3p7sK+4LIjeEGRoRMPq5qZAlu5rBGs 6h2T+ixnpPUscXL0JVJaBgtScsQZ7V1uHvG997Lj2IBdR1RzL8BkMw3K1CVGvDkgYuLH Vvj/2gMbzrN1eAQLn+qR6+ObydvtPFEQiI0LcG21QhIImZRrQzu3acT748QGvjGLBbGN qN9zdTG7Mf7UrWJ+wSkyAJpUFwWfcVoaZPMp7+joUXbWaHVKN2nTqouVYQJBhH2ChvcN U1FA== X-Gm-Message-State: AGi0PuZxtto91a5GNptuV/aZqL3TrjeLj2pI/bSVe9GhXY0WB/D857ef DqM3T7er58u6NKsEBzxjmeROCZqjGPY= X-Google-Smtp-Source: APiQypIA2h105Pr85CgOMGqrKiqha+7ppNlNLTVg9v9hLAz0Dd3UuaPskfzNF2PfhD0E5LR1zXplhw== X-Received: by 2002:a92:48ca:: with SMTP id j71mr10776192ilg.25.1589379888423; Wed, 13 May 2020 07:24:48 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id v70sm3348107ilk.84.2020.05.13.07.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 07:24:48 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Bin Meng , Simon Glass , Heinrich Schuchardt , Stefan Reinauer Subject: [PATCH 13/13] cbfs: Don't require the CBFS size with cbfs_init_mem() Date: Wed, 13 May 2020 08:23:59 -0600 Message-Id: <20200513142359.147589-14-sjg@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog In-Reply-To: <20200513142359.147589-1-sjg@chromium.org> References: <20200513142359.147589-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean The size is not actually used since it is present in the header. Drop this parameter. Also tidy up error handling while we are here. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- arch/x86/lib/fsp2/fsp_init.c | 3 +-- fs/cbfs/cbfs.c | 9 +++++---- include/cbfs.h | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/lib/fsp2/fsp_init.c b/arch/x86/lib/fsp2/fsp_init.c index c7dc2ea257..668a4aa723 100644 --- a/arch/x86/lib/fsp2/fsp_init.c +++ b/arch/x86/lib/fsp2/fsp_init.c @@ -79,11 +79,10 @@ static int get_cbfs_fsp(enum fsp_type_t type, ulong map_base, * 'COREBOOT' (CBFS, size 1814528, offset 2117632). */ ulong cbfs_base = 0x205000; - ulong cbfs_size = 0x1bb000; struct cbfs_priv *cbfs; int ret; - ret = cbfs_init_mem(map_base + cbfs_base, cbfs_size, &cbfs); + ret = cbfs_init_mem(map_base + cbfs_base, &cbfs); if (ret) return ret; if (!ret) { diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 1603409a8f..30cd58f5ad 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -275,7 +275,7 @@ int file_cbfs_init(ulong end_of_rom) return cbfs_init(&cbfs_s, end_of_rom); } -int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) +int cbfs_init_mem(ulong base, struct cbfs_priv **privp) { struct cbfs_priv priv_s, *priv = &priv_s; int ret; @@ -288,9 +288,10 @@ int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) if (ret) return ret; - file_cbfs_fill_cache(priv, priv->header.rom_size, priv->header.align); - if (priv->result != CBFS_SUCCESS) - return -EINVAL; + ret = file_cbfs_fill_cache(priv, priv->header.rom_size, + priv->header.align); + if (ret) + return log_msg_ret("fill", ret); priv->initialised = true; priv = malloc(sizeof(priv_s)); diff --git a/include/cbfs.h b/include/cbfs.h index b1a8d2cad2..70f3b7a17b 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -151,11 +151,10 @@ const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *cbfs, * cbfs_init_mem() - Set up a new CBFS * * @base: Base address of CBFS - * @size: Size of CBFS in bytes * @cbfsp: Returns a pointer to CBFS on success * @return 0 if OK, -ve on error */ -int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp); +int cbfs_init_mem(ulong base, struct cbfs_priv **privp); /***************************************************************************/