arm linux 的sd卡检测开发调研mtp-usb准备知识
使用fdisk -l 检查是否有sd卡
root@linaro-developer:/mnt# fdisk -l
WARNING: GPT (GUID Partition Table) detected on '/dev/mmcblk0'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/mmcblk0: 14.8 GB, 14763950080 bytes
256 heads, 63 sectors/track, 1787 cylinders, total 28835840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 1 4294967295 2147483647+ ee GPT
Disk /dev/mmcblk0rpmb: 0 MB, 131072 bytes
4 heads, 16 sectors/track, 4 cylinders, total 256 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mmcblk0rpmb doesn't contain a valid partition table
Disk /dev/mmcblk1: 63.9 GB, 63864569856 bytes
25 heads, 24 sectors/track, 207892 cylinders, total 124735488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x57940264
Device Boot Start End Blocks Id System
/dev/mmcblk1p1 2048 124735487 62366720 7 HPFS/NTFS/exFAT
2 第二部 确定 /mnt下有sdcard 存在
然后cat /proc/partitions
看看到底有没有mmc相关的分区
root@linaro-developer:/dev# cat /proc/partitions
major minor #blocks name
179 0 14417920 mmcblk0
179 1 65536 mmcblk0p1
179 2 512 mmcblk0p2
179 3 32 mmcblk0p3
179 4 32 mmcblk0p4
179 5 512 mmcblk0p5
179 6 500 mmcblk0p6
179 7 16384 mmcblk0p7
179 8 500 mmcblk0p8
179 9 1024 mmcblk0p9
179 10 1536 mmcblk0p10
179 11 1536 mmcblk0p11
179 12 313344 mmcblk0p12
179 13 1470464 mmcblk0p13
179 14 32768 mmcblk0p14
179 15 32768 mmcblk0p15
179 16 16384 mmcblk0p16
179 17 313344 mmcblk0p17
179 18 1 mmcblk0p18
179 19 30 mmcblk0p19
179 20 1536 mmcblk0p20
179 21 1 mmcblk0p21
179 22 8 mmcblk0p22
179 23 11665382 mmcblk0p23
179 32 128 mmcblk0rpmb
179 64 62367744 mmcblk1
179 65 62366720 mmcblk1p1
很明显有这两个分区。
SD 卡一旦插入系统,内核会自动在/dev/下创建设备文件:sdcard。 但有时可能时用户在拨出卡前并没有umount的话,第二次插卡进去后系统创建的就不是sdcard设备文件了,而是mmcblk0, mmcblk1p1, mmcblk2p1, 或mmcblk3p1.
如何知道有没有mount 成功呢
使用
cat /proc/mounts
root@linaro-developer:/etc/init.d# cat /proc/mounts
rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
udev /dev devtmpfs rw,relatime,size=684248k,nr_inodes=116589,mode=755 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620 0 0
tmpfs /run tmpfs rw,nosuid,noexec,relatime,size=166580k,mode=755 0 0
/dev/mmcblk0p13 / ext4 rw,relatime,data=ordered 0 0
selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0
/dev/mmcblk0p1 /mnt/modem vfat rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0
/dev/mmcblk0p15 /lib/firmware ext4 rw,relatime,data=ordered 0 0
none /sys/fs/cgroup tmpfs rw,relatime,size=4k,mode=755 0 0
none /sys/fs/fuse/connections fusectl rw,relatime 0 0
none /sys/kernel/debug debugfs rw,relatime 0 0
none /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
none /run/shm tmpfs rw,nosuid,nodev,relatime 0 0
none /run/user tmpfs rw,nosuid,nodev,noexec,relatime,size=102400k,mode=755 0 0
/dev/mmcblk0p14 /mnt/persist ext4 rw,relatime,data=ordered 0 0
/dev/mmcblk0p17 /cache ext4 rw,relatime,data=ordered 0 0
/dev/mmcblk0p23 /home/linaro/media ext4 rw,relatime,data=ordered 0 0
纵观列表,没有出现mmcblk1 还有mmcblk1p1 说明没有mount。
后来犯了一个错误,我把卡插到电脑上格式化成exfat的格式了,结果插到arm 开发板上无论如何也不能挂载,后来
在开发板上 使用
mkfs.ext4 /dev/mmcblk1p1
格式化成ext4.可以mkfs 然后敲tab键来找到可以使用的文件系统。
格完之后重新使用,mount -t ext4 /dev/mmcblk1p1 /mnt
来挂载sd卡。
重新插拔既可以挂载了。
此过程可以使用fdisk /dev/mmcblk1
根据打印的菜单来查看信息。
比如输入p
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/mmcblk1: 63.9 GB, 63864569856 bytes
25 heads, 24 sectors/track, 207892 cylinders, total 124735488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x57940264
Device Boot Start End Blocks Id System
/dev/mmcblk1p1 2048 124735487 62366720 7 HPFS/NTFS/exFAT