All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2] cmd/fdt: Make fdt get value endian-safe for single-cell properties
@ 2017-01-09 15:08 Andreas Färber
  2017-01-13  2:19 ` Simon Glass
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Färber @ 2017-01-09 15:08 UTC (permalink / raw)
  To: u-boot

On a Raspberry Pi 2 disagreements on cell endianness can be observed:

  U-Boot> fdt print /soc/gpio at 7e200000 phandle
  phandle = <0x0000000d>
  U-Boot> fdt get value myvar /soc/gpio at 7e200000 phandle; printenv myvar
  myvar=0x0D000000

Fix this by always treating the pointer as BE and converting it in
fdt_value_setenv(), like its counterpart fdt_parse_prop() already does.

Consistently use fdt32_t, fdt32_to_cpu() and cpu_to_fdt32().

Fixes: bc80295 ("fdt: Add get commands to fdt")
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Gerald Van Baren <gvb@unssw.com>
Signed-off-by: Andreas F?rber <afaerber@suse.de>
---
 cmd/fdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/fdt.c b/cmd/fdt.c
index 8bd345a..42397d1 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -58,7 +58,7 @@ static int fdt_value_setenv(const void *nodep, int len, const char *var)
 	else if (len == 4) {
 		char buf[11];
 
-		sprintf(buf, "0x%08X", *(uint32_t *)nodep);
+		sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep));
 		setenv(var, buf);
 	} else if (len%4 == 0 && len <= 20) {
 		/* Needed to print things like sha1 hashes. */
@@ -764,7 +764,7 @@ static int fdt_parse_prop(char * const *newval, int count, char *data, int *len)
 
 			cp = newp;
 			tmp = simple_strtoul(cp, &newp, 0);
-			*(__be32 *)data = __cpu_to_be32(tmp);
+			*(fdt32_t *)data = cpu_to_fdt32(tmp);
 			data  += 4;
 			*len += 4;
 
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH v2] cmd/fdt: Make fdt get value endian-safe for single-cell properties
  2017-01-09 15:08 [U-Boot] [PATCH v2] cmd/fdt: Make fdt get value endian-safe for single-cell properties Andreas Färber
@ 2017-01-13  2:19 ` Simon Glass
  2017-01-14 17:14   ` Simon Glass
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Glass @ 2017-01-13  2:19 UTC (permalink / raw)
  To: u-boot

On 9 January 2017 at 08:08, Andreas F?rber <afaerber@suse.de> wrote:
> On a Raspberry Pi 2 disagreements on cell endianness can be observed:
>
>   U-Boot> fdt print /soc/gpio at 7e200000 phandle
>   phandle = <0x0000000d>
>   U-Boot> fdt get value myvar /soc/gpio at 7e200000 phandle; printenv myvar
>   myvar=0x0D000000
>
> Fix this by always treating the pointer as BE and converting it in
> fdt_value_setenv(), like its counterpart fdt_parse_prop() already does.
>
> Consistently use fdt32_t, fdt32_to_cpu() and cpu_to_fdt32().
>
> Fixes: bc80295 ("fdt: Add get commands to fdt")
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Gerald Van Baren <gvb@unssw.com>
> Signed-off-by: Andreas F?rber <afaerber@suse.de>
> ---
>  cmd/fdt.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH v2] cmd/fdt: Make fdt get value endian-safe for single-cell properties
  2017-01-13  2:19 ` Simon Glass
@ 2017-01-14 17:14   ` Simon Glass
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Glass @ 2017-01-14 17:14 UTC (permalink / raw)
  To: u-boot

On 12 January 2017 at 19:19, Simon Glass <sjg@chromium.org> wrote:
> On 9 January 2017 at 08:08, Andreas F?rber <afaerber@suse.de> wrote:
>> On a Raspberry Pi 2 disagreements on cell endianness can be observed:
>>
>>   U-Boot> fdt print /soc/gpio at 7e200000 phandle
>>   phandle = <0x0000000d>
>>   U-Boot> fdt get value myvar /soc/gpio at 7e200000 phandle; printenv myvar
>>   myvar=0x0D000000
>>
>> Fix this by always treating the pointer as BE and converting it in
>> fdt_value_setenv(), like its counterpart fdt_parse_prop() already does.
>>
>> Consistently use fdt32_t, fdt32_to_cpu() and cpu_to_fdt32().
>>
>> Fixes: bc80295 ("fdt: Add get commands to fdt")
>> Cc: Joe Hershberger <joe.hershberger@ni.com>
>> Cc: Gerald Van Baren <gvb@unssw.com>
>> Signed-off-by: Andreas F?rber <afaerber@suse.de>
>> ---
>>  cmd/fdt.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-fdt, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-14 17:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-09 15:08 [U-Boot] [PATCH v2] cmd/fdt: Make fdt get value endian-safe for single-cell properties Andreas Färber
2017-01-13  2:19 ` Simon Glass
2017-01-14 17:14   ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.