• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
UBports Robot Logo UBports Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

How to compile ONLY a kernel

Scheduled Pinned Locked Moved Porting
4 Posts 3 Posters 4.1k Views 1 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      doniks
      last edited by doniks 18 Jun 2017, 09:07

      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 repo.

      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 .config
      • but when I try to run make it 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 arch/arm/configs/myconfig_defconfig
      • when I now run make ARCH=arm myconfig_defconfig it says it copied the config, OK
      • However afterwards I run make ARCH=arm it 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[1]: '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?

      D 1 Reply Last reply 18 Jun 2017, 10:30 Reply Quote 0
      • D Offline
        doniks @doniks
        last edited by doniks 18 Jun 2017, 10:30

        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

        M 1 Reply Last reply 13 Jul 2022, 18:02 Reply Quote 0
        • U Offline
          UniSuperBox
          last edited by 18 Jun 2017, 15:05

          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

          1 Reply Last reply Reply Quote 1
          • M Offline
            manit_c @doniks
            last edited by 13 Jul 2022, 18:02

            @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.

            ARCH=arm64
            CLANG_TRIPLE=aarch64-linux-gnu-
            CROSS_COMPILE=aarch64-linux-androidkernel-
            CROSS_COMPILE_COMPAT=arm-linux-androidkernel-
            LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN=prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin
            LINUX_GCC_CROSS_COMPILE_COMPAT_PREBUILTS_BIN=prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/

            There were a lot of other dependencies I had to install but that took care of the correct gcc version.

            Hope this helps someone.

            1 Reply Last reply Reply Quote 2
            • First post
              Last post