[讨论] USB和SD/MMC移植笔记(转)

leslie   2009-12-28 11:40 楼主
一、USB移植
在移植好内核和跟文件系统的基础上,进行USB的移植。
S3C2440集成了USB控制器支持USB1.1版本,支持USB主机和USB设备主机符合OHCI1.0版本,Linux2.6.29.1的内核支持USB控制器,只需在内核中配置即可。
在内核目录下,输入make menuconfig,进入配置菜单,如下:
Device Drivers-à

SCSI device support-à

<*>SCSI device support

legacy /proc/scsi/ support
<*>SCSI disk support
<*>SCSI CDROM support

HID Devices-à

<*> USB Human Interface Device(full HID)support


/dev/hiddev raw HID device support

USB support-à

<*> support for Host-side USB

USB device filesystem

USB device class-devices(DEPRECATED)

<*>OHCI HCD support

<*>USB Mass storage support

先用make clean命令清除编译内核的垃圾文件,然后用命令make zImage编译内核。
在移植的根文件系统系统目录dev下建立如下的设备文件:
mknod sda1 b 8 1
把编译好的内核和根文件系统映像文件下载到开发板,启动开发板后插入U盘,终端出现如下信息:
[@MrFeng=W]#ls
bin
etc
linuxrc
proc
sys
var
boot
home
lost+found
root
tmp
www
dev
lib
mnt
sbin
usr
[@MrFeng=W]#usb 1-1: new full speed USB device using s3c2410-ohci and address 2
usb 1-1: New USB device found, idVendor="0204", idProduct="6025"
usb 1-1: New USB device strings: Mfr="0", Product="0", SerialNumber="0"
usb 1-1: configuration #1 chosen from 1 choice
scsi0 : SCSI emulation for USB Mass Storage devices
scsi 0:0:0:0: Direct-Access
USB A
Flash Disk
2.00 PQ: 0 ANSI: 2
sd 0:0:0:0: [sda] 506420 512-byte hardware sectors: (259 MB/247 MiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] 506420 512-byte hardware sectors: (259 MB/247 MiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Assuming drive cache: write through

sda: sda1
sd 0:0:0:0: [sda] Attached SCSI removable disk

[@MrFeng=W]#mount -t vfat /dev/sda1 /mnt/usb
FAT: utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!

使用命令mount挂载U盘:
[@MrFeng=W]#mount -t vfat /dev/sda1 /mnt/usb

[@MrFeng=W]#ls /mnt/usb
bootloader.tgz
logomaker.tgz
rootfs.img
busybox-1.13.3.tar.gz
mdev.txt
server.c
examples(1).tgz
mini2440_pwm.c
zImage
getaddrinfo.c
mkyaffsimage.tgz
led_driver.c
root_qtopia.img


拔下U盘后出现:
[@MrFeng=W]#usb 1-1: USB disconnect, address 2


二、SD/MMC移植
S3C2440集成了一个MMC/SD/SDIO主机控制器,用于访问外接的SD、MMC、SDIO卡,linux-2.6.29.1包含了MMC/SD驱动程序,只需在内核中配置即可。在内核里做如下配置:
Device Drivers-?

<*>MMC/SD/SDIO card support--->

<*>MMC block device driver

Use bounce buffer for simple hosts

<*>Samsung S3C SD/MMC Card Interface support

配置好后,把编译的内核下载到开发板后,插入SD卡终端没有任何提示。细细一看,友善之臂的SD卡的写保护不是直接接地的,二是接到GPH8引脚的,于是我在内核文件/arch/arm/mash-s3c2440/mach-smdk2440.c中做如下修改:
static void __init smdk2440_machine_init(void)
{

s3c24xx_fb_set_platdata(&smdk2440_fb_info);

s3c_i2c0_set_platdata(NULL);

//开启LCD背光

s3c2410_gpio_cfgpin(S3C2410_GPG4,S3C2410_GPG4_OUTP);

s3c2410_gpio_setpin(S3C2410_GPG4,1);

//关闭SD卡写保护

s3c2410_gpio_cfgpin(S3C2410_GPH8,S3C2410_GPH8_OUTP);

s3c2410_gpio_setpin(S3C2410_GPH8,0);

platform_add_devices(smdk2440_devices, ARRAY_SIZE(smdk2440_devices));

smdk_machine_init();
}

重新编译内核,下载到开发板,将SD卡插入到卡座。在终端出现如下信息:
[@MrFeng=W]#mmc0: card 0002 removed
s3c2440-sdi s3c2440-sdi: powered down.
s3c2440-sdi s3c2440-sdi: running at 0kHz (requested: 0kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 198kHz (requested: 197kHz).
s3c2440-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz).
s3c2440-sdi s3c2440-sdi: running at 16875kHz (requested: 25000kHz).
mmc0: new SD card at address 0002
mmcblk0: mmc0:0002 00000 1.90 GiB

mmcblk0:<4>mmcblk0: retrying using single block read


拔下SD卡出现:
[@MrFeng=W]#mmc0: card 0002 removed
s3c2440-sdi s3c2440-sdi: powered down.

总结:在高版本的Linux内核中,已集成了USB和SD卡驱动,所需的只是配置,低版本的内核需要打补丁然后配置。
                                                                                                                                      1986fdr@163.com


[ 本帖最后由 leslie 于 2009-12-28 11:42 编辑 ]

回复评论 (1)

太强了啊,我现在还在为如何能给SD卡搞一个文件系统而头疼呢
点赞  2009-12-29 09:08
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复