Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
howtos:slackware_admin:cross_compiling_the_linux_kernel [2018/06/01 21:53 (UTC)]
bifferos
howtos:slackware_admin:cross_compiling_the_linux_kernel [2018/06/01 22:51 (UTC)] (current)
bifferos [Cross-compiler]
Line 13: Line 13:
 ==== Slackware Install ==== ==== Slackware Install ====
  
-My test cross-compiler build machine is Slackware64 14.2 with disk sets A,​AP,​D,​K,​L,​N. ​ I'm sure you can install a lot less to build Buildroot, in fact I'd expect only A and D to be needed, however ​in the spirit of the Slackware community is that you install everything so the risk is yours.+My test cross-compiler build machine is Slackware64 14.2 with disk sets A,​AP,​D,​K,​L,​N. ​ I'm sure you can install a lot less to build Buildroot, in fact I'd expect only A and D to be needed, however the spirit of the Slackware community is that you install everything so the risk is yours.
  
 ==== Cross-compiler ==== ==== Cross-compiler ====
Line 25: Line 25:
 $ make menuconfig</​code>​ $ make menuconfig</​code>​
  
-For building 32-bit kernels with maximum compatibility I generally select the 486 output option, (586 is the default):+You will see a configuration system much like the kernel config.  ​For building 32-bit kernels with maximum compatibility I generally select the 486 output option, (586 is the default):
  
 <​code>​Target options -> Target Architecture Variant (i486)</​code>​ <​code>​Target options -> Target Architecture Variant (i486)</​code>​
  
-[OPTIONAL] If you want, you may get better compatibility with your chosen kernel by choosing a non-default ​GCC version. ​ This is not required for this demonstration:+To make the compiler we are about to build behave more like the Slackware one we want to use glibc instead of the default ​uClibc-ng (which ​is more suited to embedded applications):
  
-<​code>​Toolchain -> GCC compiler version</​code>​+<​code>​Toolchain -> C library (glibc)</​code>​
  
-Now save that configuration ​and start it compiling:+If you don't do this you will need to disable stack protection in your kernel config when we come to compile ​that and we want to keep a standard Slackware config, because we're true Slackers heart-and-soul right? :). 
 + 
 +You can play around with many other options like kernel header versions however for building the kernel itself none of these matter. ​ The only option that may conceivably make a difference is the GCC version, particularly if you are building an old kernel version which doesn'​t support later versions of GCC.  For this demonstration we can leave the defaults though. ​ Save the config and then:
  
 <​code>​$ make</​code>​ <​code>​$ make</​code>​
  
 +While that's running we'll configure the kernel so it's ready to compile.
 ==== Kernel preparation ==== ==== Kernel preparation ====
  
Line 44: Line 47:
 $ wget https://​mirrors.slackware.com/​slackware/​slackware-14.2/​kernels/​hugesmp.s/​config -O .config</​code>​ $ wget https://​mirrors.slackware.com/​slackware/​slackware-14.2/​kernels/​hugesmp.s/​config -O .config</​code>​
  
-You should now have a .config in /​usr/​src/​linux which says '​CONFIG_64BIT is not set' at the top.+You should now have a .config in /​usr/​src/​linux which says '​CONFIG_64BIT is not set' at the top.  That will replace your old 64-bit kernel .config that you had before (included from the '​K'​ disk set).  Obviously copy the kernel someplace else if you wanted to keep that!
  
 ==== Kernel compilation ==== ==== Kernel compilation ====
  
-When the Buildroot build is done, you need to include the cross-compiler in your path.+When the Buildroot build is done, you need to include the generated ​cross-compiler in your path.
  
 <​code>​export PATH=/​usr/​src/​buildroot-2018.02.2/​output/​host/​bin:​$PATH</​code>​ <​code>​export PATH=/​usr/​src/​buildroot-2018.02.2/​output/​host/​bin:​$PATH</​code>​
  
-The compiler executable has the architecture prefix in it's name to avoid collision with the system ​gcc, you can now run it and test it works:+The compiler executable has the architecture prefix in it's name to avoid collision with the system ​GCC, you can now run it and test if it works:
  
 <​code>​$ i486-linux-gcc --version</​code>​ <​code>​$ i486-linux-gcc --version</​code>​
  
-If you are interested, you can find all the other toolchain tools like ld, ar and so on with similar prefixes. ​ Now configure your kernel if you want to.  I'm leaving the default options here:+If you are interested, you can find all the other toolchain tools like ld, ar and so on with similar prefixes. ​ Now configure your kernel if you want to:
  
 <​code>​$ cd /​usr/​src/​linux <​code>​$ cd /​usr/​src/​linux
 $ make menuconfig CROSS_COMPILE=i486-linux- ARCH=i386</​code>​ $ make menuconfig CROSS_COMPILE=i486-linux- ARCH=i386</​code>​
  
-Finally make the kernel:+I'm leaving the default options here, just appending a '​-buildroot'​ to the kernel name. Finally make the kernel:
  
 <​code>​$ make bzImage CROSS_COMPILE=i486-linux- ARCH=i386</​code>​ <​code>​$ make bzImage CROSS_COMPILE=i486-linux- ARCH=i386</​code>​
  
-Copy the built kernel to a 32-bit machine and it should boot.  If you want to compile/​install the modules as well, just make sure you don't forget to use the same CROSS_COMPILE and ARCH variables every time you specify the make commands, everything should use the cross-compiler: ​'make modules', 'make modules_install' ​and so on.  You will probably get away without these appended for some commands like 'make clean',​ but it's safest to just include them whenever you do anything ​on that kernel, they certainly won't hurt.+Copy the built kernel to a 32-bit machine and it should boot.  If you want to compile/​install the modules as well, just make sure you don't forget to use the same CROSS_COMPILE and ARCH variables every time you specify the make commands, everything should use the cross-compiler:​ 
 + 
 +<​code>​$ ​make modules ​CROSS_COMPILE=i486-linux- ARCH=i386 
 +make modules_install ​CROSS_COMPILE=i486-linux- ARCH=i386</​code>​ 
 + 
 +and so on.  You will probably get away without these appended for some commands like 'make clean',​ but it's safest to just include them whenever you do any work on that kernel, they certainly won't hurt.
  
  

In Other Languages
QR Code
QR Code howtos:slackware_admin:cross_compiling_the_linux_kernel (generated for current page)