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 1494b212c2SPaul Mackerras# needed to build the 32 bit image. These are normally HOSTCC, 1594b212c2SPaul Mackerras# but may be a third compiler if, for example, you are cross 1694b212c2SPaul Mackerras# compiling from an intel box. Once the 64bit ppc gcc is 1794b212c2SPaul Mackerras# stable it will probably simply be a compiler switch to 1894b212c2SPaul Mackerras# compile for 32bit mode. 1994b212c2SPaul Mackerras# To make it easier to setup a cross compiler, 2094b212c2SPaul Mackerras# CROSS32_COMPILE is setup as a prefix just like CROSS_COMPILE 2194b212c2SPaul Mackerras# in the toplevel makefile. 2294b212c2SPaul Mackerras 232bf11819SPaul Mackerrasall: $(obj)/zImage 2494b212c2SPaul Mackerras 2594b212c2SPaul MackerrasHOSTCC := gcc 2694b212c2SPaul MackerrasBOOTCFLAGS := $(HOSTCFLAGS) -fno-builtin -nostdinc -isystem \ 2794b212c2SPaul Mackerras $(shell $(CROSS32CC) -print-file-name=include) -fPIC 2894b212c2SPaul MackerrasBOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc 2994b212c2SPaul Mackerras 30fda7ffd2SNiels Kristian Bech Jensenifeq ($(call cc-option-yn, -fstack-protector),y) 31fda7ffd2SNiels Kristian Bech JensenBOOTCFLAGS += -fno-stack-protector 32fda7ffd2SNiels Kristian Bech Jensenendif 33fda7ffd2SNiels Kristian Bech Jensen 3494b212c2SPaul MackerrasBOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) 3594b212c2SPaul Mackerras 362bf11819SPaul Mackerraszlib := inffast.c inflate.c inftrees.c 372bf11819SPaul Mackerraszlibheader := inffast.h inffixed.h inflate.h inftrees.h infutil.h 382bf11819SPaul Mackerraszliblinuxheader := zlib.h zconf.h zutil.h 392bf11819SPaul Mackerras 40d25a9d66SDavid Gibson$(addprefix $(obj)/,$(zlib) gunzip_util.o main.o): \ 41d25a9d66SDavid Gibson $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader)) 422bf11819SPaul Mackerras 43cd197ffcSDavid Gibsonsrc-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \ 44ad9d2716SDavid Gibson ns16550.c serial.c simple_alloc.c div64.S util.S \ 45*f6dfc805SDavid Gibson gunzip_util.c elf_util.c $(zlib) devtree.c \ 46*f6dfc805SDavid Gibson 44x.c ebony.c 47*f6dfc805SDavid Gibsonsrc-plat := of.c cuboot-83xx.c cuboot-85xx.c holly.c \ 48*f6dfc805SDavid Gibson cuboot-ebony.c treeboot-ebony.c 49cd197ffcSDavid Gibsonsrc-boot := $(src-wlib) $(src-plat) empty.c 502bf11819SPaul Mackerras 512bf11819SPaul Mackerrassrc-boot := $(addprefix $(obj)/, $(src-boot)) 522bf11819SPaul Mackerrasobj-boot := $(addsuffix .o, $(basename $(src-boot))) 532bf11819SPaul Mackerrasobj-wlib := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-wlib)))) 542bf11819SPaul Mackerrasobj-plat := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-plat)))) 552bf11819SPaul Mackerras 5694b212c2SPaul Mackerrasquiet_cmd_copy_zlib = COPY $@ 5794b212c2SPaul Mackerras cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@ 5894b212c2SPaul Mackerras 5994b212c2SPaul Mackerrasquiet_cmd_copy_zlibheader = COPY $@ 6094b212c2SPaul Mackerras cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@ 6194b212c2SPaul Mackerras# stddef.h for NULL 6294b212c2SPaul Mackerrasquiet_cmd_copy_zliblinuxheader = COPY $@ 6394b212c2SPaul Mackerras cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@ 6494b212c2SPaul Mackerras 6594b212c2SPaul Mackerras$(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/% 6694b212c2SPaul Mackerras $(call cmd,copy_zlib) 6794b212c2SPaul Mackerras 6894b212c2SPaul Mackerras$(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/% 6994b212c2SPaul Mackerras $(call cmd,copy_zlibheader) 7094b212c2SPaul Mackerras 7194b212c2SPaul Mackerras$(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/% 7294b212c2SPaul Mackerras $(call cmd,copy_zliblinuxheader) 7394b212c2SPaul Mackerras 742bf11819SPaul Mackerras$(obj)/empty.c: 752bf11819SPaul Mackerras @touch $@ 7694b212c2SPaul Mackerras 772bf11819SPaul Mackerras$(obj)/zImage.lds $(obj)/zImage.coff.lds: $(obj)/%: $(srctree)/$(src)/%.S 782bf11819SPaul Mackerras @cp $< $@ 792bf11819SPaul Mackerras 802bf11819SPaul Mackerrasclean-files := $(zlib) $(zlibheader) $(zliblinuxheader) \ 815d7960ffSMilton Miller empty.c zImage.coff.lds zImage.lds 8294b212c2SPaul Mackerras 8394b212c2SPaul Mackerrasquiet_cmd_bootcc = BOOTCC $@ 8494b212c2SPaul Mackerras cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $< 8594b212c2SPaul Mackerras 8694b212c2SPaul Mackerrasquiet_cmd_bootas = BOOTAS $@ 8794b212c2SPaul Mackerras cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $< 8894b212c2SPaul Mackerras 892bf11819SPaul Mackerrasquiet_cmd_bootar = BOOTAR $@ 90235fd835SMilton Miller cmd_bootar = $(CROSS32AR) -cr $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@ 9194b212c2SPaul Mackerras 92235fd835SMilton Miller$(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c FORCE 9394b212c2SPaul Mackerras $(call if_changed_dep,bootcc) 94235fd835SMilton Miller$(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE 9594b212c2SPaul Mackerras $(call if_changed_dep,bootas) 9694b212c2SPaul Mackerras 97235fd835SMilton Miller$(obj)/wrapper.a: $(obj-wlib) FORCE 98235fd835SMilton Miller $(call if_changed,bootar) 9994b212c2SPaul Mackerras 1000cfcccb4SJosh Boyerhostprogs-y := addnote addRamDisk hack-coff mktree 10166a45dd3SPaul Mackerras 102235fd835SMilton Millertargets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a) 103cd197ffcSDavid Gibsonextra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \ 1042bf11819SPaul Mackerras $(obj)/zImage.lds $(obj)/zImage.coff.lds 10594b212c2SPaul Mackerras 1062bf11819SPaul Mackerraswrapper :=$(srctree)/$(src)/wrapper 10765b58039SMilton Millerwrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree) \ 108235fd835SMilton Miller $(wrapper) FORCE 10994b212c2SPaul Mackerras 1102bf11819SPaul Mackerras############# 1112bf11819SPaul Mackerras# Bits for building various flavours of zImage 11294b212c2SPaul Mackerras 1132bf11819SPaul Mackerrasifneq ($(CROSS32_COMPILE),) 114dcf90651SMichael EllermanCROSSWRAP := -C "$(CROSS32_COMPILE)" 1152bf11819SPaul Mackerraselse 1162bf11819SPaul Mackerrasifneq ($(CROSS_COMPILE),) 117dcf90651SMichael EllermanCROSSWRAP := -C "$(CROSS_COMPILE)" 1182bf11819SPaul Mackerrasendif 1192bf11819SPaul Mackerrasendif 12094b212c2SPaul Mackerras 1219da82a6dSMilton Miller# args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd 1222bf11819SPaul Mackerrasquiet_cmd_wrap = WRAP $@ 1239da82a6dSMilton Miller cmd_wrap =$(CONFIG_SHELL) $(wrapper) -c -o $@ -p $2 $(CROSSWRAP) \ 1249da82a6dSMilton Miller $(if $3, -s $3)$(if $4, -d $4)$(if $5, -i $5) vmlinux 1252bf11819SPaul Mackerras 1262bf11819SPaul Mackerrasimage-$(CONFIG_PPC_PSERIES) += zImage.pseries 1272bf11819SPaul Mackerrasimage-$(CONFIG_PPC_MAPLE) += zImage.pseries 128020533efSGeoff Levandimage-$(CONFIG_PPC_IBM_CELL_BLADE) += zImage.pseries 1298a8944aaSGeoff Levandimage-$(CONFIG_PPC_PS3) += zImage.ps3 130c347b798SIshizaki Kouimage-$(CONFIG_PPC_CELLEB) += zImage.pseries 1312bf11819SPaul Mackerrasimage-$(CONFIG_PPC_CHRP) += zImage.chrp 1327839af33SNicolas DETimage-$(CONFIG_PPC_EFIKA) += zImage.chrp 1332bf11819SPaul Mackerrasimage-$(CONFIG_PPC_PMAC) += zImage.pmac 1347487a224SJosh Boyerimage-$(CONFIG_PPC_HOLLY) += zImage.holly-elf 135ac18c673SScott Woodimage-$(CONFIG_DEFAULT_UIMAGE) += uImage 136ac18c673SScott Wood 137ac18c673SScott Woodifneq ($(CONFIG_DEVICE_TREE),"") 138a6afacb6SDavid Gibsonimage-$(CONFIG_PPC_83xx) += cuImage.83xx 139a6afacb6SDavid Gibsonimage-$(CONFIG_PPC_85xx) += cuImage.85xx 140*f6dfc805SDavid Gibsonimage-$(CONFIG_EBONY) += treeImage.ebony cuImage.ebony 141ac18c673SScott Woodendif 14294b212c2SPaul Mackerras 1439216ad8cSPaul Mackerras# For 32-bit powermacs, build the COFF and miboot images 1449216ad8cSPaul Mackerras# as well as the ELF images. 1452bf11819SPaul Mackerrasifeq ($(CONFIG_PPC32),y) 1462bf11819SPaul Mackerrasimage-$(CONFIG_PPC_PMAC) += zImage.coff zImage.miboot 1472bf11819SPaul Mackerrasendif 14866a45dd3SPaul Mackerras 1495d7960ffSMilton Millerinitrd- := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-)) 150*f6dfc805SDavid Gibsoninitrd-y := $(patsubst zImage%, zImage.initrd%, \ 151*f6dfc805SDavid Gibson $(patsubst treeImage%, treeImage.initrd%, $(image-y))) 1529da82a6dSMilton Millerinitrd-y := $(filter-out $(image-y), $(initrd-y)) 153235fd835SMilton Millertargets += $(image-y) $(initrd-y) 15494b212c2SPaul Mackerras 1559da82a6dSMilton Miller$(addprefix $(obj)/, $(initrd-y)): $(obj)/ramdisk.image.gz 1569da82a6dSMilton Miller 1579da82a6dSMilton Miller# Don't put the ramdisk on the pattern rule; when its missing make will try 1589da82a6dSMilton Miller# the pattern rule with less dependencies that also matches (even with the 1599da82a6dSMilton Miller# hard dependency listed). 1609da82a6dSMilton Miller$(obj)/zImage.initrd.%: vmlinux $(wrapperbits) 1619da82a6dSMilton Miller $(call if_changed,wrap,$*,,,$(obj)/ramdisk.image.gz) 1629da82a6dSMilton Miller 1639da82a6dSMilton Miller$(obj)/zImage.%: vmlinux $(wrapperbits) 1649da82a6dSMilton Miller $(call if_changed,wrap,$*) 1659da82a6dSMilton Miller 1669da82a6dSMilton Miller$(obj)/zImage.ps3: vmlinux 1679da82a6dSMilton Miller $(STRIP) -s -R .comment $< -o $@ 1689da82a6dSMilton Miller 1699da82a6dSMilton Miller$(obj)/zImage.initrd.ps3: vmlinux 1709da82a6dSMilton Miller @echo " WARNING zImage.initrd.ps3 not supported (yet)" 1719da82a6dSMilton Miller 1727487a224SJosh Boyer$(obj)/zImage.holly-elf: vmlinux $(wrapperbits) 1737487a224SJosh Boyer $(call if_changed,wrap,holly,$(obj)/dts/holly.dts,,) 1747487a224SJosh Boyer 1757487a224SJosh Boyer$(obj)/zImage.initrd.holly-elf: vmlinux $(wrapperbits) $(obj)/ramdisk.image.gz 1767487a224SJosh Boyer $(call if_changed,wrap,holly,$(obj)/dts/holly.dts,,$(obj)/ramdisk.image.gz) 1777487a224SJosh Boyer 1789da82a6dSMilton Miller$(obj)/uImage: vmlinux $(wrapperbits) 1799da82a6dSMilton Miller $(call if_changed,wrap,uboot) 1809da82a6dSMilton Miller 181d25a9d66SDavid Gibson# CONFIG_DEVICE_TREE will have "" around it, make sure to strip them 182d818d7ecSScott Wooddts = $(if $(shell echo $(CONFIG_DEVICE_TREE) | grep '^/'),\ 183d25a9d66SDavid Gibson ,$(srctree)/$(src)/dts/)$(CONFIG_DEVICE_TREE:"%"=%) 1840fdd717eSScott Wood 185d25a9d66SDavid Gibson$(obj)/cuImage.%: vmlinux $(dts) $(wrapperbits) 186a6afacb6SDavid Gibson $(call if_changed,wrap,cuboot-$*,$(dts)) 1870fdd717eSScott Wood 188*f6dfc805SDavid Gibson$(obj)/treeImage.%: vmlinux $(dts) $(wrapperbits) 189*f6dfc805SDavid Gibson $(call if_changed,wrap,treeboot-$*,$(dts)) 190*f6dfc805SDavid Gibson 191*f6dfc805SDavid Gibson$(obj)/treeImage.initrd.%: vmlinux $(dts) $(wrapperbits) 192*f6dfc805SDavid Gibson $(call if_changed,wrap,treeboot-$*,$(dts),,$(obj)/ramdisk.image.gz) 193*f6dfc805SDavid Gibson 1942bf11819SPaul Mackerras$(obj)/zImage: $(addprefix $(obj)/, $(image-y)) 1952bf11819SPaul Mackerras @rm -f $@; ln $< $@ 1962bf11819SPaul Mackerras$(obj)/zImage.initrd: $(addprefix $(obj)/, $(initrd-y)) 1972bf11819SPaul Mackerras @rm -f $@; ln $< $@ 19894b212c2SPaul Mackerras 199928370c6SAkinobu Mitainstall: $(CONFIGURE) $(addprefix $(obj)/, $(image-y)) 2002bf11819SPaul Mackerras sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" $< 20166a45dd3SPaul Mackerras 2021383a34fSMilton Miller# anything not in $(targets) 203*f6dfc805SDavid Gibsonclean-files += $(image-) $(initrd-) zImage zImage.initrd cuImage.* \ 204*f6dfc805SDavid Gibson treeImage.* 2051383a34fSMilton Miller 2061383a34fSMilton Miller# clean up files cached by wrapper 2071383a34fSMilton Millerclean-kernel := vmlinux.strip vmlinux.bin 2081383a34fSMilton Millerclean-kernel += $(addsuffix .gz,$(clean-kernel)) 2091383a34fSMilton Miller# If not absolute clean-files are relative to $(obj). 2101383a34fSMilton Millerclean-files += $(addprefix $(objtree)/, $(clean-kernel)) 211