Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

mounting SD Card on uClinux

Altera_Forum
Geehrter Beitragender II
9.331Aufrufe

Hi everyone, 

I'm trying to implement a fat file system on sd card 

I followed the instructions for Altera SPI Core on this page 

http://www.nioswiki.com/operatingsystems/uclinux/mmcsd 

didn't work... 

 

was I suppose to use SPI (3 wire) IP? 

 

thanks, 

Asaf
0 Kudos
37 Antworten
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Could give me you *.config of uclinux and your quartus project? 

thx for u help! 

MSN: maojunjie@sina.com
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Do you use a NEEK board ?  

I loaded the Quartus Design from the appropriate NiosWiki page.  

Which .config file are you talking about. There are many of them. 

 

-Michael
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

I use altera DE1 board,and use spi(three wire) IP ,and do you have *.config of kernel ,for sd card.

Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

 

--- Quote Start ---  

ok, now it's officialy closed! 

I just needed to format my sd card using mkfs.vfat command 

or through windows :S 

 

anyway, thanks for all your help and support! :D 

--- Quote End ---  

 

Don't close yet, I have a question on mouting the SD card too. I am sorry that I use ColdFire but seems people here are familiar with uClinux. 

 

I can't even see anything that the system is probing the sd card. I use QSPI from the coldfire and I choosed the MMC/SD/SDIO and used the MMC over spi. I can see the block devices in dev, but can't mount them with "mounting /dev/mmcblk0p1 on /mnt/sd failed: no such device or address" message. Whatelse do you need for the os to probe sd card on spi when boot? 

 

Some one mentioned modprobe, how to configure that into uClinux? 

 

It seems that I need to change some source files in C to let the kernel probe the SD card using spi, right? Thanks!
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

 

--- Quote Start ---  

ok, here's an update 

it appears that there's a BIG difference between  

[*] and <M> (my bad;) ) 

so the good news are that it worked only when I selected my options as  

[*] 

the bad new are... well... when I use 

 

mount -t vfat /dev/mmcblk0 /mnt 

 

I get Invalid argument error 

any ideas? 

--- Quote End ---  

 

 

Hi,  

 

I have the same situation where if i set the driver for "MMC/SD card support" as a module "[M]" the mounts do not work but if i just enable it as [*] it does. I need this feature to be a module so i would appreciate if anybody could point me in the right direction to solve this.  

 

I played with the settings of "Enable loadable module support" but so far no luck.  

 

I am using "FPS-Tech SD Host" and i set the following: 

 

Device Drivers -->  

(if i make these settings [*] it works...) 

[M] MMC/SD card support --->  

[M] MMC block device driver  

[ ] Use bounce buffer for simple hosts  

[ ] SDIO UART/GPS class support  

[ ] MMC host test driver  

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

[M] NIOS SD/SDIO/MMC Host  

 

File systems --->  

 

[*] Ext3 journalling file system support  

 

DOS/FAT/NT Filesystems ---> 

[*] VFAT (Windows-95) fs support 

(437) Default codepage for FAT 

(iso8859-1) Default iocharset for FAT 

 

-*- Native language support --->  

[*] Codepage 437 (United States, Canada) 

[*] NLS ISO 8859-1 (Latin 1; Western European Languages) 

 

Thanks in advance for your help
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

I am having a similar problem using the SPI(3-wire) IP core and uClinux. I am using DE2-115 board and tried with 4 different cards (nothing changed), also same output when using no card at all. I am using "nios2"-branch (uClinux 3.7.0+), but have tried with "v3.3-nios2 -> v3.6-nios2" with same results. 

 

mmc_spi spi32766.0: setup mode 0, 8 bits/w, 400000 Hz max --> 0 mmc0: req done (CMD58): 0: 00000000 00000000 00000000 00000000 mmc0: host doesn't support card's voltages mmc0: error -22 whilst initialising SD card  

 

My dts is configured as follows: 

