Integrating relocatable kernel build with kernel build
Hi,
I am developing relocatable kernel for PPC64 and as part of it I need to integrate the build process with the kernel build itself. As of now I am using a separate makefile to build the relocatable kernel after building the kernel.
I have updated the Makefile(s) in arch/powerpc and arch/powerpc/boot to build the relocatable kernel image as part of kernel build.
With this approach I have two problems:
1. I need to explicitly specify the relocatable vmlinux target to build it. ie
make vmlinux.reloc
2. During build process, build is not able to build the vmlinux.reloc.lds linker script from the vmlinux.reloc.lds.S source file.
I am attaching the separate makefile to build the relocatable vmlinux, makefile diffs diff.Makefile (diff between original arch/powerpc/Makefile and arch/powerpc/Makefile for relocatable support), diff.Makefile.boot (diff between original arch/powerpc/boot/Makefile and arch/powerpc/boot/Makefile for relocatable support)
There are some differences when building the kernel using the separate makefile and as part of kernel build. Stand alone makefile creates final vmlinux.reloc image in the top level directory of kernel source directory and all intermediate binary files, linker script files are present in arch/powerpc while the kernel makefile creates vmlinux.reloc and intermediate files in arch/powerpc/boot and linker scripts are present in arch/powerpc/boot directory.
Please suggest me what needs to be done in the Makefile so that the relocatable vmlinux file is built automatically when I just run make and how to build the vmlinux.reloc.lds linker script.
Another feature I am looking is to generate the "relocatable vmlinux" image in the top directory of kernel source and the intermediate vmlinux file either in arch/powerpc/kernel or arch/powerpc/boot.
Note: As of now I am not considering the CONFIG_RELOCATABLE_PPC64 option to conditionally build the relocatable image. I am building the relocatable image unconditionally.
I have not subscribed to the kbuild mailing list, so please include me in to/cc while replying to this thread.
Thanks in advance.
Regards,
Mohan.
159c159
< BOOT_TARGETS = zImage zImage.initrd uImage zImage% dtbImage% treeImage.% cuImage.% simpleImage.%
---
Quoted 1 line
BOOT_TARGETS= zImage vmlinux.reloc zImage.initrd uImage zImage% dtbImage% treeImage.% cuImage.% simpleImage.%
20c20
< all: $(obj)/zImage
---
Quoted 1 line
all: $(obj)/zImage $(obj)/vmlinux.reloc
123c123
< hostprogs-y := addnote addRamDisk hack-coff mktree dtc
---
Quoted 1 line
hostprogs-y := addnote addRamDisk hack-coff mktree dtc relocs
128a129
Quoted 1 line
132c133
< wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree dtc) \
---
Quoted 1 line
wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree dtc relocs) \
134a136,164
Quoted 21 lines
targets += vmlinux.offsets vmlinux.bin vmlinux.bin.all vmlinux.reloc.elf vmlinux.reloc reloc_apply.o
OBJCOPYFLAGS_vmlinux.bin := -O binary -R .note -R .comment -S $(obj)/vmlinux.bin: vmlinux FORCE
$(call if_changed,objcopy)
quiet_cmd_relocbin= BUILD $@cmd_relocbin = cat $(filter-out FORCE,$^) > $@
quiet_cmd_relocs= RELOCS $@cmd_relocs = $(obj)/relocs $< > $@$(obj)/vmlinux.offsets: vmlinux $(obj)/relocs FORCE
$(call if_changed,relocs)$(obj)/vmlinux.bin.all: $(obj)/vmlinux.bin $(obj)/vmlinux.offsets FORCE
$(call if_changed,relocbin)$(obj)/vmlinux.reloc.lds: $(src)/vmlinux.reloc.lds.S FORCE
$(call if_changed_dep,cpp_lds_S)
Quoted 8 lines
LDFLAGS_vmlinux.reloc.elf := -T $(obj)/vmlinux.reloc.scr -r --format binary --oformat elf64-powerpc $(obj)/vmlinux.reloc.elf: $(obj)/vmlinux.bin.all FORCE
$(call if_changed,ld)LDFLAGS_vmlinux.reloc := -T $(obj)/vmlinux.reloc.lds $(obj)/vmlinux.reloc: $(obj)/reloc_apply.o $(obj)/vmlinux.reloc.elf FORCE
$(call if_changed,ld)
278c308
< targets += $(image-y) $(initrd-y)
---
Quoted 1 line
targets += $(image-y) $(initrd-y) vmlinux.reloc
#Makefile for building vmlinux with relocatable information and code.
all: vmlinux.reloc
obj := arch/powerpc
AS = as
LD = ld
CC = gcc
CPP = $(CC) -E
#build userspace relocs program to extract list of relocation offsets $(obj)/relocs : $(obj)/relocs.c
$(CC) $(obj)/relocs.c -o $(obj)/relocs
#extract list of relocation offsets $(obj)/vmlinux.reloc.offsets : vmlinux $(obj)/relocs
$(obj)/relocs vmlinux > $(obj)/vmlinux.reloc.offsets 2>/dev/null
#binary format of vmlinux
$(obj)/vmlinux.bin: vmlinux
objcopy -O binary -R .note -R .comment -S vmlinux $(obj)/vmlinux.bin
#concatenate vmlinux binary and relocation offset $(obj)/vmlinux.bin.all : $(obj)/vmlinux.bin $(obj)/vmlinux.reloc.offsets
cat $(obj)/vmlinux.bin $(obj)/vmlinux.reloc.offsets > $(obj)/vmlinux.bin.all
#generate elf headers for the concatenated vmlinux binary and relocation offset $(obj)/vmlinux.reloc.elf : $(obj)/vmlinux.reloc.scr $(obj)/vmlinux.bin.all
$(LD) -m elf64ppc -r --format binary --oformat elf64-powerpc -T $(obj)/vmlinux.reloc.scr $(obj)/vmlinux.bin.all -o $(obj)/vmlinux.reloc.elf
#build the wrapper around kernel $(obj)/kernel/reloc_apply.o : $(obj)/kernel/reloc_apply.S
$(CC) -m64 -Wp,-MD,arch/powerpc/kernel/.reloc_apply.o.d -nostdinc -isystem /usr/lib/gcc/powerpc64-suse-linux/4.1.2/include -D__KERNEL__ -Iinclude -include include/linux/autoconf.h -D__ASSEMBLY__ -Wa,-maltivec -c -o arch/powerpc/kernel/reloc_apply.o arch/powerpc/kernel/reloc_apply.S
#linker script
$(obj)/vmlinux.reloc.lds : $(obj)/vmlinux.reloc.lds.S
$(CC) -m64 -E -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Os -msoft-float -pipe -mminimal-toc -mtraceback=none -mcall-aixdesc -mtune=power4 -mno-altivec -mno-spe -funit-at-a-time -mno-string -Wa,-maltivec -fomit-frame-pointer -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign -Wp,-MD,arch/powerpc/.vmlinux.reloc.lds.d -nostdinc -isystem /usr/lib/gcc/powerpc64-suse-linux/4.1.2/include -D__KERNEL__ -Iinclude -include include/linux/autoconf.h -Upowerpc -P -C -Upowerpc -D__ASSEMBLY__ -o arch/powerpc/vmlinux.reloc.lds arch/powerpc/vmlinux.reloc.lds.S
#build the relocatable vmlinux from vmlinux and relocatable kernel wrapper vmlinux.reloc : $(obj)/vmlinux.reloc.lds $(obj)/vmlinux.reloc.elf $(obj)/kernel/reloc_apply.o
$(LD) -m elf64ppc -T $(obj)/vmlinux.reloc.lds $(obj)/vmlinux.reloc.elf $(obj)/kernel/reloc_apply.o -o vmlinux.reloc
Hi Mohan.
Quoted 7 lines · Mohan Kumar M
Hi,
I am developing relocatable kernel for PPC64 and as part of it I need to integrate the build process with the kernel build itself. As of now I am using a separate makefile to build the relocatable kernel after building the kernel.
Quoted 7 lines
I have updated the Makefile(s) in
arch/powerpcandarch/powerpc/bootto build the relocatable kernel image as part of kernel build.With this approach I have two problems:
1. I need to explicitly specify the relocatable vmlinux target to build it. ie
make vmlinux.reloc
Add the relevant target to the all: rule in arch/powerpc/Makefile
# Default to zImage, override when needed
all: zImage
And include support for the target in same file.
Quoted 2 lines
2. During build process, build is not able to build the
vmlinux.reloc.ldslinker script from thevmlinux.reloc.lds.Ssource file.
If you just add:
extra-y += vmlinux.reloc.lds
then it should happen automatically.
ee how all archs does it in arch/$ARCH/kernel/Makefile for vmlinx.lds
Quoted 6 lines
I am attaching the separate makefile to build the relocatable vmlinux, makefile diffs diff.Makefile (diff between original
arch/powerpc/Makefileandarch/powerpc/Makefilefor relocatable support), diff.Makefile.boot (diff between originalarch/powerpc/boot/Makefileandarch/powerpc/boot/Makefilefor relocatable support)
I did not look at it this time - lacking time. But tr to provide a single unified diff next time - that i at least remotely readable.
Quoted 3 lines
Another feature I am looking is to generate the "relocatable vmlinux" image in the top directory of kernel source and the intermediate vmlinux file either in
arch/powerpc/kernelorarch/powerpc/boot.
We no longer build arch specific targets in the top-level directory of the kernel src. We print out where to locate the build file.
See x86 as an example.
Quoted 2 lines
I have not subscribed to the kbuild mailing list, so please include me in to/cc while replying to this thread.
[We always do so here].
Sam
Hi Sam,
Thank you for the reply.
Quoted 8 lines · Sam Ravnborg
Hi Mohan.
Add the relevant target to the all: rule in
arch/powerpc/Makefile# Default to zImage, override when needed
all: zImage
I added vmlinux.reloc here and now by default vmlinux.reloc is also built.
Quoted 8 lines
And include support for the target in same file.
Quoted 1 line
2. During build process, build is not able to build the
vmlinux.reloc.ldslinker script from thevmlinux.reloc.lds.Ssource file.If you just add:
extra-y +=vmlinux.reloc.lds
After including the above entry, make builds the linker script.
Quoted 5 lines
then it should happen automatically.
ee how all archs does it inarch/$ARCH/kernel/Makefileforvmlinx.lds
Quoted 8 lines
I did not look at it this time - lacking time. But tr to provide a single unified diff next time - that i at least remotely readable.
Quoted 1 line
Another feature I am looking is to generate the "relocatable vmlinux" image in the top directory of kernel source and the intermediate vmlinux file either in
arch/powerpc/kernelorarch/powerpc/boot.We no longer build arch specific targets in the top-level directory of the kernel src. We print out where to locate the build file.
Still need to build the final "relocatable vmlinux" image in the top level directory of kernel source (either as vmlinux or vmlinux.reloc).
Once again thank you.
Regards,
Mohan.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Another feature I am looking is to generate the "relocatable vmlinux" image in the top directory of kernel source and the intermediate vmlinux file either in
arch/powerpc/kernelorarch/powerpc/boot.We no longer build arch specific targets in the top-level directory of the kernel src. We print out where to locate the build file.
Still need to build the final "relocatable vmlinux" image in the top level directory of kernel source (either as vmlinux or vmlinux.reloc).
As I said above this is NOT how we do it today. So you need to fix the tools that assume this.
Sam