交叉编译时经常会用到这些头文件。
下载合适版本的linux
地址:
mirrors.aliyun.com/linux-kernel/
mirrors.edge.kernel.org/pub/linux/kernel/
解压:
biren@ubuntu:~/crossbuild/src$ tar jxf linux-3.9.tar.bz2
配置内核:
biren@ubuntu:~/crossbuild/src/linux-3.9$ make ARCH=arm menuconfig
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/lxdialog/checklist.o
HOSTCC scripts/kconfig/lxdialog/inputbox.o
HOSTCC scripts/kconfig/lxdialog/menubox.o
HOSTCC scripts/kconfig/lxdialog/textbox.o
。。。
检查源文件中的头文件:
命令:make ARCH=arm headers_check
ARCH用于指定目标架构
biren@ubuntu:~/crossbuild/src$ cd linux-3.9/
biren@ubuntu:~/crossbuild/src/linux-3.9$ make mrproper
biren@ubuntu:~/crossbuild/src/linux-3.9$ make ARCH=arm headers_check
CHK include/generated/uapi/linux/version.h
UPD include/generated/uapi/linux/version.h 此时会生成version.h文件
HOSTCC scripts/basic/fixdep
WRAP arch/arm/include/generated/asm/auxvec.h
WRAP arch/arm/include/generated/asm/bitsperlong.h
WRAP arch/arm/include/generated/asm/cputime.h
。。。
WRAP arch/arm/include/generated/asm/types.h
WRAP arch/arm/include/generated/asm/unaligned.h
HOSTCC scripts/unifdef
INSTALL include/asm-generic (35 files)
。。。
INSTALL include/uapi (0 file)
INSTALL include/asm (34 files)
CHECK include/asm-generic (35 files)
。。。
CHECK include/linux (382 files)
/home/biren/crossbuild/src/linux-3.9/usr/include/linux/kexec.h:49: userspace cannot reference function or variable defined in the kernel
/home/biren/crossbuild/src/linux-3.9/usr/include/linux/soundcard.h:1054: userspace cannot reference function or variable defined in the kernel
。。。
CHECK include/uapi (0 files)
CHECK include/asm (34 files)
生成头文件:
make ARCH=arm INSTALL_HDR_PATH=./jwj/ headers_install
INSTALL_HDR_PATH=./jwj用于指定新的头文件存放目录
biren@ubuntu:~/crossbuild/src/linux-3.9$ make ARCH=arm INSTALL_HDR_PATH=./jwj/ headers_install
CHK include/generated/uapi/linux/version.h
INSTALL jwj//include/asm-generic/ (35 files)
INSTALL jwj//include/drm/ (15 files)
INSTALL jwj//include/linux/byteorder/ (2 files)
INSTALL jwj//include/linux/caif/ (2 files)
INSTALL jwj//include/linux/can/ (5 files)
INSTALL jwj//include/linux/dvb/ (8 files)
INSTALL jwj//include/linux/hdlc/ (1 file)
INSTALL jwj//include/linux/hsi/ (1 file)
INSTALL jwj//include/linux/isdn/ (1 file)
INSTALL jwj//include/linux/mmc/ (1 file)
INSTALL jwj//include/linux/netfilter/ipset/ (4 files)
INSTALL jwj//include/linux/netfilter/ (78 files)
INSTALL jwj//include/linux/netfilter_arp/ (2 files)
INSTALL jwj//include/linux/netfilter_bridge/ (18 files)
INSTALL jwj//include/linux/netfilter_ipv4/ (10 files)
INSTALL jwj//include/linux/netfilter_ipv6/ (12 files)
INSTALL jwj//include/linux/nfsd/ (5 files)
INSTALL jwj//include/linux/raid/ (2 files)
INSTALL jwj//include/linux/spi/ (1 file)
INSTALL jwj//include/linux/sunrpc/ (1 file)
INSTALL jwj//include/linux/tc_act/ (7 files)
INSTALL jwj//include/linux/tc_ematch/ (4 files)
INSTALL jwj//include/linux/usb/ (10 files)
INSTALL jwj//include/linux/wimax/ (1 file)
INSTALL jwj//include/linux/ (382 files)
INSTALL jwj//include/mtd/ (5 files)
INSTALL jwj//include/rdma/ (6 files)
INSTALL jwj//include/scsi/fc/ (4 files)
INSTALL jwj//include/scsi/ (3 files)
INSTALL jwj//include/sound/ (10 files)
INSTALL jwj//include/video/ (3 files)
INSTALL jwj//include/xen/ (2 files)
INSTALL jwj//include/uapi/ (0 file)
INSTALL jwj//include/asm/ (34 files)
查看结果:
biren@ubuntu:~/crossbuild/src/linux-3.9/jwj/include$ ll
total 60
drwxrwxr-x 13 biren biren 4096 Apr 29 16:11 ./
drwxrwxr-x 3 biren biren 4096 Apr 29 16:11 ../
drwxrwxr-x 2 biren biren 4096 Apr 29 16:11 asm/
drwxrwxr-x 2 biren biren 4096 Apr 29 16:11 asm-generic/
drwxrwxr-x 2 biren biren 4096 Apr 29 16:11 drm/
drwxrwxr-x 23 biren biren 12288 Apr 29 16:11 linux/
drwxrwxr-x 2 biren biren 4096 Apr 29 16:11 mtd/
drwxrwxr-x 2 biren biren 4096 Apr 29 16:11 rdma/
drwxrwxr-x 3 biren biren 4096 Apr 29 16:11 scsi/
drwxrwxr-x 2 biren biren 4096 Apr 29 16:11 sound/
drwxrwxr-x 2 biren biren 4096 Apr 29 16:11 uapi/
drwxrwxr-x 2 biren biren 4096 Apr 29 16:11 video/
drwxrwxr-x 2 biren biren 4096 Apr 29 16:11 xen/
biren@ubuntu:~/crossbuild/src/linux-3.9$ tree -d ./jwj
./jwj
└── include
├── asm 交叉编译工具用到
├── asm-generic 交叉编译工具用到
├── drm
├── linux 交叉编译工具用到
│ ├── byteorder
│ ├── caif
│ ├── can
│ ├── dvb
│ ├── hdlc
│ ├── hsi
│ ├── isdn
│ ├── mmc
│ ├── netfilter
│ │ └── ipset
│ ├── netfilter_arp
│ ├── netfilter_bridge
│ ├── netfilter_ipv4
│ ├── netfilter_ipv6
│ ├── nfsd
│ ├── raid
│ ├── spi
│ ├── sunrpc
│ ├── tc_act
│ ├── tc_ematch
│ ├── usb
│ └── wimax
├── mtd
├── rdma
├── scsi
│ └── fc
├── sound
├── uapi 交叉编译工具用到
├── video
└── xen
35 directories
其中重要的几个是:asm, asm-generic, linux , uapi
uapi是从各模块抽取出来的用于启动内核相关的。
====================================
低版本的内核头文件获取
不需要以上步骤,只需从源码文件中复制出来即可。
如linux-2.6.10版本
存放在linux-2.6.10/include里
biren@ubuntu:~/crossbuild/src/linux-2.6.10/include$ ls
acpi asm-generic asm-m68k asm-ppc64 asm-sparc64 math-emu rxrpc
asm-alpha asm-h8300 asm-m68knommu asm-s390 asm-um media scsi
asm-arm asm-i386 asm-mips asm-sh asm-v850 mtd sound
asm-arm26 asm-ia64 asm-parisc asm-sh64 asm-x86_64 net video
asm-cris asm-m32r asm-ppc asm-sparc linux pcmcia
其中:asm-xxx对应asm, 选择适合的将它改名为asm即可,低版本中没有uapi目录
高版本中的asm存放在arch/arm/include下面。
====================================
如果要在系统中安装头文件可用如下命令:
apt-get install linux-headers
sudo apt-get install linux-headers
[sudo] password for biren:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package linux-headers is a virtual package provided by:
linux-headers-5.4.0-1019-ibm 5.4.0-1019.21~18.04.1
linux-headers-5.4.0-1018-ibm 5.4.0-1018.20~18.04.1
linux-headers-5.4.0-1017-ibm 5.4.0-1017.19~18.04.1
linux-headers-5.4.0-1015-ibm 5.4.0-1015.16~18.04.1
linux-headers-5.4.0-1014-ibm 5.4.0-1014.15~18.04.1
linux-headers-5.4.0-1012-ibm 5.4.0-1012.13~18.04.1
linux-headers-5.4.0-1010-ibm 5.4.0-1010.11~18.04.2
linux-headers-5.3.0-1045-gke 5.3.0-1045.48
linux-headers-5.3.0-1044-gke 5.3.0-1044.47
。。。。。。
其它说明 :
include/linux目录里必须有version.h,如果没有可以手动添加
方法如下:
(198912是版本0x03/0x09/0x00组合而成的0x030900的十进制)
#define UTS_RELEASE "3.9.0"
#define LINUX_VERSION_CODE 198912
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
获取本源码内核所支持的架构:
biren@ubuntu:~/crossbuild/src/linux-2.6.10$ ls -d include/asm-* | sed 's/.*-//'
alpha
arm
arm26
cris
generic
h8300
i386
ia64
m32r
m68k
m68knommu
mips
parisc
ppc
ppc64
s390
sh
sh64
sparc
sparc64
um
v850
x86_64
或查看linux-2.6.10/arch目录