STLINUX基础知识介绍.ppt_第1页
STLINUX基础知识介绍.ppt_第2页
STLINUX基础知识介绍.ppt_第3页
STLINUX基础知识介绍.ppt_第4页
STLINUX基础知识介绍.ppt_第5页
已阅读5页,还剩28页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、STLINUX基础知识介绍,一:STLINUX介绍,STLINUX开发环境,STLinux Distribution and Development Environment (LDDE). 1:LDDE支持ST40及ST200 2:包含完整的开发环境、编译器、调试器、下载工具、系统监控器 3:可配置内核支持 4:集成uboot 5:Multicom支持,stlinux版本,STLinux Distribution 2.3(Added 5th Nov 2007) STLinux Distribution 2.3EAR (Early Access Release) (Added 29th Mar

2、2007) STLinux Distribution 2.2(Added 19th Oct 2006) STLinux Distribution 2.0(Added 7th Oct 2005) STLinux Distribution 2.0EAR(Added 16th Jul 2005) STLinux distribution 1.0(Added 21st Feb 2005),开发与调试,开发与调试,1:NFS 基于网络文件系统的调试,一般用于调试应用及驱动 2:TFTP 基于FTP传输协议的调试,一般用于调试boot及内核等 3:其他调试方法,常用命令,make sh4-linux-gc

3、c sh4-linux-g+ sh4-linux-ld sh4-linux-nm sh4-linux-objdump,二:STLINUX软件结构,系统框图,应用程序,系统接口,KERENL,ST DRIVER,SMIT DRIVER,硬件,移植kernel,选择kernel版本 选择kernel支持的参考板 裁减kernel make menuconfig 编译kernel make vmlinux 压缩kernel mkimage vmlinux,编译stapi,1:安装mutilcom3.1.2及reference tree 2:编译源码 3:生产动态可加载模块驱动及应用静态连接库,根文件

4、系统jffs2,可读写的文件系统 系统性能高,断电保护及碎片整理功能 数据压缩效率高 mkfs.jffs2 生产文件系统压缩包 GB310压缩包中:busybox、*.so.*、st firmware、*.ko、app.exe.,flash分区,8M flash空间分配如下: Uboot 0.25M Kernel 1.5M 文件系统 6.25M,u-boot介绍,Uboot是德国DENX小组的开发用于多种嵌入式CPU的bootloader程序 支持LINUX、NetBSD, VxWorks, QNX, RTEMS, ARTOS, LynxOS嵌入式操作系统 包含两种不同的操作模式:启动加载模式

5、和下载模式 支持从网络、flash中启动kernel 支持flash读写 传递参数给kernel,移植uboot,选择uboot版本 选择uboot支持的参考板 配置硬件资源及DDR等 修改驱动:flash、uart 、ethernet,U-BOOT命令,Boot Setenv Printenv Tftp Ping .,三:字符设备驱动,LINUX设备的分类,字符设备 串口,终端,触摸屏 ls -l /dev/ttyS0 crw-rw-rw- 1 root uucp 4, 64 4月 1 19:56 /dev/ttyS0 块设备 FLASH,RAMDISK,硬盘 ls -l /dev/mtdb

6、lock3 brw-r-r- 1 505 505 31, 3 Feb 19 2005 /dev/mtdblock3 网络设备 以 Linux 的方式看待设备可区分为 3 种基本设备类型. 每个模块常常实现 3 种类型中的 1 种, 因此可分类成字符模块, 块模块, 或者一个网络模块.,设备文件与设备号,用户通过设备文件访问设备 每个设备用一个主设备号和次设备号标识 主设备号和次设备号 major number:相同的设备使用相同的驱动程序 minor number:用来区分具体设备的实例,设备驱动的基本结构,设备驱动层图,设备驱动的功能,上层软件的抽象操作与设备操作的转换 对下管理各种I/O设

7、备,内核模块机制,Linux驱动以内核模块的方式实现 一组可以动态加载/卸载的代码 Linux内核运行时动态扩展的一种技术 模块机制(Linux Kernel Module,LKM)提高了linux内核的可扩展性 用户只要有权限,就可以编写模块挂入内核 模块的缺点:增加了内核管理代价,LINUX内核模块的框架,static int init_routine (void) register_chrdev_region() devfs_mk_cdev() void cleanup_routine(void) unregister_chrdev_region() module_init(init_r

8、outine); module_exit(cleanup_routine); MODULE_LICENSE(GPL);,LINUX内核模块的框架,struct file_operations loff_t (*llseek)(struct file *,loff_t,int); ssize_t (*read)(struct file *,char *,size_t,loff_t *); ssize_t (*write)(struct file *,const char *,size_t,loff_t *); int(*ioctl) (struct inode *,struct file *,u

9、nsigned int,unsigned long); int(*mmap) (struct file *,struct vm_area_struct *); int(*open) (struct inode *,struct file *); int(*release) (struct inode *,struct file *); int(*fsync) (struct file *,struct dentry *,int datasync); int(*fasync) (int,struct file *,int); ;,LINUX内核模块的框架,(1) llseek(file, off

10、set, whence):修改文件的读写指针。 (2) read(file, buf, count, offset):从设备文件的offset 处开始读出count个字节,然后增加*offset的值。 (3) write(file, buf, count, offset):从设备文件的offset处写入count个字节,然后增加*offset的值。 (4) ioctl(inode, file, cmd, arg):向一个硬件设备发命令,对设备进行控制。 (5) mmap(file, vma):将设备空间映射到进程地址空间。 (6) open(inode, file):打开并初始化设备。 (7)

11、 release(inode, file):关闭设备并释放资源。 (8) fsync(file, dentry):实现内存与设备之间的同步通信。 (9) fasync(file, on):实现内存与设备之间的异步通信。,简单字符设备驱程,Every LKM consists of two basic functions (minimum) : int init_module(void) /*used for all initialization stuff*/ . void cleanup_module(void) /*used for a clean shutdown*/ . 安装模块命令

12、# insmod module.o #modprobe module.o 卸载模块命令 # rmmod module.o 查询系统中已装入的模块 #lsmod,简单字符设备驱程,例子 hello.c #define MODULE #include int init_module(void) printk(Hello, worldn); return 0; void cleanup_module(void) printk(Goodbye cruel worldn); 编译模块 # gcc c hello.c DMODULE D_KERNEL_ -DLINUX -Wall O2 -I/usr/sr

13、c/linux-2.6/include 安装、卸载模块 # insmod hello.o Hello world # rmmod hello Goodbye cruel world,简单字符设备驱程,static struct file_operations helloworld_fops = open : helloworld_open, read : helloworld_read, write : helloworld_write, ioctl : helloworld_ioctl, ;/kernel space,简单字符设备驱程,ssize_t helloworld_write (st

14、ruct file *filp, char *buffer, size_t size, loff_t *offset)/kernel space unsigned char stringMAX_BYTE_NUM; unsigned char size1 = copy_from_user(string,buffer,size); return (size1); void helloworld_write(unsigned int addr, unsigned char data)/user space struct datadata1=.; write(fd, ,简单字符设备驱程,Kernel space 与user space数据交互 copy_to_user(void _user *to, const void *from, unsigned long n); copy_from_user(void *to, const void _user *from, unsigned long n);,模块设计注意事项,1:模块设计与应用程序设计 模块是装入内核的,运行时CPU处于核心态 应用程序运行时CPU处于用户态 2:编译模块 设计应用程序使用的include文件:/usr/include 设计内核模块使用的include文件:/usr/src/lin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论