home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / src / linux-headers-2.6.17-6 / arch / powerpc / boot / Makefile
Encoding:
Makefile  |  2006-08-11  |  8.1 KB  |  220 lines

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