转载请注明,原文地址: http://blog.csdn.net/l461269717/article/details/8086087
-------------------------------------------------------------------------------------------------------------------------------
首先确保你的内核编译选项支持SD卡,具体见文章最下面;
第一步完成后,启动开发板之后,将SD卡插上会打印如下信息:
# ls -l /dev/mmcblk*
brw-rw---- 1 0 0 179, 0 Oct 18 15:45 /dev/mmcblk0
brw-rw---- 1 0 0 179, 1 Oct 18 15:45 /dev/mmcblk0p1
这说明当插上SD卡之后自动创建了设备节点,它属于块设备,主次设备号分别是179、0和179
其中
mmcblk0代表整个SD卡,
mmcblk0p1代表SD卡的第一个分区(不同型号SD卡产生的设备节点可能不同)
但是这里只是自动创建了设备节点,并没有自动将SD卡挂载,要访问SD卡的话,还需要自己动手去挂载:
mkdir /mnt/sdcard
然后使用命令:
mount dev/mmcblk0p1 /mnt/card
mount dev/mmcblk0p1 /mnt/card
就可以在/mnt/sdcard目录下来访问SD卡了。
那么我们如果想要SD卡自动挂载应该怎么办呢?分析mdev,
make_device
open("/etc/mdev.conf", O_RDONLY)
通过分析我们可以知道,如果存在
显然,我们想要让SD卡自动挂载的话,就需要写一个
"文件
!
废话不多说,开始动手:
首先写个脚本文件:
首先写个脚本文件:
vi /bin/
hotplug.sh
#!/bin/sh
if [ $ACTION = "add" ];
then
mount /dev/$MDEV /mnt/sdcard;
else
umount /mnt/sdcard;
fi
保存退出;
并给这个文件赋权限777:chmod 777 /bin/
hotplug.sh
然后创建mdev.conf配置文件(没有则先创建):
vi /etc/mdev.conf
在mdev.conf文件里面添加如下信息:
在mdev.conf文件里面添加如下信息:
mmcblk0p1 0:0 777 * /bin/
hotplug.sh
插上SD卡之后
ls /mnt/sdcard
发现SD卡已经自动挂载上了!
---------------------------------------------------------------------------------------------------------------------------
编译内核使uImage支持USB和SD卡:
make menuconfig ARCH=arm
1.配置usb host和sd卡
Device Drivers --->
SCSI device support --->
<*> SCSI disk support
USB support --->
<*> Support for Host-side USB
[*] USB verbose debug messages
--- USB Host Controller Drivers
<*> EHCI HCD (USB 2.0) support
<*> Intel ixp435/ixp465 on-chip EHCI HCD support
< > ISP116X HCD support
< > OHCI HCD support
< > UHCI HCD (most Intel and VIA) support
< > SL811HS HCD support
--- USB Device Class drivers
< > USB Modem (CDC ACM) support
< > USB Printer support
--- NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
--- may also be needed; see USB_STORAGE Help for more information
<*> USB Mass Storage support
[*] USB Mass Storage verbose debug
MMC/SD Card support --->
<*> MMC support
[*] MMC debugging
<*> MMC block device driver
2.配置usb和sd卡支持的文件系统(一般usb都以vfat格式,所以此处选择支持vfat)
File systems --->
DOS/FAT/NT Filesystems --->
<*> MSDOS fs support
<*> VFAT (Windows-95) fs support
(437) Default codepage for FAT
(iso8859-1) Default iocharset for FAT
<*> NTFS file system support
[ ] NTFS debugging support
[*] NTFS write support
3.配置文件系统支持的字符集
File systems --->
Native Language Support --->
(iso8859-1) Default NLS Option
<*> Codepage 437 (United States, Canada)
<*> Simplified Chinese charset (CP936, GB2312)
<*> NLS ISO 8859-1 (Latin 1; Western European Languages)
<*> NLS UTF8
Device Drivers --->
SCSI device support --->
<*> SCSI disk support
USB support --->
<*> Support for Host-side USB
[*] USB verbose debug messages
--- USB Host Controller Drivers
<*> EHCI HCD (USB 2.0) support
<*> Intel ixp435/ixp465 on-chip EHCI HCD support
< > ISP116X HCD support
< > OHCI HCD support
< > UHCI HCD (most Intel and VIA) support
< > SL811HS HCD support
--- USB Device Class drivers
< > USB Modem (CDC ACM) support
< > USB Printer support
--- NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
--- may also be needed; see USB_STORAGE Help for more information
<*> USB Mass Storage support
[*] USB Mass Storage verbose debug
MMC/SD Card support --->
<*> MMC support
[*] MMC debugging
<*> MMC block device driver
2.配置usb和sd卡支持的文件系统(一般usb都以vfat格式,所以此处选择支持vfat)
File systems --->
DOS/FAT/NT Filesystems --->
<*> MSDOS fs support
<*> VFAT (Windows-95) fs support
(437) Default codepage for FAT
(iso8859-1) Default iocharset for FAT
<*> NTFS file system support
[ ] NTFS debugging support
[*] NTFS write support
3.配置文件系统支持的字符集
File systems --->
Native Language Support --->
(iso8859-1) Default NLS Option
<*> Codepage 437 (United States, Canada)
<*> Simplified Chinese charset (CP936, GB2312)
<*> NLS ISO 8859-1 (Latin 1; Western European Languages)
<*> NLS UTF8