Purpose of Trimming
Customers sometimes have certain requirements for the boot time after power-on, so it is necessary to tailor the kernel to optimize the boot time and reduce it. Low system power consumption.
Brief Introduction to Makefiles, Kconfig and .config Files
- Makefile: A file in text form that compiles the source files
- Kconfig: A file in text for the kernel's configuration menu.
- .config: The configuration on which the kernel is compiled
- Kconfig and Makefile files are usually present in the directory structure of the Linux kernel.
- Distributed at all levels of the catalogue
- Kconfig constitutes a distributed database of kernel configurations, with each Kconfig describing the kernel associated with the source files of the directory to which it belongs.
- Configuration menu. Read out the configuration menu from Kconfig when the kernel graphically configures make menuconfig, and save it to.config after the user finishes the configuration.
- When the kernel is compiled, the main Makefile calls this.config to know how the user has configured the kernel.
Introduction to Makefile and Kconfig Syntax
● Makefile
The Makefile subdirectory is contained by the top-level Makefile. It is used to define what is compiled as a module and what is conditionally compiled.
(1) Direct compilation obj-y +=xxx.o
It means that xxx.o is compiled from xxx.c or xxx.s and compiled directly into the kernel.
(2) Conditional compilation obj-$(CONFIG_HELLO) +=xxx.o
The CONFIG_XXX of the .config file determines whether a file is compiled into the kernel or not.
(3) Module compilation obj-m +=xxx.o
It means that xxx is compiled as a module, i.e. it is compiled when make modules is executed.
● Kconfig
Each config menu item has a type definition. bool: boolean type, tristate: three states (built-in, module, remove), string: a sequence of characters, hex: hexadecimal, integer: a whole number
Function: determine the menu item displayed when make menuconfig.
1) NEW _ LEDS: The name of the configuration option. The prefix "CONFIG _" "is omitted.
2) tristate: Indicates whether the item is programmed into the kernel or into a module. The display as < >, if selected to compile as a kernel module, it will generate a configuration CONFIG_HELLO_MODULE=m in .config. Choosing Y will directly compile into the kernel, generating a configuration CONFIG_HELLO_MODULE=y in .config.
3) bool: This type can only be checked or unchecked. It is displayed as [ ] when making menuconfig, that is, it cannot be configured as a module.
4) dependon: This option depends on another option, only when the dependon is checked, the prompt message of the current configuration item will appear to set the current configuration item.
5) select: Reverse dependency, when this option is checked, the item defined after select is also checked.
6) help: help information.
tristate and bool followed by strings are the configuration item names displayed in make menuconfig.
Definitions in Kconfig like "menuconfig NEW_LEDS" or "menu "Video support for sunxi"" are typically top-level directories of a directory, where in menuconfig you can directly trim the corresponding driver by searching for that configuration item.
Catalogue Hierarchy Iteration :
In Kconfig, there are statements like "source "drivers/usb/Kconfig"" used to include (or nest) new Kconfig files, allowing each directory to manage its own configuration content without having to write all those configurations in the same file, making it easier for modification and management.
Partially Driven Tailoring
1. Tailoring Ideas
Taking the GPADC function as an example, the location of the driver in the source code kernel is:drivers/input/sensor/sunxi_gpadc.c,
So we can go to the Kconfig file in that path, and directly search for "menu” in the Kconfig file, which generally corresponds to the top-level directory of that driver.
We can see that the configuration option is named INPUT_SENSOR, corresponding to the name "Sensors" in menuconfig. Afterwards, we can directly search for this configuration option in menuconfig. Execute make menuconfig at the kernel path
ARCH=arm64 Enter the graphical configuration interface:
On this screen, type /, then INPUT_SENSOR, and press Enter.
As shown in the figure, this item is configured under the Device Drivers ---> Input device support path, and the Generic
The "input layer (needed for keyboard, mouse, ...)" configuration option is set to "y" (yes).
Cancel the configuration for Sensors, then save and exit as a .config file. Afterwards, go back to the OKT507-linux-sdk path, compile the kernel separately, and then package the image.
forlinx@ubuntu:~/work/OKT507-linux-sdk$ ./build.sh kernel
forlinx@ubuntu:~/work/OKT507-linux-sdk$ ./build.sh pack
2. Partial Drive Path
Device | Location of the driver in the source kernel | Device Name | Path in Menuconfig |
---|---|---|---|
Wifi | Wifi | wlan0 | Device Drivers ---> Remove:Network device support |
Network card | drivers/net/ethernet/allwinner/ | /sys/class/net/eth* | |
Hdmi | drivers/video/fbdev/sunxi/disp2/hdmi2/ | /dev/fb1 | Device Drivers ---> Graphics support ---> Frame buffer Devices ---> Video support for sunxi --->Remove: HDMI2.0 Driver Support(sunxi-disp2) (not yet fully modified) |
Usb-U disk | drivers/usb/storage/ | /dev/sdx | Device Drivers ---> USB support ---> Remove:USB Mass Storage support |
USB-4G | drivers/usb/serial/ | /dev/ttyUSB* | Device Drivers ---> USB support --->Remove:USB Serial Converter support |
Usb-camera | drivers/media/usb/uvc/uvc_video.c | Device Drivers ---> Multimedia support ---> Media USB Adapters --->Remove:USB Video Class (UVC) | |
Usb-camera | drivers/media/usb/uvc/uvc_video.c | Device Drivers ---> Multimedia support ---> Media USB Adapters --->Remove:USB Video Class (UVC) | |
Watchdog | drivers/watchdog/sunxi_wdt.c | /dev/watchdog | Device Drivers ---> Remove:Watchdog Timer Support |
Bluetooth | drivers/bluetooth/ | Networking support ---> Bluetooth subsystem support ---> Bluetooth device drivers --->Uncheck all (remember to record the original configuration) | |
Audio | sound/soc/sunxi | /dev/snd/ | Device Drivers ---> Sound card support ---> Advanced Linux Sound Architecture ---> ALSA for SoC audio support ---> Allwinner SoC Audio support --->Uncheck all (remember to record the original configuration) |
Pwm | drivers/pwm/pwm-sunxi.c | /sys/class/pwm/ | Device Drivers ---> Remove:Pulse-Width Modulation (PWM) Support |
OV5640_DVP | drivers/media/platform/sunxivin/modules/sensor/ov5640.c | /dev/video* | Device Drivers ---> Multimedia support ---> V4L platform devices --->Remove:sunxi video input (camera csi/mipi isp vipp)driverOpen OKT507-linux-sdk/kernel/linux-4.9/drivers/media/platform/Makefile,comment out obj-y += |
OV5640_MIPI | drivers/media/platform/sunxivin/modules/sensor/ov5640_mipi.c | ||
TP2854M | drivers/media/platform/sunxivin/modules/sensor/tp2854_mipi.c | ||
sunxi_car_reverse/ |
Device | Location of the driver in the source kernel | Path in Menuconfig | Device Name |
---|---|---|---|
GT911 touch | drivers/input/touchscreen/gt911.c | Device Drivers ---> Input device support ---> Touchscreens --->Remove:Goodix I2C touchscreen gt911、Goodix I2C touchscreen gt928、TSC2007 based touchscreens | /dev/input/event*View event with evtestCorresponding name, for example:The corresponding name of GPADC issunxi-gpadc0sunxi-gpadc1sunxi-gpadc2sunxi-gpadc3 |
GT928 touch | drivers/input/touchscreen/gt928.c | ||
TSC2007 touch | drivers/input/touchscreen/tsc2007.c | ||
LRADC | drivers/input/keyboard/sunxi-keyboard.c | drivers/input/keyboard/sunxi-keyboard.c | |
GPADC | drivers/input/sensor/sunxi_gpadc.c | Device Drivers ---> Input device supportRemove:Sensors | |
IR | drivers/media/rc/sunxi-ir-dev.c | Device Drivers ---> Multimedia support Remove:Remote controller decoders、Remote Controller devices | |
RTC | drivers/rtc/rtc-rx8010.c | Device Drivers ---> Remove:Real Time Clock | /dev/rtc0 |
The above is the trimming of one of the drivers, other functions can be trimmed following the methods mentioned earlier.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.