Makefile 8.1 KB

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