打印

SD卡用哪种文件系统比较好

[复制链接]
19330|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
我是土匪|  楼主 | 2009-7-2 13:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
armecos| | 2009-7-2 14:26 | 只看该作者

FAT文件系统不错,这里有免费文档,都移植好了,

只要使用就成了,管他什么OS,什么CPU,万能的。

*********************************
* 《ecos增值包》之FAT文件系统篇 *
*********************************
             ---FAT12/16/32在SD/MMC/CF/HDD等介质上的实现
        2007/10/28 asdjf@163.com www.armecos.com

    很多网友对实现FAT文件系统感兴趣,经常有人来信询问设计思路或者索要源码,其实,使用《ecos增值包》是不需要理会这些细节的,直接使用UNIX文件系统API接口就能在各种介质上完成FAT文件访问,不过,我们仍然愿意为《ecos增值包》正式用户提供这个设计思路文档。
    
    《ecos增值包》支持FAT12/16/32,标准UNIX文件系统接口,各种容量的SD/MMC/CF/HDD等介质,充分考虑到了速度、效率、容量、低功耗、简单性、安全性、可靠性、扩展性、并发访问、存储介质多样等各种性能指标参数。
    
    下面我们分四个层次逐步讲解FAT文件系统的设计思路。注意:《ecos增值包》不仅仅只支持FAT文件系统,它还支持RAMFS/ROMFS/JFFS2/Yaffs/TrueFFS等,所以下面介绍的内容是高度抽象的,不仅仅只适合于FAT文件系统。
    
    1、首先,我们介绍块设备驱动的特点和实现,抽象出SD/MMC/CF/HDD等块设备共有的特性,设计出适合现在及未来任何介质的万能块设备驱动,进而实现FAT over anything。
    
    2、接着讨论高速块设备驱动,这是体现块设备性能的关键指标。设计思路很简单,就是提供一个cache,读写数据尽量在高速cache中完成,必要时才读写真正的慢速块设备。这里用到了链表、HASH映射、排序二叉树等复杂的数据结构。
    
    3、有了高速的块设备驱动,文件系统的性能就有了物质保障,但是恰当地选择下层和上层数据结构,能进一步将性能发挥到极致。这里给出了块设备、磁盘、目录、节点等的数据结构描述。
    
    4、准备好了FAT相关的数据结构,接着就可以提供操作这些数据结构的函数,当然这是完全符合UNIX文件系统API接口的函数集合。用户可以使用简单统一的mount/open/read/write/close等API函数操作各种块设备。
    
    最后,我们说明UNIX相对DOS文件系统的优势并举例说明UNIX文件系统的使用方法。
    
    ----------
    块设备驱动
    ----------
    
    SD卡、MMC卡、CF卡、硬盘等大容量存储设备虽然介质形态不同,但都可以抽象出共同的特征。一般,此类设备以数据块方式被访问,工作过程中可能被移动改变。比如:动态插入、移除、改变设备,这就要求OS能够检测出设备是否在位,是否被删除,是否被更换成另一个设备。此外,有些设备提供了电源开关,在不需要使用时可以关闭电源以节省能量。有些设备涉及机械运动,如:硬盘磁头移动,这时采用一些软件算法可以大大提高性能,如:电梯排队算法,聚集操作等。还有,通过DMA + 中断等硬件加速方式可以进一步提高吞吐效率。ecos比Linux设备驱动强在没有复杂I/O结构,不涉及特权模式,可以直接操作设备,这样代码大小和读写效率都比较好。
    
    经过抽象,所有块设备驱动都可以总结为下面几种操作:读read、写write、设备自身属性操作ioctl(如弹出/关闭光盘托盘等)、初始化init、查找/枚举设备lookup。不同的设备操作方法不尽相同,如SD卡通过SPI总线访问设备而CF卡通过ATA接口访问,但是经过驱动程序抽象后,上层软件将看到统一的设备接口,所以不论硬盘、光盘、SD卡、CF卡,经过设备驱动抽象后对高层软件来说都是一样的。
    
    SD/MMC/CF/HDD/CDROM/DVDROM等介质的设备驱动详见各相关部分的描述,下面给出一个IDE硬盘接口函数的例子(其他介质与此类似,函数内部操作替换成特定介质要求的操作,对外接口不变,都是下面这个样子):

static cyg_bool ide_disk_init(struct cyg_devtab_entry *tab);

static Cyg_ErrNo ide_disk_read(disk_channel *chan, void *buf, cyg_uint32 len, cyg_uint32 block_num);

