Home >System Tutorial >LINUX >How to set up the PC compilation kernel and settings: Setting up compilation

How to set up the PC compilation kernel and settings: Setting up compilation

WBOY
WBOYforward
2024-03-13 14:52:02795browse

How to set up the PC compilation kernel and settings: Setting up compilation

Thisisfreesoftware;seethesourceforcopyingconditions.ThereisNO

warranty;notevenforMERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.

Note: The arm tool chain can be downloaded from here: reply "ARM" to view it.

2. Set the compilation target

Before configuring or compiling the kernel, you must first determine the target CPU architecture and which tool chains to use during compilation. This is the most basic information that must be determined first.

If you are compiling the kernel for the PC you are currently using, there is no need to set it.

Otherwise, embedded linux training must be set clearly.

Here we take arm as an example to illustrate.

There are two setting methods ():

a)Change Makefile

Open the Makefile in the root directory of the kernel source code, change the following two Makefile variables and save them.

ARCH:=arm

CROSS_COMPILE:=arm-linux-

Note that the setting of cross_compile here assumes that the gcc program name of the cross tool chain used is arm-linux-gcc. If the actual gcc name used is some-thing-else-gcc, then just fill in some-thing-else-. Anyway, the last three letters of gcc should be omitted from the name.

b) Each time you execute the make command, this information is passed in through the command line parameters.

This seems to be the value of the variable specified through the command line argument of the make tool.

for example

When configuring the kernel, use

makeARCH=armCROSS_COMPILE=arm-linux-menuconfig

Use

when compiling the kernel

makeARCH=armCROSS_COMPILE=arm-linux-

Note that in fact, for compiling the PC kernel, even if the user does not set it explicitly, it does not mean that these two items are not configured. Because if the user does not set these two items, the Makefile at the top of the kernel source code (located in the source code root directory) will generate the values ​​​​of these two variables through the following method.

SUBARCH:=$(shelluname-m|sed-es/i.86/i386/-es/sun4u/sparc64/

-es/arm.*/arm/-es/sa110/arm/

-es/s390x/s390/-es/parisc64/parisc/

-es/ppc.*/powerpc/-es/mips.*/mips/

-es/sh[234].*/sh/)

ARCH?=$(SUBARCH)

CROSS_COMPILE?=

Through the previous code, ARCH has become the arch of the PC compiler, that is, SUBARCH. For this reason, if the output of uname-m on the PC is ix86, the value of ARCH becomes i386.

The value of CROSS_COMPILE, if not configured, is an empty string. In this way, the name of the tool chain program used no longer has a prefix like arm-linux-, which is equivalent to using gcc on the PC.

Finally, let me say a few more words. The value of ARCH needs to be further generalized. Because there is no i386 directory in the arch directory of the kernel source code, nor is there a directory such as sparc64.

Therefore, a SRCARCH variable is constructed in the makefile on the top floor, and its value is generated through the following code. In this way, the SRCARCH variable finally matches a certain architecture name in the kernel source code arch directory.

SRCARCH:=$(ARCH)

ifeq($(ARCH),i386)

SRCARCH:=x86

endif

ifeq($(ARCH),x86_64)

SRCARCH:=x86

endif

ifeq($(ARCH),sparc64)

SRCARCH:=sparc

endif

ifeq($(ARCH),sh64)

SRCARCH:=sh

endif

3. Configure the kernel

The kernel has so many functions. What parts do we need, how each part is compiled (into the kernel or into a module), and what are the working parameters of each part? These can all be configured. To this end, before starting compilation, we need to create a configuration list, place it in the kernel source root directory, name it a .config file, and then compile the kernel we need according to this .config file.

However, there are too many configuration items in the kernel. It is too troublesome to configure Linux to set environment variables one by one. Moreover, the set of configuration items that can be configured for different CPU architecturesdetailed explanation of arm interrupt implementation in the arm linux kernel are different. For example, the configuration item whether a certain functional feature of a certain CPU should be supported arm Detailed explanation of arm interrupt implementation in the linux kernel is a configuration item related to the CPU architecture. Therefore, the kernel provides a simple configuration method.

Taking arm as an example, the specific method is as follows.

a) Based on our target CPU architecture, from the kernel source code arch/arm/configs directory, find a configuration file (such as s3c2410_defconfig) that is closest to the target system, copy it to the kernel source code root directory, and name it .config .

Note that if you are compiling the kernel for the current PC, it is best to copy the following files to the kernel source root directory as the initial configuration file. This file is the configuration file used when compiling the kernel currently running on the PC.

/lib/modules/`uname-r`/build/.config

I would like to say a few words here by the way. There are so many functions to choose from in the PC kernel configuration file. You won’t know if you don’t compile it, you will know it only if you compile it. The purpose of Linux publishers in doing this may be to make the Linux they distribute meet the various needs of users.

b) Execute makemenuconfig to make some necessary changes to this configuration, select save when exiting, and the new configuration will be updated to the .config file.

Note

The above is the detailed content of How to set up the PC compilation kernel and settings: Setting up compilation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:itcool.net. If there is any infringement, please contact admin@php.cn delete