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