当前位置:网站首页>Kconfig Kbuild
Kconfig Kbuild
2022-07-06 12:01:00 【csdndulala】
In code engineering, we often see some projects called Kconfig Kbuild The file of
The purpose of this document is : Compile oriented script , Shield hardware differences .Kconfig It's not a special script , It's a way to solve the problem , He can do it in any way :python、shell+makfefile(linux kernal、Busybox).
Introduction
For embedded or OS for , Faced with hundreds of hardware types , for instance .
If there are two I2C The hardware needs to be adapted , Common practice :Method 1 ( It is not recommended to abuse this method ,1 The same file will be modified when adding a board , Risk of incorrect modification 2 Not conducive to reading )
One .c Distinguish by macro Then compile the script / Compile macros to distinguish
#ifdef I2C_A_HARDWARE
void i2c_write()
#endif#ifdef I2C_B_HARDWARE
void i2c_write()
#endifMethod 2
Distinguish by file i2c_ahardware.c i2cb_hardware.c Finally, it is also distinguished by compiling scripts
For the second method , When adding a hardware , The built script needs to be modified :
if I2C_A_ chip
i2c_ahardware.c Participate in building
else if I2C_B_ chip
i2cbhardware.c Participate in building
else if I2C_X_ chip
i2cx_hardware.c Participate in building
…
else if chip xxx
…
…
…
endif
You can imagine when there are hundreds of chips ,makefile What will it be like , Let alone if else Nested scenes 、 File path modification 、 File name modification 、 Code integration , The modification of the compiled script caused by , really ....
Think about it
linux kernal How a set of code fits thousands of boards
U-boot How to support thousands of boardsKconfig How it works
Kconfig Working steps of
1) Read... In the current directory .config file ( If not, follow Kconfig File default configuration )
2) according to .config The content of , Display the corresponding interface
3) The programmer selects the components of the board to be built through the interface
4) sign out Kconfig Interface , Two files will be saved :.config、autoconf.hKconfig file :

Kconfig Interface after file operation : Users choose (* For choice )
Generated .config file ( This file can be used to initialize Kconfig Interface , It can also be saved as configuration files of different hardware . Use different configuration files to replace complex if else)
Kbuild file : Include and exclude the selected files

When choosing I2C_A, The final obj-y = i2c_a_hardware.o This is the input of the compilation script .autoconf.h ( according to Kconfig The selection result of , It can be used as a method 1 Macro definition file )

Kconfig Of python Implementation code can refer to :
github project ulfalizer/Kconfiglib
The use of this library :
https://blog.csdn.net/u010018991/article/details/81867316summary
- Kconfig It is equivalent to layering the functions of the compiled script , Shielding all kinds of boards 、 Chip differences
- The original if else Branch still " There is ", It is only branched by multiple hardware boards .config Profile substitution
- Kconfig It can also be applied to pure software scenarios , It can support cutting and customization of pure software
There are two ways to use in your own project Kconfig
Linux Kernel Used a bunch of scripts , stay scripts Under the table of contents , Belong to GPL agreement .
Kconfiglib Is another option , It USES Python Script to achieve Kconfig, This library License More friendly to business software .
边栏推荐
- Linux Yum install MySQL
- Kaggle competition two Sigma connect: rental listing inquiries
- 冒泡排序【C语言】
- Stage 4 MySQL database
- XML file explanation: what is XML, XML configuration file, XML data file, XML file parsing tutorial
- Apprentissage automatique - - régression linéaire (sklearn)
- ESP8266通过arduino IED连接巴法云(TCP创客云)
- Mall project -- day09 -- order module
- Funny cartoon: Programmer's logic
- Analysis of charging architecture of glory magic 3pro
猜你喜欢

Characteristics, task status and startup of UCOS III

Basic use of pytest

FTP文件上传文件实现,定时扫描文件夹上传指定格式文件文件到服务器,C语言实现FTP文件上传详解及代码案例实现

电商数据分析--用户行为分析

4. Install and deploy spark (spark on Yan mode)

Kaggle competition two Sigma connect: rental listing inquiries

RT-Thread 线程的时间片轮询调度

ARM PC=PC+8 最便于理解的阐述
![[template] KMP string matching](/img/f9/cd8b6f8e2b0335c2ec0a76fc500c9b.jpg)
[template] KMP string matching

Come and walk into the JVM
随机推荐
Word排版(小計)
列表的使用
Detailed explanation of nodejs
Some concepts often asked in database interview
ARM PC=PC+8 最便于理解的阐述
Funny cartoon: Programmer's logic
ESP8266通过Arduino IDE连接Onenet云平台(MQTT)
MongoDB
ESP学习问题记录
MP3mini播放模块arduino<DFRobotDFPlayerMini.h>函数详解
高通&MTK&麒麟 手機平臺USB3.0方案對比
SQL time injection
C language callback function [C language]
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries
MySQL START SLAVE Syntax
Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
ToggleButton实现一个开关灯的效果
Reno7 60W super flash charging architecture
FTP文件上传文件实现,定时扫描文件夹上传指定格式文件文件到服务器,C语言实现FTP文件上传详解及代码案例实现
[template] KMP string matching