Tip: Linux2.6.18SD card driver correction

Source: Internet
Author: User
Article Title: tip: Correction of the Linux2.6.18SD card driver. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Platform: s3c2440 + linux 2.6.18

In linux2.6.18, the SD card driver has many bugs. For example, there is no write protection function.

Write-protected functions are reserved in the driver module, but they are not implemented, and the code is only a few lines. It is okay to add the compiled functions.

        
         static struct mmc_host_ops s3c2410sdi_ops = {.request = s3c2410sdi_request,.set_ios = s3c2410sdi_set_ios,.get_ro = s3c2440_get_ro, //sd card ReadOnly Flag.};
        

The implementation functions are as follows:

        
         static int s3c2440_get_ro(struct mmc_host *mmc){struct s3c2410sdi_host *host = mmc_priv(mmc);unsigned long flags;int present;spin_lock_irqsave(&host->complete_lock, flags);present = read_gpio_bit(S3C2410_GPB0); present &= 0x01;spin_unlock_irqrestore(&host->complete_lock, flags);return present;}
        

There are also some hot swapping and interrupt detection ports. You only need to set them to use them.

It is troublesome to write to the SD card. If you write a file slightly larger than the SD card, an error occurs and the following information is printed:

        
         [IRQ] csta=00000a19 dsta=00000002 fsta=00002200 dcnt=00008000[IRQ] csta=00000a19 dsta=00000002 fsta=00002200 dcnt=00007000[IRQ] csta=00000a19 dsta=00000002 fsta=00002200 dcnt=00007000[IRQ] csta=00000a19 dsta=00000002 fsta=00002200 dcnt=00007000
        

Compared with the printed information transmitted normally, it is obvious that the program is suspended here.

Later, we tracked the code and found that when we write 4096 (512*8) data, we do not write down the first 512byte, so the dcnt is always 7000, this occurs because the program assigns a value of 128 to the host-> pio_words variable, and does not enter when it is reduced to 0 through host-> pio_words --

While (sdi_fsta & S3C2410_SDIFSTA_TFDET & host-> pio_words,

So host-> pio_words = sdi_bsize> 2; this line should be changed

Host-> pio_words = mrq-> data-> blocks * (sdi_bsize> 2 );

In this way, the write operation on the SD card is solved, but the write speed is not very fast.

Another question is, for example, if a cp file is written to the SD card, do you first write the file to the SDRAM, and then write the content in the SDRAM to the SD card during umount ?? When I use umount, the terminal prompt will appear too long. How long is the umount time determined based on the size of the written file?

Later, I checked the information. Linux file system update is a complicated process. After the user program modifies the file system, for example, a write operation is performed, file data records modifications in the kernel buffer. when the data is not written to the disk, the user process can still be executed. All data changes are reflected in the inode content. The disk data is actually updated asynchronously. It is very likely that the disk data will be updated after the write operation is completed for a long time. The sync Command forces all data cached on the disk to be written to the disk. if the system is terminated before the disk buffer information is written to the disk, the file system of the disk is in an unstable state. In normal mode, even if no umount operation is performed on the partition, the system will call the sync command to forcibly write all data cached on the disk to the disk before the restart, in emergency mode, the system must perform the umount operation on the mounted partition before calling the sync command to forcibly write all data cached on the disk to the disk, please pay attention to this problem in emergency mode. In fact, the "reboot-n (Don't sync before reboot or halt)" command does not require the sync command to forcibly write all the data cached on the disk to the disk before restart, which can easily explain the problem.

Therefore, after cp is complete, execute the sync command to write the buffer content to the disk, and then umount will not be delayed.

S3c2440 SD card (for LINUX) driver code:

Http://handhelds.org/cgi-bin/cvsweb.cgi/linux/kernel26/drivers/mmc/s3c2440mci.c

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.