From e748e4b780057872b4a7192db87476adaa8b501c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:06:59 -0800 Subject: bloblist: Update the tag numbering Align bloblist tags with the FW handoff spec v0.9. The most common ones are from 0. TF related ones are from 0x100. All non-standard ones from 0xfff000. Added new defined tags: BLOBLISTT_OPTEE_PAGABLE_PART for TF. BLOBLISTT_TPM_EVLOG and BLOBLISTT_TPM_CRB_BASE for TPM. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao Reviewed-by: Ilias Apalodimas --- include/bloblist.h | 67 +++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 31 deletions(-) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index 080cc46a126..92dbfda21b4 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -81,7 +81,7 @@ enum { /* Supported tags - add new ones to tag_name in bloblist.c */ enum bloblist_tag_t { - BLOBLISTT_NONE = 0, + BLOBLISTT_VOID = 0, /* * Standard area to allocate blobs used across firmware components, for @@ -89,42 +89,36 @@ enum bloblist_tag_t { * projects. */ BLOBLISTT_AREA_FIRMWARE_TOP = 0x1, + /* + * Devicetree for use by firmware. On some platforms this is passed to + * the OS also + */ + BLOBLISTT_CONTROL_FDT = 1, + BLOBLISTT_HOB_BLOCK = 2, + BLOBLISTT_HOB_LIST = 3, + BLOBLISTT_ACPI_TABLES = 4, + BLOBLISTT_TPM_EVLOG = 5, + BLOBLISTT_TPM_CRB_BASE = 6, /* Standard area to allocate blobs used across firmware components */ - BLOBLISTT_AREA_FIRMWARE = 0x100, + BLOBLISTT_AREA_FIRMWARE = 0x10, + BLOBLISTT_TPM2_TCG_LOG = 0x10, /* TPM v2 log space */ + BLOBLISTT_TCPA_LOG = 0x11, /* TPM log space */ /* * Advanced Configuration and Power Interface Global Non-Volatile * Sleeping table. This forms part of the ACPI tables passed to Linux. */ - BLOBLISTT_ACPI_GNVS = 0x100, - BLOBLISTT_INTEL_VBT = 0x101, /* Intel Video-BIOS table */ - BLOBLISTT_TPM2_TCG_LOG = 0x102, /* TPM v2 log space */ - BLOBLISTT_TCPA_LOG = 0x103, /* TPM log space */ - BLOBLISTT_ACPI_TABLES = 0x104, /* ACPI tables for x86 */ - BLOBLISTT_SMBIOS_TABLES = 0x105, /* SMBIOS tables for x86 */ - BLOBLISTT_VBOOT_CTX = 0x106, /* Chromium OS verified boot context */ + BLOBLISTT_ACPI_GNVS = 0x12, - /* - * Project-specific tags are permitted here. Projects can be open source - * or not, but the format of the data must be fuily documented in an - * open source project, including all fields, bits, etc. Naming should - * be: BLOBLISTT__ - */ - BLOBLISTT_PROJECT_AREA = 0x8000, - BLOBLISTT_U_BOOT_SPL_HANDOFF = 0x8000, /* Hand-off info from SPL */ - BLOBLISTT_VBE = 0x8001, /* VBE per-phase state */ - BLOBLISTT_U_BOOT_VIDEO = 0x8002, /* Video information from SPL */ - - /* - * Vendor-specific tags are permitted here. Projects can be open source - * or not, but the format of the data must be fuily documented in an - * open source project, including all fields, bits, etc. Naming should - * be BLOBLISTT__ - */ - BLOBLISTT_VENDOR_AREA = 0xc000, + /* Standard area to allocate blobs used for Trusted Firmware */ + BLOBLISTT_AREA_TF = 0x100, + BLOBLISTT_OPTEE_PAGABLE_PART = 0x100, - /* Tags after this are not allocated for now */ - BLOBLISTT_EXPANSION = 0x10000, + /* Other standard area to allocate blobs */ + BLOBLISTT_AREA_OTHER = 0x200, + BLOBLISTT_INTEL_VBT = 0x200, /* Intel Video-BIOS table */ + BLOBLISTT_SMBIOS_TABLES = 0x201, /* SMBIOS tables for x86 */ + BLOBLISTT_VBOOT_CTX = 0x202, /* Chromium OS verified boot context */ /* * Tags from here are on reserved for private use within a single @@ -133,9 +127,20 @@ enum bloblist_tag_t { * implementation, but cannot be used in upstream code. Allocate a * tag in one of the areas above if you want that. * - * This area may move in future. + * Project-specific tags are permitted here. Projects can be open source + * or not, but the format of the data must be fuily documented in an + * open source project, including all fields, bits, etc. Naming should + * be: BLOBLISTT__ + * + * Vendor-specific tags are also permitted. Projects can be open source + * or not, but the format of the data must be fuily documented in an + * open source project, including all fields, bits, etc. Naming should + * be BLOBLISTT__ */ - BLOBLISTT_PRIVATE_AREA = 0xffff0000, + BLOBLISTT_PRIVATE_AREA = 0xfff000, + BLOBLISTT_U_BOOT_SPL_HANDOFF = 0xfff000, /* Hand-off info from SPL */ + BLOBLISTT_VBE = 0xfff001, /* VBE per-phase state */ + BLOBLISTT_U_BOOT_VIDEO = 0xfff002, /* Video info from SPL */ }; /** -- cgit v1.2.3 From 1a2e02f955f98395142415d7c6cc14e4df903969 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:00 -0800 Subject: bloblist: Adjust API to align in powers of 2 The updated bloblist structure stores the alignment as a power-of-two value in its structures. Adjust the API to use this, to avoid needing to calling ilog2(). Update the bloblist alignment from 16 bytes to 8 bytes. Drop a stale comment while we are here. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- include/bloblist.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index 92dbfda21b4..5ad1337d1fb 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -76,7 +76,9 @@ enum { BLOBLIST_VERSION = 0, BLOBLIST_MAGIC = 0xb00757a3, - BLOBLIST_ALIGN = 16, + + BLOBLIST_ALIGN_LOG2 = 3, + BLOBLIST_ALIGN = 1 << BLOBLIST_ALIGN_LOG2, }; /* Supported tags - add new ones to tag_name in bloblist.c */ @@ -254,11 +256,11 @@ void *bloblist_find(uint tag, int size); * * @tag: Tag to add (enum bloblist_tag_t) * @size: Size of the blob - * @align: Alignment of the blob (in bytes), 0 for default + * @align_log2: Alignment of the blob (in bytes log2), 0 for default * Return: pointer to the newly added block, or NULL if there is not enough * space for the blob */ -void *bloblist_add(uint tag, int size, int align); +void *bloblist_add(uint tag, int size, int align_log2); /** * bloblist_ensure_size() - Find or add a blob @@ -268,11 +270,11 @@ void *bloblist_add(uint tag, int size, int align); * @tag: Tag to add (enum bloblist_tag_t) * @size: Size of the blob * @blobp: Returns a pointer to blob on success - * @align: Alignment of the blob (in bytes), 0 for default + * @align_log2: Alignment of the blob (in bytes log2), 0 for default * Return: 0 if OK, -ENOSPC if it is missing and could not be added due to lack * of space, or -ESPIPE it exists but has the wrong size */ -int bloblist_ensure_size(uint tag, int size, int align, void **blobp); +int bloblist_ensure_size(uint tag, int size, int align_log2, void **blobp); /** * bloblist_ensure() - Find or add a blob -- cgit v1.2.3 From 5a53e56011f11d2abbc23217a979c5b42274056c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:01 -0800 Subject: bloblist: Change the magic value This uses a new value with spec v0.9 so change it. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao Reviewed-by: Ilias Apalodimas Reviewed-by: Simon Glass --- include/bloblist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index 5ad1337d1fb..72c785411d0 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -75,7 +75,7 @@ enum { BLOBLIST_VERSION = 0, - BLOBLIST_MAGIC = 0xb00757a3, + BLOBLIST_MAGIC = 0x4a0fb10b, BLOBLIST_ALIGN_LOG2 = 3, BLOBLIST_ALIGN = 1 << BLOBLIST_ALIGN_LOG2, -- cgit v1.2.3 From 0b9f77f140483569e2ed4622704ef23fef527df8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:02 -0800 Subject: bloblist: Set version to 1 The new bloblist for v0.9 has version 1 so update this value. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao Reviewed-by: Ilias Apalodimas Reviewed-by: Simon Glass --- include/bloblist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index 72c785411d0..7eff709ec8d 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -74,7 +74,7 @@ #include enum { - BLOBLIST_VERSION = 0, + BLOBLIST_VERSION = 1, BLOBLIST_MAGIC = 0x4a0fb10b, BLOBLIST_ALIGN_LOG2 = 3, -- cgit v1.2.3 From 47e1047b0cc25269124737696971ab0c3187666d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:04 -0800 Subject: bloblist: Drop spare value from bloblist record Drop spare value from bloblist record header. For now it is still present in the header, with an underscore, so that tests continue to pass. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao --- include/bloblist.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index 7eff709ec8d..68f97395b78 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -205,13 +205,12 @@ struct bloblist_hdr { * record's data starts at this offset from the start of the record * @size: Size of record in bytes, excluding the header size. This does not * need to be aligned (e.g. 3 is OK). - * @spare: Spare space for other things */ struct bloblist_rec { u32 tag; u32 hdr_size; u32 size; - u32 spare; + u32 _spare; }; /** -- cgit v1.2.3 From 997dac6edebe5b82f4d6f9b90753f0af6e9d04f0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:05 -0800 Subject: bloblist: Checksum the entire bloblist Use a sinple 8-bit checksum for bloblist, as specified by the spec version 0.9. Spec v0.9 specifies that the entire bloblist area is checksummed, including unused portions. Update the code to follow this. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao Reviewed-by: Ilias Apalodimas --- include/bloblist.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index 68f97395b78..d2dcad69a1b 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -174,11 +174,10 @@ enum bloblist_tag_t { * sizeof(bloblist_hdr) since we need at least that much space to store a * valid bloblist * @spare: Spare space (for future use) - * @chksum: CRC32 for the entire bloblist allocated area. Since any of the + * @chksum: checksum for the entire bloblist allocated area. Since any of the * blobs can be altered after being created, this checksum is only valid * when the bloblist is finalised before jumping to the next stage of boot. - * Note that chksum is last to make it easier to exclude it from the - * checksum calculation. + * This is the value needed to make all checksummed bytes sum to 0 */ struct bloblist_hdr { u32 magic; -- cgit v1.2.3 From b6e83826ef1f4d04d350e4d2c03e3b28ab1b0ae4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:07 -0800 Subject: bloblist: Reduce blob-header size The v0.9 spec provides for an 8-byte header for each blob, with fewer fields. The blob data start address should be aligned to the alignment specified by the bloblist header. Update the implementation to match this. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao --- include/bloblist.h | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index d2dcad69a1b..7024d7bf9e5 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -24,11 +24,11 @@ * which would add to code size. For Thumb-2 the code size needed in SPL is * approximately 940 bytes (e.g. for chromebook_bob). * - * 5. Bloblist uses 16-byte alignment internally and is designed to start on a - * 16-byte boundary. Its headers are multiples of 16 bytes. This makes it easier - * to deal with data structures which need this level of alignment, such as ACPI - * tables. For use in SPL and TPL the alignment can be relaxed, since it can be - * relocated to an aligned address in U-Boot proper. + * 5. Bloblist uses 8-byte alignment internally and is designed to start on a + * 8-byte boundary. Its headers are 8 bytes long. It is possible to achieve + * larger alignment (e.g. 16 bytes) by adding a dummy header, For use in SPL and + * TPL the alignment can be relaxed, since it can be relocated to an aligned + * address in U-Boot proper. * * 6. Bloblist is designed to be passed to Linux as reserved memory. While linux * doesn't understand the bloblist header, it can be passed the indivdual blobs. @@ -77,6 +77,9 @@ enum { BLOBLIST_VERSION = 1, BLOBLIST_MAGIC = 0x4a0fb10b, + BLOBLIST_BLOB_ALIGN_LOG2 = 3, + BLOBLIST_BLOB_ALIGN = 1 << BLOBLIST_BLOB_ALIGN_LOG2, + BLOBLIST_ALIGN_LOG2 = 3, BLOBLIST_ALIGN = 1 << BLOBLIST_ALIGN_LOG2, }; @@ -199,17 +202,25 @@ struct bloblist_hdr { * * NOTE: Only exported for testing purposes. Do not use this struct. * - * @tag: Tag indicating what the record contains - * @hdr_size: Size of this header, normally sizeof(struct bloblist_rec). The - * record's data starts at this offset from the start of the record + * @tag_and_hdr_size: Tag indicating what the record contains (bottom 24 bits), and + * size of this header (top 8 bits), normally sizeof(struct bloblist_rec). + * The record's data starts at this offset from the start of the record * @size: Size of record in bytes, excluding the header size. This does not * need to be aligned (e.g. 3 is OK). */ struct bloblist_rec { - u32 tag; - u32 hdr_size; + u32 tag_and_hdr_size; u32 size; - u32 _spare; +}; + +enum { + BLOBLISTR_TAG_SHIFT = 0, + BLOBLISTR_TAG_MASK = 0xffffffU << BLOBLISTR_TAG_SHIFT, + BLOBLISTR_HDR_SIZE_SHIFT = 24, + BLOBLISTR_HDR_SIZE_MASK = 0xffU << BLOBLISTR_HDR_SIZE_SHIFT, + + BLOBLIST_HDR_SIZE = sizeof(struct bloblist_hdr), + BLOBLIST_REC_HDR_SIZE = sizeof(struct bloblist_rec), }; /** -- cgit v1.2.3 From b86b2d940caf27aa80b7c657e48770349e15491b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:08 -0800 Subject: bloblist: Adjust the bloblist header The v0.9 spec provides for a 24-byte header. Update the implementation to match this. Rename the fields of the bloblist header to align to the spec. Adds an alignment field into the bloblist header. Update the related bloblist APIs and UT testcases. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao Reviewed-by: Ilias Apalodimas --- include/bloblist.h | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index 7024d7bf9e5..4ec4b3d449e 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -166,32 +166,33 @@ enum bloblist_tag_t { * from the last. * * @magic: BLOBLIST_MAGIC + * @chksum: checksum for the entire bloblist allocated area. Since any of the + * blobs can be altered after being created, this checksum is only valid + * when the bloblist is finalized before jumping to the next stage of boot. + * This is the value needed to make all checksummed bytes sum to 0 * @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) - * @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. - * @alloced: Total size allocated so far for this bloblist. This starts out as + * @align_log2: Power of two of the maximum alignment required by this list + * @used_size: Size allocated so far for this bloblist. This starts out as * sizeof(bloblist_hdr) since we need at least that much space to store a * valid bloblist + * @total_size: The number of total bytes that the bloblist can occupy. + * Any blob producer must check if there is sufficient space before adding + * a record to the bloblist. + * @flags: Space for BLOBLISTF... flags (none yet) * @spare: Spare space (for future use) - * @chksum: checksum for the entire bloblist allocated area. Since any of the - * blobs can be altered after being created, this checksum is only valid - * when the bloblist is finalised before jumping to the next stage of boot. - * This is the value needed to make all checksummed bytes sum to 0 */ struct bloblist_hdr { u32 magic; - u32 version; - u32 hdr_size; + u8 chksum; + u8 version; + u8 hdr_size; + u8 align_log2; + u32 used_size; + u32 total_size; u32 flags; - - u32 size; - u32 alloced; u32 spare; - u32 chksum; }; /** @@ -363,10 +364,10 @@ int bloblist_finish(void); * This returns useful information about the bloblist * * @basep: Returns base address of bloblist - * @sizep: Returns the number of bytes used in the bloblist - * @allocedp: Returns the total space allocated to the bloblist + * @tsizep: Returns the total number of bytes of the bloblist + * @usizep: Returns the number of used bytes of the bloblist */ -void bloblist_get_stats(ulong *basep, ulong *sizep, ulong *allocedp); +void bloblist_get_stats(ulong *basep, ulong *tsizep, ulong *usizep); /** * bloblist_get_base() - Get the base address of the bloblist @@ -382,6 +383,13 @@ ulong bloblist_get_base(void); */ ulong bloblist_get_size(void); +/** + * bloblist_get_total_size() - Get the total size of the bloblist + * + * Return: the size in bytes + */ +ulong bloblist_get_total_size(void); + /** * bloblist_show_stats() - Show information about the bloblist * -- cgit v1.2.3 From 7d790a80b67958b49da591d32662c4b168737012 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:09 -0800 Subject: bloblist: Add alignment to bloblist_new() Allow the alignment to be specified when creating a bloblist. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao Reviewed-by: Ilias Apalodimas --- include/bloblist.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index 4ec4b3d449e..145e5c0242c 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -330,10 +330,11 @@ int bloblist_resize(uint tag, int new_size); * @addr: Address of bloblist * @size: Initial size for bloblist * @flags: Flags to use for bloblist + * @align_log2: Log base 2 of maximum alignment provided by this bloblist * Return: 0 if OK, -EFAULT if addr is not aligned correctly, -ENOSPC is the * area is not large enough */ -int bloblist_new(ulong addr, uint size, uint flags); +int bloblist_new(ulong addr, uint size, uint flags, uint align_log2); /** * bloblist_check() - Check if a bloblist exists -- cgit v1.2.3 From e266d2731145681a55d862360f1b61690b0c6820 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:10 -0800 Subject: bloblist: Update documentation and header comment Align the documentation with the v0.9 spec. Signed-off-by: Simon Glass Signed-off-by: Raymond Mao Reviewed-by: Ilias Apalodimas --- include/bloblist.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/bloblist.h b/include/bloblist.h index 145e5c0242c..84fc9438191 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -66,6 +66,7 @@ * * Copyright 2018 Google, Inc * Written by Simon Glass + * Adjusted July 2023 to match Firmware handoff specification, Release 0.9 */ #ifndef __BLOBLIST_H -- cgit v1.2.3