Linux
内核编译流程如下:
1、配置 Linux
内核。
2、编译 Linux
内核。
说明:进入 Linux
内核源码,使用 make help
参看相关配置。
1、menuconfig
它本身是一个软件,只提供图形界面配置的一些逻辑,并不负责提供内容。
2、menuconfig
是内核源码树的各目录下的 kconfig
提供的。
3、menuconfig
中所有选中配置项的相关值会保存到配置文件中(默认配置文件为 .config
)。
4、在编译内核时,Makefile
根据相关配置项选择需要编译的源码。
参考文档:Documentation/kbuild/kconfig-language.txt
。
Linux 驱动开发 六十五:《kconfig-language.txt》翻译_lqonlylove的博客-CSDN博客
#
# For a description of the syntax of this configuration file,
# see Documentation/kbuild/kconfig-language.txt.
#
mainmenu "Linux/$ARCH $KERNELVERSION Kernel Configuration"config SRCARCHstringoption env="SRCARCH"source "arch/$SRCARCH/Kconfig"
mainmenu
:标题栏;config
:定义配置项; string
:数据类型;env
:导入 Kconfig
的环境变量;source
:读取的配置文件位置。……
source "init/Kconfig" # 包含配置文件source "kernel/Kconfig.freezer"menu "System Type" # 定义配置菜单栏config MMU # 在 System Type 下定义配置项bool "MMU-based Paged Memory Management Support"default yhelpSelect if you want MMU-based virtualised addressing spacesupport by paged memory management. If unsure, say 'Y'.#
# The "ARM system type" choice list is ordered alphabetically by option
# text. Please add new entries in the option alphabetic order.
#
choiceprompt "ARM system type"default ARCH_VERSATILE if !MMUdefault ARCH_MULTIPLATFORM if MMUconfig ARCH_MULTIPLATFORMbool "Allow multiple platforms to be selected"depends on MMUselect ARCH_WANT_OPTIONAL_GPIOLIBselect ARM_HAS_SG_CHAINselect ARM_PATCH_PHYS_VIRTselect AUTO_ZRELADDRselect CLKSRC_OFselect COMMON_CLKselect GENERIC_CLOCKEVENTSselect MIGHT_HAVE_PCIselect MULTI_IRQ_HANDLERselect SPARSE_IRQselect USE_OF……config ARCH_VERSATILEbool "ARM Ltd. Versatile family"select ARCH_WANT_OPTIONAL_GPIOLIBselect ARM_AMBAselect ARM_TIMER_SP804select ARM_VICselect CLKDEV_LOOKUPselect GENERIC_CLOCKEVENTSselect HAVE_MACH_CLKDEVselect ICSTselect PLAT_VERSATILEselect PLAT_VERSATILE_CLOCKselect PLAT_VERSATILE_SCHED_CLOCKselect VERSATILE_FPGA_IRQhelpThis enables support for ARM Ltd Versatile board.……menu "Multiple platform selection"depends on ARCH_MULTIPLATFORM # Multiple platform selection 依赖 ARCH_MULTIPLATFORM 配置项comment "CPU Core family selection"……#
# This is sorted alphabetically by mach-* pathname. However, plat-*
# Kconfigs may be included either alphabetically (according to the
# plat- suffix) or along side the corresponding mach-* source.
#
source "arch/arm/mach-mvebu/Kconfig"
……menu "Bus support"
……
menu "Kernel Features"menu "CPU Power Management"source "drivers/cpufreq/Kconfig"source "drivers/cpuidle/Kconfig"endmenumenu "Floating point emulation"comment "At least one emulation must be selected"endmenu
……menu "Userspace binary formats"source "fs/Kconfig.binfmt"endmenumenu "Power management options"source "kernel/power/Kconfig"endmenusource "net/Kconfig"source "drivers/Kconfig"source "drivers/firmware/Kconfig"source "fs/Kconfig"source "arch/arm/Kconfig.debug"source "security/Kconfig"source "crypto/Kconfig"
if CRYPTO
source "arch/arm/crypto/Kconfig"
endifsource "lib/Kconfig"source "arch/arm/kvm/Kconfig"
source
:包含一个配置文件;menu
:定义一个菜单项;choice
:定义一个选项组;config
:定义一个配置项;comment
:定义一个注释;为了方便测试,在顶层 Kconfig
下添加一个 bool
配置项,配置项内容如下:
menu "onlylove test"endmenu
menu "onlylove test"config ONLYLOVE_TESTbool "onlylove test Management Support"endmenu
menu "onlylove test"config ONLYLOVE_TESTtristate "onlylove test Management Support"endmenu
menu "onlylove test"config ONLYLOVE_TESTstring "onlylove test Management Support"endmenu
menu "onlylove test"config ONLYLOVE_TESThex "onlylove test Management Support"endmenu
menu "onlylove test"config ONLYLOVE_TESTint "onlylove test Management Support"endmenu
1、添加菜单和配置项
menu "onlylove test"config ONLYLOVE_TESTtristate "onlylove test Management Support"endmenu
2、查看旧配置文件
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$ cat .config | grep ONLYLOVE_TEST
# CONFIG_ONLYLOVE_TEST is not set
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$
3、选中 onlylove test Management Support
配置项
4、查看新配置文件
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$ cat .config | grep ONLYLOVE_TEST
CONFIG_ONLYLOVE_TEST=m
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$
ICM-20608
属于 SPI
设备。onlylove@ubuntu:~/my/linux/linux-imx-4.1.15/drivers/spi$ pwd
/home/onlylove/my/linux/linux-imx-4.1.15/drivers/spi
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15/drivers/spi$ ls -l Kconfig
-rw-rw-r-- 1 onlylove onlylove 20563 May 24 2019 Kconfig
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15/drivers/spi$
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15/drivers/spi$ pwd
/home/onlylove/my/linux/linux-imx-4.1.15/drivers/spi
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15/drivers/spi$ ls -l spi-icm2068.c
ls: cannot access 'spi-icm2068.c': No such file or directory
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15/drivers/spi$ cp -f ~/my/imx6ull_drive/13_icm20608_spi/spi-icm2068.c ./
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15/drivers/spi$ ls -l spi-icm2068.c
-rw-rw-r-- 1 onlylove onlylove 12758 Nov 13 00:25 spi-icm2068.c
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15/drivers/spi$
config ONLYLOVE_ICM20608tristate "Icm20608 Device Support"helpThis supports user icm20608 device.
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$ cat .config | grep ONLYLOVE_ICM20608
CONFIG_ONLYLOVE_ICM20608=y
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$
obj-$(CONFIG_ONLYLOVE_ICM20608) += spi-icm2068.o
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$ make -j4
scripts/kconfig/conf --silentoldconfig KconfigCHK include/config/kernel.releaseCHK include/generated/uapi/linux/version.hCHK include/generated/utsrelease.h
make[1]: 'include/generated/mach-types.h' is up to date.CHK include/generated/bounds.hCHK include/generated/asm-offsets.hCALL scripts/checksyscalls.shCHK include/generated/compile.hCC drivers/spi/spi-icm2068.oLD drivers/spi/built-in.oLD drivers/built-in.oLINK vmlinuxLD vmlinux.oMODPOST vmlinux.oGEN .versionCHK include/generated/compile.hUPD include/generated/compile.hCC init/version.oLD init/built-in.oKSYM .tmp_kallsyms1.oKSYM .tmp_kallsyms2.oLD vmlinuxSORTEX vmlinuxSYSMAP System.mapOBJCOPY arch/arm/boot/ImageBuilding modules, stage 2.MODPOST 27 modulesKernel: arch/arm/boot/Image is readyLZO arch/arm/boot/compressed/piggy.lzoAS arch/arm/boot/compressed/piggy.lzo.oLD arch/arm/boot/compressed/vmlinuxOBJCOPY arch/arm/boot/zImageKernel: arch/arm/boot/zImage is ready
onlylove@ubuntu:~/my/linux/linux-imx-4.1.15$
日志 CC drivers/spi/spi-icm2068.o
表示 spi-icm2068
驱动编译成功。
以上日志可以确定 icm20608
驱动加载成功。icm20608
设备 ID
读取成功。
# ls
icm20608_app
# ls -l /dev/icm20608
crw-rw---- 1 root root 10, 62 Jan 1 00:00 /dev/icm20608
#
# ./icm20608_app /dev/icm20608
data[0] = 6 data[1] = 13 data[2] = 0 data[3] = 43 data[4] = 6 data[5] = 2067原始值:
gx = 6, gy = 13, gz = 0
ax = 43, ay = 6, az = 2067
temp = 1715
实际值:act gx = 0.37°/S, act gy = 0.79°/S, act gz = 0.00°/S
act ax = 0.02g, act ay = 0.00g, act az = 1.01g
act temp = 30.17°C
data[0] = 7 data[1] = 13 data[2] = 0 data[3] = 39 data[4] = 8 data[5] = 2063原始值:
gx = 7, gy = 13, gz = 0
ax = 39, ay = 8, az = 2063
temp = 1708
实际值:act gx = 0.43°/S, act gy = 0.79°/S, act gz = 0.00°/S
act ax = 0.02g, act ay = 0.00g, act az = 1.01g
act temp = 30.15°C
data[0] = 8 data[1] = 12 data[2] = -1 data[3] = 43 data[4] = 11 data[5] = 2067原始值:
gx = 8, gy = 12, gz = -1
ax = 43, ay = 11, az = 2067
temp = 1711
实际值:act gx = 0.49°/S, act gy = 0.73°/S, act gz = -0.06°/S
act ax = 0.02g, act ay = 0.01g, act az = 1.01g
act temp = 30.16°C
^C
#
数据读取成功。