This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM335X Uboot Unaligned Access Fail

Other Parts Discussed in Thread: AM3358

I tested unaligned  access  with the code above in u-boot, when I ran the code, I got

Start Aligned Test

u8_t * access test[1]:0 #CPU halt here
CCCCCCCC

test is  defined as global array  u8_t test[1000] = {0};

I am using SDK ti-processor-sdk-lnux-am335x-evm-01.00.00.03 

and I try to add -munaligned-access -fno-conserve-stack  to KBUILD_CFAGS in the root Makefile of uboot, but it seems not work.

I also update the u-boot/arch/arm/cpu/armv7/config.mk -mno-unaligned-accss to -munaligned-access, it seems not work neither.

What's the problem?

  • Are you using a custom board?
  • Hi Biser! Thanks for reply!

    Yes, we use our custom board. And I have am3358 starter kit & gp evm either.
  • Hi,

    Have you done any other modifications to the u-boot sources, except the above mentioned fragment of code?
    Is it possible to test your code on the latest u-boot from SDK02.00.01.07 on any of the two reference boards (starter kit or gp evm)?

    Best Regards,
    Yordan
  • Hello,
    you have to align your buffer correctly to access it correctly depending on your pointer.
    for example when using GCC, use "__attribute__((aligned(xxx)));" when defining your buffer with xxx the correct alignment/misalignment value. Refer to your compiler documentation for "alignment" attribute.
  • Hi Yordan! Thanks for your reply!

    Yes, of course,  something like ddr setting, mux setting and so on.  The fact is I need to port UIP into uboot, when i access some struct variable the uboot halt directly without any message. 

     

    I have port the code into starter kit, but the result is the same.

  • Thanks for reply!
    I didn't tune DDR3 exactly, but it works for linux, and i don't encounter any memory problem in it.
  • Hi Prodigy! Thanks for reply!
    Yes this is may a solution. but what about the variable in a aligned struct. As I need to port UIP for our application, many modification should be done.

    because i put UIP source in net directory, I try to add -fpack-struct to ccflags-y in u-boot/net/Makefile , but the result is the uboot halt at
    U-Boot 2014.07-svn473 (Feb 23 2016 - 15:10:41)
    I2C: ready
    DRAM: 128 MiB
    #halt here
  • Hi,
    This may be not an option: if you access to a variable which is not correctly aligned vs the type you are accessing, unless these is handled by the gcc with correct option (--no_unaligned_access), your CPU crashes (it is on my side with the compiler option I set)
    In your example, "test" is an array of bytes; you can access to any bytes with a pointer to byte with no problem.
    Considering that your array is aligned on a 16-bit word, accessing to test[0] will work but accessing to test[1] with a 16-bit pointer may crashes your cpu when this is not handled by the compiler.

    refer to infocenter.arm.com/.../index.jsp if not already done ^^
    "The --no_unaligned_access flag tells the compiler not to knowingly generate unaligned accesses. What is the significance of knowingly? [...] As mentioned above, a pointer should contain an address with correct alignment for the type.[...] The compiler will generate code on the assumption that a pointer is correctly aligned. It does not add code to perform run-time checks."
    and arch/arm/cpu/armv7/config.mk makefile in your U-boot

    Implementing a sw and ignoring data alignment will decrease performance. I suggest you to align buffers or put your code elsewhere from U-boot to set your own compiler option.

    Good luck!
  • Hi Prodigy ! Thanks a lot!
    You are right exactly. I have uip ran in arm926ejs which is armv5l, it works.

    i found -munaligned-access -mno-unaligned-access in arm gcc may not works for me except the code is aligned 4 bytes and i access it as 4 bytes aligned? Not sure.

    gcc.gnu.org/.../ARM-Options.html

    [cite]
    -munaligned-access
    -mno-unaligned-access
    Enables (or disables) reading and writing of 16- and 32- bit values from addresses that are not 16- or 32- bit aligned. By default unaligned access is disabled for all pre-ARMv6 and all ARMv6-M architectures, and enabled for all other architectures. If unaligned access is not enabled then words in packed data structures are accessed a byte at a time.
    The ARM attribute Tag_CPU_unaligned_access is set in the generated object file to either true or false, depending upon the setting of this option. If unaligned access is enabled then the preprocessor symbol __ARM_FEATURE_UNALIGNED is also defined.
    [/cite]