STLINUX基础知识介绍

上传人:平*** 文档编号:47517670 上传时间:2018-07-02 格式:PPT 页数:33 大小:141.86KB
返回 下载 相关 举报
STLINUX基础知识介绍_第1页
第1页 / 共33页
STLINUX基础知识介绍_第2页
第2页 / 共33页
STLINUX基础知识介绍_第3页
第3页 / 共33页
STLINUX基础知识介绍_第4页
第4页 / 共33页
STLINUX基础知识介绍_第5页
第5页 / 共33页
点击查看更多>>
资源描述

《STLINUX基础知识介绍》由会员分享,可在线阅读,更多相关《STLINUX基础知识介绍(33页珍藏版)》请在金锄头文库上搜索。

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

2、07)oSTLinux Distribution 2.2(Added 19th Oct 2006) oSTLinux Distribution 2.0(Added 7th Oct 2005) oSTLinux Distribution 2.0EAR(Added 16th Jul 2005)oSTLinux distribution 1.0(Added 21st Feb 2005)开发与调试开发与调试o1:NFSo基于网络文件系统的调试,一般用于调试应用及驱动o2:TFTPo基于FTP传输协议的调试,一般用于调试boot及内核等o3:其他调试方法常用命令omakeosh4-linux-gccos

3、h4-linux-g+osh4-linux-ldosh4-linux-nmosh4-linux-objdump二:STLINUX软件结构系统框图应用程序系统接口KERENLST DRIVERSMIT DRIVER硬件移植kernelo选择kernel版本o选择kernel支持的参考板o裁减kernel make menuconfigo编译kernel make vmlinuxo压缩kernel mkimage vmlinux编译stapio1:安装mutilcom3.1.2及reference treeo2:编译源码o3:生产动态可加载模块驱动及应用静态连 接库根文件系统jffs2o可读写的文

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

5、络、flash中启动kernelo支持flash读写o传递参数给kernel移植ubooto选择uboot版本o选择uboot支持的参考板o配置硬件资源及DDR等o修改驱动:flash、uart 、ethernetU-BOOT命令oBootoSetenvoPrintenvoTftpoPingo.三:字符设备驱动LINUX设备的分类o字符设备n串口,终端,触摸屏nls -l /dev/ttyS0 crw-rw-rw- 1 root uucp 4, 64 4月 1 19:56 /dev/ttyS0o块设备nFLASH,RAMDISK,硬盘nls -l /dev/mtdblock3 brw-r-r-

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

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

8、t(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 *,unsigned int,unsigned l

9、ong);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, offset, whence):修改文件的读写指针。(2) re

10、ad(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) release(inode, file):关闭设备并释放资源。(

11、8) fsync(file, dentry):实现内存与设备之间的同步通信。(9) fasync(file, on):实现内存与设备之间的异步通信。简单字符设备驱程nEvery 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*/ . n安装模块命令 # insmod module.o #modprobe module.

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

13、 insmod hello.oHello world# rmmod helloGoodbye cruel world简单字符设备驱程ostatic struct file_operations helloworld_fops = o open : helloworld_open,o read : helloworld_read,o write : helloworld_write,o ioctl : helloworld_ioctl,o;/kernel space简单字符设备驱程ossize_t helloworld_write (struct file *filp, char *buffer

14、, size_t size, loff_t *offset)/kernel spaceoo unsigned char stringMAX_BYTE_NUM;o unsigned char size1 = copy_from_user(string,buffer,size);o return (size1); oovoid helloworld_write(unsigned int addr, unsigned char data)/user spaceoostruct datadata1=.;owrite(fd,o简单字符设备驱程Kernel space 与user space数据交互cop

15、y_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/linux-2.6/include 在编译内核模块时要用-I指明include路径3:设计的模块可以调用Linux内核及其他模块已经输出(exported) 的函数,不能利用标准C提供的库函数如printf模块设计注意事项4:区分应用部分代码与模块部分代码o一般要求代码尽量放入应用部分;o对于时间响应要求高的代码放入模块;o对硬件进行直接操作的代码放入模块;o中断在用户空间无法用o应用程序中有完整的 C 库可以连接.o应用程序由于自身原因错误不会对其他任务及内核有影响

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 教学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号