Author Topic: On-device kernel compilation  (Read 899 times)

SL

  • Newbie
  • *
  • Posts: 16
    • View Profile
On-device kernel compilation
« on: April 26, 2021, 10:21:12 pm »
This post is modified to capture improvements made for latest version (v4) of the Cosmo Debian/KDE installer: https://support.planetcom.co.uk/index.php/Linux_for_Cosmo

The whole process is now seamless, greatly simplified and is based on the gemian wiki entry for kernel compilation https://github.com/gemian/gemian/wiki/KernelCompilation.

Steps:
1. Install version 4 of the the Cosmo Debian/KDE image (first link above).
2. Follow instructions from the second link above but install the dependencies before pulling down the kernel sources and add git (needed for pulling down the sources) in the dependencies.
3. Happy (kernel) hacking.

Thanks to Adam Boardman for providing the links/missing pieces.

==============================Relevant to v3 of the debian installer only and left here for record and info===================

This post is an adaption to on-device compilation of the steps described in:
https://www.oesf.org/forum/index.php?topic=36321.0

It shows all the steps of arriving at the on-device kernel compile capability. I am not an expert at any of this and appreciate any useful suggestions (especially as far as the device tree compiler is concerned, if you know the actual sources used, please let me know).

Make sure you have enough space to compile the kernel when partitioning your cosmo. The minimum that works for me is 60 GB Android / 60 GB Linux partitioning scheme (90/30 crashed the kernel compile).

Set-up your environment as described in the article above:
Code: [Select]
sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev bc git gcc-aarch64-linux-gnu vim
mkdir KERNEL_OUT

Download the kernel source:
Code: [Select]
git clone https://github.com/gemian/cosmo-linux-kernel-4.4.git
Edit the Makefile:
Code: [Select]
cd cosmo-linux-kernel-4.4
vim Makefile

Find the line with KBUILD_CFLAGS (line 398) and edit from:
Code: [Select]
KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \to
Code: [Select]
KBUILD_CFLAGS   := -w -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \and save the edit

Import the kernel configuration:
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 k71v1_64_bsp_defconfig
This command results in a few warnings, but does not result in a bad kernel compile:
Code: [Select]
cosmo@cosmopda:~/cosmo-linux-kernel-4.4$ make O=../KERNEL_OUT ARCH=arm64 k71v1_64_bsp_defconfig
make[1]: Entering directory '/home/cosmo/KERNEL_OUT'
  HOSTCC  scripts/basic/fixdep
  GEN     ./Makefile
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
drivers/input/touchscreen/mediatek/NT36xxx/Kconfig:4:warning: ignoring type redefinition of 'TOUCHSCREEN_MTK_NT36xxx' from 'boolean' to 'tristate'
drivers/input/fingerprint/chips_driver/Kconfig:1:warning: ignoring type redefinition of 'MTK_FINGERPRINT_CHIPSAILING_CS358' from 'tristate' to 'boolean'
drivers/input/fingerprint/aw6302_driver/Kconfig:1:warning: ignoring type redefinition of 'MTK_SIMSWAP_AW6302' from 'tristate' to 'boolean'
warning: (MTK_GROUP_ENABLE_VERITY) selects INTEGRITY_ASYMMETRIC_KEYS which has unmet direct dependencies (INTEGRITY && INTEGRITY_SIGNATURE)
warning: (MACH_MT6771 && MACH_MT6775 && PINCTRL_MT6739 && PINCTRL_MT6775) selects MTK_EINT_MULTI_TRIGGER_DESIGN which has unmet direct dependencies (PINCTRL && PINCTRL_MTK)
warning: (MTK_GROUP_ENABLE_VERITY) selects INTEGRITY_ASYMMETRIC_KEYS which has unmet direct dependencies (INTEGRITY && INTEGRITY_SIGNATURE)
warning: (MACH_MT6771 && MACH_MT6775 && PINCTRL_MT6739 && PINCTRL_MT6775) selects MTK_EINT_MULTI_TRIGGER_DESIGN which has unmet direct dependencies (PINCTRL && PINCTRL_MTK)
#
# configuration written to .config
#
make[1]: Leaving directory '/home/cosmo/cosmo/KERNEL_OUT'

