1 # Makefile for making ELF bootable images for booting on CHRP
4 # Geert Uytterhoeven September 1997
6 # Based on coffboot by Paul Mackerras
7 # Simplified for ppc64 by Todd Inglett
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.
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.
25 BOOTCFLAGS := $(HOSTCFLAGS) -fno-builtin -nostdinc -isystem $(shell $(CROSS32CC) -print-file-name=include)
26 BOOTAFLAGS := -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
27 BOOTLFLAGS := -Ttext 0x00400000 -e _start -T $(srctree)/$(src)/zImage.lds
28 OBJCOPYFLAGS := contents,alloc,load,readonly,data
30 zlib := infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c
31 zlibheader := infblock.h infcodes.h inffast.h inftrees.h infutil.h
32 zliblinuxheader := zlib.h zconf.h zutil.h
34 $(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader))
35 #$(addprefix $(obj)/,main.o): $(addprefix $(obj)/,zlib.h)
37 src-boot := crt0.S string.S prom.c main.c div64.S
39 src-boot := $(addprefix $(obj)/, $(src-boot))
40 obj-boot := $(addsuffix .o, $(basename $(src-boot)))
42 BOOTCFLAGS += -I$(obj) -I$(srctree)/$(obj)
44 quiet_cmd_copy_zlib = COPY $@
45 cmd_copy_zlib = sed "s@__attribute_used__@@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
47 quiet_cmd_copy_zlibheader = COPY $@
48 cmd_copy_zlibheader = sed "s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
50 quiet_cmd_copy_zliblinuxheader = COPY $@
51 cmd_copy_zliblinuxheader = sed "s@<linux/string.h>@\"string.h\"@;s@<linux/kernel.h>@<stddef.h>@;s@<linux/\([^>]\+\).*@\"\1\"@" $< > $@
53 $(addprefix $(obj)/,$(zlib)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
56 $(addprefix $(obj)/,$(zlibheader)): $(obj)/%: $(srctree)/lib/zlib_inflate/%
57 $(call cmd,copy_zlibheader)
59 $(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
60 $(call cmd,copy_zliblinuxheader)
62 clean-files := $(zlib) $(zlibheader) $(zliblinuxheader)
65 quiet_cmd_bootcc = BOOTCC $@
66 cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
68 quiet_cmd_bootas = BOOTAS $@
69 cmd_bootas = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
71 quiet_cmd_bootld = BOOTLD $@
72 cmd_bootld = $(CROSS32LD) $(BOOTLFLAGS) -o $@ $(2)
74 $(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)
79 #-----------------------------------------------------------
80 # ELF sections within the zImage bootloader/wrapper
81 #-----------------------------------------------------------
82 required := vmlinux.strip
85 obj-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.o, $(section)))
86 src-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.c, $(section)))
87 gz-sec = $(foreach section, $(1), $(patsubst %,$(obj)/kernel-%.gz, $(section)))
89 hostprogs-y := addnote addRamDisk
90 targets += zImage.vmode zImage.initrd.vmode zImage zImage.initrd \
91 $(patsubst $(obj)/%,%, $(call obj-sec, $(required) $(initrd))) \
92 $(patsubst $(obj)/%,%, $(call src-sec, $(required) $(initrd))) \
93 $(patsubst $(obj)/%,%, $(call gz-sec, $(required) $(initrd))) \
97 quiet_cmd_ramdisk = RAMDISK $@
98 cmd_ramdisk = $(obj)/addRamDisk $(obj)/ramdisk.image.gz $< $@
100 quiet_cmd_stripvm = STRIP $@
101 cmd_stripvm = $(STRIP) -s $< -o $@
103 vmlinux.strip: vmlinux
104 $(call if_changed,stripvm)
105 $(obj)/vmlinux.initrd: vmlinux.strip $(obj)/addRamDisk $(obj)/ramdisk.image.gz
106 $(call if_changed,ramdisk)
108 quiet_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)
113 quiet_cmd_addnote = ADDNOTE $@
114 cmd_addnote = $(obj)/addnote $@
116 $(call gz-sec, $(required)): $(obj)/kernel-%.gz: %
117 $(call if_changed,gzip)
119 $(obj)/kernel-initrd.gz: $(obj)/ramdisk.image.gz
120 cp -f $(obj)/ramdisk.image.gz $@
122 $(call src-sec, $(required) $(initrd)): $(obj)/kernel-%.c: $(obj)/kernel-%.gz
125 $(call obj-sec, $(required) $(initrd)): $(obj)/kernel-%.o: $(obj)/kernel-%.c
126 $(call if_changed_dep,bootcc)
127 $(call cmd,addsection)
129 $(obj)/zImage.vmode: obj-boot += $(call obj-sec, $(required))
130 $(obj)/zImage.vmode: $(call obj-sec, $(required)) $(obj-boot) $(srctree)/$(src)/zImage.lds
131 $(call cmd,bootld,$(obj-boot))
133 $(obj)/zImage.initrd.vmode: obj-boot += $(call obj-sec, $(required) $(initrd))
134 $(obj)/zImage.initrd.vmode: $(call obj-sec, $(required) $(initrd)) $(obj-boot) $(srctree)/$(src)/zImage.lds
135 $(call cmd,bootld,$(obj-boot))
137 $(obj)/zImage: $(obj)/zImage.vmode $(obj)/addnote
139 $(call if_changed,addnote)
141 $(obj)/zImage.initrd: $(obj)/zImage.initrd.vmode $(obj)/addnote
143 $(call if_changed,addnote)
145 install: $(CONFIGURE) $(BOOTIMAGE)
146 sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" "$(BOOTIMAGE)"
148 clean-files := $(addprefix $(objtree)/, $(obj-boot) vmlinux.strip)