static Cyg_ErrNo ide_disk_write(disk_channel *chan, const void *buf, cyg_uint32 len, cyg_uint32 block_num);

static Cyg_ErrNo ide_disk_get_config(disk_channel *chan, cyg_uint32 key, const void *xbuf, cyg_uint32 *len);

static Cyg_ErrNo ide_disk_set_config(disk_channel *chan, cyg_uint32 key, const void *xbuf, cyg_uint32 *len);

static Cyg_ErrNo ide_disk_lookup(struct cyg_devtab_entry **tab, struct cyg_devtab_entry *sub_tab, const char *name);

    --------------
    高速块设备驱动
    --------------
    
    仅有块设备驱动还是远远不够的,因为这些大容量存储设备相对CPU而言都是慢速设备,如果不采取任何措施直接访问,那么效果会非常不令人满意。更何况现代的虚拟存储系统会把内存中暂时不需要的数据转移到硬盘上,从而模拟出一个比实际大得多的内存,所以,块设备驱动不仅与文件系统性能有关,还和OS虚拟内存性能有关。如何实现高速大容量数据访问呢?一个非常有效的办法就是通过内存提供一块CACHE暂存数据,读写数据尽量在高速cache中完成,必要时才读写真正的慢速大容量块设备。这种方法存在一定的风险,如果在数据真正写入设备前掉电,那么cache缓存里的数据将丢失。
    
    上面笼统地说到要缓存数据,但是何时缓存,怎么缓存,切入点在什么地方并没有说清楚。其实具体到FAT文件系统里,就是要缓存FAT表数据、文件目录和文件数据。其他一些数据,如引导信息等在设备枚举初始化后就被存到相应的设备信息结构体里了,以后再访问这些数据直接从这些结构体里提取即可,不需要每次都重新读设备。
    
    先说说FAT表是如何缓存的吧。一般来说FAT表大小不固定,FAT表数量也可以有多个(用于冗余备份,提高安全性),而且操作频繁,属于关键数据,但是如果一次将整个FAT表缓存,首先不知道整个FAT表有多大,数量有多少,即使知道这些,内存可能也装不下整个FAT表,况且只有少部分FAT信息被用到,那么怎么缓存FAT表才是最佳的呢?办法就是只缓存用到的一小块FAT信息,把整个FAT表打散成一个个小碎片,用到哪块就缓存哪块。问题又来了,你是如何知道某个小碎片对应哪个FAT表片段啊?如果内存不够用了该怎么办啊?
    
    呵呵,这就要用到一系列的复杂数据结构了。FAT表里使用“簇”来描述信息,而内存中使用内存块来表述,所以,首先要写一个“簇号<-->块号”的互换函数,使得FAT信息和内存块对应起来。然后把缓存的FAT碎片用链表连接起来,以后每次读写FAT信息时,先在这个链表里查找该FAT信息是否已经被缓存,判断方法是把簇号转换成块号,在链表里搜索有无相同块号的内存块,如果有相同块号的内存块,就说明此FAT片段先前已经被缓存。与此同时,把该块内存块移动到链表头部,根据临近相关原理,下次被搜索的概率最大,因为离头部最近,所以可以提高搜索效率和命中率。如果内存不够用了,那么首先释放链表末尾的数据块,因为那个位置的内存块意味着最长时间没有被访问过。如果事先将各个内存块连成排序二叉树,那么查找速度还会提升。任何写入的FAT信息将被同时写入多个FAT表里。
    
    说完FAT表这个最关键的数据缓存,接着就要说说文件目录的缓存。和通过簇号信息访问FAT表不同,目录是通过路径名访问的,那么如何通过路径名得知目录是否被缓存呢?ecos文件系统和UNIX文件系统一样,把文件和目录抽象成节点node,在node里保存相关信息。从文件名映射到节点的最好办法就是HASH映射。

