From patchwork Wed Aug 14 03:09:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1146733 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=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="jk1jgguy"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 467ZQD0Yzwz9sDB for ; Wed, 14 Aug 2019 13:12:36 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C17A6C21E42; Wed, 14 Aug 2019 03:10:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id AE169C21D9A; Wed, 14 Aug 2019 03:10:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2836EC21C6A; Wed, 14 Aug 2019 03:09:30 +0000 (UTC) Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by lists.denx.de (Postfix) with ESMTPS id 1560CC21D72 for ; Wed, 14 Aug 2019 03:09:28 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id g17so28085672otl.2 for ; Tue, 13 Aug 2019 20:09:28 -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=LinrW7bByP8kuUms5OOZgYeaVsvlwS07cOjYBrybBbk=; b=jk1jgguyyZkhpofzsoCCyqM+7fAg2lxWlI6Q8/o6ifKHsxW8po4+g5gMZW7BHobAX3 ko+2UCz4jamektg8p4bnnhKN+p1ls0p5w57NALrufbWwdIlBttcKddlPzY02CJDiCqWI ar8wk7Y4k5slXwM+o0c9+BaLs6TpHREDEoZvo= 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=LinrW7bByP8kuUms5OOZgYeaVsvlwS07cOjYBrybBbk=; b=TfHq0SUekxcJ8JFajKlASkApwG4NjNRNU33JKDTF7/0F4y/qAmUDm0otEeBImsyh/0 JTDIkLUfhqmDNX78156d9JTu3H/8jrwyEsPo8m6S44qJssleg8IXUD0N1FmH3QhCZTF0 6hAA3NQWBW2DCkkcc9Qi+FnERYSQTnbAQaLa8pMe7rTCdLyVvxnFgXhQxEPIl8o2YjfM ut8rUm2gheJQ1xY38qgkSacuQqzvrLQs8rFEI20PD2fYViuFk6mwCdmzT8FW6C+jjjGQ /GadgpztUjLjBNWFf0WAuNbYl69bvRNvqVwO7Weop93fGSDraQRvhI42eCWH6qpdvDC+ iKzg== X-Gm-Message-State: APjAAAULWIm1ZiKjpG0mw6dg6utmw6yvSR8j+KNGpJtVABcMjMwp+ONs BDIivzD2MaagU8xKSTPfRsysYpeMKEs= X-Google-Smtp-Source: APXvYqwBI6bBwosJ5UwT6qhpuNsCe2gkJUBBipIXzG0+L3md6u8VkV4WD03cyvriI+49qFJqSwQidA== X-Received: by 2002:a05:6602:2518:: with SMTP id i24mr5670111ioe.277.1565752166869; Tue, 13 Aug 2019 20:09:26 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id a6sm4141021ios.20.2019.08.13.20.09.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 20:09:26 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 13 Aug 2019 21:09:12 -0600 Message-Id: <20190814030914.256689-5-sjg@chromium.org> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog In-Reply-To: <20190814030914.256689-1-sjg@chromium.org> References: <20190814030914.256689-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Joe Hershberger , Stefan Reinauer Subject: [U-Boot] [PATCH 4/6] cbfs: Move result variable into the struct X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Move the result variable into the struct also, so that it can be used when BSS is not available. Add a function to read it. Note that all functions sill use the BSS version of the data. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- cmd/cbfs.c | 4 ++-- fs/cbfs/cbfs.c | 45 +++++++++++++++++++++++++-------------------- include/cbfs.h | 7 +++++++ 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/cmd/cbfs.c b/cmd/cbfs.c index 3d1fc95972..98e652a4e7 100644 --- a/cmd/cbfs.c +++ b/cmd/cbfs.c @@ -29,7 +29,7 @@ static int do_cbfs_init(cmd_tbl_t *cmdtp, int flag, int argc, } } file_cbfs_init(end_of_rom); - if (file_cbfs_result != CBFS_SUCCESS) { + if (cbfs_get_result() != CBFS_SUCCESS) { printf("%s.\n", file_cbfs_error()); return 1; } @@ -67,7 +67,7 @@ static int do_cbfs_fsload(cmd_tbl_t *cmdtp, int flag, int argc, file = file_cbfs_find(argv[2]); if (!file) { - if (file_cbfs_result == CBFS_FILE_NOT_FOUND) + if (cbfs_get_result() == CBFS_FILE_NOT_FOUND) printf("%s: %s\n", file_cbfs_error(), argv[2]); else printf("%s.\n", file_cbfs_error()); diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index f4298d7320..dafdfb1a07 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -8,7 +8,6 @@ #include #include -enum cbfs_result file_cbfs_result; static const u32 good_magic = 0x4f524243; static const u8 good_file_magic[] = "LARCHIVE"; @@ -16,13 +15,14 @@ struct cbfs_priv { int initialized; struct cbfs_header header; struct cbfs_cachenode *file_cache; + enum cbfs_result result; }; static struct cbfs_priv cbfs_s; const char *file_cbfs_error(void) { - switch (file_cbfs_result) { + switch (cbfs_s.result) { case CBFS_SUCCESS: return "Success"; case CBFS_NOT_INITIALIZED: @@ -38,6 +38,11 @@ const char *file_cbfs_error(void) } } +enum cbfs_result cbfs_get_result(void) +{ + return cbfs_s.result; +} + /* Do endian conversion on the CBFS header structure. */ static void swap_header(struct cbfs_header *dest, struct cbfs_header *src) { @@ -99,7 +104,7 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, swap_file_header(&header, fileHeader); if (header.offset < sizeof(struct cbfs_fileheader)) { - file_cbfs_result = CBFS_BAD_FILE; + priv->result = CBFS_BAD_FILE; return -1; } newNode->next = NULL; @@ -161,7 +166,7 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, size -= used; start += used; } - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; } /* Get the CBFS header out of the ROM and do endian conversion. */ @@ -176,7 +181,7 @@ static int file_cbfs_load_header(uintptr_t end_of_rom, if (header->magic != good_magic || header->offset > header->rom_size - header->boot_block_size) { - file_cbfs_result = CBFS_BAD_HEADER; + cbfs_s.result = CBFS_BAD_HEADER; return 1; } return 0; @@ -195,7 +200,7 @@ void cbfs_init(struct cbfs_priv *priv, uintptr_t end_of_rom) file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size, priv->header.align); - if (file_cbfs_result == CBFS_SUCCESS) + if (priv->result == CBFS_SUCCESS) priv->initialized = 1; } @@ -209,10 +214,10 @@ const struct cbfs_header *file_cbfs_get_header(void) struct cbfs_priv *priv = &cbfs_s; if (priv->initialized) { - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; return &priv->header; } else { - file_cbfs_result = CBFS_NOT_INITIALIZED; + priv->result = CBFS_NOT_INITIALIZED; return NULL; } } @@ -222,10 +227,10 @@ const struct cbfs_cachenode *file_cbfs_get_first(void) struct cbfs_priv *priv = &cbfs_s; if (!priv->initialized) { - file_cbfs_result = CBFS_NOT_INITIALIZED; + priv->result = CBFS_NOT_INITIALIZED; return NULL; } else { - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; return priv->file_cache; } } @@ -235,14 +240,14 @@ void file_cbfs_get_next(const struct cbfs_cachenode **file) struct cbfs_priv *priv = &cbfs_s; if (!priv->initialized) { - file_cbfs_result = CBFS_NOT_INITIALIZED; + priv->result = CBFS_NOT_INITIALIZED; *file = NULL; return; } if (*file) *file = (*file)->next; - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; } const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv, @@ -251,7 +256,7 @@ const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv, struct cbfs_cachenode *cache_node = priv->file_cache; if (!priv->initialized) { - file_cbfs_result = CBFS_NOT_INITIALIZED; + priv->result = CBFS_NOT_INITIALIZED; return NULL; } @@ -261,9 +266,9 @@ const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv, cache_node = cache_node->next; } if (!cache_node) - file_cbfs_result = CBFS_FILE_NOT_FOUND; + priv->result = CBFS_FILE_NOT_FOUND; else - file_cbfs_result = CBFS_SUCCESS; + priv->result = CBFS_SUCCESS; return cache_node; } @@ -307,27 +312,27 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, size -= used; start += used; } - file_cbfs_result = CBFS_FILE_NOT_FOUND; + cbfs_s.result = CBFS_FILE_NOT_FOUND; return NULL; } const char *file_cbfs_name(const struct cbfs_cachenode *file) { - file_cbfs_result = CBFS_SUCCESS; + cbfs_s.result = CBFS_SUCCESS; return file->name; } u32 file_cbfs_size(const struct cbfs_cachenode *file) { - file_cbfs_result = CBFS_SUCCESS; + cbfs_s.result = CBFS_SUCCESS; return file->data_length; } u32 file_cbfs_type(const struct cbfs_cachenode *file) { - file_cbfs_result = CBFS_SUCCESS; + cbfs_s.result = CBFS_SUCCESS; return file->type; } @@ -342,7 +347,7 @@ long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer, size = maxsize; memcpy(buffer, file->data, size); - file_cbfs_result = CBFS_SUCCESS; + cbfs_s.result = CBFS_SUCCESS; return size; } diff --git a/include/cbfs.h b/include/cbfs.h index b8d1dabbf6..742e34e24f 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -90,6 +90,13 @@ extern enum cbfs_result file_cbfs_result; */ const char *file_cbfs_error(void); +/** + * cbfs_get_result() - Get the result of the last CBFS operation + * + *@return last result + */ +enum cbfs_result cbfs_get_result(void); + /** * file_cbfs_init() - Initialize the CBFS driver and load metadata into RAM. *