Configure the kernel:
Code: [Select]
make O=../KERNEL_OUT ARCH=arm64 menuconfigHit save, ok, exit. exit;). Again, same warnings as above, but the kernel compile can continue.

Start compilation:
Code: [Select]
make  O=../KERNEL_OUT ARCH=arm64
This will do the majority of the kernel compile, but eventually (~1 hour of happy compiling) results in an error that needs to be fixed:
Code: [Select]
CHK     include/generated/compile.h
  UPD     include/generated/compile.h
  CC      init/version.o
  LD      init/built-in.o
  KSYM    .tmp_kallsyms1.o
  KSYM    .tmp_kallsyms2.o
  LD      vmlinux
  SORTEX  vmlinux
  SYSMAP  System.map
for i in /home/cosmo/cosmo-linux-kernel-4.4/arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dts /home/cosmo/cosmo-linux-kernel-4.4/arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dts /home/cosmo/cosmo-linux-kernel-4.4/arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dts; do \
        base_prj=`grep -m 1 '#include [<\"].*\/cust\.dtsi[>\"]' $i | sed 's/#include [<"]//g'\
        | sed 's/\/cust\.dtsi[>"]//g' | sed 's/\/\*//g' | sed 's/\*\///g' | sed 's/ //g'`\
        prj_path=./arch/arm64/boot/dts/$base_prj ;\
        dws_path=/home/cosmo/cosmo-linux-kernel-4.4/drivers/misc/mediatek/dws/mt6771/$base_prj.dws ;\
        if [ -f $dws_path ] ; then \
                mkdir -p $prj_path ;\
                 /home/cosmo/cosmo-linux-kernel-4.4/tools/dct/DrvGen.py $dws_path $prj_path $prj_path cust_dtsi;\
        fi \
done
[DCT_INFO]: DWS file path is /home/cosmo/cosmo-linux-kernel-4.4/drivers/misc/mediatek/dws/mt6771/k71v1_64_bsp.dws
[DCT_INFO]: Gen files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Log files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Parameter is cust_dtsi
[DCT_INFO]: chip id: MT6771
[DCT_INFO]: Chip ID : MT6771
[DCT_INFO]: Project Info: Sylvia
[DCT_INFO]: Start to generate cust_dtsi file...
[DCT_INFO]: Generate cust_dtsi file successfully!
[DCT_INFO]: DWS file path is /home/cosmo/cosmo-linux-kernel-4.4/drivers/misc/mediatek/dws/mt6771/k71v1_64_bsp.dws
[DCT_INFO]: Gen files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Log files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Parameter is cust_dtsi
[DCT_INFO]: chip id: MT6771
[DCT_INFO]: Chip ID : MT6771
[DCT_INFO]: Project Info: Sylvia
[DCT_INFO]: Start to generate cust_dtsi file...
[DCT_INFO]: Generate cust_dtsi file successfully!
[DCT_INFO]: DWS file path is /home/cosmo/cosmo-linux-kernel-4.4/drivers/misc/mediatek/dws/mt6771/k71v1_64_bsp.dws
[DCT_INFO]: Gen files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Log files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Parameter is cust_dtsi
[DCT_INFO]: chip id: MT6771
[DCT_INFO]: Chip ID : MT6771
[DCT_INFO]: Project Info: Sylvia
[DCT_INFO]: Start to generate cust_dtsi file...
[DCT_INFO]: Generate cust_dtsi file successfully!
for i in /home/cosmo/cosmo-linux-kernel-4.4/arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dts /home/cosmo/cosmo-linux-kernel-4.4/arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dts /home/cosmo/cosmo-linux-kernel-4.4/arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dts; do \
        base_prj=`grep -m 1 '#include [<\"].*\/cust\.dtsi[>\"]' $i | sed 's/#include [<"]//g'\
        | sed 's/\/cust\.dtsi[>"]//g' | sed 's/\/\*//g' | sed 's/\*\///g' | sed 's/ //g'`\
        prj_path=./arch/arm64/boot/dts/$base_prj ;\
        dws_path=/home/cosmo/cosmo-linux-kernel-4.4/drivers/misc/mediatek/dws/mt6771/$base_prj.dws ;\
        if [ -f $dws_path ] ; then \
                mkdir -p $prj_path ;\
                 /home/cosmo/cosmo-linux-kernel-4.4/tools/dct/DrvGen.py $dws_path $prj_path $prj_path cust_dtsi;\
        fi \
