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;