All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: "Tom Rini" <trini@konsulko.com>, "Bin Meng" <bmeng.cn@gmail.com>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Bill Mills" <bill.mills@linaro.org>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"François Ozog" <francois.ozog@linaro.org>,
	"Simon Glass" <sjg@chromium.org>
Subject: [PATCH 13/31] bloblist: Refactor Kconfig to support alloc or fixed
Date: Sun, 31 Oct 2021 19:17:15 -0600	[thread overview]
Message-ID: <20211101011734.1614781-14-sjg@chromium.org> (raw)
In-Reply-To: <20211101011734.1614781-1-sjg@chromium.org>

At present we do support allocating the bloblist but the Kconfig is a bit
strange, since we still have to specify an address in that case. Partly
this is because it is a pain to have CONFIG options that disappears when
its dependency is enabled. It means that we must have #ifdefs in the code,
either in the C code or header file.

Make use of IF_ENABLED_INT() and its friend to solve that problem, so we
can separate out the location of bloblist into a choice. Put the address
and size into variables so we can log the result.

Add the options for SPL as well, so we can use CONFIG_IS_ENABLED().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/Kconfig    | 91 ++++++++++++++++++++++++++++++++++++++++++-----
 common/bloblist.c | 39 ++++++++++++--------
 2 files changed, 106 insertions(+), 24 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 4cf1831f599..2c6f5901c8a 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -721,15 +721,17 @@ config TPL_BLOBLIST
 
 if BLOBLIST
 
-config BLOBLIST_SIZE
-	hex "Size of bloblist"
-	depends on BLOBLIST
-	default 0x400
+choice
+	prompt "Bloblist location"
 	help
-	  Sets the size of the bloblist in bytes. This must include all
-	  overhead (alignment, bloblist header, record header). The bloblist
-	  is set up in the first part of U-Boot to run (TPL, SPL or U-Boot
-	  proper), and this sane bloblist is used for subsequent phases.
+	  Select the location of the bloblist, via various means.
+
+config BLOBLIST_FIXED
+	bool "Place bloblist at a fixed address in memory"
+	help
+	  Select this to used a fixed memory address for the bloblist. If the
+	  bloblist exists at this address from a previous phase, it used as is.
+	  If not it is created at this address in U-Boot.
 
 config BLOBLIST_ALLOC
 	bool "Allocate bloblist"
@@ -738,18 +740,31 @@ config BLOBLIST_ALLOC
 	  specify a fixed address on systems where this is unknown or can
 	  change at runtime.
 
+endchoice
+
 config BLOBLIST_ADDR
 	hex "Address of bloblist"
 	default 0xc000 if SANDBOX
+	depends on BLOBLIST_FIXED
 	help
 	  Sets the address of the bloblist, set up by the first part of U-Boot
 	  which runs. Subsequent U-Boot phases typically use the same address.
 
 	  This is not used if BLOBLIST_ALLOC is selected.
 
+config BLOBLIST_SIZE
+	hex "Size of bloblist"
+	default 0x400
+	help
+	  Sets the size of the bloblist in bytes. This must include all
+	  overhead (alignment, bloblist header, record header). The bloblist
+	  is set up in the first part of U-Boot to run (TPL, SPL or U-Boot
+	  proper), and this sane bloblist is used for subsequent phases.
+
 config BLOBLIST_SIZE_RELOC
 	hex "Size of bloblist after relocation"
-	default BLOBLIST_SIZE
+	default BLOBLIST_SIZE if BLOBLIST_FIXED || BLOBLIST_ALLOC
+	default 0 if BLOBLIST_PASSAGE
 	help
 	  Sets the size of the bloblist in bytes after relocation. Since U-Boot
 	  has a lot more memory available then, it is possible to use a larger
@@ -758,6 +773,64 @@ config BLOBLIST_SIZE_RELOC
 
 endif # BLOBLIST
 
+if SPL_BLOBLIST
+
+choice
+	prompt "Bloblist location in SPL"
+	help
+	  Select the location of the bloblist, via various means. Typically
+	  you should use the same value for SPL as for U-Boot, since they need
+	  to look in the same place. But if BLOBLIST_ALLOC is used, then a
+	  fresh bloblist will be created each time, since there is no shared
+	  address (between phases) for the bloblist.
+
+config SPL_BLOBLIST_FIXED
+	bool "Place bloblist at a fixed address in memory"
+	help
+	  Select this to used a fixed memory address for the bloblist. If the
+	  bloblist exists at this address from a previous phase, it used as is.
+	  If not it is created at this address in SPL.
+
+config SPL_BLOBLIST_ALLOC
+	bool "Allocate bloblist"
+	help
+	  Allocate the bloblist using malloc(). This avoids the need to
+	  specify a fixed address on systems where this is unknown or can
+	  change at runtime.
+
+endchoice
+
+endif # SPL_BLOBLIST
+
+if TPL_BLOBLIST
+
+choice
+	prompt "Bloblist location in TPL"
+	help
+	  Select the location of the bloblist, via various means. Typically
+	  you should use the same value for SPL as for U-Boot, since they need
+	  to look in the same place. But if BLOBLIST_ALLOC is used, then a
+	  fresh bloblist will be created each time, since there is no shared
+	  address (between phases) for the bloblist.
+
+config TPL_BLOBLIST_FIXED
+	bool "Place bloblist at a fixed address in memory"
+	help
+	  Select this to used a fixed memory address for the bloblist. If the
+	  bloblist exists at this address from a previous phase, it used as is.
+	  If not it is created at this address in TPL.
+
+config TPL_BLOBLIST_ALLOC
+	bool "Allocate bloblist"
+	help
+	  Allocate the bloblist using malloc(). This avoids the need to
+	  specify a fixed address on systems where this is unknown or can
+	  change at runtime.
+
+endchoice
+
+endif # TPL_BLOBLIST
+
 endmenu
 
 source "common/spl/Kconfig"