done
[DCT_INFO]: DWS file path is /home/cosmo/cosmo-linux-kernel-4.4/drivers/misc/mediatek/dws/mt6771/k71v1_64_bsp.dws
[DCT_INFO]: Gen files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Log files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Parameter is cust_dtsi
[DCT_INFO]: chip id: MT6771
[DCT_INFO]: Chip ID : MT6771
[DCT_INFO]: Project Info: Sylvia
[DCT_INFO]: Start to generate cust_dtsi file...
[DCT_INFO]: Generate cust_dtsi file successfully!
[DCT_INFO]: DWS file path is /home/cosmo/cosmo-linux-kernel-4.4/drivers/misc/mediatek/dws/mt6771/k71v1_64_bsp.dws
[DCT_INFO]: Gen files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Log files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Parameter is cust_dtsi
[DCT_INFO]: chip id: MT6771
[DCT_INFO]: Chip ID : MT6771
[DCT_INFO]: Project Info: Sylvia
[DCT_INFO]: Start to generate cust_dtsi file...
[DCT_INFO]: Generate cust_dtsi file successfully!
[DCT_INFO]: DWS file path is /home/cosmo/cosmo-linux-kernel-4.4/drivers/misc/mediatek/dws/mt6771/k71v1_64_bsp.dws
[DCT_INFO]: Gen files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Log files path is /home/cosmo/KERNEL_OUT/arch/arm64/boot/dts/k71v1_64_bsp
[DCT_INFO]: Parameter is cust_dtsi
[DCT_INFO]: chip id: MT6771
[DCT_INFO]: Chip ID : MT6771
[DCT_INFO]: Project Info: Sylvia
[DCT_INFO]: Start to generate cust_dtsi file...
[DCT_INFO]: Generate cust_dtsi file successfully!
  DTC     arch/arm64/boot/dts/mediatek/mt6771.dtb
/bin/sh: 1: /home/cosmo/cosmo-linux-kernel-4.4/scripts/dtc/dtc_overlay: Exec format error
make[2]: *** [scripts/Makefile.lib:302: arch/arm64/boot/dts/mediatek/mt6771.dtb] Error 2
make[1]: *** [arch/arm64/Makefile:126: mediatek/mt6771.dtb] Error 2
make[1]: Leaving directory '/home/cosmo/KERNEL_OUT'
make: *** [Makefile:152: sub-make] Error 2

Fix:
This fix involves a native compile of the device tree compiler and associated libraries, since the version in the kernel is compiled for X86-64, but the Cosmo needs AArch64:
Code: [Select]
readelf -h scripts/dtc/dtc_overlay
Get the source code for the device tree compiler:
Code: [Select]
cd
git clone https://git.kernel.org/pub/scm/utils/dtc/dtc.git

Download some needed dependencies:
Code: [Select]
sudo apt install pkg-config
Compile:
Code: [Select]
cd dtc
sudo make install PREFIX=/usr
make check
cp dtc /home/cosmo/cosmo-linux-kernel-4.4/scripts/dtc/dtc_overlay
cd

Also need a native compile of ufdt and associated libraries, since the version in the kernel is compiled for X86-64, but the Cosmo needs AArch64 (ie. similar problem as last error):
Code: [Select]
readelf -h /home/cosmo/cosmo-linux-kernel-4.4/scripts/dtc/ufdt_apply_overlay
Get libufdt source code:
Code: [Select]
cd
mkdir libufdt
cd libufdt
https://android.googlesource.com/platform/system/libufdt/+/refs/heads/master(use your favorite web browser, select tgz and save master.tar.gz in libufdt directory)
Code: [Select]
tar -xvf master.tar.gz
Compile the libufdt_sysdeps library:
Code: [Select]
cd sysdeps
gcc -shared libufdt_sysdeps_posix.c -Iinclude -fPIC -o libufdt_sysdeps.so
sudo cp libufdt_sysdeps.so /usr/lib