static unsigned int 
hash_fn(const char *str, unsigned int strlen)
{
    unsigned int i = 0, val = 0;

    while (i++ < strlen)
        val = (val ^ (int)toupper(*str++)) << 1;
    return(val);
}

    通过上面提供的HASH算法,给出文件路径名和其长度,立即可以得到节点号。如:node = hash_fn(filename, filenamelen)。HASH算法可能产生碰撞,此时需进一步调整,不过总体而言,映射效率很高。文件名比较时先比较长度再比较文件名字串,这样速度快。通过node_hash_find()函数可以立即判断目录是否已在缓存里。
    
    最后说下文件数据缓存。FAT文件对应簇号,只要根据簇号找到内存块就可以找到数据缓存,和FAT表的缓存原理一样。
    
    读数据时,先判断cache缓存里是否已存在,如果存在就直接读取数据,否则,从真实设备中读取数据并缓存;
    写数据时,直接写入cache中,没有就创建一个内存缓存块,当释放缓存时,数据写入实际设备中。只要在缓存链表里的数据肯定都是“脏”的。
    
    通过缓存FAT表片段、文件目录项、文件数据,大容量慢速存储设备就被虚拟成了一个高速的块设备。
    
    -----------------------
    FAT文件系统相关数据结构
    -----------------------
    
    有了高速的块设备驱动,接下来就要在上面实现FAT文件系统,这时,看到的块设备就是统一的FAT格式,FAT文件系统的本意也就是在块设备上以FAT格式组织文件信息。FAT文件系统的操作对象就是一堆数据结构。
    
    首先介绍一个宏定义:DISK_INSTANCE(_number_,_port_,_chan_,_mbr_supp_,_name_)
    不同的介质支持的FAT结构略有不同,如软盘和CF卡不支持MBR而SD卡和硬盘就支持。有些设备格式化为几个逻辑分区,每个分区都要用一个名字对应。这个宏就是用来通知OS介质支持的具体FAT格式的。如:

DISK_INSTANCE(0, 0, 0, true, "/dev/hda/");
DISK_INSTANCE(1, 0, 1, true, "/dev/hdb/");
DISK_INSTANCE(2, 1, 0, true, "/dev/hdc/");
DISK_INSTANCE(3, 1, 1, true, "/dev/hdd/");

    就表示支持4个硬盘,IDE0的主从,IDE1的主从,均支持MBR,其设备名后缀依次为a、b、c、d。
    
    文件目录项结构体
typedef struct fatfs_dir_entry_s
{
    char              filename[12+1]; // File name
    mode_t            mode;           // Node type
    size_t            size;           // Size of file in bytes
    time_t            ctime;          // Creation timestamp
    time_t            atime;          // Last access timestamp
    time_t            mtime;          // Last write timestamp
    cyg_uint8         priv_data;      // Private data
    cyg_uint32        cluster;        // First cluster number
    cyg_uint32        parent_cluster; // First cluster of parent dentry
    fatfs_data_pos_t  disk_pos;       // Position of dir entry on disk
#ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
    cyg_fs_attrib_t    attrib;     // Attribute bits for DOS compatability
#endif //CYGCFG_FS_FAT_USE_ATTRIBUTES
} fatfs_dir_entry_t;


    存储设备全局结构体
typedef struct fatfs_disk_s
{
    cyg_uint32    sector_size;          // Sector size in bytes
    cyg_uint32    sector_size_log2;     // Sector size log2
    cyg_uint32    cluster_size;         // Cluster size in bytes
    cyg_uint32    cluster_size_log2;    // Cluster size log2 
    cyg_uint32    fat_tbl_pos;          // Position of the first FAT table
    cyg_uint32    fat_tbl_size;         // FAT table size in bytes
    cyg_uint32    fat_tbl_nents;        // Number of entries in FAT table
    cyg_uint32    fat_tbls_num;         // Number of FAT tables
    cyg_uint32    fat_root_dir_pos;     // Position of the root dir
    cyg_uint32    fat_root_dir_size;    // Root dir size in bytes 
    cyg_uint32    fat_root_dir_nents;   // Max number of entries in root dir
    cyg_uint32    fat_root_dir_cluster; // Cluster number of root dir (FAT32) 
    cyg_uint32    fat_data_pos;         // Position of data area
    fatfs_type_t  fat_type;             // Type of FAT - 12, 16 or 32 
    
    cyg_io_handle_t  dev_h;           // Disk device handle
    fatfs_node_t    *root;            // Root dir node

    cyg_uint8       *bcache_mem;      // Block cache memory base
    cyg_blib_t       blib;            // Block cache and access library instance

    fatfs_node_t  node_pool_base[FATFS_NODE_POOL_SIZE]; // Node pool base   
    fatfs_node_t *node_pool[FATFS_NODE_POOL_SIZE];      // Node pool 
    cyg_uint32    node_pool_free_cnt;                   // Node pool free cnt
    
    fatfs_node_list_t  live_nlist;    // List of nodes with refcnt > 0
    fatfs_node_list_t  dead_nlist;    // List of nodes with refcnt == 0
    fatfs_hash_table_t node_hash;     // Hash of nodes in live and dead lists
} fatfs_disk_t;

    上面论述的是FAT文件系统最重要的几个内部结构体,原始的FAT结构在相关标准参考里有详细描述,这里不再赘述。
    
    ----------------
    UNIX文件系统接口
    ----------------
    
    上面提供了FAT文件系统的数据结构,下面提供操作这些数据结构的接口函数,它们都符合UNIX标准。

