Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 549e8152 authored by Paul Mackerras's avatar Paul Mackerras
Browse files

powerpc: Make the 64-bit kernel as a position-independent executable



This implements CONFIG_RELOCATABLE for 64-bit by making the kernel as
a position-independent executable (PIE) when it is set.  This involves
processing the dynamic relocations in the image in the early stages of
booting, even if the kernel is being run at the address it is linked at,
since the linker does not necessarily fill in words in the image for
which there are dynamic relocations.  (In fact the linker does fill in
such words for 64-bit executables, though not for 32-bit executables,
so in principle we could avoid calling relocate() entirely when we're
running a 64-bit kernel at the linked address.)

The dynamic relocations are processed by a new function relocate(addr),
where the addr parameter is the virtual address where the image will be
run.  In fact we call it twice; once before calling prom_init, and again
when starting the main kernel.  This means that reloc_offset() returns
0 in prom_init (since it has been relocated to the address it is running
at), which necessitated a few adjustments.

This also changes __va and __pa to use an equivalent definition that is
simpler.  With the relocatable kernel, PAGE_OFFSET and MEMORY_START are
constants (for 64-bit) whereas PHYSICAL_START is a variable (and
KERNELBASE ideally should be too, but isn't yet).

With this, relocatable kernels still copy themselves down to physical
address 0 and run there.

Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent e31aa453
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -806,6 +806,19 @@ config PIN_TLB
endmenu

if PPC64
config RELOCATABLE
	bool "Build a relocatable kernel"
	help
	  This builds a kernel image that is capable of running anywhere
	  in the RMA (real memory area) at any 16k-aligned base address.
	  The kernel is linked as a position-independent executable (PIE)
	  and contains dynamic relocations which are processed early
	  in the bootup process.

	  One use is for the kexec on panic case where the recovery kernel
	  must live at a different physical address than the primary
	  kernel.

config PAGE_OFFSET
	hex
	default "0xc000000000000000"
+3 −1
Original line number Diff line number Diff line
@@ -63,7 +63,9 @@ override CC += -m$(CONFIG_WORD_SIZE)
override AR	:= GNUTARGET=elf$(CONFIG_WORD_SIZE)-powerpc $(AR)
endif

LDFLAGS_vmlinux	:= -Bstatic
LDFLAGS_vmlinux-yy := -Bstatic
LDFLAGS_vmlinux-$(CONFIG_PPC64)$(CONFIG_RELOCATABLE) := -pie
LDFLAGS_vmlinux	:= $(LDFLAGS_vmlinux-yy)

CFLAGS-$(CONFIG_PPC64)	:= -mminimal-toc -mtraceback=none  -mcall-aixdesc
CFLAGS-$(CONFIG_PPC32)	:= -ffixed-r2 -mmultiple
+3 −0
Original line number Diff line number Diff line
@@ -310,8 +310,11 @@ $(obj)/dtbImage.%: vmlinux $(wrapperbits) $(obj)/%.dtb
$(obj)/vmlinux.strip: vmlinux
	$(STRIP) -s -R .comment $< -o $@

# The iseries hypervisor won't take an ET_DYN executable, so this
# changes the type (byte 17) in the file to ET_EXEC (2).
$(obj)/zImage.iseries: vmlinux
	$(STRIP) -s -R .comment $< -o $@
	printf "\x02" | dd of=$@ conv=notrunc bs=1 seek=17

$(obj)/uImage: vmlinux $(wrapperbits)
	$(call if_changed,wrap,uboot)
+4 −2
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ int parse_elf64(void *hdr, struct elf_info *info)
	      elf64->e_ident[EI_MAG3]  == ELFMAG3	&&
	      elf64->e_ident[EI_CLASS] == ELFCLASS64	&&
	      elf64->e_ident[EI_DATA]  == ELFDATA2MSB	&&
	      elf64->e_type            == ET_EXEC	&&
	      (elf64->e_type            == ET_EXEC ||
	       elf64->e_type            == ET_DYN)	&&
	      elf64->e_machine         == EM_PPC64))
		return 0;

@@ -58,7 +59,8 @@ int parse_elf32(void *hdr, struct elf_info *info)
	      elf32->e_ident[EI_MAG3]  == ELFMAG3	&&
	      elf32->e_ident[EI_CLASS] == ELFCLASS32	&&
	      elf32->e_ident[EI_DATA]  == ELFDATA2MSB	&&
	      elf32->e_type            == ET_EXEC	&&
	      (elf32->e_type            == ET_EXEC ||
	       elf32->e_type            == ET_DYN)      &&
	      elf32->e_machine         == EM_PPC))
		return 0;

+1 −1
Original line number Diff line number Diff line
@@ -437,7 +437,7 @@ typedef struct {
	})
#endif /* 1 */

/* This is only valid for addresses >= KERNELBASE */
/* This is only valid for addresses >= PAGE_OFFSET */
static inline unsigned long get_kernel_vsid(unsigned long ea, int ssize)
{
	if (ssize == MMU_SEGSIZE_256M)
Loading