1

I have a custom Linux kernel (link to the GitHub repo) for an SoC and I need to build it and run on the board.

1

The SoC is ARM based but I am compiling it on x86, so I've downloaded a cross compiler gcc version 6.2.0 (GCC) that the vendor provides.

2

I placed the cross-compiler directory into the /opt directory:

[user@valhalla /]$ tree -L 2 opt/
opt/
├── arm_tools_6.2.0_linux
│   ├── arm-none-eabi
│   ├── bin
│   ├── include
│   ├── lib
│   ├── lib64
│   ├── libexec
│   ├── local
│   └── share

3

Then I've downloaded the kernel from the GitHub repository:

[user@valhalla ~]$ git clone https://github.com/elvees/linux elvees-linux
[user@valhalla ~]$ cd elvees-linux

4

Chose a branch mcom02-4.4y:

[user@valhalla elvees-linux]$ git checkout mcom02-4.4y

5

Then I wrote the following build script:

#!/usr/bin/env bash

#------------------------------------------------------------------------------
# File: build.sh
# Author: eanmos
# E-mail: eanmos@ya.ru
# Usage:
#
#     $ ./build.sh
#
# Description:
#
# The scripts builds the kernel and outputs the zImage file.
#
# If the kernel configuration file .config was not found then
# the default config for the MCOM platform is used.
#
# By default the script looks for the toolchain in the
#
#     /opt/arm_tools_6.2.0_linux
#
# directory. You can set custom path using the $TOOLCHAIN_PATH
# variable:
#
#     $ TOOLCHAIN_PATH=tools ./build.sh
#------------------------------------------------------------------------------

#--------------------------------------
# Prepare the toolchain
#--------------------------------------

# If $TOOLCHAIN_PATH is not set, use the default value.
readonly TOOLCHAIN_DEFAULT_PATH="/opt/arm_tools_6.2.0_linux"
export TOOLCHAIN_PATH="${TOOLCHAIN_PATH:-$TOOLCHAIN_DEFAULT_PATH}"

if [ ! -d $TOOLCHAIN_PATH ]; then
    echo -e "ERROR: toolchain not found. Directory $TOOLCHAIN_PATH doesn't exist.\n"
    echo -e "By default the script looks for the toolchain in the\n"
    echo -e "\t/opt/arm_tools_6.2.0_linux\n"
    echo -e "directory. You can set custom path using the \$TOOLCHAIN_PATH"
    echo -e "variable:\n"
    echo -e "\tTOOLCHAIN_PATH=tools ./build.sh\n"
    echo -e "Toolchain can be found on the Elvees website:\n"
    echo -e "\tftp://ftp.elvees.com/1892VM14YA/Baremetal/Tools/"
    exit
fi

# Paths needed for the toolchain to run.
export PATH="$TOOLCHAIN_PATH/bin:$PATH"
export LD_LIBRARY_PATH="$TOOLCHAIN_PATH/local/lib:$LD_LIBRARY_PATH"

#--------------------------------------
# Set ARCH and CROSS_COMPILE variables
#--------------------------------------

export ARCH="arm"
export CROSS_COMPILE="arm-none-eabi-"

#--------------------------------------
# Create default MCOM config if the .config file doesn't exist
#--------------------------------------

if [ ! -f .config ]; then
    echo "WARNING: the kernel configuration file was not found. Use default MCOM-platform config."
    make mcom_defconfig
fi

#--------------------------------------
# Build the kernel
#--------------------------------------

# Run Make and pass to it number of host's CPUs for
# parallel building.
readonly HOST_NPROC="$(nproc)"
make -j$HOST_NPROC zImage

6

Then I am trying to build the kernel:

[user@valhalla elvees-linux]$ ./build.sh

but compilation fails:

WARNING: the kernel configuration file was not found. Use default MCOM-platform config.
  HOSTCC  scripts/basic/fixdep
  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
#
# configuration written to .config
#
scripts/kconfig/conf  --silentoldconfig Kconfig
  CHK     include/config/kernel.release
  WRAP    arch/arm/include/generated/asm/bitsperlong.h
  WRAP    arch/arm/include/generated/asm/cputime.h
  WRAP    arch/arm/include/generated/asm/current.h
  WRAP    arch/arm/include/generated/asm/errno.h
  WRAP    arch/arm/include/generated/asm/emergency-restart.h
  WRAP    arch/arm/include/generated/asm/ioctl.h
  WRAP    arch/arm/include/generated/asm/irq_regs.h
  WRAP    arch/arm/include/generated/asm/ipcbuf.h
  WRAP    arch/arm/include/generated/asm/exec.h
  WRAP    arch/arm/include/generated/asm/kdebug.h
  WRAP    arch/arm/include/generated/asm/local.h
  WRAP    arch/arm/include/generated/asm/mm-arch-hooks.h
  WRAP    arch/arm/include/generated/asm/msi.h
  WRAP    arch/arm/include/generated/asm/param.h
  WRAP    arch/arm/include/generated/asm/parport.h
  WRAP    arch/arm/include/generated/asm/msgbuf.h
  WRAP    arch/arm/include/generated/asm/poll.h
  WRAP    arch/arm/include/generated/asm/local64.h
  WRAP    arch/arm/include/generated/asm/preempt.h
  WRAP    arch/arm/include/generated/asm/resource.h
  WRAP    arch/arm/include/generated/asm/rwsem.h
  WRAP    arch/arm/include/generated/asm/seccomp.h
  WRAP    arch/arm/include/generated/asm/sections.h
  WRAP    arch/arm/include/generated/asm/segment.h
  WRAP    arch/arm/include/generated/asm/sembuf.h
  WRAP    arch/arm/include/generated/asm/serial.h
  WRAP    arch/arm/include/generated/asm/shmbuf.h
  WRAP    arch/arm/include/generated/asm/siginfo.h
  WRAP    arch/arm/include/generated/asm/simd.h
  WRAP    arch/arm/include/generated/asm/sizes.h
  WRAP    arch/arm/include/generated/asm/sockios.h
  WRAP    arch/arm/include/generated/asm/socket.h
  WRAP    arch/arm/include/generated/asm/termbits.h
  WRAP    arch/arm/include/generated/asm/termios.h
  WRAP    arch/arm/include/generated/asm/timex.h
  WRAP    arch/arm/include/generated/asm/trace_clock.h
  UPD     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  UPD     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  HOSTCC  scripts/basic/bin2c
  HOSTCC  scripts/dtc/dtc.o
  HOSTCC  scripts/dtc/flattree.o
  HOSTCC  scripts/genksyms/genksyms.o
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  CC      scripts/mod/devicetable-offsets.s
  MKELF   scripts/mod/elfconfig.h
  CHK     scripts/mod/devicetable-offsets.h
  UPD     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/sumversion.o
  HOSTCC  scripts/dtc/fstree.o
