• 欢迎访问少将全栈,学会感恩,乐于付出,珍惜缘份,成就彼此、推荐使用最新版火狐浏览器和Chrome浏览器访问本网站。
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏少将全栈吧
  • 欢迎加博主微信:jiang_shaobo

pcDuino linux内核驱动开发一入门

点滴 admin 6年前 (2014-03-20) 420次浏览 已收录 扫描二维码

继pcDuino
linux移植一、二、三,成功搭建linux最小系统,抽点时间开始linux内核驱动开发之旅。由于时间关系,基本上都是边玩边写,一些还没写完甚至
有问题,就被转载了,以致大家看到的五花八门,希望转载的人也及时更新。遗留的很多问题随着时间都慢慢解决了,都是亲身体验能跑起来的,才敢写在这。我自
己收获了很多,希望读到的人也能有收获,希望能一直坚持下去。

开发环境
系统:ubuntu 10.04.4
板:pcDuino(全志A10)
编译器:gcc-linaro-arm-linux-gnueabihf-4.8-2013.04-20130417_linux.tar.bz2
搭建开发环境详见ubuntu 10.04.4开发环境配置。

目标
一.配置 编译android-3.4.29,放到pcDuino上,板子串口正常输出
二.配置内核,支持nfs挂载网络文件系统
三.最简内核驱动开发

这个是在pcDuino linux移植一、二、三的基础上写的,重点介绍内核驱动开发,其它具体移植过程不再详述。最基础的裸板开发、u-boot移植以及linux移植,参考前面的文章,这里不再重复。

一、编译内核

这里用官方提供的源码kernel for pcduino,我试了哈,这里面有些常用的驱动,比如网卡驱动之类,在官方提供的kernel平台再添加自己的驱动。

1.准备工作

获取交叉编译器 https://launchpad.net/linaro-toolchain-binaries/+download 我选的当时最新的gcc-linaro-arm-linux-gnueabihf-4.8-2013.04-20130417_linux.tar.bz2,下载解压即可,配置过程还不清楚的看Ubuntu 10.04.4开发环境配置。

获取内核源码git clone https://github.com/pcduino/kernel ,没有git要先安装git,sudo apt-get install git.

change@change:~$ git clone https://github.com/pcduino/kernel
便会在当前目录下生成kernel目录,并获取源码,这个过程有点长,与网速有关,耐心等待

2.配置、编译内核

打开kernel目录下的Makefile,修改6:

CROSS_COMPILE= your-path /gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux/bin/arm-linux-gnueabihf-

其中your-path是gcc-linaro-arm-linux-gnueabihf-4.8-2013.04-20130417_linux.tar.bz2的解压路径

change@change:~$ cd kernel/
change@change:~/kernel$ cd linux-sunxi/
change@change:~/kernel/linux-sunxi$ make mrproper

change@change:~/kernel/linux-sunxi$ cd ..
change@change:~/kernel$ make linux

编译过程超长,我编译这个花了一下午,编译过程会遇到些问题,我在pcduino linux 移植二就有遇到

Package libusb-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libusb-1.0.pc’
to the PKG_CONFIG_PATH environment variable
No package ’libusb-1.0’ found
Package libusb-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libusb-1.0.pc’
to the PKG_CONFIG_PATH environment variable
No package ’libusb-1.0’ found

解决方法:

change@change:/$ sudo apt-get install libusb-1.0-0-dev

change@change:/$ ls /usr/lib/pkgconfig/libusb-1.0.pc
/usr/lib/pkgconfig/libusb-1.0.pc

change@change:/$ export PKG_CONFIG_PATH=/usr/lib/pkgconfig:$PKG_CONFIG_PATH
change@change:/$ set | grep PKG_CONFIG
PKG_CONFIG_PATH=/usr/lib/pkgconfig:
change@change:/$ pkg-config libusb-1.0 –cflags –libs
-I/usr/include/libusb-1.0 -lusb-1.0
这个问题就解决了。还有的问题也能在前面pcduino linux 移植中找到,不再重复。编译完成最终会在下面目录下生成内核镜像

change@change:~$ cd kernel/build/sun4i_defconfig-linux/arch/arm/boot/
change@change:~/kernel/build/sun4i_defconfig-linux/arch/arm/boot$ ls
compressed Image uImage zImage
change@change:~/kernel/build/sun4i_defconfig-linux/arch/arm/boot$

3.测试

经过pcDuino
linux移植一、二、三,我们已制作一张可启动的tf卡,现在用我们新的内核uImage,替换掉以前的进行测试。将上次制作的启动卡插到PC机,弹出
窗口,直接拷贝上面编译生成的uimage到sdb1,替换掉以前的,取下tf卡插到pcduino启动如下:

U-Boot 2012.10 (Apr 19 2013 – 18:46:44) Allwinner Technology

