Camera驱动在Linux内核的移植

更新时间:2023-11-10 08:26:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Camera驱动在Linux内核的移植

一、内核移植步骤

1, 修改顶层目录下的Makefile

ARCH ?= $(SUBARCH)

CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:\修改为: ARCH :=arm

CROSS_COMPILE :=/usr/local/arm/4.4.3/bin/arm-linux- 2, 拷贝配置文件

这里用的是FS2410开发板,拷贝相应的板文件到顶层目录下 cp arch/arm/configs/s3c2410_defconfig ./ 编译配置文件,生成.config文件:

Make s3c2410_defconfig 内核配置的目的:

.config文件记录了哪些部分会被编译进内核,哪些部分会被编译成内核模块,内核在编译前,寻找.config文件,作为他编译的准则。即.config文件是给Makefile来读

3,1)选择板子

在arch/arm/mach-s3c2410/Kconfig中,修改相应的配置 root@mach-s3c2410# vimKconfig root@mach-s3c2410#pwd

/change/linux-3.1.4/arch/arm/mach-s3c2410 config ARCH_SMDK2410 bool \select CPU_S3C2410 select MACH_SMDK help

Say Y here if you are using the SMDK2410 or the derived module A9M2410 http://www.fsforth.de 改成:

config ARCH_SMDK2410 bool \select CPU_S3C2410 select MACH_SMDK

select S3C_DEV_USB_HOST select S3C_DEV_NAND select S3C2410_SETUP_TS help

Say Y here if you are using the SMDK2410 or the derived module A9M2410 http://www.fsforth.de

2)选配资源,这里用的是fs2410开发板,可以在/arch/arm/kconfig中选配 if ARCH_S3C2410

#source \s3c2410目标板:

source \#A8目标板:

#source \#source \#source \#source \#source \endif

4, 内核配置

1) General setup --->

[*] Prompt for development and/or incomplete code/drivers(可选) [*] Automatically append version information to the version string│ Kernel compression mode (Gzip) --->

2)[*] Enable loadable module support ---> [*] Forced module loading [*] Module unloading [*] Forced module unloading [*] Module versioning support 3)System Type --->(选板子) S3C2410 Machines --->

[*] SMDK2410/A9M2410(只选择此项)

[ ] IPAQ H1940(选择后下载地址会在31008000) 4)Kernel Features --->

[*] Use the ARM EABI to compile the kernel

[*] Allow old ABI binaries to run with this kernel (EXPERIMENTAL [*] Provide old way to pass kernel parameters 5)Userspace binary formats ---> [*] Kernel support for ELF binaries

[*] Write ELF core dumps with partial segments

<> Kernel support for a.out and ECOFF binaries(此项不选,选择后会报某些错) 6)Networking support Networking options ---> [*] TCP/IP networking ……

7)Device Drivers --->(设备驱动,根据需要添加修改,如网卡,led,lcd,beep等)

[*] Network device support --->(网卡设备支持) Character devices --->(字符设备支持,如:led,lcd) <*> Multimedia support --->(多媒体支持,如:V4L2) [*] USB support --->(USB支持)

8)File systems --->(文件系统,支持yaffs2,crmfs等)

[*] Network File Systems --->(网络文件系统) <*> NFS client support [*] Root file system on NFS 5, 内核编译并拷贝到tftpboot下

makezImage

cp arch/arm/boot/zImage /tftpboot 6, 查看内存映射表:

root@linux-3.1.4# vim System.map 从内存映射表中可以知道下载地址

说明:以上的相关配置是针对arm平台的基本配置。如果想实现文件共享,led,lcd驱动

等,则可以在此基础上修改和添加。

二,Nand flash驱动的添加

目的:nand flash 是默认配置的,只是他的分区可以根据我们的实际情况来配置

1, 修改分区信息表

在arch/arm/plat-s3c24xx/common-smdk.c中有nand flash的分区信息,根据我们实际生产中的需要,进行一些修改:

staticstructmtd_partitionsmdk_default_nand_part[] = { [0] = {

.name = \ .size = 0x40000, .offset = 0, }, [1] = {

.name = \ .offset = 0x40000, .size = 0x400000, }, [2] = {

.name = \ .offset = 0x440000, .size = 0x800000, }, [3] = {

.name = \ .offset = 0xc40000, .size = 0x33c0000, }, }