diff --git a/common/bloblist.c b/common/bloblist.c
index b5fea12b697..6e7f813db94 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -4,6 +4,7 @@
  * Written by Simon Glass <sjg@chromium.org>
  */
 
+#define LOG_DEBUG
 #define LOG_CATEGORY	LOGC_BLOBLIST
 
 #include <common.h>
@@ -360,6 +361,8 @@ int bloblist_finish(void)
 	struct bloblist_hdr *hdr = gd->bloblist;
 
 	hdr->chksum = bloblist_calc_chksum(hdr);
+	log_debug("Finished bloblist size %lx at %lx\n", (ulong)hdr->size,
+		  (ulong)map_to_sysmem(hdr));
 
 	return 0;
 }
@@ -415,8 +418,9 @@ void bloblist_reloc(void *to, uint to_size, void *from, uint from_size)
 
 int bloblist_init(void)
 {
-	bool expected;
 	int ret = -ENOENT;
+	ulong addr, size;
+	bool expected;
 
 	/**
 	 * Wed expect to find an existing bloblist in the first phase of U-Boot
@@ -425,27 +429,32 @@ int bloblist_init(void)
 	expected = !u_boot_first_phase();
 	if (spl_prev_phase() == PHASE_TPL && !IS_ENABLED(CONFIG_TPL_BLOBLIST))
 		expected = false;
-	if (expected)
-		ret = bloblist_check(CONFIG_BLOBLIST_ADDR,
-				     CONFIG_BLOBLIST_SIZE);
+	addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED, CONFIG_BLOBLIST_ADDR);
+	size = CONFIG_BLOBLIST_SIZE;
+	if (expected) {
+		ret = bloblist_check(addr, size);
+		if (ret) {
+			log_warning("Expected bloblist at %lx not found (err=%d)\n",
+				    addr, ret);
+		} else {
+			/* Get the real size, if it is not what we expected */
+			size = gd->bloblist->size;
+		}
+	}
 	if (ret) {
-		ulong addr;
-
-		log(LOGC_BLOBLIST, expected ? LOGL_WARNING : LOGL_DEBUG,
-		    "Existing bloblist not found: creating new bloblist\n");
-		if (IS_ENABLED(CONFIG_BLOBLIST_ALLOC)) {
-			void *ptr = memalign(BLOBLIST_ALIGN,
-					     CONFIG_BLOBLIST_SIZE);
+		if (CONFIG_IS_ENABLED(BLOBLIST_ALLOC)) {
+			void *ptr = memalign(BLOBLIST_ALIGN, size);
 
 			if (!ptr)
 				return log_msg_ret("alloc", -ENOMEM);
 			addr = map_to_sysmem(ptr);
-		} else {
-			addr = CONFIG_BLOBLIST_ADDR;
 		}
-		ret = bloblist_new(addr, CONFIG_BLOBLIST_SIZE, 0);
+		log_debug("Creating new bloblist size %lx at %lx\n", size,
+			  addr);
+		ret = bloblist_new(addr, size, 0);
 	} else {
-		log_debug("Found existing bloblist\n");
+		log_debug("Found existing bloblist size %lx at %lx\n", size,
+			  addr);
 	}
 
 	return ret;
-- 
2.33.1.1089.g2158813163f-goog


  parent reply	other threads:[~2021-11-01  1:21 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01  1:17 [PATCH 00/31] passage: Define a standard for firmware data flow Simon Glass
2021-11-01  1:17 ` Simon Glass
2021-11-01  1:17 ` [PATCH 01/31] Makefile: Correct TPL rule for OF_REAL Simon Glass
2021-11-01  6:54   ` Ilias Apalodimas
2021-11-14  0:34   ` Simon Glass
2021-11-01  1:17 ` [PATCH 02/31] kconfig: Add support for conditional values Simon Glass
2021-11-01  7:05   ` Ilias Apalodimas
2022-01-12 21:28     ` Simon Glass
2022-01-12 21:56       ` Tom Rini
2022-01-12 22:22         ` Simon Glass
2022-01-12 23:04           ` Tom Rini
2022-01-13  7:56         ` Rasmus Villemoes
2022-01-13 12:52           ` Tom Rini
2022-01-13 13:56             ` Simon Glass
2022-01-13 15:01             ` Rasmus Villemoes
2022-01-13 15:29               ` Tom Rini
2021-11-01  1:17 ` [PATCH 03/31] dm: core: Allow getting some basic stats Simon Glass
2021-11-01  7:07   ` Ilias Apalodimas
2021-11-01  1:17 ` [PATCH 04/31] stddef: Avoid warning with clang with offsetof() Simon Glass
2022-01-13  8:08   ` Rasmus Villemoes
2022-01-13 13:07     ` Tom Rini
2022-01-13 13:37       ` Simon Glass
2022-01-13 13:41         ` Tom Rini
2022-01-13 13:50           ` Simon Glass
2021-11-01  1:17 ` [PATCH 05/31] fdt: Drop SPL_BUILD macro Simon Glass
2021-11-01  7:42   ` Ilias Apalodimas
2021-11-01  1:17 ` [PATCH 06/31] bloblist: Put the magic number first Simon Glass
2021-11-01  1:17 ` [PATCH 07/31] bloblist: Rename the SPL tag Simon Glass
2021-11-01  1:17 ` [PATCH 08/31] bloblist: Drop unused tags Simon Glass
2021-11-01  1:17 ` [PATCH 09/31] bloblist: Use explicit numbering for the tags Simon Glass
2021-11-01  1:17 ` [PATCH 10/31] bloblist: Support allocating the bloblist Simon Glass
2021-11-01  1:17 ` [PATCH 11/31] bloblist: Use LOG_CATEGORY to simply logging Simon Glass
2021-11-01  1:17 ` [PATCH 12/31] bloblist: Use 'phase' consistently for bloblists Simon Glass
2021-11-01  1:17 ` Simon Glass [this message]
2021-11-01  1:17 ` [PATCH 14/31] arm: qemu: Add an SPL build Simon Glass
2021-11-01  1:17   ` Simon Glass
2021-11-01  1:17 ` [PATCH 15/31] bloblist: Add functions to obtain base address and size Simon Glass
2021-11-01  1:17 ` [PATCH 16/31] passage: Support an incoming passage Simon Glass
2021-11-01  1:17 ` [PATCH 17/31] passage: Support a control devicetree Simon Glass
2021-11-01  1:17 ` [PATCH 18/31] passage: arm: Accept a passage from the previous phase Simon Glass
2021-11-01  1:17 ` [PATCH 19/31] passage: spl: Support adding the dtb to the passage bloblist Simon Glass
2021-11-01  1:17 ` [PATCH 20/31] passage: spl: Support passing the passage to U-Boot Simon Glass
2021-11-01  1:17 ` [PATCH 21/31] passage: Record where the devicetree came from Simon Glass
2021-11-01  1:17 ` [PATCH 22/31] passage: Report the devicetree source Simon Glass
2021-11-01  1:17 ` [PATCH 23/31] passage: Add a qemu test for ARM Simon Glass
2021-11-01  1:17 ` [PATCH 24/31] bloblist: doc: Bring in the API documentation Simon Glass
2021-11-01  1:17 ` [PATCH 25/31] bloblist: Relicense to allow BSD-3-Clause Simon Glass
2021-11-01  1:17 ` [PATCH 26/31] sandbox: Add a way of checking structs for standard passage Simon Glass
2021-11-01  1:17 ` [PATCH 27/31] passage: Add documentation Simon Glass
2021-11-01  1:17 ` [PATCH 28/31] passage: Add docs for spl_handoff Simon Glass
2021-11-01  1:17 ` [PATCH 29/31] x86: Move Intel GNVS file into the common include directory Simon Glass
2021-11-01  1:17 ` [PATCH 30/31] passage: Add checks for pre-existing blobs Simon Glass
2021-11-01  1:17 ` [PATCH 31/31] WIP: RFC: Add a gitlab test Simon Glass
2021-11-01  8:53 ` [PATCH 00/31] passage: Define a standard for firmware data flow François Ozog
2021-11-01  8:53   ` François Ozog
2021-11-01 18:19   ` Mark Kettenis
2021-11-01 18:19     ` Mark Kettenis
2021-11-01 20:45     ` François Ozog
2021-11-01 20:45       ` François Ozog
2021-11-02 14:58   ` Simon Glass
2021-11-02 14:58     ` Simon Glass
2021-11-02 16:03     ` François Ozog
2021-11-02 16:03       ` François Ozog
2021-11-05  2:02       ` Simon Glass
2021-11-05  2:02         ` Simon Glass
2021-11-05  8:26         ` François Ozog
2021-11-05  8:26           ` François Ozog
2021-11-05 16:12           ` Simon Glass
2021-11-05 16:12             ` Simon Glass
2021-11-05 16:31             ` François Ozog
2021-11-05 16:31               ` François Ozog
2021-11-05 17:16               ` Simon Glass
2021-11-05 17:16                 ` Simon Glass
2021-11-08 16:20                 ` François Ozog
2021-11-08 16:20                   ` François Ozog
2021-11-10 19:37                   ` Simon Glass
2021-11-10 19:37                     ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211101011734.1614781-14-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=bill.mills@linaro.org \
    --cc=bmeng.cn@gmail.com \
    --cc=francois.ozog@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.