Skip to contentSkip to conversation

fdt: remove unaligned access in fdt_fixup_ethernet()

PATCH In review Stephen Warren 4 participants 6 messages May 28, 2013 – Jun 12, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fdt: remove unaligned access in fdt_fixup_ethernet()

Some ARM compilers may emit code that makes unaligned accesses when faced with constructs such as:

char mac[16] = "ethaddr";

Replace this with a strcpy() call instead to avoid this. strcpy() is used here, rather than replacing all usage of the mac variable with the string itself, since the loop itself sprintf()s to the variable each iteration, so strcpy() is doing basically the same thing.

Reported-by Florian Meier
---
 common/fdt_support.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
common/fdt_support.c +2 -1
index 812acb4..89e7883 100644
@@ -454,7 +454,7 @@ void fdt_fixup_ethernet(void *fdt)
 {
 	int node, i, j;
 	char enet[16], *tmp, *end;
-	char mac[16] = "ethaddr";
+	char mac[16];
 	const char *path;
 	unsigned char mac_addr[6];
 
@@ -463,6 +463,7 @@ void fdt_fixup_ethernet(void *fdt)
 		return;
 
 	i = 0;
+	strcpy(mac, "ethaddr");
 	while ((tmp = getenv(mac)) != NULL) {
 		sprintf(enet, "ethernet%d", i);
 		path = fdt_getprop(fdt, node, enet, NULL);
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 fdt: remove unaligned access in fdt_fixup_ethernet()

Hi

Quoted 6 lines · Stephen Warren

Some ARM compilers may emit code that makes unaligned accesses when faced with constructs such as:

char mac[16] = "ethaddr";

Recently I have seen some of this emails. I understand the problem but is it a compiler problem? Is it reported somewhere?

Michael

Quoted 39 lines

Replace this with a strcpy() call instead to avoid this. strcpy() is used here, rather than replacing all usage of the mac variable with the string itself, since the loop itself sprintf()s to the variable each iteration, so strcpy() is doing basically the same thing.

Reported-by Florian Meier
---
 common/fdt_support.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
common/fdt_support.c +2 -2
index 812acb4..89e7883 100644
@@ -454,7 +454,7 @@ void fdt_fixup_ethernet(void *fdt)
 {
        int node, i, j;
        char enet[16], *tmp, *end;
-       char mac[16] = "ethaddr";
+       char mac[16];
        const char *path;
        unsigned char mac_addr[6];
 
@@ -463,6 +463,7 @@ void fdt_fixup_ethernet(void *fdt)
                return;
 
        i = 0;
+       strcpy(mac, "ethaddr");
        while ((tmp = getenv(mac)) != NULL) {
                sprintf(enet, "ethernet%d", i);
                path = fdt_getprop(fdt, node, enet, NULL);
--

1.7.10.4

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#2 lore raw

PATCH 1/1 fdt: remove unaligned access in fdt_fixup_ethernet()

Quoted 5 lines · Michael Trimarchi

Hi

Quoted 1 line · On May 28, 2013 6:02 AM, "Stephen Warren" <[email protected]…
Quoted 8 lines
Quoted 5 lines

Some ARM compilers may emit code that makes unaligned accesses when faced with constructs such as:

char mac[16] = "ethaddr";

Recently I have seen some of this emails. I understand the problem but is it a compiler problem? Is it reported somewhere?

The situation is explained in doc/README.arm-unaligned-accesses.

IIUC, the basic synopsis is that before ARMv7, the HW could not perform unaligned accesses, whereas ARMv7 and later can (with an enable bit in HW). Newer gcc takes advantage of this fact when it knows it's compiling for ARMv7 or later. However, in order to support pre-ARMv7, U-Boot has disabled this feature even on ARMv7 HW at runtime, so it's obvious where the code is making unaligned accesses, so U-Boot still works on pre-ARMv7. However, where gcc "implicitly" emits unaligned accesses, we have to fix them up, as in this patch.

#3 lore raw

PATCH 1/1 fdt: remove unaligned access in fdt_fixup_ethernet()

In reply to Stephen Warren
Quoted 9 lines · Stephen Warren

Some ARM compilers may emit code that makes unaligned accesses when faced with constructs such as:

char mac[16] = "ethaddr";

Replace this with a strcpy() call instead to avoid this. strcpy() is used here, rather than replacing all usage of the mac variable with the string itself, since the loop itself sprintf()s to the variable each iteration, so strcpy() is doing basically the same thing.

Jerry, does this patch look good? This fixes a problem that prevents U-Boot from booting a Linux kernel for some people. Thanks.

#4 lore raw
In reply to Stephen Warren
Quoted 5 lines · Stephen Warren

Some ARM compilers may emit code that makes unaligned accesses when faced with constructs such as:

char mac[16] = "ethaddr";

Quoted 7 lines

Replace this with a strcpy() call instead to avoid this. strcpy() is used here, rather than replacing all usage of the mac variable with the string itself, since the loop itself sprintf()s to the variable each iteration, so strcpy() is doing basically the same thing.

Reported-by Florian Meier

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130607/22b9944e/attachment.pgp>
#5 lore raw

Hi Stephen,

Sorry for not applying this in a timely manner. Thanks, Tom, for covering for me.

gvb

Quoted 16 lines · Tom Rini
Quoted 5 lines · Stephen Warren

Some ARM compilers may emit code that makes unaligned accesses when faced with constructs such as:

char mac[16] = "ethaddr";

Quoted 7 lines

Replace this with a strcpy() call instead to avoid this. strcpy() is used here, rather than replacing all usage of the mac variable with the string itself, since the loop itself sprintf()s to the variable each iteration, so strcpy() is doing basically the same thing.

Reported-by Florian Meier

Applied to u-boot/master, thanks!