* [PATCH 2/4] of: implement of_property_write_strings for multiple strings
2020-09-30 12:53 [PATCH 1/4] include: string: migrate barebox function from <linux/string.h> Ahmad Fatoum
@ 2020-09-30 12:53 ` Ahmad Fatoum
2020-09-30 12:53 ` [PATCH 3/4] ARM: stm32mp: init: set up CPU and bootsource at core init level Ahmad Fatoum
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2020-09-30 12:53 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The current way to set a property with multiple values (e.g. compatible
strings) is to have
char properties[] = "st,stm32mp157c-dk2\0st,stm32mp157";
of_set_property(np, "compatible", properties, sizeof(properties), 1);
Add a new helper to make this easier at the cost of one runtime
reallocation:
of_property_write_strings(np, "compatible,
"st,stm32mp157c-dk2", "st,stm32mp157", NULL);
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/of/base.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++
include/of.h | 2 ++
include/string.h | 1 +
lib/string.c | 13 +++++++++++++
4 files changed, 64 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4e88af7b22e2..f5aad268b2d0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -23,6 +23,7 @@
#include <memory.h>
#include <linux/sizes.h>
#include <of_graph.h>
+#include <string.h>
#include <linux/ctype.h>
#include <linux/amba/bus.h>
#include <linux/err.h>
@@ -1182,6 +1183,53 @@ int of_property_write_u64_array(struct device_node *np,
return 0;
}
+/**
+ * of_property_write_strings - Write strings 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.
+ * @...: pointers to strings 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, -EINVAL if no strings specified.
+ */
+int of_property_write_strings(struct device_node *np,
+ const char *propname, ...)
+{
+ const char *val;
+ char *buf = NULL, *next;
+ size_t len = 0;
+ va_list ap;
+ int ret = 0;
+
+ va_start(ap, propname);
+ for (val = va_arg(ap, char *); val; val = va_arg(ap, char *))
+ len += strlen(val) + 1;
+ va_end(ap);
+
+ if (!len)
+ return -EINVAL;
+
+ buf = malloc(len);
+ if (!buf)
+ return -ENOMEM;
+
+ next = buf;
+
+ va_start(ap, propname);
+ for (val = va_arg(ap, char *); val; val = va_arg(ap, char *))
+ next = stpcpy(next, val) + 1;
+ va_end(ap);
+
+ ret = of_set_property(np, propname, buf, len, 1);
+ free(buf);
+ return ret;
+}
+
/**
* 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
diff --git a/include/of.h b/include/of.h
index fc36f7a21ac9..d5947fbaab56 100644
--- a/include/of.h
+++ b/include/of.h
@@ -231,6 +231,8 @@ extern int of_property_write_u64_array(struct device_node *np,
size_t sz);
extern int of_property_write_string(struct device_node *np, const char *propname,
const char *value);
+extern int of_property_write_strings(struct device_node *np, const char *propname,
+ ...) __attribute__((__sentinel__));
extern struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name,
diff --git a/include/string.h b/include/string.h
index 063e85f62cf8..b51566fd002a 100644
--- a/include/string.h
+++ b/include/string.h
@@ -6,6 +6,7 @@
int strtobool(const char *str, int *val);
char *strsep_unescaped(char **, const char *);
+char *stpcpy(char *dest, const char *src);
void *__default_memset(void *, int, __kernel_size_t);
void *__nokasan_default_memset(void *, int, __kernel_size_t);
diff --git a/lib/string.c b/lib/string.c
index 003070fa53e0..d250e5864313 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -100,6 +100,19 @@ char * strcpy(char * dest,const char *src)
#endif
EXPORT_SYMBOL(strcpy);
+/**
+ * stpcpy - Copy a %NUL terminated string, but return pointer to %NUL
+ * @dest: Where to copy the string to
+ * @src: Where to copy the string from
+ */
+char *stpcpy(char *dest, const char *src)
+{
+ while ((*dest++ = *src++) != '\0')
+ /* nothing */;
+ return dest - 1;
+}
+EXPORT_SYMBOL(stpcpy);
+
#ifndef __HAVE_ARCH_STRNCPY
/**
* strncpy - Copy a length-limited, %NUL-terminated string
--
2.28.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] ARM: stm32mp: dk2: have barebox image support DK1 as well
2020-09-30 12:53 [PATCH 1/4] include: string: migrate barebox function from <linux/string.h> Ahmad Fatoum
2020-09-30 12:53 ` [PATCH 2/4] of: implement of_property_write_strings for multiple strings Ahmad Fatoum
2020-09-30 12:53 ` [PATCH 3/4] ARM: stm32mp: init: set up CPU and bootsource at core init level Ahmad Fatoum
@ 2020-09-30 12:53 ` Ahmad Fatoum
2020-10-01 9:14 ` Ahmad Fatoum
2020-10-02 4:10 ` [PATCH 1/4] include: string: migrate barebox function from <linux/string.h> Sascha Hauer
3 siblings, 1 reply; 6+ messages in thread
From: Ahmad Fatoum @ 2020-09-30 12:53 UTC (permalink / raw)
To: barebox; +Cc: Holger Assmann, Ahmad Fatoum
The STM32MP157C-DK2 and STM32MP157A-DK1 are basically the same board
except the DK2 has a MIPI-DSI display attached and the SoC has a
crypto IP block.
Allow the same barebox image to run on both boards by deciding
that if we are compiled with a 157C-DK2 device tree, but we have
a 157A SoC, it must be a DK1 instead.
Cc: Holger Assmann <h.assmann@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/boards/stm32mp157c-dk2/board.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/arch/arm/boards/stm32mp157c-dk2/board.c b/arch/arm/boards/stm32mp157c-dk2/board.c
index 46366031218d..55afdd49e6e5 100644
--- a/arch/arm/boards/stm32mp157c-dk2/board.c
+++ b/arch/arm/boards/stm32mp157c-dk2/board.c
@@ -2,17 +2,23 @@
#include <common.h>
#include <init.h>
#include <mach/bbu.h>
+#include <mach/revision.h>
+#include <of.h>
-static int dk2_postcore_init(void)
+static int dkx_postcore_init(void)
{
if (!of_machine_is_compatible("st,stm32mp157c-dk2"))
return 0;
- stm32mp_bbu_mmc_register_handler("sd", "/dev/mmc0.ssbl",
- BBU_HANDLER_FLAG_DEFAULT);
+ if (stm32mp_cputype() == CPU_STM32MP157Axx) {
+ of_property_write_strings(of_get_root_node(), "compatible",
+ "st,stm32mp157a-dk1", "st,stm32mp157", NULL);
+ barebox_set_model("STM32MP157A-DK1");
+ } else {
+ barebox_set_model("STM32MP157C-DK2");
+ }
- barebox_set_model("STM32MP157C-DK2");
-
- return 0;
+ return stm32mp_bbu_mmc_register_handler("sd", "/dev/mmc0.ssbl",
+ BBU_HANDLER_FLAG_DEFAULT);
}
-postcore_initcall(dk2_postcore_init);
+postcore_initcall(dkx_postcore_init);
--
2.28.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/4] include: string: migrate barebox function from <linux/string.h>
2020-09-30 12:53 [PATCH 1/4] include: string: migrate barebox function from <linux/string.h> Ahmad Fatoum
` (2 preceding siblings ...)
2020-09-30 12:53 ` [PATCH 4/4] ARM: stm32mp: dk2: have barebox image support DK1 as well Ahmad Fatoum
@ 2020-10-02 4:10 ` Sascha Hauer
3 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2020-10-02 4:10 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Sep 30, 2020 at 02:53:00PM +0200, Ahmad Fatoum wrote:
> <linux/string.h> was imported from Linux. In order to keep changes
> to a minimum, add prototypes for new barebox functions to <string.h>
> instead.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> include/linux/string.h | 1 -
> include/string.h | 1 +
> 2 files changed, 1 insertion(+), 1 deletion(-)
Applied, thanks
Sascha
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 2b699957e824..85c3eb1de340 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -10,7 +10,6 @@ extern "C" {
>
> extern char * strpbrk(const char *,const char *);
> extern char * strsep(char **,const char *);
> -extern char * strsep_unescaped(char **,const char *);
> extern __kernel_size_t strspn(const char *,const char *);
>
>
> diff --git a/include/string.h b/include/string.h
> index 727bc51934bc..063e85f62cf8 100644
> --- a/include/string.h
> +++ b/include/string.h
> @@ -5,6 +5,7 @@
> #include <linux/string.h>
>
> int strtobool(const char *str, int *val);
> +char *strsep_unescaped(char **, const char *);
>
> void *__default_memset(void *, int, __kernel_size_t);
> void *__nokasan_default_memset(void *, int, __kernel_size_t);
> --
> 2.28.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread