Skip to contentSkip to conversation

bloblist: Enhancements for standard passage

PATCH Superseded Simon Glass 1 participant 24 messages Jan 13, 2022 x86

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover bloblist: Enhancements for standard passage

This series collects together the prerequisites for standard passage. The only change is to drop the CONFIG_IF_ENABLED_INT() macro.

Changes in v2:
- Create an accessor for CONFIG_BLOBLIST_ADDR instead of the Kconfig macro

Simon Glass (12):
stddef: Avoid warning with clang with offsetof()
fdt: Drop SPL_BUILD macro
bloblist: Put the magic number first
bloblist: Rename the SPL tag
bloblist: Drop unused tags
bloblist: Use explicit numbering for the tags
bloblist: Use LOG_CATEGORY to simply logging
bloblist: Use 'phase' consistently for bloblists
bloblist: Refactor Kconfig to support alloc or fixed
bloblist: Add functions to obtain base address and size
bloblist: doc: Bring in the API documentation
bloblist: Relicense to allow BSD-3-Clause

 arch/x86/cpu/broadwell/cpu_from_spl.c |   4 +-
 common/Kconfig                        |  95 +++++++++++--
 common/bloblist.c                     | 119 +++++++++++------
 common/board_f.c                      |   2 +-
 common/spl/spl.c                      |   4 +-
 doc/develop/bloblist.rst              |   8 +-
 drivers/serial/serial-uclass.c        |   3 +-
 include/bloblist.h                    | 184 +++++++++++++++++++-------
 include/fdtdec.h                      |   6 -
 include/linux/stddef.h                |   8 +-
 test/bloblist.c                       |  21 ++-
 11 files changed, 333 insertions(+), 121 deletions(-)
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#1 lore raw

PATCH v2 1/12 stddef: Avoid warning with clang with offsetof()

Some bright sparks have decided that a cast on a constant cannot be a constant, so offsetof() produces this warning on clang-10:

include/intel_gnvs.h:113:1: error: static_assert expression is not an
integral constant expression
check_member(acpi_global_nvs, unused2, GNVS_CHROMEOS_ACPI_OFFSET); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/kernel.h:284:2: note: expanded from macro 'check_member'

        offsetof(struct structure, member) == (offset), \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/stddef.h:20:32: note: expanded from macro 'offsetof'
                                ^

include/intel_gnvs.h:113:1: note: cast that performs the conversions of
a reinterpret_cast is ot allowed in a constant expression
include/linux/stddef.h:20:33: note: expanded from macro 'offsetof'

Fix it by using the compiler built-in version, if available.

---

(no changes since v1)

 include/linux/stddef.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
include/linux/stddef.h +7 -1
index c540f6100d4..a7f546fdfe5 100644
@@ -1,6 +1,8 @@
 #ifndef _LINUX_STDDEF_H
 #define _LINUX_STDDEF_H
 
+#include <linux/compiler_types.h>
+
 #undef NULL
 #if defined(__cplusplus)
 #define NULL 0
@@ -14,7 +16,11 @@
 
 #ifndef __CHECKER__
 #undef offsetof
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#ifdef __compiler_offsetof
+#define offsetof(TYPE, MEMBER)	__compiler_offsetof(TYPE, MEMBER)
+#else
+#define offsetof(TYPE, MEMBER)	((size_t)&((TYPE *)0)->MEMBER)
+#endif
 #endif
 
 #endif
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#2 lore raw

PATCH v2 2/12 fdt: Drop SPL_BUILD macro

In reply to Simon Glass

This old macro is not needed anymore since we can use IS_ENABLED() now. Drop it.

---

(no changes since v1)

 drivers/serial/serial-uclass.c | 3 ++-
 include/fdtdec.h               | 6 ------
 2 files changed, 2 insertions(+), 7 deletions(-)
drivers/serial/serial-uclass.c +2 -1
index 30d44214d7d..96a1cb65ba2 100644
@@ -104,7 +104,8 @@ static void serial_find_console_or_panic(void)
 			}
 		}
 	}
