* [PATCH 1/2] misc: introduce string_to_bin
@ 2010-08-05 11:23 Baruch Siach
2010-08-05 11:23 ` [PATCH 2/2] setser: new command to set serial number on ARM Baruch Siach
2010-08-05 12:23 ` [PATCH 1/2] misc: introduce string_to_bin Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 2 replies; 9+ messages in thread
From: Baruch Siach @ 2010-08-05 11:23 UTC (permalink / raw)
To: barebox
Factor out string_to_bin from string_to_ethaddr. string_to_bin is useful for
other hex data strings.
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
include/common.h | 1 +
lib/misc.c | 29 +++++++++++++++++++++++++++++
net/net.c | 17 +----------------
3 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/include/common.h b/include/common.h
index 0edc778..f600eb0 100644
--- a/include/common.h
+++ b/include/common.h
@@ -127,6 +127,7 @@ struct memarea_info {
int spec_str_to_info(const char *str, struct memarea_info *info);
int parse_area_spec(const char *str, ulong *start, ulong *size);
+int string_to_bin(const char *str, u8 *buf, unsigned int buflen);
/* Just like simple_strtoul(), but this one honors a K/M/G suffix */
unsigned long strtoul_suffix(const char *str, char **endp, int base);
diff --git a/lib/misc.c b/lib/misc.c
index 549b960..7735725 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -107,3 +107,32 @@ int parse_area_spec(const char *str, ulong *start, ulong *size)
return -1;
}
EXPORT_SYMBOL(parse_area_spec);
+
+/*
+ * This function parses strings in the form "xx:xx:xx...", where x is an
+ * hexadecimal digit.
+ */
+int string_to_bin(const char *str, u8 *buf, unsigned int buflen)
+{
+ int i;
+ char *e;
+
+ if (!str || strlen(str) != buflen*3 - 1)
+ return -1;
+
+ for (i = 0; i < buflen-1; i++)
+ if (str[i*3 + 2] != ':')
+ return -1;
+
+ for (i = 0; str[i]; i++)
+ if (!isxdigit(str[i]) && !(str[i] == ':'))
+ return -1;
+
+ for (i = 0; i < buflen; i++) {
+ buf[i] = simple_strtoul(str, &e, 16);
+ str = e + 1;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(string_to_bin);
diff --git a/net/net.c b/net/net.c
index 8d99595..017de8b 100644
--- a/net/net.c
+++ b/net/net.c
@@ -161,22 +161,7 @@ void print_IPaddr (IPaddr_t x)
int string_to_ethaddr(const char *str, char *enetaddr)
{
- int reg;
- char *e;
-
- if (!str || strlen(str) != 17)
- return -1;
-
- if (str[2] != ':' || str[5] != ':' || str[8] != ':' ||
- str[11] != ':' || str[14] != ':')
- return -1;
-
- for (reg = 0; reg < 6; ++reg) {
- enetaddr[reg] = simple_strtoul (str, &e, 16);
- str = e + 1;
- }
-
- return 0;
+ return string_to_bin(str, enetaddr, 6);
}
void ethaddr_to_string(const unsigned char *enetaddr, char *str)
--
1.7.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] setser: new command to set serial number on ARM
2010-08-05 11:23 [PATCH 1/2] misc: introduce string_to_bin Baruch Siach
@ 2010-08-05 11:23 ` Baruch Siach
2010-08-18 4:49 ` Baruch Siach
2010-08-05 12:23 ` [PATCH 1/2] misc: introduce string_to_bin Jean-Christophe PLAGNIOL-VILLARD
1 sibling, 1 reply; 9+ messages in thread
From: Baruch Siach @ 2010-08-05 11:23 UTC (permalink / raw)
To: barebox
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
commands/Kconfig | 8 ++++++++
commands/Makefile | 1 +
commands/setser.c | 43 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 0 deletions(-)
create mode 100644 commands/setser.c
diff --git a/commands/Kconfig b/commands/Kconfig
index 1ffc826..9d11a8b 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -231,6 +231,14 @@ config CMD_BOOTU
compile in the 'bootu' command to start raw (uncompressed)
Linux images
+config CMD_SETSER
+ tristate
+ depends on ARM
+ prompt "setser"
+ help
+ compile in the 'setser' command to set the 64bit serial number to be
+ passed to the Linux kernel upon boot
+
config CMD_LINUX16
tristate
default y if X86
diff --git a/commands/Makefile b/commands/Makefile
index b99f042..276af85 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -1,4 +1,5 @@
obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_CMD_SETSER) += setser.o
obj-$(CONFIG_CMD_LINUX16) += linux16.o
obj-$(CONFIG_CMD_LOADB) += loadb.o xyzModem.o
obj-$(CONFIG_CMD_LOADY) += loadb.o xyzModem.o
diff --git a/commands/setser.c b/commands/setser.c
new file mode 100644
index 0000000..ef4fb0a
--- /dev/null
+++ b/commands/setser.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010 Baruch Siach <baruch@tkos.co.il>,
+ * Orex Computed Radiography
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <common.h>
+#include <command.h>
+#include <asm/armlinux.h>
+#include <asm/byteorder.h>
+
+static int do_setser(struct command *cmdtp, int argc, char *argv[])
+{
+ int ret;
+ u8 buf[8];
+
+ if (argc != 2)
+ return COMMAND_ERROR_USAGE;
+
+ ret = string_to_bin(argv[1], buf, 8);
+ if (ret < 0)
+ return COMMAND_ERROR_USAGE;
+
+ armlinux_set_serial(be64_to_cpup((u64 *)buf));
+
+ return 0;
+}
+
+static const __maybe_unused char cmd_setser_help[] =
+"Usage: setser xx:xx:xx:xx:xx:xx:xx:xx\n"
+"Set 64bit serial number to pass to the Linux kernel\n";
+
+BAREBOX_CMD_START(setser)
+ .cmd = do_setser,
+ .usage = "set serial number",
+ BAREBOX_CMD_HELP(cmd_setser_help)
+BAREBOX_CMD_END
--
1.7.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] setser: new command to set serial number on ARM
2010-08-05 11:23 ` [PATCH 2/2] setser: new command to set serial number on ARM Baruch Siach
@ 2010-08-18 4:49 ` Baruch Siach
0 siblings, 0 replies; 9+ messages in thread
From: Baruch Siach @ 2010-08-18 4:49 UTC (permalink / raw)
To: barebox
Hi Barebox list,
Ping?
Should I implement this as a character device? :-)
baruch
On Thu, Aug 05, 2010 at 02:23:18PM +0300, Baruch Siach wrote:
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
> commands/Kconfig | 8 ++++++++
> commands/Makefile | 1 +
> commands/setser.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 52 insertions(+), 0 deletions(-)
> create mode 100644 commands/setser.c
>
> diff --git a/commands/Kconfig b/commands/Kconfig
> index 1ffc826..9d11a8b 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -231,6 +231,14 @@ config CMD_BOOTU
> compile in the 'bootu' command to start raw (uncompressed)
> Linux images
>
> +config CMD_SETSER
> + tristate
> + depends on ARM
> + prompt "setser"
> + help
> + compile in the 'setser' command to set the 64bit serial number to be
> + passed to the Linux kernel upon boot
> +
> config CMD_LINUX16
> tristate
> default y if X86
> diff --git a/commands/Makefile b/commands/Makefile
> index b99f042..276af85 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -1,4 +1,5 @@
> obj-$(CONFIG_CMD_BOOTM) += bootm.o
> +obj-$(CONFIG_CMD_SETSER) += setser.o
> obj-$(CONFIG_CMD_LINUX16) += linux16.o
> obj-$(CONFIG_CMD_LOADB) += loadb.o xyzModem.o
> obj-$(CONFIG_CMD_LOADY) += loadb.o xyzModem.o
> diff --git a/commands/setser.c b/commands/setser.c
> new file mode 100644
> index 0000000..ef4fb0a
> --- /dev/null
> +++ b/commands/setser.c
> @@ -0,0 +1,43 @@
> +/*
> + * Copyright (c) 2010 Baruch Siach <baruch@tkos.co.il>,
> + * Orex Computed Radiography
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * http://www.opensource.org/licenses/gpl-license.html
> + * http://www.gnu.org/copyleft/gpl.html
> + */
> +
> +#include <common.h>
> +#include <command.h>
> +#include <asm/armlinux.h>
> +#include <asm/byteorder.h>
> +
> +static int do_setser(struct command *cmdtp, int argc, char *argv[])
> +{
> + int ret;
> + u8 buf[8];
> +
> + if (argc != 2)
> + return COMMAND_ERROR_USAGE;
> +
> + ret = string_to_bin(argv[1], buf, 8);
> + if (ret < 0)
> + return COMMAND_ERROR_USAGE;
> +
> + armlinux_set_serial(be64_to_cpup((u64 *)buf));
> +
> + return 0;
> +}
> +
> +static const __maybe_unused char cmd_setser_help[] =
> +"Usage: setser xx:xx:xx:xx:xx:xx:xx:xx\n"
> +"Set 64bit serial number to pass to the Linux kernel\n";
> +
> +BAREBOX_CMD_START(setser)
> + .cmd = do_setser,
> + .usage = "set serial number",
> + BAREBOX_CMD_HELP(cmd_setser_help)
> +BAREBOX_CMD_END
> --
> 1.7.1
>
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] misc: introduce string_to_bin
2010-08-05 11:23 [PATCH 1/2] misc: introduce string_to_bin Baruch Siach
2010-08-05 11:23 ` [PATCH 2/2] setser: new command to set serial number on ARM Baruch Siach
@ 2010-08-05 12:23 ` Jean-Christophe PLAGNIOL-VILLARD
2010-08-05 12:43 ` Baruch Siach
1 sibling, 1 reply; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-08-05 12:23 UTC (permalink / raw)
To: Baruch Siach; +Cc: barebox
Hi,
how about use the kernel printf format instead
Best Regards,
J.
On 14:23 Thu 05 Aug , Baruch Siach wrote:
> Factor out string_to_bin from string_to_ethaddr. string_to_bin is useful for
> other hex data strings.
>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
> include/common.h | 1 +
> lib/misc.c | 29 +++++++++++++++++++++++++++++
> net/net.c | 17 +----------------
> 3 files changed, 31 insertions(+), 16 deletions(-)
>
> diff --git a/include/common.h b/include/common.h
> index 0edc778..f600eb0 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -127,6 +127,7 @@ struct memarea_info {
>
> int spec_str_to_info(const char *str, struct memarea_info *info);
> int parse_area_spec(const char *str, ulong *start, ulong *size);
> +int string_to_bin(const char *str, u8 *buf, unsigned int buflen);
>
> /* Just like simple_strtoul(), but this one honors a K/M/G suffix */
> unsigned long strtoul_suffix(const char *str, char **endp, int base);
> diff --git a/lib/misc.c b/lib/misc.c
> index 549b960..7735725 100644
> --- a/lib/misc.c
> +++ b/lib/misc.c
> @@ -107,3 +107,32 @@ int parse_area_spec(const char *str, ulong *start, ulong *size)
> return -1;
> }
> EXPORT_SYMBOL(parse_area_spec);
> +
> +/*
> + * This function parses strings in the form "xx:xx:xx...", where x is an
> + * hexadecimal digit.
> + */
> +int string_to_bin(const char *str, u8 *buf, unsigned int buflen)
> +{
> + int i;
> + char *e;
> +
> + if (!str || strlen(str) != buflen*3 - 1)
> + return -1;
> +
> + for (i = 0; i < buflen-1; i++)
> + if (str[i*3 + 2] != ':')
> + return -1;
> +
> + for (i = 0; str[i]; i++)
> + if (!isxdigit(str[i]) && !(str[i] == ':'))
> + return -1;
> +
> + for (i = 0; i < buflen; i++) {
> + buf[i] = simple_strtoul(str, &e, 16);
> + str = e + 1;
> + }
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(string_to_bin);
> diff --git a/net/net.c b/net/net.c
> index 8d99595..017de8b 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -161,22 +161,7 @@ void print_IPaddr (IPaddr_t x)
>
> int string_to_ethaddr(const char *str, char *enetaddr)
> {
> - int reg;
> - char *e;
> -
> - if (!str || strlen(str) != 17)
> - return -1;
> -
> - if (str[2] != ':' || str[5] != ':' || str[8] != ':' ||
> - str[11] != ':' || str[14] != ':')
> - return -1;
> -
> - for (reg = 0; reg < 6; ++reg) {
> - enetaddr[reg] = simple_strtoul (str, &e, 16);
> - str = e + 1;
> - }
> -
> - return 0;
> + return string_to_bin(str, enetaddr, 6);
> }
>
> void ethaddr_to_string(const unsigned char *enetaddr, char *str)
> --
> 1.7.1
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] misc: introduce string_to_bin
2010-08-05 12:23 ` [PATCH 1/2] misc: introduce string_to_bin Jean-Christophe PLAGNIOL-VILLARD
@ 2010-08-05 12:43 ` Baruch Siach
2010-08-05 13:41 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 9+ messages in thread
From: Baruch Siach @ 2010-08-05 12:43 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
Hi Jean-Christophe,
On Thu, Aug 05, 2010 at 02:23:49PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> how about use the kernel printf format instead
How can I use printf to convert a string representation to binary?
baruch
> On 14:23 Thu 05 Aug , Baruch Siach wrote:
> > Factor out string_to_bin from string_to_ethaddr. string_to_bin is useful for
> > other hex data strings.
> >
> > Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> > ---
> > include/common.h | 1 +
> > lib/misc.c | 29 +++++++++++++++++++++++++++++
> > net/net.c | 17 +----------------
> > 3 files changed, 31 insertions(+), 16 deletions(-)
> >
> > diff --git a/include/common.h b/include/common.h
> > index 0edc778..f600eb0 100644
> > --- a/include/common.h
> > +++ b/include/common.h
> > @@ -127,6 +127,7 @@ struct memarea_info {
> >
> > int spec_str_to_info(const char *str, struct memarea_info *info);
> > int parse_area_spec(const char *str, ulong *start, ulong *size);
> > +int string_to_bin(const char *str, u8 *buf, unsigned int buflen);
> >
> > /* Just like simple_strtoul(), but this one honors a K/M/G suffix */
> > unsigned long strtoul_suffix(const char *str, char **endp, int base);
> > diff --git a/lib/misc.c b/lib/misc.c
> > index 549b960..7735725 100644
> > --- a/lib/misc.c
> > +++ b/lib/misc.c
> > @@ -107,3 +107,32 @@ int parse_area_spec(const char *str, ulong *start, ulong *size)
> > return -1;
> > }
> > EXPORT_SYMBOL(parse_area_spec);
> > +
> > +/*
> > + * This function parses strings in the form "xx:xx:xx...", where x is an
> > + * hexadecimal digit.
> > + */
> > +int string_to_bin(const char *str, u8 *buf, unsigned int buflen)
> > +{
> > + int i;
> > + char *e;
> > +
> > + if (!str || strlen(str) != buflen*3 - 1)
> > + return -1;
> > +
> > + for (i = 0; i < buflen-1; i++)
> > + if (str[i*3 + 2] != ':')
> > + return -1;
> > +
> > + for (i = 0; str[i]; i++)
> > + if (!isxdigit(str[i]) && !(str[i] == ':'))
> > + return -1;
> > +
> > + for (i = 0; i < buflen; i++) {
> > + buf[i] = simple_strtoul(str, &e, 16);
> > + str = e + 1;
> > + }
> > +
> > + return 0;
> > +}
> > +EXPORT_SYMBOL(string_to_bin);
> > diff --git a/net/net.c b/net/net.c
> > index 8d99595..017de8b 100644
> > --- a/net/net.c
> > +++ b/net/net.c
> > @@ -161,22 +161,7 @@ void print_IPaddr (IPaddr_t x)
> >
> > int string_to_ethaddr(const char *str, char *enetaddr)
> > {
> > - int reg;
> > - char *e;
> > -
> > - if (!str || strlen(str) != 17)
> > - return -1;
> > -
> > - if (str[2] != ':' || str[5] != ':' || str[8] != ':' ||
> > - str[11] != ':' || str[14] != ':')
> > - return -1;
> > -
> > - for (reg = 0; reg < 6; ++reg) {
> > - enetaddr[reg] = simple_strtoul (str, &e, 16);
> > - str = e + 1;
> > - }
> > -
> > - return 0;
> > + return string_to_bin(str, enetaddr, 6);
> > }
> >
> > void ethaddr_to_string(const unsigned char *enetaddr, char *str)
> > --
> > 1.7.1
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] misc: introduce string_to_bin
2010-08-05 12:43 ` Baruch Siach
@ 2010-08-05 13:41 ` Jean-Christophe PLAGNIOL-VILLARD
2010-08-05 14:13 ` Baruch Siach
0 siblings, 1 reply; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-08-05 13:41 UTC (permalink / raw)
To: Baruch Siach; +Cc: barebox
Hi,
On 15:43 Thu 05 Aug , Baruch Siach wrote:
> Hi Jean-Christophe,
>
> On Thu, Aug 05, 2010 at 02:23:49PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > how about use the kernel printf format instead
>
> How can I use printf to convert a string representation to binary?
as example for ethernet address on the kernel we use %M or for UUID we %U to
print it in the right format. so take a look on vsprintf.c
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] misc: introduce string_to_bin
2010-08-05 13:41 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2010-08-05 14:13 ` Baruch Siach
2010-08-19 6:43 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 9+ messages in thread
From: Baruch Siach @ 2010-08-05 14:13 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
Hi Jean-Christophe,
On Thu, Aug 05, 2010 at 03:41:14PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 15:43 Thu 05 Aug , Baruch Siach wrote:
> > On Thu, Aug 05, 2010 at 02:23:49PM +0200, Jean-Christophe PLAGNIOL-VILLARD
> > wrote:
> > > how about use the kernel printf format instead
> >
> > How can I use printf to convert a string representation to binary?
> as example for ethernet address on the kernel we use %M or for UUID we %U to
> print it in the right format. so take a look on vsprintf.c
This is good for converting binary values to strings, not the other way around
as we do here.
baruch
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] misc: introduce string_to_bin
2010-08-05 14:13 ` Baruch Siach
@ 2010-08-19 6:43 ` Jean-Christophe PLAGNIOL-VILLARD
2010-08-19 12:37 ` Baruch Siach
0 siblings, 1 reply; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-08-19 6:43 UTC (permalink / raw)
To: Baruch Siach; +Cc: barebox
On 17:13 Thu 05 Aug , Baruch Siach wrote:
> Hi Jean-Christophe,
>
> On Thu, Aug 05, 2010 at 03:41:14PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 15:43 Thu 05 Aug , Baruch Siach wrote:
> > > On Thu, Aug 05, 2010 at 02:23:49PM +0200, Jean-Christophe PLAGNIOL-VILLARD
> > > wrote:
> > > > how about use the kernel printf format instead
> > >
> > > How can I use printf to convert a string representation to binary?
> > as example for ethernet address on the kernel we use %M or for UUID we %U to
> > print it in the right format. so take a look on vsprintf.c
>
> This is good for converting binary values to strings, not the other way around
> as we do here.
It's the same here u can do %xs to print it as hexa so it will be easier to
use
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] misc: introduce string_to_bin
2010-08-19 6:43 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2010-08-19 12:37 ` Baruch Siach
0 siblings, 0 replies; 9+ messages in thread
From: Baruch Siach @ 2010-08-19 12:37 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
Hi Jean-Christophe,
On Thu, Aug 19, 2010 at 08:43:48AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 17:13 Thu 05 Aug , Baruch Siach wrote:
> > On Thu, Aug 05, 2010 at 03:41:14PM +0200, Jean-Christophe PLAGNIOL-VILLARD
> > wrote:
> > > On 15:43 Thu 05 Aug , Baruch Siach wrote:
> > > > On Thu, Aug 05, 2010 at 02:23:49PM +0200, Jean-Christophe PLAGNIOL-VILLARD
> > > > wrote:
> > > > > how about use the kernel printf format instead
> > > >
> > > > How can I use printf to convert a string representation to binary?
> > > as example for ethernet address on the kernel we use %M or for UUID we %U to
> > > print it in the right format. so take a look on vsprintf.c
> >
> > This is good for converting binary values to strings, not the other way around
> > as we do here.
> It's the same here u can do %xs to print it as hexa so it will be easier to
> use
Apparently I'm missing something obvious here. I'll try to clarify how I see
things. Feel free to correct my understanding.
The various printf() variants take binary data as an argument, and translate
it into a string representation, according to the format string.
The purposed string_to_bin() function does the opposite. It takes a string
argument
const char* mac_str = "01:02:03:04:05:06";
and return the binary equivalent of this string in the buf pointer:
u8 mac[6];
string_to_bin(mac_str, mac, 6)
now the mac[] array contains the binary representation of the string mac_str,
in big-endian order.
I've found no way to do the same with printf.
baruch
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-08-19 12:37 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-05 11:23 [PATCH 1/2] misc: introduce string_to_bin Baruch Siach
2010-08-05 11:23 ` [PATCH 2/2] setser: new command to set serial number on ARM Baruch Siach
2010-08-18 4:49 ` Baruch Siach
2010-08-05 12:23 ` [PATCH 1/2] misc: introduce string_to_bin Jean-Christophe PLAGNIOL-VILLARD
2010-08-05 12:43 ` Baruch Siach
2010-08-05 13:41 ` Jean-Christophe PLAGNIOL-VILLARD
2010-08-05 14:13 ` Baruch Siach
2010-08-19 6:43 ` Jean-Christophe PLAGNIOL-VILLARD
2010-08-19 12:37 ` Baruch Siach
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox