blob: 3c78d72a84bb4b186002d85eda14d178ffc9fe15 [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
Olaf Hering70540362005-10-28 17:46:38 -070030zlib := infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c
31zlibheader := infblock.h infcodes.h inffast.h inftrees.h infutil.h
32zliblinuxheader := zlib.h zconf.h zutil.h
33
34$(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader))
35#$(addprefix $(obj)/,main.o): $(addprefix $(obj)/,zlib.h)
36
37src-boot := crt0.S string.S prom.c main.c imagesize.c div64.S
38src-boot += $(zlib)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039src-boot := $(addprefix $(obj)/, $(src-boot))
40obj-boot := $(addsuffix .o, $(basename $(src-boot)))
41
Olaf Hering70540362005-10-28 17:46:38 -070042BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
43
44quiet_cmd_copy_zlib = COPY $@
45 cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
46
47quiet_cmd_copy_zlibheader = COPY $@
48 cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
49# stddef.h for NULL
50quiet_cmd_copy_zliblinuxheader = COPY $@
51 cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
52
53$(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
54 $(call cmd,copy_zlib)
55
56$(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
57 $(call cmd,copy_zlibheader)
58
59$(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
60 $(call cmd,copy_zliblinuxheader)
61
62clean-files := $(zlib) $(zlibheader) $(zliblinuxheader)
63
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065quiet_cmd_bootcc = BOOTCC $@
66 cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
67
68quiet_cmd_bootas = BOOTAS $@
69 cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
70
Geoff Levanda24c8482005-08-15 13:59:13 -070071quiet_cmd_bootld = BOOTLD $@
72 cmd_bootld = $(CROSS32LD) $(BOOTLFLAGS) -o $@ $(2)
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074$(patsubst %.c,%.o, $(filter %.c, $(src-boot))): %.o: %.c
75 $(call if_changed_dep,bootcc)
76$(patsubst %.S,%.o, $(filter %.S, $(src-boot))): %.o: %.S
77 $(call if_changed_dep,bootas)
78
79#-----------------------------------------------------------
80# ELF sections within the zImage bootloader/wrapper
81#-----------------------------------------------------------
82required := vmlinux.strip
83initrd := initrd
84
85obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
86src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
87gz-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))
88
Olaf Hering45891f762005-06-28 21:01:21 +100089hostprogs-y := addnote addRamDisk
Geoff Levanda24c8482005-08-15 13:59:13 -070090targets += zImage.vmode zImage.initrd.vmode zImage zImage.initrd imagesize.c \
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
92 $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
93 $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
94 vmlinux.initrd
95extra-y := initrd.o
96
97quiet_cmd_ramdisk = RAMDISK $@
98 cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@
99
Geoff Levande4df7672005-08-10 17:57:42 -0700100quiet_cmd_stripvm = STRIP $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 cmd_stripvm = $(STRIP) -s $< -o $@
102
103vmlinux.strip: vmlinux FORCE
104 $(call if_changed,stripvm)
105$(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz FORCE
106 $(call if_changed,ramdisk)
107
Geoff Levande4df7672005-08-10 17:57:42 -0700108quiet_cmd_addsection = ADDSEC $@
109 cmd_addsection = $(CROSS32OBJCOPY) $@ \
110 --add-section=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(patsubst %.o,%.gz, $@) \
111 --set-section-flags=.kernel:$(strip $(patsubst $(obj)/kernel-%.o,%, $@))=$(OBJCOPYFLAGS)
112
113quiet_cmd_imagesize = GENSIZE $@
114 cmd_imagesize = ls -l vmlinux.strip | \
115 awk '{printf "/* generated -- do not edit! */\n" "unsigned long vmlinux_filesize = %d;\n", $$5}' \
116 > $(obj)/imagesize.c && \
117 $(CROSS_COMPILE)nm -n vmlinux | tail -n 1 | \
118 awk '{printf "unsigned long vmlinux_memsize = 0x%s;\n", substr($$1,8)}' >> $(obj)/imagesize.c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Geoff Levanda24c8482005-08-15 13:59:13 -0700120quiet_cmd_addnote = ADDNOTE $@
121 cmd_addnote = $(obj)/addnote $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123$(call gz-sec, $(required)): $(obj)/kernel-%.gz: % FORCE
124 $(call if_changed,gzip)
125
126$(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
127 cp -f $(obj)/ramdisk.image.gz $@
128
129$(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz FORCE
Geoff Levande4df7672005-08-10 17:57:42 -0700130 @touch $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132$(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c FORCE
133 $(call if_changed_dep,bootcc)
Geoff Levande4df7672005-08-10 17:57:42 -0700134 $(call cmd,addsection)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Geoff Levanda24c8482005-08-15 13:59:13 -0700136$(obj)/zImage.vmode: obj-boot += $(call obj-sec, $(required))
137$(obj)/zImage.vmode: $(call obj-sec, $(required)) $(obj-boot) FORCE
138 $(call cmd,bootld,$(obj-boot))
139
140$(obj)/zImage.initrd.vmode: obj-boot += $(call obj-sec, $(required) $(initrd))
141$(obj)/zImage.initrd.vmode: $(call obj-sec, $(required) $(initrd)) $(obj-boot) FORCE
142 $(call cmd,bootld,$(obj-boot))
143
144$(obj)/zImage: $(obj)/zImage.vmode $(obj)/addnote FORCE
145 @cp -f $< $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 $(call if_changed,addnote)
147
Geoff Levanda24c8482005-08-15 13:59:13 -0700148$(obj)/zImage.initrd: $(obj)/zImage.initrd.vmode $(obj)/addnote FORCE
149 @cp -f $< $@
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 $(call if_changed,addnote)
151
152$(obj)/imagesize.c: vmlinux.strip
Geoff Levande4df7672005-08-10 17:57:42 -0700153 $(call cmd,imagesize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155install: $(CONFIGURE) $(BOOTIMAGE)
156 sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" "$(BOOTIMAGE)"
157
158clean-files := $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)