2009-09-26 14:52:05     Fault when enabling MMC support

Document created by Aaronwu Employee on Aug 19, 2013
Version 1Show Document
  • View in full screen mode

2009-09-26 14:52:05     Fault when enabling MMC support

Frank Van Hooft (CANADA)

Message: 80494   

 

We're bringing our BF523 board to life, and it's going quite well except for one wierd (to us) problem. When we enable MMC/SD card support in menuconfig, it results in uclinux faulting. We're using 2009R1. The fault appears to be happening in the function bfin_spi_setup() in the file spi_bfin_5xx.c as a result of the mmc code calling bfin_spi_setup() with an unsupported mode of 7. But we've no idea why. We do not have a card plugged in (in fact the socket isn't even soldered onto the board yet).

 

In function bfin_spi_setup() we've put a printk at the top of the function so we can see how it's being called, as follows:

 

printk("bfin_spi_setup() mode 0x%x\n", spi->mode);

 

The boot messages look like this:

 

## Booting kernel from Legacy Image at 02000000 ...       

   Image Name:   Linux-2.6.28.10-ADI-2009R1-svn74         

   Created:      2009-09-26  17:40:54 UTC                 

   Image Type:   Blackfin Linux Kernel Image (gzip compressed)

   Data Size:    2004856 Bytes =  1.9 MB                    

   Load Address: 00001000                                   

   Entry Point:  00145dc0                                   

   Verifying Checksum ... OK                                

   Uncompressing Kernel Image ... OK                        

Starting Kernel at = 00145dc0                               

Linux version 2.6.28.10-ADI-2009R1-svn7432 (frank@downstairs-linux) (gcc version 4.1.2 (ADI svn)) #94 Sat Sep 26 10:40:50 PDT 2009                                                                                                              

bootconsole [early_shadow0] enabled                                                                                    

bootconsole [early_BFuart0] enabled                                                                                    

early printk enabled on early_BFuart0                                                                                  

Board Memory: 64MB                                                                                                     

Kernel Managed Memory: 64MB                                                                                            

Memory map:                                                                                                            

  fixedcode = 0x00000400-0x00000490                                                                                    

  text      = 0x00001000-0x000d5a60                                                                                    

  rodata    = 0x000d5a60-0x0011d634                                                                                    

  bss       = 0x0011e000-0x0012d094                                                                                    

  data      = 0x0012d094-0x0013a000                                                                                    

    stack   = 0x00138000-0x0013a000                                                                                    

  init      = 0x0013a000-0x003ad000                                                                                    

  available = 0x003ad000-0x03fff000                                                                                    

Hardware Trace Active and Enabled                                                                                      

Boot Mode: 3                                                                                                           

Reset caused by Software reset                                                                                         

Blackfin support (C) 2004-2009 Analog Devices, Inc.                                                                    

Compiled for ADSP-BF523 Rev 0.2                                                                                        

Blackfin Linux support by   blackfin.uclinux.org/                                                                 

Processor Speed: 528 MHz core clock and 105 MHz System Clock                                                           

NOMPU: setting up cplb tables                                                                                          

Instruction Cache Enabled for CPU0                                                                                     

Data Cache Enabled for CPU0 (write-back)                                                                               

Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 16255                                            

Kernel command line: root=/dev/mtdblock0 rw clkin_hz=16000000 earlyprintk=serial,uart0,57600 console=ttyBF0,57600      

Configuring Blackfin Priority Driven Interrupts                                                                        

PID hash table entries: 256 (order: 8, 1024 bytes)                                                                     

console [ttyBF0] enabled, bootconsole disabled                                                                         

console [ttyBF0] enabled, bootconsole disabled                                                                         

Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)                                                          

Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)                                                           

Memory available: 61200k/65536k RAM, (2508k init code, 850k kernel code, 402k data, 0k dma, 572k reserved)             

Calibrating delay loop... 1048.57 BogoMIPS (lpj=2097152)                                                               

Mount-cache hash table entries: 512                                                                                    

Blackfin Scratchpad data SRAM: 4 KB                                                                                    

Blackfin L1 Data A SRAM: 16 KB (16 KB free)                                                                            

Blackfin L1 Data B SRAM: 16 KB (16 KB free)                                                                            

Blackfin L1 Instruction SRAM: 48 KB (42 KB free)                                                                       

