LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (http://www.linuxquestions.org/questions/debian-26/)
-   -   Compile 32-bit kernel on a 64-bit machine (http://www.linuxquestions.org/questions/debian-26/compile-32-bit-kernel-on-a-64-bit-machine-677212/)

kushalkoolwal 10-17-2008 05:45 PM

Compile 32-bit kernel on a 64-bit machine
 
Hi,

I am running Debian Lenny on AMD X2 64-bit Dual Core processor.
Code:

Linux debian 2.6.26 #1 SMP Thu Oct 9 17:33:13 PDT 2008 x86_64 GNU/Linux
Now I am trying to compile a 2.6.26 kernel (32-bit kernel) for a 32-bit machine (target machine) on my current 64-bit machine (i.e. cross-compiling) but I am getting error when I run make-kpkg:

Code:

debian:/usr/src/linux-2.6.27# fakeroot make-kpkg --initrd --arch i386 kernel_image kernel_headers
exec debian/rules  DEBIAN_REVISION=2.6.27-10.00.Custom    KPKG_ARCH=i386  INITRD=YES  kernel_image kernel_headers
dpkg-architecture: warning: Specified GNU system type i486-linux-gnu does not match gcc system type x86_64-linux-gnu.
dpkg-architecture: warning: Specified GNU system type i486-linux-gnu does not match gcc system type x86_64-linux-gnu.
dpkg-architecture: warning: Specified GNU system type i486-linux-gnu does not match gcc system type x86_64-linux-gnu.
dpkg-architecture: warning: Specified GNU system type i486-linux-gnu does not match gcc system type x86_64-linux-gnu.

====== making target CONFIG-common [new prereqs: testdir]======

====== making target CONFIG-common [new prereqs: stamp-conf]======
This is kernel package version 11.001-0.1.
====== making stamp-arch-conf because of  ======

====== making target CONFIG-arch [new prereqs: stamp-arch-conf]======
====== making conf.vars because of Makefile .config ======

/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 25: i486-linux-gnu-gcc: command not found
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 26: i486-linux-gnu-gcc: command not found
make[1]: i486-linux-gnu-gcc: Command not found
====== making target CONFIG-arch [new prereqs: .config conf.vars]======
This is kernel package version 11.001-0.1.
====== making target CONFIG/linux-headers-2.6.27 [new prereqs: CONFIG-arch]======

====== making target CONFIG/linux-image-2.6.27 [new prereqs: CONFIG-arch]======

====== making target CONFIG/linux-uml-2.6.27 [new prereqs: CONFIG-arch]======

====== making target CONFIG/linux-xen0-2.6.27 [new prereqs: CONFIG-arch]======

====== making target CONFIG/linux-xenu-2.6.27 [new prereqs: CONFIG-arch]======

====== making stamp-configure-arch because of  ======
====== making target configure-arch [new prereqs: stamp-configure-arch]======
====== making stamp-indep-conf because of  ======

====== making target CONFIG-indep [new prereqs: stamp-indep-conf]======
====== making target debian/stamp-kernel-conf [new prereqs: .config Makefile]======
/usr/bin/make CROSS_COMPILE=i486-linux-gnu- ARCH=i386 \
                oldconfig
make[1]: Entering directory `/usr/src/linux-2.6.27'
scripts/kconfig/conf -o arch/x86/Kconfig
#
# configuration written to .config
#
make[1]: Leaving directory `/usr/src/linux-2.6.27'
/usr/bin/make CROSS_COMPILE=i486-linux-gnu- ARCH=i386 prepare
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 25: i486-linux-gnu-gcc: command not found
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 26: i486-linux-gnu-gcc: command not found
make[1]: i486-linux-gnu-gcc: Command not found
make[1]: Entering directory `/usr/src/linux-2.6.27'
scripts/kconfig/conf -s arch/x86/Kconfig
make[1]: Leaving directory `/usr/src/linux-2.6.27'
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 25: i486-linux-gnu-gcc: command not found
/usr/src/linux-2.6.27/scripts/gcc-version.sh: line 26: i486-linux-gnu-gcc: command not found
make[1]: i486-linux-gnu-gcc: Command not found
make[1]: Entering directory `/usr/src/linux-2.6.27'
  CHK    include/linux/version.h
  CHK    include/linux/utsrelease.h
  CC      kernel/bounds.s
/bin/sh: i486-linux-gnu-gcc: command not found
make[2]: *** [kernel/bounds.s] Error 127
make[1]: *** [prepare0] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.27'
make: *** [debian/stamp-kernel-conf] Error 2
debian:/usr/src/linux-2.6.27#

So basically I am getting errors like:
Code:

make[1]: i486-linux-gnu-gcc: Command not found
As per "man make-kpkg":
Code:

  --arch foo
              This is useful for setting the architecture when you are cross compiling. If you are not cross compiling, the architecture  is  determined  automatically.  The
              same  effect  can be achieved by setting the environment variable KPKG_ARCH.  The value should be whatever DEB_HOST_ARCH_CPU contains when dpkg-architecture is
              run on the target machine, or it can be an other architecture in a multi-arch set (like i386/amd64).

On searching for "i486-linux-gnu-gcc" I found that the package that needs to be installed is gcc which is already installed on my system.

How do I resolve this issue?

EDIT Here is the solution.

pinniped 10-17-2008 07:40 PM

Did you explicitly set up a cross-compiler or you just changed the "arch"?

It should be possible to build on your 64-bit compiler if you can pass the "-m32" flag. Most of the CPU-specific features are actually selected in the kernel config file, so "-m32" should generate 80386 code and other kernel config selections will provide support for other features of your target x86 CPU.

If you need to provide an initramfs image and so on for your target computer, you will also need a copy of the files to go into that image.

kushalkoolwal 10-17-2008 07:48 PM

Quote:

Originally Posted by pinniped (Post 3314059)
Did you explicitly set up a cross-compiler or you just changed the "arch"?

Not sure what you mean by "explicitly set up a cross-compiler". All I did was to pass the -arch flag as mentioned in my above post. I did not do anything else?

Quote:

Originally Posted by pinniped (Post 3314059)
It should be possible to build on your 64-bit compiler if you can pass the "-m32" flag. Most of the CPU-specific features are actually selected in the kernel config file, so "-m32" should generate 80386 code and other kernel config selections will provide support for other features of your target x86 CPU.

where do I pass the "-m32" flag? I don't see any options in the make-kpkg?

pinniped 10-17-2008 10:49 PM

Well, you didn't set up a cross-compiler then. You're just lucky that the compiler on x86_64 will also compile for x86. You can edit the Makefile and add "-m32" to the CFLAGS list.

kushalkoolwal 10-18-2008 11:35 AM

Quote:

Originally Posted by pinniped (Post 3314130)
Well, you didn't set up a cross-compiler then.

Thanks for the tips. Out of curiosity is there any documentation that explains how to set-up a cross-compiler? I am assuming that the cross-compiling method is different than adding "-m32" flag?

pinniped 10-18-2008 05:27 PM

Quote:

Originally Posted by kushalkoolwal (Post 3314744)
Thanks for the tips. Out of curiosity is there any documentation that explains how to set-up a cross-compiler? I am assuming that the cross-compiling method is different than adding "-m32" flag?

A genuine cross-compiler is very different; you have to build the entire compiler and tool chain - linker, assembler, etc. To be useful for building more than just a kernel, you'll also have to build at least a libc library. Basically, you build gcc and the various tools to run on your machine but generate code for another machine. Managing the search paths and where various things are stored on your machine is the tricky part.

You can find links to documentation on setting up cross-compilers from the GCC project website. You can also look at the CLFS project in the Linux From Scratch project for an example of setting up a cross-compiler.

kushalkoolwal 06-15-2009 05:48 PM

Alright, after a month of research I found some answers to my original question.

Solution
If you natively want to compile a 32-bit kernel then you need to have 32-bit cross-compiling stuff installed as also mentioned by one of the members. However there is another way also to do the same - using debootstrap.


All times are GMT -5. The time now is 06:31 PM.