Makefile 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. 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.
  19. all: $(obj)/zImage
  20. BOOTCFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
  21. -fno-strict-aliasing -Os -msoft-float -pipe \
  22. -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
  23. -isystem $(shell $(CROSS32CC) -print-file-name=include)
  24. BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
  25. ifdef CONFIG_DEBUG_INFO
  26. BOOTCFLAGS += -g
  27. endif
  28. ifeq ($(call cc-option-yn, -fstack-protector),y)
  29. BOOTCFLAGS += -fno-stack-protector
  30. endif
  31. BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
  32. $(obj)/4xx.o: BOOTCFLAGS += -mcpu=440
  33. $(obj)/ebony.o: BOOTCFLAGS += -mcpu=440
  34. $(obj)/treeboot-walnut.o: BOOTCFLAGS += -mcpu=405
  35. zlib := inffast.c inflate.c inftrees.c
  36. zlibheader := inffast.h inffixed.h inflate.h inftrees.h infutil.h
  37. zliblinuxheader := zlib.h zconf.h zutil.h
  38. $(addprefix $(obj)/,$(zlib) gunzip_util.o main.o): \
  39. $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader))
  40. src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
  41. ns16550.c serial.c simple_alloc.c div64.S util.S \
  42. gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \
  43. 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \
  44. cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c \
  45. fsl-soc.c mpc8xx.c pq2.c
  46. src-plat := of.c cuboot-52xx.c cuboot-83xx.c cuboot-85xx.c holly.c \
  47. cuboot-ebony.c treeboot-ebony.c prpmc2800.c \
  48. ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \
  49. cuboot-pq2.c cuboot-sequoia.c treeboot-walnut.c cuboot-bamboo.c \
  50. fixed-head.S ep88xc.c cuboot-hpc2.c
  51. src-boot := $(src-wlib) $(src-plat) empty.c
  52. src-boot := $(addprefix $(obj)/, $(src-boot))
  53. obj-boot := $(addsuffix .o, $(basename $(src-boot)))
  54. obj-wlib := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-wlib))))
  55. obj-plat := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-plat))))
  56. quiet_cmd_copy_zlib = COPY $@
  57. cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@
  58. quiet_cmd_copy_zlibheader = COPY $@
  59. cmd_copy_zlibheader = sed "s@<linux/\([^>]*\).*@\"\1\"@" $< > $@
  60. # stddef.h for NULL
  61. quiet_cmd_copy_zliblinuxheader = COPY $@
  62. cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]*\).*@\"\1\"@" $< > $@
  63. $(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  64. $(call cmd,copy_zlib)
  65. $(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  66. $(call cmd,copy_zlibheader)
  67. $(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
  68. $(call cmd,copy_zliblinuxheader)
  69. $(obj)/empty.c:
  70. @touch $@
  71. $(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds: $(obj)/%: $(srctree)/$(src)/%.S
  72. @cp $< $@
  73. clean-files := $(zlib) $(zlibheader) $(zliblinuxheader) \
  74. empty.c zImage zImage.coff.lds zImage.ps3.lds zImage.lds
  75. quiet_cmd_bootcc = BOOTCC $@
  76. cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
  77. quiet_cmd_bootas = BOOTAS $@
  78. cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
  79. quiet_cmd_bootar = BOOTAR $@
  80. cmd_bootar = $(CROSS32AR) -cr $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@
  81. $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c FORCE
  82. $(call if_changed_dep,bootcc)
  83. $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE
  84. $(call if_changed_dep,bootas)
  85. $(obj)/wrapper.a: $(obj-wlib) FORCE
  86. $(call if_changed,bootar)
  87. hostprogs-y := addnote addRamDisk hack-coff mktree
  88. targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a)
  89. extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \
  90. $(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds
  91. wrapper :=$(srctree)/$(src)/wrapper
  92. wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree) \
  93. $(wrapper) FORCE
  94. #############
  95. # Bits for building various flavours of zImage
  96. ifneq ($(CROSS32_COMPILE),)
  97. CROSSWRAP := -C "$(CROSS32_COMPILE)"
  98. else
  99. ifneq ($(CROSS_COMPILE),)
  100. CROSSWRAP := -C "$(CROSS_COMPILE)"
  101. endif
  102. endif
  103. # args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd
  104. quiet_cmd_wrap = WRAP $@
  105. cmd_wrap =$(CONFIG_SHELL) $(wrapper) -c -o $@ -p $2 $(CROSSWRAP) \
  106. $(if $3, -s $3)$(if $4, -d $4)$(if $5, -i $5) vmlinux
  107. image-$(CONFIG_PPC_PSERIES) += zImage.pseries
  108. image-$(CONFIG_PPC_MAPLE) += zImage.pseries
  109. image-$(CONFIG_PPC_IBM_CELL_BLADE) += zImage.pseries
  110. image-$(CONFIG_PPC_PS3) += zImage.ps3
  111. image-$(CONFIG_PPC_CELLEB) += zImage.pseries
  112. image-$(CONFIG_PPC_CHRP) += zImage.chrp
  113. image-$(CONFIG_PPC_EFIKA) += zImage.chrp
  114. image-$(CONFIG_PPC_PMAC) += zImage.pmac
  115. image-$(CONFIG_PPC_HOLLY) += zImage.holly
  116. image-$(CONFIG_PPC_PRPMC2800) += zImage.prpmc2800
  117. image-$(CONFIG_PPC_ISERIES) += zImage.iseries
  118. image-$(CONFIG_DEFAULT_UIMAGE) += uImage
  119. ifneq ($(CONFIG_DEVICE_TREE),"")
  120. image-$(CONFIG_PPC_8xx) += cuImage.8xx
  121. image-$(CONFIG_PPC_EP88XC) += zImage.ep88xc
  122. image-$(CONFIG_8260) += cuImage.pq2
  123. image-$(CONFIG_PPC_MPC52xx) += cuImage.52xx
  124. image-$(CONFIG_PPC_83xx) += cuImage.83xx
  125. image-$(CONFIG_PPC_85xx) += cuImage.85xx
  126. image-$(CONFIG_MPC7448HPC2) += cuImage.hpc2
  127. image-$(CONFIG_EBONY) += treeImage.ebony cuImage.ebony
  128. image-$(CONFIG_BAMBOO) += treeImage.bamboo cuImage.bamboo
  129. image-$(CONFIG_SEQUOIA) += cuImage.sequoia
  130. image-$(CONFIG_WALNUT) += treeImage.walnut
  131. endif
  132. # For 32-bit powermacs, build the COFF and miboot images
  133. # as well as the ELF images.
  134. ifeq ($(CONFIG_PPC32),y)
  135. image-$(CONFIG_PPC_PMAC) += zImage.coff zImage.miboot
  136. endif
  137. initrd- := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-))
  138. initrd-y := $(patsubst zImage%, zImage.initrd%, \
  139. $(patsubst treeImage%, treeImage.initrd%, $(image-y)))
  140. initrd-y := $(filter-out $(image-y), $(initrd-y))
  141. targets += $(image-y) $(initrd-y)
  142. $(addprefix $(obj)/, $(initrd-y)): $(obj)/ramdisk.image.gz
  143. # If CONFIG_WANT_DEVICE_TREE is set and CONFIG_DEVICE_TREE isn't an
  144. # empty string, define 'dts' to be path to the dts
  145. # CONFIG_DEVICE_TREE will have "" around it, make sure to strip them
  146. ifeq ($(CONFIG_WANT_DEVICE_TREE),y)
  147. ifneq ($(CONFIG_DEVICE_TREE),"")
  148. dts = $(if $(shell echo $(CONFIG_DEVICE_TREE) | grep '^/'),\
  149. ,$(srctree)/$(src)/dts/)$(CONFIG_DEVICE_TREE:"%"=%)
  150. endif
  151. endif
  152. # Don't put the ramdisk on the pattern rule; when its missing make will try
  153. # the pattern rule with less dependencies that also matches (even with the
  154. # hard dependency listed).
  155. $(obj)/zImage.initrd.%: vmlinux $(wrapperbits) $(dts)
  156. $(call if_changed,wrap,$*,$(dts),,$(obj)/ramdisk.image.gz)
  157. $(obj)/zImage.%: vmlinux $(wrapperbits) $(dts)
  158. $(call if_changed,wrap,$*,$(dts))
  159. # This cannot be in the root of $(src) as the zImage rule always adds a $(obj)
  160. # prefix
  161. $(obj)/vmlinux.strip: vmlinux
  162. $(STRIP) -s -R .comment $< -o $@
  163. $(obj)/zImage.iseries: vmlinux
  164. $(STRIP) -s -R .comment $< -o $@
  165. $(obj)/zImage.ps3: vmlinux $(wrapper) $(wrapperbits) $(srctree)/$(src)/dts/ps3.dts
  166. $(STRIP) -s -R .comment $< -o vmlinux.strip
  167. $(call cmd,wrap,ps3,$(srctree)/$(src)/dts/ps3.dts,,)
  168. $(obj)/zImage.initrd.ps3: vmlinux $(wrapper) $(wrapperbits) $(srctree)/$(src)/dts/ps3.dts $(obj)/ramdisk.image.gz
  169. $(call cmd,wrap,ps3,$(srctree)/$(src)/dts/ps3.dts,,$(obj)/ramdisk.image.gz)
  170. $(obj)/uImage: vmlinux $(wrapperbits)
  171. $(call if_changed,wrap,uboot)
  172. $(obj)/cuImage.%: vmlinux $(dts) $(wrapperbits)
  173. $(call if_changed,wrap,cuboot-$*,$(dts))
  174. $(obj)/treeImage.initrd.%: vmlinux $(dts) $(wrapperbits)
  175. $(call if_changed,wrap,treeboot-$*,$(dts),,$(obj)/ramdisk.image.gz)
  176. $(obj)/treeImage.%: vmlinux $(dts) $(wrapperbits)
  177. $(call if_changed,wrap,treeboot-$*,$(dts))
  178. # If there isn't a platform selected then just strip the vmlinux.
  179. ifeq (,$(image-y))
  180. image-y := vmlinux.strip
  181. endif
  182. $(obj)/zImage: $(addprefix $(obj)/, $(image-y))
  183. @rm -f $@; ln $< $@
  184. $(obj)/zImage.initrd: $(addprefix $(obj)/, $(initrd-y))
  185. @rm -f $@; ln $< $@
  186. install: $(CONFIGURE) $(addprefix $(obj)/, $(image-y))
  187. sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" $<
  188. # anything not in $(targets)
  189. clean-files += $(image-) $(initrd-) zImage zImage.initrd cuImage.* treeImage.* \
  190. otheros.bld
  191. # clean up files cached by wrapper
  192. clean-kernel := vmlinux.strip vmlinux.bin
  193. clean-kernel += $(addsuffix .gz,$(clean-kernel))
  194. # If not absolute clean-files are relative to $(obj).
  195. clean-files += $(addprefix $(objtree)/, $(clean-kernel))