首页 > 代码库 > AM335x(TQ335x)学习笔记——Nand&&网卡驱动移植

AM335x(TQ335x)学习笔记——Nand&&网卡驱动移植

移植完成声卡驱动之后本想再接再励,移植网卡驱动,但没想到的是TI维护的内核太健壮,移植网卡驱动跟之前移植按键驱动一样简单,Nand驱动也是如此,于是,本人将Nand和网卡放在同一篇文章中介绍。介绍之前先感慨一下:TI的维护的内核真的很健壮,DTS真的很强大。

1. Nand驱动移植

阅读TQ335x的原理图可知,TQ335x的Nand连接到了GPMC上,且都是使用的相应引脚的MODE0复用功能,AM335x上上电复位后这些引脚的默认状态就处于MODE0模式,故无需进行pinmux设置,原始的DTS中pinmux仅有一条:

0x160 (PIN_INPUT | MUX_MODE7)       /* spi0_cs1.gpio0_6 */
此处不做任何修改,直接编译内核,并放到开发板上运行会发现内核可以识别Nand但是因为没有开启OMAP的BCH功能,该项配置需要在内核配置项中进行配置,配置方式如下:

Device Drivers  --->
	<*> Memory Technology Device (MTD) support  --->
		<*>   NAND Device Support  --->
			<*>     Support hardware based BCH error correction
保存配置并退出menuconfig,然后重新编译内核并放到开发板上运行,此时会发现内核已经可以正常识别Nand了,完整的启动Log会在文章末尾给出。从这里可以看出,TI的内核维护的真的很不错,比以前移植三星芯片时省事很多。

2. 网卡驱动移植

进行网卡驱动移植的方法与进行Nand驱动移植的方法相同,逻辑上讲,先应该去确认下网卡的引脚连接并在DTS中进行相应的pinmux设置,但是,移植完Nand后查看内核的启动Log可知,网卡已经正常识别了,因此,可以直接执行指令:

udhcpc
来动态获取ip(需要将开发板通过网线连接到路由器并开启路由器的DHCP功能,默认一般是开启的),会发现开发板能够从路由器分配到IP,但是没有分配DNS,这是因为我们只做文件系统时没有进行dhcp的设置。设置方法很简单,将busybox中的examples/udhcp/simple.script拷贝到根文件系统的usr/share/udhcpc/目录下,并改名为default.script即可。然后重新执行:

udhcpc

会发现开发板可以正常获取到IP和DNS,但是仍有一处错误,详细如下:

@tq335x #udhcpc 
udhcpc (v1.22.1) started
Setting IP address 0.0.0.0 on eth0
[   11.489311] net eth0: initializing cpsw version 1.12 (0)
[   11.576237] net eth0: phy found : id is : 0x1cc915
<span style="color:#ff0000;">[   11.581418] libphy: PHY 4a101000.mdio:01 not found
[   11.586480] net eth0: phy 4a101000.mdio:01 not found on slave 1</span>
Sending discover...
[   13.576458] cpsw 4a100000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
Sending discover...
Sending select for 192.168.0.103...
Lease of 192.168.0.103 obtained, lease time 86400
Setting IP address 192.168.0.103 on eth0
Deleting routers
route: SIOCDELRT: No such process
Adding router 192.168.0.1
Recreating /etc/resolv.conf
 Adding DNS server 10.0.0.1
标记红色的文字即错误所在,参考TI官网提供的evm开发板的dts,本文对tq335x.dts做如下修改:

&mac {
    <span style="color:#ff0000;">slaves = <1>;</span>
    pinctrl-names = "default", "sleep";
    pinctrl-0 = <&cpsw_default>;
    pinctrl-1 = <&cpsw_sleep>;
    status = "okay";
};
然后删除以下节点:
&cpsw_emac1 {
    phy_id = <&davinci_mdio>, <1>;
    phy-mode = "rgmii-txid";
};
重新编译tq335x.dtb:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- tq335x.dtb
用新的tq335x.dtb启动开发板:
load mmc 0:1 0x88000000 /boot/tq335x.dtb
load mmc 0:1 0x82000000 /boot/zImage
bootz 0x82000000 - 0x88000000
最后,再次使用指令:

udhcpc
进行测试,会发现开发板能够正常获取IP和DNS。如果您的路由器已经连接到了外网,还可以使用ping指令测试与外网的连接,如ping谷歌的DNS服务器:
ping 8.8.8.8
至此,就完成了TQ335x的Nand和网卡驱动移植,并不需要深入的了解其内部的工作原理,有问题可以留言讨论。如果想了解这两个模块的工作原理,强烈推荐韦东山老师的嵌入式教学视频,静下心来看的话,绝对物有所值。该视频还是需要一定的硬件和软件功底的,如果看不懂可以补习下C语言、基本原理图阅读等方面的知识。

3. 启动Log

完整的启动Log如下:

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 3.17.2 (lilianrong@smarter) (gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-12ubuntu1) ) #73 SMP Tue Dec 23 22:06:01 CST 2014
[    0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] Machine model: TI AM335x EVM
[    0.000000] cma: Reserved 16 MiB at 9e800000
[    0.000000] Memory policy: Data cache writeback
[    0.000000]   HighMem zone: 1048574 pages exceeds freesize 0
[    0.000000] CPU: All CPU(s) started in SVC mode.
[    0.000000] AM335X ES2.1 (sgx neon )
[    0.000000] PERCPU: Embedded 9 pages/cpu @dfa99000 s14336 r8192 d14336 u36864
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 129792
[    0.000000] Kernel command line: console=ttyO0,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext3 rootwait
[    0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Memory: 484108K/523264K available (6082K kernel code, 667K rwdata, 2448K rodata, 410K init, 8214K bss, 39156K reserved, 0K highmem)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xffe00000   (2048 kB)
[    0.000000]     vmalloc : 0xe0800000 - 0xff000000   ( 488 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xe0000000   ( 512 MB)
[    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
[    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)
[    0.000000]       .text : 0xc0008000 - 0xc085cc80   (8532 kB)
[    0.000000]       .init : 0xc085d000 - 0xc08c3800   ( 410 kB)
[    0.000000]       .data : 0xc08c4000 - 0xc096ac10   ( 668 kB)
[    0.000000]        .bss : 0xc096ac10 - 0xc11707a0   (8215 kB)
[    0.000000] Hierarchical RCU implementation.
[    0.000000]  RCU restricting CPUs from NR_CPUS=2 to nr_cpu_ids=1.
[    0.000000] RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[    0.000000] NR_IRQS:16 nr_irqs:16 16
[    0.000000] IRQ: Found an INTC at 0xfa200000 (revision 5.0) with 128 interrupts
[    0.000000] Total of 128 interrupts on 1 active controller
[    0.000000] OMAP clockevent source: timer2 at 24000000 Hz
[    0.000013] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 178956969942ns
[    0.000062] OMAP clocksource: timer1 at 24000000 Hz
[    0.000794] Console: colour dummy device 80x30
[    0.000846] Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar
[    0.000855] ... MAX_LOCKDEP_SUBCLASSES:  8
[    0.000863] ... MAX_LOCK_DEPTH:          48
[    0.000870] ... MAX_LOCKDEP_KEYS:        8191
[    0.000877] ... CLASSHASH_SIZE:          4096
[    0.000884] ... MAX_LOCKDEP_ENTRIES:     32768
[    0.000891] ... MAX_LOCKDEP_CHAINS:      65536
[    0.000898] ... CHAINHASH_SIZE:          32768
[    0.000906]  memory used by lock dependency info: 5167 kB
[    0.000914]  per task-struct memory footprint: 1152 bytes
[    0.000956] Calibrating delay loop... 996.14 BogoMIPS (lpj=4980736)
[    0.079052] pid_max: default: 32768 minimum: 301
[    0.079452] Security Framework initialized
[    0.079577] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.079589] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.081767] CPU: Testing write buffer coherency: ok
[    0.082936] CPU0: thread -1, cpu 0, socket -1, mpidr 0
[    0.083055] Setting up static identity map for 0x805c3270 - 0x805c32e0
[    0.086292] Brought up 1 CPUs
[    0.086313] SMP: Total of 1 processors activated.
[    0.086323] CPU: All CPU(s) started in SVC mode.
[    0.088953] devtmpfs: initialized
[    0.097712] VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 3
[    0.133428] omap_hwmod: tptc0 using broken dt data from edma
[    0.133784] omap_hwmod: tptc1 using broken dt data from edma
[    0.134117] omap_hwmod: tptc2 using broken dt data from edma
[    0.141998] omap_hwmod: debugss: _wait_target_disable failed
[    0.199949] pinctrl core: initialized pinctrl subsystem
[    0.202465] regulator-dummy: no parameters
[    0.232121] NET: Registered protocol family 16
[    0.240699] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.242951] cpuidle: using governor ladder
[    0.242981] cpuidle: using governor menu
[    0.254980] OMAP GPIO hardware version 0.1
[    0.270240] omap-gpmc 50000000.gpmc: could not find pctldev for node /pinmux@44e10800/nandflash_pins_s0, deferring probe
[    0.270283] platform 50000000.gpmc: Driver omap-gpmc requests probe deferral
[    0.274806] hw-breakpoint: debug architecture 0x4 unsupported.
[    0.319718] edma-dma-engine edma-dma-engine.0: TI EDMA DMA engine driver
[    0.321050] vbat: 5000 mV 
[    0.321878] lis3_reg: no parameters
[    0.325259] SCSI subsystem initialized
[    0.326052] usbcore: registered new interface driver usbfs
[    0.326223] usbcore: registered new interface driver hub
[    0.330168] usbcore: registered new device driver usb
[    0.330998] omap_i2c 44e0b000.i2c: could not find pctldev for node /pinmux@44e10800/pinmux_i2c0_pins, deferring probe
[    0.331037] platform 44e0b000.i2c: Driver omap_i2c requests probe deferral
[    0.331092] omap_i2c 4802a000.i2c: could not find pctldev for node /pinmux@44e10800/pinmux_i2c1_pins, deferring probe
[    0.331116] platform 4802a000.i2c: Driver omap_i2c requests probe deferral
[    0.332291] Advanced Linux Sound Architecture Driver Initialized.
[    0.335642] Switched to clocksource timer1
[    0.487189] NET: Registered protocol family 2
[    0.489058] TCP established hash table entries: 4096 (order: 2, 16384 bytes)
[    0.489243] TCP bind hash table entries: 4096 (order: 5, 147456 bytes)
[    0.490606] TCP: Hash tables configured (established 4096 bind 4096)
[    0.490797] TCP: reno registered
[    0.490823] UDP hash table entries: 256 (order: 2, 20480 bytes)
[    0.491013] UDP-Lite hash table entries: 256 (order: 2, 20480 bytes)
[    0.492039] NET: Registered protocol family 1
[    0.493915] RPC: Registered named UNIX socket transport module.
[    0.493936] RPC: Registered udp transport module.
[    0.493946] RPC: Registered tcp transport module.
[    0.493955] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.495229] hw perfevents: enabled with armv7_cortex_a8 PMU driver, 5 counters available
[    0.499735] futex hash table entries: 256 (order: 2, 16384 bytes)
[    0.504791] VFS: Disk quotas dquot_6.5.2
[    0.504950] Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    0.507753] NFS: Registering the id_resolver key type
[    0.508115] Key type id_resolver registered
[    0.508132] Key type id_legacy registered
[    0.508279] jffs2: version 2.2. (NAND) (SUMMARY)  漏 2001-2006 Red Hat, Inc.
[    0.508729] msgmni has been set to 977
[    0.513651] io scheduler noop registered
[    0.513685] io scheduler deadline registered
[    0.513753] io scheduler cfq registered (default)
[    0.516150] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568
[    0.521255] backlight supply power not found, using dummy regulator
[    0.524492] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.530892] omap_uart 44e09000.serial: no wakeirq for uart0
[    0.531504] 44e09000.serial: ttyO0 at MMIO 0x44e09000 (irq = 88, base_baud = 3000000) is a OMAP UART0
[    1.232153] console [ttyO0] enabled
[    1.241558] omap_rng 48310000.rng: OMAP Random Number Generator ver. 20
[    1.249198] [drm] Initialized drm 1.1.0 20060810
[    1.261409] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[    1.268521] [drm] No driver support for vblank timestamp query.
[    1.331152] Console: switching to colour frame buffer device 100x30
[    1.342247] tilcdc 4830e000.lcdc: fb0:  frame buffer device
[    1.348135] tilcdc 4830e000.lcdc: registered panic notifier
[    1.354036] [drm] Initialized tilcdc 1.0.0 20121205 on minor 0
[    1.389964] brd: module loaded
[    1.408309] loop: module loaded
[    1.414443] mtdoops: mtd device (mtddev=name/number) must be supplied
[    1.425081] usbcore: registered new interface driver asix
[    1.430985] usbcore: registered new interface driver ax88179_178a
[    1.437512] usbcore: registered new interface driver cdc_ether
[    1.443772] usbcore: registered new interface driver smsc95xx
[    1.449928] usbcore: registered new interface driver net1080
[    1.455981] usbcore: registered new interface driver cdc_subset
[    1.462281] usbcore: registered new interface driver zaurus
[    1.468354] usbcore: registered new interface driver cdc_ncm
[    1.476438] usbcore: registered new interface driver cdc_wdm
[    1.482554] usbcore: registered new interface driver usb-storage
[    1.489102] usbcore: registered new interface driver usbtest
[    1.497261] mousedev: PS/2 mouse device common for all mice
[    1.508204] omap_rtc 44e3e000.rtc: rtc core: registered 44e3e000.rtc as rtc0
[    1.516418] i2c /dev entries driver
[    1.520156] Driver for 1-wire Dallas network protocol.
[    1.533123] omap_wdt: OMAP Watchdog Timer Rev 0x01: initial timeout 60 sec
[    1.543243] omap_hsmmc 48060000.mmc: unable to get vmmc regulator -517
[    1.550707] platform 48060000.mmc: Driver omap_hsmmc requests probe deferral
[    1.560219] ledtrig-cpu: registered to indicate activity on CPUs
[    1.567132] usbcore: registered new interface driver usbhid
[    1.572953] usbhid: USB HID core driver
[    1.584275] davinci_evm sound: ASoC: CODEC (null) not registered
[    1.591095] davinci_evm sound: snd_soc_register_card failed (-517)
[    1.597727] platform sound: Driver davinci_evm requests probe deferral
[    1.605542] oprofile: using arm/armv7
[    1.610156] TCP: cubic registered
[    1.613633] Initializing XFRM netlink socket
[    1.618345] NET: Registered protocol family 17
[    1.623080] NET: Registered protocol family 15
[    1.628155] Key type dns_resolver registered
[    1.632833] omap_voltage_late_init: Voltage driver support not added
[    1.639539] sr_dev_init: No voltage domain specified for smartreflex0. Cannot initialize
[    1.648011] sr_dev_init: No voltage domain specified for smartreflex1. Cannot initialize
[    1.657602] ThumbEE CPU extension supported.
[    1.662123] Registering SWP/SWPB emulation handler
[    1.667204] SmartReflex Class3 initialized
[    1.679204] omap-gpmc 50000000.gpmc: GPMC revision 6.0
[    1.686359] nand: device found, Manufacturer ID: 0xec, Chip ID: 0xd3
[    1.693006] nand: Samsung NAND 1GiB 3,3V 8-bit
[    1.697702] nand: 1024MiB, SLC, page size: 2048, OOB size: 64
[    1.703702] nand: using OMAP_ECC_BCH8_CODE_HW ECC scheme
[    1.709544] 10 ofpart partitions found on MTD device omap2-nand.0
[    1.715935] Creating 10 MTD partitions on "omap2-nand.0":
[    1.721581] 0x000000000000-0x000000020000 : "NAND.SPL"
[    1.738760] 0x000000020000-0x000000040000 : "NAND.SPL.backup1"
[    1.750072] 0x000000040000-0x000000060000 : "NAND.SPL.backup2"
[    1.759540] 0x000000060000-0x000000080000 : "NAND.SPL.backup3"
[    1.770709] 0x000000080000-0x0000000c0000 : "NAND.u-boot-spl"
[    1.780999] 0x0000000c0000-0x0000001c0000 : "NAND.u-boot"
[    1.794193] 0x0000001c0000-0x0000001e0000 : "NAND.u-boot-env"
[    1.803810] 0x0000001e0000-0x000000200000 : "NAND.u-boot-env.backup1"
[    1.815705] 0x000000200000-0x000000a00000 : "NAND.kernel"
[    1.831741] 0x000000a00000-0x000010000000 : "NAND.file-system"
[    2.128744] tps65910 0-002d: No interrupt support, no core IRQ
[    2.145804] vrtc: 1800 mV 
[    2.149201] vrtc: supplied by vbat
[    2.156403] vio: at 1500 mV 
[    2.159674] vio: supplied by vbat
[    2.166535] vdd_mpu: 912 <--> 1312 mV at 1325 mV 
[    2.171674] vdd_mpu: supplied by vbat
[    2.178847] vdd_core: 912 <--> 1150 mV at 1137 mV 
[    2.184071] vdd_core: supplied by vbat
[    2.190808] vdd3: 5000 mV 
[    2.196352] vdig1: at 1800 mV 
[    2.199763] vdig1: supplied by vbat
[    2.206242] vdig2: at 1800 mV 
[    2.209646] vdig2: supplied by vbat
[    2.216312] vpll: at 1800 mV 
[    2.219632] vpll: supplied by vbat
[    2.226021] vdac: at 1800 mV 
[    2.229339] vdac: supplied by vbat
[    2.235593] vaux1: at 1800 mV 
[    2.238998] vaux1: supplied by vbat
[    2.245289] vaux2: at 3300 mV 
[    2.248809] vaux2: supplied by vbat
[    2.255223] vaux33: at 3300 mV 
[    2.258804] vaux33: supplied by vbat
[    2.265220] vmmc: 1800 <--> 3300 mV at 3300 mV 
[    2.270279] vmmc: supplied by vbat
[    2.276822] vbb: at 3000 mV 
[    2.280309] vbb: supplied by vbat
[    2.288030] omap_i2c 44e0b000.i2c: bus 0 rev0.11 at 400 kHz
[    2.301649] omap_i2c 4802a000.i2c: bus 1 rev0.11 at 100 kHz
[    2.347377] wm8960 0-001a: No platform data supplied
[    2.424716] mmc0: host does not support reading read-only switch. assuming write-enable.
[    2.436373] mmc0: new high speed SDHC card at address aaaa
[    2.444716] mmcblk0: mmc0:aaaa SL16G 14.8 GiB 
[    2.456727]  mmcblk0: p1 p2
[    2.471831] davinci_evm sound: wm8960-hifi <-> 4803c000.mcasp mapping ok
[    2.555784] davinci_mdio 4a101000.mdio: davinci mdio revision 1.6
[    2.562174] davinci_mdio 4a101000.mdio: detected phy mask ffffffde
[    2.572385] libphy: 4a101000.mdio: probed
[    2.576709] davinci_mdio 4a101000.mdio: phy[0]: device 4a101000.mdio:00, driver unknown
[    2.585071] davinci_mdio 4a101000.mdio: phy[5]: device 4a101000.mdio:05, driver unknown
[    2.594702] cpsw 4a100000.ethernet: Detected MACID = c4:ed:ba:88:b5:e4
[    2.606568] input: gpio_keyad@0 as /devices/gpio_keyad@0/input/input0
[    2.616308] omap_rtc 44e3e000.rtc: setting system clock to 2000-01-01 00:00:00 UTC (946684800)
[    2.625329] sr_init: No PMIC hook to init smartreflex
[    2.630961] sr_init: platform driver register failed for SR
[    2.653937] lis3_reg: disabling
[    2.657604] ALSA device list:
[    2.660710]   #0: AM335x-EVM
[    2.779242] kjournald starting.  Commit interval 5 seconds
[    2.787736] EXT3-fs (mmcblk0p2): using internal journal
[    2.795710] EXT3-fs (mmcblk0p2): recovery complete
[    2.800726] EXT3-fs (mmcblk0p2): mounted filesystem with ordered data mode
[    2.808089] VFS: Mounted root (ext3 filesystem) on device 179:2.
[    2.818461] devtmpfs: mounted
[    2.822292] Freeing unused kernel memory: 408K (c085d000 - c08c3000)
----------mount all..........
----------Starting mdev......

