问题描述
我正在尝试为32位single-core Intel Atom计算机编译内核。不用说,编译会花费大量时间。它已经进行了2个小时,但仍仅在驱动程序模块中途完成。
在我的主桌面上编译内核仅需15分钟,但这是一台64位计算机。我可以交叉编译以从更好的计算机生成32位内核软件包吗?
最佳办法
虽然内核可以是cross-compiled,但最简单的方法是创建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
像通常那样构建内核。
次佳办法
Afaik,在gcc中,您可以设置-m32
标志以使其将linux源编译为32位可执行文件。我对Makefile没有广泛的了解,但是您可以对其进行调整。
编辑:我想在这里添加a question from stackoverflow,它被告知设置cflags:
export CFLAGS=-m32
在Torvalds‘github帐户中的linux存储库中,我发现主makefile的以下部分可能对您有用,因为它告诉您可以通过设置环境变量来设置目标体系结构。阅读注释,当前,这些行来自174-196行之间的this file:
# 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