CPU: SUNXI Family
Board: pcDuino
I2C: ready
DRAM: 1 GiB
MMC: SUNXI SD/MMC: 0
*** Warning – bad CRC, using default environment

In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
reading uEnv.txt

144 bytes read
Loaded environment from uEnv.txt
reading boot.scr

270 bytes read
Jumping to boot.scr
## Executing script at 44000000
reading script.bin

” from mmc 0:1 ** “script.bin
reading uImage

” from mmc 0:1 ** “uImage
bootm – boot application image from memory

Usage:
bootm [addr [arg …]]
– boot application image stored in memory
passing arguments ’arg …’; when booting a Linux kernel,
’arg’ can be the address of an initrd image

Sub-commands to do part of the bootm sequence. The sub-commands must be
issued in the order below (it’s ok to not issue all sub-commands):
start [addr [arg …]]
loados – load OS image
cmdline – OS specific command line processing/setup
bdt – OS specific bd_t processing
prep – OS specific prep before relocation or go
go – start OS
reading script.bin

44900 bytes read
reading uImage

6339288 bytes read
## Booting kernel from Legacy Image at 48000000 …
Image Name: Linux-3.4.29++
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 6339224 Bytes = 6 MiB
Load Address: 40008000
Entry Point: 40008000
Verifying Checksum … OK
Loading Kernel Image … OK
OK

Starting kernel …

[ 0.000000] Booting Linux on physical CPU 0
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Linux version 3.4.29++ ( change@change ) (gcc version 4.7.3 20130328 (prerelease) (crosstool-NG
linaro-1.13.1-4.7-2013.04-20130415 – Linaro GCC 2013.04) ) #2 PREEMPT
Mon May 6 12:33:31 CST 2013
[ 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: sun4i
[ 0.000000] Memory cut off:
[ 0.000000] MALI : 0x5c000000 – 0x5fffffff ( 64 MB)
[ 0.000000] Ignoring unrecognised tag 0x00000000
[ 0.000000] Memory Reserved:

……….//省略若干,太长了

[ 6.100000] Freeing init memory: 1628K
[ 6.620000] Warning: this sunxi disp driver will see significant redesign.
[ 6.620000] Applications using /dev/disp directly will break.
[ 6.630000] For more information visit: http://linux-sunxi.org/Sunxi_disp_driver
[ 6.640000] disp: process 53 (setwindow) has skipped the version handshake.
/dev/mmcblk0p2
e2fsck 1.42.7 (21-Jan-2013)
/dev/mmcblk0p2: clean, 452/59648 files, 9962/238087 blocks
[ 6.720000] EXT3-fs (mmcblk0p2): error: couldn’t mount because of unsupported optional features (240)
mount: mounting /dev/mmcblk0p2 on /mnt failed: Invalid argument
[ 6.750000] EXT4-fs (mmcblk0p2): barriers disabled
[ 6.770000] EXT4-fs (mmcblk0p2): mounted filesystem with
writeback data mode. Opts: noauto_da_alloc,barrier=0,data=writeback
mount: mounting devpts on /dev/pts failed: No such file or directory
mount: mounting /dev/mmcblk0p1 on /boot failed: No such file or directory

Please press Enter to activate this console.

Processing /etc/profile… Done

/ # ifconfig
/ # ifconfig eth0
eth0 Link encap:Ethernet HWaddr 62:09:5F:8B:FC:51
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:55 Base address:0xb000

/ # ifconfig eth0 172.16.1.111
[ 34.700000] wemac wemac.0: WARNING: no IRQ resource flags set.
[ 34.850000] wemac wemac.0: eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
/ # ifconfig
eth0 Link encap:Ethernet HWaddr 62:09:5F:8B:FC:51
inet addr:172.16.1.111 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::6009:5fff:fe8b:fc51/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:398 (398.0 B)
Interrupt:55 Base address:0xb000

/ # ping 172.16.1.134
PING 172.16.1.134 (172.16.1.134): 56 data bytes
64 bytes from 172.16.1.134: seq=0 ttl=64 time=1.354 ms
64 bytes from 172.16.1.134: seq=1 ttl=64 time=0.322 ms
64 bytes from 172.16.1.134: seq=2 ttl=64 time=0.987 ms
64 bytes from 172.16.1.134: seq=3 ttl=64 time=0.964 ms
^C
— 172.16.1.134 ping statistics —
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.322/0.906/1.354 ms
/ #

看到系统基本正常启动了,网卡工作也正常能ping通。先写到这里,下一步实现目标二,待续。。。

喜欢 (0)
[🍬谢谢你请我吃糖果🍬🍬~]
分享 (0)
关于作者:
少将,关注Web全栈开发、项目管理,持续不断的学习、努力成为一个更棒的开发,做最好的自己,让世界因你不同。