Unaligned access in ubldr.bin

Warner Losh imp at bsdimp.com
Wed Sep 7 13:23:01 UTC 2016


On Wed, Sep 7, 2016 at 12:46 AM, Erik Moe <e.moe at rcn.com> wrote:
> Hello,
>
> I’ve been trying to bring up FreeBSD on the USB Armory based on the i.MX53.  I’ve made myself a u-boot patch that will load and start ubldr.bin but I’m running into a issue with what I think is an unaligned access issue:

which version of u-boot are you using?


> ## Starting application at 0x70800000 ...
> data abort
> pc : [<70824bac>]          lr : [<7081846c>]
> sp : 8f550c98  ip : 70835a00     fp : 8f550cb0
> r10: 00000002  r9 : 70838d58     r8 : 70833cd9
> r7 : 707fff08  r6 : 000054f0     r5 : 70833cd9  r4 : 00000000
> r3 : 70828fc4  r2 : 70833cd9     r1 : 00000001  r0 : 7083705c
> Flags: Nzcv  IRQs off  FIQs off  Mode SVC_32
> Resetting CPU ...
>
> I’ve hand dissambled the code at  pc=0x70824bac:
>
> 0x70824ba8: 0xe59f21d0 ldr r2, [pc, #464]
> 0x70824bac: 0xe5825000 str r5, [r2]
> 0x70824bb0: 0xe5d53000 ldrb r3, [r5]
> 0x70824bb4: 0xe353002d cmp r3, #45
> 0x70824bb8: 0x1a00000b bne #+44
>
> The offending instructions is "str r5, [r2]” where r2 = 0x70833cd9, which sort of makes sense since it isn’t aligned on a 4 byte boundary.  I’m new to arm ARM, so I’m not really sure.  My questions are these:
>
> 1.) Doesn’t ARMv6 and higher architecture allow unaligned access?  Is there something that u-boot needs be doing in initialization to allow unaligned access?

It does, but usually that's configured later in boot.

> 2.) Does ubldr make the assumption that unaligned access is allowed and maybe shouldn’t?  I would think not since ubldr has been around for a while and works on numerous ARM processors.

It may be that the compiler is generating bad code in this case? You
might check to see how we're building it and to see if that's causing
problems.

I've been trying to bring up v2016.07 on some boards and that fails
where v2016.05 worked. I get data alignment issues, but all I'm
changing is u-boot.img.

Warner

> Any thoughts at which direction to investigate would be appreciated.
>
> Thanks,
> Erik
>
> FYI, ubldr is failing in “getopt”.  I’ve used objdump to disassemble ubldr.bin.  You’ll have to subtract the offset 0xf8 and add 0x7080000 to the addresses bellow to get them to align with the addresses above.
>
>
> getopt(int nargc, char * const *nargv, const char *ostr)
> {
>    24c4c:       e92d4df0        push    {r4, r5, r6, r7, r8, sl, fp, lr}
>    24c50:       e28db018        add     fp, sp, #24
>    24c54:       e1a07000        mov     r7, r0
>         static char *place = EMSG;              /* option letter processing */
>         char *oli;                              /* option letter list index */
>
>         if (optreset || !*place) {              /* update scanning pointer */
>    24c58:       e59f0214        ldr     r0, [pc, #532]  ; 24e74 <getopt+0x228>
>    24c5c:       e1a06001        mov     r6, r1
>    24c60:       e1a08002        mov     r8, r2
>    24c64:       e5901000        ldr     r1, [r0]
>    24c68:       e3510000        cmp     r1, #0
>    24c6c:       1a000004        bne     24c84 <getopt+0x38>
>    24c70:       e59f1200        ldr     r1, [pc, #512]  ; 24e78 <getopt+0x22c>
>    24c74:       e5913000        ldr     r3, [r1]
>    24c78:       e5d34000        ldrb    r4, [r3]
>    24c7c:       e3540000        cmp     r4, #0
>    24c80:       1a00001d        bne     24cfc <getopt+0xb0>
>    24c84:       e3a01000        mov     r1, #0
>                 optreset = 0;
>    24c88:       e5801000        str     r1, [r0]
>                 if (optind >= nargc || *(place = nargv[optind]) != '-') {
>                         place = EMSG;
>                         return (-1);
>                 }
>                 if (place[1] && *++place == '-') {      /* found "--" */
>                         ++optind;
>    24c8c:       e59f01e8        ldr     r0, [pc, #488]  ; 24e7c <getopt+0x230>
>    24c90:       e5901000        ldr     r1, [r0]
>         static char *place = EMSG;              /* option letter processing */
>         char *oli;                              /* option letter list index */
>
>         if (optreset || !*place) {              /* update scanning pointer */
>                 optreset = 0;
>                 if (optind >= nargc || *(place = nargv[optind]) != '-') {
>    24c94:       e1510007        cmp     r1, r7
>    24c98:       aa000011        bge     24ce4 <getopt+0x98>
>    24c9c:       e7965101        ldr     r5, [r6, r1, lsl #2]
>    24ca0:       e59f21d0        ldr     r2, [pc, #464]  ; 24e78 <getopt+0x22c>
>    24ca4:       e5825000        str     r5, [r2]
>    24ca8:       e5d53000        ldrb    r3, [r5]
>    24cac:       e353002d        cmp     r3, #45 ; 0x2d
>
>
> _______________________________________________
> freebsd-arm at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-arm
> To unsubscribe, send any mail to "freebsd-arm-unsubscribe at freebsd.org"


More information about the freebsd-arm mailing list