Julius Werner has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/85462?usp=email )
Change subject: commonlib/device_tree: Make END token part of struct_size ......................................................................
commonlib/device_tree: Make END token part of struct_size
According to the FDT specification the FDT_END token is supposed to be the last token in the structure block, not a free-floating token immediately outside of it. That means we're supposed to count it in struct_size. It seems that the kernel never cared about this, but some FDT parsing utilities like `fdtgrep` do.
Change-Id: Icdeadbeefcafed00dbabefeed1337c0debc86836 Signed-off-by: Julius Werner jwerner@chromium.org --- M src/commonlib/device_tree.c 1 file changed, 2 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/62/85462/1
diff --git a/src/commonlib/device_tree.c b/src/commonlib/device_tree.c index cb7a596..b2daac9 100644 --- a/src/commonlib/device_tree.c +++ b/src/commonlib/device_tree.c @@ -935,12 +935,11 @@
uint8_t *struct_start = dest; header->structure_offset = htobe32(dest - (uint8_t *)start_dest); + be32enc(&dest[struct_size], FDT_TOKEN_END); + struct_size += sizeof(uint32_t); header->structure_size = htobe32(struct_size); dest += struct_size;
- *((uint32_t *)dest) = htobe32(FDT_TOKEN_END); - dest += sizeof(uint32_t); - uint8_t *strings_start = dest; header->strings_offset = htobe32(dest - (uint8_t *)start_dest); header->strings_size = htobe32(strings_size);