Makefile 4.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Makefile for making ELF bootable images for booting on CHRP
# using Open Firmware.
#
# Geert Uytterhoeven	September 1997
#
# Based on coffboot by Paul Mackerras
# Simplified for ppc64 by Todd Inglett
#
# NOTE:	this code is built for 32 bit in ELF32 format even though
#	it packages a 64 bit kernel.  We do this to simplify the
#	bootloader and increase compatibility with OpenFirmware.
#
#	To this end we need to define BOOTCC, etc, as the tools
#	needed to build the 32 bit image.  These are normally HOSTCC,
#	but may be a third compiler if, for example, you are cross
#	compiling from an intel box.  Once the 64bit ppc gcc is
#	stable it will probably simply be a compiler switch to
#	compile for 32bit mode.
#	To make it easier to setup a cross compiler,
#	CROSS32_COMPILE is setup as a prefix just like CROSS_COMPILE
#	in the toplevel makefile.

CROSS32_COMPILE =
#CROSS32_COMPILE = /usr/local/ppc/bin/powerpc-linux-

26
BOOTCC		:= $(CROSS32_COMPILE)gcc
27 28
HOSTCC		:= gcc
BOOTCFLAGS	:= $(HOSTCFLAGS) -Iinclude -fno-builtin 
29
BOOTAS		:= $(CROSS32_COMPILE)as
30 31 32 33 34
BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional
BOOTLD		:= $(CROSS32_COMPILE)ld
BOOTLFLAGS	:= -Ttext 0x00400000 -e _start -T $(obj)/zImage.lds
BOOTOBJCOPY	:= $(CROSS32_COMPILE)objcopy
OBJCOPYFLAGS    := contents,alloc,load,readonly,data
35

36
src-boot := crt0.S string.S prom.c main.c zlib.c imagesize.c div64.S
37 38
src-boot := $(addprefix $(obj)/, $(src-boot))
obj-boot := $(addsuffix .o, $(basename $(src-boot)))
39 40 41 42 43

quiet_cmd_bootcc = BOOTCC  $@
      cmd_bootcc = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<

quiet_cmd_bootas = BOOTAS  $@
44 45 46 47 48
      cmd_bootas = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<

$(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c
	$(call if_changed_dep,bootcc)
$(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S
49 50
	$(call if_changed_dep,bootas)

51 52 53 54 55 56 57 58 59 60 61
#-----------------------------------------------------------
# ELF sections within the zImage bootloader/wrapper
#-----------------------------------------------------------
required := vmlinux .config System.map
initrd   := initrd

obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
gz-sec  = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))

host-progs		:= piggy addnote addSystemMap addRamDisk
62
targets 		+= zImage zImage.initrd imagesize.c \
63 64 65
			   $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
			   $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
			   $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
66
			   vmlinux.sm vmlinux.initrd vmlinux.sminitrd
67
extra-y			:= sysmap.o initrd.o
68 69 70 71 72 73 74 75 76 77 78 79 80 81

quiet_cmd_sysmap = SYSMAP   $@
      cmd_sysmap = $(obj)/addSystemMap System.map $< $@
$(obj)/vmlinux.sm: vmlinux $(obj)/addSystemMap System.map FORCE
	$(call if_changed,sysmap)

quiet_cmd_ramdisk = RAMDISK $@
      cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz System.map $< $@
$(obj)/vmlinux.initrd: vmlinux $(obj)/addRamDisk $(obj)/ramdisk.image.gz System.map FORCE
	$(call if_changed,ramdisk)

$(obj)/vmlinux.sminitrd: $(obj)/vmlinux.sm $(obj)/addRamDisk $(obj)/ramdisk.image.gz FORCE
	$(call if_changed,ramdisk)

Sam Ravnborg's avatar
Sam Ravnborg committed
82
$(obj)/sysmap.o: System.map $(obj)/piggyback FORCE
83 84 85 86 87 88 89 90
	$(call if_changed,piggy)

addsection = $(BOOTOBJCOPY) $(1) \
		--add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(patsubst %.o,%.gz, $(1)) \
		--set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(OBJCOPYFLAGS)

quiet_cmd_addnote = ADDNOTE $@ 
      cmd_addnote = $(BOOTLD) $(BOOTLFLAGS) -o $@ $(obj-boot) && $(obj)/addnote $@
91 92 93 94

quiet_cmd_piggy = PIGGY   $@
      cmd_piggy = $(obj)/piggyback $(@:.o=) < $< | $(BOOTAS) -o $@

Sam Ravnborg's avatar
Sam Ravnborg committed
95
$(call gz-sec, $(required)): $(obj)/kernel-%.gz: % FORCE
96
	$(call if_changed,gzip)
97

98 99
$(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
	cp -f $(obj)/ramdisk.image.gz $@
100

101
$(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz FORCE
102
	touch $@
103

Sam Ravnborg's avatar
Sam Ravnborg committed
104
$(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c FORCE
105 106
	$(call if_changed_dep,bootcc)
	$(call addsection, $@)
107

108 109
$(obj)/zImage: obj-boot += $(call obj-sec, $(required))
$(obj)/zImage: $(call obj-sec, $(required)) $(obj-boot) $(obj)/addnote FORCE
110 111
	$(call if_changed,addnote)

112 113
$(obj)/zImage.initrd: obj-boot += $(call obj-sec, $(required) $(initrd))
$(obj)/zImage.initrd: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(obj)/addnote FORCE
114 115 116 117 118 119
	$(call if_changed,addnote)

$(obj)/imagesize.c: vmlinux
	@echo Generating $@
	ls -l vmlinux | \
	awk '{printf "/* generated -- do not edit! */\n" \
120
		"unsigned long vmlinux_filesize = %d;\n", $$5}' > $(obj)/imagesize.c
Alan Cox's avatar
Alan Cox committed
121
	$(CROSS_COMPILE)nm -n vmlinux | tail -n 1 | \
122
	awk '{printf "unsigned long vmlinux_memsize = 0x%s;\n", substr($$1,8)}' \
123 124
		>> $(obj)/imagesize.c

125 126
install: $(CONFIGURE) $(BOOTIMAGE)
	sh -x $(src)/install.sh "$(KERNELRELEASE)" "$(obj)/zImage" "$(TOPDIR)/System.map" "$(INSTALL_PATH)"
127 128

clean-files := $(patsubst $(obj)/%,%, $(obj-boot))