Makefile 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) \
  35. $(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. src-plat := of.c cuboot-83xx.c cuboot-85xx.c
  40. src-boot := $(src-wlib) $(src-plat) empty.c
  41. src-boot := $(addprefix $(obj)/, $(src-boot))
  42. obj-boot := $(addsuffix .o, $(basename $(src-boot)))
  43. obj-wlib := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-wlib))))
  44. obj-plat := $(addsuffix .o, $(basename $(addprefix $(obj)/, $(src-plat))))
  45. quiet_cmd_copy_zlib = COPY $@
  46. cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  47. quiet_cmd_copy_zlibheader = COPY $@
  48. cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  49. # stddef.h for NULL
  50. quiet_cmd_copy_zliblinuxheader = COPY $@
  51. cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  52. $(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  53. $(call cmd,copy_zlib)
  54. $(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  55. $(call cmd,copy_zlibheader)
  56. $(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
  57. $(call cmd,copy_zliblinuxheader)
  58. $(obj)/empty.c:
  59. @touch $@
  60. $(obj)/zImage.lds $(obj)/zImage.coff.lds: $(obj)/%: $(srctree)/$(src)/%.S
  61. @cp $< $@
  62. clean-files := $(zlib) $(zlibheader) $(zliblinuxheader) \
  63. empty.c zImage.coff.lds zImage.lds
  64. quiet_cmd_bootcc = BOOTCC $@
  65. cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
  66. quiet_cmd_bootas = BOOTAS $@
  67. cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
  68. quiet_cmd_bootar = BOOTAR $@
  69. cmd_bootar = $(CROSS32AR) -cr $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@
  70. $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c FORCE
  71. $(call if_changed_dep,bootcc)
  72. $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S FORCE
  73. $(call if_changed_dep,bootas)
  74. $(obj)/wrapper.a: $(obj-wlib) FORCE
  75. $(call if_changed,bootar)
  76. hostprogs-y := addnote addRamDisk hack-coff mktree
  77. targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a)
  78. extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \
  79. $(obj)/zImage.lds $(obj)/zImage.coff.lds
  80. wrapper :=$(srctree)/$(src)/wrapper
  81. wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree) \
  82. $(wrapper) FORCE
  83. #############
  84. # Bits for building various flavours of zImage
  85. ifneq ($(CROSS32_COMPILE),)
  86. CROSSWRAP := -C "$(CROSS32_COMPILE)"
  87. else
  88. ifneq ($(CROSS_COMPILE),)
  89. CROSSWRAP := -C "$(CROSS_COMPILE)"
  90. endif
  91. endif
  92. # args (to if_changed): 1 = (this rule), 2 = platform, 3 = dts 4=dtb 5=initrd
  93. quiet_cmd_wrap = WRAP $@
  94. cmd_wrap =$(CONFIG_SHELL) $(wrapper) -c -o $@ -p $2 $(CROSSWRAP) \
  95. $(if $3, -s $3)$(if $4, -d $4)$(if $5, -i $5) vmlinux
  96. image-$(CONFIG_PPC_PSERIES) += zImage.pseries
  97. image-$(CONFIG_PPC_MAPLE) += zImage.pseries
  98. image-$(CONFIG_PPC_IBM_CELL_BLADE) += zImage.pseries
  99. image-$(CONFIG_PPC_PS3) += zImage.ps3
  100. image-$(CONFIG_PPC_CELLEB) += zImage.pseries
  101. image-$(CONFIG_PPC_CHRP) += zImage.chrp
  102. image-$(CONFIG_PPC_EFIKA) += zImage.chrp
  103. image-$(CONFIG_PPC_PMAC) += zImage.pmac
  104. image-$(CONFIG_DEFAULT_UIMAGE) += uImage cuImage
  105. # For 32-bit powermacs, build the COFF and miboot images
  106. # as well as the ELF images.
  107. ifeq ($(CONFIG_PPC32),y)
  108. image-$(CONFIG_PPC_PMAC) += zImage.coff zImage.miboot
  109. endif
  110. initrd- := $(patsubst zImage%, zImage.initrd%, $(image-n) $(image-))
  111. initrd-y := $(patsubst zImage%, zImage.initrd%, $(image-y))
  112. initrd-y := $(filter-out $(image-y), $(initrd-y))
  113. targets += $(image-y) $(initrd-y)
  114. $(addprefix $(obj)/, $(initrd-y)): $(obj)/ramdisk.image.gz
  115. # Don't put the ramdisk on the pattern rule; when its missing make will try
  116. # the pattern rule with less dependencies that also matches (even with the
  117. # hard dependency listed).
  118. $(obj)/zImage.initrd.%: vmlinux $(wrapperbits)
  119. $(call if_changed,wrap,$*,,,$(obj)/ramdisk.image.gz)
  120. $(obj)/zImage.%: vmlinux $(wrapperbits)
  121. $(call if_changed,wrap,$*)
  122. $(obj)/zImage.ps3: vmlinux
  123. $(STRIP) -s -R .comment $< -o $@
  124. $(obj)/zImage.initrd.ps3: vmlinux
  125. @echo " WARNING zImage.initrd.ps3 not supported (yet)"
  126. $(obj)/uImage: vmlinux $(wrapperbits)
  127. $(call if_changed,wrap,uboot)
  128. cuboot-plat-$(CONFIG_83xx) += 83xx
  129. cuboot-plat-$(CONFIG_85xx) += 85xx
  130. cuboot-plat-y += unknown-platform
  131. dts = $(if $(shell echo $(CONFIG_DEVICE_TREE) | grep '^/'),\
  132. ,$(srctree)/$(src)/dts/)$(CONFIG_DEVICE_TREE)
  133. $(obj)/cuImage: vmlinux $(wrapperbits)
  134. $(call if_changed,wrap,cuboot-$(word 1,$(cuboot-plat-y)),$(dts))
  135. $(obj)/zImage: $(addprefix $(obj)/, $(image-y))
  136. @rm -f $@; ln $< $@
  137. $(obj)/zImage.initrd: $(addprefix $(obj)/, $(initrd-y))
  138. @rm -f $@; ln $< $@
  139. install: $(CONFIGURE) $(addprefix $(obj)/, $(image-y))
  140. sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" $<
  141. # anything not in $(targets)
  142. clean-files += $(image-) $(initrd-) zImage zImage.initrd \
  143. cuImage.elf cuImage.bin.gz
  144. # clean up files cached by wrapper
  145. clean-kernel := vmlinux.strip vmlinux.bin
  146. clean-kernel += $(addsuffix .gz,$(clean-kernel))
  147. # If not absolute clean-files are relative to $(obj).
  148. clean-files += $(addprefix $(objtree)/, $(clean-kernel))