blob: d3567e47cbba4b2bec6275484d9d78620f19882e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001# 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
24HOSTCC := gcc
Olaf Heringdecd3002005-08-08 13:24:38 +100025BOOTCFLAGS := $(HOSTCFLAGS) -fno-builtin -nostdinc -isystem $(shell $(CROSS32CC) -print-file-name=include)
26BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
Linus Torvalds1da177e2005-04-16 15:20:36 -070027BOOTLFLAGS := -Ttext 0x00400000 -e _start -T $(srctree)/$(src)/zImage.lds
28OBJCOPYFLAGS := contents,alloc,load,readonly,data
29
30src-boot := crt0.S string.S prom.c main.c zlib.c imagesize.c div64.S
31src-boot := $(addprefix $(obj)/, $(src-boot))
32obj-boot := $(addsuffix .o, $(basename $(src-boot)))
33
34quiet_cmd_bootcc = BOOTCC $@
35 cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
36
37quiet_cmd_bootas = BOOTAS $@
38 cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
39
Geoff Levanda24c8482005-08-15 13:59:13 -070040quiet_cmd_bootld = BOOTLD $@
41 cmd_bootld = $(CROSS32LD) $(BOOTLFLAGS) -o $@ $(2)
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043$(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c
44 $(call if_changed_dep,bootcc)
45$(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S
46 $(call if_changed_dep,bootas)
47
48#-----------------------------------------------------------
49# ELF sections within the zImage bootloader/wrapper
50#-----------------------------------------------------------
51required := vmlinux.strip
52initrd := initrd
53
54obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
55src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
56gz-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))
57
Olaf Hering45891f762005-06-28 21:01:21 +100058hostprogs-y := addnote addRamDisk
Geoff Levanda24c8482005-08-15 13:59:13 -070059targets += zImage.vmode zImage.initrd.vmode zImage zImage.initrd imagesize.c \
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
61 $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
62 $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
63 vmlinux.initrd
64extra-y := initrd.o
65
66quiet_cmd_ramdisk = RAMDISK $@
67 cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@
68
69quiet_cmd_stripvm = STRIP $@
70 cmd_stripvm = $(STRIP) -s $< -o $@
71
72vmlinux.strip: vmlinux FORCE
73 $(call if_changed,stripvm)
74$(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz FORCE
75 $(call if_changed,ramdisk)
76
77addsection = $(CROSS32OBJCOPY) $(1) \
78 --add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(patsubst %.o,%.gz, $(1)) \
79 --set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $(1)))=$(OBJCOPYFLAGS)
80
Geoff Levanda24c8482005-08-15 13:59:13 -070081quiet_cmd_addnote = ADDNOTE $@
82 cmd_addnote = $(obj)/addnote $@
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084$(call gz-sec, $(required)): $(obj)/kernel-%.gz: % FORCE
85 $(call if_changed,gzip)
86
87$(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
88 cp -f $(obj)/ramdisk.image.gz $@
89
90$(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz FORCE
91 touch $@
92
93$(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c FORCE
94 $(call if_changed_dep,bootcc)
95 $(call addsection, $@)
96
Geoff Levanda24c8482005-08-15 13:59:13 -070097$(obj)/zImage.vmode: obj-boot += $(call obj-sec, $(required))
98$(obj)/zImage.vmode: $(call obj-sec, $(required)) $(obj-boot) FORCE
99 $(call cmd,bootld,$(obj-boot))
100
101$(obj)/zImage.initrd.vmode: obj-boot += $(call obj-sec, $(required) $(initrd))
102$(obj)/zImage.initrd.vmode: $(call obj-sec, $(required) $(initrd)) $(obj-boot) FORCE
103 $(call cmd,bootld,$(obj-boot))
104
105$(obj)/zImage: $(obj)/zImage.vmode $(obj)/addnote FORCE
106 @cp -f $< $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 $(call if_changed,addnote)
108
Geoff Levanda24c8482005-08-15 13:59:13 -0700109$(obj)/zImage.initrd: $(obj)/zImage.initrd.vmode $(obj)/addnote FORCE
110 @cp -f $< $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 $(call if_changed,addnote)
112
113$(obj)/imagesize.c: vmlinux.strip
114 @echo Generating $@
115 ls -l vmlinux.strip | \
116 awk '{printf "/* generated -- do not edit! */\n" \
117 "unsigned long vmlinux_filesize = %d;\n", $$5}' > $(obj)/imagesize.c
118 $(CROSS_COMPILE)nm -n vmlinux | tail -n 1 | \
119 awk '{printf "unsigned long vmlinux_memsize = 0x%s;\n", substr($$1,8)}' \
120 >> $(obj)/imagesize.c
121
122install: $(CONFIGURE) $(BOOTIMAGE)
123 sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" "$(BOOTIMAGE)"
124
125clean-files := $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)