From 74710b8316b40c9e3081c1014813867d4764796b Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 28 Oct 2024 13:45:51 +0000 Subject: [PATCH] [fdt] Add ability to parse unsigned integer properties Signed-off-by: Michael Brown --- src/core/fdt.c | 38 ++++++++++++++++++++++++++++++++++++++ src/include/ipxe/fdt.h | 1 + 2 files changed, 39 insertions(+) diff --git a/src/core/fdt.c b/src/core/fdt.c index f439422cf..b7289fd36 100644 --- a/src/core/fdt.c +++ b/src/core/fdt.c @@ -367,6 +367,44 @@ const char * fdt_string ( unsigned int offset, const char *name ) { return desc.data; } +/** + * Find integer property + * + * @v offset Starting node offset + * @v name Property name + * @v value Integer value to fill in + * @ret rc Return status code + */ +int fdt_u64 ( unsigned int offset, const char *name, uint64_t *value ) { + struct fdt_descriptor desc; + const uint8_t *data; + size_t remaining; + int rc; + + /* Clear value */ + *value = 0; + + /* Find property */ + if ( ( rc = fdt_property ( offset, name, &desc ) ) != 0 ) + return rc; + + /* Check range */ + if ( desc.len > sizeof ( *value ) ) { + DBGC ( &fdt, "FDT oversized integer property \"%s\"\n", name ); + return -ERANGE; + } + + /* Parse value */ + data = desc.data; + remaining = desc.len; + while ( remaining-- ) { + *value <<= 8; + *value |= *(data++); + } + + return 0; +} + /** * Get MAC address from property * diff --git a/src/include/ipxe/fdt.h b/src/include/ipxe/fdt.h index 97efa100c..9b9b01b6c 100644 --- a/src/include/ipxe/fdt.h +++ b/src/include/ipxe/fdt.h @@ -96,6 +96,7 @@ struct fdt { extern int fdt_path ( const char *path, unsigned int *offset ); extern int fdt_alias ( const char *name, unsigned int *offset ); extern const char * fdt_string ( unsigned int offset, const char *name ); +extern int fdt_u64 ( unsigned int offset, const char *name, uint64_t *value ); extern int fdt_mac ( unsigned int offset, struct net_device *netdev ); extern int register_fdt ( const struct fdt_header *hdr );