Integrating relocatable kernel build with kernel build

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.%
---
> BOOT_TARGETS = zImage vmlinux.reloc zImage.initrd uImage zImage% dtbImage% treeImage.% cuImage.% simpleImage.%
20c20
< all: $(obj)/zImage
---
> all: $(obj)/zImage $(obj)/vmlinux.reloc
123c123
< hostprogs-y	:= addnote addRamDisk hack-coff mktree dtc
---
> hostprogs-y	:= addnote addRamDisk hack-coff mktree dtc relocs
128a129
> 
132c133
< wrapperbits	:= $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree dtc) \
---
> wrapperbits	:= $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree dtc relocs) \
134a136,164
> 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)
> 
> 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)
---
> 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

[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux