linux开发摘要

来源:互联网 发布:cs go mac 编辑:程序博客网 时间:2024/05/10 01:20

1.linux内核文档链接点击打开链接

2.配置文件

在out\target\product\project\obj\KERNEL_OBJ\.config中可以看到

 

  1. # CONFIG_MTD_LPDDR is not set  
  2. # CONFIG_MTD_UBI is not set  
  3. CONFIG_DTC=y  
  4. CONFIG_OF=y  
  5.   
  6.   
  7. #  
  8. # Device Tree and Open Firmware support  
  9. #  
  10. # CONFIG_PROC_DEVICETREE is not set  
  11. # CONFIG_OF_SELFTEST is not set  
  12. CONFIG_OF_FLATTREE=y  
  13. CONFIG_OF_EARLY_FLATTREE=y  
  14. CONFIG_OF_ADDRESS=y  
  15. CONFIG_OF_IRQ=y  
  16. CONFIG_OF_DEVICE=y  
  17. CONFIG_OF_I2C=y  
  18. CONFIG_OF_NET=y  
  19. CONFIG_OF_MDIO=y  
  20. CONFIG_OF_SPMI=y  
  21. CONFIG_OF_MTD=y  
  22. CONFIG_OF_SLIMBUS=y  
  23. CONFIG_OF_BATTERYDATA=y  
  24. CONFIG_OF_RESERVED_MEM=y  
  25. ...  

但这个文件是自动生成的,应该主要是由\kernel\arch\arm\configs下的文件汇总的,但是没有找到定义CONFIG_OF=y的源头。

对于msm8909平台user版本,.config文件是由msm8909-1gb_defconfig、kernel下Kconfig文件内容汇总在一起。每个Kconfig分别描述了所属目录源文件相关的内核配置菜单

但如果msm8909-1gb_defconfig注释了#CONFIG_QPNP_VM_BMS=y,但W:\kernel\drivers\power\Kconfig下对应的下有default=y,最后是以Kconfig的为准的

config QPNP_VM_BMS
tristate "QPNP Voltage-Mode Battery Monitoring System driver"
depends on SPMI
depends on MSM_QPNP_INT
default y
help
  Say Y here to enable support for QPNP chip vm-bms device.
  The voltage-mode (vm) BMS driver uses periodic VBATT
  readings from the battery to calculate the State of
  Charge.

如果Kconfig没有default,msm8909-1gb_defconfig的为#CONFIG_QPNP_VM_BMS=y或是CONFIG_QPNP_VM_BMS=,也就是没有选择或是没有设置,就在.config文件中插入一行注释# CONFIG_QPNP_VM_BMS is not set

3.主要的设备树文件

 \kernel\Documentation\devicetree\bindings\fb\mdss-dsi-panel.txt描述显示屏panel的配置信息
kernel\Documentation\devicetree\bindings\arm\gic.txt-----ARM Generic Interrupt Controller,ARM一般中断控制器设备树信息描述
kernel\Documentation\devicetree\bindings\interrupt-controller\interrupts.txt----Specifying interrupt information for devices

 \kernel\Documentation\input\input.txt和input-programming.txt介绍输入子系统

\kernel\Documentation\devicetree\bindings\pinctrl\msm-pinctrl.txt------------MSM TLMM pinmux controller

kernel\Documentation\devicetree\bindings\pinctrl\pinctrl-bindings.txt

 

4..CONFIG_OF

在一些驱动中经常看到#ifdef CONFIG_OF,这里的OF是Open Firmware。

Open Firmware. This was invented long time ago when Apple was producing laptops based on PowerPC CPUs. Openfirmware provides a good description of the devices connected to the platform. In Linux kernel the part that works with device data is called Device Tree (DT). More details in the Usage model.

详细参考kernel\Documentation\devicetree\usage-model.txt

 

5.mk文件(makefile)

 

 += (在现有的文件上,追加)
:= (之前的值清空,重新赋值)

 

6.fdt:flatteneddevice tree

 

7.modules.order:这个文件记录了Makefile中模块出现的顺序。modprobe通过它来确定解决多个模块匹配的别名(指定模块的绝对路径)。
如:kernel//home/cjz/Desktop/test/driver/input/vms.ko
 modules.builtin:这个文件列出了所有编译到内核的模块,通过这个当modprobe加载一些内核模块时就不会失败。

 

8.注册驱动的时候,通过对应的总线匹配到对应的设备,设备在设备树中有对应的描述,在bootloader阶段会传递设备树内容给内核,匹配到对应的设备后调用驱动的probe函数

设备树中每个表示一个设备的节点都需要一个 compatible 属性。compatible 属性是操作系统用来决定使用哪个设备驱动来绑定到一个设备上的关键因素

 

9.典型的外设、核心和主机驱动图

10.设备树英文文档链接点击打开链接

11.驱动加载顺序

优先级定义在include/linux/init.h,其中对于同一级别的 __initcall的次序 主要由MakeFile中.o文件的链接次序决定,具体看Kernel下的主Makefile ---- Build vmlinux以及kernel/driver 下的obj-y

12.linux为什么要挂载到/mnt或其它目录,直接访问/dev不行吗?

/dev是不加文件系统的,只能通过read/write命令对他进行读写。但是你看不到的。想要看到他里面有那个文件或者文件夹,只有加载了文件系统,才可以。所以你用mount命令的时候要加-t指定文件系统,例如:mount -t vfat /dev/hda1 /mnt,挂载/dev/hda1设备到/mnt,文件系统是vfat。

13.config的生成

通过menuconfig生成。每个开发平台都有一个可供参考的配置文件,如arch/arm/configs/xxxxxx_defconfig目录下的文件,都是硬件厂商提供的,针对硬件平台的配置文件。当我们执行make menuconfig就会读取源码目录下所有Kconfig内容,并生成界面中的选项菜单


14. 一个模块由多个源文件编译生成

kernel\msm-3.18\Documentation\kbuild\makefiles.txt

If a kernel module is built from several source files, you specify
that you want to build a module in the same way as above; however,
kbuild needs to know which object files you want to build your
module from, so you have to tell it by setting a $(<module_name>-y)
variable.
Example:
#drivers/isdn/i4l/Makefile
obj-$(CONFIG_ISDN_I4L) += isdn.o
isdn-y := isdn_net_lib.o isdn_v110.o isdn_common.o

isdn就是模块名字,isdn.o由isdn_net_lib.o isdn_v110.o isdn_common.o组成


15.debugfs对应/sys/kernel/debug目录


16.一种方法可以快速知道device对应的驱动


17.如何查看gpio 使用状态,以及被那些模块request

cat /sys/kernel/debug/gpio


18.objdump命令是用查看目标文件或者可执行的目标文件的构成的gcc工具


19. tree命令以树状图列出文件目录结构,


20 代码中I2C从设备采用7位的地址,最后一位读写由i2c_msg结构体的flags来决定。

struct i2c_msg {
__u16 addr;/* slave address*/
__u16 flags;
#define I2C_M_TEN0x0010/* this is a ten bit chip address */
#define I2C_M_RD0x0001/* read data, from slave to master */
#define I2C_M_STOP0x8000/* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_NOSTART0x4000/* if I2C_FUNC_NOSTART */
#define I2C_M_REV_DIR_ADDR0x2000/* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_IGNORE_NAK0x1000/* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_NO_RD_ACK0x0800/* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_RECV_LEN0x0400/* length will be first received byte */
__u16 len;/* msg length*/
__u8 *buf;/* pointer to msg data*/
};

0 0
原创粉丝点击