Please press Enter to activate this console. 
@tq335x #
@tq335x #udhcpc 
udhcpc (v1.22.1) started
Setting IP address 0.0.0.0 on eth0
[   11.489311] net eth0: initializing cpsw version 1.12 (0)
[   11.576237] net eth0: phy found : id is : 0x1cc915
[   11.581418] libphy: PHY 4a101000.mdio:01 not found
[   11.586480] net eth0: phy 4a101000.mdio:01 not found on slave 1
Sending discover...
[   13.576458] cpsw 4a100000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
Sending discover...
Sending select for 192.168.0.103...
Lease of 192.168.0.103 obtained, lease time 86400
Setting IP address 192.168.0.103 on eth0
Deleting routers
route: SIOCDELRT: No such process
Adding router 192.168.0.1
Recreating /etc/resolv.conf
 Adding DNS server 10.0.0.1
@tq335x #ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=38 time=471.858 ms
64 bytes from 8.8.8.8: seq=1 ttl=38 time=479.178 ms
64 bytes from 8.8.8.8: seq=3 ttl=38 time=574.362 ms
64 bytes from 8.8.8.8: seq=4 ttl=38 time=476.201 ms
^C
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 4 packets received, 20% packet loss
round-trip min/avg/max = 471.858/500.399/574.362 ms
@tq335x #






本文作者:girlkoo

本文连接:http://blog.csdn.net/girlkoo/article/details/42110683

AM335x(TQ335x)学习笔记——Nand&&网卡驱动移植