Makefile 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. These are normally HOSTCC,
  15. # but may be a third compiler if, for example, you are cross
  16. # compiling from an intel box. Once the 64bit ppc gcc is
  17. # stable it will probably simply be a compiler switch to
  18. # compile for 32bit mode.
  19. # To make it easier to setup a cross compiler,
  20. # CROSS32_COMPILE is setup as a prefix just like CROSS_COMPILE
  21. # in the toplevel makefile.
  22. all: $(obj)/zImage
  23. HOSTCC := gcc
  24. BOOTCFLAGS := $(HOSTCFLAGS) -fno-builtin -nostdinc -isystem \
  25. $(shell $(CROSS32CC) -print-file-name=include) -fPIC
  26. BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
  27. ifeq ($(call cc-option-yn, -fstack-protector),y)
  28. BOOTCFLAGS += -fno-stack-protector
  29. endif
  30. BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
  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 \
  39. 44x.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c
  40. src-plat := of.c cuboot-83xx.c cuboot-85xx.c holly.c \
  41. cuboot-ebony.c treeboot-ebony.c prpmc2800.c
  42. src-boot := $(src-wlib) $(src-plat) empty.c
  43. src-boot := $(addprefix $(obj)/, $(src-boot))
  44. obj-boot := $(addsuffix .o, $(basename $(src-boot)))
  45. obj-wlib := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-wlib))))
  46. obj-plat := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-plat))))
  47. quiet_cmd_copy_zlib = COPY $@
  48. cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  49. quiet_cmd_copy_zlibheader = COPY $@
  50. cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  51. # stddef.h for NULL
  52. quiet_cmd_copy_zliblinuxheader = COPY $@
  53. cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  54. $(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  55. $(call cmd,copy_zlib)
  56. $(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  57. $(call cmd,copy_zlibheader)
  58. $(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
  59. $(call cmd,copy_zliblinuxheader)
  60. $(obj)/empty.c:
  61. @touch $@
  62. $(obj)/zImage.lds $(obj)/zImage.coff.lds: $(obj)/%: $(srctree)/$(src)/%.S
  63. @cp $< $@
  64. clean-files := $(zlib) $(zlibheader) $(zliblinuxheader) \
  65. empty.c zImage.coff.lds zImage.lds
  66. quiet_cmd_bootcc = BOOTCC $@
  67. cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
  68. quiet_cmd_bootas = BOOTAS $@
  69. cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
  70. quiet_cmd_bootar = BOOTAR $@
  71. cmd_bootar = $(CROSS32AR) -cr $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@
  72. $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c FORCE
  73. $(call if_changed_dep,bootcc)
  74. $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE
  75. $(call if_changed_dep,bootas)
  76. $(obj)/wrapper.a: $(obj-wlib) FORCE
  77. $(call if_changed,bootar)
  78. hostprogs-y := addnote addRamDisk hack-coff mktree
  79. targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a)
  80. extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \
  81. $(obj)/zImage.lds $(obj)/zImage.coff.lds
  82. wrapper :=$(srctree)/$(src)/wrapper
  83. wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree) \
  84. $(wrapper) FORCE
  85. #############
  86. # Bits for building various flavours of zImage
  87. ifneq ($(CROSS32_COMPILE),)
  88. CROSSWRAP := -C "$(CROSS32_COMPILE)"
  89. else
  90. ifneq ($(CROSS_COMPILE),)
  91. CROSSWRAP := -C "$(CROSS_COMPILE)"
  92. endif
  93. endif
  94. # args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd
  95. quiet_cmd_wrap = WRAP $@
  96. cmd_wrap =$(CONFIG_SHELL) $(wrapper) -c -o $@ -p $2 $(CROSSWRAP) \
  97. $(if $3, -s $3)$(if $4, -d $4)$(if $5, -i $5) vmlinux
  98. image-$(CONFIG_PPC_PSERIES) += zImage.pseries
  99. image-$(CONFIG_PPC_MAPLE) += zImage.pseries
  100. image-$(CONFIG_PPC_IBM_CELL_BLADE) += zImage.pseries
  101. image-$(CONFIG_PPC_PS3) += zImage.ps3
  102. image-$(CONFIG_PPC_CELLEB) += zImage.pseries
  103. image-$(CONFIG_PPC_CHRP) += zImage.chrp
  104. image-$(CONFIG_PPC_EFIKA) += zImage.chrp
  105. image-$(CONFIG_PPC_PMAC) += zImage.pmac
  106. image-$(CONFIG_PPC_HOLLY) += zImage.holly-elf
  107. image-$(CONFIG_PPC_PRPMC2800) += zImage.prpmc2800
  108. image-$(CONFIG_DEFAULT_UIMAGE) += uImage
  109. ifneq ($(CONFIG_DEVICE_TREE),"")
  110. image-$(CONFIG_PPC_83xx) += cuImage.83xx
  111. image-$(CONFIG_PPC_85xx) += cuImage.85xx
  112. image-$(CONFIG_EBONY) += treeImage.ebony cuImage.ebony
  113. endif
  114. # For 32-bit powermacs, build the COFF and miboot images
  115. # as well as the ELF images.
  116. ifeq ($(CONFIG_PPC32),y)
  117. image-$(CONFIG_PPC_PMAC) += zImage.coff zImage.miboot
  118. endif
  119. initrd- := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-))
  120. initrd-y := $(patsubst zImage%, zImage.initrd%, \
  121. $(patsubst treeImage%, treeImage.initrd%, $(image-y)))
  122. initrd-y := $(filter-out $(image-y), $(initrd-y))
  123. targets += $(image-y) $(initrd-y)
  124. $(addprefix $(obj)/, $(initrd-y)): $(obj)/ramdisk.image.gz
  125. dts- := $(patsubst zImage%, zImage.dts%, $(image-n) $(image-))
  126. dts-y := $(patsubst zImage%, zImage.dts%, $(image-y))
  127. dts-y := $(filter-out $(image-y), $(dts-y))
  128. targets += $(image-y) $(dts-y)
  129. dts_initrd- := $(patsubst zImage%, zImage.dts_initrd%, $(image-n) $(image-))
  130. dts_initrd-y := $(patsubst zImage%, zImage.dts_initrd%, $(image-y))
  131. dts_initrd-y := $(filter-out $(image-y), $(dts_initrd-y))
  132. targets += $(image-y) $(dts_initrd-y)
  133. $(addprefix $(obj)/, $(dts_initrd-y)): $(obj)/ramdisk.image.gz
  134. # Don't put the ramdisk on the pattern rule; when its missing make will try
  135. # the pattern rule with less dependencies that also matches (even with the
  136. # hard dependency listed).
  137. $(obj)/zImage.dts_initrd.%: vmlinux $(wrapperbits) $(dts) $(obj)/ramdisk.image.gz
  138. $(call if_changed,wrap,$*,$(dts),,$(obj)/ramdisk.image.gz)
  139. $(obj)/zImage.dts.%: vmlinux $(wrapperbits) $(dts)
  140. $(call if_changed,wrap,$*,$(dts))
  141. $(obj)/zImage.initrd.%: vmlinux $(wrapperbits)
  142. $(call if_changed,wrap,$*,,,$(obj)/ramdisk.image.gz)
  143. $(obj)/zImage.%: vmlinux $(wrapperbits)
  144. $(call if_changed,wrap,$*)
  145. $(obj)/zImage.ps3: vmlinux
  146. $(STRIP) -s -R .comment $< -o $@
  147. $(obj)/zImage.initrd.ps3: vmlinux
  148. @echo " WARNING zImage.initrd.ps3 not supported (yet)"
  149. $(obj)/zImage.holly-elf: vmlinux $(wrapperbits)
  150. $(call if_changed,wrap,holly,$(obj)/dts/holly.dts,,)
  151. $(obj)/zImage.initrd.holly-elf: vmlinux $(wrapperbits) $(obj)/ramdisk.image.gz
  152. $(call if_changed,wrap,holly,$(obj)/dts/holly.dts,,$(obj)/ramdisk.image.gz)
  153. $(obj)/uImage: vmlinux $(wrapperbits)
  154. $(call if_changed,wrap,uboot)
  155. # CONFIG_DEVICE_TREE will have "" around it, make sure to strip them
  156. dts = $(if $(shell echo $(CONFIG_DEVICE_TREE) | grep '^/'),\
  157. ,$(srctree)/$(src)/dts/)$(CONFIG_DEVICE_TREE:"%"=%)
  158. $(obj)/cuImage.%: vmlinux $(dts) $(wrapperbits)
  159. $(call if_changed,wrap,cuboot-$*,$(dts))
  160. $(obj)/treeImage.%: vmlinux $(dts) $(wrapperbits)
  161. $(call if_changed,wrap,treeboot-$*,$(dts))
  162. $(obj)/treeImage.initrd.%: vmlinux $(dts) $(wrapperbits)
  163. $(call if_changed,wrap,treeboot-$*,$(dts),,$(obj)/ramdisk.image.gz)
  164. $(obj)/zImage: $(addprefix $(obj)/, $(image-y))
  165. @rm -f $@; ln $< $@
  166. $(obj)/zImage.initrd: $(addprefix $(obj)/, $(initrd-y))
  167. @rm -f $@; ln $< $@
  168. $(obj)/zImage.dts: $(addprefix $(obj)/, $(dts-y))
  169. @rm -f $@; ln $< $@
  170. $(obj)/zImage.dts_initrd: $(addprefix $(obj)/, $(dts_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.* \
  176. treeImage.* zImage.dts zImage.dts_initrd
  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))