This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / arch / ppc64 / boot / Makefile
1 # Makefile for making ELF bootable images for booting on CHRP
2 # using Open Firmware.
3 #
4 # Geert Uytterhoeven    September 1997
5 #
6 # Based on coffboot by Paul Mackerras
7 # Simplified for ppc64 by Todd Inglett
8 #
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.
12 #
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.
22
23 CROSS32_COMPILE ?=
24 #CROSS32_COMPILE = /usr/local/ppc/bin/powerpc-linux-
25
26 HAS_BIARCH      := $(shell if gcc -m32 -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo y; else echo n; fi;)
27 ifeq ($(HAS_BIARCH),y)
28 BOOTCC := gcc -m32
29 BOOTLD := ld -m elf32ppclinux
30 BOOTAS := as -32
31 BOOTOBJCOPY := objcopy --target elf32-powerpc
32 else
33 BOOTCC = $(CROSS32_COMPILE)gcc
34 BOOTLD = $(CROSS32_COMPILE)ld
35 BOOTAS = $(CROSS32_COMPILE)as
36 BOOTOBJCOPY = $(CROSS32_COMPILE)objcopy
37 endif
38
39 HOSTCC          := gcc
40 BOOTCFLAGS      := $(HOSTCFLAGS) $(LINUXINCLUDE) -fno-builtin 
41 BOOTAFLAGS      := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional
42 BOOTLFLAGS      := -Ttext 0x00400000 -e _start -T $(srctree)/$(src)/zImage.lds
43 OBJCOPYFLAGS    := contents,alloc,load,readonly,data
44
45 src-boot := crt0.S string.S prom.c main.c zlib.c imagesize.c div64.S
46 src-boot := $(addprefix $(obj)/, $(src-boot))
47 obj-boot := $(addsuffix .o, $(basename $(src-boot)))
48
49 quiet_cmd_bootcc = BOOTCC  $@
50       cmd_bootcc = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
51
52 quiet_cmd_bootas = BOOTAS  $@
53       cmd_bootas = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
54
55 $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c
56         $(call if_changed_dep,bootcc)
57 $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S
58         $(call if_changed_dep,bootas)
59
60 #-----------------------------------------------------------
61 # ELF sections within the zImage bootloader/wrapper
62 #-----------------------------------------------------------
63 required := vmlinux.strip
64 initrd   := initrd
65
66 obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
67 src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
68 gz-sec  = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))
69
70 hostprogs-y             := piggy addnote addRamDisk
71 targets                 += zImage zImage.initrd imagesize.c \
72                            $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
73                            $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
74                            $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
75                            vmlinux.initrd
76 extra-y                 := initrd.o
77
78 quiet_cmd_ramdisk = RAMDISK $@
79       cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@
80
81 quiet_cmd_stripvm = STRIP $@
82       cmd_stripvm = $(STRIP) -s $< -o $@
83
84 vmlinux.strip: vmlinux FORCE
85         $(call if_changed,stripvm)
86 $(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz FORCE
87         $(call if_changed,ramdisk)
88
89 addsection = $(BOOTOBJCOPY) $(1) \
90                 --add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(patsubst %.o,%.gz, $(1)) \
91                 --set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(OBJCOPYFLAGS)
92
93 quiet_cmd_addnote = ADDNOTE $@ 
94       cmd_addnote = $(BOOTLD) $(BOOTLFLAGS) -o $@ $(obj-boot) && $(obj)/addnote $@
95
96 quiet_cmd_piggy = PIGGY   $@
97       cmd_piggy = $(obj)/piggyback $(@:.o=) < $< | $(BOOTAS) -o $@
98
99 $(call gz-sec, $(required)): $(obj)/kernel-%.gz: % FORCE
100         $(call if_changed,gzip)
101
102 $(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
103         cp -f $(obj)/ramdisk.image.gz $@
104
105 $(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz FORCE
106         touch $@
107
108 $(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c FORCE
109         $(call if_changed_dep,bootcc)
110         $(call addsection, $@)
111
112 $(obj)/zImage: obj-boot += $(call obj-sec, $(required))
113 $(obj)/zImage: $(call obj-sec, $(required)) $(obj-boot) $(obj)/addnote FORCE
114         $(call if_changed,addnote)
115
116 $(obj)/zImage.stub: $(obj-boot) FORCE
117         $(BOOTLD) -r $(BOOTLFLAGS) -o $@ $(obj-boot)
118
119 $(obj)/zImage.initrd: obj-boot += $(call obj-sec, $(required) $(initrd))
120 $(obj)/zImage.initrd: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(obj)/addnote FORCE
121         $(call if_changed,addnote)
122
123 $(obj)/imagesize.c: vmlinux.strip
124         @echo Generating $@
125         ls -l vmlinux.strip | \
126         awk '{printf "/* generated -- do not edit! */\n" \
127                 "unsigned long vmlinux_filesize = %d;\n", $$5}' > $(obj)/imagesize.c
128         $(CROSS_COMPILE)nm -n vmlinux | tail -n 1 | \
129         awk '{printf "unsigned long vmlinux_memsize = 0x%s;\n", substr($$1,8)}' \
130                 >> $(obj)/imagesize.c
131
132 install: $(CONFIGURE) $(obj)/$(BOOTIMAGE)
133         sh -x $(src)/install.sh "$(KERNELRELEASE)" "$(obj)/$(BOOTIMAGE)" "$(INSTALL_PATH)"
134
135 clean-files := $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)