name: 代表分区名字

size: 代表flash分区大小(单位:字节)

offset: 代表flash分区的起始地址(相对于0x0的偏移)

2,在此前的基础上配置内核:

Device Drivers --->

<*> Memory Technology Device (MTD) support ---> <*> NAND Device Support --->

<*> NAND Flash support for Samsung S3C SoCs

3,编译好,移植到开发板后可以看见这样的打印信息:

Creating 4 MTD partitions on \0x000000000000-0x000000040000 : \

0x000000040000-0x000000440000 : \0x000000440000-0x000000c40000 : \0x000000c40000-0x000004000000 : \

三、网卡驱动的添加:

目的:将网卡驱动移植到linux-3.1.4内核上,使其可以通过网络nfs的方式挂载主机环境上的文件系统,从而实现linux系统的启动

在此前的内核移植的步骤上面进行以下的修改和配置:

1, 我们这里用到的网卡是cs8900。将已经下载好的网卡驱动程序cs8900.c和cs8900.h两个文件拷贝到驱动下

root@linux-3.1.4#cp ……/cs8900.* drivers/net/arm 2, 修改drivers/net/arm/Kconfig 添加cs8900的配置项: root@linux-3.1.4# cd drivers/net/arm/ root@arm# vimKconfig 进行以下的配置(添加): config ARM_CS8900 tristate \depends on ARM help

support cs8900

3, 修改drivers/net/arm/Makefile 添加内核编译配置: root@arm# vimMakefile 添加一下的内容:

obj-$(CONFIG_ARM_CS8900) +=cs8900.o 4, 添加地址映射:

在arch/arm/plat-s3c24xx/include/plat/map.h添加宏定义: root@linux-3.1.4# vim arch/arm/mach-s3c2410/include/mach/map.h

#define S3C24XX_VA_CS8900 0xE0000000 #define S3C24XX_PA_CS8900 0x19000000 #define S3C24XX_SZ_CS8900 SZ_1M 5, 添加平台代码

在arch/arm/mach-s3c2410/mach-smdk2410.c中添加: root@linux-3.1.4# vim arch/arm/mach-s3c2410/mach-smdk2410.c staticstructmap_desc smdk2410_iodesc[] __initdata = {

IODESC_ENT(CS8900)} 6, 虚拟地址到物理地址的转换:

查看arch/arm/plat-samsang/include/plat/cpu.h

root@linux-3.1.4#vim arch/arm/plat-samsung/include/plat/cpu.h

#define IODESC_ENT(x) { (unsigned long)S3C24XX_VA_##x,

__phys_to_pfn(S3C24XX_PA_##x), S3C24XX_SZ_##x, MT_DEVICE } 7, 一点说明:在linux-3.1.4内核的网卡驱动里面加入了中断处理机制 添加:

#include

将set_irq_type(dev->irq, (1<<1)||(1<<0));修改为: irq_set_irq_type(dev->irq, (1<<1)||(1<<0)); 8, 内核配置,使之支持cs8900网卡: Device Drivers --->

[*] Network device support ---> [*] Ethernet (10 or 100Mbit) ---> <*> cs8900 support 9, 重新编译内核 makezImage

10,网卡移植好了可以再板子上面看见以下信息:

Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410)

eth0: CS8900A rev E at 0xe0000300 irq=53, addr: 00: 0:3E:26:0A: 0

四,LED驱动的添加

1, 将led.c驱动文件拷贝到linux-3.1.4/drivers/char/目录下

root@char# pwd

/change/linux-3.1.4/drivers/char

root@char# cp /mnt/hgfs/fh/driver/my_driver/led.c ./ 2, 修改当前目录下的配置文件,增加内核配置项 root@char# vim Kconfig

添加:

config ARCH_S3C2410_LED tristate \

default y help

s3c2410 led support

3, 修改Makefile,添加内核配置 root@char# vim Makefile

obj-$(CONFIG_ARCH_S3C2410_LED) +=led.o 4, 配置板文件资源

1)struct resource smdk2410_myres[] = {

[0] = { .start = 0x56000054,

.end = 0x56000054,

.flags = IORESOURCE_MEM, }, //GPFDAT [1] = {

.start = 0x56000050, .end = 0x56000050,

.flags = IORESOURCE_MEM, }, //GPFCON };

2)structplatform_device smdk2410_platdev = {

.name =\驱动程序里面的设备名 .id = 0,

.num_resources = ARRAY_SIZE(smdk2410_myres), .resource = smdk2410_myres, };

3)static structplatform_device *smdk2410_devices[] __initdata = { &smdk2410_platdev, }

注:我这里用的是fs2410开发板上的D12号led灯,配置其他的led灯同理。 5, 配置内核

root@linux-3.1.4# make menuconfig Device Drivers ---> Character devices --->

<*> s3c2410 led support (NEW) 6, 重新编译内核

Make zImage

五,蜂鸣器的驱动添加

蜂鸣器的驱动添加和led的驱动添加过程是一样的,过程如下:

1, root@char# cp /mnt/hgfs/fh/driver/my_driver/beep.c ./ 2, 修改drivers/char/Kconfig,提供内核配置项 config ARCH_S3C2410_BEEP

tristate \

default y

help

s3c2410 beep support

3, 修改Makefile

obj-$(CONFIG_ARCH_S3C2410_BEEP) += beep.o 4, 资源选配,和led的资源选配同理 5, 选配内核

root@linux-3.1.4# make menuconfig Device Drivers --->

Character devices ---> <*> s3c2410 beep support (NEW) 6, 编译内核

root@linux-3.1.4#make zImage

六,LCD驱动的添加

在嵌入式系统中,lcd常作为交互使用,其移植步骤如下:

1, 在板文件arch/arm/mach-s3c2410/mach-smdk2310.c中添加下列的头文件

root@mach-s3c2410# vim mach-smdk2410.c #include

#include

2, 添加LCD相关的平台信息

root@mach-s3c2410# vim mach-smdk2410.c

//相关的配置信息根据LCD屏相应的参数配置

staticstruct s3c2410fb_display s3c2410_lcd_cfg[] __initdata = { {

.lcdcon5 = S3C2410_LCDCON5_FRM565 | S3C2410_LCDCON5_INVVCLK |

S3C2410_LCDCON5_INVVLINE | S3C2410_LCDCON5_INVVFRAME| S3C2410_LCDCON5_PWREN | S3C2410_LCDCON5_HWSWP, .type = S3C2410_LCDCON1_TFT, .width = 320, .height = 240, .pixclock = 100000, .xres = 320, .yres = 240, .bpp = 16,

.left_margin = 20,//13, .right_margin = 38,//8, .hsync_len = 30,//4, .upper_margin = 4,//2, .lower_margin = 15,//7, .vsync_len = 3,//4, }, };

staticstruct s3c2410fb_mach_info s3c2410_fb_info __initdata = { .displays = s3c2410_lcd_cfg,

.num_displays = ARRAY_SIZE(s3c2410_lcd_cfg), .default_display= 0, .gpcup = 0xffffffff, .gpcup_mask = 0xffffffff, .gpccon = 0xaa9556a9, .gpccon_mask = 0xffffffff, .gpdup = 0xffffffff, .gpdup_mask = 0xffffffff, .gpdcon = 0xaaaaaaaa, .gpdcon_mask = 0xffffffff, .lpcsel = ((0xCE6) & ~7) | 1<<4, };

static void __init smdk2410_init(void)

{

s3c24xx_fb_set_platdata(&s3c2410_fb_info); }

3, 配置内核

root@linux-3.1.4#make menuconfig Device Drivers ---> Graphics support --->

<*> Support for frame buffer devices ---> <*> S3C2410 LCD framebuffer support

[*] Bootup logo --->//LCD成功启动,就可以看见linuxLOGO^^

4,编译内核 makezImage

七,USB驱动的添加

1, 配置内核

root@linux-3.1.4# make menuconfig Device Drivers ---> SCSI device support ---> <*> SCSI disk support <*> SCSI generic support <*> SCSI media changer support [*] USB support --->

<*> USB Mass Storage support File systems --->

-*- Native language support --->

<*> Codepage 437 (United States, Canada) <*> Simplified Chinese charset (CP936, GB2312) <*> ASCII (United States)

<*> NLS ISO 8859-1 (Latin 1; Western European Languages) 2, 编译内核 makezImage

八,视频V4L2驱动的添加

1, 配置内核

Device Drivers ---> <*> Multimedia support ---> <*> Video For Linux

[*] Video capture adapters (NEW) ---> [*] V4L USB devices (NEW) ---> <*> USB Video Class (UVC)

[*] UVC input events device support (NEW) 2,编译内核 makezImage

进过上面八个步骤的配置,我们可以在板子上面看见这样的打印信息: Using CS8900-0 device

TFTP from server 192.168.2.201; our IP address is 192.168.2.200 Filename 'zImage'. Load address: 0x30008000

Loading: #################################################################

################################################################# #################################### done

Bytes transferred = 2430016 (251440 hex) setuplinux parameters at 0x30000100

linux command line is: \ip=192.168.2.200\

## Starting application at 0x30008000 ... Uncompressing Linux... done, booting the kernel.

Linux version 3.1.4@genehang (root@ubuntu) (gcc version 4.4.3 (ctng-1.6.1) ) #7 Thu Jan 12 14:38:47 CST 2012 CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177 CPU: VIVT data cache, VIVT instruction cache Machine: fs2410@panzhh

ATAG_INITRD is deprecated; please update your bootloader. Memory policy: ECC disabled, Data cache writeback

BUG: mapping for 0x19000000 at 0xe0000000 overlaps vmalloc space CPU S3C2410A (id 0x32410002)

S3C24XX Clocks, Copyright 2004 Simtec Electronics

S3C2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on

Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256 Kernel command line: root=nfsnfsroot=192.168.2.201:/source/rootfsinit=/linuxrc console=ttySAC0,115200ip=192.168.2.200 PID hash table entries: 256 (order: -2, 1024 bytes)

Dentry cache hash table entries: 8192 (order: 3, 32768 bytes) Inode-cache hash table entries: 4096 (order: 2, 16384 bytes) Memory: 64MB = 64MB total

Memory: 60140k/60140k available, 5396k reserved, 0K highmem Virtual kernel memory layout:

vector : 0xffff0000 - 0xffff1000 ( 4 kB) fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB) DMA : 0xffc00000 - 0xffe00000 ( 2 MB) vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB) lowmem : 0xc0000000 - 0xc4000000 ( 64 MB) modules : 0xbf000000 - 0xc0000000 ( 16 MB) .text : 0xc0008000 - 0xc0439a60 (4295 kB) .init : 0xc043a000 - 0xc045d000 ( 140 kB) .data : 0xc045e000 - 0xc04864e0 ( 162 kB) .bss : 0xc0486504 - 0xc04aead4 ( 162 kB) NR_IRQS:85

irq: clearing subpending status 00000002 Console: colour dummy device 80x30

Calibrating delay loop... 50.17 BogoMIPS (lpj=125440) pid_max: default: 32768 minimum: 301 Mount-cache hash table entries: 512 CPU: Testing write buffer coherency: ok

gpiochip_add: gpios 256..271 (GPIOJ) failed to register gpiochip_add: gpios 288..303 (GPIOK) failed to register gpiochip_add: gpios 320..334 (GPIOL) failed to register gpiochip_add: gpios 352..353 (GPIOM) failed to register

NET: Registered protocol family 16

S3C Power Management, Copyright 2004 Simtec Electronics S3C2410: Initialising architecture bio: create slab at 0 SCSI subsystem initialized

usbcore: registered new interface driver usbfs usbcore: registered new interface driver hub usbcore: registered new device driver usb NET: Registered protocol family 2

IP route cache hash table entries: 1024 (order: 0, 4096 bytes) TCP established hash table entries: 2048 (order: 2, 16384 bytes) TCP bind hash table entries: 2048 (order: 1, 8192 bytes) TCP: Hash tables configured (established 2048 bind 2048) TCP reno registered

UDP hash table entries: 256 (order: 0, 4096 bytes) UDP-Lite hash table entries: 256 (order: 0, 4096 bytes) NET: Registered protocol family 1

RPC: Registered named UNIX socket transport module. RPC: Registered udp transport module. RPC: Registered tcp transport module.

RPC: Registered tcp NFSv4.1 backchannel transport module. NetWinder Floating Point Emulator V0.97 (extended precision) s3c-adc s3c24xx-adc: attached adc driver

JFFS2 version 2.2. (NAND) (SUMMARY) 漏 2001-2006 Red Hat, Inc. ROMFS MTD (C) 2007 Red Hat, Inc. msgmni has been set to 117 io scheduler noop registered io scheduler deadline registered io scheduler cfq registered (default)

