blob: f2d850ca5056bbaece7661d61dcd1f7a5a5ca5a6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001# 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
Paul Mackerras2bf11812006-09-27 22:47:03 +100023all: $(obj)/zImage
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25HOSTCC := gcc
Paul Mackerras94b212c2005-11-16 13:38:21 +110026BOOTCFLAGS := $(HOSTCFLAGS) -fno-builtin -nostdinc -isystem \
27 $(shell $(CROSS32CC) -print-file-name=include) -fPIC
Olaf Heringdecd3002005-08-08 13:24:38 +100028BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Niels Kristian Bech Jensenfda7ffd2006-07-02 13:02:27 +020030ifeq ($(call cc-option-yn, -fstack-protector),y)
31BOOTCFLAGS += -fno-stack-protector
32endif
33
Olaf Hering70540362005-10-28 17:46:38 -070034BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
35
Paul Mackerras2bf11812006-09-27 22:47:03 +100036zlib := inffast.c inflate.c inftrees.c
37zlibheader := inffast.h inffixed.h inflate.h inftrees.h infutil.h
38zliblinuxheader := zlib.h zconf.h zutil.h
39
40$(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) \
41 $(addprefix $(obj)/,$(zlibheader))
42
David Gibsoncd197ff2007-03-05 14:24:52 +110043src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
David Gibsonad9d2712007-03-05 14:24:52 +110044 ns16550.c serial.c simple_alloc.c div64.S util.S \
Mark A. Greer88e68732007-03-27 15:29:50 -070045 gunzip_util.c elf_util.c $(zlib) devtree.c
Scott Wood4536b932007-04-27 03:09:01 +100046src-plat := of.c cuboot-83xx.c cuboot-85xx.c
David Gibsoncd197ff2007-03-05 14:24:52 +110047src-boot := $(src-wlib) $(src-plat) empty.c
Paul Mackerras2bf11812006-09-27 22:47:03 +100048
49src-boot := $(addprefix $(obj)/, $(src-boot))
50obj-boot := $(addsuffix .o, $(basename $(src-boot)))
51obj-wlib := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-wlib))))
52obj-plat := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-plat))))
53
Olaf Hering70540362005-10-28 17:46:38 -070054quiet_cmd_copy_zlib = COPY $@
55 cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
56
57quiet_cmd_copy_zlibheader = COPY $@
58 cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
59# stddef.h for NULL
60quiet_cmd_copy_zliblinuxheader = COPY $@
61 cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
62
63$(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
64 $(call cmd,copy_zlib)
65
66$(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
67 $(call cmd,copy_zlibheader)
68
69$(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
70 $(call cmd,copy_zliblinuxheader)
71
Paul Mackerras2bf11812006-09-27 22:47:03 +100072$(obj)/empty.c:
73 @touch $@
Olaf Hering70540362005-10-28 17:46:38 -070074
Paul Mackerras2bf11812006-09-27 22:47:03 +100075$(obj)/zImage.lds $(obj)/zImage.coff.lds: $(obj)/%: $(srctree)/$(src)/%.S
76 @cp $< $@
77
78clean-files := $(zlib) $(zlibheader) $(zliblinuxheader) \
Milton Miller5d7960f2007-03-21 09:03:10 -060079 empty.c zImage.coff.lds zImage.lds
Olaf Hering70540362005-10-28 17:46:38 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081quiet_cmd_bootcc = BOOTCC $@
82 cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
83
84quiet_cmd_bootas = BOOTAS $@
85 cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
86
Paul Mackerras2bf11812006-09-27 22:47:03 +100087quiet_cmd_bootar = BOOTAR $@
Milton Miller235fd832007-03-21 09:02:37 -060088 cmd_bootar = $(CROSS32AR) -cr $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@
Geoff Levanda24c8482005-08-15 13:59:13 -070089
Milton Miller235fd832007-03-21 09:02:37 -060090$(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 $(call if_changed_dep,bootcc)
Milton Miller235fd832007-03-21 09:02:37 -060092$(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 $(call if_changed_dep,bootas)
94
Milton Miller235fd832007-03-21 09:02:37 -060095$(obj)/wrapper.a: $(obj-wlib) FORCE
96 $(call if_changed,bootar)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Josh Boyer0cfcccb2006-10-13 10:07:01 -050098hostprogs-y := addnote addRamDisk hack-coff mktree
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Milton Miller235fd832007-03-21 09:02:37 -0600100targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a)
David Gibsoncd197ff2007-03-05 14:24:52 +1100101extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \
Paul Mackerras2bf11812006-09-27 22:47:03 +1000102 $(obj)/zImage.lds $(obj)/zImage.coff.lds
Paul Mackerras66a45dd2006-01-14 15:04:06 +1100103
Paul Mackerras2bf11812006-09-27 22:47:03 +1000104wrapper :=$(srctree)/$(src)/wrapper
Milton Miller65b58032007-03-19 14:58:04 -0600105wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree) \
Milton Miller235fd832007-03-21 09:02:37 -0600106 $(wrapper) FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Paul Mackerras2bf11812006-09-27 22:47:03 +1000108#############
109# Bits for building various flavours of zImage
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Paul Mackerras2bf11812006-09-27 22:47:03 +1000111ifneq ($(CROSS32_COMPILE),)
Michael Ellermandcf90652006-09-30 11:54:09 +1000112CROSSWRAP := -C "$(CROSS32_COMPILE)"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000113else
114ifneq ($(CROSS_COMPILE),)
Michael Ellermandcf90652006-09-30 11:54:09 +1000115CROSSWRAP := -C "$(CROSS_COMPILE)"
Paul Mackerras2bf11812006-09-27 22:47:03 +1000116endif
117endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Milton Miller9da82a62007-03-21 09:03:23 -0600119# args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd
Paul Mackerras2bf11812006-09-27 22:47:03 +1000120quiet_cmd_wrap = WRAP $@
Milton Miller9da82a62007-03-21 09:03:23 -0600121 cmd_wrap =$(CONFIG_SHELL) $(wrapper) -c -o $@ -p $2 $(CROSSWRAP) \
122 $(if $3, -s $3)$(if $4, -d $4)$(if $5, -i $5) vmlinux
Paul Mackerras2bf11812006-09-27 22:47:03 +1000123
Geoff Levand020533e2006-10-07 15:33:53 -0700124image-$(CONFIG_PPC_PSERIES) += zImage.pseries
125image-$(CONFIG_PPC_MAPLE) += zImage.pseries
126image-$(CONFIG_PPC_IBM_CELL_BLADE) += zImage.pseries
Geoff Levand8a8944a2006-12-04 16:11:38 -0800127image-$(CONFIG_PPC_PS3) += zImage.ps3
Ishizaki Kouc347b792007-02-02 16:47:17 +0900128image-$(CONFIG_PPC_CELLEB) += zImage.pseries
Geoff Levand020533e2006-10-07 15:33:53 -0700129image-$(CONFIG_PPC_CHRP) += zImage.chrp
Nicolas DET7839af32006-11-17 17:08:37 +0100130image-$(CONFIG_PPC_EFIKA) += zImage.chrp
Geoff Levand020533e2006-10-07 15:33:53 -0700131image-$(CONFIG_PPC_PMAC) += zImage.pmac
Scott Woodac18c672007-05-03 04:00:00 +1000132image-$(CONFIG_DEFAULT_UIMAGE) += uImage
133
134ifneq ($(CONFIG_DEVICE_TREE),"")
David Gibsona6afacb2007-05-01 10:20:20 +1000135image-$(CONFIG_PPC_83xx) += cuImage.83xx
136image-$(CONFIG_PPC_85xx) += cuImage.85xx
Scott Woodac18c672007-05-03 04:00:00 +1000137endif
Geoff Levanda24c8482005-08-15 13:59:13 -0700138
Paul Mackerras9216ad82006-01-15 13:00:08 +1100139# For 32-bit powermacs, build the COFF and miboot images
140# as well as the ELF images.
Paul Mackerras2bf11812006-09-27 22:47:03 +1000141ifeq ($(CONFIG_PPC32),y)
142image-$(CONFIG_PPC_PMAC) += zImage.coff zImage.miboot
143endif
Paul Mackerras66a45dd2006-01-14 15:04:06 +1100144
Milton Miller5d7960f2007-03-21 09:03:10 -0600145initrd- := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-))
Paul Mackerras2bf11812006-09-27 22:47:03 +1000146initrd-y := $(patsubst zImage%, zImage.initrd%, $(image-y))
Milton Miller9da82a62007-03-21 09:03:23 -0600147initrd-y := $(filter-out $(image-y), $(initrd-y))
Milton Miller235fd832007-03-21 09:02:37 -0600148targets += $(image-y) $(initrd-y)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Milton Miller9da82a62007-03-21 09:03:23 -0600150$(addprefix $(obj)/, $(initrd-y)): $(obj)/ramdisk.image.gz
151
152# Don't put the ramdisk on the pattern rule; when its missing make will try
153# the pattern rule with less dependencies that also matches (even with the
154# hard dependency listed).
155$(obj)/zImage.initrd.%: vmlinux $(wrapperbits)
156 $(call if_changed,wrap,$*,,,$(obj)/ramdisk.image.gz)
157
158$(obj)/zImage.%: vmlinux $(wrapperbits)
159 $(call if_changed,wrap,$*)
160
161$(obj)/zImage.ps3: vmlinux
162 $(STRIP) -s -R .comment $< -o $@
163
164$(obj)/zImage.initrd.ps3: vmlinux
165 @echo " WARNING zImage.initrd.ps3 not supported (yet)"
166
167$(obj)/uImage: vmlinux $(wrapperbits)
168 $(call if_changed,wrap,uboot)
169
Scott Woodd818d7e2007-04-28 06:32:15 +1000170dts = $(if $(shell echo $(CONFIG_DEVICE_TREE) | grep '^/'),\
Scott Wood0fdd7172007-04-17 09:25:50 +1000171 ,$(srctree)/$(src)/dts/)$(CONFIG_DEVICE_TREE)
172
David Gibsona6afacb2007-05-01 10:20:20 +1000173$(obj)/cuImage.%: vmlinux $(wrapperbits)
174 $(call if_changed,wrap,cuboot-$*,$(dts))
Scott Wood0fdd7172007-04-17 09:25:50 +1000175
Paul Mackerras2bf11812006-09-27 22:47:03 +1000176$(obj)/zImage: $(addprefix $(obj)/, $(image-y))
177 @rm -f $@; ln $< $@
178$(obj)/zImage.initrd: $(addprefix $(obj)/, $(initrd-y))
179 @rm -f $@; ln $< $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Akinobu Mita928370c2007-04-10 21:05:31 +1000181install: $(CONFIGURE) $(addprefix $(obj)/, $(image-y))
Paul Mackerras2bf11812006-09-27 22:47:03 +1000182 sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" $<
Paul Mackerras66a45dd2006-01-14 15:04:06 +1100183
Milton Miller1383a342007-03-28 02:21:04 -0600184# anything not in $(targets)
David Gibsona6afacb2007-05-01 10:20:20 +1000185clean-files += $(image-) $(initrd-) zImage zImage.initrd cuImage.*
Milton Miller1383a342007-03-28 02:21:04 -0600186
187# clean up files cached by wrapper
188clean-kernel := vmlinux.strip vmlinux.bin
189clean-kernel += $(addsuffix .gz,$(clean-kernel))
190# If not absolute clean-files are relative to $(obj).
191clean-files += $(addprefix $(objtree)/, $(clean-kernel))