Chinaunix首页 | 论坛 | 博客
  • 博客访问: 333936
  • 博文数量: 92
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 960
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-21 19:38
文章分类

全部博文(92)

文章存档

2010年(71)

2009年(21)

我的朋友

分类: 嵌入式

2009-08-21 19:55:27

At the end of last semester, I successfully applied for a national project with other two students. Our aim is to create a PDA which can help owner control his or her private possessions, for example car or house door through bluetooth. We divided the whole project into three main part, in the first part we shall have a good understanding of Linux-arm environment, and make it sure that bluetooth module can work in the chip.  In the second step we will use Qt create user interface, finally we will create a real PDA include the function we need.
 
For the past two month, I have read several books about linux and linux device driver in Chinese. And with errors and faults, eventually I made a gcc-3.4.5-glibc-2.3.6 by using crosstool-0.43. Also I successfully used busybox-1.13.0 to create my own root file system which include dev etc lib mnt proc var tmp sys root. However the further I go into the embedded system world, the more knowledge I find myself lack. Therefore I am determined to pick a English linux book to read, and I choose "Essential Linux Device Drivers" written by Sreekrishnan Venkateswaran. I will make notes to record what I learn.
 
Chapter 1. Introduction
1>Linux Distribution
Because a GNU/Linux system consists of numerous utilities, programs, libraries, and tools, in addition to the
kernel, it's a daunting task to acquire and correctly install all the pieces. Linux distributions come to the rescue
by classifying the components and bundling them into packages in an orderly fashion.
what I use is Ubuntu
 
2>Looking at the Sources
the Linux kernel we choose is linux-2.6.26.5
 
3>Building the Kernel
 menuconfig is a text interface to the kernel configuration menu
 If you don't want to weave the configuration from scratch, use the file arch/your-arch/defconfig (or arch/yourarch/
configs/your-machine_defconfig if there are several supported platforms for your architecture) as the
starting point. So, if you are compiling the kernel for the 32-bit x86 architecture, do this:
bash> cp arch/x86/configs/i386_defconfig .config
          In my computer: #cp  arch/arm/configs/s3c2410_defconfig .config
Compile the kernel and generate a compressed boot image:
bash> make bzImage                                      
           In my computer: #make zImage
                                      #cp arch/arm/boot/zImage /tftpboot
 
 4>Loadable Modules
Because Linux runs on a variety of architectures and supports zillions of I/O devices, it's not feasible to
permanently compile support for all possible devices into the base kernel. Distributions generally package a
minimal kernel image and supply the rest of the functionalities in the form of kernel modules. During runtime,
the necessary modules are dynamically loaded on demand.
To generate modules, go to the root of your kernel source tree and build:
bash> cd /usr/src/linux-X.Y.Z/
bash> make modules
           In my computer # make modules
                                    # ls net/bluetooth/
af_bluetooth.c   bluetooth.mod.o  cmtp        hci_core.o   hci_sock.o   Kconfig      l2cap.mod.o  Makefile       sco.ko
af_bluetooth.o   bluetooth.o      hci_conn.c  hci_event.c  hci_sysfs.c  l2cap.c      l2cap.o      modules.order  sco.mod.c
bluetooth.ko     bnep             hci_conn.o  hci_event.o  hci_sysfs.o  l2cap.ko     lib.c        rfcomm         sco.mod.o
bluetooth.mod.c  built-in.o       hci_core.c  hci_sock.c   hidp         l2cap.mod.c  lib.o        sco.c          sco.o
It is very clear that bluetooth.ko  sco.ko   l2cap.ko
bash> make modules_install
This creates a kernel source directory structure under /lib/modules/X.Y.Z/kernel/ and populates it with loadable
module objects. This also invokes the depmod utility that generates module dependencies in the file
/lib/modules/X.Y.Z/modules.dep.
           In my computer  # vim /lib/modules/2.6.20-15-generic/modules.dep
/lib/modules/2.6.20-15-generic/kernel/net/bluetooth/bluetooth.ko:
/lib/modules/2.6.20-15-generic/kernel/net/bluetooth/sco.ko: /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/bluetooth.ko
/lib/modules/2.6.20-15-generic/kernel/net/bluetooth/hidp/hidp.ko: /lib/modules/2.6.20-15-generic/kernel/drivers/hid/hid.ko /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/l2cap.ko /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/bluetooth.ko
/lib/modules/2.6.20-15-generic/kernel/net/bluetooth/rfcomm/rfcomm.ko: /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/l2cap.ko /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/bluetooth.ko
/lib/modules/2.6.20-15-generic/kernel/net/bluetooth/l2cap.ko: /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/bluetooth.ko
/lib/modules/2.6.20-15-generic/kernel/net/bluetooth/cmtp/cmtp.ko: /lib/modules/2.6.20-15-generic/kernel/drivers/isdn/capi/kernelcapi.ko /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/l2cap.ko /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/bluetooth.ko
/lib/modules/2.6.20-15-generic/kernel/net/bluetooth/bnep/bnep.ko: /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/l2cap.ko /lib/modules/2.6.20-15-generic/kernel/net/bluetooth/bluetooth.ko
            In my computer    # modprobe l2cap
                                         # lsmod

Module                  Size  Used by
l2cap                  25728  0
bluetooth              55908  1 l2cap

             It is very clear that modprobe is very clever, before it insmod l2cap, it will probe other modules that l2cap will need.
 
Here is something I fail to understand in this chapter:
To compile a kernel driver as a module, toggle the corresponding menu choice button to while configuring
the kernel. Most of the device driver examples in this book are implemented as kernel modules. To build a
module mymodule.ko from its source file mymodule.c, create a one-line Makefile and execute it as follows:
bash> cd /path/to/module-source/
bash> echo "obj-m += mymodule.ko" > Makefile
bash> make –C /path/to/kernel-sources/ M=`pwd` modules
make: Entering directory '/path/to/kernel-sources'
Building modules, stage 2.
MODPOST
CC /path/to/module-sources/mymodule.mod.o
LD [M] /path/to/module-sources/mymodule.ko
make: Leaving directory '/path/to/kernel-sources'
bash> insmod ./mymodule.ko
                                   

 
阅读(1030) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~