Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED]Cross Compilling Kernel without genkernel
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
Troopo
Apprentice
Apprentice


Joined: 14 Jun 2015
Posts: 158

PostPosted: Thu Jun 23, 2016 11:13 pm    Post subject: [SOLVED]Cross Compilling Kernel without genkernel Reply with quote

Hi,

I'm trying to build an i686 kernel on my amd64 machine for another machine.

Could not get clear instructions for that and spent a few hours trying to make it work.

Here are the steps i did, please take a look and tell me if something is missing:

Code:

sudo crossdev -t i686
sudo cp -r /usr/src/linux-4.4.6-gentoo/ /tmp/gen
cd /tmp/gen/
sudo make mrproper
sudo cp ~/Downloads/bla/config ./.config
sudo make ARCH=x86 CROSS_COMPILE=i686-pc-linux-gnu- all -j8
sudo make ARCH=x86 CROSS_COMPILE=i686-pc-linux-gnu- modules -j8
sudo make INSTALL_MOD_PATH=kernel_modules modules_install -j8


Thanks


Last edited by Troopo on Sat Jun 25, 2016 8:14 pm; edited 1 time in total
Back to top
View user's profile Send private message
Troopo
Apprentice
Apprentice


Joined: 14 Jun 2015
Posts: 158

PostPosted: Fri Jun 24, 2016 9:43 am    Post subject: Reply with quote

After that i copy everything to the other machine:
Code:

sudo genkernel --kernname=test --arch-override=x86 initramfs
sudo mv /boot/initramfs-test-x86-4.4.6-gentoo /mnt/test/iniramfs-test
sudo cp arch/x86/boot/bzImage /mnt/test/kernel-test
sudo cp System.map /mnt/test/System.map-test
sudo cp -r kernel_moudles/lib /mnt/test


And copy from test to the right places in the other machine /boot and /usr/lib
Then update grub2 cfg

Another question would be if there is a better\easier way to do this copy\install, initramfs and where does it say which modules folder does it use?
Hopefully i got everything right including the name conventions...
Back to top
View user's profile Send private message
szatox
Veteran
Veteran


Joined: 27 Aug 2013
Posts: 1746

PostPosted: Fri Jun 24, 2016 5:38 pm    Post subject: Reply with quote

Hint:
Code:
alias make-armv7='make -j8 -l4 INSTALL_MOD_PATH=/usr/armv7a-hardfloat-linux-gnueabi/ INSTALL_PATH="/usr/armv7a-hardfloat-linux-gnueabi/boot/" ARCH=arm CROSS_COMPILE=/usr/bin/armv7a-hardfloat-linux-gnueabi-'


Now, the hard question: Why would you want to cross compile kernel for i686? Do you run your compilation on a SPARC?
If your build host is an x86_64 machine, you have 2 better options:
1) get 32 bit stage 3 and build in chroot
2) simply demand your native compiler to generate 32-bit code. It does work this way. I'm not sure which variable controls it, but I'd start with a close look at ARCH=
Back to top
View user's profile Send private message
Troopo
Apprentice
Apprentice


Joined: 14 Jun 2015
Posts: 158

PostPosted: Fri Jun 24, 2016 6:38 pm    Post subject: Reply with quote

szatox wrote:
Hint:
Code:
alias make-armv7='make -j8 -l4 INSTALL_MOD_PATH=/usr/armv7a-hardfloat-linux-gnueabi/ INSTALL_PATH="/usr/armv7a-hardfloat-linux-gnueabi/boot/" ARCH=arm CROSS_COMPILE=/usr/bin/armv7a-hardfloat-linux-gnueabi-'


Now, the hard question: Why would you want to cross compile kernel for i686? Do you run your compilation on a SPARC?
If your build host is an x86_64 machine, you have 2 better options:
1) get 32 bit stage 3 and build in chroot
2) simply demand your native compiler to generate 32-bit code. It does work this way. I'm not sure which variable controls it, but I'd start with a close look at ARCH=


To be honest i'm rather new to this and didn't understand most of what you have said.

The example you gave seems to be related to ARM devices and most of what is there i already used as shown in my previous comments.

The situation is rather simple, i have 2 machines: first one is a PC which is the main one i use and it's x86_64 and the other is an old laptop which is only x86, i want to compile my kernel for the laptop in my main machine since it only takes a couple of mins while if i do this natively on the laptop it would take me about 11 hours.

So in short my host is x86_64 and my target is x86 only, i'm still having an issue figuring out the best way to create and initramfs as mentioned in my last comment.

Oh and all of this because that laptop seems to be having some kernel related issues with the FS so i'm experimenting with the options in order to fix it and that means multiple kernel compilations.

When i will have the time to go trough the options and optimize the kernel for my hardware that would be awesome but at the moment make all is the best i can do, and genkernel has an issue with cross compiling so i have to do it this way.

As a last note this is very educational for me :)

Thanks.
Back to top
View user's profile Send private message
bstaletic
Apprentice
Apprentice


Joined: 05 Apr 2014
Posts: 225

PostPosted: Fri Jun 24, 2016 7:21 pm    Post subject: Reply with quote

There may be an even easier way. When you open kernel config there's an option that says something like "build 64bit kernel image". Try unchecking that and building as usual. There's also "-m32" flag for gcc, that tells gcc to produce 32bit code.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13836

PostPosted: Sat Jun 25, 2016 1:15 am    Post subject: Reply with quote

Compiling an x86-only kernel from an x86_64 system is natively supported without the use of a cross-compiler. I had the same situation you describe: a powerful x86_64 and a slower x86-only and I routinely used the x86_64 to build for the x86. I never installed an i686 cross-compiler. You need to set ARCH=x86, either in the environment or on the Make command line. You should start from a clean build area when you set that option for the first time. If you still have trouble, please run make mrproper; export ARCH=x86; make menuconfig, make your choices, and then make. If any steps fail, post which step failed and the output it produced. You should not need to set compiler flags (such as -m32) explicitly. Setting ARCH=x86 should cause the kernel build system to supply those flags automatically when they are appropriate.

Caution: make mrproper will delete your .config. I prefer not trying to reuse a config across architectures, but you may want to save your existing config as a reference for what options to enable in the new x86 kernel.
Back to top
View user's profile Send private message
Troopo
Apprentice
Apprentice


Joined: 14 Jun 2015
Posts: 158

PostPosted: Sat Jun 25, 2016 8:14 pm    Post subject: Reply with quote

Thanks for your comments, i guess you are correct i don't really need to cross compile in this case but it was a possibility and cool one too :)
I did learn a lot from this experience.

I'm marking this as resolved.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum