Relocatable kernel for ppc44x
Hi,
John mentioned in his email that we have some patches. I am also sending them [patch 1/7-6/7]. It is support for non zero boot address for ppc44x.
Patch 7/7 is relocatable support for ppc44x.
All patches are against 2.6.31.13 but it shouldn't be big problem to port them to the latest and greatest.
We are using 256MB alignment which is fine for our purposes. But I think it could be simple to change it to any different style.
I have tested it on QEMU system emulator with u-boot.
I have used its with vmlinux.bin.gz and DTB. Not sure about your configuration but the best is not to relocate DTB. Address of DTB should be in 256MB boundary to be able to access it in the first pinned 256MB tlb. I haven't tested any other configuration but I have tried not to break anyone. Not sure if I can use r25, r26 and r21 (I need two regs for storing temp values). I look forward on your recommendation.
The idea of this patch is to find out where the kernel runs. Pinned 256MB in asm - setup memstart_addr and kernstart_addr in ASM and not to break generic PPC code. And also setup TLB for larger memories in mmu_mapin_ram. Have tested system till 768MB.
Thanks for your comments,
Michal
P.S.: Sorry for faults in PPC asm - I am not PPC expert.
RFC PATCH 1/7 powerpc: ppc440 remove zero physical memory base assumption
From: John Williams <[email protected]>
The macro PHYSICAL_START is available in this context, currently always with the value zero. However, that will change in a future patchset.
For now, just remove the zero physical address start assumption in head_44x.S where we setup the initial TLB, and in the later MMU setup where we map in the remainder of low mem if required.
--- arch/powerpc/kernel/head_44x.S | 5 +++-- arch/powerpc/mm/44x_mmu.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/kernel/head_44x.S +3 -2
@@ -135,8 +135,9 @@ skpinv: addi r4,r4,1 /* Increment */ lis r3,PAGE_OFFSET@h ori r3,r3,PAGE_OFFSET@l - /* Kernel is at the base of RAM */ - li r4, 0 /* Load the kernel physical address */ + /* Kernel is at PHYSICAL_START */ + lis r4,PHYSICAL_START@h + ori r4,r4,PHYSICAL_START@l /* Load the kernel PID = 0 */ li r0,0
arch/powerpc/mm/44x_mmu.c +1 -1
@@ -94,7 +94,7 @@ unsigned long __init mmu_mapin_ram(void)/* Pin in enough TLBs to cover any lowmem not covered by the * initial 256M mapping established in head_44x.S */ -for (addr =PPC_PIN_SIZE ; addr < lowmem_end_addr; +for (addr =PHYSICAL_START +PPC_PIN_SIZE ; addr < lowmem_end_addr; addr +=PPC_PIN_SIZE )ppc44x_pin_tlb (addr +PAGE_OFFSET , addr);
Signature · 1 line
1.5.5.6
RFC PATCH 2/7 powerpc: Permit non-zero physical start address for PPC44x
From: John Williams <[email protected]>
The initial TLB entry is 256M, meaning that the physical base address must be 256M aligned.
--- arch/powerpc/Kconfig | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
arch/powerpc/Kconfig +2 -1
@@ -845,7 +845,7 @@ config KERNEL_START config PHYSICAL_START_BOOL bool "Set physical address where the kernel is loaded" - depends on ADVANCED_OPTIONS && FLATMEM && FSL_BOOKE + depends on ADVANCED_OPTIONS && FLATMEM && (FSL_BOOKE || 44x) help This gives the physical address where the kernel is loaded.
@@ -858,6 +858,7 @@ config PHYSICAL_START config PHYSICAL_ALIGN hex + default "0x10000000" if 44x default "0x04000000" if FSL_BOOKE help This value puts the alignment restrictions on physical address
Signature · 1 line
1.5.5.6
RFC PATCH 4/7 powerpc: Let simpleboot function with non zero-based memory maps
In reply to Michal SimekFrom: John Williams <[email protected]>
It is unnecessarily restrictive to fatal() if there is physical memory at a non-zero base address.
--- arch/powerpc/boot/simpleboot.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
arch/powerpc/boot/simpleboot.c +0 -5
@@ -56,11 +56,6 @@ void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,if (size < (*na+*ns) *sizeof (u32))fatal ("cannot get memory range\n" ); -/* Only interested in memory based at 0 */ -for (i =0 ; i < *na; i++) -if (*reg++ !=0 ) -fatal ("Memory range is not based at address 0\n" ); -/* get the memsize and trucate it to under 4G on 32 bit machines */ memsize64 =0 ;for (i =0 ; i < *ns; i++)
Signature · 1 line
1.5.5.6
RFC PATCH 5/7 powerpc: Consider a non-zero boot address when computing the bootwrapper start
From: John Williams <[email protected]>
There's no fundamental reason the bootwrapper can't boot off a non-zero base, we just need to make sure we account for it in the link.
Do this by adding the (up-aligned) kernel size to membase, and using that as the link address.
--- arch/powerpc/boot/wrapper | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
arch/powerpc/boot/wrapper +9 -5
@@ -139,9 +139,16 @@ tmp=$tmpdir/zImage.$$.o ksection=.kernel:vmlinux.strip isection=.kernel:initrd -# default auto-calculate link_address to make room for the kernel +# physical offset of kernel image +membase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'` + +# auto-calculate link_address to make room for the kernel # round up kernel image size to nearest megabyte -link_address=`${CROSS}size -x ${kernel} | grep ${kernel} | awk '{printf("0x%08x", and($4 + 0x0fffff, 0xfffe0000))}'` + +# don't forget to add membase for non-zero kernel boot +membase_dec=`printf "%d" $membase` + +link_address=`${CROSS}size -x ${kernel} | grep ${kernel} | awk -v membase=$membase_dec '{printf("0x%08x", membase + and($4 + 0x0fffff, 0xfffe0000))}'` case "$platform" in pseries)
@@ -259,9 +266,6 @@ if [ -n "$version" ]; then uboot_version="-n Linux-$version" fi -# physical offset of kernel image -membase=`${CROSS}objdump -p "$kernel" | grep -m 1 LOAD | awk '{print $7}'` - case "$platform" in uboot) rm -f "$ofile"
Signature · 1 line
1.5.5.6
RFC PATCH 7/7 powerpc: Support RELOCATABLE kernel for PPC44x
In reply to Michal SimekChanges:
- Find out address where kernel runs
- Create the first 256MB TLB from online detected address
Limitations:
- Kernel must be aligned to 256MB
Backport:
- Changes in page.h are backported from newer kernel version
mmu_mapin_ram function has to reflect offset in memory start. memstart_addr and kernstart_addr are setup directly from asm code to ensure that only ppc44x is affected.
--- arch/powerpc/Kconfig | 3 ++- arch/powerpc/include/asm/page.h | 7 ++++++- arch/powerpc/kernel/head_44x.S | 28 ++++++++++++++++++++++++++++ arch/powerpc/mm/44x_mmu.c | 6 +++++- 4 files changed, 41 insertions(+), 3 deletions(-)
arch/powerpc/Kconfig +2 -1
@@ -796,7 +796,8 @@ config LOWMEM_CAM_NUM config RELOCATABLE bool "Build a relocatable kernel (EXPERIMENTAL)" - depends on EXPERIMENTAL && ADVANCED_OPTIONS && FLATMEM && FSL_BOOKE + depends on EXPERIMENTAL && ADVANCED_OPTIONS && FLATMEM + depends on FSL_BOOKE || (44x && !SMP) help This builds a kernel image that is capable of running at the location the kernel is loaded at (some alignment restrictions may
arch/powerpc/include/asm/page.h +6 -1
@@ -108,8 +108,13 @@ extern phys_addr_t kernstart_addr;#define pfn_to_kaddr (pfn) __va((pfn) << PAGE_SHIFT)#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) -#define __va (x) ((void *)((unsigned long)(x) + PAGE_OFFSET - MEMORY_START)) +#ifdef CONFIG_BOOKE +#define __va (x) ((void *)(unsigned long)((phys_addr_t)(x) - PHYSICAL_START + KERNELBASE)) +#define __pa (x) ((unsigned long)(x) + PHYSICAL_START - KERNELBASE) +#else +#define __va (x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - MEMORY_START))#define __pa (x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START) +#endif /* * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI,
arch/powerpc/kernel/head_44x.S +28 -0
@@ -59,6 +59,17 @@ _ENTRY(_start); * of abatron_pteptrs */ nop + +#ifdef CONFIG_RELOCATABLE + bl jump /* Find our address */ + nop +jump: mflr r25 /* Make it accessible */ + /* just for and */ + lis r26, 0xfffffff0@h + ori r26, r26, 0xfffffff0@l + and. r21, r25, r26 +#endif + /* * Save parameters we are passed */
@@ -135,9 +146,14 @@ skpinv: addi r4,r4,1 /* Increment */ lis r3,PAGE_OFFSET@h ori r3,r3,PAGE_OFFSET@l +#ifdef CONFIG_RELOCATABLE + /* load physical address where kernel runs */ + mr r4,r21 +#else /* Kernel is at PHYSICAL_START */ lis r4,PHYSICAL_START@h ori r4,r4,PHYSICAL_START@l +#endif /* Load the kernel PID = 0 */ li r0,0
@@ -258,6 +274,18 @@ skpinv: addi r4,r4,1 /* Increment */ mr r5,r29 mr r6,r28 mr r7,r27 + +#ifdef CONFIG_RELOCATABLE + /* save kernel and memory start */ + lis r25,kernstart_addr@h + ori r25,r25,kernstart_addr@l + stw r21,4(r25) + + lis r25,memstart_addr@h + ori r25,r25,memstart_addr@l + stw r21,4(r25) +#endif + bl machine_init bl MMU_init
arch/powerpc/mm/44x_mmu.c +5 -1
@@ -91,12 +91,16 @@ void __init MMU_init_hw(void)unsigned long __init mmu_mapin_ram (void ) {unsigned long addr; +unsigned long offset =0 ; +#if defined(CONFIG_RELOCATABLE ) + offset = memstart_addr; +#endif /* Pin in enough TLBs to cover any lowmem not covered by the * initial 256M mapping established in head_44x.S */ for (addr =PHYSICAL_START +PPC_PIN_SIZE ; addr < lowmem_end_addr; addr +=PPC_PIN_SIZE ) -ppc44x_pin_tlb (addr +PAGE_OFFSET , addr); +ppc44x_pin_tlb (addr +PAGE_OFFSET - offset, addr);return total_lowmem; }
Signature · 1 line
1.5.5.6
RFC PATCH 3/7 powerpc: simpleboot get load address from ELF instead of assuming zero
In reply to Michal SimekFrom: John Williams <[email protected]>
simpleboot current assumes that the physical load address is zero, even if the ELF payload has a non-zero paddr.
This is a simple fix that avoids a custom pltform_ops handler in this case.
--- arch/powerpc/boot/elf.h | 1 + arch/powerpc/boot/elf_util.c | 2 ++ arch/powerpc/boot/main.c | 1 + 3 files changed, 4 insertions(+), 0 deletions(-)
arch/powerpc/boot/elf.h +1 -0
@@ -150,6 +150,7 @@ struct elf_info {unsigned long loadsize;unsigned long memsize;unsigned long elfoffset; +unsigned long loadaddr; };int parse_elf64 (void *hdr,struct elf_info *info);int parse_elf32 (void *hdr,struct elf_info *info);
arch/powerpc/boot/elf_util.c +2 -0
@@ -43,6 +43,7 @@ int parse_elf64(void *hdr, struct elf_info *info) info->loadsize = (unsigned long )elf64ph->p_filesz; info->memsize = (unsigned long )elf64ph->p_memsz; info->elfoffset = (unsigned long )elf64ph->p_offset; + info->loadaddr = (unsigned long )elf64ph->p_paddr;return 1 ; }
@@ -74,5 +75,6 @@ int parse_elf32(void *hdr, struct elf_info *info) info->loadsize = elf32ph->p_filesz; info->memsize = elf32ph->p_memsz; info->elfoffset = elf32ph->p_offset; + info->loadaddr = elf32ph->p_paddr;return 1 ; }
arch/powerpc/boot/main.c +1 -0
@@ -56,6 +56,7 @@ static struct addr_range prep_kernel(void)if (platform_ops.vmlinux_alloc) { addr = platform_ops.vmlinux_alloc (ei.memsize); }else { + addr = ei.loadaddr;/* * Check if the kernel image (without bss) would overwrite the * bootwrapper. The device tree has been moved in fdt_init()
Signature · 1 line
1.5.5.6
RFC PATCH 6/7 powerpc: Update the default FIT image to use the correct load/boot addresses
In reply to Michal SimekFrom: John Williams <[email protected]>
The default kernel_fdt.its hard codes zero load/start addresses, but this may no longer be true.
As we copy the FIT tree descriptor, update these values based on the incoming ELF payload.
--- arch/powerpc/boot/wrapper | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
arch/powerpc/boot/wrapper +5 -1
@@ -281,7 +281,11 @@ uboot-fit) rm -f "$ofile" #[ "$vmz" != vmlinux.bin.gz ] && mv "$vmz" "vmlinux.bin.gz" mv "$dtb" "target.dtb" - cp arch/powerpc/boot/kernel_fdt.its . + # Check the ELF file for a non-zero load/entry address + membase=${membase:2:8} + sed -e "s/load = <.*$/load = <${membase}>;/g" \ + -e "s/entry = <.*$/entry = <${membase}>;/g" \ + arch/powerpc/boot/kernel_fdt.its > kernel_fdt.its mkimage -f kernel_fdt.its "$ofile" #rm kernet_fdt.its exit 0
Signature · 1 line
1.5.5.6
Re: [RFC PATCH 7/7] powerpc: Support RELOCATABLE kernel for PPC44x
In reply to Michal SimekQuoted 63 lines · Michal Simek
Changes:
- Find out address where kernel runs
- Create the first 256MB TLB from online detected addressLimitations:
- Kernel must be aligned to 256MBBackport:
- Changes inpage.hare backported from newer kernel version
mmu_mapin_ramfunction has to reflect offset in memory start.memstart_addrandkernstart_addrare setup directly from asm code to ensure that only ppc44x is affected.Signed-off-by Michal Simek<[email protected]>--- arch/powerpc/Kconfig | 3 ++- arch/powerpc/include/asm/page.h | 7 ++++++- arch/powerpc/kernel/head_44x.S | 28 ++++++++++++++++++++++++++++ arch/powerpc/mm/44x_mmu.c | 6 +++++- 4 files changed, 41 insertions(+), 3 deletions(-)arch/powerpc/Kconfig +2
-1@@ -796,7 +796,8 @@ config LOWMEM_CAM_NUM config RELOCATABLE bool "Build a relocatable kernel (EXPERIMENTAL)" - depends on EXPERIMENTAL&& ADVANCED_OPTIONS&& FLATMEM&& FSL_BOOKE + depends on EXPERIMENTAL&& ADVANCED_OPTIONS&& FLATMEM + depends on FSL_BOOKE || (44x&& !SMP) help This builds a kernel image that is capable of running at the location the kernel is loaded at (some alignment restrictions mayarch/powerpc/include/asm/page.h +6
-1@@ -108,8 +108,13 @@ extern phys_addr_t kernstart_addr;#define pfn_to_kaddr (pfn) __va((pfn)<< PAGE_SHIFT)#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr)>> PAGE_SHIFT) -#define __va (x) ((void *)((unsigned long)(x) + PAGE_OFFSET - MEMORY_START)) +#ifdef CONFIG_BOOKE +#define __va (x) ((void *)(unsigned long)((phys_addr_t)(x) - PHYSICAL_START + KERNELBASE)) +#define __pa (x) ((unsigned long)(x) + PHYSICAL_START - KERNELBASE) +#else +#define __va (x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - MEMORY_START))#define __pa (x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START) +#endif /* * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI, arch/powerpc/kernel/head_44x.S +0
-0@@ -59,6 +59,17 @@ _ENTRY(_start); * of abatron_pteptrs */ nop
arch/powerpc/kernel/head_44x.S _ENTRY(_start); · line 71
Quoted 10 lines
arch/powerpc/kernel/head_44x.S +10
-0+ +#ifdef CONFIG_RELOCATABLE + bl jump /* Find our address */ + nop +jump: mflr r25 /* Make it accessible */ + /* just for and */ + lis r26, 0xfffffff0@h + ori r26, r26, 0xfffffff0@l + and. r21, r25, r26 +#endif
Hmm. So we are assuming we are running from a 1:1 mapping at the entry. It is much more safe to read our tlb entry and use the RPN instead.
Quoted 12 lines
arch/powerpc/kernel/head_44x.S +5
-0+#ifdef CONFIG_RELOCATABLE + /* load physical address where kernel runs */ + mr r4,r21 +#else /* Kernel is at PHYSICAL_START */ lis r4,PHYSICAL_START@h ori r4,r4,PHYSICAL_START@l +#endif /* Load the kernel PID = 0 */ li r0,0
arch/powerpc/kernel/head_44x.S skpinv: addi r4,r4,1 /* Increment */ · line 282
Quoted 9 lines
arch/powerpc/kernel/head_44x.S +6
-0@@ -258,6 +274,18 @@ skpinv: addi r4,r4,1 /* Increment */ mr r5,r29 mr r6,r28 mr r7,r27 + +#ifdef CONFIG_RELOCATABLE + /* save kernel and memory start */ + lis r25,kernstart_addr@h + ori r25,r25,kernstart_addr@l + stw r21,4(r25)
1) You have to use ERPN value in the higher word of kernel_start_addr.
2) You have to account for the (KERNEL_BASE - PAGE_OFFSET) shift for kernel_start_addr.
arch/powerpc/kernel/head_44x.S skpinv: addi r4,r4,1 /* Increment */
Quoted 7 lines
arch/powerpc/kernel/head_44x.S +6
-0+ + lis r25,memstart_addr@h + ori r25,r25,memstart_addr@l + stw r21,4(r25) +#endif +
Suzuki