mmc_spi: spi <at> 0x10003420 { compatible = "ALTR,spi-12.0", "ALTR,spi-1.0"; reg = < 0x10003420 0x00000020 >; interrupt-parent = < &cpu >; interrupts = < 2 >; mmc-slot <at> 0 { compatible = "mmc-spi-slot"; reg = < 0x00000000 >; voltage-ranges = <3300 3300>; spi-max-frequency = <2000000>; }; };  

 

I have really checked all the wire connections multiple times. They are connected as follows: 

SD_DAT --> MISO SD_CMD <-- MOSI SD_CLK <-- SCLK SD_DAT <-- SS_N  

 

Any hints or suggestions on what I am doing wrong is appreciated. Thank you.
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

 

--- Quote Start ---  

well, I'm still stuck 

I thought I'd see something like this 

 

on boot, as ashown in nioswiki 

so I thought of a few possible problems 

1. pin assignments 

2. IP core not configured as should 

3. driver not loaded 

 

now I'm down to either it's an IP problem or driver problem 

so just to make sure again 

it is Altera's SPI (3 wire interface) IP, right? not someone else's similar IP? 

and if so could someone show me the right configuration? 

 

Thanks again, 

Asaf 

--- Quote End ---  

 

 

Hi, 

 

I am having the same issue and don't see this message which I am supposedly see when boot up. 

mmc_spi spi2.0: assuming spi bus stays unshared! 

mmc_spi spi2.0: assuming 3.2-3.4 v slot power 

mmc_spi spi2.0: sd/mmc host mmc0, no dma, no wp, no poweroff 

 

I follow exactly the recommended setting, but still don't see the message at the bootup 

 

Device Drivers ---> 

[*] SPI support ---> 

[*] Altera SPI Controller Device Drivers ---> 

[*] MMC/SD card support ---> 

[*] MMC/SD over SPI File systems ---> 

[*] Ext3 journalling file system support File systems ---> DOS/FAT/NT Filesystems ---> 

[*] VFAT (Windows-95) fs support File systems ---> -*- Native language support ---> 

[*] Codepage 437 (United States, Canada) File systems ---> -*- Native language support ---> 

[*] NLS ISO 8859-1 (Latin 1; Western European Languages) 

 

On the hdl side in quartus, the pin out as follow 

input wire SD_DAT, // sd.MISO 

output wire SD_CMD, // .MOSI 

output wire SD_CLK, // .SCLK 

output wire SD_DAT3, // .SS_n 

.... 

my_NIOS_mmc_spi mmc_spi ( 

.clk (mypll_c2_clk), // clk.clk 

.reset_n (~rst_controller_002_reset_out_reset), // reset.reset_n 

.data_from_cpu (mmc_spi_spi_control_port_translator_avalon_anti_slave_0_writedata), // spi_control_port.writedata 

.data_to_cpu (mmc_spi_spi_control_port_translator_avalon_anti_slave_0_readdata), // .readdata 

.mem_addr (mmc_spi_spi_control_port_translator_avalon_anti_slave_0_address), // .address 

.read_n (~mmc_spi_spi_control_port_translator_avalon_anti_slave_0_read), // .read_n 

.spi_select (mmc_spi_spi_control_port_translator_avalon_anti_slave_0_chipselect), // .chipselect 

.write_n (~mmc_spi_spi_control_port_translator_avalon_anti_slave_0_write), // .write_n 

.irq (irq_synchronizer_005_receiver_irq), // irq.irq 

.MISO_to_the_mmc_spi (SD_DAT), // external.export 

.MOSI_from_the_mmc_spi (SD_CMD), // .export 

.SCLK_from_the_mmc_spi (SD_CLK), // .export 

.SS_n_from_the_mmc_spi (SD_DAT3) // .export 

); 

 

Please help! I greatly appreciated if anyone can point me to the right direction??
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Just checked my PinPlanner, these are my settings for a DE2-115 board. Maybe it'll help if you also use DE2-115. 

 

