Author Topic: How to crosscompile the Cosmo Linux kernel  (Read 5387 times)

drbytes

  • Newbie
  • *
  • Posts: 17
    • View Profile
How to crosscompile the Cosmo Linux kernel
« on: July 27, 2020, 03:00:29 am »

This information was buried in another thread where I tried to get my Cosmo to talk to my Nodemcu devices via serial, for that to happen I had to compile the 4.4 kernel released 24 Juli 2020.
@Varti suggested to extract the relevant kernel building information and place it in a separate post.

Here are the steps I took if anybody wants to compile the kernel used on the Cosmo to add support for devices or just good old tinkering.

Get hold of a debian machine, either Install debian in a virtual machine or use an existing installation.
Install some dependencies and create a folder cosmo to keep everything organized.

Code: [Select]
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev bc git gcc-aarch64-linux-gnu
mkdir cosmo
cd cosmo
mkdir KERNEL_OUT

Go ahead and get the cosmo kernel used in the 24/07 build and cd into the directory:
Code: [Select]
git clone https://github.com/gemian/cosmo-linux-kernel-4.4.git

You should have this directory structure now if you started in your home directory :
~/cosmo/
            |_ KERNEL_OUT/
            |_ cosmo-linux-kernel-4.4/

Edit the Makefile
Code: [Select]
cd cosmo-linux-kernel-4.4/
nano Makefile

--> Find "KBUILD_CFLAGS" and change the line
Code: [Select]
KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ to
Code: [Select]
KBUILD_CFLAGS   := -w -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
Import the latest kernel config, it's the one that is in the 24/07 build
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 k71v1_64_bsp_defconfigConfigure your kernel and save to the default .config location
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfigbuild it
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
Your module should be in ../KERNEL_OUT/drivers, just scp it over to your cosmo, depmod and modprobe it.

Enjoy



Varti

  • Administrator
  • Hero Member
  • *****
  • Posts: 1266
    • View Profile
Re: How to crosscompile the Cosmo Linux kernel
« Reply #1 on: July 27, 2020, 04:45:58 am »
Thanks, I have now set the post as sticky.

Varti
Planet Gemini PDA WiFi/LTE with Mediatek x27
SL-C1000 running Arch Linux ARM May2017, K30225 Wi-Fi CF Card, 64GB SDXC card
and many other Zauruses!

suhrm

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How to crosscompile the Cosmo Linux kernel
« Reply #2 on: July 29, 2020, 12:39:03 pm »
Have you been able to build .deb packages (want to have kernel headers as well in order to install some drivers and this is much easier to manage with .deb). I get some missing UAPI file ../fpsgo.h error. Managed to compile .deb a long time ago however I did not note down all of the steps I took.

klampfenfreak

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: How to crosscompile the Cosmo Linux kernel
« Reply #3 on: August 18, 2020, 02:44:39 pm »
Hi,
for what stands the "-w" option in the KBUILD_FLAGS file, please?

How can I create a flashable .img from the build Kernel, please?

Thank you!
klampfenfreak


klampfenfreak

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: How to crosscompile the Cosmo Linux kernel
« Reply #4 on: August 21, 2020, 06:47:45 pm »
Ok, what I had read for now, the "-w" disables error messages.
I like to have the option to mount cifs filesystem, so I  crosscompiled the kernel to get the missing modules in the *.ko format.
But I only get .o files in the KERNEL_Output folder. How can I covert them to load them as modules.
It the first time I compile a kernel and I am a little bit confused.
I also tried to dd the Image.gz but I think I have to melt it with a ramdisk. Where I get the ramdisk file for Cosmo?Is it the same ramdisk which is included in the android kernel?
Thank you :)
   

cam1965

  • Sr. Member
  • ****
  • Posts: 410
    • View Profile
    • http://
Re: How to crosscompile the Cosmo Linux kernel
« Reply #5 on: August 22, 2020, 10:16:11 am »
Look inside /usr/share/kernel. There is a file called initrd.img-gemini.cpio.gz . This is the ramdisk. If it is not there, install cosmo-linux-kernel and cosmo-linux-kernel-headers. You can see all my posts . I have compiled the kernel inside cosmo ( much more complicated , since I have not used -w flags and had to link and modify a lot of files ). In my case I had used mkinitramfs  to generate the ramdisk. But compiling outside cosmo communicator I think it is not possible. Good luck.

Please see one of  my posts here  ( it has the parameters to generate the kernel )

https://www.oesf.org/forum/index.php?topic=36195.msg295355#msg295355

« Last Edit: August 22, 2020, 10:38:23 am by cam1965 »

SL

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: How to crosscompile the Cosmo Linux kernel
« Reply #6 on: April 22, 2021, 11:47:51 am »
Thanks, managed to compile the kernel on device (using 60/60 partition scheme, 90/30 was not enough); lost sudo on reboot though, so still need to do some tinkering.

Edit: Started a new topic for on-device kernel compile; currently this works great for v4 of the cosmo debian installer.
« Last Edit: May 06, 2021, 09:41:47 am by SL »
Nokia N900, Cosmo Communicator