From patchwork Wed Aug 14 03:09:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1146730 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="W2NChYt1"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 467ZNq5dvSz9sDB for ; Wed, 14 Aug 2019 13:11:23 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 6B9F2C21C50; Wed, 14 Aug 2019 03:09:37 +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=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 1C7DDC21C8B; Wed, 14 Aug 2019 03:09:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B3AB2C21BE5; Wed, 14 Aug 2019 03:09:24 +0000 (UTC) Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by lists.denx.de (Postfix) with ESMTPS id 2A03BC21C29 for ; Wed, 14 Aug 2019 03:09:24 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id t24so1729499oij.13 for ; Tue, 13 Aug 2019 20:09:24 -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=IJtZR+kQJV+VngXxMxVuunigPbThey/xLJ2GiLe6Njk=; b=W2NChYt1Wr+yT79Yc/96Om6hPAHqwHtkCk9wln6jaxUNT1MgZ0YaM6TTDImFko5tkj ZYshMTXZWj1l77VWDmOsQoJx8aNgPwBzElHOsm1DD3mLgEg0kkZAbQ6nuLg5d2RlLYiE KuCzMCg8HNRU2BbJTN8BgReCNPvIvREE3/GB4= 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=IJtZR+kQJV+VngXxMxVuunigPbThey/xLJ2GiLe6Njk=; b=niLOU6rtZL5K8y6xik8Zttwc2nWZcoVKS1pxPyaHgxIobVc8AuVXghc/P4xVvB2wWC B/037Vu4a86jZsazsp1cq3wIK/FEDgDnscuCelNQVlAFZWf55GMW6JYHnVwrOeDKISF8 OSrSMw7CVissJJuMXG90etQ6yAHaCU2ygviaL59nhdoocPkdrAKlAA1oKVPS8r5HDcR1 MGeY8RH9rk/edmtw+TsTdMqdm7/fq+zMjamo3ute+FE123+7UFBXDpsVFkFwYNsuaE8U 4f1KUiAxJJFhBrxfPXbAn503NCrOkac6ud7pXohdpIMob3v777TTs4scvLYD7Uj+yQiG EwhQ== X-Gm-Message-State: APjAAAWaH0iYN2XxruW2ZsfIC9GCXaiMIEZ1fE9ej9FRzySz0uXZfaeB 5knAohDYjNwfwI6UvczWLXoOwnyuSCk= X-Google-Smtp-Source: APXvYqwW0Rrlyy5oHaauNkABbL9rsWX1In1mDOTD++aZawv/5tE8+ceLcl3rRKADhnhXPHgoc7JQ+Q== X-Received: by 2002:a02:c487:: with SMTP id t7mr1035677jam.99.1565752162646; Tue, 13 Aug 2019 20:09:22 -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.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 20:09:22 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 13 Aug 2019 21:09:09 -0600 Message-Id: <20190814030914.256689-2-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: Stefan Reinauer , Tien Fong Chee Subject: [U-Boot] [PATCH 1/6] cbfs: Allow CBFS to be used in SPL 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" Add a new Kconfig option to enable CBFS in SPL. This can be useful when the memory-init code is in CBFS. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/Makefile | 1 + fs/cbfs/Kconfig | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/fs/Makefile b/fs/Makefile index 2ed4aeac0e..42e669c40c 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -8,6 +8,7 @@ ifdef CONFIG_SPL_BUILD obj-$(CONFIG_FS_LOADER) += fs.o obj-$(CONFIG_SPL_FS_FAT) += fat/ obj-$(CONFIG_SPL_FS_EXT4) += ext4/ +obj-$(CONFIG_SPL_FS_CBFS) += cbfs/ else obj-y += fs.o diff --git a/fs/cbfs/Kconfig b/fs/cbfs/Kconfig index 16089547a5..49eb6aca33 100644 --- a/fs/cbfs/Kconfig +++ b/fs/cbfs/Kconfig @@ -6,3 +6,15 @@ config FS_CBFS on systems that use coreboot as the first boot-loader and then load U-Boot to actually boot the Operating System. You can also enable CMD_CBFS to get command-line access. + +config SPL_FS_CBFS + bool "Enable CBFS (Coreboot Filesystem) in SPL" + help + Define this to enable support for reading from a Coreboot + filesystem. This is a ROM-based filesystem used for accessing files + on systems that use coreboot as the first boot-loader and then load + U-Boot to actually boot the Operating System. + + Note that most functions in the CBFS API do not work with SPL. Only + those which accept a cbfs_priv * can be used, since BSS it not + available. From patchwork Wed Aug 14 03:09:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1146731 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="RXgVeYUS"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 467ZP16mrVz9sDB for ; Wed, 14 Aug 2019 13:11:33 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9E3EAC21DDC; Wed, 14 Aug 2019 03:09:46 +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 6ED8EC21D9A; Wed, 14 Aug 2019 03:09:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D1879C21C29; Wed, 14 Aug 2019 03:09:25 +0000 (UTC) Received: from mail-ot1-f68.google.com (mail-ot1-f68.google.com [209.85.210.68]) by lists.denx.de (Postfix) with ESMTPS id 3FE9EC21BE5 for ; Wed, 14 Aug 2019 03:09:25 +0000 (UTC) Received: by mail-ot1-f68.google.com with SMTP id c34so39057856otb.7 for ; Tue, 13 Aug 2019 20:09:25 -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=UMBp37/Z2Ulnon+wq/QQWtZPvUQ0mQJRHjD6mt3IwFc=; b=RXgVeYUSpFgMOGq5M3ZsD601xp6Qd/d/CiJfzXn8TxicY7srZloBFGjZ6OMpjUkA1W DPAanhcarRRYzX1jZaQ42+z2uoCwAVZDvq1tHfl4A2qxvCijPuSYcHFf8QN3q56xCshX GkA2b8kRHu7guPkMeKJhztYL7WyCyAQQropOI= 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=UMBp37/Z2Ulnon+wq/QQWtZPvUQ0mQJRHjD6mt3IwFc=; b=LBob1QhbhFlqtnVB89hiFFtgLxguAC7kLjeoqaLOlnQWFzaWTmnG+dko/dDzKf02DX QzTWqDtib9iRzZ9a1ReRN5zKv6HHh4NZZ8AC4sG8RAVuk2Z02uyBZ30w67SW//HIF2c+ R3MLd1qrEkaimOrGbd2qMfIFfp5pna4b5sNXbr6NKzqn8ncGo2u3gAb0S7wKgp7bkM09 qqTAd7rfUl3X2u0pTrIeeKvDRyMzXiznNwVdw1MjSYTwSMxvQQGy68hbZ224Fh9JuGdt hjoYtNUoZ0CB67v4a+IDj79ZEzg7jKTrmz4VLsCySOCzaS8cfbQNX9LZCTto4ElMMPKs lugA== X-Gm-Message-State: APjAAAXFt/Ya1GeXycIDhRfupW+Zrb+AhxsWRqVcZzUG1e1/Pveso/EK d8l4Ywr7pbpgtEMR6hrFMnk37mP4474= X-Google-Smtp-Source: APXvYqzdWt2H3GiwDIJK7owiedgsz1qRvWIB+VuvqVystkBREt7eypb6IWIBK959KkreuJGRfYmDrw== X-Received: by 2002:a5e:d611:: with SMTP id w17mr14383943iom.34.1565752164070; Tue, 13 Aug 2019 20:09:24 -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.23 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 20:09:23 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 13 Aug 2019 21:09:10 -0600 Message-Id: <20190814030914.256689-3-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: Stefan Reinauer Subject: [U-Boot] [PATCH 2/6] cbfs: Move declarations above functions 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" At present this file has a function at the top, above declarations. This is normally avoided, so fix it. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index af4d3c5e56..2a9edcc9a0 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -9,6 +9,11 @@ #include enum cbfs_result file_cbfs_result; +static const u32 good_magic = 0x4f524243; +static const u8 good_file_magic[] = "LARCHIVE"; +static int initialized; +static struct cbfs_header cbfs_header; +static struct cbfs_cachenode *file_cache; const char *file_cbfs_error(void) { @@ -28,15 +33,6 @@ const char *file_cbfs_error(void) } } - -static const u32 good_magic = 0x4f524243; -static const u8 good_file_magic[] = "LARCHIVE"; - - -static int initialized; -static struct cbfs_header cbfs_header; -static struct cbfs_cachenode *file_cache; - /* Do endian conversion on the CBFS header structure. */ static void swap_header(struct cbfs_header *dest, struct cbfs_header *src) { From patchwork Wed Aug 14 03:09:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1146732 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="O6caCtwI"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 467ZPB4lJvz9sDB for ; Wed, 14 Aug 2019 13:11:42 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 1ADC3C21E0F; Wed, 14 Aug 2019 03:10:20 +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=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 23097C21DA2; Wed, 14 Aug 2019 03:09:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3AC84C21D74; Wed, 14 Aug 2019 03:09:29 +0000 (UTC) Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by lists.denx.de (Postfix) with ESMTPS id A10CCC21C29 for ; Wed, 14 Aug 2019 03:09:26 +0000 (UTC) Received: by mail-ot1-f67.google.com with SMTP id k18so46938525otr.3 for ; Tue, 13 Aug 2019 20:09:26 -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=5RDloMCVxwLgH641nxjc6n3PVrcjgy01Hfvj3MnfRk0=; b=O6caCtwIkupZmRCTG1APzRX1R0A3p9b7q9zFrsDOQ1WhX0IFnrvasZdA7HdHnItJtX Jr3G2mGFKANAzuuDpdNd3wzz6fubz6f9DcWR5KVXRY9b0UdLbRecKgMpOqfzDgxt3Fsb hhbjPrpaRSnotG11W5QPzqQHmWfOALbtgAchY= 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=5RDloMCVxwLgH641nxjc6n3PVrcjgy01Hfvj3MnfRk0=; b=JovHHvQBw2xHHioosTK78HRXtPDqnMdU3m7KZFWV6JY6AOf48n/9hRgh8j6Iozsc5J AaBYBa3E+pl3x+BT2xMaer/28DN2/uC0ohdzvif6z0zGp5BDlpOUg1Fb/vmpQROumC9t 1vFFNdzB4AFRQhhgrXG8sa1naKQDGij/SIyNqpFFt5gMnKIedgZE2MGHLeB1G/09ZAV9 R5XnIzwO9SFIDKaK43CiJmR1nK6pvyB92gGbd0kQ7hjcuFexBOzIXB0VApFSCrgMyhlM SwMZvlOPT3SJEj8Ddqh52V61PIVm032LsBWVAjgmfi3tzgFSfqb0X/wxipZ70jNLyoTt Cqyg== X-Gm-Message-State: APjAAAUt8SHYxcduKG6UR/xnOVaN8PlHh3lwrtkbmXno83pekm+bCg3k E0aZSq9IaoOnMcbu/1GM4iy2irCkbnU= X-Google-Smtp-Source: APXvYqwS63npmlodsc51nDVMjACkwpf106aApZu5A556ZtXjXLmQ1x58hHUJof7H5Sng8GfDccmgzg== X-Received: by 2002:a5d:8c84:: with SMTP id g4mr3820735ion.211.1565752165453; Tue, 13 Aug 2019 20:09:25 -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.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 20:09:25 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 13 Aug 2019 21:09:11 -0600 Message-Id: <20190814030914.256689-4-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: Stefan Reinauer Subject: [U-Boot] [PATCH 3/6] cbfs: Move static variables into a 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" At present there are a number of static variables in BSS. This cannot work with SPL, at least until BSS is available in board_init_r(). Move the variables into a struct, so it is possible to malloc() it and use it before BSS is available. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 96 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index 2a9edcc9a0..f4298d7320 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -11,9 +11,14 @@ enum cbfs_result file_cbfs_result; static const u32 good_magic = 0x4f524243; static const u8 good_file_magic[] = "LARCHIVE"; -static int initialized; -static struct cbfs_header cbfs_header; -static struct cbfs_cachenode *file_cache; + +struct cbfs_priv { + int initialized; + struct cbfs_header header; + struct cbfs_cachenode *file_cache; +}; + +static struct cbfs_priv cbfs_s; const char *file_cbfs_error(void) { @@ -69,8 +74,9 @@ static void swap_file_header(struct cbfs_fileheader *dest, * * @return 1 if a file is found, 0 if one isn't. */ -static int file_cbfs_next_file(u8 *start, u32 size, u32 align, - struct cbfs_cachenode *newNode, u32 *used) +static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, + u32 align, struct cbfs_cachenode *newNode, + u32 *used) { struct cbfs_fileheader header; @@ -117,20 +123,21 @@ static int file_cbfs_next_file(u8 *start, u32 size, u32 align, } /* Look through a CBFS instance and copy file metadata into regular memory. */ -static void file_cbfs_fill_cache(u8 *start, u32 size, u32 align) +static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, + u32 align) { struct cbfs_cachenode *cache_node; struct cbfs_cachenode *newNode; - struct cbfs_cachenode **cache_tail = &file_cache; + struct cbfs_cachenode **cache_tail = &priv->file_cache; /* Clear out old information. */ - cache_node = file_cache; + cache_node = priv->file_cache; while (cache_node) { struct cbfs_cachenode *oldNode = cache_node; cache_node = cache_node->next; free(oldNode); } - file_cache = NULL; + priv->file_cache = NULL; while (size >= align) { int result; @@ -138,8 +145,8 @@ static void file_cbfs_fill_cache(u8 *start, u32 size, u32 align) newNode = (struct cbfs_cachenode *) malloc(sizeof(struct cbfs_cachenode)); - result = file_cbfs_next_file(start, size, align, - newNode, &used); + result = file_cbfs_next_file(priv, start, size, align, newNode, + &used); if (result < 0) { free(newNode); @@ -175,27 +182,35 @@ static int file_cbfs_load_header(uintptr_t end_of_rom, return 0; } -void file_cbfs_init(uintptr_t end_of_rom) +void cbfs_init(struct cbfs_priv *priv, uintptr_t end_of_rom) { u8 *start_of_rom; - initialized = 0; - if (file_cbfs_load_header(end_of_rom, &cbfs_header)) + priv->initialized = 0; + + if (file_cbfs_load_header(end_of_rom, &priv->header)) return; - start_of_rom = (u8 *)(end_of_rom + 1 - cbfs_header.rom_size); + start_of_rom = (u8 *)(end_of_rom + 1 - priv->header.rom_size); - file_cbfs_fill_cache(start_of_rom, cbfs_header.rom_size, - cbfs_header.align); + file_cbfs_fill_cache(priv, start_of_rom, priv->header.rom_size, + priv->header.align); if (file_cbfs_result == CBFS_SUCCESS) - initialized = 1; + priv->initialized = 1; +} + +void file_cbfs_init(uintptr_t end_of_rom) +{ + cbfs_init(&cbfs_s, end_of_rom); } const struct cbfs_header *file_cbfs_get_header(void) { - if (initialized) { + struct cbfs_priv *priv = &cbfs_s; + + if (priv->initialized) { file_cbfs_result = CBFS_SUCCESS; - return &cbfs_header; + return &priv->header; } else { file_cbfs_result = CBFS_NOT_INITIALIZED; return NULL; @@ -204,20 +219,24 @@ const struct cbfs_header *file_cbfs_get_header(void) const struct cbfs_cachenode *file_cbfs_get_first(void) { - if (!initialized) { + struct cbfs_priv *priv = &cbfs_s; + + if (!priv->initialized) { file_cbfs_result = CBFS_NOT_INITIALIZED; return NULL; } else { file_cbfs_result = CBFS_SUCCESS; - return file_cache; + return priv->file_cache; } } void file_cbfs_get_next(const struct cbfs_cachenode **file) { - if (!initialized) { + struct cbfs_priv *priv = &cbfs_s; + + if (!priv->initialized) { file_cbfs_result = CBFS_NOT_INITIALIZED; - file = NULL; + *file = NULL; return; } @@ -226,11 +245,12 @@ void file_cbfs_get_next(const struct cbfs_cachenode **file) file_cbfs_result = CBFS_SUCCESS; } -const struct cbfs_cachenode *file_cbfs_find(const char *name) +const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *priv, + const char *name) { - struct cbfs_cachenode *cache_node = file_cache; + struct cbfs_cachenode *cache_node = priv->file_cache; - if (!initialized) { + if (!priv->initialized) { file_cbfs_result = CBFS_NOT_INITIALIZED; return NULL; } @@ -248,26 +268,33 @@ const struct cbfs_cachenode *file_cbfs_find(const char *name) return cache_node; } +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 char *name) { + struct cbfs_priv *priv = &cbfs_s; u8 *start; u32 size; u32 align; static struct cbfs_cachenode node; - if (file_cbfs_load_header(end_of_rom, &cbfs_header)) + if (file_cbfs_load_header(end_of_rom, &priv->header)) return NULL; - start = (u8 *)(end_of_rom + 1 - cbfs_header.rom_size); - size = cbfs_header.rom_size; - align = cbfs_header.align; + start = (u8 *)(end_of_rom + 1 - priv->header.rom_size); + size = priv->header.rom_size; + align = priv->header.align; while (size >= align) { int result; u32 used; - result = file_cbfs_next_file(start, size, align, &node, &used); + result = file_cbfs_next_file(priv, start, size, align, &node, + &used); if (result < 0) return NULL; @@ -287,18 +314,21 @@ const struct cbfs_cachenode *file_cbfs_find_uncached(uintptr_t end_of_rom, const char *file_cbfs_name(const struct cbfs_cachenode *file) { file_cbfs_result = CBFS_SUCCESS; + return file->name; } u32 file_cbfs_size(const struct cbfs_cachenode *file) { file_cbfs_result = CBFS_SUCCESS; + return file->data_length; } u32 file_cbfs_type(const struct cbfs_cachenode *file) { file_cbfs_result = CBFS_SUCCESS; + return file->type; } @@ -312,7 +342,7 @@ long file_cbfs_read(const struct cbfs_cachenode *file, void *buffer, size = maxsize; memcpy(buffer, file->data, size); - file_cbfs_result = CBFS_SUCCESS; + return size; } 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. * From patchwork Wed Aug 14 03:09:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1146728 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="SgrDvxmR"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 467ZNV0cQmz9sDB for ; Wed, 14 Aug 2019 13:11:05 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A8C58C21E0D; Wed, 14 Aug 2019 03:09:56 +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_H2, 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 045E2C21D65; Wed, 14 Aug 2019 03:09:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A508FC21D74; Wed, 14 Aug 2019 03:09:31 +0000 (UTC) Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by lists.denx.de (Postfix) with ESMTPS id 6DD5BC21DB6 for ; Wed, 14 Aug 2019 03:09:29 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id o6so1737545oic.9 for ; Tue, 13 Aug 2019 20:09:29 -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=0MECfPucJk46rb7ShxG7q9lqWsyfWO5uKLbryLeKnns=; b=SgrDvxmRueAT+5Je8bTOTrQi15DM+9Sd271+d7x3/PXHTBZ99ujV7FvlAAaBy9kkZJ AP4IUEfDpgdZWe0wjlvmdsSeukFaDqM6UXl6dtVaxPeQBSBHa4Kxw3TLQt8exNhCp3zK MtkU6IlE1j9u3cU+MsgAyF7d4uD/DhbV6wsE4= 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=0MECfPucJk46rb7ShxG7q9lqWsyfWO5uKLbryLeKnns=; b=cXHUWxB6M1LguY3Uv9uSQmeW95T5eoh6AZNhAuc40JxWB6HpnZuGKABb3YD1RNA4Ni PbGYxooGDqRHsyWQLEHKGs9pJ52FWW3Up6W8KBMf+m+5pn8A4LyUuFSKq1fvYKz8kqX9 aCzs8g3MfsnqSevE1ysHN+MWG5iH6sUopmdtNVZ+UVy+I/o4YxUrqUMcXjJnVyLHwFAJ CT/xZXjtWy55jYF0csQo1b5KAUmBoWx5nlwLX0uXL1fKtRCMsa8SIOxg4Ew0OIm71nND PtONS0rW6tPpErV8wsiRv9+oRmlvkOgsrEknSleySqNhj+oJM+pxlIhQJkC+5qJUui0f jkrA== X-Gm-Message-State: APjAAAWHJoGdwU7/32ahpHHq8sR7oFTpvrB5xlHjrj607J0Aa479PYtJ /EErrJ0D65LbbfP8k2/2kLc48wyCB28= X-Google-Smtp-Source: APXvYqwsupLZasK/zRuxeFDoSh23vJA4bIXC9rAUkI6QYbM2/eBuzxx8VqgR0ALP3JOdmpyf0rbqGQ== X-Received: by 2002:a02:c992:: with SMTP id b18mr1079903jap.128.1565752168222; Tue, 13 Aug 2019 20:09:28 -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.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 20:09:27 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 13 Aug 2019 21:09:13 -0600 Message-Id: <20190814030914.256689-6-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: Stefan Reinauer Subject: [U-Boot] [PATCH 5/6] cbfs: Add functions to support multiple CBFSs 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" Sometimes an image has multiple CBFS. The current CBFS API is limited to handling only one at time. Also it keeps track of the CBFS internally in BSS, which does not work before relocation, for example. Add a few new functions to overcome these limitations. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/cbfs.h | 22 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index dafdfb1a07..bb795e7288 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -187,6 +187,23 @@ static int file_cbfs_load_header(uintptr_t end_of_rom, return 0; } +static int cbfs_load_header_ptr(struct cbfs_priv *priv, ulong base, + struct cbfs_header *header) +{ + struct cbfs_header *header_in_rom; + + header_in_rom = (struct cbfs_header *)base; + 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 -EFAULT; + } + + return 0; +} + void cbfs_init(struct cbfs_priv *priv, uintptr_t end_of_rom) { u8 *start_of_rom; @@ -209,6 +226,35 @@ void file_cbfs_init(uintptr_t end_of_rom) cbfs_init(&cbfs_s, end_of_rom); } +int cbfs_init_mem(ulong base, ulong size, struct cbfs_priv **privp) +{ + struct cbfs_priv priv_s, *priv = &priv_s; + int ret; + + /* + * 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. + */ + ret = cbfs_load_header_ptr(priv, base + 0x38, &priv->header); + if (ret) + return ret; + + file_cbfs_fill_cache(priv, (u8 *)base, priv->header.rom_size, + priv->header.align); + if (priv->result != CBFS_SUCCESS) + return -EINVAL; + + priv->initialized = 1; + priv = malloc(sizeof(priv_s)); + if (!priv) + return -ENOMEM; + memcpy(priv, &priv_s, sizeof(priv_s)); + *privp = priv; + + return 0; +} + const struct cbfs_header *file_cbfs_get_header(void) { struct cbfs_priv *priv = &cbfs_s; diff --git a/include/cbfs.h b/include/cbfs.h index 742e34e24f..6d4c4d4b06 100644 --- a/include/cbfs.h +++ b/include/cbfs.h @@ -135,6 +135,28 @@ void file_cbfs_get_next(const struct cbfs_cachenode **file); */ const struct cbfs_cachenode *file_cbfs_find(const char *name); +struct cbfs_priv *priv; + +/** + * cbfs_find_file() - Find a file in a given CBFS + * + * @cbfs: CBFS to look in (use cbfs_init_mem() to set it up) + * @name: Filename to look for + * @return pointer to CBFS node if found, else NULL + */ +const struct cbfs_cachenode *cbfs_find_file(struct cbfs_priv *cbfs, + const char *name); + +/** + * 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); + /***************************************************************************/ /* All of the functions below can be used without first initializing CBFS. */ From patchwork Wed Aug 14 03:09:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1146729 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="L935baiR"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 467ZNp17Dlz9sNp for ; Wed, 14 Aug 2019 13:11:22 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id BC401C21DD3; Wed, 14 Aug 2019 03:10:07 +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 75CA5C21DD4; Wed, 14 Aug 2019 03:09:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5AA27C21DA6; Wed, 14 Aug 2019 03:09:33 +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 43C8DC21D56 for ; Wed, 14 Aug 2019 03:09:31 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id o101so26138499ota.8 for ; Tue, 13 Aug 2019 20:09:31 -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=UK5jwSXGRR4uheXap9ze8c6DtbzIY1BhNcmL0hBtr3Q=; b=L935baiR59gfMbkl+2J/hn+TUFdMKBJ6ihfe1eXHyUm+o1fgMrITa4aAbV9qw82CP8 daJnCtlCpr5qE2SIkS/gU0p7WA0RkwpoiRa0DsFADG/p4Q7+OtfCTR7oWJf94XTJBbnA 9HKXfA6HOpIDiqBqtHCq21Ow99CPHvgHMigqM= 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=UK5jwSXGRR4uheXap9ze8c6DtbzIY1BhNcmL0hBtr3Q=; b=MNDi8uzCdygWrtVRwfx76uOKuCcVPzm1/DSnPryt5qRe4MFHKf1bzLXDH1H2ft6rKS LKSs6okpo5WsAGOBcqDYYQCTZZ4RVFOHgibpX/tVMDE7nuuQoUw9P166sKzY0B2A89L+ 3AUhlDpKq2RutXtCkYRNtmOf5CTsLdo6DYDbe8Oh4OH6SvEKgL8gFWuGKdxQQpidDxjl tjpI0Sc3yITcNipF8t62loGeqxCLg3r4sd8JVFrlAr2DUurwTRpzuxf7oU03NIu5+XvF gw3c3aJeYoxk+VRbMBK7PfitD+casItAt2it2XWoaK76IRKzr/WorU9hsiefB0Zsl4FS kjHQ== X-Gm-Message-State: APjAAAU7m7ow+qeEBmfvDcYxHoXRVbrreSDd4nm213ZZuWq0FVjBGy/A wvawcNDbWaKHkZ/LG9Mp8IyubGIIYHU= X-Google-Smtp-Source: APXvYqwAOY6rHhYBX7yCLfK6FAUOYgfxlxVGJYYMFYOlIU9EYaJoC7u6m0iLcGu1mn/kudgfMmgtIQ== X-Received: by 2002:a05:6602:98:: with SMTP id h24mr43661909iob.49.1565752170119; Tue, 13 Aug 2019 20:09:30 -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.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 20:09:29 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 13 Aug 2019 21:09:14 -0600 Message-Id: <20190814030914.256689-7-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: Stefan Reinauer Subject: [U-Boot] [PATCH 6/6] cbfs: Rename camel-case variables 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" Rename some camel-case variables to match U-Boot style. Camel case is not generally allowed in U-Boot. Rename this variable to fit in with the style. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- fs/cbfs/cbfs.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/fs/cbfs/cbfs.c b/fs/cbfs/cbfs.c index bb795e7288..aaf9ce941b 100644 --- a/fs/cbfs/cbfs.c +++ b/fs/cbfs/cbfs.c @@ -73,14 +73,14 @@ static void swap_file_header(struct cbfs_fileheader *dest, * @param start The location in memory to start from. * @param size The size of the memory region to search. * @param align The alignment boundaries to check on. - * @param newNode A pointer to the file structure to load. + * @param new_node A pointer to the file structure to load. * @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. */ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, - u32 align, struct cbfs_cachenode *newNode, + u32 align, struct cbfs_cachenode *new_node, u32 *used) { struct cbfs_fileheader header; @@ -88,34 +88,34 @@ static int file_cbfs_next_file(struct cbfs_priv *priv, u8 *start, u32 size, *used = 0; while (size >= align) { - const struct cbfs_fileheader *fileHeader = + const struct cbfs_fileheader *file_header = (const struct cbfs_fileheader *)start; u32 name_len; u32 step; /* Check if there's a file here. */ - if (memcmp(good_file_magic, &(fileHeader->magic), - sizeof(fileHeader->magic))) { + if (memcmp(good_file_magic, &file_header->magic, + sizeof(file_header->magic))) { *used += align; size -= align; start += align; continue; } - swap_file_header(&header, fileHeader); + swap_file_header(&header, file_header); if (header.offset < sizeof(struct cbfs_fileheader)) { priv->result = CBFS_BAD_FILE; return -1; } - newNode->next = NULL; - newNode->type = header.type; - newNode->data = start + header.offset; - newNode->data_length = header.len; + new_node->next = NULL; + new_node->type = header.type; + new_node->data = start + header.offset; + new_node->data_length = header.len; name_len = header.offset - sizeof(struct cbfs_fileheader); - newNode->name = (char *)fileHeader + + new_node->name = (char *)file_header + sizeof(struct cbfs_fileheader); - newNode->name_length = name_len; - newNode->attributes_offset = header.attributes_offset; + new_node->name_length = name_len; + new_node->attributes_offset = header.attributes_offset; step = header.len; if (step % align) @@ -132,15 +132,15 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, u32 align) { struct cbfs_cachenode *cache_node; - struct cbfs_cachenode *newNode; + struct cbfs_cachenode *new_node; struct cbfs_cachenode **cache_tail = &priv->file_cache; /* Clear out old information. */ cache_node = priv->file_cache; while (cache_node) { - struct cbfs_cachenode *oldNode = cache_node; + struct cbfs_cachenode *old_node = cache_node; cache_node = cache_node->next; - free(oldNode); + free(old_node); } priv->file_cache = NULL; @@ -148,20 +148,20 @@ static void file_cbfs_fill_cache(struct cbfs_priv *priv, u8 *start, u32 size, int result; u32 used; - newNode = (struct cbfs_cachenode *) + new_node = (struct cbfs_cachenode *) malloc(sizeof(struct cbfs_cachenode)); - result = file_cbfs_next_file(priv, start, size, align, newNode, + result = file_cbfs_next_file(priv, start, size, align, new_node, &used); if (result < 0) { - free(newNode); + free(new_node); return; } else if (result == 0) { - free(newNode); + free(new_node); break; } - *cache_tail = newNode; - cache_tail = &newNode->next; + *cache_tail = new_node; + cache_tail = &new_node->next; size -= used; start += used;