initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / ppc64 / boot / Makefile
blob8f99c9dbc912fd8d39373fe37d8f6aef228d9009
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.
23 CROSS32_COMPILE ?=
24 #CROSS32_COMPILE = /usr/local/ppc/bin/powerpc-linux-
26 BOOTCC := $(CROSS32_COMPILE)gcc
27 HOSTCC := gcc
28 BOOTCFLAGS := $(HOSTCFLAGS) $(LINUXINCLUDE) -fno-builtin
29 BOOTAS := $(CROSS32_COMPILE)as
30 BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional
31 BOOTLD := $(CROSS32_COMPILE)ld
32 BOOTLFLAGS := -Ttext 0x00400000 -e _start -T $(srctree)/$(src)/zImage.lds
33 BOOTOBJCOPY := $(CROSS32_COMPILE)objcopy
34 OBJCOPYFLAGS := contents,alloc,load,readonly,data
36 src-boot := crt0.S string.S prom.c main.c zlib.c imagesize.c div64.S
37 src-boot := $(addprefix $(obj)/, $(src-boot))
38 obj-boot := $(addsuffix .o, $(basename $(src-boot)))
40 quiet_cmd_bootcc = BOOTCC $@
41 cmd_bootcc = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
43 quiet_cmd_bootas = BOOTAS $@
44 cmd_bootas = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
46 $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c
47 $(call if_changed_dep,bootcc)
48 $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S
49 $(call if_changed_dep,bootas)
51 #-----------------------------------------------------------
52 # ELF sections within the zImage bootloader/wrapper
53 #-----------------------------------------------------------
54 required := vmlinux.strip
55 initrd := initrd
57 obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
58 src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
59 gz-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))
61 hostprogs-y := piggy addnote addRamDisk
62 targets += zImage zImage.initrd imagesize.c \
63 $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
64 $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
65 $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
66 vmlinux.initrd
67 extra-y := initrd.o
69 quiet_cmd_ramdisk = RAMDISK $@
70 cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@
72 quiet_cmd_stripvm = STRIP $@
73 cmd_stripvm = $(STRIP) -s $< -o $@
75 vmlinux.strip: vmlinux FORCE
76 $(call if_changed,stripvm)
77 $(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz FORCE
78 $(call if_changed,ramdisk)
80 addsection = $(BOOTOBJCOPY) $(1) \
81 --add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(patsubst %.o,%.gz, $(1)) \
82 --set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(OBJCOPYFLAGS)
84 quiet_cmd_addnote = ADDNOTE $@
85 cmd_addnote = $(BOOTLD) $(BOOTLFLAGS) -o $@ $(obj-boot) && $(obj)/addnote $@
87 quiet_cmd_piggy = PIGGY $@
88 cmd_piggy = $(obj)/piggyback $(@:.o=) < $< | $(BOOTAS) -o $@
90 $(call gz-sec, $(required)): $(obj)/kernel-%.gz: % FORCE
91 $(call if_changed,gzip)
93 $(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
94 cp -f $(obj)/ramdisk.image.gz $@
96 $(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz FORCE
97 touch $@
99 $(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c FORCE
100 $(call if_changed_dep,bootcc)
101 $(call addsection, $@)
103 $(obj)/zImage: obj-boot += $(call obj-sec, $(required))
104 $(obj)/zImage: $(call obj-sec, $(required)) $(obj-boot) $(obj)/addnote FORCE
105 $(call if_changed,addnote)
107 $(obj)/zImage.initrd: obj-boot += $(call obj-sec, $(required) $(initrd))
108 $(obj)/zImage.initrd: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(obj)/addnote FORCE
109 $(call if_changed,addnote)
111 $(obj)/imagesize.c: vmlinux.strip
112 @echo Generating $@
113 ls -l vmlinux.strip | \
114 awk '{printf "/* generated -- do not edit! */\n" \
115 "unsigned long vmlinux_filesize = %d;\n", $$5}' > $(obj)/imagesize.c
116 $(CROSS_COMPILE)nm -n vmlinux | tail -n 1 | \
117 awk '{printf "unsigned long vmlinux_memsize = 0x%s;\n", substr($$1,8)}' \
118 >> $(obj)/imagesize.c
120 install: $(CONFIGURE) $(obj)/$(BOOTIMAGE)
121 sh -x $(src)/install.sh "$(KERNELRELEASE)" "$(obj)/$(BOOTIMAGE)" "$(INSTALL_PATH)"
123 clean-files := $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)