during GIMPLE pass: strlen
scripts/genksyms/genksyms.c: In function ‘main’:
scripts/genksyms/genksyms.c:760:5: internal compiler error: Illegal instruction
  760 | int main(int argc, char **argv)
      |     ^~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
make[2]: *** [scripts/Makefile.host:108: scripts/genksyms/genksyms.o] Error 1
make[1]: *** [scripts/Makefile.build:484: scripts/genksyms] Error 2
make[1]: *** Waiting for unfinished jobs....
  HOSTCC  scripts/dtc/data.o
  HOSTCC  scripts/dtc/livetree.o
  HOSTCC  scripts/mod/modpost.o
  HOSTCC  scripts/dtc/treesource.o
  HOSTCC  scripts/dtc/srcpos.o
  HOSTCC  scripts/dtc/checks.o
  HOSTCC  scripts/dtc/util.o
  HOSTCC  scripts/mod/file2alias.o
  SHIPPED scripts/dtc/dtc-lexer.lex.c
  Generating include/generated/mach-types.h
  SHIPPED scripts/dtc/dtc-parser.tab.h
  SHIPPED scripts/dtc/dtc-parser.tab.c
  HOSTCC  scripts/dtc/dtc-lexer.lex.o
  HOSTCC  scripts/dtc/dtc-parser.tab.o
  CC      kernel/bounds.s
  CHK     include/generated/timeconst.h
  UPD     include/generated/timeconst.h
  CHK     include/generated/bounds.h
  UPD     include/generated/bounds.h
  CC      arch/arm/kernel/asm-offsets.s
  CHK     include/generated/asm-offsets.h
  HOSTLD  scripts/dtc/dtc
  UPD     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [scripts/Makefile.host:100: scripts/dtc/dtc] Error 1
make[1]: *** [scripts/Makefile.build:484: scripts/dtc] Error 2
  HOSTLD  scripts/mod/modpost
make: *** [Makefile:554: scripts] Error 2
make: *** Waiting for unfinished jobs....

Host

I am building the kernel inside a VirtualBox virtual machine. It runs Arch Linux with the latest packages (July 24, 2020):

[user@valhalla ~]$ gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.1.0 (GCC)
[user@valhalla ~]$ ld -v

GNU ld (GNU Binutils) 2.34.0

There is a strange thing: I actually can successfully build the kernel on my personal laptop with Arch Linux where all the packages are restored to the April 9, 2020.

But I can't reproduce this behavior on any other machine with same Arch Linux, with all the packages restored to the same date.

In other words, even if I install Arch Linux on some machine, downgrade all the packages to April 9, 2020, I can't build the kernel.

I've tried to use some other distros: Lubuntu, CentOS, Xubuntu but it doesn't help.


What information should I give to figure out what is happening?

eanmos
  • 387
  • 1
  • 6
  • 15
  • That internal compiler error is probably a bug that should be reported to the gcc team. Did you try adding some memory (say 512M) to your VM? If so, is the compiler error the same? – xhienne Jul 24 '20 at 11:50
  • @xhienne, I've add a couple of gigabytes RAM (so it is 4096MiB now) to the VM, but the error is still the same. – eanmos Jul 24 '20 at 12:02
  • Changes.txt says it wants gcc 3.2 to build this kernel. https://github.com/elvees/linux/blob/mcom02-4.4.y/Documentation/Changes – stark Jul 24 '20 at 14:34
  • It may be worth merging the latest linux-4.4.y stable in case there were any fixes needed for GCC 10 host compiler. – Ian Abbott Jul 24 '20 at 16:27
  • 2
    I managed to reproduce the error on a Debian "testing" system. Merging the latest linux-4.4.y stable branch didn't help. However, it built using Debian's gnu-arm-linux-gnueabihf toolchain (with `ARCH=arm` and `CROSS_COMPILE=arm-linux-gnueabihf-`), so I guess something in your toolchain is messing with the host gcc. – Ian Abbott Jul 24 '20 at 17:11
  • @IanAbbott, thank you very much for the respond! I've tried to use `arm-linux-gnueabihf-gcc` on Ubuntu 20.04 LTS and it works. Can you post an answer? I'll accept it. – eanmos Jul 27 '20 at 09:01
  • 1
    I suspect the vendor-provided gcc was built to use some CPU features that were not enabled in your virtual machine. – Nate Eldredge May 26 '21 at 01:02

1 Answers1

1

You need to apply this patch to your kernel tree: https://github.com/Tomoms/android_kernel_oppo_msm8974/commit/11647f99b4de6bc460e106e876f72fc7af3e54a6