net_namespace: 288 bytes                                                                                               

NET: Registered protocol family 16                                                                                     

Blackfin DMA Controller                                                                                                

ezbrd_init(): registering device resources                                                                             

NET: Registered protocol family 1                                                                                      

msgmni has been set to 119                                                                                             

io scheduler noop registered (default)                                                                                 

simple-gpio: now handling 48 GPIOs: 0 - 47                                                                             

Serial: Blackfin serial driver                                                                                         

bfin-uart.1: ttyBF0 at MMIO 0xffc00400 (irq = 29) is a BFIN-UART                                                       

bfin-uart.1: ttyBF1 at MMIO 0xffc02000 (irq = 31) is a BFIN-UART                                                       

brd: module loaded                                                                                                     

bfin_spi_setup() mode 0x3                                                                                              

m25p80 spi0.1: m25p32 (4096 Kbytes)                                                                                    

Creating 3 MTD partitions on "ST m25p32":                                                                              

0x00000000-0x00030000 : "bootloader(spi)"                                                                              

0x00030000-0x003f0000 : "linux kernel(spi)"                                                                            

0x003f0000-0x00400000 : "config block(spi)"                                                                            

bfin_spi_setup() mode 0x3                                                                                              

bfin-spi bfin-spi.0: Blackfin on-chip SPI Controller Driver, Version 1.0, regs_base@ffc00500, dma channel@7            

rtc-bfin rtc-bfin: rtc core: registered rtc-bfin as rtc0                                                               

i2c /dev entries driver                                                                                                

i2c-bfin-twi i2c-bfin-twi.0: Blackfin BF5xx on-chip I2C TWI Contoller, regs_base@ffc01400                              

bfin-wdt: initialized: timeout=20 sec (nowayout=0)                                                                     

bfin_spi_setup() mode 0x3                                                                                              

mmc_spi spi0.6: ASSUMING 3.2-3.4 V slot power                                                                          

mmc_spi spi0.6: SD/MMC host mmc0, no DMA, no WP, no poweroff                                                           

bfin_spi_setup() mode 0x7                                                                                              

mmc_spi spi0.6: requested mode not fully supported                                                                     

NULL pointer access                                                                                                    

Kernel OOPS in progress                                                                                                

Deferred Exception context                                                                                             

CURRENT PROCESS:                                                                                                       

COMM=kmmcd PID=35                                                                                                      

CPU = 0                                                                                                                

invalid mm                                                                                                             

return address: [0x000a233c]; contents of:                                                                             

0x000a2310:  e122  008c  3044  5090  e4a8  000a  b0f0  e140                                                            

0x000a2320:  0010  e100  b260  e3fb  66f5  6357  e418  001f                                                            

0x000a2330:  0c00  1029  0000  6000  e618  001f [e5a8] 0006                                                            

0x000a2340:  4342  0c02  1c2c  0000  e522  0049  e450  0093                                                            

 

ADSP-BF523-0.2 528(MHz CCLK) 105(MHz SCLK) (mpu off)

Linux version 2.6.28.10-ADI-2009R1-svn7432        

Built with gcc version 4.1.2 (ADI svn)            

 

SEQUENCER STATUS:               Not tainted

SEQSTAT: 00002027  IPEND: 8030  SYSCFG: 0006

  EXCAUSE   : 0x27                         

  interrupts disabled                      

  physical IVG5 asserted : <0xffa00bbc> { _evt_ivhw + 0x0 }

  physical IVG15 asserted : <0xffa00e30> { _evt_system_call + 0x0 }

  logical irq   6 mapped  : <0xffa00328> { _timer_interrupt + 0x0 }

  logical irq  21 mapped  : <0x000a6618> { _bfin_rtc_interrupt + 0x0 }

  logical irq  27 mapped  : <0x000a90f4> { _bfin_twi_interrupt_entry + 0x0 }

  logical irq 112 mapped  : <0x000b1514> { _mmc_spi_detect_irq + 0x0 }    

RETE: <0x00000000> /* Maybe null pointer? */                             

RETN: <0x00441ec8> /* kernel dynamic memory */                           

RETX: <0x00000480> /* Maybe fixed code section */                        

RETS: <0x000a23c2> { _bfin_spi_setup + 0x156 }                           

