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. That's normally the same 15# compiler for the rest of the kernel, with the -m32 flag added. 16# To make it easier to setup a cross compiler, 17# CROSS32_COMPILE is setup as a prefix just like CROSS_COMPILE 18# in the toplevel makefile. 19 20all: $(obj)/zImage 21 22BOOTCFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ 23 -fno-strict-aliasing -Os -msoft-float -pipe \ 24 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \ 25 -isystem $(shell $(CROSS32CC) -print-file-name=include) 26BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc 27 28ifdef CONFIG_DEBUG_INFO 29BOOTCFLAGS += -g 30endif 31 32ifeq ($(call cc-option-yn, -fstack-protector),y) 33BOOTCFLAGS += -fno-stack-protector 34endif 35 36BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) 37 38$(obj)/4xx.o: BOOTCFLAGS += -mcpu=440 39$(obj)/ebony.o: BOOTCFLAGS += -mcpu=440 40$(obj)/treeboot-walnut.o: BOOTCFLAGS += -mcpu=405 41 42zlib := inffast.c inflate.c inftrees.c 43zlibheader := inffast.h inffixed.h inflate.h inftrees.h infutil.h 44zliblinuxheader := zlib.h zconf.h zutil.h 45 46$(addprefix $(obj)/,$(zlib) gunzip_util.o main.o): \ 47 $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader)) 48 49src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \ 50 ns16550.c serial.c simple_alloc.c div64.S util.S \ 51 gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \ 52 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \ 53 cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c \ 54 fsl-soc.c mpc8xx.c pq2.c 55src-plat := of.c cuboot-52xx.c cuboot-83xx.c cuboot-85xx.c holly.c \ 56 cuboot-ebony.c treeboot-ebony.c prpmc2800.c \ 57 ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \ 58 cuboot-pq2.c cuboot-sequoia.c treeboot-walnut.c cuboot-bamboo.c \ 59 fixed-head.S ep88xc.c cuboot-hpc2.c 60src-boot := $(src-wlib) $(src-plat) empty.c 61 62src-boot := $(addprefix $(obj)/, $(src-boot)) 63obj-boot := $(addsuffix .o, $(basename $(src-boot))) 64obj-wlib := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-wlib)))) 65obj-plat := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-plat)))) 66 67quiet_cmd_copy_zlib = COPY $@ 68 cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@ 69 70quiet_cmd_copy_zlibheader = COPY $@ 71 cmd_copy_zlibheader = sed "s@<linux/\([^>]*\).*@\"\1\"@" $< > $@ 72# stddef.h for NULL 73quiet_cmd_copy_zliblinuxheader = COPY $@ 74 cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@ 75 76$(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/% 77 $(call cmd,copy_zlib) 78 79$(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/% 80 $(call cmd,copy_zlibheader) 81 82$(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/% 83 $(call cmd,copy_zliblinuxheader) 84 85$(obj)/empty.c: 86 @touch $@ 87 88$(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds: $(obj)/%: $(srctree)/$(src)/%.S 89 @cp $< $@ 90 91clean-files := $(zlib) $(zlibheader) $(zliblinuxheader) \ 92 empty.c zImage zImage.coff.lds zImage.ps3.lds zImage.lds 93 94quiet_cmd_bootcc = BOOTCC $@ 95 cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $< 96 97quiet_cmd_bootas = BOOTAS $@ 98 cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $< 99 100quiet_cmd_bootar = BOOTAR $@ 101 cmd_bootar = $(CROSS32AR) -cr $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@ 102 103$(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c FORCE 104 $(call if_changed_dep,bootcc) 105$(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE 106 $(call if_changed_dep,bootas) 107 108$(obj)/wrapper.a: $(obj-wlib) FORCE 109 $(call if_changed,bootar) 110 111hostprogs-y := addnote addRamDisk hack-coff mktree 112 113targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a) 114extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \ 115 $(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds 116 117wrapper :=$(srctree)/$(src)/wrapper 118wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree) \ 119 $(wrapper) FORCE 120 121############# 122# Bits for building various flavours of zImage 123 124ifneq ($(CROSS32_COMPILE),) 125CROSSWRAP := -C "$(CROSS32_COMPILE)" 126else 127ifneq ($(CROSS_COMPILE),) 128CROSSWRAP := -C "$(CROSS_COMPILE)" 129endif 130endif 131 132# args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd 133quiet_cmd_wrap = WRAP $@ 134 cmd_wrap =$(CONFIG_SHELL) $(wrapper) -c -o $@ -p $2 $(CROSSWRAP) \ 135 $(if $3, -s $3)$(if $4, -d $4)$(if $5, -i $5) vmlinux 136 137image-$(CONFIG_PPC_PSERIES) += zImage.pseries 138image-$(CONFIG_PPC_MAPLE) += zImage.pseries 139image-$(CONFIG_PPC_IBM_CELL_BLADE) += zImage.pseries 140image-$(CONFIG_PPC_PS3) += zImage.ps3 141image-$(CONFIG_PPC_CELLEB) += zImage.pseries 142image-$(CONFIG_PPC_CHRP) += zImage.chrp 143image-$(CONFIG_PPC_EFIKA) += zImage.chrp 144image-$(CONFIG_PPC_PMAC) += zImage.pmac 145image-$(CONFIG_PPC_HOLLY) += zImage.holly 146image-$(CONFIG_PPC_PRPMC2800) += zImage.prpmc2800 147image-$(CONFIG_PPC_ISERIES) += zImage.iseries 148image-$(CONFIG_DEFAULT_UIMAGE) += uImage 149 150ifneq ($(CONFIG_DEVICE_TREE),"") 151image-$(CONFIG_PPC_8xx) += cuImage.8xx 152image-$(CONFIG_PPC_EP88XC) += zImage.ep88xc 153image-$(CONFIG_8260) += cuImage.pq2 154image-$(CONFIG_PPC_MPC52xx) += cuImage.52xx 155image-$(CONFIG_PPC_83xx) += cuImage.83xx 156image-$(CONFIG_PPC_85xx) += cuImage.85xx 157image-$(CONFIG_MPC7448HPC2) += cuImage.hpc2 158image-$(CONFIG_EBONY) += treeImage.ebony cuImage.ebony 159image-$(CONFIG_BAMBOO) += treeImage.bamboo cuImage.bamboo 160image-$(CONFIG_SEQUOIA) += cuImage.sequoia 161image-$(CONFIG_WALNUT) += treeImage.walnut 162endif 163 164# For 32-bit powermacs, build the COFF and miboot images 165# as well as the ELF images. 166ifeq ($(CONFIG_PPC32),y) 167image-$(CONFIG_PPC_PMAC) += zImage.coff zImage.miboot 168endif 169 170initrd- := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-)) 171initrd-y := $(patsubst zImage%, zImage.initrd%, \ 172 $(patsubst treeImage%, treeImage.initrd%, $(image-y))) 173initrd-y := $(filter-out $(image-y), $(initrd-y)) 174targets += $(image-y) $(initrd-y) 175 176$(addprefix $(obj)/, $(initrd-y)): $(obj)/ramdisk.image.gz 177 178# If CONFIG_WANT_DEVICE_TREE is set and CONFIG_DEVICE_TREE isn't an 179# empty string, define 'dts' to be path to the dts 180# CONFIG_DEVICE_TREE will have "" around it, make sure to strip them 181ifeq ($(CONFIG_WANT_DEVICE_TREE),y) 182ifneq ($(CONFIG_DEVICE_TREE),"") 183dts = $(if $(shell echo $(CONFIG_DEVICE_TREE) | grep '^/'),\ 184 ,$(srctree)/$(src)/dts/)$(CONFIG_DEVICE_TREE:"%"=%) 185endif 186endif 187 188# Don't put the ramdisk on the pattern rule; when its missing make will try 189# the pattern rule with less dependencies that also matches (even with the 190# hard dependency listed). 191$(obj)/zImage.initrd.%: vmlinux $(wrapperbits) $(dts) 192 $(call if_changed,wrap,$*,$(dts),,$(obj)/ramdisk.image.gz) 193 194$(obj)/zImage.%: vmlinux $(wrapperbits) $(dts) 195 $(call if_changed,wrap,$*,$(dts)) 196 197# This cannot be in the root of $(src) as the zImage rule always adds a $(obj) 198# prefix 199$(obj)/vmlinux.strip: vmlinux 200 $(STRIP) -s -R .comment $< -o $@ 201 202$(obj)/zImage.iseries: vmlinux 203 $(STRIP) -s -R .comment $< -o $@ 204 205$(obj)/zImage.ps3: vmlinux $(wrapper) $(wrapperbits) $(srctree)/$(src)/dts/ps3.dts 206 $(STRIP) -s -R .comment $< -o vmlinux.strip 207 $(call cmd,wrap,ps3,$(srctree)/$(src)/dts/ps3.dts,,) 208 209$(obj)/zImage.initrd.ps3: vmlinux $(wrapper) $(wrapperbits) $(srctree)/$(src)/dts/ps3.dts $(obj)/ramdisk.image.gz 210 $(call cmd,wrap,ps3,$(srctree)/$(src)/dts/ps3.dts,,$(obj)/ramdisk.image.gz) 211 212$(obj)/uImage: vmlinux $(wrapperbits) 213 $(call if_changed,wrap,uboot) 214 215$(obj)/cuImage.%: vmlinux $(dts) $(wrapperbits) 216 $(call if_changed,wrap,cuboot-$*,$(dts)) 217 218$(obj)/treeImage.initrd.%: vmlinux $(dts) $(wrapperbits) 219 $(call if_changed,wrap,treeboot-$*,$(dts),,$(obj)/ramdisk.image.gz) 220 221$(obj)/treeImage.%: vmlinux $(dts) $(wrapperbits) 222 $(call if_changed,wrap,treeboot-$*,$(dts)) 223 224# If there isn't a platform selected then just strip the vmlinux. 225ifeq (,$(image-y)) 226image-y := vmlinux.strip 227endif 228 229$(obj)/zImage: $(addprefix $(obj)/, $(image-y)) 230 @rm -f $@; ln $< $@ 231$(obj)/zImage.initrd: $(addprefix $(obj)/, $(initrd-y)) 232 @rm -f $@; ln $< $@ 233 234install: $(CONFIGURE) $(addprefix $(obj)/, $(image-y)) 235 sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" $< 236 237# anything not in $(targets) 238clean-files += $(image-) $(initrd-) zImage zImage.initrd cuImage.* treeImage.* \ 239 otheros.bld 240 241# clean up files cached by wrapper 242clean-kernel := vmlinux.strip vmlinux.bin 243clean-kernel += $(addsuffix .gz,$(clean-kernel)) 244# If not absolute clean-files are relative to $(obj). 245clean-files += $(addprefix $(objtree)/, $(clean-kernel)) 246