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 src-boot
:= crt0.S string.S prom.c main.c zlib.c imagesize.c div64.S
31 src-boot
:= $(addprefix $(obj
)/, $(src-boot
))
32 obj-boot
:= $(addsuffix .o
, $(basename $(src-boot
)))
34 quiet_cmd_bootcc
= BOOTCC
$@
35 cmd_bootcc
= $(CROSS32CC
) -Wp
,-MD
,$(depfile
) $(BOOTCFLAGS
) -c
-o
$@
$<
37 quiet_cmd_bootas
= BOOTAS
$@
38 cmd_bootas
= $(CROSS32CC
) -Wp
,-MD
,$(depfile
) $(BOOTAFLAGS
) -c
-o
$@
$<
40 quiet_cmd_bootld
= BOOTLD
$@
41 cmd_bootld
= $(CROSS32LD
) $(BOOTLFLAGS
) -o
$@
$(2)
43 $(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
)
48 #-----------------------------------------------------------
49 # ELF sections within the zImage bootloader/wrapper
50 #-----------------------------------------------------------
51 required
:= vmlinux.
strip
54 obj-sec
= $(foreach section
, $(1), $(patsubst %,$(obj
)/kernel-
%.o
, $(section
)))
55 src-sec
= $(foreach section
, $(1), $(patsubst %,$(obj
)/kernel-
%.c
, $(section
)))
56 gz-sec
= $(foreach section
, $(1), $(patsubst %,$(obj
)/kernel-
%.gz
, $(section
)))
58 hostprogs-y
:= addnote addRamDisk
59 targets
+= zImage.vmode zImage.initrd.vmode zImage zImage.initrd imagesize.c \
60 $(patsubst $(obj
)/%,%, $(call obj-sec
, $(required
) $(initrd
))) \
61 $(patsubst $(obj
)/%,%, $(call src-sec
, $(required
) $(initrd
))) \
62 $(patsubst $(obj
)/%,%, $(call gz-sec
, $(required
) $(initrd
))) \
66 quiet_cmd_ramdisk
= RAMDISK
$@
67 cmd_ramdisk
= $(obj
)/addRamDisk
$(obj
)/ramdisk.image.gz
$< $@
69 quiet_cmd_stripvm
= STRIP
$@
70 cmd_stripvm
= $(STRIP
) -s
$< -o
$@
72 vmlinux.
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
)
77 quiet_cmd_addsection
= ADDSEC
$@
78 cmd_addsection
= $(CROSS32OBJCOPY
) $@ \
79 --add-section
=.kernel
:$(strip $(patsubst $(obj
)/kernel-
%.o
,%, $@
))=$(patsubst %.o
,%.gz
, $@
) \
80 --set-section-flags
=.kernel
:$(strip $(patsubst $(obj
)/kernel-
%.o
,%, $@
))=$(OBJCOPYFLAGS
)
82 quiet_cmd_imagesize
= GENSIZE
$@
83 cmd_imagesize
= ls
-l vmlinux.
strip | \
84 awk
'{printf "/* generated -- do not edit! */\n" "unsigned long vmlinux_filesize = %d;\n", $$5}' \
85 > $(obj
)/imagesize.c
&& \
86 $(CROSS_COMPILE
)nm
-n vmlinux | tail
-n
1 | \
87 awk
'{printf "unsigned long vmlinux_memsize = 0x%s;\n", substr($$1,8)}' >> $(obj
)/imagesize.c
89 quiet_cmd_addnote
= ADDNOTE
$@
90 cmd_addnote
= $(obj
)/addnote
$@
92 $(call gz-sec
, $(required
)): $(obj
)/kernel-
%.gz
: % FORCE
93 $(call if_changed
,gzip
)
95 $(obj
)/kernel-initrd.gz
: $(obj
)/ramdisk.image.gz
96 cp
-f
$(obj
)/ramdisk.image.gz
$@
98 $(call src-sec
, $(required
) $(initrd
)): $(obj
)/kernel-
%.c
: $(obj
)/kernel-
%.gz FORCE
101 $(call obj-sec
, $(required
) $(initrd
)): $(obj
)/kernel-
%.o
: $(obj
)/kernel-
%.c FORCE
102 $(call if_changed_dep
,bootcc
)
103 $(call cmd
,addsection
)
105 $(obj
)/zImage.vmode
: obj-boot
+= $(call obj-sec
, $(required
))
106 $(obj
)/zImage.vmode
: $(call obj-sec
, $(required
)) $(obj-boot
) FORCE
107 $(call cmd
,bootld
,$(obj-boot
))
109 $(obj
)/zImage.initrd.vmode
: obj-boot
+= $(call obj-sec
, $(required
) $(initrd
))
110 $(obj
)/zImage.initrd.vmode
: $(call obj-sec
, $(required
) $(initrd
)) $(obj-boot
) FORCE
111 $(call cmd
,bootld
,$(obj-boot
))
113 $(obj
)/zImage
: $(obj
)/zImage.vmode
$(obj
)/addnote FORCE
115 $(call if_changed
,addnote
)
117 $(obj
)/zImage.initrd
: $(obj
)/zImage.initrd.vmode
$(obj
)/addnote FORCE
119 $(call if_changed
,addnote
)
121 $(obj
)/imagesize.c
: vmlinux.
strip
122 $(call cmd
,imagesize
)
124 install: $(CONFIGURE
) $(BOOTIMAGE
)
125 sh
-x
$(srctree
)/$(src
)/install.sh
"$(KERNELRELEASE)" vmlinux System.map
"$(INSTALL_PATH)" "$(BOOTIMAGE)"
127 clean-files
:= $(addprefix $(objtree
)/, $(obj-boot
) vmlinux.
strip)