PC  : <0x000a233c> { _bfin_spi_setup + 0xd0 }                            

DCPLB_FAULT_ADDR: <0x00000006> /* Maybe null pointer? */                  

ICPLB_FAULT_ADDR: <0x000a233c> { _bfin_spi_setup + 0xd0 }                 

 

PROCESSOR STATE:

R0 : 00000000    R1 : 0000ffff    R2 : ffffffff    R3 : 00000e6f

R4 : 00000000    R5 : 00000000    R6 : 00441fb8    R7 : ffffffea

P0 : 00000e3c    P1 : 0012f1d0    P2 : 0012e6c0    P3 : 03c2c53c

P4 : 03c3dc00    P5 : 00000000    FP : 00440000    SP : 00441dec

LB0: 000aac88    LT0: 000aac88    LC0: 00000000

LB1: 000870aa    LT1: 0008709e    LC1: 00000000

B0 : 0000001b    L0 : 00000000    M0 : 00000001    I0 : 00000001

B1 : 00000000    L1 : 00000000    M1 : 00000000    I1 : 0000000f

B2 : 00000000    L2 : 00000000    M2 : 00000000    I2 : 00000000

B3 : 00000000    L3 : 00000000    M3 : 00000000    I3 : 000df570

A0.w: 00000019   A0.x: 00000000   A1.w: 00000005   A1.x: 00000000

USP : 00000000  ASTAT: 00003025

 

Hardware Trace:

   0 Target : <0x00004ce0> { _trap_c + 0x0 }

     Source : <0xffa0061a> { _exception_to_level5 + 0xae } CALL pcrel

   1 Target : <0xffa0056c> { _exception_to_level5 + 0x0 }

     Source : <0xffa00428> { _bfin_return_from_exception + 0x18 } RTX

   2 Target : <0xffa00410> { _bfin_return_from_exception + 0x0 }

     Source : <0xffa004c4> { _ex_trap_c + 0x6c } JUMP.S

   3 Target : <0xffa00458> { _ex_trap_c + 0x0 }

     Source : <0xffa006e6> { _trap + 0x5a } JUMP (P4)

   4 Target : <0xffa0068c> { _trap + 0x0 }

     Source : <0x000a2338> { _bfin_spi_setup + 0xcc } 0xe618

   5 Target : <0x000a232c> { _bfin_spi_setup + 0xc0 }

     Source : <0x000a23c6> { _bfin_spi_setup + 0x15a } JUMP.S

   6 Target : <0x000a23c2> { _bfin_spi_setup + 0x156 }

     Source : <0x0000f126> { _printk + 0x16 } RTS

   7 Target : <0x0000f122> { _printk + 0x12 }

     Source : <0x0000f9be> { _vprintk + 0x132 } RTS

   8 Target : <0x0000f9b2> { _vprintk + 0x126 }

     Source : <0xffa00bb8> { __common_int_entry + 0xcc } RTI

   9 Target : <0xffa00b56> { __common_int_entry + 0x6a }

     Source : <0xffa009a8> { _return_from_int + 0x58 } RTS

  10 Target : <0xffa009a8> { _return_from_int + 0x58 }

     Source : <0xffa0097e> { _return_from_int + 0x2e } IF !CC JUMP

  11 Target : <0xffa00950> { _return_from_int + 0x0 }

     Source : <0xffa00b52> { __common_int_entry + 0x66 } CALL pcrel

  12 Target : <0xffa00b50> { __common_int_entry + 0x64 }

     Source : <0xffa002e2> { _asm_do_IRQ + 0x62 } RTS

  13 Target : <0xffa002da> { _asm_do_IRQ + 0x5a }

     Source : <0x00012f58> { __local_bh_enable + 0x40 } RTS

  14 Target : <0x00012f18> { __local_bh_enable + 0x0 }

     Source : <0x00013040> { ___do_softirq + 0x9c } JUMP.L

  15 Target : <0x00013038> { ___do_softirq + 0x94 }

     Source : <0x0001301c> { ___do_softirq + 0x78 } IF !CC JUMP

 

Kernel Stack

Stack info:

SP: [0x00441df0] <0x00441df0> /* kernel dynamic memory */

 

 

 