Compile the libufdt library:
Code: [Select]
cd ..
gcc -c ufdt_convert.c ufdt_node.c ufdt_node_pool.c ufdt_overlay.c ufdt_prop_dict.c -Iinclude -Isysdeps/include -fPIC
gcc -shared ufdt_convert.o ufdt_node.o ufdt_node_pool.o ufdt_overlay.o ufdt_prop_dict.o -lfdt -o libufdt.so
sudo cp libufdt.so /usr/lib

Compile the driver program:
Code: [Select]
cd tests/src
gcc ufdt_overlay_test_app.c util.c -I../../include -I../../sysdeps/include -lufdt -lufdt_sysdeps -o ufdt_apply_overlay
cp ufdt_apply_overlay /home/cosmo/cosmo-linux-kernel-4.4/scripts/dtc
cd

Back to the main compile task:
Code: [Select]
cd cosmo/cosmo-linux-kernel-4.4
make  O=../KERNEL_OUT ARCH=arm64

This results in a clean compile (after ~5min):
Code: [Select]
mtk-Kbuild CONFIG_MALI_PLATFORM_THIRDPARTY_NAME := "mt6771"
*GPU defined ENABLE_MTK_DEBUG
imgsensor drv by common ../common/v1_1/s5k2x7_mipi_raw/ ../common/v1_1/sp5509_mipi_raw/ ../common/v1_1/gc5035_mipi_raw/ ../common/v1_1/gc5025_mipi_raw/
imgsensor drv by platform
build trng...
  Building modules, stage 2.
  MODPOST 26 modules
  CC      crypto/md4.mod.o
  LD [M]  crypto/md4.ko
  CC      crypto/xor.mod.o
  LD [M]  crypto/xor.ko
  CC      drivers/misc/mediatek/connectivity/fmradio/fmradio_drv.mod.o
  LD [M]  drivers/misc/mediatek/connectivity/fmradio/fmradio_drv.ko
  CC      drivers/misc/mediatek/connectivity/gps/gps_drv.mod.o
  LD [M]  drivers/misc/mediatek/connectivity/gps/gps_drv.ko
  CC      drivers/net/macvlan.mod.o
  LD [M]  drivers/net/macvlan.ko
  CC      drivers/net/usb/r8152.mod.o
  LD [M]  drivers/net/usb/r8152.ko
  CC      drivers/net/usb/rtl8150.mod.o
  LD [M]  drivers/net/usb/rtl8150.ko
  CC      fs/btrfs/btrfs.mod.o
  LD [M]  fs/btrfs/btrfs.ko
  CC      fs/cifs/cifs.mod.o
  LD [M]  fs/cifs/cifs.ko
  CC      fs/ecryptfs/ecryptfs.mod.o
  LD [M]  fs/ecryptfs/ecryptfs.ko
  CC      fs/fscache/fscache.mod.o
  LD [M]  fs/fscache/fscache.ko
  CC      fs/lockd/lockd.mod.o
  LD [M]  fs/lockd/lockd.ko
  CC      fs/nfs/nfs.mod.o
  LD [M]  fs/nfs/nfs.ko
  CC      fs/nfs/nfsv2.mod.o
  LD [M]  fs/nfs/nfsv2.ko
  CC      fs/nfs/nfsv3.mod.o
  LD [M]  fs/nfs/nfsv3.ko
  CC      fs/nfs/nfsv4.mod.o
  LD [M]  fs/nfs/nfsv4.ko
  CC      fs/nfs_common/grace.mod.o
  LD [M]  fs/nfs_common/grace.ko
  CC      fs/udf/udf.mod.o
  LD [M]  fs/udf/udf.ko
  CC      lib/crc-itu-t.mod.o
  LD [M]  lib/crc-itu-t.ko
  CC      lib/raid6/raid6_pq.mod.o
  LD [M]  lib/raid6/raid6_pq.ko
  CC      net/dns_resolver/dns_resolver.mod.o
  LD [M]  net/dns_resolver/dns_resolver.ko
  CC      net/ipv4/tcp_htcp.mod.o
  LD [M]  net/ipv4/tcp_htcp.ko
  CC      net/ipv4/tcp_westwood.mod.o
  LD [M]  net/ipv4/tcp_westwood.ko
  CC      net/sunrpc/auth_gss/auth_rpcgss.mod.o
  LD [M]  net/sunrpc/auth_gss/auth_rpcgss.ko
  CC      net/sunrpc/auth_gss/rpcsec_gss_krb5.mod.o
  LD [M]  net/sunrpc/auth_gss/rpcsec_gss_krb5.ko
  CC      net/sunrpc/sunrpc.mod.o
  LD [M]  net/sunrpc/sunrpc.ko
make[1]: Leaving directory '/home/cosmo/KERNEL_OUT'
« Last Edit: May 05, 2021, 08:24:58 pm by SL »
Nokia N900, Cosmo Communicator

Adam Boardman

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: On-device kernel compilation
« Reply #1 on: April 27, 2021, 12:01:08 pm »
We have a branch (packaging) which is now buildable on both a Debian 10 amd64(Desktop) with cross compilation and natively (arm64) on the device (in Gemini days there were two branches for this). Using the Debian configuration files as detailed on the wiki:
https://github.com/gemian/gemian/wiki/KernelCompilation#cosmo

You end up with a regular Debian installable package which gives the advantage of keeping you on the update tracks for upstream improvements. Ideally you'll be making your own kernels to test out new features that everyone wants and so after testing you'll be pushing the fixes up to share with everyone else.

For those that keen on building outside of the Debian packaging system you can review the commands in debian/rules to see what the steps are and pick out the bits you want.

SL

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: On-device kernel compilation
« Reply #2 on: April 29, 2021, 11:59:30 pm »
Followed your instructions on the wiki page for Kernel Compile, managed to compile, install and run the latest kernel from the created debian package, but still had to apply my fix for dtc and ufdt. For some reason on my set-up qemu did not trigger for dtc_overlay and ufdt_apply_overlay, even though I have qemu installed.

Thanks for the link to the wiki, that helped a bunch.
« Last Edit: April 30, 2021, 12:01:42 am by SL »
Nokia N900, Cosmo Communicator

Adam Boardman

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: On-device kernel compilation
« Reply #3 on: April 30, 2021, 05:43:12 pm »
If you check the Gotchas:
 * If the build fails 'scripts/dtc/dtc_overlay: Exec format error' due to wrong cpu arch check your running a kernel dated Dec 2020 or newer (uname -a) and installed the qemu build dependencies (qemu-user-binfmt).

I'd be interested to know if you still need those fixes now you've pulled in a kernel built with this fix: https://github.com/gemian/cosmo-linux-kernel-4.4/commit/fc4253769f854b888b5515b1d316593dbc3d3df9

The date suggested relates to Gemian build server built kernel releases (ie available via apt).

shuntcap

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
Re: On-device kernel compilation
« Reply #4 on: April 30, 2021, 08:33:05 pm »
Followed your instructions on the wiki page for Kernel Compile, managed to compile, install and run the latest kernel from the created debian package, but still had to apply my fix for dtc and ufdt. For some reason on my set-up qemu did not trigger for dtc_overlay and ufdt_apply_overlay, even though I have qemu installed.

Thanks for the link to the wiki, that helped a bunch.
SL, if your build still needs to run the bundled dtc_overlay, make sure these files exist:
Code: [Select]
/proc/sys/fs/binfmt_misc/qemu-x86_64
/usr/bin/qemu-x86_64

If they don't exist, qemu-user-binfmt and/or binfmt-support is not installed properly and x86_64 executables will not transparently run.

