How to compile ONLY a kernel
While trying to build the whole system for my N7, I'm looking for a way of ONLY building a kernel, preferably outside of the whole gigantic source tree checked out by
However, I think I'm stuck with two (hopefully) simple questions:
- how to set the kernel config file
- how to do the cross compilation
What I've tried so far:
- clone the kernel I want to try ( git://github.com/freedreno/kernel-msm.git, branch mako-kernel)
- copy the config I want to use into
- but when I try to run
makeit will always insist on going through an endless series of questions what to configure and how to update the config instead of just using it
- looking at this: https://stackoverflow.com/questions/41885015/what-exactly-does-linux-kernels-make-defconfig-do#41886394 I have now copied my config into
- when I now run
make ARCH=arm myconfig_defconfigit says it copied the config, OK
- However afterwards I run
make ARCH=armit fails quickly (error below). I think this is because I'm using the wrong compiler. Which would make sense because I'm on my laptop and I guess I need an arm crosscompiler, but I don't know how to do this.
CHK include/linux/version.h CHK include/generated/utsrelease.h make: 'include/generated/mach-types.h' is up to date. CC kernel/bounds.s gcc: error: unrecognized argument in option ‘-mabi=aapcs-linux’ gcc: note: valid arguments to ‘-mabi=’ are: ms sysv gcc: error: unrecognized command line option ‘-mlittle-endian’ gcc: error: unrecognized command line option ‘-mapcs’ gcc: error: unrecognized command line option ‘-mno-sched-prolog’ gcc: error: unrecognized command line option ‘-mno-thumb-interwork’ /media/peter/share2/data/freedreno/kernel-msm/./Kbuild:35: recipe for target 'kernel/bounds.s' failed
Can someone help me? Am I just approaching this the wrong way?
I think I figured it out - the compiler is happily chugging along - let's see.
What I did was: Following this: https://www.acmesystems.it/arm9_toolchain , https://wiki.ubuntu.com/KernelTeam/ARMKernelCrossCompile I did
sudo apt install gcc-arm-linux-gnueabihf export CROSS_COMPILE=arm-linux-gnueabihf- export CC=/usr/bin/arm-linux-gnueabihf-gcc export $(dpkg-architecture -aarmhf) make clean make ARCH=arm myconfig_defconfig make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf-
That got me one step further, but then make was complaining about something with gcc 5, so I assume that I was using a too new compiler version, so I installed 4.8. Afterwards it seemed as if still the wrong compiler was picked up at some steps, so I created a couple of symlinks to make sure it uses the right one:
sudo apt install gcc-4.8-arm-linux-gnueabihf
mkdir ~/bin-gcc-4.8 cd ~/bin-gcc-4.8 ln -s /usr/bin/arm-linux-gnueabihf-gcc-4.8 . ln -s arm-linux-gnueabihf-gcc-4.8 arm-linux-gnueabihf-gcc ln -s /usr/bin/arm-linux-gnueabihf-ld . ln -s /usr/bin/arm-linux-gnueabihf-ar .
export PATH=~/bin-gcc-4.8:$PATH export CC=/usr/bin/arm-linux-gnueabihf-gcc-4.8 export CROSS_COMPILE=arm-linux-gnueabihf- export $(dpkg-architecture -aarmhf) make clean make ARCH=arm myconfig_defconfig make ARCH=arm CROSS_COMPILE=~/bin-gcc-4.8/arm-linux-gnueabihf-
Maybe there are more straight forward ways to achieve this ... Whatever, it seems to work
Yes, that is exactly how you do it. Generally the Android build system will use its own customized versions of gcc automagically, so you need to specify any alternatives yourself in a single build.
I was able to use update-alternatives to swap out my compilers once upon a time, though I don't recommend that unless you're building in a container. https://forums.ubports.com/topic/129/solution-building-ubuntu-touch-source-on-ubuntu-16-10
@doniks Thanks for the post, it gave me clues on my issue.
This is an old thread but wanted to add to your post because it took me so long to get it to compile. Having never compiled an Android Kernel before I think I spent 2 days on it.
Using Ubuntu 18, gcc-4.8 was not available through apt. I ended up download the AOSP8 source. The source contains gcc for the android version located in prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android
Looking at the build.config.aarch64 file https://android.googlesource.com/kernel/common/+/a5d10f0defc377d43672b304e31e37a517fbf0bf/build.config.aarch64
I found the variables, needed for the kernel source.
There were a lot of other dependencies I had to install but that took care of the correct gcc version.
Hope this helps someone.