[fdt] Add ability to parse unsigned integer properties

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2024-10-28 13:45:51 +00:00
parent cc45ca372c
commit 74710b8316
2 changed files with 39 additions and 0 deletions

View File

@ -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
*

View File

@ -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 );