S3C2440 + Linux 2.6.18
驅動缺少寫保護檢測,s3c2410sdi_ops 結構中 get_ro 回調未實現。
static struct mmc_host_ops s3c2410sdi_ops = {
.request = s3c2410sdi_request,
.set_ios = s3c2410sdi_set_ios,
.get_ro = s3c2440_get_ro, // 新增:SD 卡唯讀標誌
};
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;
}
熱插拔中斷檢測等功能只需相應配置即可正常使用。
寫入較大檔案時程式掛起,打印:
[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
對比正常傳輸發現:寫入 4096 位元組(512×8)只寫入第一個 512 位元組就停止,dcnt 卡在 7000。
程式將 host->pio_words 固定為 128,遞減至 0 後不再進入迴圈:
while (sdi_fsta & S3C2410_SDIFSTA_TFDET && host->pio_words)
// 原代碼
host->pio_words = sdi_bsize >> 2;
// 修正為
host->pio_words = mrq->data->blocks * (sdi_bsize >> 2);
修正後寫操作正常完成,但寫入速度仍有提升空間。
複製檔案到 SD 卡後執行 umount,終端提示符延遲出現。
sync 強制將緩衝區所有資料寫入磁碟。若緩衝區未刷新即關機,檔案系統處於不穩定狀態。
syncumount 才觸發 syncreboot -n(不執行 sync 重啟)驗證上述行為cp 完成後先執行 sync 刷新緩衝區,再 umount,避免延遲