194b212c2SPaul Mackerras# Makefile for making ELF bootable images for booting on CHRP 294b212c2SPaul Mackerras# using Open Firmware. 394b212c2SPaul Mackerras# 494b212c2SPaul Mackerras# Geert Uytterhoeven September 1997 594b212c2SPaul Mackerras# 694b212c2SPaul Mackerras# Based on coffboot by Paul Mackerras 794b212c2SPaul Mackerras# Simplified for ppc64 by Todd Inglett 894b212c2SPaul Mackerras# 994b212c2SPaul Mackerras# NOTE: this code is built for 32 bit in ELF32 format even though 1094b212c2SPaul Mackerras# it packages a 64 bit kernel. We do this to simplify the 1194b212c2SPaul Mackerras# bootloader and increase compatibility with OpenFirmware. 1294b212c2SPaul Mackerras# 1394b212c2SPaul Mackerras# To this end we need to define BOOTCC, etc, as the tools 14b610b978SDavid Gibson# needed to build the 32 bit image. That's normally the same 15b610b978SDavid Gibson# compiler for the rest of the kernel, with the -m32 flag added. 1694b212c2SPaul Mackerras# To make it easier to setup a cross compiler, 1794b212c2SPaul Mackerras# CROSS32_COMPILE is setup as a prefix just like CROSS_COMPILE 1894b212c2SPaul Mackerras# in the toplevel makefile. 1994b212c2SPaul Mackerras 202bf11819SPaul Mackerrasall: $(obj)/zImage 2194b212c2SPaul Mackerras 22b610b978SDavid GibsonBOOTCFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ 23b610b978SDavid Gibson -fno-strict-aliasing -Os -msoft-float -pipe \ 24b610b978SDavid Gibson -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \ 25b610b978SDavid Gibson -isystem $(shell $(CROSS32CC) -print-file-name=include) 2694b212c2SPaul MackerrasBOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc 2794b212c2SPaul Mackerras 28*105c13ddSGrant Likelyifdef CONFIG_DEBUG_INFO 29*105c13ddSGrant LikelyBOOTCFLAGS += -g 30*105c13ddSGrant Likelyendif 31*105c13ddSGrant Likely 32fda7ffd2SNiels Kristian Bech Jensenifeq ($(call cc-option-yn, -fstack-protector),y) 33fda7ffd2SNiels Kristian Bech JensenBOOTCFLAGS += -fno-stack-protector 34fda7ffd2SNiels Kristian Bech Jensenendif 35fda7ffd2SNiels Kristian Bech Jensen 3694b212c2SPaul MackerrasBOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) 3794b212c2SPaul Mackerras 38869680c1SJosh Boyer$(obj)/4xx.o: BOOTCFLAGS += -mcpu=440 39988519acSDavid Gibson$(obj)/ebony.o: BOOTCFLAGS += -mcpu=440 402e71cc0dSJosh Boyer$(obj)/treeboot-walnut.o: BOOTCFLAGS += -mcpu=405 4160e41753SJosh Boyer 422bf11819SPaul Mackerraszlib := inffast.c inflate.c inftrees.c 432bf11819SPaul Mackerraszlibheader := inffast.h inffixed.h inflate.h inftrees.h infutil.h 442bf11819SPaul Mackerraszliblinuxheader := zlib.h zconf.h zutil.h 452bf11819SPaul Mackerras 46d25a9d66SDavid Gibson$(addprefix $(obj)/,$(zlib) gunzip_util.o main.o): \ 47d25a9d66SDavid Gibson $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader)) 482bf11819SPaul Mackerras 49cd197ffcSDavid Gibsonsrc-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \ 50ad9d2716SDavid Gibson ns16550.c serial.c simple_alloc.c div64.S util.S \ 512e601613SDavid Gibson gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \ 52d0f53fafSScott Wood 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \ 53bbc6fac3SScott Wood cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c \ 54bbc6fac3SScott Wood fsl-soc.c mpc8xx.c pq2.c 5585498ae8SGrant Likelysrc-plat := of.c cuboot-52xx.c cuboot-83xx.c cuboot-85xx.c holly.c \ 56bafdb645SGeoff Levand cuboot-ebony.c treeboot-ebony.c prpmc2800.c \ 57606d08bcSValentine Barshak ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \ 5811c146ccSScott Wood cuboot-pq2.c cuboot-sequoia.c treeboot-walnut.c cuboot-bamboo.c \ 59c4e05bc5SRoy Zang fixed-head.S ep88xc.c cuboot-hpc2.c 60cd197ffcSDavid Gibsonsrc-boot := $(src-wlib) $(src-plat) empty.c 612bf11819SPaul Mackerras 622bf11819SPaul Mackerrassrc-boot := $(addprefix $(obj)/, $(src-boot)) 632bf11819SPaul Mackerrasobj-boot := $(addsuffix .o, $(basename $(src-boot))) 642bf11819SPaul Mackerrasobj-wlib := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-wlib)))) 652bf11819SPaul Mackerrasobj-plat := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-plat)))) 662bf11819SPaul Mackerras 6794b212c2SPaul Mackerrasquiet_cmd_copy_zlib = COPY $@ 6867ccd2fcSSegher Boessenkool cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@ 6994b212c2SPaul Mackerras 7094b212c2SPaul Mackerrasquiet_cmd_copy_zlibheader = COPY $@ 7167ccd2fcSSegher Boessenkool cmd_copy_zlibheader = sed "s@<linux/\([^>]*\).*@\"\1\"@" $< > $@ 7294b212c2SPaul Mackerras# stddef.h for NULL 7394b212c2SPaul Mackerrasquiet_cmd_copy_zliblinuxheader = COPY $@ 7467ccd2fcSSegher Boessenkool cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@ 7594b212c2SPaul Mackerras 7694b212c2SPaul Mackerras$(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/% 7794b212c2SPaul Mackerras $(call cmd,copy_zlib) 7894b212c2SPaul Mackerras 7994b212c2SPaul Mackerras$(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/% 8094b212c2SPaul Mackerras $(call cmd,copy_zlibheader) 8194b212c2SPaul Mackerras 8294b212c2SPaul Mackerras$(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/% 8394b212c2SPaul Mackerras $(call cmd,copy_zliblinuxheader) 8494b212c2SPaul Mackerras 852bf11819SPaul Mackerras$(obj)/empty.c: 862bf11819SPaul Mackerras @touch $@ 8794b212c2SPaul Mackerras 88bafdb645SGeoff Levand$(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds: $(obj)/%: $(srctree)/$(src)/%.S 892bf11819SPaul Mackerras @cp $< $@ 902bf11819SPaul Mackerras 912bf11819SPaul Mackerrasclean-files := $(zlib) $(zlibheader) $(zliblinuxheader) \ 92bafdb645SGeoff Levand empty.c zImage zImage.coff.lds zImage.ps3.lds zImage.lds 9394b212c2SPaul Mackerras 9494b212c2SPaul Mackerrasquiet_cmd_bootcc = BOOTCC $@ 9594b212c2SPaul Mackerras cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $< 9694b212c2SPaul Mackerras 9794b212c2SPaul Mackerrasquiet_cmd_bootas = BOOTAS $@ 9894b212c2SPaul Mackerras cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $< 9994b212c2SPaul Mackerras 1002bf11819SPaul Mackerrasquiet_cmd_bootar = BOOTAR $@ 101235fd835SMilton Miller cmd_bootar = $(CROSS32AR) -cr $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@ 10294b212c2SPaul Mackerras 103235fd835SMilton Miller$(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c FORCE 10494b212c2SPaul Mackerras $(call if_changed_dep,bootcc) 105235fd835SMilton Miller$(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE 10694b212c2SPaul Mackerras $(call if_changed_dep,bootas) 10794b212c2SPaul Mackerras 108235fd835SMilton Miller$(obj)/wrapper.a: $(obj-wlib) FORCE 109235fd835SMilton Miller $(call if_changed,bootar) 11094b212c2SPaul Mackerras 1110cfcccb4SJosh Boyerhostprogs-y := addnote addRamDisk hack-coff mktree 11266a45dd3SPaul Mackerras 113235fd835SMilton Millertargets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a) 114cd197ffcSDavid Gibsonextra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \ 115bafdb645SGeoff Levand $(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds 11694b212c2SPaul Mackerras 1172bf11819SPaul Mackerraswrapper :=$(srctree)/$(src)/wrapper 11865b58039SMilton Millerwrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree) \ 119235fd835SMilton Miller $(wrapper) FORCE 12094b212c2SPaul Mackerras 1212bf11819SPaul Mackerras############# 1222bf11819SPaul Mackerras# Bits for building various flavours of zImage 12394b212c2SPaul Mackerras 1242bf11819SPaul Mackerrasifneq ($(CROSS32_COMPILE),) 125dcf90651SMichael EllermanCROSSWRAP := -C "$(CROSS32_COMPILE)" 1262bf11819SPaul Mackerraselse 1272bf11819SPaul Mackerrasifneq ($(CROSS_COMPILE),) 128dcf90651SMichael EllermanCROSSWRAP := -C "$(CROSS_COMPILE)" 1292bf11819SPaul Mackerrasendif 1302bf11819SPaul Mackerrasendif 13194b212c2SPaul Mackerras 1329da82a6dSMilton Miller# args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd 1332bf11819SPaul Mackerrasquiet_cmd_wrap = WRAP $@ 1349da82a6dSMilton Miller cmd_wrap =$(CONFIG_SHELL) $(wrapper) -c -o $@ -p $2 $(CROSSWRAP) \ 1359da82a6dSMilton Miller $(if $3, -s $3)$(if $4, -d $4)$(if $5, -i $5) vmlinux 1362bf11819SPaul Mackerras 1372bf11819SPaul Mackerrasimage-$(CONFIG_PPC_PSERIES) += zImage.pseries 1382bf11819SPaul Mackerrasimage-$(CONFIG_PPC_MAPLE) += zImage.pseries 139020533efSGeoff Levandimage-$(CONFIG_PPC_IBM_CELL_BLADE) += zImage.pseries 1408a8944aaSGeoff Levandimage-$(CONFIG_PPC_PS3) += zImage.ps3 141c347b798SIshizaki Kouimage-$(CONFIG_PPC_CELLEB) += zImage.pseries 1422bf11819SPaul Mackerrasimage-$(CONFIG_PPC_CHRP) += zImage.chrp 1437839af33SNicolas DETimage-$(CONFIG_PPC_EFIKA) += zImage.chrp 1442bf11819SPaul Mackerrasimage-$(CONFIG_PPC_PMAC) += zImage.pmac 145b0e80206SMark A. Greerimage-$(CONFIG_PPC_HOLLY) += zImage.holly 146c368d921SMark A. Greerimage-$(CONFIG_PPC_PRPMC2800) += zImage.prpmc2800 1470570d4edSStephen Rothwellimage-$(CONFIG_PPC_ISERIES) += zImage.iseries 148ac18c673SScott Woodimage-$(CONFIG_DEFAULT_UIMAGE) += uImage 149ac18c673SScott Wood 150ac18c673SScott Woodifneq ($(CONFIG_DEVICE_TREE),"") 1510b195812SScott Woodimage-$(CONFIG_PPC_8xx) += cuImage.8xx 15211c146ccSScott Woodimage-$(CONFIG_PPC_EP88XC) += zImage.ep88xc 153e5d8d54dSScott Woodimage-$(CONFIG_8260) += cuImage.pq2 15485498ae8SGrant Likelyimage-$(CONFIG_PPC_MPC52xx) += cuImage.52xx 155a6afacb6SDavid Gibsonimage-$(CONFIG_PPC_83xx) += cuImage.83xx 156a6afacb6SDavid Gibsonimage-$(CONFIG_PPC_85xx) += cuImage.85xx 157c4e05bc5SRoy Zangimage-$(CONFIG_MPC7448HPC2) += cuImage.hpc2 158f6dfc805SDavid Gibsonimage-$(CONFIG_EBONY) += treeImage.ebony cuImage.ebony 159658e8170SJosh Boyerimage-$(CONFIG_BAMBOO) += treeImage.bamboo cuImage.bamboo 160606d08bcSValentine Barshakimage-$(CONFIG_SEQUOIA) += cuImage.sequoia 1615326152fSJosh Boyerimage-$(CONFIG_WALNUT) += treeImage.walnut 162ac18c673SScott Woodendif 16394b212c2SPaul Mackerras 1649216ad8cSPaul Mackerras# For 32-bit powermacs, build the COFF and miboot images 1659216ad8cSPaul Mackerras# as well as the ELF images. 1662bf11819SPaul Mackerrasifeq ($(CONFIG_PPC32),y) 1672bf11819SPaul Mackerrasimage-$(CONFIG_PPC_PMAC) += zImage.coff zImage.miboot 1682bf11819SPaul Mackerrasendif 16966a45dd3SPaul Mackerras 1705d7960ffSMilton Millerinitrd- := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-)) 171f6dfc805SDavid Gibsoninitrd-y := $(patsubst zImage%, zImage.initrd%, \ 172f6dfc805SDavid Gibson $(patsubst treeImage%, treeImage.initrd%, $(image-y))) 1739da82a6dSMilton Millerinitrd-y := $(filter-out $(image-y), $(initrd-y)) 174235fd835SMilton Millertargets += $(image-y) $(initrd-y) 17594b212c2SPaul Mackerras 1769da82a6dSMilton Miller$(addprefix $(obj)/, $(initrd-y)): $(obj)/ramdisk.image.gz 1779da82a6dSMilton Miller 178a00cec48SMark A. Greer# If CONFIG_WANT_DEVICE_TREE is set and CONFIG_DEVICE_TREE isn't an 179a00cec48SMark A. Greer# empty string, define 'dts' to be path to the dts 180a00cec48SMark A. Greer# CONFIG_DEVICE_TREE will have "" around it, make sure to strip them 181a00cec48SMark A. Greerifeq ($(CONFIG_WANT_DEVICE_TREE),y) 182a00cec48SMark A. Greerifneq ($(CONFIG_DEVICE_TREE),"") 183a00cec48SMark A. Greerdts = $(if $(shell echo $(CONFIG_DEVICE_TREE) | grep '^/'),\ 184a00cec48SMark A. Greer ,$(srctree)/$(src)/dts/)$(CONFIG_DEVICE_TREE:"%"=%) 185a00cec48SMark A. Greerendif 186a00cec48SMark A. Greerendif 187a00cec48SMark A. Greer 1889da82a6dSMilton Miller# Don't put the ramdisk on the pattern rule; when its missing make will try 1899da82a6dSMilton Miller# the pattern rule with less dependencies that also matches (even with the 1909da82a6dSMilton Miller# hard dependency listed). 191a00cec48SMark A. Greer$(obj)/zImage.initrd.%: vmlinux $(wrapperbits) $(dts) 192a00cec48SMark A. Greer $(call if_changed,wrap,$*,$(dts),,$(obj)/ramdisk.image.gz) 1939da82a6dSMilton Miller 194a00cec48SMark A. Greer$(obj)/zImage.%: vmlinux $(wrapperbits) $(dts) 195a00cec48SMark A. Greer $(call if_changed,wrap,$*,$(dts)) 1969da82a6dSMilton Miller 1974bb09281STony Breeds# This cannot be in the root of $(src) as the zImage rule always adds a $(obj) 1984bb09281STony Breeds# prefix 1994bb09281STony Breeds$(obj)/vmlinux.strip: vmlinux 2004bb09281STony Breeds $(STRIP) -s -R .comment $< -o $@ 2014bb09281STony Breeds 2020570d4edSStephen Rothwell$(obj)/zImage.iseries: vmlinux 2030570d4edSStephen Rothwell $(STRIP) -s -R .comment $< -o $@ 2040570d4edSStephen Rothwell 205bafdb645SGeoff Levand$(obj)/zImage.ps3: vmlinux $(wrapper) $(wrapperbits) $(srctree)/$(src)/dts/ps3.dts 206bafdb645SGeoff Levand $(STRIP) -s -R .comment $< -o vmlinux.strip 207bafdb645SGeoff Levand $(call cmd,wrap,ps3,$(srctree)/$(src)/dts/ps3.dts,,) 2089da82a6dSMilton Miller 209bafdb645SGeoff Levand$(obj)/zImage.initrd.ps3: vmlinux $(wrapper) $(wrapperbits) $(srctree)/$(src)/dts/ps3.dts $(obj)/ramdisk.image.gz 210bafdb645SGeoff Levand $(call cmd,wrap,ps3,$(srctree)/$(src)/dts/ps3.dts,,$(obj)/ramdisk.image.gz) 2119da82a6dSMilton Miller 2129da82a6dSMilton Miller$(obj)/uImage: vmlinux $(wrapperbits) 2139da82a6dSMilton Miller $(call if_changed,wrap,uboot) 2149da82a6dSMilton Miller 215d25a9d66SDavid Gibson$(obj)/cuImage.%: vmlinux $(dts) $(wrapperbits) 216a6afacb6SDavid Gibson $(call if_changed,wrap,cuboot-$*,$(dts)) 2170fdd717eSScott Wood 218f6dfc805SDavid Gibson$(obj)/treeImage.initrd.%: vmlinux $(dts) $(wrapperbits) 219f6dfc805SDavid Gibson $(call if_changed,wrap,treeboot-$*,$(dts),,$(obj)/ramdisk.image.gz) 220f6dfc805SDavid Gibson 2216a32d085SDavid Gibson$(obj)/treeImage.%: vmlinux $(dts) $(wrapperbits) 2226a32d085SDavid Gibson $(call if_changed,wrap,treeboot-$*,$(dts)) 2236a32d085SDavid Gibson 2244bb09281STony Breeds# If there isn't a platform selected then just strip the vmlinux. 2254bb09281STony Breedsifeq (,$(image-y)) 2264bb09281STony Breedsimage-y := vmlinux.strip 2274bb09281STony Breedsendif 2284bb09281STony Breeds 2292bf11819SPaul Mackerras$(obj)/zImage: $(addprefix $(obj)/, $(image-y)) 2302bf11819SPaul Mackerras @rm -f $@; ln $< $@ 2312bf11819SPaul Mackerras$(obj)/zImage.initrd: $(addprefix $(obj)/, $(initrd-y)) 2322bf11819SPaul Mackerras @rm -f $@; ln $< $@ 23394b212c2SPaul Mackerras 234928370c6SAkinobu Mitainstall: $(CONFIGURE) $(addprefix $(obj)/, $(image-y)) 2352bf11819SPaul Mackerras sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" $< 23666a45dd3SPaul Mackerras 2371383a34fSMilton Miller# anything not in $(targets) 238bafdb645SGeoff Levandclean-files += $(image-) $(initrd-) zImage zImage.initrd cuImage.* treeImage.* \ 239bafdb645SGeoff Levand otheros.bld 2401383a34fSMilton Miller 2411383a34fSMilton Miller# clean up files cached by wrapper 2421383a34fSMilton Millerclean-kernel := vmlinux.strip vmlinux.bin 2431383a34fSMilton Millerclean-kernel += $(addsuffix .gz,$(clean-kernel)) 2441383a34fSMilton Miller# If not absolute clean-files are relative to $(obj). 2451383a34fSMilton Millerclean-files += $(addprefix $(objtree)/, $(clean-kernel)) 246