Marshall Dawson has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/33397
Change subject: util/amdfwtool: Align PSP NVRAM ......................................................................
util/amdfwtool: Align PSP NVRAM
Align the PSP's NVRAM item since it's intended to be updateable in the flash device.
Change-Id: I6b28525624b95b411cc82de0cbe430ea7871149d Signed-off-by: Marshall Dawson marshalldawson3rd@gmail.com --- M util/amdfwtool/amdfwtool.c 1 file changed, 26 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/97/33397/1
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index 51e913c..f2ce34c 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -79,6 +79,7 @@ #define ALIGN(val, by) (((val) + (by) - 1) & ~((by) - 1)) #define TABLE_ALIGNMENT 0x1000U #define BLOB_ALIGNMENT 0x100U +#define ERASE_ALIGNMENT 0x1000U
#define EMBEDDED_FW_SIGNATURE 0x55aa55aa #define PSP_COOKIE 0x50535024 /* 'PSP$' */ @@ -457,6 +458,31 @@ else pspdir->entries[count].addr = 1; count++; + } else if (fw_table[i].type == AMD_FW_PSP_NVRAM) { + if (fw_table[i].filename == NULL) + continue; + /* TODO: Add a way to reserve for NVRAM without + * requiring a filename. This isn't a feature used + * by coreboot systems, so priority is very low. + */ + ctx->current = ALIGN(ctx->current, ERASE_ALIGNMENT); + bytes = copy_blob(BUFF_CURRENT(*ctx), + fw_table[i].filename, BUFF_ROOM(*ctx)); + if (bytes <= 0) { + free(ctx->rom); + exit(1); + } + + pspdir->entries[count].type = fw_table[i].type; + pspdir->entries[count].subprog = fw_table[i].subprog; + pspdir->entries[count].rsvd = 0; + pspdir->entries[count].size = (uint32_t)bytes; + pspdir->entries[count].addr = RUN_CURRENT(*ctx); + + ctx->current = ALIGN(ctx->current + bytes, + BLOB_ALIGNMENT); + ctx->current = ALIGN(ctx->current, ERASE_ALIGNMENT); + count++; } else if (fw_table[i].filename != NULL) { bytes = copy_blob(BUFF_CURRENT(*ctx), fw_table[i].filename, BUFF_ROOM(*ctx));
Martin Roth has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33397 )
Change subject: util/amdfwtool: Align PSP NVRAM ......................................................................
Patch Set 1: Code-Review+2
Martin Roth has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33397 )
Change subject: util/amdfwtool: Align PSP NVRAM ......................................................................
Patch Set 1: Code-Review+1
(1 comment)
https://review.coreboot.org/#/c/33397/1/util/amdfwtool/amdfwtool.c File util/amdfwtool/amdfwtool.c:
https://review.coreboot.org/#/c/33397/1/util/amdfwtool/amdfwtool.c@479 PS1, Line 479: (uint32_t)bytes; Should this be rounded up to fill the entire 4k flash sector?
Kyösti Mälkki has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33397 )
Change subject: util/amdfwtool: Align PSP NVRAM ......................................................................
Patch Set 1:
(2 comments)
https://review.coreboot.org/#/c/33397/1/util/amdfwtool/amdfwtool.c File util/amdfwtool/amdfwtool.c:
https://review.coreboot.org/#/c/33397/1/util/amdfwtool/amdfwtool.c@484 PS1, Line 484: ctx->current = ALIGN(ctx->current, ERASE_ALIGNMENT); Why the intermediate value with BLOB_ALIGNMENT?
https://review.coreboot.org/#/c/33397/1/util/amdfwtool/amdfwtool.c@508 PS1, Line 508: if (count > MAX_PSP_ENTRIES) { Unrelated, but you really should test for invalid indexing of arrays before the access happens.
Hello build bot (Jenkins), Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/33397
to look at the new patch set (#2).
Change subject: util/amdfwtool: Align PSP NVRAM ......................................................................
util/amdfwtool: Align PSP NVRAM
Align the PSP's NVRAM item since it's intended to be updateable in the flash device.
Change-Id: I6b28525624b95b411cc82de0cbe430ea7871149d Signed-off-by: Marshall Dawson marshalldawson3rd@gmail.com --- M util/amdfwtool/amdfwtool.c 1 file changed, 28 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/97/33397/2
Marshall Dawson has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33397 )
Change subject: util/amdfwtool: Align PSP NVRAM ......................................................................
Patch Set 2:
(3 comments)
https://review.coreboot.org/#/c/33397/1/util/amdfwtool/amdfwtool.c File util/amdfwtool/amdfwtool.c:
https://review.coreboot.org/#/c/33397/1/util/amdfwtool/amdfwtool.c@479 PS1, Line 479: (uint32_t)bytes;
Should this be rounded up to fill the entire 4k flash sector?
Yes, done
https://review.coreboot.org/#/c/33397/1/util/amdfwtool/amdfwtool.c@484 PS1, Line 484: ctx->current = ALIGN(ctx->current, ERASE_ALIGNMENT);
Why the intermediate value with BLOB_ALIGNMENT?
I didn't want this code to need to know which was the larger granularity. Will change it to use a max() value instead.
https://review.coreboot.org/#/c/33397/1/util/amdfwtool/amdfwtool.c@508 PS1, Line 508: if (count > MAX_PSP_ENTRIES) {
Unrelated, but you really should test for invalid indexing of arrays before the access happens.
Maybe I'll consider that for a follow-on.
Since the utility allocates the size of the rom, I don't think it's an emergency, and in fact count should never be greater than the number of items in the fw_table. We allocate the amount of memory equal to the flash's size. The intent here was to not write a higher count into the header than the header was meant to describe.
Martin Roth has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/33397 )
Change subject: util/amdfwtool: Align PSP NVRAM ......................................................................
Patch Set 2: Code-Review+2
Martin Roth has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/33397 )
Change subject: util/amdfwtool: Align PSP NVRAM ......................................................................
util/amdfwtool: Align PSP NVRAM
Align the PSP's NVRAM item since it's intended to be updateable in the flash device.
Change-Id: I6b28525624b95b411cc82de0cbe430ea7871149d Signed-off-by: Marshall Dawson marshalldawson3rd@gmail.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/33397 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Martin Roth martinroth@google.com --- M util/amdfwtool/amdfwtool.c 1 file changed, 28 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Martin Roth: Looks good to me, approved
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index a3a692d..4a05dfe 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -77,8 +77,11 @@ #define MIN_ROM_KB 256
#define ALIGN(val, by) (((val) + (by) - 1) & ~((by) - 1)) +#define _MAX(A, B) (((A) > (B)) ? (A) : (B)) +#define ERASE_ALIGNMENT 0x1000U #define TABLE_ALIGNMENT 0x1000U #define BLOB_ALIGNMENT 0x100U +#define BLOB_ERASE_ALIGNMENT _MAX(BLOB_ALIGNMENT, ERASE_ALIGNMENT)
#define DEFAULT_SOFT_FUSE_CHAIN "0x1"
@@ -456,6 +459,31 @@ pspdir->entries[count].size = 0xFFFFFFFF; pspdir->entries[count].addr = fw_table[i].other; count++; + } else if (fw_table[i].type == AMD_FW_PSP_NVRAM) { + if (fw_table[i].filename == NULL) + continue; + /* TODO: Add a way to reserve for NVRAM without + * requiring a filename. This isn't a feature used + * by coreboot systems, so priority is very low. + */ + ctx->current = ALIGN(ctx->current, ERASE_ALIGNMENT); + bytes = copy_blob(BUFF_CURRENT(*ctx), + fw_table[i].filename, BUFF_ROOM(*ctx)); + if (bytes <= 0) { + free(ctx->rom); + exit(1); + } + + pspdir->entries[count].type = fw_table[i].type; + pspdir->entries[count].subprog = fw_table[i].subprog; + pspdir->entries[count].rsvd = 0; + pspdir->entries[count].size = ALIGN(bytes, + ERASE_ALIGNMENT); + pspdir->entries[count].addr = RUN_CURRENT(*ctx); + + ctx->current = ALIGN(ctx->current + bytes, + BLOB_ERASE_ALIGNMENT); + count++; } else if (fw_table[i].filename != NULL) { bytes = copy_blob(BUFF_CURRENT(*ctx), fw_table[i].filename, BUFF_ROOM(*ctx));