Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 $(shell $(CROSS32CC) -print-file-name=include) -fPIC
  24. BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
  25. BOOTLFLAGS := -T $(srctree)/$(src)/zImage.lds
  26. OBJCOPYFLAGS := contents,alloc,load,readonly,data
  27. zlib := infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c
  28. zlibheader := infblock.h infcodes.h inffast.h inftrees.h infutil.h
  29. zliblinuxheader := zlib.h zconf.h zutil.h
  30. $(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader))
  31. #$(addprefix $(obj)/,main.o): $(addprefix $(obj)/,zlib.h)
  32. src-boot := string.S prom.c main.c div64.S crt0.S
  33. src-boot += $(zlib)
  34. src-boot := $(addprefix $(obj)/, $(src-boot))
  35. obj-boot := $(addsuffix .o, $(basename $(src-boot)))
  36. BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
  37. quiet_cmd_copy_zlib = COPY $@
  38. cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  39. quiet_cmd_copy_zlibheader = COPY $@
  40. cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  41. # stddef.h for NULL
  42. quiet_cmd_copy_zliblinuxheader = COPY $@
  43. cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
  44. $(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  45. $(call cmd,copy_zlib)
  46. $(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
  47. $(call cmd,copy_zlibheader)
  48. $(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
  49. $(call cmd,copy_zliblinuxheader)
  50. clean-files := $(zlib) $(zlibheader) $(zliblinuxheader)
  51. quiet_cmd_bootcc = BOOTCC $@
  52. cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
  53. quiet_cmd_bootas = BOOTAS $@
  54. cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
  55. quiet_cmd_bootld = BOOTLD $@
  56. cmd_bootld = $(CROSS32LD) $(BOOTLFLAGS) -o $@ $(2)
  57. $(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c
  58. $(call if_changed_dep,bootcc)
  59. $(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S
  60. $(call if_changed_dep,bootas)
  61. #-----------------------------------------------------------
  62. # ELF sections within the zImage bootloader/wrapper
  63. #-----------------------------------------------------------
  64. required := vmlinux.strip
  65. initrd := initrd
  66. obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
  67. src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
  68. gz-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))
  69. hostprogs-y := addnote addRamDisk
  70. targets += zImage.vmode zImage.initrd.vmode zImage zImage.initrd \
  71. $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
  72. $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
  73. $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
  74. vmlinux.initrd
  75. extra-y := initrd.o
  76. quiet_cmd_ramdisk = RAMDISK $@
  77. cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@
  78. quiet_cmd_stripvm = STRIP $@
  79. cmd_stripvm = $(STRIP) -s $< -o $@
  80. vmlinux.strip: vmlinux
  81. $(call if_changed,stripvm)
  82. $(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz
  83. $(call if_changed,ramdisk)
  84. quiet_cmd_addsection = ADDSEC $@
  85. cmd_addsection = $(CROSS32OBJCOPY) $@ \
  86. --add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(patsubst %.o,%.gz, $@) \
  87. --set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(OBJCOPYFLAGS)
  88. quiet_cmd_addnote = ADDNOTE $@
  89. cmd_addnote = $(obj)/addnote $@
  90. $(call gz-sec, $(required)): $(obj)/kernel-%.gz: %
  91. $(call if_changed,gzip)
  92. $(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
  93. cp -f $(obj)/ramdisk.image.gz $@
  94. $(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz
  95. @touch $@
  96. $(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c
  97. $(call if_changed_dep,bootcc)
  98. $(call cmd,addsection)
  99. $(obj)/zImage.vmode: obj-boot += $(call obj-sec, $(required))
  100. $(obj)/zImage.vmode: $(call obj-sec, $(required)) $(obj-boot) $(srctree)/$(src)/zImage.lds
  101. $(call cmd,bootld,$(obj-boot))
  102. $(obj)/zImage.initrd.vmode: obj-boot += $(call obj-sec, $(required) $(initrd))
  103. $(obj)/zImage.initrd.vmode: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(srctree)/$(src)/zImage.lds
  104. $(call cmd,bootld,$(obj-boot))
  105. $(obj)/zImage: $(obj)/zImage.vmode $(obj)/addnote
  106. @cp -f $< $@
  107. $(call if_changed,addnote)
  108. $(obj)/zImage.initrd: $(obj)/zImage.initrd.vmode $(obj)/addnote
  109. @cp -f $< $@
  110. $(call if_changed,addnote)
  111. install: $(CONFIGURE) $(BOOTIMAGE)
  112. sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" "$(BOOTIMAGE)"
  113. clean-files := $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)