Adam, SL and I were discussing dtc_overlay outside of the forum and we couldn't figure out why dtc_overlay had to be bundled with the kernel source instead of using the compiled version of scripts/dtc/dtc.  Can you elaborate on the differences between the built dtc and the bundled dtc_overlay (and ufdt_apply_overlay)?

Adam Boardman

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: On-device kernel compilation
« Reply #5 on: May 01, 2021, 06:00:38 am »
Sorry I've not looked into the dtc stuff beyond fixing the errors I encounter when trying to get the kernel to build.

shuntcap

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
Re: On-device kernel compilation
« Reply #6 on: May 04, 2021, 12:44:39 am »
Sorry I've not looked into the dtc stuff beyond fixing the errors I encounter when trying to get the kernel to build.
That's interesting... this would seem to suggest that the x86_64 dtc_overlay and ufdt_apply_overlay binaries are supplied by MediaTek.  Looking at scripts/drvgen/drvgen.mk confirms this:
"Copyright (C) 2016 MediaTek Inc."

This "drvgen" isn't in any mainline kernel, it's from MediaTek for their kernels.

So if anyone wants to build as pristine a kernel as possible on-device, using qemu_binfmt appears to be the best way.  But if SL's method of recompiling ufdt_apply_overlay works, great!  By the way, dtc_overlay doesn't need to be recompiled.  The "dtc" binary is built by the kernel build and is in scripts/dtc.  scripts/Makefile.lib was modified from stock to call dtc_overlay instead of dtc, so either changing scripts/Makefile.lib from dtc_overlay to dtc or just copying scripts/dtc/dtc to scripts/dtc/dtc_overlay should work if you're determined to build the kernel on the Cosmo.

SL

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: On-device kernel compilation
« Reply #7 on: May 04, 2021, 10:19:04 pm »

SL, if your build still needs to run the bundled dtc_overlay, make sure these files exist:
Code: [Select]
/proc/sys/fs/binfmt_misc/qemu-x86_64
/usr/bin/qemu-x86_64

If they don't exist, qemu-user-binfmt and/or binfmt-support is not installed properly and x86_64 executables will not transparently run.

Confirmed, they exist.

I think I will need to install v4 of the Cosmo Linux Debian first (https://support.planetcom.co.uk/index.php/Linux_for_Cosmo#Download_and_Install_Linux_firmware_v4_.28latest.29) and then report back.
Nokia N900, Cosmo Communicator

shuntcap

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
Re: On-device kernel compilation
« Reply #8 on: May 05, 2021, 01:21:17 am »

SL, if your build still needs to run the bundled dtc_overlay, make sure these files exist:
Code: [Select]
/proc/sys/fs/binfmt_misc/qemu-x86_64
/usr/bin/qemu-x86_64

If they don't exist, qemu-user-binfmt and/or binfmt-support is not installed properly and x86_64 executables will not transparently run.

Confirmed, they exist.

I think I will need to install v4 of the Cosmo Linux Debian first (https://support.planetcom.co.uk/index.php/Linux_for_Cosmo#Download_and_Install_Linux_firmware_v4_.28latest.29) and then report back.
I'm still using v3.  Did you try running dtc_overlay directly?  For example, cd into your kernel directory, then try "scripts/dtc/dtc_overlay -v" and see if it prints "Version: DTC 1.4.2-Android-build" or just complains with a "cannot execute binary file" error.

SL

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: On-device kernel compilation
« Reply #9 on: May 05, 2021, 05:28:25 pm »
I was still getting the binary execution error. Have switched over to v4 now, so am not able to provide actual output from the device quickly. Thanks for staying engaged on this topic.
Nokia N900, Cosmo Communicator

kmd

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: On-device kernel compilation
« Reply #10 on: May 28, 2021, 01:08:45 pm »
hello i am tryingto compile it on cosmo comunictaor linux V4 fresh install all thesteps followed n errors the final make file for the final output getting 2 errors
1 helio-dvfsrx.h no such file
2. error 2 drivers/devfreq

/drvgen/drvgen.mk:61: target 'arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dtb' given more than once in the same rule
scripts/drvgen/drvgen.mk:61: target 'arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dtb' given more than once in the same rule
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
make[1]: 'include/generated/vdso-offsets.h' is up to date.
  CHK     scripts/mod/devicetable-offsets.h
  CHK     include/generated/compile.h
  CHK     kernel/config_data.h
  CC      drivers/devfreq/helio-dvfsrc.o
drivers/devfreq/helio-dvfsrc.c:27:10: fatal error: helio-dvfsrc.h: No such file or directory
 #include <helio-dvfsrc.h>
          ^~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.build:278: drivers/devfreq/helio-dvfsrc.o] Error 1
make[1]: *** [scripts/Makefile.build:484: drivers/devfreq] Error 2
make: *** [Makefile:1008: drivers] Error 2

cam1965

  • Sr. Member
  • ****
  • Posts: 331
    • View Profile
    • http://
Re: On-device kernel compilation
« Reply #11 on: May 28, 2021, 07:12:48 pm »
hello i am tryingto compile it on cosmo comunictaor linux V4 fresh install all thesteps followed n errors the final make file for the final output getting 2 errors
1 helio-dvfsrx.h no such file
2. error 2 drivers/devfreq

/drvgen/drvgen.mk:61: target 'arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dtb' given more than once in the same rule
scripts/drvgen/drvgen.mk:61: target 'arch/arm64/boot/dts/mediatek/k71v1_64_bsp.dtb' given more than once in the same rule
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
make[1]: 'include/generated/vdso-offsets.h' is up to date.
  CHK     scripts/mod/devicetable-offsets.h
  CHK     include/generated/compile.h
  CHK     kernel/config_data.h
  CC      drivers/devfreq/helio-dvfsrc.o
drivers/devfreq/helio-dvfsrc.c:27:10: fatal error: helio-dvfsrc.h: No such file or directory
 #include <helio-dvfsrc.h>
          ^~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.build:278: drivers/devfreq/helio-dvfsrc.o] Error 1
