Makefile 8.7 KB

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