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

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

在我的主桌面上编译内核只需要15分钟,但它是64位机器。 我可以交叉编译从更好的机器生成32位内核包吗?

虽然内核可以交叉编译,但最简单的方法是创建一个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没有广泛的了解,但你可以调整它们。

编辑:我想在这里添加一个来自stackoverflow的问题 ,在其中告诉它设置cflags:

 export CFLAGS=-m32 

Torvalds的github帐户中的linux存储库中,我发现您可能会发现有用的主要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