Makefile 8.0 KB

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