Makefile 8.2 KB

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