mirror of
https://github.com/ipxe/ipxe
synced 2025-12-11 22:11:08 +03:00
[fdt] Provide fdt_strings() to read string list properties
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -402,6 +402,46 @@ static int fdt_property ( struct fdt *fdt, unsigned int offset,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find strings property
|
||||||
|
*
|
||||||
|
* @v fdt Device tree
|
||||||
|
* @v offset Starting node offset
|
||||||
|
* @v name Property name
|
||||||
|
* @v count String count to fill in
|
||||||
|
* @ret string String property, or NULL on error
|
||||||
|
*/
|
||||||
|
const char * fdt_strings ( struct fdt *fdt, unsigned int offset,
|
||||||
|
const char *name, unsigned int *count ) {
|
||||||
|
struct fdt_descriptor desc;
|
||||||
|
const char *data;
|
||||||
|
size_t len;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Return a zero count on error */
|
||||||
|
*count = 0;
|
||||||
|
|
||||||
|
/* Find property */
|
||||||
|
if ( ( rc = fdt_property ( fdt, offset, name, &desc ) ) != 0 )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* Check NUL termination */
|
||||||
|
data = desc.data;
|
||||||
|
if ( desc.len && ( data[ desc.len - 1 ] != '\0' ) ) {
|
||||||
|
DBGC ( fdt, "FDT unterminated string property \"%s\"\n",
|
||||||
|
name );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Count number of strings */
|
||||||
|
for ( len = desc.len ; len-- ; ) {
|
||||||
|
if ( data[len] == '\0' )
|
||||||
|
(*count)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find string property
|
* Find string property
|
||||||
*
|
*
|
||||||
@@ -412,21 +452,10 @@ static int fdt_property ( struct fdt *fdt, unsigned int offset,
|
|||||||
*/
|
*/
|
||||||
const char * fdt_string ( struct fdt *fdt, unsigned int offset,
|
const char * fdt_string ( struct fdt *fdt, unsigned int offset,
|
||||||
const char *name ) {
|
const char *name ) {
|
||||||
struct fdt_descriptor desc;
|
unsigned int count;
|
||||||
int rc;
|
|
||||||
|
|
||||||
/* Find property */
|
/* Find strings property */
|
||||||
if ( ( rc = fdt_property ( fdt, offset, name, &desc ) ) != 0 )
|
return fdt_strings ( fdt, offset, name, &count );
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* Check NUL termination */
|
|
||||||
if ( strnlen ( desc.data, desc.len ) == desc.len ) {
|
|
||||||
DBGC ( fdt, "FDT unterminated string property \"%s\"\n",
|
|
||||||
name );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return desc.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ extern int fdt_path ( struct fdt *fdt, const char *path,
|
|||||||
unsigned int *offset );
|
unsigned int *offset );
|
||||||
extern int fdt_alias ( struct fdt *fdt, const char *name,
|
extern int fdt_alias ( struct fdt *fdt, const char *name,
|
||||||
unsigned int *offset );
|
unsigned int *offset );
|
||||||
|
extern const char * fdt_strings ( struct fdt *fdt, unsigned int offset,
|
||||||
|
const char *name, unsigned int *count );
|
||||||
extern const char * fdt_string ( struct fdt *fdt, unsigned int offset,
|
extern const char * fdt_string ( struct fdt *fdt, unsigned int offset,
|
||||||
const char *name );
|
const char *name );
|
||||||
extern int fdt_u64 ( struct fdt *fdt, unsigned int offset, const char *name,
|
extern int fdt_u64 ( struct fdt *fdt, unsigned int offset, const char *name,
|
||||||
|
|||||||
Reference in New Issue
Block a user