1 # Makefile for making ELF bootable images for booting on CHRP
4 # Geert Uytterhoeven September 1997
6 # Based on coffboot by Paul Mackerras
7 # Simplified for ppc64 by Todd Inglett
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.
13 # To this end we need to define BOOTCC, etc, as the tools
14 # needed to build the 32 bit image. That's normally the same
15 # compiler for the rest of the kernel, with the -m32 flag added.
16 # To make it easier to setup a cross compiler,
17 # CROSS32_COMPILE is setup as a prefix just like CROSS_COMPILE
18 # in the toplevel makefile.
22 BOOTCFLAGS
:= -Wall
-Wundef
-Wstrict-prototypes
-Wno-trigraphs \
23 -fno-strict-aliasing
-Os
-msoft-float
-pipe \
24 -fomit-frame-pointer
-fno-builtin
-fPIC
-nostdinc \
25 -isystem
$(shell $(CROSS32CC
) -print-file-name
=include)
26 BOOTAFLAGS
:= -D__ASSEMBLY__
$(BOOTCFLAGS
) -traditional
-nostdinc
28 ifdef CONFIG_DEBUG_INFO
32 ifeq ($(call cc-option-yn
, -fstack-protector
),y
)
33 BOOTCFLAGS
+= -fno-stack-protector
36 BOOTCFLAGS
+= -I
$(obj
) -I
$(srctree
)/$(obj
) -I
$(srctree
)/$(src
)/libfdt
38 $(obj
)/4xx.o
: BOOTCFLAGS
+= -mcpu
=440
39 $(obj
)/ebony.o
: BOOTCFLAGS
+= -mcpu
=440
40 $(obj
)/cuboot-taishan.o
: BOOTCFLAGS
+= -mcpu
=440
41 $(obj
)/cuboot-katmai.o
: BOOTCFLAGS
+= -mcpu
=440
42 $(obj
)/treeboot-walnut.o
: BOOTCFLAGS
+= -mcpu
=405
45 zlib
:= inffast.c inflate.c inftrees.c
46 zlibheader
:= inffast.h inffixed.h inflate.h inftrees.h infutil.h
47 zliblinuxheader
:= zlib.h zconf.h zutil.h
49 $(addprefix $(obj
)/,$(zlib
) gunzip_util.o main.o
): \
50 $(addprefix $(obj
)/,$(zliblinuxheader
)) $(addprefix $(obj
)/,$(zlibheader
))
52 src-libfdt
:= fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c
53 src-wlib
:= string.S crt0.S stdio.c main.c \
54 $(addprefix libfdt
/,$(src-libfdt
)) libfdt-wrapper.c \
55 ns16550.c serial.c simple_alloc.c div64.S util.S \
56 gunzip_util.c elf_util.c
$(zlib
) devtree.c oflib.c ofconsole.c \
57 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \
58 cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c \
59 fsl-soc.c mpc8xx.c pq2.c
60 src-plat
:= of.c cuboot-52xx.c cuboot-824x.c cuboot-83xx.c cuboot-85xx.c holly.c \
61 cuboot-ebony.c treeboot-ebony.c prpmc2800.c \
62 ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \
63 cuboot-pq2.c cuboot-sequoia.c treeboot-walnut.c cuboot-bamboo.c \
64 fixed-head.S ep88xc.c cuboot-hpc2.c ep405.c cuboot-taishan.c \
65 cuboot-katmai.c cuboot-rainier.c redboot-8xx.c ep8248e.c \
66 cuboot-warp.c cuboot-85xx-cpm2.c
67 src-boot
:= $(src-wlib
) $(src-plat
) empty.c
69 src-boot
:= $(addprefix $(obj
)/, $(src-boot
))
70 obj-boot
:= $(addsuffix .o
, $(basename $(src-boot
)))
71 obj-wlib
:= $(addsuffix .o
, $(basename $(addprefix $(obj
)/, $(src-wlib
))))
72 obj-plat
:= $(addsuffix .o
, $(basename $(addprefix $(obj
)/, $(src-plat
))))
74 quiet_cmd_copy_zlib
= COPY
$@
75 cmd_copy_zlib
= sed
"s@__used@@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@
77 quiet_cmd_copy_zlibheader
= COPY
$@
78 cmd_copy_zlibheader
= sed
"s@<linux/\([^>]*\).*@\"\1\"@" $< > $@
80 quiet_cmd_copy_zliblinuxheader
= COPY
$@
81 cmd_copy_zliblinuxheader
= sed
"s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@
83 $(addprefix $(obj
)/,$(zlib
)): $(obj
)/%: $(srctree
)/lib
/zlib_inflate
/%
86 $(addprefix $(obj
)/,$(zlibheader
)): $(obj
)/%: $(srctree
)/lib
/zlib_inflate
/%
87 $(call cmd
,copy_zlibheader
)
89 $(addprefix $(obj
)/,$(zliblinuxheader
)): $(obj
)/%: $(srctree
)/include/linux
/%
90 $(call cmd
,copy_zliblinuxheader
)
95 $(obj
)/zImage.lds
$(obj
)/zImage.coff.lds
$(obj
)/zImage.ps3.lds
: $(obj
)/%: $(srctree
)/$(src
)/%.S
98 clean-files
:= $(zlib
) $(zlibheader
) $(zliblinuxheader
) \
99 empty.c zImage zImage.coff.lds zImage.ps3.lds zImage.lds
101 quiet_cmd_bootcc
= BOOTCC
$@
102 cmd_bootcc
= $(CROSS32CC
) -Wp
,-MD
,$(depfile
) $(BOOTCFLAGS
) -c
-o
$@
$<
104 quiet_cmd_bootas
= BOOTAS
$@
105 cmd_bootas
= $(CROSS32CC
) -Wp
,-MD
,$(depfile
) $(BOOTAFLAGS
) -c
-o
$@
$<
107 quiet_cmd_bootar
= BOOTAR
$@
108 cmd_bootar
= $(CROSS32AR
) -cr
$@.
$$$$ $(filter-out FORCE
,$^
); mv
$@.
$$$$ $@
110 $(patsubst %.c
,%.o
, $(filter %.c
, $(src-boot
))): %.o
: %.c FORCE
111 $(Q
)mkdir
-p
$(dir $@
)
112 $(call if_changed_dep
,bootcc
)
113 $(patsubst %.S
,%.o
, $(filter %.S
, $(src-boot
))): %.o
: %.S FORCE
114 $(Q
)mkdir
-p
$(dir $@
)
115 $(call if_changed_dep
,bootas
)
117 $(obj
)/wrapper.a
: $(obj-wlib
) FORCE
118 $(call if_changed
,bootar
)
120 hostprogs-y
:= addnote addRamDisk hack-coff mktree dtc
122 targets
+= $(patsubst $(obj
)/%,%,$(obj-boot
) wrapper.a
)
123 extra-y
:= $(obj
)/wrapper.a
$(obj-plat
) $(obj
)/empty.o \
124 $(obj
)/zImage.lds
$(obj
)/zImage.coff.lds
$(obj
)/zImage.ps3.lds
126 wrapper
:=$(srctree
)/$(src
)/wrapper
127 wrapperbits
:= $(extra-y
) $(addprefix $(obj
)/,addnote hack-coff mktree dtc
) \
131 # Bits for building dtc
132 # DTC_GENPARSER := 1 # Uncomment to rebuild flex/bison output
134 dtc-objs
:= dtc.o flattree.o fstree.o data.o livetree.o treesource.o srcpos.o checks.o
135 dtc-objs
+= dtc-lexer.
lex.o dtc-parser.tab.o
136 dtc-objs
:= $(addprefix dtc-src
/, $(dtc-objs
))
138 # prerequisites on generated files needs to be explicit
139 $(obj
)/dtc-src
/dtc-parser.tab.o
: $(obj
)/dtc-src
/dtc-parser.tab.c
$(obj
)/dtc-src
/dtc-parser.tab.h
140 $(obj
)/dtc-src
/dtc-lexer.
lex.o
: $(obj
)/dtc-src
/dtc-lexer.
lex.c
$(obj
)/dtc-src
/dtc-parser.tab.h
142 HOSTCFLAGS
+= -I
$(src
)/dtc-src
/ -I
$(src
)/libfdt
/
144 targets
+= dtc-src
/dtc-parser.tab.c
145 targets
+= dtc-src
/dtc-lexer.
lex.c
151 quiet_cmd_bison
= BISON
$@
152 cmd_bison
= $(BISON
) -o
$@
-d
$<; cp
$@
$@_shipped
153 quiet_cmd_flex
= FLEX
$@
154 cmd_flex
= $(FLEX
) -o
$@
$<; cp
$@
$@_shipped
156 $(obj
)/dtc-src
/dtc-parser.tab.c
: $(src
)/dtc-src
/dtc-parser.y FORCE
157 $(call if_changed
,bison
)
159 $(obj
)/dtc-src
/dtc-parser.tab.h
: $(obj
)/dtc-src
/dtc-parser.tab.c
161 $(obj
)/dtc-src
/dtc-lexer.
lex.c
: $(src
)/dtc-src
/dtc-lexer.l FORCE
162 $(call if_changed
,flex
)
166 # Bits for building various flavours of zImage
168 ifneq ($(CROSS32_COMPILE
),)
169 CROSSWRAP
:= -C
"$(CROSS32_COMPILE)"
171 ifneq ($(CROSS_COMPILE
),)
172 CROSSWRAP
:= -C
"$(CROSS_COMPILE)"
176 # args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd
177 quiet_cmd_wrap
= WRAP
$@
178 cmd_wrap
=$(CONFIG_SHELL
) $(wrapper
) -c
-o
$@
-p
$2 $(CROSSWRAP
) \
179 $(if
$3, -s
$3)$(if
$4, -d
$4)$(if
$5, -i
$5) vmlinux
181 image-
$(CONFIG_PPC_PSERIES
) += zImage.pseries
182 image-
$(CONFIG_PPC_MAPLE
) += zImage.pseries
183 image-
$(CONFIG_PPC_IBM_CELL_BLADE
) += zImage.pseries
184 image-
$(CONFIG_PPC_PS3
) += zImage.ps3
185 image-
$(CONFIG_PPC_CELLEB
) += zImage.pseries
186 image-
$(CONFIG_PPC_CHRP
) += zImage.chrp
187 image-
$(CONFIG_PPC_EFIKA
) += zImage.chrp
188 image-
$(CONFIG_PPC_PMAC
) += zImage.pmac
189 image-
$(CONFIG_PPC_HOLLY
) += zImage.holly
190 image-
$(CONFIG_PPC_PRPMC2800
) += zImage.prpmc2800
191 image-
$(CONFIG_PPC_ISERIES
) += zImage.iseries
192 image-
$(CONFIG_DEFAULT_UIMAGE
) += uImage
194 ifneq ($(CONFIG_DEVICE_TREE
),"")
195 image-
$(CONFIG_PPC_8xx
) += cuImage
.8xx
196 image-
$(CONFIG_PPC_EP88XC
) += zImage.ep88xc
197 image-
$(CONFIG_EP405
) += zImage.ep405
198 image-
$(CONFIG_8260
) += cuImage.pq2
199 image-
$(CONFIG_EP8248E
) += zImage.ep8248e
200 image-
$(CONFIG_PPC_MPC52xx
) += cuImage
.52xx
201 image-
$(CONFIG_STORCENTER
) += cuImage
.824x
202 image-
$(CONFIG_PPC_83xx
) += cuImage
.83xx
203 image-
$(CONFIG_PPC_85xx
) += cuImage
.85xx
204 ifeq ($(CONFIG_CPM2
),y
)
205 image-
$(CONFIG_PPC_85xx
) += cuImage
.85xx-cpm2
207 image-
$(CONFIG_MPC7448HPC2
) += cuImage.hpc2
208 image-
$(CONFIG_EBONY
) += treeImage.ebony cuImage.ebony
209 image-
$(CONFIG_BAMBOO
) += treeImage.bamboo cuImage.bamboo
210 image-
$(CONFIG_SEQUOIA
) += cuImage.sequoia
211 image-
$(CONFIG_RAINIER
) += cuImage.rainier
212 image-
$(CONFIG_WALNUT
) += treeImage.walnut
213 image-
$(CONFIG_TAISHAN
) += cuImage.taishan
214 image-
$(CONFIG_KATMAI
) += cuImage.katmai
215 image-
$(CONFIG_WARP
) += cuImage.warp
218 ifneq ($(CONFIG_REDBOOT
),"")
219 image-
$(CONFIG_PPC_8xx
) += zImage.redboot-8xx
222 # For 32-bit powermacs, build the COFF and miboot images
223 # as well as the ELF images.
224 ifeq ($(CONFIG_PPC32
),y
)
225 image-
$(CONFIG_PPC_PMAC
) += zImage.coff zImage.miboot
228 initrd-
:= $(patsubst zImage
%, zImage.initrd
%, $(image-n
) $(image-
))
229 initrd-y
:= $(patsubst zImage
%, zImage.initrd
%, \
230 $(patsubst treeImage
%, treeImage.initrd
%, $(image-y
)))
231 initrd-y
:= $(filter-out $(image-y
), $(initrd-y
))
232 targets
+= $(image-y
) $(initrd-y
)
234 $(addprefix $(obj
)/, $(initrd-y
)): $(obj
)/ramdisk.image.gz
236 # If CONFIG_WANT_DEVICE_TREE is set and CONFIG_DEVICE_TREE isn't an
237 # empty string, define 'dts' to be path to the dts
238 # CONFIG_DEVICE_TREE will have "" around it, make sure to strip them
239 ifeq ($(CONFIG_WANT_DEVICE_TREE
),y
)
240 ifneq ($(CONFIG_DEVICE_TREE
),"")
241 dts
= $(if
$(shell echo
$(CONFIG_DEVICE_TREE
) | grep
'^/'),\
242 ,$(srctree
)/$(src
)/dts
/)$(CONFIG_DEVICE_TREE
:"%"=%)
246 # Don't put the ramdisk on the pattern rule; when its missing make will try
247 # the pattern rule with less dependencies that also matches (even with the
248 # hard dependency listed).
249 $(obj
)/zImage.initrd.
%: vmlinux
$(wrapperbits
) $(dts
)
250 $(call if_changed
,wrap
,$*,$(dts
),,$(obj
)/ramdisk.image.gz
)
252 $(obj
)/zImage.
%: vmlinux
$(wrapperbits
) $(dts
)
253 $(call if_changed
,wrap
,$*,$(dts
))
255 # This cannot be in the root of $(src) as the zImage rule always adds a $(obj)
257 $(obj
)/vmlinux.
strip: vmlinux
258 $(STRIP
) -s
-R .comment
$< -o
$@
260 $(obj
)/zImage.iseries
: vmlinux
261 $(STRIP
) -s
-R .comment
$< -o
$@
263 $(obj
)/zImage.ps3
: vmlinux
$(wrapper
) $(wrapperbits
) $(srctree
)/$(src
)/dts
/ps3.dts
264 $(STRIP
) -s
-R .comment
$< -o vmlinux.
strip
265 $(call cmd
,wrap
,ps3
,$(srctree
)/$(src
)/dts
/ps3.dts
,,)
267 $(obj
)/zImage.initrd.ps3
: vmlinux
$(wrapper
) $(wrapperbits
) $(srctree
)/$(src
)/dts
/ps3.dts
$(obj
)/ramdisk.image.gz
268 $(call cmd
,wrap
,ps3
,$(srctree
)/$(src
)/dts
/ps3.dts
,,$(obj
)/ramdisk.image.gz
)
270 $(obj
)/uImage
: vmlinux
$(wrapperbits
)
271 $(call if_changed
,wrap
,uboot
)
273 $(obj
)/cuImage.
%: vmlinux
$(dts
) $(wrapperbits
)
274 $(call if_changed
,wrap
,cuboot-
$*,$(dts
))
276 $(obj
)/treeImage.initrd.
%: vmlinux
$(dts
) $(wrapperbits
)
277 $(call if_changed
,wrap
,treeboot-
$*,$(dts
),,$(obj
)/ramdisk.image.gz
)
279 $(obj
)/treeImage.
%: vmlinux
$(dts
) $(wrapperbits
)
280 $(call if_changed
,wrap
,treeboot-
$*,$(dts
))
282 # If there isn't a platform selected then just strip the vmlinux.
284 image-y
:= vmlinux.
strip
287 $(obj
)/zImage
: $(addprefix $(obj
)/, $(image-y
))
289 $(obj
)/zImage.initrd
: $(addprefix $(obj
)/, $(initrd-y
))
292 install: $(CONFIGURE
) $(addprefix $(obj
)/, $(image-y
))
293 sh
-x
$(srctree
)/$(src
)/install.sh
"$(KERNELRELEASE)" vmlinux System.map
"$(INSTALL_PATH)" $<
295 # anything not in $(targets)
296 clean-files
+= $(image-
) $(initrd-
) zImage zImage.initrd cuImage.
* treeImage.
* \
299 # clean up files cached by wrapper
300 clean-kernel
:= vmlinux.
strip vmlinux.bin
301 clean-kernel
+= $(addsuffix .gz
,$(clean-kernel
))
302 # If not absolute clean-files are relative to $(obj).
303 clean-files
+= $(addprefix $(objtree
)/, $(clean-kernel
))
305 WRAPPER_OBJDIR
:= /usr
/lib
/kernel-wrapper
306 WRAPPER_DTSDIR
:= /usr
/lib
/kernel-wrapper
/dts
307 WRAPPER_BINDIR
:= /usr
/sbin
310 extra-installed
:= $(patsubst $(obj
)/%, $(DESTDIR
)$(WRAPPER_OBJDIR
)/%, $(extra-y
))
311 hostprogs-installed
:= $(patsubst %, $(DESTDIR
)$(WRAPPER_BINDIR
)/%, $(hostprogs-y
))
312 wrapper-installed
:= $(DESTDIR
)$(WRAPPER_BINDIR
)/wrapper
313 dts-installed
:= $(patsubst $(obj
)/dts
/%, $(DESTDIR
)$(WRAPPER_DTSDIR
)/%, $(wildcard $(obj
)/dts
/*.dts
))
315 all-installed
:= $(extra-installed
) $(hostprogs-installed
) $(wrapper-installed
) $(dts-installed
)
317 quiet_cmd_mkdir
= MKDIR
$(patsubst $(INSTALL_HDR_PATH
)/%,%,$@
)
318 cmd_mkdir
= mkdir
-p
$@
320 quiet_cmd_install
= INSTALL
$(patsubst $(DESTDIR
)$(WRAPPER_OBJDIR
)/%,%,$@
)
321 cmd_install
= $(INSTALL
) -m0644
$(patsubst $(DESTDIR
)$(WRAPPER_OBJDIR
)/%,$(obj
)/%,$@
) $@
323 quiet_cmd_install_dts
= INSTALL
$(patsubst $(DESTDIR
)$(WRAPPER_DTSDIR
)/%,dts
/%,$@
)
324 cmd_install_dts
= $(INSTALL
) -m0644
$(patsubst $(DESTDIR
)$(WRAPPER_DTSDIR
)/%,$(srctree
)/$(obj
)/dts
/%,$@
) $@
326 quiet_cmd_install_exe
= INSTALL
$(patsubst $(DESTDIR
)$(WRAPPER_BINDIR
)/%,%,$@
)
327 cmd_install_exe
= $(INSTALL
) -m0755
$(patsubst $(DESTDIR
)$(WRAPPER_BINDIR
)/%,$(obj
)/%,$@
) $@
329 quiet_cmd_install_wrapper
= INSTALL
$(patsubst $(DESTDIR
)$(WRAPPER_BINDIR
)/%,%,$@
)
330 cmd_install_wrapper
= $(INSTALL
) -m0755
$(patsubst $(DESTDIR
)$(WRAPPER_BINDIR
)/%,$(srctree
)/$(obj
)/%,$@
) $@
;\
331 sed
-i
$@
-e
's%^object=.*%object=$(WRAPPER_OBJDIR)%' \
332 -e
's%^objbin=.*%objbin=$(WRAPPER_BINDIR)%' \
335 $(DESTDIR
)$(WRAPPER_OBJDIR
) $(DESTDIR
)$(WRAPPER_DTSDIR
) $(DESTDIR
)$(WRAPPER_BINDIR
):
338 $(extra-installed
) : $(DESTDIR
)$(WRAPPER_OBJDIR
)/% : $(obj
)/% |
$(DESTDIR
)$(WRAPPER_OBJDIR
)
341 $(hostprogs-installed
) : $(DESTDIR
)$(WRAPPER_BINDIR
)/% : $(obj
)/% |
$(DESTDIR
)$(WRAPPER_BINDIR
)
342 $(call cmd
,install_exe
)
344 $(dts-installed
) : $(DESTDIR
)$(WRAPPER_DTSDIR
)/% : $(srctree
)/$(obj
)/dts
/% |
$(DESTDIR
)$(WRAPPER_DTSDIR
)
345 $(call cmd
,install_dts
)
347 $(wrapper-installed
): $(DESTDIR
)$(WRAPPER_BINDIR
) $(srctree
)/$(obj
)/wrapper |
$(DESTDIR
)$(WRAPPER_BINDIR
)
348 $(call cmd
,install_wrapper
)
350 $(obj
)/bootwrapper_install
: $(all-installed
)