Console: switching to colour frame buffer device 40x30 fb0: s3c2410fb frame buffer device

Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled

s3c2410-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 70) is a S3C2410

console [ttySAC0] enabled

s3c2410-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 73) is a S3C2410 lp: driver loaded but no devices found ==========beep============== ==========led============= ppdev: user-space parallel port driver brd: module loaded loop: module loaded

Uniform Multi-Platform E-IDE driver ide-gd driver 1.18 ide-cd driver 5.00

SCSI Media Changer driver v0.25

S3C24XX NAND Driver, (c) 2004 Simtec Electronics

s3c24xx-nand s3c2410-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns s3c24xx-nand s3c2410-nand: NAND hardware ECC

NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit) Scanning device for bad blocks Creating 4 MTD partitions on \0x000000000000-0x000000040000 : \0x000000040000-0x000000440000 : \0x000000440000-0x000000c40000 : \0x000000c40000-0x000004000000 : \

Cirrus Logic CS8900A driver for Linux (Modified for SMDK2410) eth0: CS8900A rev E at 0xe0000300 irq=53, addr: 00: 0:3E:26:0A: 0 ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver s3c2410-ohcis3c2410-ohci: S3C24XX OHCI

s3c2410-ohcis3c2410-ohci: new USB bus registered, assigned bus number 1 s3c2410-ohcis3c2410-ohci: irq 42, io mem 0x49000000 hub 1-0:1.0: USB hub found hub 1-0:1.0: 2 ports detected Initializing USB Mass Storage driver...

usbcore: registered new interface driver usb-storage USB Mass Storage support registered.

usbcore: registered new interface driver libusual usbcore: registered new interface driver usbserial USB Serial support registered for generic

usbcore: registered new interface driver usbserial_generic usbserial: USB Serial Driver core

USB Serial support registered for FTDI USB Serial Device usbcore: registered new interface driver ftdi_sio ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver USB Serial support registered for pl2303 usbcore: registered new interface driver pl2303 pl2303: Prolific PL2303 USB to serial adaptor driver mousedev: PS/2 mouse device common for all mice S3C24XX RTC, (c) 2004,2006Simtec Electronics s3c-rtc s3c2410-rtc: rtc disabled, re-enabling s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0 Linux video capture interface: v2.00

usbcore: registered new interface driver uvcvideo USB Video Class driver (1.1.1)

S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics

s3c2410-wdts3c2410-wdt: watchdog inactive, reset disabled, irq enabled s3c-sdi s3c2410-sdi: powered down.

s3c-sdi s3c2410-sdi: mmc0 - using pio, sw SDIO IRQ TCP cubic registered

NET: Registered protocol family 17

s3c-rtc s3c2410-rtc: setting system clock to 2003-12-26 11:23:28 UTC (1072437808) cs8900_start

enable the ethernetcontrolle request_irq

IP-Config: Guessing netmask 255.255.255.0 IP-Config: Complete:

device=eth0, addr=192.168.2.200, mask=255.255.255.0, gw=255.255.255.255, host=192.168.2.200, domain=, nis-domain=(none),

bootserver=255.255.255.255, rootserver=192.168.2.201, rootpath=

VFS: Mounted root (nfs filesystem) on device 0:12. Freeing init memory: 140K

Please press Enter to activate this console.

[root@$ /]#usb 1-1: new full speed USB device number 2 using s3c2410-ohci uvcvideo: Found UVC 1.00 device USB2.0 Camera (1871:0316)

input: USB2.0 Camera as /devices/platform/s3c2410-ohci/usb1/1-1/1-1:1.0/input/input0 [root@$ /]#ls

beep_app dev home linuxrc root tmp binetcled_appmntsbinusr

boot fun lib proc sys var

VFS: Mounted root (nfs filesystem) on device 0:12. Freeing init memory: 140K

Please press Enter to activate this console.

[root@$ /]#usb 1-1: new full speed USB device number 2 using s3c2410-ohci uvcvideo: Found UVC 1.00 device USB2.0 Camera (1871:0316)

input: USB2.0 Camera as /devices/platform/s3c2410-ohci/usb1/1-1/1-1:1.0/input/input0 [root@$ /]#ls

beep_app dev home linuxrc root tmp binetcled_appmntsbinusr

boot fun lib proc sys var

本文来源:https://www.bwwdw.com/article/hezv.html

Top