Makefile 8.1 KB

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