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>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/85462
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Julius Werner 2024-12-03 12:43:11 -08:00
commit bcced7caea

View file

@ -935,12 +935,11 @@ void dt_flatten(const struct device_tree *tree, void *start_dest)
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);