[U-Boot] kb9202/at91rm9200: compiler quirk?

Matthias Kaehlcke matthias at kaehlcke.net
Mon May 4 20:13:15 CEST 2009


hi,

i'm trying to do a forward port of the out of tree patches for the
kwikbyte kb9202b. my board is booting and detects the nand flash, but
only in certain circumstances.

the hwcontrol function looks like this:

#define KB9202_NAND_NCE ((unsigned int)1 << 28) /* EN* on D28 */

static void kb9202_nand_hwcontrol(struct mtd_info *mtd, int cmd,
unsigned int ctrl)
{
	...

	if (ctrl & NAND_NCE)
		AT91C_BASE_PIOB->PIO_CODR = KB9202_NAND_NCE;
	else
		AT91C_BASE_PIOB->PIO_SODR = KB9202_NAND_NCE;

	...
}

the problem is that for some reason the enable signal isn't generated
when using the pre-processor constant KB9202_NAND_NCE. on the other
hand it is generated when using ((unsigned int)1 << 28), instead of
the define. it took me some hours to figure this out ...

the generated assembler code differs slightly:

[without define]

Dump of assembler code for function kb9202_nand_hwcontrol:
0x21f1998c <kb9202_nand_hwcontrol+0>:   tst     r2, #128        ; 0x80
0x21f19990 <kb9202_nand_hwcontrol+4>:   ldr     r0, [r0, #152]
0x21f19994 <kb9202_nand_hwcontrol+8>:   beq     0x21f199d0 <kb9202_nand_hwcontrol+68>
0x21f19998 <kb9202_nand_hwcontrol+12>:  ldr     r3, [r0, #4]
0x21f1999c <kb9202_nand_hwcontrol+16>:  tst     r2, #2  ; 0x2
0x21f199a0 <kb9202_nand_hwcontrol+20>:  bic     r3, r3, #6291456; 0x600000
0x21f199a4 <kb9202_nand_hwcontrol+24>:  orrne   r3, r3, #2097152; 0x200000
0x21f199a8 <kb9202_nand_hwcontrol+28>:  tst     r2, #4  ; 0x4
0x21f199ac <kb9202_nand_hwcontrol+32>:  orrne   r3, r3, #4194304; 0x400000
0x21f199b0 <kb9202_nand_hwcontrol+36>:  tst     r2, #1  ; 0x1
0x21f199b4 <kb9202_nand_hwcontrol+40>:  str     r3, [r0, #4]

0x21f199b8 <kb9202_nand_hwcontrol+44>:  movne   r2, #268435456  ; 0x10000000
0x21f199bc <kb9202_nand_hwcontrol+48>:  mvnne   r3, #1792       ; 0x700
0x21f199c0 <kb9202_nand_hwcontrol+52>:  moveq   r2, #268435456  ; 0x10000000
0x21f199c4 <kb9202_nand_hwcontrol+56>:  mvneq   r3, #1792       ; 0x700

0x21f199c8 <kb9202_nand_hwcontrol+60>:  strne   r2, [r3, #-203]
0x21f199cc <kb9202_nand_hwcontrol+64>:  streq   r2, [r3, #-207]
0x21f199d0 <kb9202_nand_hwcontrol+68>:  cmn     r1, #1  ; 0x1
0x21f199d4 <kb9202_nand_hwcontrol+72>:  ldrne   r2, [r0, #4]
0x21f199d8 <kb9202_nand_hwcontrol+76>:  andne   r3, r1, #255    ; 0xff
0x21f199dc <kb9202_nand_hwcontrol+80>:  strneb  r3, [r2]
0x21f199e0 <kb9202_nand_hwcontrol+84>:  mov     pc, lr


[differences with define]

0x21f199b8 <kb9202_nand_hwcontrol+44>:  movne   r2, #268435456  ; 0x10000000
0x21f199bc <kb9202_nand_hwcontrol+48>:  mvnne   r3, #2304       ; 0x900
0x21f199c0 <kb9202_nand_hwcontrol+52>:  moveq   r2, #268435456  ; 0x10000000
0x21f199c4 <kb9202_nand_hwcontrol+56>:  mvneq   r3, #2304       ; 0x900


any idea what could be the problem? some kind of compiler optimization
i guess, though i expected the two expressions to be 100% equivalent.

--
Matthias Kaehlcke
Embedded Linux Engineer
Barcelona

         An ounce of practice is worth more than tons of preaching
                            (Mahatma Gandhi)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-


More information about the U-Boot mailing list