// 文件系统操作Filesystem operations
static int fatfs_mount  (cyg_fstab_entry *fste, cyg_mtab_entry *mte);
static int fatfs_umount (cyg_mtab_entry *mte);
static int fatfs_open   (cyg_mtab_entry *mte, cyg_dir dir, const char *name, int mode, cyg_file *fte);
static int fatfs_unlink (cyg_mtab_entry *mte, cyg_dir dir, const char *name);
static int fatfs_mkdir  (cyg_mtab_entry *mte, cyg_dir dir, const char *name);
static int fatfs_rmdir  (cyg_mtab_entry *mte, cyg_dir dir, const char *name);
static int fatfs_rename (cyg_mtab_entry *mte, cyg_dir dir1, const char *name1, cyg_dir dir2, const char *name2 );
static int fatfs_link   (cyg_mtab_entry *mte, cyg_dir dir1, const char *name1, cyg_dir dir2, const char *name2, int type);
static int fatfs_opendir(cyg_mtab_entry *mte, cyg_dir dir, const char *name, cyg_file *fte );
static int fatfs_chdir  (cyg_mtab_entry *mte, cyg_dir dir, const char *name, cyg_dir *dir_out );
static int fatfs_stat   (cyg_mtab_entry *mte, cyg_dir dir, const char *name, struct stat *buf);
static int fatfs_getinfo(cyg_mtab_entry *mte, cyg_dir dir, const char *name, int key, void *buf, int len );
static int fatfs_setinfo(cyg_mtab_entry *mte, cyg_dir dir, const char *name, int key, void *buf, int len );

