3

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
user0193
  • 288
  • 1
  • 7
  • Is `/arch/mips/boot/tools/entry` executable? Did you try running it? – stark Dec 27 '20 at 01:41
  • well I simply made it executable by 'chmod +x entry' but it still doesnt work. Maybe the entry point itself is bad, so just wanna know what could be i seeking to troubleshoot? – user0193 Dec 27 '20 at 14:08
  • You ran entry and i gave the same error? – stark Dec 27 '20 at 14:39
  • 1
    Please, share the script that you are executing and which produces the output that you quoted. – Xypron Dec 28 '20 at 00:28
  • @stark i get `0x` only when I run `. entry`. Anyways I have updated compile instructions to reproduce the issue. Its a small kernel image so it would take only 2 mins or less – user0193 Dec 28 '20 at 21:28
  • @Xypron, good point. I have updated the question with compile instructions to reproduce the issue. Its really tiny linux kernel and compiles fast in couple of minutes. – user0193 Dec 28 '20 at 21:29
  • @stark entry must not be run as standalone executable. – gfdsal Dec 29 '20 at 14:04
  • @gfdsal Why is that? As long as you give it the correct arguments it should give the result. Most likely the arguments are the problem, since the script is simple – stark Dec 29 '20 at 14:41
  • @stark yes, thats what i meant, running it as standalone, just like what op did will not get the arguments as arguments are produced in compile time – gfdsal Dec 29 '20 at 14:46
  • 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 relative to `/`, i.e. the root directory, instead of where-ever your kernel source is actually stored. Try inserting some `echo 'KBUILD_SRC = ' $KBUILD_SRC` and `echo 'obj = ' $obj`commands just before the **mkimage** command in the `uImage:` section of **arch/mips/boot/Makefile** – sawdust Jan 08 '21 at 01:36

1 Answers1

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.

sawdust
  • 16,103
  • 3
  • 40
  • 50
  • This actually worked but im bit lost in the explanation (pardon me). Are you saying it didnot find the "correct path"? and why as you put it the `when the actual problem is that it is missing because the script never executed` , was **KBUILD_SRC** not finding the correct location? – user0193 Jan 08 '21 at 15:53
  • 1
    *"This actually worked"* -- Glad to help. Please see edits to my answer for a hopefully better explanation. You could also debug this further by inserting echo commands into the Makefiles; see my original comment to your question above. BTW I had read your question earlier, but because it involved MIPS, makefiles, and scripts I passed on it. Your polite request and the bounty got me to analyze it again, so your actions were effective! – sawdust Jan 08 '21 at 23:08
  • I am glad i got your attention. the kernel compiled perfectly after your edits and i was able to even boot into it on MIPS handheld! Thanks alot! – user0193 Jan 09 '21 at 14:28