


Tip1: Cross-compilation options
Compile Linux, usually you only need to run make menuconfig
Configure the modules to be compiled and run make
. Linux defaults to local compilation, which means compiling the kernel used by the local machine.
In embedded development, cross compilation is often required. To do cross compilation, you need to add macro definitions after the make
command. For example, cross compile to arm target:
make ARCH=arm CROSS_COMPILE=arm-linux-
ARCH=arm
: Indicates that the target CPU is an ARM architecture
CROSS_COMPILE=arm-linux-
:
indicates the cross used in the compilation process The compilation chain is arm-linux
. Of course, you can also directly modify the ARCH
and CROSS_COMPILE
macro definitions in Makefile
. This achieves the same effect. But it is not recommended to modify the Makefile directly.
Tip2:源码与目标文件分离
Linux内核编译过程会产生很多的文件,包括目标文件、临时文件等等,默认情况下,编译生成的文件会存放在内核源码目录。
当你使用git status
显示自己对内核代码的修改时也会把这些临时文件显示出来,而且提交还必须一个文件一个文件地指定,相当麻烦。
因此我们可以在父目录创建一个存放编译文件的目录,如build-kernel
,然后再make
命令后面加上宏定义:
make O=../build-kernel
这样在编译Linux内核时,所有编译产生的文件,都会放在build-kernel目录,如果build-kernel目录不存在,也会自动创建。这样可以实现Linux内核源码与编译产生的文件分离。
Tip3:获得编译命令及选项
编译linux时,默认不会显示编译的命令,如果你要获得编译命令及其选项,可以在make命令后面加上宏定义:
make V=1
如果希望编译系统告诉你为何某个目标文件需要重新编译,则:
make V=2
内核编译脚本
最后分享我常用的内核编译脚本mk.sh
,给大家参考:
#!/bin/sh export ARCH=arm export PATH=~/toolchain/arm_glibc/host/bin:$PATH export CROSS_COMPILE=arm-linux-gnu- #make O=../bd defconfig make O=../bd menuconfig -j32 make O=../bd dtbs #反汇编 $(CROSS_COMPILE)objdump -d ../bd/vmlinux > ../image/vmlinux_dump.txt #生成uImage ../ubd/tools/mkimage -A arm -T kernel -C none -O linux -a 0x80200000 -e 0x80200000 -n "debug kernel" -d ../bd/Image ../image/uImage
其中,make O=../bd defconfig
只有在第一次编译内核的才使用,第一次编译过后,将这句注释,后面都通过make menuconfig
修改内核配置。
objdump
反汇编对大多数人来说可能用不上,一般在内核移植、启动分析时比较有用,但由于工作需要,我通常都会把反汇编加上。
The above is the detailed content of A few tips you must know when compiling the Linux kernel. For more information, please follow other related articles on the PHP Chinese website!

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。

在linux中,mnt是存储挂载设备的目录;mnt是mount的缩写,是挂载的意思,mount命令用于挂载linux系统外的文件,因此mnt目录可以理解为mount命令挂载光驱、USB等设备后,会在mut中找到相应的设备目录。

手机远程linux工具有:1、JuiceSSH,是一款功能强大的安卓SSH客户端应用,可直接对linux服务进行管理;2、Termius,可以利用手机来连接Linux服务器;3、Termux,一个强大的远程终端工具;4、向日葵远程控制等等。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
