]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[fdt] Provide fdt_strings() to read string list properties
authorMichael Brown <mcb30@ipxe.org>
Mon, 14 Apr 2025 10:32:17 +0000 (11:32 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 14 Apr 2025 10:32:17 +0000 (11:32 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/fdt.c
src/include/ipxe/fdt.h

index 199a53497e7118d1b9954d9d6227e0270255390b..2ca41bc08d928c9df79975ddc72424d93e4b65ab 100644 (file)
@@ -403,30 +403,59 @@ static int fdt_property ( struct fdt *fdt, unsigned int offset,
 }
 
 /**
- * Find string property
+ * 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_string ( struct fdt *fdt, unsigned int offset,
-                         const char *name ) {
+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 */
-       if ( strnlen ( desc.data, desc.len ) == desc.len ) {
+       data = desc.data;
+       if ( desc.len && ( data[ desc.len - 1 ] != '\0' ) ) {
                DBGC ( fdt, "FDT unterminated string property \"%s\"\n",
                       name );
                return NULL;
        }
 
-       return desc.data;
+       /* Count number of strings */
+       for ( len = desc.len ; len-- ; ) {
+               if ( data[len] == '\0' )
+                       (*count)++;
+       }
+
+       return data;
+}
+
+/**
+ * Find string property
+ *
+ * @v fdt              Device tree
+ * @v offset           Starting node offset
+ * @v name             Property name
+ * @ret string         String property, or NULL on error
+ */
+const char * fdt_string ( struct fdt *fdt, unsigned int offset,
+                         const char *name ) {
+       unsigned int count;
+
+       /* Find strings property */
+       return fdt_strings ( fdt, offset, name, &count );
 }
 
 /**
index 7eec5cd8850742c4ed1bcd04a9f4e4487fa09d2e..1e05c9e2d269b71e0ea2f26745958a9d34d4f6c1 100644 (file)
@@ -115,6 +115,8 @@ extern int fdt_path ( struct fdt *fdt, const char *path,
                      unsigned int *offset );
 extern int fdt_alias ( struct fdt *fdt, const char *name,
                       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,
                                 const char *name );
 extern int fdt_u64 ( struct fdt *fdt, unsigned int offset, const char *name,