Skip to contentSkip to conversation

kb9202/at91rm9200: compiler quirk?

U-Boot Matthias Kaehlcke 2 participants 3 messages May 4, 2009

lore
Share & tools
lore
#0 lore raw

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 `-

#1 lore raw
Quoted 5 lines · Matthias Kaehlcke

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.

I've never test the nand on rm9200 as the rm9200ek does not have it but I'll try this

Quoted 4 lines

the hwcontrol function looks like this:

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

unsigned int is not needed

Quoted 8 lines

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;

try writel(KB9202_NAND_NCE, AT91C_BASE_PIOB->PIO_CODR);

Quoted 2 lines
	else
		AT91C_BASE_PIOB->PIO_SODR = KB9202_NAND_NCE;

and writel(KB9202_NAND_NCE, AT91C_BASE_PIOB->PIO_SODR);

Quoted 8 lines
	...
}

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 ...

Best Regards,
J.

#2 lore raw

hi jean-christophe,

El Mon, May 04, 2009 at 11:26:12PM +0200 Jean-Christophe PLAGNIOL-VILLARD ha dit:

Quoted 18 lines · Matthias Kaehlcke
Quoted 4 lines

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.

I've never test the nand on rm9200 as the rm9200ek does not have it but I'll try this

Quoted 4 lines

the hwcontrol function looks like this:

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

unsigned int is not needed

Quoted 6 lines

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

{
	...
Quoted 6 lines
Quoted 2 lines
	if (ctrl & NAND_NCE)
		AT91C_BASE_PIOB->PIO_CODR = KB9202_NAND_NCE;

try writel(KB9202_NAND_NCE, AT91C_BASE_PIOB->PIO_CODR);

Quoted 2 lines
	else
		AT91C_BASE_PIOB->PIO_SODR = KB9202_NAND_NCE;

and writel(KB9202_NAND_NCE, AT91C_BASE_PIOB->PIO_SODR);

thanks for your response

i just tried it with writel(), but it doesn't work either, not even without the define :(

any other idea?

Signature · 11 lines
Matthias Kaehlcke
Embedded Linux Engineer
Barcelona

    Yo soy como soy y t? eres como eres, construyamos un mundo donde yo
    pueda ser sin dejar de ser yo, donde t? puedas ser sin dejar de ser
    t?, y donde ni yo ni t? obliguemos al otro a ser como yo o como t?
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-