You can see bfin_spi_setup() being called by MTD with mode 3, which works fine. Then it's called more than once by the mmc code, twice with a mode 3, but a third time with a mode 7, which fails.  I'm assuming it's the error code within bfin_spi_setup() that's actually triggering the fault (if so, that's not very graceful :-) but I've not been able to confirm that.

 

MMC is enabled in menuconfig as follows:

 

  --- MMC/SD/SDIO card support                                                             

                       [ ]   MMC debugging                                                                     

                       [ ]   Allow unsafe resume (DANGEROUS)                                                    

                             *** MMC/SD/SDIO Card Drivers ***                                                   

                       <*>   MMC block device driver                                                            

                       [*]     Use bounce buffer for simple hosts                                               

                       < >   SDIO UART/GPS class support                                                        

                       < >   MMC host test driver                                                               

                             *** MMC/SD/SDIO Host Controller Drivers ***                                        

                       < >   Secure Digital Host Controller Interface support                                   

                       <*>   MMC/SD/SDIO over SPI   

 

SPI is enabled in menuconfig as follows:

 

    --- SPI support                                                                          

                       [ ]   Debug support for SPI drivers                                                      

                             *** SPI Master Controller Drivers ***                                              

                       <*>   SPI controller driver for ADI Blackfin5xx                                          

                       [*]     SPI bus lock                                                                     

                       < >   emulate SPI bus with Blackfin SPORT                                                

                       < >   Bitbanging SPI master                                                              

                             *** SPI Protocol Masters ***                                                       

                       < >   SPI EEPROMs from most vendors                                                      

                       < >   User mode SPI device driver support                                                

                       < >   Infineon TLE62X0 (for power switching)    

 

In the board configuration file, done according the wiki page   docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:spi_mmc, the mmc SPI is defined for mode 3.

 

#if defined(CONFIG_MMC_SPI) || defined(CONFIG_MMC_SPI_MODULE)

    {

        .modalias = "mmc_spi",

        .max_speed_hz = 20000000,     /* max spi clock (SCK) speed in HZ */

        .bus_num = 0,

        .chip_select = 6,

        .platform_data = &bfin_mmc_spi_pdata,

        .controller_data = &mmc_spi_chip_info,

        .mode = SPI_MODE_3,

    },

#endif

 

 

 

I've attached a couple of files to this post. A menuconfig config file (config_fvh) and a board configuration file (ezbrd.c, our edited version of it).

 

The only theory we've managed to come up with is that the mmc code is searching for a card, and when it's unable to find one using mode 3, it tries again with mode 7. Hopefully we're wrong and it's just a silly misconfiguration on our part. But nothing that we've been able to find. Any help would be appreciated. Thanks.

 

config_fvh

ezbrd.c

QuoteReplyEditDelete

 

 

2009-09-27 05:36:25     Re: Fault when enabling MMC support

Yi Li (CHINA)

Message: 80523   

 

Frank,

 

I think the spi_bf5xx.c has a bug in bfin_spi_setup():

 

1. Why "mode 0x7"?

 

mmc_spi.c:  mmc_spi_initsequence()

 

    host->spi->mode |= SPI_CS_HIGH;

    if (spi_setup(host->spi) != 0) {

        /* Just warn; most cards work without it. */

        dev_warn(&host->spi->dev,

                "can't change chip-select polarity\n");

        host->spi->mode &= ~SPI_CS_HIGH;

    }

 

The mmc_spi will try to test whether SPI_CS_HIGH works, if not, it give a warning. SPI_MODE_3 | SPI_CS_HIGH we got 0x7.

 

2. Why null pointer exception:

 

bfin_spi_setup():

 

        /* Abort device setup if requested features are not supported */

        if (spi->mode & ~(SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST)) {

                dev_err(&spi->dev, "requested mode not fully supported\n");

                goto error;

        }

 

 

error:

 

Something bad may happen at error handling code.  Can you see what happened at "_bfin_spi_setup + 0xd0"?

 

-Yi

QuoteReplyEditDelete

 

 

2009-09-27 05:46:06     Re: Fault when enabling MMC support

Yi Li (CHINA)

Message: 80524   

 

Ok. I think the NULL pointer exception is caused by:

 

bfin_spi_setup():

 

error:

 

  if ((chip->chip_select_num > 0)       <------------ chip is still NULL at the moment.

 

I will fix this - but it is interesting why this bug is not triggered before (we have tested mmc_spi a lot on 2009R1) - I will have a check.

 

-YI

QuoteReplyEditDelete

 

 

2009-09-27 18:26:27     Re: Fault when enabling MMC support

Frank Van Hooft (CANADA)

Message: 80530   

 

Hi Yi,

 

Thanks very much for your efforts to hunt & fix this bug!

 

As for your wondering why it hasn't turned up before, the only thought I have is perhaps it's somehow specific to a BF52x configuration? I've noticed that both the BF526-EZBOARD and the BF527-EZKIT do not have SD card sockets on them. In which case, perhaps MMC has never been tested on BF52x before?  I don't know; it's only a guess.

QuoteReplyEditDelete

 

 

2009-09-28 00:23:58     Re: Fault when enabling MMC support

Yi Li (CHINA)

Message: 80537   

 

Frank,

 

This bug is caused by my commit to spi_bf5xx.c on 2009R1 branch. I've fixed this on the branch. You may update you 2009R1 branch or use this patch:

 

--- branches/2009R1/drivers/spi/spi_bfin5xx.c    2009-09-28 03:16:01 UTC (rev 7478)

+++ branches/2009R1/drivers/spi/spi_bfin5xx.c    2009-09-28 04:03:38 UTC (rev 7479)

@@ -1240,6 +1240,9 @@

 

  error:

     if (ret) {

+        if (!chip)

+            return ret;

+

         if (drv_data->dma_requested)

             free_dma(drv_data->dma_channel);

         drv_data->dma_requested = 0;

 

 

 

-Yi

QuoteReplyEditDelete

 

 

2009-09-28 01:19:19     Re: Fault when enabling MMC support

Frank Van Hooft (CANADA)

Message: 80541   

 

Looks good Yi. I can see it try a couple of times with mode 3, then it tries mode 7, without crashing (!), then it tries a whole bunch more times with mode 3, and then presumably it gives up (as it should, because there's certainly no card there right now). Here's the boot messages:

 

 

 

<snip>

bfin_spi_setup() mode 0x3                                                                                              

m25p80 spi0.1: m25p32 (4096 Kbytes)                                                                                    

Creating 3 MTD partitions on "ST m25p32":                                                                              

0x00000000-0x00030000 : "bootloader(spi)"                                                                              

0x00030000-0x003f0000 : "linux kernel(spi)"                                                                            

0x003f0000-0x00400000 : "config block(spi)"                                                                            

bfin_spi_setup() mode 0x3                                                                                              

bfin-spi bfin-spi.0: Blackfin on-chip SPI Controller Driver, Version 1.0, regs_base@ffc00500, dma channel@7            

rtc-bfin rtc-bfin: rtc core: registered rtc-bfin as rtc0                                                               

i2c /dev entries driver                                                                                                

i2c-bfin-twi i2c-bfin-twi.0: Blackfin BF5xx on-chip I2C SCCB TWI Controller, regs_base@ffc01400                        

bfin-wdt: initialized: timeout=20 sec (nowayout=0)                                                                     

bfin_spi_setup() mode 0x3                                                                                              

mmc_spi spi0.6: ASSUMING 3.2-3.4 V slot power                                                                          

mmc_spi spi0.6: SD/MMC host mmc0, no DMA, no WP, no poweroff

bfin_spi_setup() mode 0x7

mmc_spi spi0.6: requested mode not fully supported

mmc_spi spi0.6: can't change chip-select polarity

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

rtc-bfin rtc-bfin: setting system clock to 1971-06-04 00:48:13 UTC (44844493)

Freeing unused kernel memory: 2636k freed

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

bfin_spi_setup() mode 0x3

hostname: not found

<snip>

 

 

 

Looks good to me. Thanks very much!

QuoteReplyEditDelete

 

 

2009-09-28 04:32:43     Re: Fault when enabling MMC support

Yi Li (CHINA)

Message: 80562   

 

Also, when using spi_lock_bus(), please be aware of bug [#5551] -   blackfin.uclinux.org/gf/project/uclinux-dist/tracker/?action=TrackerItemEdit&tracker_id=141&tracker_item_id=5551.

 

This bug has been fixed on brach and trunk - so please update your svn branch.

 

-Yi

Attachments

Outcomes