diff --git a/src/dt/dt.h b/src/dt/dt.h index 0ac6bcd..67f5fb7 100644 --- a/src/dt/dt.h +++ b/src/dt/dt.h @@ -193,6 +193,8 @@ extern int of_property_write_u64_array(struct device_node *np, const char *propname, const uint64_t *values, size_t sz); +extern int of_property_write_string(struct device_node *np, + const char *propname, const char *value); extern struct device_node *of_parse_phandle(const struct device_node *np, const char *phandle_name, diff --git a/src/libdt-utils.sym b/src/libdt-utils.sym index ee7f430..2c63d55 100644 --- a/src/libdt-utils.sym +++ b/src/libdt-utils.sym @@ -63,6 +63,7 @@ of_property_read_u64; of_property_read_u8_array; of_property_write_bool; + of_property_write_string; of_property_write_u16_array; of_property_write_u32_array; of_property_write_u64_array; diff --git a/src/libdt.c b/src/libdt.c index 3adeed2..8236a69 100644 --- a/src/libdt.c +++ b/src/libdt.c @@ -1212,6 +1212,28 @@ } /** + * of_property_write_string - Write a string to a property. If + * the property does not exist, it will be created and appended to the given + * device node. + * + * @np: device node to which the property value is to be written. + * @propname: name of the property to be written. + * @value: pointer to the string to write + * + * Search for a property in a device node and write a string to + * it. If the property does not exist, it will be created and appended to + * the device node. Returns 0 on success, -ENOMEM if the property or array + * of elements cannot be created. + */ +int of_property_write_string(struct device_node *np, + const char *propname, const char *value) +{ + size_t len = strlen(value); + + return of_set_property(np, propname, value, len + 1, 1); +} + +/** * of_parse_phandle - Resolve a phandle property to a device_node pointer * @np: Pointer to device node holding phandle property * @phandle_name: Name of property holding a phandle value