Makefile 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. HOSTCC := gcc
  23. BOOTCFLAGS := $(HOSTCFLAGS) -fno-builtin -nostdinc -isystem \
  24. $(shell $(CROSS32CC) -print-file-name=include) -fPIC
  25. BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
  26. OBJCOPYFLAGS := contents,alloc,load,readonly,data
  27. OBJCOPY_COFF_ARGS := -O aixcoff-rs6000 --set-start 0x500000
  28. OBJCOPY_MIB_ARGS := -O aixcoff-rs6000 -R .stab -R .stabstr -R .comment
  29. zlib := inffast.c inflate.c inftrees.c
  30. zlibheader := inffast.h inffixed.h inflate.h inftrees.h infutil.h
  31. zliblinuxheader := zlib.h zconf.h zutil.h
  32. $(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader))
  33. #$(addprefix $(obj)/,main.o): $(addprefix $(obj)/,zlib.h)
  34. src-boot := crt0.S string.S prom.c stdio.c main.c div64.S
  35. src-boot += $(zlib)
  36. src-boot := $(addprefix $(obj)/, $(src-boot))
  37. obj-boot := $(addsuffix .o, $(basename $(src-boot)))
  38. ifeq ($(call cc-option-yn, -fstack-protector),y)
  39. BOOTCFLAGS += -fno-stack-protector
  40. endif
  41. BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
  42. quiet_cmd_copy_zlib = COPY $@
  43. cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  44. quiet_cmd_copy_zlibheader = COPY $@
  45. cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  46. # stddef.h for NULL
  47. quiet_cmd_copy_zliblinuxheader = COPY $@
  48. cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  49. $(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  50. $(call cmd,copy_zlib)
  51. $(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  52. $(call cmd,copy_zlibheader)
  53. $(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
  54. $(call cmd,copy_zliblinuxheader)
  55. clean-files := $(zlib) $(zlibheader) $(zliblinuxheader)
  56. quiet_cmd_bootcc = BOOTCC $@
  57. cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
  58. quiet_cmd_bootas = BOOTAS $@
  59. cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
  60. quiet_cmd_bootld = BOOTLD $@
  61. cmd_bootld = $(CROSS32LD) -T $(srctree)/$(src)/$(3) -o $@ $(2)
  62. $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c
  63. $(call if_changed_dep,bootcc)
  64. $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S
  65. $(call if_changed_dep,bootas)
  66. #-----------------------------------------------------------
  67. # ELF sections within the zImage bootloader/wrapper
  68. #-----------------------------------------------------------
  69. required := vmlinux.strip
  70. initrd := initrd
  71. obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
  72. src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
  73. gz-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))
  74. hostprogs-y := addnote addRamDisk hack-coff
  75. targets += zImage.vmode zImage.initrd.vmode zImage zImage.initrd \
  76. zImage.coff zImage.initrd.coff miboot.image miboot.initrd.image \
  77. $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
  78. $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
  79. $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
  80. vmlinux.initrd dummy.o
  81. extra-y := initrd.o
  82. quiet_cmd_ramdisk = RAMDISK $@
  83. cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@
  84. quiet_cmd_stripvm = STRIP $@
  85. cmd_stripvm = $(STRIP) -s -R .comment $< -o $@
  86. vmlinux.strip: vmlinux
  87. $(call if_changed,stripvm)
  88. $(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz
  89. $(call if_changed,ramdisk)
  90. quiet_cmd_addsection = ADDSEC $@
  91. cmd_addsection = $(CROSS32OBJCOPY) $@ \
  92. --add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(patsubst %.o,%.gz, $@) \
  93. --set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(OBJCOPYFLAGS)
  94. quiet_cmd_addnote = ADDNOTE $@
  95. cmd_addnote = $(obj)/addnote $@
  96. quiet_cmd_gen-miboot = GEN $@
  97. cmd_gen-miboot = $(OBJCOPY) $(OBJCOPY_MIB_ARGS) \
  98. --add-section=$1=$(word 2, $^) $< $@
  99. quiet_cmd_gencoff = COFF $@
  100. cmd_gencoff = $(OBJCOPY) $(OBJCOPY_COFF_ARGS) $@ && \
  101. $(obj)/hack-coff $@
  102. $(call gz-sec, $(required)): $(obj)/kernel-%.gz: %
  103. $(call if_changed,gzip)
  104. $(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
  105. cp -f $(obj)/ramdisk.image.gz $@
  106. $(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz
  107. @touch $@
  108. $(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c
  109. $(call if_changed_dep,bootcc)
  110. $(call cmd,addsection)
  111. $(obj)/zImage.vmode $(obj)/zImage.coff: obj-boot += $(call obj-sec, $(required))
  112. $(obj)/zImage.vmode: $(call obj-sec, $(required)) $(obj-boot) $(srctree)/$(src)/zImage.lds
  113. $(call cmd,bootld,$(obj-boot),zImage.lds)
  114. $(obj)/zImage.initrd.vmode $(obj)/zImage.initrd.coff: obj-boot += $(call obj-sec, $(required) $(initrd))
  115. $(obj)/zImage.initrd.vmode: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(srctree)/$(src)/zImage.lds
  116. $(call cmd,bootld,$(obj-boot),zImage.lds)
  117. # For 32-bit powermacs, build the COFF and miboot images
  118. # as well as the ELF images.
  119. coffimage-$(CONFIG_PPC_PMAC)-$(CONFIG_PPC32) := $(obj)/zImage.coff
  120. coffrdimg-$(CONFIG_PPC_PMAC)-$(CONFIG_PPC32) := $(obj)/zImage.initrd.coff
  121. mibootimg-$(CONFIG_PPC_PMAC)-$(CONFIG_PPC32) := $(obj)/miboot.image
  122. mibrdimg-$(CONFIG_PPC_PMAC)-$(CONFIG_PPC32) := $(obj)/miboot.initrd.image
  123. $(obj)/zImage: $(obj)/zImage.vmode $(obj)/addnote $(coffimage-y-y) \
  124. $(mibootimg-y-y)
  125. @cp -f $< $@
  126. $(call if_changed,addnote)
  127. $(obj)/zImage.initrd: $(obj)/zImage.initrd.vmode $(obj)/addnote \
  128. $(coffrdimg-y-y) $(mibrdimg-y-y)
  129. @cp -f $< $@
  130. $(call if_changed,addnote)
  131. $(obj)/zImage.coff: $(call obj-sec, $(required)) $(obj-boot) \
  132. $(srctree)/$(src)/zImage.coff.lds $(obj)/hack-coff
  133. $(call cmd,bootld,$(obj-boot),zImage.coff.lds)
  134. $(call cmd,gencoff)
  135. $(obj)/zImage.initrd.coff: $(call obj-sec, $(required) $(initrd)) $(obj-boot) \
  136. $(srctree)/$(src)/zImage.coff.lds $(obj)/hack-coff
  137. $(call cmd,bootld,$(obj-boot),zImage.coff.lds)
  138. $(call cmd,gencoff)
  139. $(obj)/miboot.image: $(obj)/dummy.o $(obj)/vmlinux.gz
  140. $(call cmd,gen-miboot,image)
  141. $(obj)/miboot.initrd.image: $(obj)/miboot.image $(images)/ramdisk.image.gz
  142. $(call cmd,gen-miboot,initrd)
  143. #-----------------------------------------------------------
  144. # build u-boot images
  145. #-----------------------------------------------------------
  146. quiet_cmd_mygzip = GZIP $@
  147. cmd_mygzip = gzip -f -9 < $< > $@.$$$$ && mv $@.$$$$ $@
  148. quiet_cmd_objbin = OBJCOPY $@
  149. cmd_objbin = $(OBJCOPY) -O binary $< $@
  150. quiet_cmd_uimage = UIMAGE $@
  151. cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A ppc -O linux -T kernel \
  152. -C gzip -a 00000000 -e 00000000 -n 'Linux-$(KERNELRELEASE)' \
  153. -d $< $@
  154. MKIMAGE := $(srctree)/scripts/mkuboot.sh
  155. targets += uImage
  156. extra-y += vmlinux.bin vmlinux.gz
  157. $(obj)/vmlinux.bin: vmlinux FORCE
  158. $(call if_changed,objbin)
  159. $(obj)/vmlinux.gz: $(obj)/vmlinux.bin FORCE
  160. $(call if_changed,mygzip)
  161. $(obj)/uImage: $(obj)/vmlinux.gz
  162. $(Q)rm -f $@
  163. $(call cmd,uimage)
  164. @echo -n ' Image: $@ '
  165. @if [ -f $@ ]; then echo 'is ready' ; else echo 'not made'; fi
  166. install: $(CONFIGURE) $(BOOTIMAGE)
  167. sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" "$(BOOTIMAGE)"
  168. clean-files += $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)