Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error building Android kernel: "multiple target patterns"

I attempted to build a fresh kernel for Nexus 5X following Google's instructions on this page

  • Build system: Ubuntu 14.04 x86_64
  • Target system: MTC19T/bullhead (Actually any marshmallow version on 5X)
  • Toolchain: android-6.0.1_r25/prebuilts/gcc/linux-x86/aarch64/

Exact sequence of commands I executed are:

$ git clone https://android.googlesource.com/kernel/msm
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-android-
$ cd msm
$ git checkout -b android-msm-bullhead-3.10-marshmallow-mr1 origin/android-msm-bullhead-3.10-marshmallow-mr1
$ make bullhead_defconfig
$ make

I am greeted with following error after last command:

Makefile:796: *** multiple target patterns.  Stop.

Investigations:

Now line 796 in makefile is:

vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE

and other relevant lines are:

vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN)

export KBUILD_VMLINUX_INIT := $(head-y) $(init-y)
export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y)
export KBUILD_LDS          := arch/$(SRCARCH)/kernel/vmlinux.lds

I found that if I remove $(libs-y) from $(KBUILD_VMLINUX_MAIN) this error disappears, and build continues for some time. I am sure I wil find some or other issue later, so I decided to debug further.

Disclaimer: Rest of this is a bit gray area for me

$(libs-y) is defined as:

libs-y      := lib/
libs-y1     := $(patsubst %/, %/lib.a, $(libs-y))
libs-y2     := $(patsubst %/, %/built-in.o, $(libs-y))
libs-y      := $(libs-y1) $(libs-y2)

So I called scripts/link-vmlinux.sh with parameters lib/lib.a lib/built-in.o FORCE and am greeted with this error:

gps@gps-HP-ProBook-4540s:~/andsrc/kernel/msm$ ./scripts/link-vmlinux.sh lib/lib.a lib/built-in.o FORCE
trap: SIGHUP: bad trap

Since this output has :, this probably explains the original make error.

Now, disabling the line containing trap does not help, we get another error:

gps@gps-HP-ProBook-4540s:~/andsrc/kernel/msm$ ./scripts/link-vmlinux.sh lib/lib.a lib/built-in.o FORCE
  LD      vmlinux.o
./scripts/link-vmlinux.sh: 44: ./scripts/link-vmlinux.sh: -r: not found

I am not very sure what to try next. Any help is appreciated.

like image 623
GPS Avatar asked May 19 '16 08:05

GPS


3 Answers

Pretty old question, but I just had the same problem and I want to tell that the issue appears only if you've set CROSS_COMPILE incorrectly. No need to comment out trap, export explicitly LD and LDFLAGS or do other hacks.

Documentation is unclear in what CROSS_COMPILE means. CROSS_COMPILE must be the path-prefix of the pre-built tools i.e. if you did

cd /files/src
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6

Then, you have to export CROSS_COMPILE=/files/src/arm-eabi-4.8/bin/arm-eabi-, so ${CROSS_COMPILE}ld would mean /files/src/arm-eabi-4.8/bin/arm-eabi-ld

As far as I see you were exporting it exactly as documentation shows as CROSS_COMPILE=aarch64-linux-android-, which I guess is wrong path-prefix.

If you are building on ubuntu, consider installing gcc-aarch64-linux-gnu, gcc-arm-linux-gnueabi and setting CROSS_COMPILE to /usr/bin/aarch64-linux-gnu-

like image 130
Grief Avatar answered Nov 07 '22 00:11

Grief


I'm fixed CROSS_COMPILE variable to the valid path. But same error still there. Then i add

$(info VAR="$(vmlinux-deps)")

just before vmlinux call. And the issue become clear:

/usr/bin/aarch64-linux-gnu-gcc: No such file or directory Is your PATH set correctly?

I have installed g++ only, not gcc. Installing 'gcc' package solve the problem. On ubuntu:

sudo apt-get install gcc-aarch64-linux-gnu

like image 3
Dmitry Screwer Avatar answered Nov 07 '22 00:11

Dmitry Screwer


Lines 44 and 45 look something like this:

${LD} ${LDFLAGS} -r -o ${1} ${KBUILD_VMLINUX_INIT}  \
        --start-group ${KBUILD_VMLINUX_MAIN} --end-group

So what's happening is that $LD and $LDFLAGS are undefined which leaves the command to just be -r ..., and -r isn't a command on your system, hence the command not found.

Define $LD and $LDFLAGS then it will run whatever $LD is with the $LDFLAGS + the remainder of the other command.

If you still have problems, add a comment and I'll look into it further.

like image 2
jdek Avatar answered Nov 07 '22 00:11

jdek