commonlib/device_tree.c: Add a function that reads FDT ints

Follow the recommendation at
https://review.coreboot.org/c/coreboot/+/84796/comment/21f615a2_99a41147/
and implement support for reading integer properties generically, using
their size to determine how much to read. This will be used for reading
`load`, `entry` and perhaps others.

Change-Id: I02d27eb5e23dfbfc1404d209ee8d60968e22bb80
Signed-off-by: Benjamin Doron <benjamin.doron@9elements.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/85643
Reviewed-by: Maximilian Brune <maximilian.brune@9elements.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Benjamin Doron 2024-12-17 15:46:14 -05:00 committed by Matt DeVillier
commit b66b7f7860
2 changed files with 22 additions and 0 deletions

View file

@ -259,6 +259,26 @@ static u32 fdt_read_cell_props(const void *blob, u32 node_offset, u32 *addrcp, u
return offset;
}
uint64_t fdt_read_int_prop(struct fdt_property *prop, u32 cells)
{
if (cells == 0)
cells = prop->size / 4;
if (cells * 4 != prop->size) {
printk(BIOS_ERR, "FDT integer property of size %u @%p doesn't match expected cell count %u\n",
prop->size, prop->data, cells);
return 0;
}
if (cells == 2)
return be64dec(prop->data);
else if (cells == 1)
return be32dec(prop->data);
printk(BIOS_ERR, "Illegal FDT integer property size %u @%p\n", prop->size, prop);
return 0;
}
/*
* fdt_find_node searches for a node relative to another node
*