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
)/treeboot-walnut.o
: BOOTCFLAGS
+= -mcpu
=405
42 zlib
:= inffast.c inflate.c inftrees.c
43 zlibheader
:= inffast.h inffixed.h inflate.h inftrees.h infutil.h
44 zliblinuxheader
:= zlib.h zconf.h zutil.h
46 $(addprefix $(obj
)/,$(zlib
) gunzip_util.o main.o
): \
47 $(addprefix $(obj
)/,$(zliblinuxheader
)) $(addprefix $(obj
)/,$(zlibheader
))
49 src-libfdt
:= fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c
50 src-wlib
:= string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
51 $(addprefix libfdt
/,$(src-libfdt
)) libfdt-wrapper.c \
52 ns16550.c serial.c simple_alloc.c div64.S util.S \
53 gunzip_util.c elf_util.c
$(zlib
) devtree.c oflib.c ofconsole.c \
54 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \
55 cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c \
56 fsl-soc.c mpc8xx.c pq2.c
57 src-plat
:= of.c cuboot-52xx.c cuboot-83xx.c cuboot-85xx.c holly.c \
58 cuboot-ebony.c treeboot-ebony.c prpmc2800.c \
59 ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \
60 cuboot-pq2.c cuboot-sequoia.c treeboot-walnut.c cuboot-bamboo.c \
61 fixed-head.S ep88xc.c cuboot-hpc2.c
62 src-boot
:= $(src-wlib
) $(src-plat
) empty.c
64 src-boot
:= $(addprefix $(obj
)/, $(src-boot
))
65 obj-boot
:= $(addsuffix .o
, $(basename $(src-boot
)))
66 obj-wlib
:= $(addsuffix .o
, $(basename $(addprefix $(obj
)/, $(src-wlib
))))
67 obj-plat
:= $(addsuffix .o
, $(basename $(addprefix $(obj
)/, $(src-plat
))))
69 quiet_cmd_copy_zlib
= COPY
$@
70 cmd_copy_zlib
= sed
"s@__attribute_used__@@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@
72 quiet_cmd_copy_zlibheader
= COPY
$@
73 cmd_copy_zlibheader
= sed
"s@<linux/\([^>]*\).*@\"\1\"@" $< > $@
75 quiet_cmd_copy_zliblinuxheader
= COPY
$@
76 cmd_copy_zliblinuxheader
= sed
"s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@
78 $(addprefix $(obj
)/,$(zlib
)): $(obj
)/%: $(srctree
)/lib
/zlib_inflate
/%
81 $(addprefix $(obj
)/,$(zlibheader
)): $(obj
)/%: $(srctree
)/lib
/zlib_inflate
/%
82 $(call cmd
,copy_zlibheader
)
84 $(addprefix $(obj
)/,$(zliblinuxheader
)): $(obj
)/%: $(srctree
)/include/linux
/%
85 $(call cmd
,copy_zliblinuxheader
)
90 $(obj
)/zImage.lds
$(obj
)/zImage.coff.lds
$(obj
)/zImage.ps3.lds
: $(obj
)/%: $(srctree
)/$(src
)/%.S
93 clean-files
:= $(zlib
) $(zlibheader
) $(zliblinuxheader
) \
94 empty.c zImage zImage.coff.lds zImage.ps3.lds zImage.lds
96 quiet_cmd_bootcc
= BOOTCC
$@
97 cmd_bootcc
= $(CROSS32CC
) -Wp
,-MD
,$(depfile
) $(BOOTCFLAGS
) -c
-o
$@
$<
99 quiet_cmd_bootas
= BOOTAS
$@
100 cmd_bootas
= $(CROSS32CC
) -Wp
,-MD
,$(depfile
) $(BOOTAFLAGS
) -c
-o
$@
$<
102 quiet_cmd_bootar
= BOOTAR
$@
103 cmd_bootar
= $(CROSS32AR
) -cr
$@.
$$$$ $(filter-out FORCE
,$^
); mv
$@.
$$$$ $@
105 $(patsubst %.c
,%.o
, $(filter %.c
, $(src-boot
))): %.o
: %.c FORCE
106 $(Q
)mkdir
-p
$(dir $@
)
107 $(call if_changed_dep
,bootcc
)
108 $(patsubst %.S
,%.o
, $(filter %.S
, $(src-boot
))): %.o
: %.S FORCE
109 $(Q
)mkdir
-p
$(dir $@
)
110 $(call if_changed_dep
,bootas
)
112 $(obj
)/wrapper.a
: $(obj-wlib
) FORCE
113 $(call if_changed
,bootar
)
115 hostprogs-y
:= addnote addRamDisk hack-coff mktree
117 targets
+= $(patsubst $(obj
)/%,%,$(obj-boot
) wrapper.a
)
118 extra-y
:= $(obj
)/wrapper.a
$(obj-plat
) $(obj
)/empty.o \
119 $(obj
)/zImage.lds
$(obj
)/zImage.coff.lds
$(obj
)/zImage.ps3.lds
121 wrapper
:=$(srctree
)/$(src
)/wrapper
122 wrapperbits
:= $(extra-y
) $(addprefix $(obj
)/,addnote hack-coff mktree
) \
126 # Bits for building various flavours of zImage
128 ifneq ($(CROSS32_COMPILE
),)
129 CROSSWRAP
:= -C
"$(CROSS32_COMPILE)"
131 ifneq ($(CROSS_COMPILE
),)
132 CROSSWRAP
:= -C
"$(CROSS_COMPILE)"
136 # args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd
137 quiet_cmd_wrap
= WRAP
$@
138 cmd_wrap
=$(CONFIG_SHELL
) $(wrapper
) -c
-o
$@
-p
$2 $(CROSSWRAP
) \
139 $(if
$3, -s
$3)$(if
$4, -d
$4)$(if
$5, -i
$5) vmlinux
141 image-
$(CONFIG_PPC_PSERIES
) += zImage.pseries
142 image-
$(CONFIG_PPC_MAPLE
) += zImage.pseries
143 image-
$(CONFIG_PPC_IBM_CELL_BLADE
) += zImage.pseries
144 image-
$(CONFIG_PPC_PS3
) += zImage.ps3
145 image-
$(CONFIG_PPC_CELLEB
) += zImage.pseries
146 image-
$(CONFIG_PPC_CHRP
) += zImage.chrp
147 image-
$(CONFIG_PPC_EFIKA
) += zImage.chrp
148 image-
$(CONFIG_PPC_PMAC
) += zImage.pmac
149 image-
$(CONFIG_PPC_HOLLY
) += zImage.holly
150 image-
$(CONFIG_PPC_PRPMC2800
) += zImage.prpmc2800
151 image-
$(CONFIG_PPC_ISERIES
) += zImage.iseries
152 image-
$(CONFIG_DEFAULT_UIMAGE
) += uImage
154 ifneq ($(CONFIG_DEVICE_TREE
),"")
155 image-
$(CONFIG_PPC_8xx
) += cuImage
.8xx
156 image-
$(CONFIG_PPC_EP88XC
) += zImage.ep88xc
157 image-
$(CONFIG_8260
) += cuImage.pq2
158 image-
$(CONFIG_PPC_MPC52xx
) += cuImage
.52xx
159 image-
$(CONFIG_PPC_83xx
) += cuImage
.83xx
160 image-
$(CONFIG_PPC_85xx
) += cuImage
.85xx
161 image-
$(CONFIG_MPC7448HPC2
) += cuImage.hpc2
162 image-
$(CONFIG_EBONY
) += treeImage.ebony cuImage.ebony
163 image-
$(CONFIG_BAMBOO
) += treeImage.bamboo cuImage.bamboo
164 image-
$(CONFIG_SEQUOIA
) += cuImage.sequoia
165 image-
$(CONFIG_WALNUT
) += treeImage.walnut
168 # For 32-bit powermacs, build the COFF and miboot images
169 # as well as the ELF images.
170 ifeq ($(CONFIG_PPC32
),y
)
171 image-
$(CONFIG_PPC_PMAC
) += zImage.coff zImage.miboot
174 initrd-
:= $(patsubst zImage
%, zImage.initrd
%, $(image-n
) $(image-
))
175 initrd-y
:= $(patsubst zImage
%, zImage.initrd
%, \
176 $(patsubst treeImage
%, treeImage.initrd
%, $(image-y
)))
177 initrd-y
:= $(filter-out $(image-y
), $(initrd-y
))
178 targets
+= $(image-y
) $(initrd-y
)
180 $(addprefix $(obj
)/, $(initrd-y
)): $(obj
)/ramdisk.image.gz
182 # If CONFIG_WANT_DEVICE_TREE is set and CONFIG_DEVICE_TREE isn't an
183 # empty string, define 'dts' to be path to the dts
184 # CONFIG_DEVICE_TREE will have "" around it, make sure to strip them
185 ifeq ($(CONFIG_WANT_DEVICE_TREE
),y
)
186 ifneq ($(CONFIG_DEVICE_TREE
),"")
187 dts
= $(if
$(shell echo
$(CONFIG_DEVICE_TREE
) | grep
'^/'),\
188 ,$(srctree
)/$(src
)/dts
/)$(CONFIG_DEVICE_TREE
:"%"=%)
192 # Don't put the ramdisk on the pattern rule; when its missing make will try
193 # the pattern rule with less dependencies that also matches (even with the
194 # hard dependency listed).
195 $(obj
)/zImage.initrd.
%: vmlinux
$(wrapperbits
) $(dts
)
196 $(call if_changed
,wrap
,$*,$(dts
),,$(obj
)/ramdisk.image.gz
)
198 $(obj
)/zImage.
%: vmlinux
$(wrapperbits
) $(dts
)
199 $(call if_changed
,wrap
,$*,$(dts
))
201 # This cannot be in the root of $(src) as the zImage rule always adds a $(obj)
203 $(obj
)/vmlinux.
strip: vmlinux
204 $(STRIP
) -s
-R .comment
$< -o
$@
206 $(obj
)/zImage.iseries
: vmlinux
207 $(STRIP
) -s
-R .comment
$< -o
$@
209 $(obj
)/zImage.ps3
: vmlinux
$(wrapper
) $(wrapperbits
) $(srctree
)/$(src
)/dts
/ps3.dts
210 $(STRIP
) -s
-R .comment
$< -o vmlinux.
strip
211 $(call cmd
,wrap
,ps3
,$(srctree
)/$(src
)/dts
/ps3.dts
,,)
213 $(obj
)/zImage.initrd.ps3
: vmlinux
$(wrapper
) $(wrapperbits
) $(srctree
)/$(src
)/dts
/ps3.dts
$(obj
)/ramdisk.image.gz
214 $(call cmd
,wrap
,ps3
,$(srctree
)/$(src
)/dts
/ps3.dts
,,$(obj
)/ramdisk.image.gz
)
216 $(obj
)/uImage
: vmlinux
$(wrapperbits
)
217 $(call if_changed
,wrap
,uboot
)
219 $(obj
)/cuImage.
%: vmlinux
$(dts
) $(wrapperbits
)
220 $(call if_changed
,wrap
,cuboot-
$*,$(dts
))
222 $(obj
)/treeImage.initrd.
%: vmlinux
$(dts
) $(wrapperbits
)
223 $(call if_changed
,wrap
,treeboot-
$*,$(dts
),,$(obj
)/ramdisk.image.gz
)
225 $(obj
)/treeImage.
%: vmlinux
$(dts
) $(wrapperbits
)
226 $(call if_changed
,wrap
,treeboot-
$*,$(dts
))
228 # If there isn't a platform selected then just strip the vmlinux.
230 image-y
:= vmlinux.
strip
233 $(obj
)/zImage
: $(addprefix $(obj
)/, $(image-y
))
235 $(obj
)/zImage.initrd
: $(addprefix $(obj
)/, $(initrd-y
))
238 install: $(CONFIGURE
) $(addprefix $(obj
)/, $(image-y
))
239 sh
-x
$(srctree
)/$(src
)/install.sh
"$(KERNELRELEASE)" vmlinux System.map
"$(INSTALL_PATH)" $<
241 # anything not in $(targets)
242 clean-files
+= $(image-
) $(initrd-
) zImage zImage.initrd cuImage.
* treeImage.
* \
245 # clean up files cached by wrapper
246 clean-kernel
:= vmlinux.
strip vmlinux.bin
247 clean-kernel
+= $(addsuffix .gz
,$(clean-kernel
))
248 # If not absolute clean-files are relative to $(obj).
249 clean-files
+= $(addprefix $(objtree
)/, $(clean-kernel
))
251 WRAPPER_OBJDIR
:= /usr
/lib
/kernel-wrapper
252 WRAPPER_DTSDIR
:= /usr
/lib
/kernel-wrapper
/dts
253 WRAPPER_BINDIR
:= /usr
/sbin
256 extra-installed
:= $(patsubst $(obj
)/%, $(DESTDIR
)$(WRAPPER_OBJDIR
)/%, $(extra-y
))
257 hostprogs-installed
:= $(patsubst %, $(DESTDIR
)$(WRAPPER_BINDIR
)/%, $(hostprogs-y
))
258 wrapper-installed
:= $(DESTDIR
)$(WRAPPER_BINDIR
)/wrapper
259 dts-installed
:= $(patsubst $(obj
)/dts
/%, $(DESTDIR
)$(WRAPPER_DTSDIR
)/%, $(wildcard $(obj
)/dts
/*.dts
))
261 all-installed
:= $(extra-installed
) $(hostprogs-installed
) $(wrapper-installed
) $(dts-installed
)
263 quiet_cmd_mkdir
= MKDIR
$(patsubst $(INSTALL_HDR_PATH
)/%,%,$@
)
264 cmd_mkdir
= mkdir
-p
$@
266 quiet_cmd_install
= INSTALL
$(patsubst $(DESTDIR
)$(WRAPPER_OBJDIR
)/%,%,$@
)
267 cmd_install
= $(INSTALL
) -m0644
$(patsubst $(DESTDIR
)$(WRAPPER_OBJDIR
)/%,$(obj
)/%,$@
) $@
269 quiet_cmd_install_dts
= INSTALL
$(patsubst $(DESTDIR
)$(WRAPPER_DTSDIR
)/%,dts
/%,$@
)
270 cmd_install_dts
= $(INSTALL
) -m0644
$(patsubst $(DESTDIR
)$(WRAPPER_DTSDIR
)/%,$(srctree
)/$(obj
)/dts
/%,$@
) $@
272 quiet_cmd_install_exe
= INSTALL
$(patsubst $(DESTDIR
)$(WRAPPER_BINDIR
)/%,%,$@
)
273 cmd_install_exe
= $(INSTALL
) -m0755
$(patsubst $(DESTDIR
)$(WRAPPER_BINDIR
)/%,$(obj
)/%,$@
) $@
275 quiet_cmd_install_wrapper
= INSTALL
$(patsubst $(DESTDIR
)$(WRAPPER_BINDIR
)/%,%,$@
)
276 cmd_install_wrapper
= $(INSTALL
) -m0755
$(patsubst $(DESTDIR
)$(WRAPPER_BINDIR
)/%,$(srctree
)/$(obj
)/%,$@
) $@
;\
277 sed
-i
$@
-e
's%^object=.*%object=$(WRAPPER_OBJDIR)%' \
278 -e
's%^objbin=.*%objbin=$(WRAPPER_BINDIR)%' \
281 $(DESTDIR
)$(WRAPPER_OBJDIR
) $(DESTDIR
)$(WRAPPER_DTSDIR
) $(DESTDIR
)$(WRAPPER_BINDIR
):
284 $(extra-installed
) : $(DESTDIR
)$(WRAPPER_OBJDIR
)/% : $(obj
)/% |
$(DESTDIR
)$(WRAPPER_OBJDIR
)
287 $(hostprogs-installed
) : $(DESTDIR
)$(WRAPPER_BINDIR
)/% : $(obj
)/% |
$(DESTDIR
)$(WRAPPER_BINDIR
)
288 $(call cmd
,install_exe
)
290 $(dts-installed
) : $(DESTDIR
)$(WRAPPER_DTSDIR
)/% : $(srctree
)/$(obj
)/dts
/% |
$(DESTDIR
)$(WRAPPER_DTSDIR
)
291 $(call cmd
,install_dts
)
293 $(wrapper-installed
): $(DESTDIR
)$(WRAPPER_BINDIR
) $(srctree
)/$(obj
)/wrapper |
$(DESTDIR
)$(WRAPPER_BINDIR
)
294 $(call cmd
,install_wrapper
)
296 $(obj
)/bootwrapper_install
: $(all-installed
)