在64位机器上编译32位内核

在64位机器上编译32位内核

我正在尝试为 32 位单核 Intel Atom 机器编译内核。不用说,编译花费了大量的时间。它已经进行了 2 个小时,但驱动程序模块仍然只完成了一半。

在我的主台式机上编译内核仅需 15 分钟,但它是一台 64 位机器。我可以从更好的机器上进行交叉编译以生成 32 位内核包吗?

答案1

虽然内核可以交叉编译,但最简单的方法是创建一个 32 位(i386)chroot 并在其中构建它。

安装ubuntu-dev-tools

$ sudo apt-get install ubuntu-dev-tools

创建 i386 chroot:

$ mk-sbuild --arch=i386 precise

(您可能需要运行两次。第一次,它会安装schroot等并进行设置mk-sbuild

然后进入chroot:

$ schroot -c precise-i386

并像平常一样构建内核。

答案2

据我所知,在 gcc 中,您可以设置-m32标志以让其将 Linux 源代码编译为 32 位可执行文件。我对 Makefile 了解不多,但您可以对其进行调整。

编辑: 我想补充来自 stackoverflow 的一个问题这里,它被告知要设置 cflags:

export CFLAGS=-m32

从 Linux 存储库中托瓦兹' github 帐户,我在主 makefile 中找到了以下部分,您可能会觉得有用,因为它告诉您可以通过设置环境变量来设置目标体系结构。阅读评论,目前,这些行来自这个文件,在行之间174-196

# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
# When performing cross compilation for other architectures ARCH shall be set
# to the target architecture. (See arch/* for the possibilities).
# ARCH can be set during invocation of make:
# make ARCH=ia64
# Another way is to have ARCH set in the environment.
# The default ARCH is the host where make is executed.

# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# A third alternative is to store a setting in .config so that plain
# "make" in the configured kernel build directory always uses that.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH        ?= $(SUBARCH)
CROSS_COMPILE   ?= $(CONFIG_CROSS_COMPILE:"%"=%)

# ...
# There are more architecture related stuff beyond this line

相关内容