Makefile 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. BOOTLFLAGS := -T $(srctree)/$(src)/zImage.lds
  27. OBJCOPYFLAGS := contents,alloc,load,readonly,data
  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 := string.S prom.c main.c div64.S crt0.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) $(BOOTLFLAGS) -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
  71. targets += zImage.vmode zImage.initrd.vmode zImage zImage.initrd \
  72. $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
  73. $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
  74. $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
  75. vmlinux.initrd
  76. extra-y := initrd.o
  77. quiet_cmd_ramdisk = RAMDISK $@
  78. cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@
  79. quiet_cmd_stripvm = STRIP $@
  80. cmd_stripvm = $(STRIP) -s -R .comment $< -o $@
  81. vmlinux.strip: vmlinux
  82. $(call if_changed,stripvm)
  83. $(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz
  84. $(call if_changed,ramdisk)
  85. quiet_cmd_addsection = ADDSEC $@
  86. cmd_addsection = $(CROSS32OBJCOPY) $@ \
  87. --add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(patsubst %.o,%.gz, $@) \
  88. --set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(OBJCOPYFLAGS)
  89. quiet_cmd_addnote = ADDNOTE $@
  90. cmd_addnote = $(obj)/addnote $@
  91. $(call gz-sec, $(required)): $(obj)/kernel-%.gz: %
  92. $(call if_changed,gzip)
  93. $(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
  94. cp -f $(obj)/ramdisk.image.gz $@
  95. $(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz
  96. @touch $@
  97. $(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c
  98. $(call if_changed_dep,bootcc)
  99. $(call cmd,addsection)
  100. $(obj)/zImage.vmode: obj-boot += $(call obj-sec, $(required))
  101. $(obj)/zImage.vmode: $(call obj-sec, $(required)) $(obj-boot) $(srctree)/$(src)/zImage.lds
  102. $(call cmd,bootld,$(obj-boot))
  103. $(obj)/zImage.initrd.vmode: obj-boot += $(call obj-sec, $(required) $(initrd))
  104. $(obj)/zImage.initrd.vmode: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(srctree)/$(src)/zImage.lds
  105. $(call cmd,bootld,$(obj-boot))
  106. $(obj)/zImage: $(obj)/zImage.vmode $(obj)/addnote
  107. @cp -f $< $@
  108. $(call if_changed,addnote)
  109. $(obj)/zImage.initrd: $(obj)/zImage.initrd.vmode $(obj)/addnote
  110. @cp -f $< $@
  111. $(call if_changed,addnote)
  112. #-----------------------------------------------------------
  113. # build u-boot images
  114. #-----------------------------------------------------------
  115. quiet_cmd_mygzip = GZIP $@
  116. cmd_mygzip = gzip -f -9 < $< > $@.$$$$ && mv $@.$$$$ $@
  117. quiet_cmd_objbin = OBJCOPY $@
  118. cmd_objbin = $(OBJCOPY) -O binary $< $@
  119. quiet_cmd_uimage = UIMAGE $@
  120. cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A ppc -O linux -T kernel \
  121. -C gzip -a 00000000 -e 00000000 -n 'Linux-$(KERNELRELEASE)' \
  122. -d $< $@
  123. MKIMAGE := $(srctree)/scripts/mkuboot.sh
  124. targets += uImage
  125. extra-y += vmlinux.bin vmlinux.gz
  126. $(obj)/vmlinux.bin: vmlinux FORCE
  127. $(call if_changed,objbin)
  128. $(obj)/vmlinux.gz: $(obj)/vmlinux.bin FORCE
  129. $(call if_changed,mygzip)
  130. $(obj)/uImage: $(obj)/vmlinux.gz
  131. $(Q)rm -f $@
  132. $(call cmd,uimage)
  133. @echo -n ' Image: $@ '
  134. @if [ -f $@ ]; then echo 'is ready' ; else echo 'not made'; fi
  135. install: $(CONFIGURE) $(BOOTIMAGE)
  136. sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" "$(BOOTIMAGE)"
  137. clean-files += $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)