Makefile 7.3 KB

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