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