public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
* Integrating relocatable kernel build with kernel build
@ 2008-07-09 18:31 Mohan Kumar M
  2008-07-09 20:27 ` Sam Ravnborg
  0 siblings, 1 reply; 4+ messages in thread
From: Mohan Kumar M @ 2008-07-09 18:31 UTC (permalink / raw)
  To: sam; +Cc: linux-kbuild

[-- Attachment #1: Type: text/plain, Size: 2158 bytes --]

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.

[-- Attachment #2: diff.Makefile --]
[-- Type: text/plain, Size: 224 bytes --]

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.%

[-- Attachment #3: diff.Makefile.boot --]
[-- Type: text/plain, Size: 1556 bytes --]

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

[-- Attachment #4: make.reloc --]
[-- Type: text/plain, Size: 2471 bytes --]

#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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Integrating relocatable kernel build with kernel build
  2008-07-09 18:31 Integrating relocatable kernel build with kernel build Mohan Kumar M
@ 2008-07-09 20:27 ` Sam Ravnborg
  2008-07-10 14:10   ` Mohan Kumar M
  0 siblings, 1 reply; 4+ messages in thread
From: Sam Ravnborg @ 2008-07-09 20:27 UTC (permalink / raw)
  To: Mohan Kumar M; +Cc: linux-kbuild

Hi Mohan.

On Thu, Jul 10, 2008 at 12:01:38AM +0530, Mohan Kumar M wrote:
> 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

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.


> 2. During build process, build is not able to build the 
> vmlinux.reloc.lds linker script from the vmlinux.reloc.lds.S source 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

> 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)

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.

> 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.
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.

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Integrating relocatable kernel build with kernel build
  2008-07-09 20:27 ` Sam Ravnborg
@ 2008-07-10 14:10   ` Mohan Kumar M
  2008-07-10 19:44     ` Sam Ravnborg
  0 siblings, 1 reply; 4+ messages in thread
From: Mohan Kumar M @ 2008-07-10 14:10 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: linux-kbuild

Hi Sam,

Thank you for the reply.

Sam Ravnborg wrote:
> 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.
> 
> And include support for the target in same file.
> 
> 
>> 2. During build process, build is not able to build the 
>> vmlinux.reloc.lds linker script from the vmlinux.reloc.lds.S source file.
> 
> If you just add:
> extra-y += vmlinux.reloc.lds

After including the above entry, make builds the linker script.

> 
> then it should happen automatically.
> ee how all archs does it in arch/$ARCH/kernel/Makefile for vmlinx.lds
> 

> 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.
> 
>> 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.
> 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.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Integrating relocatable kernel build with kernel build
  2008-07-10 14:10   ` Mohan Kumar M
@ 2008-07-10 19:44     ` Sam Ravnborg
  0 siblings, 0 replies; 4+ messages in thread
From: Sam Ravnborg @ 2008-07-10 19:44 UTC (permalink / raw)
  To: Mohan Kumar M; +Cc: linux-kbuild

> >
> >>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.
> >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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-10 19:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-09 18:31 Integrating relocatable kernel build with kernel build Mohan Kumar M
2008-07-09 20:27 ` Sam Ravnborg
2008-07-10 14:10   ` Mohan Kumar M
2008-07-10 19:44     ` Sam Ravnborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox