linux开发摘要
1.linux內核文檔鏈接點擊打開鏈接
2.配置文件
在out\target\product\project\obj\KERNEL_OBJ\.config中可以看到
?
但這個文件是自動生成的,應該主要是由\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_TEN 0x0010 /* this is a ten bit chip address */
#define I2C_M_RD 0x0001 /* read data, from slave to master */
#define I2C_M_STOP 0x8000 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_NOSTART 0x4000 /* if I2C_FUNC_NOSTART */
#define I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
__u16 len; /* msg length */
__u8 *buf; /* pointer to msg data */
};
21.監測系統可用內從,用cat /proc/meminfo下的MemAvailabble這項,而不是MemFree來判斷,這些項的意義,可參考kernel\msm-3.18\Documentation\filesystems\proc.txt文檔介紹
總結
- 上一篇: android中SELINUX规则分析和
- 下一篇: 什么是menuconfig和menuco