-	if (!SPL_BUILD || !CONFIG_IS_ENABLED(OF_CONTROL) || !blob) {
+	if (!IS_ENABLED(CONFIG_SPL_BUILD) || !CONFIG_IS_ENABLED(OF_CONTROL) ||
+	    !blob) {
 		/*
 		 * Try to use CONFIG_CONS_INDEX if available (it is numbered
 		 * from 1!).
include/fdtdec.h +0 -6
index 09525ce510a..15f2d2bbbaa 100644
@@ -49,12 +49,6 @@ struct fdt_memory {
 
 struct bd_info;
 
-#ifdef CONFIG_SPL_BUILD
-#define SPL_BUILD	1
-#else
-#define SPL_BUILD	0
-#endif
-
 /**
  * enum fdt_source_t - indicates where the devicetree came from
  *
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#3 lore raw

Re: [PATCH v2 02/12] fdt: Drop SPL_BUILD macro

This old macro is not needed anymore since we can use IS_ENABLED() now. Drop it.

---

(no changes since v1)

 drivers/serial/serial-uclass.c | 3 ++-
 include/fdtdec.h               | 6 ------
 2 files changed, 2 insertions(+), 7 deletions(-)

Applied to u-boot-dm, thanks!

#4 lore raw

PATCH v2 3/12 bloblist: Put the magic number first

In reply to Simon Glass

It seems best to put the magic number right at the start of the bloblist header, so it is easier to check. This is how devicetree works.

Make this change now, before other projects make use of bloblist. Other changes may be needed / discussed, but that is TBD.

Add a checker function as well.

---

(no changes since v1)

 include/bloblist.h | 25 +++++++++++++++++++++++--
 test/bloblist.c    |  7 +++++++
 2 files changed, 30 insertions(+), 2 deletions(-)
include/bloblist.h +23 -2
index 9f007c7a94d..29ea5a768a6 100644
@@ -13,6 +13,8 @@
 #ifndef __BLOBLIST_H
 #define __BLOBLIST_H
 
+#include <mapmem.h>
+
 enum {
 	BLOBLIST_VERSION	= 0,
 	BLOBLIST_MAGIC		= 0xb00757a3,
@@ -59,11 +61,11 @@ enum bloblist_tag_t {
  * Each bloblist record is aligned to a 16-byte boundary and follows immediately
  * from the last.
  *
+ * @magic: BLOBLIST_MAGIC
  * @version: BLOBLIST_VERSION
  * @hdr_size: Size of this header, normally sizeof(struct bloblist_hdr). The
  *	first bloblist_rec starts at this offset from the start of the header
  * @flags: Space for BLOBLISTF_... flags (none yet)
- * @magic: BLOBLIST_MAGIC
  * @size: Total size of the bloblist (non-zero if valid) including this header.
  *	The bloblist extends for this many bytes from the start of this header.
  *	When adding new records, the bloblist can grow up to this size.
@@ -78,10 +80,10 @@ enum bloblist_tag_t {
  *	calculation.
  */
 struct bloblist_hdr {
+	u32 magic;
 	u32 version;
 	u32 hdr_size;
 	u32 flags;
-	u32 magic;
 
 	u32 size;
 	u32 alloced;
@@ -111,6 +113,25 @@ struct bloblist_rec {
 	u32 spare;
 };
 
+/**
+ * bloblist_check_magic() - return a bloblist if the magic matches
+ *
+ * @addr: Address to check
+ * @return pointer to bloblist, if the magic matches, else NULL
+ */
+static inline void *bloblist_check_magic(ulong addr)
+{
+	u32 *ptr;
+
+	if (!addr)
+		return NULL;
+	ptr = map_sysmem(addr, 0);
+	if (*ptr != BLOBLIST_MAGIC)
+		return NULL;
+
+	return ptr;
+}
+
 /**
  * bloblist_find() - Find a blob
  *
test/bloblist.c +7 -0
index b48be38dc3e..525e94b7217 100644
@@ -71,7 +71,9 @@ static int bloblist_test_init(struct unit_test_state *uts)
 
 	hdr = clear_bloblist();
 	ut_asserteq(-ENOENT, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
+	ut_asserteq_ptr(NULL, bloblist_check_magic(TEST_ADDR));
 	ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0));
+	ut_asserteq_ptr(hdr, bloblist_check_magic(TEST_ADDR));
 	hdr->version++;
 	ut_asserteq(-EPROTONOSUPPORT, bloblist_check(TEST_ADDR,
 						     TEST_BLOBLIST_SIZE));
@@ -83,6 +85,11 @@ static int bloblist_test_init(struct unit_test_state *uts)
 	ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
 	ut_assertok(bloblist_finish());
 	ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
+
+	hdr->magic++;
+	ut_asserteq_ptr(NULL, bloblist_check_magic(TEST_ADDR));
+	hdr->magic--;
+
 	hdr->flags++;
 	ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
 
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#5 lore raw

Re: [PATCH v2 03/12] bloblist: Put the magic number first

It seems best to put the magic number right at the start of the bloblist header, so it is easier to check. This is how devicetree works.

Make this change now, before other projects make use of bloblist. Other changes may be needed / discussed, but that is TBD.

Add a checker function as well.

---

(no changes since v1)

 include/bloblist.h | 25 +++++++++++++++++++++++--
 test/bloblist.c    |  7 +++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!

#6 lore raw

PATCH v2 4/12 bloblist: Rename the SPL tag

In reply to Simon Glass

Add a U_BOOT prefix to this tag since it is specific to the U-Boot project.

---

(no changes since v1)

 arch/x86/cpu/broadwell/cpu_from_spl.c | 4 ++--
 common/bloblist.c                     | 2 +-
 common/board_f.c                      | 2 +-
 common/spl/spl.c                      | 4 ++--
 include/bloblist.h                    | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
arch/x86/cpu/broadwell/cpu_from_spl.c +2 -2
index e5f62e7187c..df5a9675ee4 100644
@@ -23,7 +23,7 @@ int dram_init(void)
 {
 	struct spl_handoff *ho;
 
-	ho = bloblist_find(BLOBLISTT_SPL_HANDOFF, sizeof(*ho));
+	ho = bloblist_find(BLOBLISTT_U_BOOT_SPL_HANDOFF, sizeof(*ho));
 	if (!ho)
 		return log_msg_ret("Missing SPL hand-off info", -ENOENT);
 	handoff_load_dram_size(ho);
@@ -56,7 +56,7 @@ int dram_init_banksize(void)
 {
 	struct spl_handoff *ho;
 
-	ho = bloblist_find(BLOBLISTT_SPL_HANDOFF, sizeof(*ho));
+	ho = bloblist_find(BLOBLISTT_U_BOOT_SPL_HANDOFF, sizeof(*ho));
 	if (!ho)
 		return log_msg_ret("Missing SPL hand-off info", -ENOENT);
 	handoff_load_dram_banks(ho);
common/bloblist.c +1 -1
index 01b04103d91..89b415d6178 100644
@@ -32,7 +32,7 @@ DECLARE_GLOBAL_DATA_PTR;
 static const char *const tag_name[] = {
 	[BLOBLISTT_NONE]		= "(none)",
 	[BLOBLISTT_EC_HOSTEVENT]	= "EC host event",
-	[BLOBLISTT_SPL_HANDOFF]		= "SPL hand-off",
+	[BLOBLISTT_U_BOOT_SPL_HANDOFF]		= "SPL hand-off",
 	[BLOBLISTT_VBOOT_CTX]		= "Chrome OS vboot context",
 	[BLOBLISTT_VBOOT_HANDOFF]	= "Chrome OS vboot hand-off",
 	[BLOBLISTT_ACPI_GNVS]		= "ACPI GNVS",
common/board_f.c +1 -1
index dd69c3b6b77..a68760092ac 100644
@@ -283,7 +283,7 @@ static int setup_mon_len(void)
 static int setup_spl_handoff(void)
 {
 #if CONFIG_IS_ENABLED(HANDOFF)
-	gd->spl_handoff = bloblist_find(BLOBLISTT_SPL_HANDOFF,
+	gd->spl_handoff = bloblist_find(BLOBLISTT_U_BOOT_SPL_HANDOFF,
 					sizeof(struct spl_handoff));
 	debug("Found SPL hand-off info %p\n", gd->spl_handoff);
 #endif
common/spl/spl.c +2 -2
index 4c101ec5d34..f51d1f32052 100644
@@ -408,7 +408,7 @@ static int setup_spl_handoff(void)
 {
 	struct spl_handoff *ho;
 
-	ho = bloblist_ensure(BLOBLISTT_SPL_HANDOFF, sizeof(struct spl_handoff));
+	ho = bloblist_ensure(BLOBLISTT_U_BOOT_SPL_HANDOFF, sizeof(struct spl_handoff));
 	if (!ho)
 		return -ENOENT;
 
@@ -425,7 +425,7 @@ static int write_spl_handoff(void)
 	struct spl_handoff *ho;
 	int ret;
 
-	ho = bloblist_find(BLOBLISTT_SPL_HANDOFF, sizeof(struct spl_handoff));
+	ho = bloblist_find(BLOBLISTT_U_BOOT_SPL_HANDOFF, sizeof(struct spl_handoff));
 	if (!ho)
 		return -ENOENT;
 	handoff_save_dram(ho);
include/bloblist.h +1 -1
index 29ea5a768a6..d4d48f76ff4 100644
@@ -27,7 +27,7 @@ enum bloblist_tag_t {
 
 	/* Vendor-specific tags are permitted here */
 	BLOBLISTT_EC_HOSTEVENT,		/* Chromium OS EC host-event mask */
-	BLOBLISTT_SPL_HANDOFF,		/* Hand-off info from SPL */
+	BLOBLISTT_U_BOOT_SPL_HANDOFF,		/* Hand-off info from SPL */
 	BLOBLISTT_VBOOT_CTX,		/* Chromium OS verified boot context */
 	BLOBLISTT_VBOOT_HANDOFF,	/* Chromium OS internal handoff info */
 	/*
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#7 lore raw

Re: [PATCH v2 04/12] bloblist: Rename the SPL tag

Add a U_BOOT prefix to this tag since it is specific to the U-Boot project.

---

(no changes since v1)

 arch/x86/cpu/broadwell/cpu_from_spl.c | 4 ++--
 common/bloblist.c                     | 2 +-
 common/board_f.c                      | 2 +-
 common/spl/spl.c                      | 4 ++--
 include/bloblist.h                    | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

Applied to u-boot-dm, thanks!

#8 lore raw

PATCH v2 5/12 bloblist: Drop unused tags

In reply to Simon Glass

The EC event log tag is no-longer used. The vboot handoff is now handled by the vboot context instead.

Drop these unused tags.

---

(no changes since v1)

 common/bloblist.c  | 4 +---
 include/bloblist.h | 2 --
 test/bloblist.c    | 4 ++--
 3 files changed, 3 insertions(+), 7 deletions(-)
common/bloblist.c +1 -3
index 89b415d6178..784eff61dea 100644
@@ -31,10 +31,8 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static const char *const tag_name[] = {
 	[BLOBLISTT_NONE]		= "(none)",
-	[BLOBLISTT_EC_HOSTEVENT]	= "EC host event",
-	[BLOBLISTT_U_BOOT_SPL_HANDOFF]		= "SPL hand-off",
+	[BLOBLISTT_U_BOOT_SPL_HANDOFF]	= "SPL hand-off",
 	[BLOBLISTT_VBOOT_CTX]		= "Chrome OS vboot context",
-	[BLOBLISTT_VBOOT_HANDOFF]	= "Chrome OS vboot hand-off",
 	[BLOBLISTT_ACPI_GNVS]		= "ACPI GNVS",
 	[BLOBLISTT_INTEL_VBT]		= "Intel Video-BIOS table",
 	[BLOBLISTT_TPM2_TCG_LOG]	= "TPM v2 log space",
include/bloblist.h +0 -2
index d4d48f76ff4..fac25907c07 100644
@@ -26,10 +26,8 @@ enum bloblist_tag_t {
 	BLOBLISTT_NONE = 0,
 
 	/* Vendor-specific tags are permitted here */
-	BLOBLISTT_EC_HOSTEVENT,		/* Chromium OS EC host-event mask */
 	BLOBLISTT_U_BOOT_SPL_HANDOFF,		/* Hand-off info from SPL */
 	BLOBLISTT_VBOOT_CTX,		/* Chromium OS verified boot context */
-	BLOBLISTT_VBOOT_HANDOFF,	/* Chromium OS internal handoff info */
 	/*
 	 * Advanced Configuration and Power Interface Global Non-Volatile
 	 * Sleeping table. This forms part of the ACPI tables passed to Linux.
test/bloblist.c +2 -2
index 525e94b7217..2e8e23d77dd 100644
@@ -289,9 +289,9 @@ static int bloblist_test_cmd_list(struct unit_test_state *uts)
 	console_record_reset();
 	run_command("bloblist list", 0);
 	ut_assert_nextline("Address       Size  Tag Name");
-	ut_assert_nextline("%08lx  %8x    1 EC host event",
+	ut_assert_nextline("%08lx  %8x    1 SPL hand-off",
 			   (ulong)map_to_sysmem(data), TEST_SIZE);
-	ut_assert_nextline("%08lx  %8x    2 SPL hand-off",
+	ut_assert_nextline("%08lx  %8x    2 Chrome OS vboot context",
 			   (ulong)map_to_sysmem(data2), TEST_SIZE2);
 	ut_assert_console_end();
 	ut_unsilence_console(uts);
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#9 lore raw

Re: [PATCH v2 05/12] bloblist: Drop unused tags

The EC event log tag is no-longer used. The vboot handoff is now handled by the vboot context instead.

Drop these unused tags.

---

(no changes since v1)

 common/bloblist.c  | 4 +---
 include/bloblist.h | 2 --
 test/bloblist.c    | 4 ++--
 3 files changed, 3 insertions(+), 7 deletions(-)

Applied to u-boot-dm, thanks!

#10 lore raw

PATCH v2 6/12 bloblist: Use explicit numbering for the tags

In reply to Simon Glass

At present if someone adds a tag in the middle of the list it works well enough within a U-Boot build. But if these tags are used in another project, or with an older version of SPL, the numbers make become inconsistent.

Use explicit tag numbers that never change, to resolve this problem. Allocate areas for existing U-Boot tags and set up an area for use by projects and vendors, as well as for private use. Keep tags above 0x10000 unallocated for now.

Update bloblist_tag_name() and the tests to work with this new setup.

---

(no changes since v1)

 common/bloblist.c  | 45 +++++++++++++++++++++++------------
 include/bloblist.h | 58 +++++++++++++++++++++++++++++++++++++---------
 test/bloblist.c    | 12 +++++-----
 3 files changed, 83 insertions(+), 32 deletions(-)
common/bloblist.c +30 -15
index 784eff61dea..baf1d371b71 100644
@@ -29,24 +29,39 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static const char *const tag_name[] = {
-	[BLOBLISTT_NONE]		= "(none)",
-	[BLOBLISTT_U_BOOT_SPL_HANDOFF]	= "SPL hand-off",
-	[BLOBLISTT_VBOOT_CTX]		= "Chrome OS vboot context",
-	[BLOBLISTT_ACPI_GNVS]		= "ACPI GNVS",
-	[BLOBLISTT_INTEL_VBT]		= "Intel Video-BIOS table",
-	[BLOBLISTT_TPM2_TCG_LOG]	= "TPM v2 log space",
-	[BLOBLISTT_TCPA_LOG]		= "TPM log space",
-	[BLOBLISTT_ACPI_TABLES]		= "ACPI tables for x86",
-	[BLOBLISTT_SMBIOS_TABLES]	= "SMBIOS tables for x86",
+static struct tag_name {
+	enum bloblist_tag_t tag;
+	const char *name;
+} tag_name[] = {
+	{ BLOBLISTT_NONE, "(none)" },
+
+	/* BLOBLISTT_AREA_FIRMWARE_TOP */
+
+	/* BLOBLISTT_AREA_FIRMWARE */
+	{ BLOBLISTT_ACPI_GNVS, "ACPI GNVS" },
+	{ BLOBLISTT_INTEL_VBT, "Intel Video-BIOS table" },
+	{ BLOBLISTT_TPM2_TCG_LOG, "TPM v2 log space" },
+	{ BLOBLISTT_TCPA_LOG, "TPM log space" },
+	{ BLOBLISTT_ACPI_TABLES, "ACPI tables for x86" },
+	{ BLOBLISTT_SMBIOS_TABLES, "SMBIOS tables for x86" },
+	{ BLOBLISTT_VBOOT_CTX, "Chrome OS vboot context" },
+
+	/* BLOBLISTT_PROJECT_AREA */
+	{ BLOBLISTT_U_BOOT_SPL_HANDOFF, "SPL hand-off" },
+
+	/* BLOBLISTT_VENDOR_AREA */
 };
 
 const char *bloblist_tag_name(enum bloblist_tag_t tag)
 {
-	if (tag < 0 || tag >= BLOBLISTT_COUNT)
-		return "invalid";
+	int i;
 
-	return tag_name[tag];
+	for (i = 0; i < ARRAY_SIZE(tag_name); i++) {
+		if (tag_name[i].tag == tag)
+			return tag_name[i].name;
+	}
+
+	return "invalid";
 }
 
 static struct bloblist_rec *bloblist_first_blob(struct bloblist_hdr *hdr)
@@ -381,10 +396,10 @@ void bloblist_show_list(void)
 	struct bloblist_hdr *hdr = gd->bloblist;
 	struct bloblist_rec *rec;
 
-	printf("%-8s  %8s  Tag Name\n", "Address", "Size");
+	printf("%-8s  %8s   Tag Name\n", "Address", "Size");
 	for (rec = bloblist_first_blob(hdr); rec;
 	     rec = bloblist_next_blob(hdr, rec)) {
-		printf("%08lx  %8x  %3d %s\n",
+		printf("%08lx  %8x  %4x %s\n",
 		       (ulong)map_to_sysmem((void *)rec + rec->hdr_size),
 		       rec->size, rec->tag, bloblist_tag_name(rec->tag));
 	}
include/bloblist.h +47 -11

68 lines not on this page · raw message

test/bloblist.c +6 -6
index 2e8e23d77dd..c5788d5cd82 100644
@@ -19,9 +19,9 @@ DECLARE_GLOBAL_DATA_PTR;
 		UNIT_TEST(_name, _flags, bloblist_test)
 
 enum {
-	TEST_TAG		= 1,
-	TEST_TAG2		= 2,
-	TEST_TAG_MISSING	= 3,
+	TEST_TAG		= BLOBLISTT_U_BOOT_SPL_HANDOFF,
+	TEST_TAG2		= BLOBLISTT_VBOOT_CTX,
+	TEST_TAG_MISSING	= 0x10000,
 
 	TEST_SIZE		= 10,
 	TEST_SIZE2		= 20,
@@ -288,10 +288,10 @@ static int bloblist_test_cmd_list(struct unit_test_state *uts)
 	ut_silence_console(uts);
 	console_record_reset();
 	run_command("bloblist list", 0);
-	ut_assert_nextline("Address       Size  Tag Name");
-	ut_assert_nextline("%08lx  %8x    1 SPL hand-off",
+	ut_assert_nextline("Address       Size   Tag Name");
+	ut_assert_nextline("%08lx  %8x  8000 SPL hand-off",
 			   (ulong)map_to_sysmem(data), TEST_SIZE);
-	ut_assert_nextline("%08lx  %8x    2 Chrome OS vboot context",
+	ut_assert_nextline("%08lx  %8x   106 Chrome OS vboot context",
 			   (ulong)map_to_sysmem(data2), TEST_SIZE2);
 	ut_assert_console_end();
 	ut_unsilence_console(uts);
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#11 lore raw

Re: [PATCH v2 06/12] bloblist: Use explicit numbering for the tags

At present if someone adds a tag in the middle of the list it works well enough within a U-Boot build. But if these tags are used in another project, or with an older version of SPL, the numbers make become inconsistent.

Use explicit tag numbers that never change, to resolve this problem. Allocate areas for existing U-Boot tags and set up an area for use by projects and vendors, as well as for private use. Keep tags above 0x10000 unallocated for now.

Update bloblist_tag_name() and the tests to work with this new setup.

---

(no changes since v1)

 common/bloblist.c  | 45 +++++++++++++++++++++++------------
 include/bloblist.h | 58 +++++++++++++++++++++++++++++++++++++---------
 test/bloblist.c    | 12 +++++-----
 3 files changed, 83 insertions(+), 32 deletions(-)

Applied to u-boot-dm, thanks!

#12 lore raw

PATCH v2 7/12 bloblist: Use LOG_CATEGORY to simply logging

In reply to Simon Glass

Use the convenience functions to improve readability.

---

(no changes since v1)

 common/bloblist.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
common/bloblist.c +10 -11
index baf1d371b71..b5fea12b697 100644
@@ -4,6 +4,8 @@
  * Written by Simon Glass <[email protected]>
  */
 
+#define LOG_CATEGORY	LOGC_BLOBLIST
+
 #include <common.h>
 #include <bloblist.h>
 #include <log.h>
@@ -133,9 +135,8 @@ static int bloblist_addrec(uint tag, int size, int align,
 	new_alloced = data_start + ALIGN(size, align);
 
 	if (new_alloced > hdr->size) {
-		log(LOGC_BLOBLIST, LOGL_ERR,
-		    "Failed to allocate %x bytes size=%x, need size=%x\n",
-		    size, hdr->size, new_alloced);
+		log_err("Failed to allocate %x bytes size=%x, need size=%x\n",
+			size, hdr->size, new_alloced);
 		return log_msg_ret("bloblist add", -ENOSPC);
 	}
 	rec = (void *)hdr + hdr->alloced;
@@ -249,14 +250,13 @@ static int bloblist_resize_rec(struct bloblist_hdr *hdr,
 	expand_by = ALIGN(new_size - rec->size, BLOBLIST_ALIGN);
 	new_alloced = ALIGN(hdr->alloced + expand_by, BLOBLIST_ALIGN);
 	if (new_size < 0) {
-		log(LOGC_BLOBLIST, LOGL_DEBUG,
-		    "Attempt to shrink blob size below 0 (%x)\n", new_size);
+		log_debug("Attempt to shrink blob size below 0 (%x)\n",
+			  new_size);
 		return log_msg_ret("size", -EINVAL);
 	}
 	if (new_alloced > hdr->size) {
-		log(LOGC_BLOBLIST, LOGL_ERR,
-		    "Failed to allocate %x bytes size=%x, need size=%x\n",
-		    new_size, hdr->size, new_alloced);
+		log_err("Failed to allocate %x bytes size=%x, need size=%x\n",
+			new_size, hdr->size, new_alloced);
 		return log_msg_ret("alloc", -ENOSPC);
 	}
 
@@ -347,8 +347,7 @@ int bloblist_check(ulong addr, uint size)
 		return log_msg_ret("Bad size", -EFBIG);
 	chksum = bloblist_calc_chksum(hdr);
 	if (hdr->chksum != chksum) {
-		log(LOGC_BLOBLIST, LOGL_ERR, "Checksum %x != %x\n", hdr->chksum,
-		    chksum);
+		log_err("Checksum %x != %x\n", hdr->chksum, chksum);
 		return log_msg_ret("Bad checksum", -EIO);
 	}
 	gd->bloblist = hdr;
@@ -446,7 +445,7 @@ int bloblist_init(void)
 		}
 		ret = bloblist_new(addr, CONFIG_BLOBLIST_SIZE, 0);
 	} else {
-		log(LOGC_BLOBLIST, LOGL_DEBUG, "Found existing bloblist\n");
+		log_debug("Found existing bloblist\n");
 	}
 
 	return ret;
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#13 lore raw

Re: [PATCH v2 07/12] bloblist: Use LOG_CATEGORY to simply logging

Use the convenience functions to improve readability.

---

(no changes since v1)

 common/bloblist.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

Applied to u-boot-dm, thanks!

#14 lore raw

PATCH v2 8/12 bloblist: Use 'phase' consistently for bloblists

In reply to Simon Glass

We typically refer to the different U-Boot builds that a board runs through as phases. This avoids confusion with the word 'stage' which is used with bootstage, for example. Fix up some bloblist Kconfig help which uses the wrong term.

---

(no changes since v1)

 common/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/Kconfig +3 -3
index 0892d9be362..ca136b1ac7f 100644
@@ -717,7 +717,7 @@ config BLOBLIST
 	  from TPL to SPL to U-Boot proper (and potentially to Linux). The
 	  blob list supports multiple binary blobs of data, each with a tag,
 	  so that different U-Boot components can store data which can survive
-	  through to the next stage of the boot.
+	  through to the next phase of the boot.
 
 config SPL_BLOBLIST
 	bool "Support for a bloblist in SPL"
@@ -746,7 +746,7 @@ config BLOBLIST_SIZE
 	  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 stages.
+	  proper), and this sane bloblist is used for subsequent phases.
 
 config BLOBLIST_ALLOC
 	bool "Allocate bloblist"
@@ -760,7 +760,7 @@ config BLOBLIST_ADDR
 	default 0xc000 if SANDBOX
 	help
 	  Sets the address of the bloblist, set up by the first part of U-Boot
-	  which runs. Subsequent U-Boot stages typically use the same address.
+	  which runs. Subsequent U-Boot phases typically use the same address.
 
 	  This is not used if BLOBLIST_ALLOC is selected.
 
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#15 lore raw

Re: [PATCH v2 08/12] bloblist: Use 'phase' consistently for bloblists

We typically refer to the different U-Boot builds that a board runs through as phases. This avoids confusion with the word 'stage' which is used with bootstage, for example. Fix up some bloblist Kconfig help which uses the wrong term.

---

(no changes since v1)

 common/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Applied to u-boot-dm, thanks!

#16 lore raw

PATCH v2 9/12 bloblist: Refactor Kconfig to support alloc or fixed

In reply to Simon Glass

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().

---

Changes in v2:
- Create an accessor for CONFIG_BLOBLIST_ADDR instead of the Kconfig macro

 common/Kconfig     | 91 +++++++++++++++++++++++++++++++++++++++++-----
 common/bloblist.c  | 39 ++++++++++++--------
 include/bloblist.h | 10 +++++
 3 files changed, 116 insertions(+), 24 deletions(-)
common/Kconfig +82 -9
index ca136b1ac7f..82cd864baf9 100644
@@ -738,15 +738,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"
@@ -755,18 +757,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
@@ -775,6 +790,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"
common/bloblist.c +24 -15
index b5fea12b697..0049bb9a395 100644
@@ -4,6 +4,7 @@
  * Written by Simon Glass <[email protected]>
  */
 
+#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 = 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;
include/bloblist.h +10 -0
index 5de4545160e..13f2b3f1009 100644
@@ -147,6 +147,16 @@ struct bloblist_rec {
 	u32 spare;
 };
 
+/* access CONFIG_BLOBLIST_ADDR, dealing with it possibly not being defined */
+static inline ulong bloblist_addr(void)
+{
+#ifdef CONFIG_BLOBLIST_FIXED
+	return CONFIG_BLOBLIST_ADDR;
+#else
+	return 0;
+#endif
+}
+
 /**
  * bloblist_check_magic() - return a bloblist if the magic matches
  *
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#17 lore raw

Re: [PATCH v2 09/12] bloblist: Refactor Kconfig to support alloc or fixed

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().

---

Changes in v2:
- Create an accessor for CONFIG_BLOBLIST_ADDR instead of the Kconfig macro

 common/Kconfig     | 91 +++++++++++++++++++++++++++++++++++++++++-----
 common/bloblist.c  | 39 ++++++++++++--------
 include/bloblist.h | 10 +++++
 3 files changed, 116 insertions(+), 24 deletions(-)

Applied to u-boot-dm, thanks!

#18 lore raw

PATCH v2 10/12 bloblist: Add functions to obtain base address and size

In reply to Simon Glass

Add a few convenience functions to obtain useful information about the bloblist.

---

(no changes since v1)

 common/bloblist.c  | 12 ++++++++++++
 include/bloblist.h | 14 ++++++++++++++
 test/bloblist.c    |  2 ++
 3 files changed, 28 insertions(+)
common/bloblist.c +12 -0
index 0049bb9a395..1ed9172d897 100644
@@ -367,6 +367,18 @@ int bloblist_finish(void)
 	return 0;
 }
 
+ulong bloblist_get_base(void)
+{
+	return map_to_sysmem(gd->bloblist);
+}
+
+ulong bloblist_get_size(void)
+{
+	struct bloblist_hdr *hdr = gd->bloblist;
+
+	return hdr->size;
+}
+
 void bloblist_get_stats(ulong *basep, ulong *sizep, ulong *allocedp)
 {
 	struct bloblist_hdr *hdr = gd->bloblist;
include/bloblist.h +14 -0
index 13f2b3f1009..d9e108d8618 100644
@@ -302,6 +302,20 @@ int bloblist_finish(void);
  */
 void bloblist_get_stats(ulong *basep, ulong *sizep, ulong *allocedp);
 
+/**
+ * bloblist_get_base() - Get the base address of the bloblist
+ *
+ * @returns base address of bloblist
+ */
+ulong bloblist_get_base(void);
+
+/**
+ * bloblist_get_size() - Get the size of the bloblist
+ *
+ * @returns the size in bytes
+ */
+ulong bloblist_get_size(void);
+
 /**
  * bloblist_show_stats() - Show information about the bloblist
  *
test/bloblist.c +2 -0
index c5788d5cd82..720be7e244f 100644
@@ -107,6 +107,8 @@ static int bloblist_test_blob(struct unit_test_state *uts)
 	hdr = clear_bloblist();
 	ut_assertnull(bloblist_find(TEST_TAG, TEST_BLOBLIST_SIZE));
 	ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0));
+	ut_asserteq(TEST_BLOBLIST_SIZE, bloblist_get_size());
+	ut_asserteq(TEST_ADDR, bloblist_get_base());
 	ut_asserteq(map_to_sysmem(hdr), TEST_ADDR);
 
 	/* Add a record and check that we can find it */
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#19 lore raw

Re: [PATCH v2 10/12] bloblist: Add functions to obtain base address and size

Add a few convenience functions to obtain useful information about the bloblist.

---

(no changes since v1)

 common/bloblist.c  | 12 ++++++++++++
 include/bloblist.h | 14 ++++++++++++++
 test/bloblist.c    |  2 ++
 3 files changed, 28 insertions(+)

Applied to u-boot-dm, thanks!

#20 lore raw

PATCH v2 11/12 bloblist: doc: Bring in the API documentation

In reply to Simon Glass

FIx up various minor errors and add the API documentation to the bloblist docs, since it is quite useful to see it in the same place.

---

(no changes since v1)

 doc/develop/bloblist.rst |  8 +++-
 include/bloblist.h       | 79 +++++++++++++++++++++++-----------------
 2 files changed, 52 insertions(+), 35 deletions(-)
doc/develop/bloblist.rst +7 -1
index 47274cf8e26..572aa65d764 100644
@@ -31,7 +31,7 @@ Blobs
 While each blob in the bloblist can be of any length, bloblists are designed to
 hold small amounts of data, typically a few KB at most. It is not possible to
 change the length of a blob once it has been written. Each blob is normally
-created from a C structure which can beused to access its fields.
+created from a C structure which can be used to access its fields.
 
 
 Blob tags
@@ -93,6 +93,12 @@ This should move to using bloblist, to avoid having its own mechanism for
 passing information between U-Boot parts.
 
 
+API documentation
+-----------------
+
+.. kernel-doc:: include/bloblist.h
+
+
 Simon Glass
 [email protected]
 12-Aug-2018
include/bloblist.h +45 -34

196 lines not on this page · raw message

Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#21 lore raw

Re: [PATCH v2 11/12] bloblist: doc: Bring in the API documentation

FIx up various minor errors and add the API documentation to the bloblist docs, since it is quite useful to see it in the same place.

---

(no changes since v1)

 doc/develop/bloblist.rst |  8 +++-
 include/bloblist.h       | 79 +++++++++++++++++++++++-----------------
 2 files changed, 52 insertions(+), 35 deletions(-)

Applied to u-boot-dm, thanks!

#22 lore raw

PATCH v2 12/12 bloblist: Relicense to allow BSD-3-Clause

In reply to Simon Glass

This implementation is intended to be copied to other projects and modified, to as to foster a standard means of communcating runtime information between firmware projects.

The GPL-2 license is too restrictive for some projects, e.g. those intended as reference implementations rather than designed for collaborative open-source development.

Update the license to make this easier to share.

---

(no changes since v1)

 common/bloblist.c  | 2 +-
 include/bloblist.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
common/bloblist.c +1 -1
index 1ed9172d897..056b50c2cb6 100644
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
+// SPDX-License-Identifier: GPL-2.0+ BSD-3-Clause
 /*
  * Copyright 2018 Google, Inc
  * Written by Simon Glass <[email protected]>
include/bloblist.h +1 -1
index 798babe9235..173129b0273 100644
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
+/* SPDX-License-Identifier: GPL-2.0+ BSD-3-Clause */
 /*
  * This provides a standard way of passing information between boot phases
  * (TPL -> SPL -> U-Boot proper.)
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#23 lore raw

Re: [PATCH v2 12/12] bloblist: Relicense to allow BSD-3-Clause

This implementation is intended to be copied to other projects and modified, to as to foster a standard means of communcating runtime information between firmware projects.

The GPL-2 license is too restrictive for some projects, e.g. those intended as reference implementations rather than designed for collaborative open-source development.

Update the license to make this easier to share.

---

(no changes since v1)

 common/bloblist.c  | 2 +-
 include/bloblist.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!