This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
RE: memory alignment issue when compile eCos with codesourcery toolchain arm-none-eabi-gcc
- From: "Lu Karl-B01968" <Karl dot Lu at FREESCALE dot COM>
- To: "Chris Zimman" <czimman at bloomberg dot com>
- Cc: <ecos-discuss at ecos dot sourceware dot org>
- Date: Wed, 15 Oct 2008 19:34:01 +0800
- Subject: [ECOS] RE: memory alignment issue when compile eCos with codesourcery toolchain arm-none-eabi-gcc
- References: <7FD1F85C96D70C4A89DA1DF7667EAE960D7C2C@zch01exm23.fsl.freescale.net> <F31C1582037F5041B0CD525FD870AE6A012E8BA1@ny2545.corp.bloomberg.com>
Thanks Chris.
We are using Freescale i.Mx31 which is an ARM11 chip.
The problem happens when a 2-byte aligned address is assigned to pointer which requires 4-byte aligned. For example, in lan92xx_send() in if_lan92xx.c, one code line is as below,
----------
unsigned int data, *pdata;
pdata = (unsigned int *)sg_list[i].buf;
-----------
Here sg_list[i].buf is 2-byte aligned while pdata needs 4-byte aligned. Then following code will hang the system
----------
data = *pdata;
---------
In fconfig.c, the problem is similar. Val_ptr is of "void *" type and it is pointed to a char in a long string (for command processing). It is not guaranteed to be 4-byte aligned. Then when setting IP address, following code will fail
----------
lp += diag_sprintf(lp, "%s", inet_ntoa((in_addr_t *)val_ptr));
---------
Because (in_addr_t *) in function inet_ntoa expects val_ptr to be 4-byte aligned.
Do you think there is a way to work around this issue without code modification?
Regards
Karl Lu
-----Original Message-----
From: Chris Zimman [mailto:czimman@bloomberg.com]
Sent: 2008å10æ15æ 19:16
To: Lu Karl-B01968
Cc: ecos-discuss-owner@ecos.sourceware.org
Subject: RE: memory alignment issue when compile eCos with codesourcery toolchain arm-none-eabi-gcc
> We are using arm-none-eabi toolchain (we downloaded 2008q1 release
> from
CodeSoucery website) to build eCos/redboot. Thanks to Chris, we resolved the
> link issues in arm.ld but we are meeting memory alignment issue now.
> In
ecos/package/redboot/current/include/net/net.h, we have to modify the code,
> addÂ__attribute__((aligned(4),packed)) for struct eth_header_t and
> pktbuf_t
and force them to the 4-byte aligned. Otherwise, Ethernet driver code
> will hang the system during RedBoot startup. We also find in
ecos/package/redboot/current/src/fconfig.c, we also have to force val_ptr in
> get_config() to be 4-byte aligned otherwise we can't config IP address
> when
we run fconfig in redboot. This command will abort and report "**
> command abort - illegal memory access?"
> We can modify the code manually whenever we meet such kind of memory
alignment problem but it is really annoying. We wanted to find a compile option > in arm-none-eabi-gcc to work around this issue but failed. Did you meet the similar memory alignment issue? How did you work around this issue?
Hi Karl,
I didn't run into any alignment issues per se. Without knowing anything else, where is val_ptr pointed at? Is the pointer valid and pointing to what it should be? I would suspect something other than the EABI related stuff directly.
Which ARM processor are you targeting?
Just for the sake of comparison, I'm attaching the linker script that I use for EABI. Have a look at that and let's go from there.
--Chris