// 文件操作File operations
static int fatfs_fo_read   (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
static int fatfs_fo_write  (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
static int fatfs_fo_lseek  (struct CYG_FILE_TAG *fp, off_t *pos, int whence );
static int fatfs_fo_ioctl  (struct CYG_FILE_TAG *fp, CYG_ADDRWORD com, CYG_ADDRWORD data);
static int fatfs_fo_fsync  (struct CYG_FILE_TAG *fp, int mode );        
static int fatfs_fo_close  (struct CYG_FILE_TAG *fp);
static int fatfs_fo_fstat  (struct CYG_FILE_TAG *fp, struct stat *buf );
static int fatfs_fo_getinfo(struct CYG_FILE_TAG *fp, int key, void *buf, int len );
static int fatfs_fo_setinfo(struct CYG_FILE_TAG *fp, int key, void *buf, int len );

// 目录操作Directory operations
static int fatfs_fo_dirread (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
static int fatfs_fo_dirlseek(struct CYG_FILE_TAG *fp, off_t *pos, int whence);

    依次完成上面的各个函数就可以实现FAT文件系统。除了这些内容,还需要一些辅助函数,如:UNIX-DOS时间格式转换、FAT簇操作、FAT项类型判断等。
    
    -------------------------
    UNIX相对DOS文件系统的优势
    -------------------------
    
    1、标准的文件系统API接口,Linux里的大量现成源码能很容易地移植到ecos系统中;
    
    2、信息隐藏得比较好。挂装操作可以把任何介质上的任何文件系统挂装到任何目录,用户看到的只是统一的目录,不会感觉到介质差异,有利于编程操作。而DOS文件系统要指定驱动器,暴露了底层细节,程序移植性差。
    
    3、支持多任务并发。DOS是单任务的,独占系统,本质上不支持多任务。UNIX天然支持多用户多任务并发访问。
    
    --------------------
    如何使用ecos文件系统
    --------------------
    
    1、挂装
    
    文件系统使用前需要挂装操作,即把某介质上的某文件系统挂装到某目录,函数如下所示:
    mount(设备名,挂装目录,文件系统名),如:
    
    挂装RAM文件系统,设备名恒为空,挂装在根目录:
    err = mount( "", "/", "ramfs" );
    
    挂装FAT文件系统,设备名为/dev/hda/硬盘,挂装在根目录:
    err = mount( "/dev/hda/", "/", "fatfs" ); //hda后一定要加“/”,否则挂不上
    
    2、打开
    
    访问任何文件前先按某种属性打开并获得句柄。
    open(文件名,打开属性)
    
    以只读方式打开文件filename,返回句柄fd:
    fd = open(filename, O_RDONLY);
    
    3、读写
    
    (文件句柄,缓冲区,长度),返回实际读出/写入的数据长度
    
    len = read(fd, buf, len);
    len = write(fd, buf, len);
    
    4、关闭
    
    关闭文件,导致缓存数据实际写入存储设备。
    close(文件句柄)
    
    close(fd);
    
    5、卸载
    
    卸载整个文件系统,导致缓存数据实际写入存储设备。
    err = umount(挂装目录);
    
    err = umount( "/" );
    
    由上可见,《ecos增值包》文件系统的使用是相当简单容易的,www.armecos.com免费下载提供bin演示程序,有EASYARM2200或者SMARTARM2200开发板并对文件系统感兴趣的网友,可以尝试使用,该演示支持ROMFS/RAMFS/CF/SD/等介质,使用上面介绍的文件系统进行开发。除此之外,《ecos增值包》还提供其他文件系统支持,各种bootloader,多种完整TCP/IP协议栈,USB、GUI、VxWorks等内容,一揽子解决嵌入式开发遇到的各种问题。

使用特权

评论回复
板凳
armecos| | 2009-7-2 14:26 | 只看该作者

SD卡驱动测试

********************
* SD卡驱动程序设计 *
********************
                 ------《ecos增值包》之SD卡驱动
    2006/09/17   asdjf@163.com  www.armecos.com

------------
SD卡驱动测试
------------

一张512M的SD卡,格式化成FAT32,创建两个文本文件:
a.txt
    1234567890
b.txt
    abcdefghijklmn
用winhex软件分析,FAT1位于32扇区,a.txt文件位于1980扇区,b.txt文件位于1988扇区,当然启动部分就固定在0扇区。
下面是用SD卡驱动读出的识别信息CID、CSD、0扇区数据、32扇区数据、1980扇区数据、1988扇区数据,和winhex的数据对比,完全一致。

SD卡先关电源再打开,初始化硬件,检测卡是否插入,接着发送复位命令、激活初始化处理命令、读取并解析CID、读取并解析CSD、设置SPI时钟为最大值、设置读写块长度。(其他如OCR、SCR、CRC校验等省略。)每个命令都给出了命令、参数、应答信息,同时给出编码封装后的字节序。每个命令都超时等待应答成功,有写命令的应答带有返回数据。

SD卡测试程序分析了MBR信息,准确读出了几个特定扇区的数据。接着向指定的100扇区强制写入固定数据,再读出来,结果数据一致。在完成写入命令后,还需要等待数据写入完成,写入扇区需要相对比较长的时间,这里使用忙等待模式(更快的可以使用异步模式,完成写命令后先处理其他任务,不必一直等待写数据完成)。

经测试,寄存器读、数据读写均正确完成。

test by yangyi
2007/09/17

+


    *******************************
    *        SD Card Test         *
    *******************************

Power down!
Power up!

Card insert

Request 40 00 00 00 00 95 ff
Sent command cmd = 00 arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 01
Request 41 00 00 00 00 ff ff
Sent command cmd = 01 arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 01
Request 41 00 00 00 00 ff ff
Sent command cmd = 01 arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 01
Request 41 00 00 00 00 ff ff
Sent command cmd = 01 arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 01
Request 41 00 00 00 00 ff ff
Sent command cmd = 01 arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 01
Request 41 00 00 00 00 ff ff
Sent command cmd = 01 arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
Request 4a 00 00 00 00 ff ff
Sent command cmd = 0a arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
mmc_spi_read_data(): got data and CRC 4a 36


CID data: 27 50 48 53 44 35 31 32 11 21 f0 56 01 00 68 ab
CID data: register
        : Manufacturer ID       : MID = 0x27
        : OEM/Application ID    : OID = 0x5048
        : Product name          : PNM = SD512
        : Product revision      : PRV = hwrev(0x01)  fwrev(0x01)
        : Product serial number : PSN = 0x21f05601
        : Manufacturing date    : MDT = 2006-08


Request 49 00 00 00 00 ff ff
Sent command cmd = 09 arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
mmc_spi_read_data(): got data and CRC 53 78


CSD data: 00 4f 00 32 5f 59 83 ca f6 db 7f 87 8a 40 00 2d
CID data: register
        : Data read time parameter1 : TAAC                 = 40000000ns
        : Data read time parameter2 : NSAC                 = 0
        : Max data transfer rate    : TRAN_SPEED           = 25000000Hz
        : Card command class        : CCC                  = 5f5
        : Card capacity             : C_SIZE、C_SIZE_MULT  = 994304 Blocks (485MB)
        : Max read data length      : READ_BL_LEN          = 9
        : Read block partial enable : READ_BL_PARTIAL      = 1
        : Write block misalign      : WRITE_BLK_MISALIGN   = 0
        : Read block misalign       : READ_BLK_MISALIGN    = 0
        : Write speed factor        : R2W_FACTOR           =  1
        : Max write data length     : WRITE_BL_LEN         = 9
        : Write block partial enable: WRITE_BL_PARTIAL     = 0


mmc_spi_read_disk_block(0): sending command
Request 51 00 00 00 00 ff ff
Sent command cmd = 11 arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
mmc_spi_read_disk_block(0): reading data token/data/crc
mmc_spi_read_data(): got data and CRC 96 bc


MBR dump
0000: eb 58 90 4d  53 44 4f 53  35 2e 30 00  02 08 20 00
0010: 02 00 00 00  00 f8 00 00  3f 00 ff 00  00 00 00 00
0020: 00 2c 0f 00  ca 03 00 00  00 00 00 00  02 00 00 00
0030: 01 00 06 00  00 00 00 00  00 00 00 00  00 00 00 00
0040: 00 00 29 cb  90 87 a8 4e  4f 20 4e 41  4d 45 20 20
0050: 20 20 46 41  54 33 32 20  20 20 33 c9  8e d1 bc f4
0060: 7b 8e c1 8e  d9 bd 00 7c  88 4e 02 8a  56 40 b4 08
0070: cd 13 73 05  b9 ff ff 8a  f1 66 0f b6  c6 40 66 0f
0080: b6 d1 80 e2  3f f7 e2 86  cd c0 ed 06  41 66 0f b7
0090: c9 66 f7 e1  66 89 46 f8  83 7e 16 00  75 38 83 7e
00a0: 2a 00 77 32  66 8b 46 1c  66 83 c0 0c  bb 00 80 b9
00b0: 01 00 e8 2b  00 e9 48 03  a0 fa 7d b4  7d 8b f0 ac
00c0: 84 c0 74 17  3c ff 74 09  b4 0e bb 07  00 cd 10 eb
00d0: ee a0 fb 7d  eb e5 a0 f9  7d eb e0 98  cd 16 cd 19
00e0: 66 60 66 3b  46 f8 0f 82  4a 00 66 6a  00 66 50 06
00f0: 53 66 68 10  00 01 00 80  7e 02 00 0f  85 20 00 b4
0100: 41 bb aa 55  8a 56 40 cd  13 0f 82 1c  00 81 fb 55
0110: aa 0f 85 14  00 f6 c1 01  0f 84 0d 00  fe 46 02 b4
0120: 42 8a 56 40  8b f4 cd 13  b0 f9 66 58  66 58 66 58
0130: 66 58 eb 2a  66 33 d2 66  0f b7 4e 18  66 f7 f1 fe
0140: c2 8a ca 66  8b d0 66 c1  ea 10 f7 76  1a 86 d6 8a
0150: 56 40 8a e8  c0 e4 06 0a  cc b8 01 02  cd 13 66 61
0160: 0f 82 54 ff  81 c3 00 02  66 40 49 0f  85 71 ff c3
0170: 4e 54 4c 44  52 20 20 20  20 20 20 00  00 00 00 00
0180: 00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00
0190: 00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00
01a0: 00 00 00 00  00 00 00 00  00 00 00 00  0d 0a 4e 54
01b0: 4c 44 52 20  69 73 20 6d  69 73 73 69  6e 67 ff 0d
01c0: 0a 44 69 73  6b 20 65 72  72 6f 72 ff  0d 0a 50 72
01d0: 65 73 73 20  61 6e 79 20  6b 65 79 20  74 6f 20 72
01e0: 65 73 74 61  72 74 0d 0a  00 00 00 00  00 00 00 00
01f0: 00 00 00 00  00 00 00 00  00 ac bf cc  00 00 55 aa
Read block 0 (partition table)
Signature 0x55 0xaa, should be 0x55 0xaa
Partition 0: boot ff, first sector 0d 0a 44, file system 69, last sector 73 6b 20
           : first sector (linear) 6f 72 72 65, sector count 0a 0d ff 72
Partition 1: boot 50, first sector 72 65 73, file system 73, last sector 20 61 6e
           : first sector (linear) 65 6b 20 79, sector count 6f 74 20 79
Partition 2: boot 20, first sector 72 65 73, file system 74, last sector 61 72 74
           : first sector (linear) 00 00 0a 0d, sector count 00 00 00 00
Partition 3: boot 00, first sector 00 00 00, file system 00, last sector 00 00 00
           : first sector (linear) ac 00 00 00, sector count 00 00 cc bf


mmc_spi_read_disk_block(0): sending command
Request 51 00 00 00 00 ff ff
Sent command cmd = 11 arg = 0: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
mmc_spi_read_disk_block(0): reading data token/data/crc
mmc_spi_read_data(): got data and CRC 96 bc


Sector info(0 sec : boot):
----------------------------------------------------------------

       0  eb 58 90 4d 53 44 4f 53 35 2e 30  0  2  8 20  0 
      10   2  0  0  0  0 f8  0  0 3f  0 ff  0  0  0  0  0 
      20   0 2c  f  0 ca  3  0  0  0  0  0  0  2  0  0  0 
      30   1  0  6  0  0  0  0  0  0  0  0  0  0  0  0  0 
      40   0  0 29 cb 90 87 a8 4e 4f 20 4e 41 4d 45 20 20 
      50  20 20 46 41 54 33 32 20 20 20 33 c9 8e d1 bc f4 
      60  7b 8e c1 8e d9 bd  0 7c 88 4e  2 8a 56 40 b4  8 
      70  cd 13 73  5 b9 ff ff 8a f1 66  f b6 c6 40 66  f 
      80  b6 d1 80 e2 3f f7 e2 86 cd c0 ed  6 41 66  f b7 
      90  c9 66 f7 e1 66 89 46 f8 83 7e 16  0 75 38 83 7e 
      a0  2a  0 77 32 66 8b 46 1c 66 83 c0  c bb  0 80 b9 
      b0   1  0 e8 2b  0 e9 48  3 a0 fa 7d b4 7d 8b f0 ac 
      c0  84 c0 74 17 3c ff 74  9 b4  e bb  7  0 cd 10 eb 
      d0  ee a0 fb 7d eb e5 a0 f9 7d eb e0 98 cd 16 cd 19 
      e0  66 60 66 3b 46 f8  f 82 4a  0 66 6a  0 66 50  6 
      f0  53 66 68 10  0  1  0 80 7e  2  0  f 85 20  0 b4 
     100  41 bb aa 55 8a 56 40 cd 13  f 82 1c  0 81 fb 55 
     110  aa  f 85 14  0 f6 c1  1  f 84  d  0 fe 46  2 b4 
     120  42 8a 56 40 8b f4 cd 13 b0 f9 66 58 66 58 66 58 
     130  66 58 eb 2a 66 33 d2 66  f b7 4e 18 66 f7 f1 fe 
     140  c2 8a ca 66 8b d0 66 c1 ea 10 f7 76 1a 86 d6 8a 
     150  56 40 8a e8 c0 e4  6  a cc b8  1  2 cd 13 66 61 
     160   f 82 54 ff 81 c3  0  2 66 40 49  f 85 71 ff c3 
     170  4e 54 4c 44 52 20 20 20 20 20 20  0  0  0  0  0 
     180   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     190   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1a0   0  0  0  0  0  0  0  0  0  0  0  0  d  a 4e 54 
     1b0  4c 44 52 20 69 73 20 6d 69 73 73 69 6e 67 ff  d 
     1c0   a 44 69 73 6b 20 65 72 72 6f 72 ff  d  a 50 72 
     1d0  65 73 73 20 61 6e 79 20 6b 65 79 20 74 6f 20 72 
     1e0  65 73 74 61 72 74  d  a  0  0  0  0  0  0  0  0 
     1f0   0  0  0  0  0  0  0  0  0 ac bf cc  0  0 55 aa 

----------------------------------------------------------------

mmc_spi_read_disk_block(32): sending command
Request 51 00 00 40 00 ff ff
Sent command cmd = 11 arg = 16384: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
mmc_spi_read_disk_block(32): reading data token/data/crc
mmc_spi_read_data(): got data and CRC 76 3a


Sector info(32 sec : root dir):
----------------------------------------------------------------

       0  f8 ff ff ff ff ff ff ff ff ff ff  f ff ff ff  f 
      10  ff ff ff  f  0  0  0  0  0  0  0  0  0  0  0  0 
      20   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      30   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      40   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      50   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      60   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      70   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      80   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      90   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      a0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      b0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      c0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      d0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      e0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      f0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     100   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     110   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     120   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     130   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     140   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     150   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     160   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     170   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     180   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     190   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1a0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1b0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1c0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1d0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1e0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1f0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 

----------------------------------------------------------------

mmc_spi_read_disk_block(1980): sending command
Request 51 00 0f 78 00 ff ff
Sent command cmd = 11 arg = 1013760: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
mmc_spi_read_disk_block(1980): reading data token/data/crc
mmc_spi_read_data(): got data and CRC 9a 31


Sector info(1980 sec : a.txt):
----------------------------------------------------------------

       0  31 32 33 34 35 36 37 38 39 30  0  0  0  0  0  0 
      10   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      20   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      30   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      40   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      50   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      60   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      70   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      80   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      90   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      a0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      b0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      c0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      d0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      e0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      f0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     100   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     110   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     120   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     130   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     140   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     150   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     160   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     170   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     180   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     190   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1a0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1b0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1c0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1d0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1e0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1f0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 

----------------------------------------------------------------

mmc_spi_read_disk_block(1988): sending command
Request 51 00 0f 88 00 ff ff
Sent command cmd = 11 arg = 1017856: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
mmc_spi_read_disk_block(1988): reading data token/data/crc
mmc_spi_read_data(): got data and CRC 67 a2


Sector info(1988 sec : b.txt):
----------------------------------------------------------------

       0  61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e  0  0 
      10   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      20   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      30   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      40   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      50   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      60   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      70   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      80   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      90   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      a0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      b0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      c0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      d0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      e0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
      f0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     100   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     110   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     120   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     130   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     140   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     150   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     160   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     170   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     180   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     190   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1a0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1b0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1c0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1d0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1e0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
     1f0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 

----------------------------------------------------------------



Write test
mmc_spi_write_disk_block(), sending command
Request 58 00 00 c8 00 ff ff
Sent command cmd = 18 arg = 51200: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
mmc_spi_write_disk_block(): sending data token/data/crc
mmc_spi_write_disk_block(): got data response token e5
mmc_spi_write_disk_block(), polling for ! busy, got response 00
mmc_spi_write_disk_block(), polling for ! busy, got response 00
mmc_spi_write_disk_block(), polling for ! busy, got response 00
mmc_spi_write_disk_block(), polling for ! busy, got response 00
mmc_spi_write_disk_block(), polling for ! busy, got response 00
mmc_spi_write_disk_block(), polling for ! busy, got response 00
mmc_spi_write_disk_block(), polling for ! busy, got response 00
mmc_spi_write_disk_block(), polling for ! busy, got response 00
mmc_spi_write_disk_block(), polling for ! busy, got response 01
mmc_spi_read_disk_block(100): sending command
Request 51 00 00 c8 00 ff ff
Sent command cmd = 11 arg = 51200: reply bytes ff ff ff ff ff ff ff
  loop 0, additional reply 00
mmc_spi_read_disk_block(100): reading data token/data/crc
mmc_spi_read_data(): got data and CRC 40 da


Sector info(100 sec : test):
----------------------------------------------------------------

       0   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f 
      10  10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 
      20  20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 
      30  30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 
      40  40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 
      50  50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 
      60  60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 
      70  70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 
      80  80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 
      90  90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f 
      a0  a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af 
      b0  b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf 
      c0  c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf 
      d0  d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df 
      e0  e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef 
      f0  f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 
     100   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f 
     110  10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 
     120  20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 
     130  30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 
     140  40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 
     150  50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 
     160  60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 
     170  70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 
     180  80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 
     190  90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f 
     1a0  a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af 
     1b0  b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf 
     1c0  c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf 
     1d0  d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df 
     1e0  e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef 
     1f0  f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff 

----------------------------------------------------------------

使用特权

评论回复
地板
我是土匪|  楼主 | 2009-7-2 14:29 | 只看该作者

大哥,回答简介一点

一针见血就好,你做再多的广告,我也不买啊,因为要免费的

还是感谢杨大侠

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

226

主题

1761

帖子

30

粉丝