系统信息:
root@zaidi:/home/uzair# uname -a
Linux zaidi 3.11.0-26-generic #45~precise1-Ubuntu SMP Tue Jul 15 04:04:35 UTC 2014 i686 i686 i386 GNU/Linux
我正在尝试编写一个简单的设备驱动程序。为此,我需要下载我正在运行的内核的源代码(对吗?)
我发现了以下两种方法:
apt-get install linux-source-$(uname -r)
apt-get source linux-image-$(uname -r)
这两个命令有什么区别?构建驱动程序实际上需要哪一个。我有一个这样的 make 文件:
# Makefile – makefile of our first driver
# if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq (${KERNELRELEASE},)
obj-m := ofd.o
# Otherwise we were called directly from the command line.
# Invoke the kernel build system.
else
KERNEL_SOURCE := /usr/src/linux
PWD := $(shell pwd)
default:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
clean:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
endif
我想要源代码/usr/src/linux
答案1
apt-get install
安装过程与安装方式的区别apt-get source
:
sudo apt-get install <package>
/var/cache/apt/archives
从存储库安装包及其依赖项,并在扩展中找到缓存的文件.deb
。sudo apt-get source <package>
将下载当前目录中的源文件。
现在看看如何从下载的源文件构建和安装包(来自存储库):
- 首先通过命令安装 build-dependencies:
sudo apt-get build-dep <package>
- 然后通过命令下载源包:
sudo apt-get source <package>
- 然后导航到包含源的目录
cd
并使用它dpkg-buildpackage -uc -us -b
来获取二进制文件,dpkg-buildpackage -uc -us -S
而无需使用 sudo 即可获得源包。 - 它获取/构建
.deb
可以通过以下方式安装的文件dpkg -i <file-name>.deb
但如果<package>
可以直接从存储库安装,则建议通过以下命令安装软件包
sudo apt-get install <package>
要从源代码编译包,请访问:社区帮助
答案2
您只需要适当的linux-headers
包:
apt-cache show linux-source-3.13.0
Package: linux-source-3.13.0
...
Description-en: Linux kernel source for version 3.13.0 with Ubuntu patches
This package provides the source code for the Linux kernel version
3.13.0.
.
This package is mainly meant for other packages to use, in order to build
custom flavours.
.
If you wish to use this package to create a custom Linux kernel, then it
is suggested that you investigate the package kernel-package, which has
been designed to ease the task of creating kernel image packages.
.
If you are simply trying to build third-party modules for your kernel,
you do not want this package. Install the appropriate linux-headers
package instead.
做:
sudo apt-get install linux-headers-$(uname -r)