make[1]: *** [scripts/Makefile.build:484: drivers/devfreq] Error 2
make: *** [Makefile:1008: drivers] Error 2

First :

git clone https://github.com/gemian/cosmo-linux-kernel-4.4.git
cd cosmo-linux-kernel-4.4
git checkout packaging

go to home directory ( type cd enter )


So make a compressed backup of the kernel
tar cjvf kernel.tar.bz2 cosmo-linux-kernel-4.4

Enter to the source
cd  cosmo-linux-kernel-4.4

cp arch/arm64/configs/k71v1_64_bsp_defconfig ./.config

Make menuconfig ( install the packages to compile  in order to menuconfig works )

Make your changes.

copy .config file to some location ( cp .config /home/cosmo/confignew )

remove the directory rm -rf cosmo-linux-kernel-4.4

extract the kernel backup

tar jxvf kernel.tar.bz2

Enter the source ( cd cosmo-linux-kernel-4.4 )

copy the confignew file to arch/arm64/configs/k71v1_64_bsp_defconfig ( cp /home/cosmo/confignew arch/arm64/configs/k71v1_64_bsp_defconfig )

so do : debuild -b -uc -us

after the process : sudo dpkg -i ../cosmo-linux-kernel*deb

Good luck.
CAM1965

SL

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: On-device kernel compilation
« Reply #12 on: June 03, 2021, 10:48:21 am »
cam1965's post should work for you, make sure the sources are properly downloaded.

When I do a search on a successful compile run following a fresh install of v4 cosmo linux kernel  and kernel sources i get the following (ie. no issue with a missing helio-dvfsrc):

Code: [Select]
cosmo@cosmocom:~$ cat cosmo-linux-kernel_0.1_arm64.build | grep -i helio
  CC      drivers/devfreq/helio-dvfsrc.o
  CC      drivers/devfreq/helio-dvfsrc-sysfs.o
  CC      drivers/devfreq/helio-dvfsrc-mt6771.o
  CC      drivers/devfreq/helio-dvfsrc-opp-mt6771.o
cosmo@cosmocom:~$
Nokia N900, Cosmo Communicator