Skip to content

Commit 5fc9484

Browse files
paulburtonralfbaechle
authored andcommitted
MIPS: Set ISA bit in entry-y for microMIPS kernels
When building a kernel for the microMIPS ISA, ensure that the ISA bit (ie. bit 0) in the entry address is set. Otherwise we may include an entry address in images which bootloaders will jump to as MIPS32 code. I originally tried using "objdump -f" to obtain the entry address, which works for microMIPS but it always outputs a 32 bit address for a 32 bit ELF whilst nm will sign extend to 64 bit. That matters for systems where we might want to run a MIPS32 kernel on a MIPS64 CPU & load it with a MIPS64 bootloader, which would then jump to a non-canonical (non-sign-extended) address. This works in all cases as it only changes the behaviour for microMIPS kernels, but isn't the prettiest solution. A possible alternative would be to write a custom tool to just extract, sign extend & print the entry point of an ELF executable. I'm open to feedback if that would be preferred. Signed-off-by: Paul Burton <[email protected]> Cc: [email protected] Patchwork: https://patchwork.linux-mips.org/patch/16950/ Signed-off-by: Ralf Baechle <[email protected]>
1 parent 527f102 commit 5fc9484

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

arch/mips/Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,21 @@ include arch/mips/Kbuild.platforms
243243
ifdef CONFIG_PHYSICAL_START
244244
load-y = $(CONFIG_PHYSICAL_START)
245245
endif
246-
entry-y = 0x$(shell $(NM) vmlinux 2>/dev/null \
246+
247+
entry-noisa-y = 0x$(shell $(NM) vmlinux 2>/dev/null \
247248
| grep "\bkernel_entry\b" | cut -f1 -d \ )
249+
ifdef CONFIG_CPU_MICROMIPS
250+
#
251+
# Set the ISA bit, since the kernel_entry symbol in the ELF will have it
252+
# clear which would lead to images containing addresses which bootloaders may
253+
# jump to as MIPS32 code.
254+
#
255+
entry-y = $(patsubst %0,%1,$(patsubst %2,%3,$(patsubst %4,%5, \
256+
$(patsubst %6,%7,$(patsubst %8,%9,$(patsubst %a,%b, \
257+
$(patsubst %c,%d,$(patsubst %e,%f,$(entry-noisa-y)))))))))
258+
else
259+
entry-y = $(entry-noisa-y)
260+
endif
248261

249262
cflags-y += -I$(srctree)/arch/mips/include/asm/mach-generic
250263
drivers-$(CONFIG_PCI) += arch/mips/pci/

0 commit comments

Comments
 (0)