[PATCH] ppc64: make arch/ppc64/boot standalone
[linux-2.6/openmoko-kernel/knife-kernel.git] / arch / ppc64 / boot / Makefile
blob2c5f5e73d00c76d3e4a56e8f721656c926aa55e9
1 # Makefile for making ELF bootable images for booting on CHRP
2 # using Open Firmware.
4 # Geert Uytterhoeven September 1997
6 # Based on coffboot by Paul Mackerras
7 # Simplified for ppc64 by Todd Inglett
9 # NOTE: this code is built for 32 bit in ELF32 format even though
10 # it packages a 64 bit kernel. We do this to simplify the
11 # bootloader and increase compatibility with OpenFirmware.
13 # To this end we need to define BOOTCC, etc, as the tools
14 # needed to build the 32 bit image. These are normally HOSTCC,
15 # but may be a third compiler if, for example, you are cross
16 # compiling from an intel box. Once the 64bit ppc gcc is
17 # stable it will probably simply be a compiler switch to
18 # compile for 32bit mode.
19 # To make it easier to setup a cross compiler,
20 # CROSS32_COMPILE is setup as a prefix just like CROSS_COMPILE
21 # in the toplevel makefile.
24 HOSTCC := gcc
25 BOOTCFLAGS := $(HOSTCFLAGS) -fno-builtin -nostdinc -isystem $(shell $(CROSS32CC) -print-file-name=include)
26 BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
27 BOOTLFLAGS := -Ttext 0x00400000 -e _start -T $(srctree)/$(src)/zImage.lds
28 OBJCOPYFLAGS := contents,alloc,load,readonly,data
30 src-boot := crt0.S string.S prom.c main.c zlib.c imagesize.c div64.S
31 src-boot := $(addprefix $(obj)/, $(src-boot))
32 obj-boot := $(addsuffix .o, $(basename $(src-boot)))
34 quiet_cmd_bootcc = BOOTCC $@
35 cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
37 quiet_cmd_bootas = BOOTAS $@
38 cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
40 $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c
41 $(call if_changed_dep,bootcc)
42 $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S
43 $(call if_changed_dep,bootas)
45 #-----------------------------------------------------------
46 # ELF sections within the zImage bootloader/wrapper
47 #-----------------------------------------------------------
48 required := vmlinux.strip
49 initrd := initrd
51 obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
52 src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
53 gz-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))
55 hostprogs-y := addnote addRamDisk
56 targets += zImage zImage.initrd imagesize.c \
57 $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
58 $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
59 $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
60 vmlinux.initrd
61 extra-y := initrd.o
63 quiet_cmd_ramdisk = RAMDISK $@
64 cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@
66 quiet_cmd_stripvm = STRIP $@
67 cmd_stripvm = $(STRIP) -s $< -o $@
69 vmlinux.strip: vmlinux FORCE
70 $(call if_changed,stripvm)
71 $(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz FORCE
72 $(call if_changed,ramdisk)
74 addsection = $(CROSS32OBJCOPY) $(1) \
75 --add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(patsubst %.o,%.gz, $(1)) \
76 --set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(OBJCOPYFLAGS)
78 quiet_cmd_addnote = ADDNOTE $@
79 cmd_addnote = $(CROSS32LD) $(BOOTLFLAGS) -o $@ $(obj-boot) && $(obj)/addnote $@
81 $(call gz-sec, $(required)): $(obj)/kernel-%.gz: % FORCE
82 $(call if_changed,gzip)
84 $(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
85 cp -f $(obj)/ramdisk.image.gz $@
87 $(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz FORCE
88 touch $@
90 $(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c FORCE
91 $(call if_changed_dep,bootcc)
92 $(call addsection, $@)
94 $(obj)/zImage: obj-boot += $(call obj-sec, $(required))
95 $(obj)/zImage: $(call obj-sec, $(required)) $(obj-boot) $(obj)/addnote FORCE
96 $(call if_changed,addnote)
98 $(obj)/zImage.initrd: obj-boot += $(call obj-sec, $(required) $(initrd))
99 $(obj)/zImage.initrd: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(obj)/addnote FORCE
100 $(call if_changed,addnote)
102 $(obj)/imagesize.c: vmlinux.strip
103 @echo Generating $@
104 ls -l vmlinux.strip | \
105 awk '{printf "/* generated -- do not edit! */\n" \
106 "unsigned long vmlinux_filesize = %d;\n", $$5}' > $(obj)/imagesize.c
107 $(CROSS_COMPILE)nm -n vmlinux | tail -n 1 | \
108 awk '{printf "unsigned long vmlinux_memsize = 0x%s;\n", substr($$1,8)}' \
109 >> $(obj)/imagesize.c
111 install: $(CONFIGURE) $(BOOTIMAGE)
112 sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" "$(BOOTIMAGE)"
114 clean-files := $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)