SD_CLK - PIN_AE13 

SD_CMD - PIN_AD14 

SD_DAT0 - PIN_AE14 (not SD_DAT[0] for some reason...) 

SD_DAT3 - PIN_AC14 (no SD_DAT[3] for some reason...)
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Hi, I am using the DE2-115 with uclinux v3.7 and our pin out are the same as you had stated. 

SCLK -> SD_CLK -> PIN_AE13 (Clk) 

MOSI -> SD_CMD -> PIN_AD14 (Data Input) 

MISO -> SD_DAT -> PIN_AE14 (Data output) 

SS_N -> SD_DAT3 -> PIN_AC14 (Chip Selection) 

I still don't see the mmc_spi message on the bootup screen. I check the kernel setting many times and can't think of anything I did wrong??  

 

Please help anyone!
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Have you edited your dts file with mmc-spi-slot? See section 3.2 in my uClinux_nios2.pdf document.

Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

 

--- Quote Start ---  

Have you edited your dts file with mmc-spi-slot? See section 3.2 in my uClinux_nios2.pdf document. 

--- Quote End ---  

 

 

Hi, Thanks for your respond. I got it to work and thanks to Alex Hornung.  

Problem: 

1) device tree 

spi_0: spi@0x140 { 

compatible = "ALTR,spi-altera_avalon_spi", "ALTR,spi-1.0"; 

reg = < 0x00000140 0x00000020 >; 

interrupt-parent = < &myCPU >; 

interrupts = < 3 >; 

/*# address-cells = < 1 >; */ <-comment out 

/*# size-cells = < 0 >; */ <-comment out 

 

mmc-spi@0 { <- make sure is named mmc-spi 

compatible = "mmc-spi-slot"; 

spi-max-frequency = < 10000000 >; 

reg = < 0x00000000 >; 

voltage-ranges = < 3300 3300 >; <-missing important piece  

}; //end mmc-slot@0 

}; //end spi@0x140 (mmc_spi) 

2) menuconfig - Make sure selection is [*] and not [M] 

3) of_mmc_spi.c <-there is a bug 

for (i = 0; i < num_ranges; i++) { 

const int j = i * 2; 

u32 mask; 

u32 vdd_min = be32_to_cpu(voltage_ranges[j]); 

u32 vdd_max = be32_to_cpu(voltage_ranges[j + 1]); 

 

mask = mmc_vddrange_to_ocrmask(voltage_ranges[j], 

voltage_ranges[j + 1]); 

mask = mmc_vddrange_to_ocrmask(vdd_min, vdd_max);  

 

if (!mask) { 

ret = -EINVAL; 

dev_err(dev, "OF: voltage-range# %d is invalid\n", i); 

goto err_ocr; 

oms->pdata.ocr_mask |= mask; 

}
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Hi 

When i insert the SD card i get the below message and also can't mount the SD Card 

 

root:/dev> mmc0: SD Status: Invalid Allocation Unit size. 

mmc0: host does not support reading read-only switch. assuming write-enable. 

mmc0: new SD card on SPI 

mmcblk0: mmc0:0000 SD512 478 MiB 

mmcblk0: p1 

 

root:/dev> mount -t vfat /dev/mmcblk0 /mnt 

mount: mounting /dev/mmcblk0 on /mnt failed: No such device 

root:/dev> mount -t vfat /dev/mmcblk0p1 /mnt 

mount: mounting /dev/mmcblk0p1 on /mnt failed: No such device 

root:/dev> 

 

I also format the sdcard with FAT32 and 512byte but it doesn't help 

Please give me some suggestion to fix the problem
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Hi, 

It's a good sign if you see it detect the SD Card size. I am using a 2 GB SD Card so perhaps you may want to try a bigger size memory? Also, to make sure you enabled the [*] fat32 in file system doing kernel setup. I hope this help. 

 

 

 

--- Quote Start ---  

Hi 

When i insert the SD card i get the below message and also can't mount the SD Card 

 

root:/dev> mmc0: SD Status: Invalid Allocation Unit size. 

mmc0: host does not support reading read-only switch. assuming write-enable. 

mmc0: new SD card on SPI 

mmcblk0: mmc0:0000 SD512 478 MiB 

mmcblk0: p1 

 

root:/dev> mount -t vfat /dev/mmcblk0 /mnt 

mount: mounting /dev/mmcblk0 on /mnt failed: No such device 

root:/dev> mount -t vfat /dev/mmcblk0p1 /mnt 

mount: mounting /dev/mmcblk0p1 on /mnt failed: No such device 

root:/dev> 

 

I also format the sdcard with FAT32 and 512byte but it doesn't help 

Please give me some suggestion to fix the problem 

--- Quote End ---  

Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Hi, all

May be, it's too late to answer, but my message may help someone in the future and one question still left regarding this topic. 

 

 

--- Quote Start ---  

 

Please give me some suggestion to fix the problem 

--- Quote End ---  

 

 

Well, next step is definitely simple: 

 

Lets look at the devices, configured in the system: 

 

/# cat /proc/devices Character devices: 1 mem 2 pty 3 ttyp 4 ttyS 5 /dev/tty 5 /dev/console 5 /dev/ptmx 10 misc 128 ptm 136 pts 153 spi 204 ttyUL Block devices: 1 ramdisk 259 blkext 179 mmc <--- Got it!  

 

OK, our MMC card is configured as block device and had major number 179. 

 

/# ls /sys/dev/block/ | grep 179 179:0 179:1  

 

We see two devices with major = 179. The first one with minor number 0 is MMC (SD) card itself and the second with number 1 is the first (and last in my case) partition on the card. 

The problem is that "ls /dev/" command shows nothing about MMC, but we can make device node manually via mknod command: 

 

/# mknod /dev/mmcblk0p1 b 179 1 /# mount /dev/mmcblk0p1 /mnt/ /# ls /mnt simpleImage.xilinx.ub vmlinux  

 

Thats it! 

 

Well, but I still do not know, how to make next step: say system to create /dev/mmcblk0p1 node automatically and have root partition on my SD card during boot. 

 

Thanks all for this topic, it was helpful. 

 

PS: Well, there was almost nothing magic. 

On BB: 

1. Format your SD card in ext2 or ext3. 

2. Copy busybox content into SD 

3. (For paranoics like me :) ) Create static node /dev/mmcblk0p1 on SD using mknod with major:minor numbers 179:1 

4. [MAGIC] Edit kernel boot parameters with "root=/dev/mmcblk0p1" and (this is important!) "rootdelay=3". 

The "rootdelay" parameter says kernel to wait until root partition initialization complete. Three seconds was enough in my case. [/MAGIC] 

 

Thats all, folks. :)
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Hello i am trying to implement SDCard in my DE2-115 and i've followed the steps described in the# 6 post. However i get this error in the linux boot process spi_altera: pobe of d000900.spi failed with error -16. 

There appears to be a mmc in proc/devices though. 

 

Any ideas? Can i use the default clock frequency of SPI 3 wire? I think it's 128khz. 

 

Solved it! It was a problem with EPCS ADDRESS SPAM being too high, it was going in the SPI 3 wire address spam
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

I feel like it's really slow to read/write in the SDCard. It's formated with FAT file system and my NIOS2 is running at 100mhz. 

Any tips?
Altera_Forum
Geehrter Beitragender II
1.761Aufrufe

Hi, 

 

 

--- Quote Start ---  

I feel like it's really slow to read/write in the SDCard. It's formated with FAT file system and my NIOS2 is running at 100mhz. 

Any tips? 

--- Quote End ---  

 

 

Please refer to the next, 

 

http://www.alterawiki.com/wiki/linux_with_mmu_on_veek/t-pad 

 

or 

 

http://www.alteraforum.com/forum/showthread.php?t=25605 

 

Kazu
Antworten