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. 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 23 24HOSTCC := gcc 25BOOTCFLAGS := $(HOSTCFLAGS) -fno-builtin -nostdinc -isystem \ 26 $(shell $(CROSS32CC) -print-file-name=include) -fPIC 27BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc 28OBJCOPYFLAGS := contents,alloc,load,readonly,data 29OBJCOPY_COFF_ARGS := -O aixcoff-rs6000 --set-start 0x500000 30OBJCOPY_MIB_ARGS := -O aixcoff-rs6000 -R .stab -R .stabstr -R .comment 31 32zlib := inffast.c inflate.c inftrees.c 33zlibheader := inffast.h inffixed.h inflate.h inftrees.h infutil.h 34zliblinuxheader := zlib.h zconf.h zutil.h 35 36$(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader)) 37#$(addprefix $(obj)/,main.o): $(addprefix $(obj)/,zlib.h) 38 39src-boot-$(CONFIG_PPC_MULTIPLATFORM) := of.c 40src-boot := crt0.S string.S stdio.c main.c div64.S $(src-boot-y) 41src-boot += $(zlib) 42src-boot := $(addprefix $(obj)/, $(src-boot)) 43obj-boot := $(addsuffix .o, $(basename $(src-boot))) 44 45ifeq ($(call cc-option-yn, -fstack-protector),y) 46BOOTCFLAGS += -fno-stack-protector 47endif 48 49BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj) 50 51quiet_cmd_copy_zlib = COPY $@ 52 cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@ 53 54quiet_cmd_copy_zlibheader = COPY $@ 55 cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@ 56# stddef.h for NULL 57quiet_cmd_copy_zliblinuxheader = COPY $@ 58 cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@ 59 60$(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/% 61 $(call cmd,copy_zlib) 62 63$(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/% 64 $(call cmd,copy_zlibheader) 65 66$(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/% 67 $(call cmd,copy_zliblinuxheader) 68 69clean-files := $(zlib) $(zlibheader) $(zliblinuxheader) 70 71 72quiet_cmd_bootcc = BOOTCC $@ 73 cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $< 74 75quiet_cmd_bootas = BOOTAS $@ 76 cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $< 77 78quiet_cmd_bootld = BOOTLD $@ 79 cmd_bootld = $(CROSS32LD) -T $(srctree)/$(src)/$(3) -o $@ $(2) 80 81$(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c 82 $(call if_changed_dep,bootcc) 83$(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S 84 $(call if_changed_dep,bootas) 85 86#----------------------------------------------------------- 87# ELF sections within the zImage bootloader/wrapper 88#----------------------------------------------------------- 89required := vmlinux.strip 90initrd := initrd 91 92obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section))) 93src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section))) 94gz-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section))) 95 96hostprogs-y := addnote addRamDisk hack-coff 97 98targets += zImage.vmode zImage.initrd.vmode zImage zImage.initrd \ 99 zImage.coff zImage.initrd.coff miboot.image miboot.initrd.image \ 100 $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \ 101 $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \ 102 $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \ 103 vmlinux.initrd dummy.o 104extra-y := initrd.o 105 106quiet_cmd_ramdisk = RAMDISK $@ 107 cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@ 108 109quiet_cmd_stripvm = STRIP $@ 110 cmd_stripvm = $(STRIP) -s -R .comment $< -o $@ 111 112vmlinux.strip: vmlinux 113 $(call if_changed,stripvm) 114$(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz 115 $(call if_changed,ramdisk) 116 117quiet_cmd_addsection = ADDSEC $@ 118 cmd_addsection = $(CROSS32OBJCOPY) $@ \ 119 --add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(patsubst %.o,%.gz, $@) \ 120 --set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(OBJCOPYFLAGS) 121 122quiet_cmd_addnote = ADDNOTE $@ 123 cmd_addnote = $(obj)/addnote $@ 124 125quiet_cmd_gen-miboot = GEN $@ 126 cmd_gen-miboot = $(OBJCOPY) $(OBJCOPY_MIB_ARGS) \ 127 --add-section=$1=$(word 2, $^) $< $@ 128 129quiet_cmd_gencoff = COFF $@ 130 cmd_gencoff = $(OBJCOPY) $(OBJCOPY_COFF_ARGS) $@ && \ 131 $(obj)/hack-coff $@ 132 133$(call gz-sec, $(required)): $(obj)/kernel-%.gz: % 134 $(call if_changed,gzip) 135 136$(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz 137 cp -f $(obj)/ramdisk.image.gz $@ 138 139$(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz 140 @touch $@ 141 142$(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c 143 $(call if_changed_dep,bootcc) 144 $(call cmd,addsection) 145 146$(obj)/zImage.vmode $(obj)/zImage.coff: obj-boot += $(call obj-sec, $(required)) 147$(obj)/zImage.vmode: $(call obj-sec, $(required)) $(obj-boot) $(srctree)/$(src)/zImage.lds 148 $(call cmd,bootld,$(obj-boot),zImage.lds) 149 150$(obj)/zImage.initrd.vmode $(obj)/zImage.initrd.coff: obj-boot += $(call obj-sec, $(required) $(initrd)) 151$(obj)/zImage.initrd.vmode: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(srctree)/$(src)/zImage.lds 152 $(call cmd,bootld,$(obj-boot),zImage.lds) 153 154# For 32-bit powermacs, build the COFF and miboot images 155# as well as the ELF images. 156coffimage-$(CONFIG_PPC_PMAC)-$(CONFIG_PPC32) := $(obj)/zImage.coff 157coffrdimg-$(CONFIG_PPC_PMAC)-$(CONFIG_PPC32) := $(obj)/zImage.initrd.coff 158mibootimg-$(CONFIG_PPC_PMAC)-$(CONFIG_PPC32) := $(obj)/miboot.image 159mibrdimg-$(CONFIG_PPC_PMAC)-$(CONFIG_PPC32) := $(obj)/miboot.initrd.image 160 161$(obj)/zImage: $(obj)/zImage.vmode $(obj)/addnote $(coffimage-y-y) \ 162 $(mibootimg-y-y) 163 @cp -f $< $@ 164 $(call if_changed,addnote) 165 166$(obj)/zImage.initrd: $(obj)/zImage.initrd.vmode $(obj)/addnote \ 167 $(coffrdimg-y-y) $(mibrdimg-y-y) 168 @cp -f $< $@ 169 $(call if_changed,addnote) 170 171$(obj)/zImage.coff: $(call obj-sec, $(required)) $(obj-boot) \ 172 $(srctree)/$(src)/zImage.coff.lds $(obj)/hack-coff 173 $(call cmd,bootld,$(obj-boot),zImage.coff.lds) 174 $(call cmd,gencoff) 175 176$(obj)/zImage.initrd.coff: $(call obj-sec, $(required) $(initrd)) $(obj-boot) \ 177 $(srctree)/$(src)/zImage.coff.lds $(obj)/hack-coff 178 $(call cmd,bootld,$(obj-boot),zImage.coff.lds) 179 $(call cmd,gencoff) 180 181$(obj)/miboot.image: $(obj)/dummy.o $(obj)/vmlinux.gz 182 $(call cmd,gen-miboot,image) 183 184$(obj)/miboot.initrd.image: $(obj)/miboot.image $(images)/ramdisk.image.gz 185 $(call cmd,gen-miboot,initrd) 186 187#----------------------------------------------------------- 188# build u-boot images 189#----------------------------------------------------------- 190quiet_cmd_mygzip = GZIP $@ 191cmd_mygzip = gzip -f -9 < $< > $@.$$$$ && mv $@.$$$$ $@ 192 193quiet_cmd_objbin = OBJCOPY $@ 194 cmd_objbin = $(OBJCOPY) -O binary $< $@ 195 196quiet_cmd_uimage = UIMAGE $@ 197 cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A ppc -O linux -T kernel \ 198 -C gzip -a 00000000 -e 00000000 -n 'Linux-$(KERNELRELEASE)' \ 199 -d $< $@ 200 201MKIMAGE := $(srctree)/scripts/mkuboot.sh 202targets += uImage 203extra-y += vmlinux.bin vmlinux.gz 204 205$(obj)/vmlinux.bin: vmlinux FORCE 206 $(call if_changed,objbin) 207 208$(obj)/vmlinux.gz: $(obj)/vmlinux.bin FORCE 209 $(call if_changed,mygzip) 210 211$(obj)/uImage: $(obj)/vmlinux.gz 212 $(Q)rm -f $@ 213 $(call cmd,uimage) 214 @echo -n ' Image: $@ ' 215 @if [ -f $@ ]; then echo 'is ready' ; else echo 'not made'; fi 216 217install: $(CONFIGURE) $(BOOTIMAGE) 218 sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" "$(BOOTIMAGE)" 219 220clean-files += $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip) 221