Linux compilation | Invalid entrypoint

被刻印的时光 ゝ 提交于 2021-01-20 07:10:22

问题


I am compiling a linux kernel using mipsel toolchain.

Everything works fine except at the very last point which states invalid entry point:

sh: 0: Can't open /arch/mips/boot/tools/entry
rm -f arch/mips/boot/vmlinux.bin.gz
gzip -9 arch/mips/boot/vmlinux.bin
mkimage -A mips -O linux -T kernel -C gzip \
    -a 0x80010000 -e  \
    -n 'Linux-2.6.31.3-g29b45174-dirty' \
    -d arch/mips/boot/vmlinux.bin.gz arch/mips/boot/uImage
mkimage: invalid entry point -n

Now it mentioned sh: 0: Can't open /arch/mips/boot/tools/entry

So I checked that file and it has following:

#!/bin/sh

# grab the kernel_entry address from the vmlinux elf image
entry=`$1 $2  | grep kernel_entry`

fs=`echo $entry | grep ffffffff`  # check toolchain output

if [ -n "$fs" ]; then
    echo "0x"`$1 $2  | grep kernel_entry | cut -c9- | awk '{print $1}'`
else
    echo "0x"`$1 $2  | grep kernel_entry | cut -c1- | awk '{print $1}'`
fi

Now i understand something is generating the kernel entry point, but that generated entry point is invalid.

Question: What exactly generates kernel entry point and what potentially could be done to fix the issue?

The problem can be reproduced through following steps:


Compilation instructions:

$ cd
$ wget https://github.com/steward-fu/a320/releases/download/v1.0/mipsel-4.1.2-nopic.tar.bz2
$ tar xvf mipsel-4.1.2-nopic.tar.bz2
$ sudo mv mipsel-4.1.2-nopic /opt/rg300
$ export PATH=$PATH:/opt/rg300/bin
$ git clone https://github.com/rs-97-cfw/rs97-linux-kernel-NoNDA rg300_kernel
$ cd rg300_kernel
$ ARCH=mips make uImage

回答1:


This looks like a path issue caused by improper value of an environment variable.
The error message sh: 0: Can't open /arch/mips/boot/tools/entry is a full path relative to /, i.e. the root directory, instead of correctly specifying where your kernel source is actually stored, e.g. /home/your_username/rg300_kernel/arch/mips/boot/tools/entry.

Question: What exactly generates kernel entry point and what potentially could be done to fix the issue?

The issue is not the script itself, but rather how the script is invoked.
The directory path to where your kernel source resides is incorrectly specified.
Because the script is never found and executed, there is no value provided for the -e option for specifying the entry point.
Consequently the mkimage utility (incorrectly) complains of an "invalid entry point", but the actual problem is that no value was obtainable because the script was never located & executed.


The salient text for specifying the path of the script is:

$(KBUILD_SRC)/$(obj)/tools/entry

Your build output indicates that the obj environment variable is correctly set to arch/mips/boot.
But KBUILD_SRC seems to be incorrectly set to just / (the root directory) or is blank (???!!!) or is undefined, rather than something like /home/your_username/rg300_kernel or whatever the correct path is.

For a workaround you could try replacing variable KBUILD_SRC with srctree in arch/mips/boot/Makefile:

 uImage: $(VMLINUX) vmlinux.bin
     rm -f $(obj)/vmlinux.bin.gz
     gzip -9 $(obj)/vmlinux.bin
     mkimage -A mips -O linux -T kernel -C gzip \
-        -a $(LOADADDR) -e $(shell sh $(KBUILD_SRC)/$(obj)/tools/entry $(NM) $(VMLINUX) ) \
+        -a $(LOADADDR) -e $(shell sh $(srctree)/$(obj)/tools/entry $(NM) $(VMLINUX) ) \
         -n 'Linux-$(KERNELRELEASE)' \
         -d $(obj)/vmlinux.bin.gz $(obj)/uImage
     @echo '  Kernel: arch/mips/boot/$@ is ready' 

Variable srctree appears to be derived from KBUILD_SRC (in the top-level kernel Makefile), and using it as a substitution is really a WAG for a workaround.
Perhaps somewhere KBUILD_SRC is getting clobbered or not exported, but makefiles (and scripts) is not my expertise so I am unable to explain the underlying cause.



来源:https://stackoverflow.com/questions/65461633/linux-compilation-invalid-entrypoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!