]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/bootstrap/server/src/Make.rules
fa27afc474f79fd192c918f9802a7040144dd123
[l4.git] / l4 / pkg / bootstrap / server / src / Make.rules
1 # vim:set ft=make:
2
3 # User definable variables for bootstrap:
4 # - BOOTSTRAP_SEARCH_PATH
5 # - BOOTSTRAP_ELF_NAME
6 # - BOOTSTRAP_MODULES_LIST
7 # - BOOTSTRAP_DO_RAW_IMAGE
8 # - BOOTSTRAP_DO_UIMAGE
9 # - BOOTSTRAP_UIMAGE_COMPRESSION: set to none, gzip, or bzip2
10 # - BOOTSTRAP_CMDLINE: compiled-in command line, only used if no cmdline
11 #                      given via multi-boot boot loader (e.g. on arm)
12
13 DEFAULT_RELOC_arm   := 0x01000000
14 DEFAULT_RELOC_x86   := 0x002d0000
15 DEFAULT_RELOC_amd64 := 0x002d0000
16 DEFAULT_RELOC_ppc32 := 0x002d0000
17 DEFAULT_RELOC_sparc := 0x00100000
18 RELOC_PHYS          := y
19 LDFLAGS              = -Bstatic
20 EXTRA_GENERAL_D_DEP  = .redo-change-tracker
21 INCLUDE_MAKE_RULES   = $(SRC_DIR)/*/Make.rules
22 BOOTSTRAP_LD_dep    := $(SRC_DIR)/ldscript.inc
23 #REQUIRES_LIBS        = libbsd-lite
24
25 include $(L4DIR)/mk/Makeconf
26 -include $(OBJ_DIR)/Makeconf.local
27 -include $(L4DIR)/conf/Makeconf.boot
28 -include $(OBJ_BASE)/conf/Makeconf.boot
29
30 # Checks added Nov 2010:
31 ifneq ($(wildcard $(L4DIR)/conf/Makeconf.bootstrap),)
32 $(error $(L4DIR)/conf/Makeconf.bootstrap not used anymore. Please use $(L4DIR)/conf/Makeconf.boot now)
33 endif
34 ifneq ($(wildcard $(OBJ_BASE)/Makeconf.bootstrap),)
35 $(error $(OBJ_BASE)/Makeconf.bootstrap not used anymore. Please use $(OBJ_BASE)/conf/Makeconf.boot now)
36 endif
37
38 BOOTSTRAP_SEARCH_PATH        ?= .
39 BOOTSTRAP_MODULES_LIST       ?= $(SRC_DIR)/modules.list
40 BOOTSTRAP_MODULE_PATH_BINLIB ?= $(OBJ_BASE)/bin/$(SYSTEM)/$(BUILD_ABI):$(OBJ_BASE)/lib/$(SYSTEM)/$(BUILD_ABI):$(OBJ_BASE)/lib/$(SYSTEM)
41 BOOTSTRAP_ELF_NAME           ?= bootstrap.elf
42 MKIMAGE                      ?= mkimage
43 BOOTSTRAP_UIMAGE_COMPRESSION ?= none
44
45 ifeq ($(BUILD_ARCH),$(filter $(BUILD_ARCH),arm ppc32))
46   # ARM/PPC always uses single image mode
47   # when no entry is given we build the useless auto-build target
48   ifeq ($(E)$(ENTRY),)
49     BOOTSTRAP_ELF_NAME := bootstrap.auto-build-useless.elf
50   endif
51   ENTRY := auto-build-entry
52 endif
53
54
55 PRIVATE_INCDIR   = $(SRC_DIR) $(SRC_DIR)/ARCH-$(ARCH)
56
57 # special include directories only needed for <l4/sys/kernel.h>
58 PRIVATE_INCDIR_init_kip_v2.o      = $(OBJ_BASE)/include/$(ARCH)/l4f \
59                                     $(DROPS_STDDIR)/include/$(ARCH)/l4f
60 PRIVATE_INCDIR_init_arm_kip.o     = $(OBJ_BASE)/include/$(ARCH)/l4f \
61                                     $(DROPS_STDDIR)/include/$(ARCH)/l4f
62
63 TARGET          := $(BOOTSTRAP_ELF_NAME)
64 TARGET_BIN       = $(BOOTSTRAP_ELF_NAME)
65 MODE             = lib
66
67 ifeq ($(PLATFORM_TYPE),)
68 ifeq ($(X86_PLATFORM_TYPE),)
69 X86_PLATFORM_TYPE = pc
70 endif
71
72 PLATFORM_TYPE-arm   = $(ARM_PLATFORM_TYPE)
73 PLATFORM_TYPE-ppc32 = $(PPC_PLATFORM_TYPE)
74 PLATFORM_TYPE-x86   = $(X86_PLATFORM_TYPE)
75 PLATFORM_TYPE-amd64 = $(X86_PLATFORM_TYPE)
76 PLATFORM_TYPE-sparc = $(SPARC_PLATFORM_TYPE)
77 PLATFORM_TYPE       = $(PLATFORM_TYPE-$(ARCH))
78 endif
79
80 SUPPORT_CC_arm-sa1000     := support_sa1000.cc
81 SUPPORT_CC_arm-pxa        := support_pxa.cc
82 SUPPORT_CC_arm-integrator := support_integrator.cc
83 SUPPORT_CC_arm-rv         := support_rv.cc
84 SUPPORT_CC_arm-omap3evm   := support_omap3evm.cc
85 SUPPORT_CC_arm-beagleboard:= support_beagleboard.cc
86 SUPPORT_CC_arm-tegra2     := support_tegra2.cc
87 SUPPORT_CC_arm-imx21      := support_imx.cc
88 SUPPORT_CC_arm-imx51      := support_imx.cc
89 SUPPORT_CC_arm-om         := support_om.cc
90 SUPPORT_CC_arm-kirkwood   := support_kirkwood.cc
91 DEFAULT_RELOC_arm-imx21   := 0x00200000  # because of blob
92
93 ifneq ($(DEFAULT_RELOC_arm-$(PLATFORM_TYPE)),)
94 DEFAULT_RELOC_arm         := $(DEFAULT_RELOC_arm-$(PLATFORM_TYPE))
95 endif
96
97 SUPPORT_CC_ppc32-mpc5200  := support_mpc5200.cc
98
99 SUPPORT_CC_x86-pc         := support_x86_pc.cc
100
101 SUPPORT_CC_amd64-pc       := support_x86_pc.cc
102
103 SUPPORT_CC_sparc-leon3    := support_sparc_leon3.cc
104
105 SRC_C           += exec.c module.c
106 SRC_CC          += region.cc startup.cc init_kip_v2.cc init_kip_v4.cc \
107                    libc_support+.cc patch.cc
108
109 SRC_CC_x86      += ARCH-x86/reboot.cc
110 SRC_CC_amd64    += ARCH-x86/reboot.cc
111 SRC_C_x86       += base_critical.c ARCH-x86/serial.c
112 SRC_C_amd64     += base_critical.c ARCH-x86/serial.c
113 SRC_CC_arm      += ARCH-arm/reboot.cc
114 SRC_CC_ppc32    += ARCH-ppc32/init_kip_v2-arch.cc \
115                    ARCH-ppc32/reboot.cc
116 SRC_CC_sparc    += ARCH-sparc/reboot.cc
117 SRC_CC          += $(SUPPORT_CC_$(ARCH)-$(PLATFORM_TYPE))
118 SRC_S           += ARCH-$(ARCH)/crt0.S
119
120 OPTS             = -g -Os $(CARCHFLAGS_$(ARCH)) $(CARCHFLAGS_$(ARCH)_$(CPU))
121 DEFINES         += -DRAM_BASE=$(RAM_BASE)
122 DEFINES         += -DCMDLINE="\"$(BOOTSTRAP_CMDLINE)\""
123 DEFINES         += -DPLATFORM_TYPE=\"$(PLATFORM_TYPE)\"
124 DEFINES         += -DPLATFORM_TYPE_$(PLATFORM_TYPE)
125
126 MOD_ADDR         = 0x02000000
127
128 CPPFLAGS        += $(BID_PKG_CONFIG_CFLAGS)
129
130 ifeq ($(SUPPORT_CC_$(ARCH)-$(PLATFORM_TYPE)),)
131  $(error A proper PLATFORM_TYPE must be set for a build.)
132 endif
133
134 DRV_LIBS-ppc32   = -ldrivers_of
135 DRV_LIBS         = -ldrivers_uart $(DRV_LIBS-$(ARCH))
136 CRT0             =
137 LDSCRIPT         = bootstrap.ld
138 LDNMAGIC         =
139
140 vpath bootstrap.ld.in $(SRC_DIR)/ARCH-$(ARCH)
141
142 # can be overwritten by Makeconf.local
143 COMPRESS        ?= 0
144 LOADER_MBI      ?= 0
145 REALMODE_LOADING ?= 0
146 RML             ?= 0
147
148 ifneq ($(REALMODE_LOADING)$(RML),00)
149 REALMODE_LOADING := 1
150 $(error Info: Default reloc needs to be 0x00100000)
151 # And if you have done so you probably need to relink sigma0 and/or moe
152 endif
153
154 ifeq ($(ARCH),arm)
155 LOADER_MBI       := 1
156 CPPFLAGS         += -DSINGLE_SECTION
157 endif
158
159
160 # convenience
161 ifneq ($(E),)
162 ENTRY           := $(E)
163 endif
164
165 ENTRY_FN := $(shell echo "$(ENTRY)" | tr '[ ]' '[_]' )
166
167 # we need to re-do if some things change
168 # we do not need to track BOOTSTRACE_CMDLINE as it's only used in startup.cc
169 # and that is regenerated every time
170 REDO_TEXT_CMD = echo "$(ENTRY) '$(COMPRESS)' '$(RAM_SIZE_MB)' '$(PLATFORM_TYPE)' '$(LOADER_MBI)'"
171 .redo-change-tracker: FORCE
172         $(VERBOSE)if  test ! -r "$@" ||                    \
173                     ! $(REDO_TEXT_CMD) | cmp -s "$@"; then \
174           $(REDO_TEXT_CMD) > $@;  \
175         fi
176
177 ifneq ($(ENTRY),)
178
179 INSTALL_TARGET  = $(BOOTSTRAP_ELF_NAME) bootstrap_$(ENTRY_FN) bootstrap_$(ENTRY_FN).elf
180 ifeq ($(ARCH),amd64)
181 INSTALL_TARGET += bootstrap32.elf
182 BOOTSTRAP_LINK_SOURCE = bootstrap32.elf
183 else
184 BOOTSTRAP_LINK_SOURCE = $(BOOTSTRAP_ELF_NAME)
185 endif
186
187 bootstrap_$(ENTRY_FN): $(BOOTSTRAP_LINK_SOURCE)
188         $(VERBOSE)$(LN) -f $< $@
189
190 bootstrap_$(ENTRY_FN).elf: $(BOOTSTRAP_LINK_SOURCE)
191         $(VERBOSE)$(LN) -f $< $@
192
193 bootstrap_$(ENTRY_FN).raw: bootstrap.raw
194         $(VERBOSE)$(LN) -f $< $@
195
196 bootstrap_$(ENTRY_FN).uimage: bootstrap.uimage
197         $(VERBOSE)$(LN) -f $< $@
198
199  ifeq ($(ARCH),$(filter $(ARCH),arm ppc32))
200    BID_POST_PROG_LINK_MSG_$(BOOTSTRAP_ELF_NAME) = echo -e "  ==> Stripping $@"
201    BID_POST_PROG_LINK_$(BOOTSTRAP_ELF_NAME)     = \
202       $(VERBOSE)LANG=C $(NM) -C $@ | \
203         LANG=C $(GREP) -q "V vtable for Platform_base" || \
204            { echo -e "\nERROR: Missing at least one platform instantiation.\n"; \
205              exit 1; } ; $(STRIP) $@
206
207    ifneq ($(BOOTSTRAP_DO_RAW_IMAGE)$(BOOTSTRAP_DO_UIMAGE),)
208      BOOTSTRAP_RAW      := bootstrap.raw
209      INSTALL_TARGET     += bootstrap.raw bootstrap_$(ENTRY_FN).raw
210      ifneq ($(BOOTSTRAP_DO_UIMAGE),)
211        ifneq ($(shell command -v $(MKIMAGE)),)
212          BOOTSTRAP_UIMAGE   := bootstrap.uimage
213          INSTALL_TARGET     += bootstrap.uimage bootstrap_$(ENTRY_FN).uimage
214        else
215          $(info mkimage($(MKIMAGE)) missing, not building bootstrap.uimage)
216        endif
217      endif
218    endif
219  endif
220
221 all:: $(addprefix $(IMAGES_DIR)/,$(INSTALL_TARGET))
222         $(VERBOSE)echo "  Image size(s) in bytes:"
223         $(VERBOSE)for f in $(filter bootstrap_$(ENTRY_FN).elf bootstrap.raw bootstrap.uimage, $(INSTALL_TARGET)); do \
224           find . -name $$f -printf " %30f:  %s\n"; \
225         done
226         $(if $(BOOTSTRAP_DO_RAW_IMAGE),$(VERBOSE)echo "  Start address: $(patsubst -Ttext=%,%,$(LDFLAGS_bootstrap.elf))")
227         $(VERBOSE)echo "  --> Build-Nr: $$(cat .build_nr)"
228
229 # install images into easy to reach directory in build dir
230 $(IMAGES_DIR)/%: % $(IMAGES_DIR)/Makefile
231         $(VERBOSE)if [ "$(ENTRY)" != "auto-build-entry" ]; then \
232           echo "  ==> Installing $< in image directory";        \
233           $(LN) -sf $(PWD)/$< $(dir $@);                        \
234         fi
235
236 $(IMAGES_DIR)/Makefile: $(SRC_DIR)/Make.rules
237         @echo "  ==> Preparing image directory"
238         $(VERBOSE)install -d $(dir $@)
239         $(VERBOSE)$(ECHO) "# Automatically generated by bootstrap"                           > $@
240         $(VERBOSE)$(ECHO) "\$$(if \$$(MAKECMDGOALS),%,a):"                                  >> $@
241         $(VERBOSE)$(ECHO) "     \$$(MAKE) -C .. image \$$(if \$$(MAKECMDGOALS),E=\"\$$@\")" >> $@
242 else
243   INSTALL_TARGET = bootstrap
244 endif # ENTRY
245
246 ifneq ($(REALMODE_LOADING),0)
247 LOADER_MBI       = 1
248 CPPFLAGS        += -DREALMODE_LOADING -DSINGLE_SECTION
249 # don't install bootstrap_$(ENTRY_FN).elf
250 INSTALL_TARGET   = bootstrap.load
251 endif
252
253 ifneq ($(LOADER_MBI),0)
254 SRC_CC          += loader_mbi.cc
255 MOD_ADDR         = 0x00150000
256 CPPFLAGS        += -DLOADER_MBI
257 endif
258
259 ifneq ($(COMPRESS),0)
260 SRC_C           += uncompress.c gunzip.c
261 CPPFLAGS        += -DCOMPRESS
262 else
263 CPPFLAGS        += -DPLACE_MODULES_AT_MODADDR
264 endif
265
266 ifneq ($(RAM_SIZE_MB),)
267 CPPFLAGS        += -DRAM_SIZE_MB=$(RAM_SIZE_MB)
268 endif
269
270 CXXFLAGS += -fno-rtti -fno-exceptions
271 CXXFLAGS += $(call checkcxx,-fno-threadsafe-statics)
272
273 ifneq ($(ENTRY),)
274  ifeq ($(filter clean cleanall,$(MAKECMDGOALS)),)
275    $(info Building entry "$(ENTRY)".)
276    BUILD_DUMMY := $(shell SEARCHPATH="$(BOOTSTRAP_SEARCH_PATH):$(BOOTSTRAP_MODULE_PATH_BINLIB)" \
277                           CROSS_COMPILE=$(SYSTEM_TARGET) \
278                    OPT_ARCH=$(ARCH) \
279                    OPT_COMPRESS=$(COMPRESS) \
280                    L4DIR=$(L4DIR) \
281                           $(SRC_DIR)/build.pl $(BOOTSTRAP_MODULES_LIST) "$(ENTRY)" 1>&2 \
282                     || echo X-build-failed-X)
283    ifeq ($(BUILD_DUMMY),X-build-failed-X)
284     $(error Processing of module list failed!)
285    else
286     BUILD_DUMMY := $(shell echo $(BUILD_DUMMY))
287    endif
288    # mod.make.inc is generated by build.pl
289    include mod.make.inc
290  endif
291
292  OBJS_$(BOOTSTRAP_ELF_NAME)   += $(MODULE_OBJECT_FILES)
293  CPPFLAGS                     += -DIMAGE_MODE
294  BOOTSTRAP_LD_dep             += mod.make.inc
295  STARTUP_C_dep                := mod.make.inc
296 endif
297
298 CPPFLAGS        += -DMODADDR=$(MOD_ADDR)
299
300 LIBS             =
301 L4_LIBS          = -static -nostdlib $(DRV_LIBS) -lcxx_base -lcxx_io
302 L4_LIBS         += -luc_c $(GCCLIB)
303
304 all:: $(BOOTSTRAP_RAW)
305
306 # image for use with pxelinux
307 bootstrap.load: $(TARGET_BIN) bootsect.o.img setup.o.img
308         @$(GEN_MESSAGE)
309         $(VERBOSE)objcopy -O binary -R .note -R .comment -S $< $<.load.bin
310         $(VERBOSE)cat bootsect.o.img setup.o.img $<.load.bin > $@
311
312 bootsect.o.img: ARCH-x86/bootsect.S Makefile
313         @$(GEN_MESSAGE)
314         $(VERBOSE)$(CC) -traditional -nostdinc -nostdlib -c $<
315         $(VERBOSE)$(LD) -m elf_i386 -Ttext 0x0 -o $@ -s --oformat binary \
316           bootsect.o
317         $(VERBOSE)chmod -x $@
318
319 setup.o.img: ARCH-x86/setup.S Makefile
320         @$(GEN_MESSAGE)
321         $(VERBOSE)$(CC) -traditional -nostdinc -nostdlib -DARCH_$(ARCH) -c $<
322         $(VERBOSE)$(LD) -m elf_i386 -Ttext 0x0 -o $@ -s --oformat binary \
323           -e begtext setup.o
324         $(VERBOSE)dd if=/dev/zero bs=1 count=$$((3072 - `wc -c < setup.o.img`)) >> setup.o.img 2> /dev/null
325         $(VERBOSE)chmod -x $@
326
327 # raw version without ELF, primarily useful for ARM
328 $(BOOTSTRAP_RAW): $(TARGET_BIN)
329         @$(GEN_MESSAGE)
330         $(VERBOSE)cp $< $@.tmp
331         $(VERBOSE)$(OBJCOPY) -O binary $@.tmp $@
332         $(VERBOSE)chmod -x $@
333         $(VERBOSE)$(RM) $@.tmp
334
335 %.gzip: %
336         gzip -c9 $^ > $@
337
338 %.bzip2: %
339         bzip2 -c9 $^ > $@
340
341 %.none: %
342         ln -sf $^ $@
343
344 MKIMAGE_ARCH = $(if $(filter ppc32,$(ARCH)),ppc,$(ARCH))
345
346 # u-boot image, based on raw-version
347 $(BOOTSTRAP_UIMAGE): $(BOOTSTRAP_RAW).$(BOOTSTRAP_UIMAGE_COMPRESSION)
348         @$(GEN_MESSAGE)
349         $(VERBOSE)$(MKIMAGE) -e $(call default_reloc,$(ARCH)) \
350            -a $(call default_reloc,$(ARCH)) -A $(MKIMAGE_ARCH)  \
351            -C $(BOOTSTRAP_UIMAGE_COMPRESSION) \
352            -d $^ $@
353
354 $(TARGET): $(LDSCRIPT) $(OBJS_$(TARGET))
355
356
357 increment_build_nr = \
358    $(shell if [ -e .build_nr ]; then            \
359              nr=$$(($$(cat .build_nr) + 1));    \
360            else                                 \
361              nr=1;                              \
362            fi;                                  \
363            echo $$nr > .build_nr; echo $$nr)
364
365
366 startup.o: $(STARTUP_C_dep)
367 startup.o: CPPFLAGS += -DBUILD_DATE="\"$(shell date)\"" -DBUILD_NR=\"$(call increment_build_nr)\"
368
369 $(LDSCRIPT): $(LDSCRIPT).in $(GENERAL_D_LOC) $(BOOTSTRAP_LD_dep)
370         @$(GEN_MESSAGE)
371         $(VERBOSE)cpp -P $(CPPFLAGS) -DLINKADDR=$(DEFAULT_RELOC_$(ARCH)) $< $@;
372
373 clean::
374         $(VERBOSE)$(RM) mod.make.inc mod*.bin mbi_modules.bin $(LDSCRIPT)
375         $(VERBOSE)$(RM) setup.o.img bootsect.o.img
376         $(VERBOSE)$(RM) mod*.bin
377         $(VERBOSE)$(RM) $(SRC32_C:.c=.o32) $(SRC32_S:.S=.o32)
378         $(VERBOSE)$(RM) .redo-change-tracker
379
380 cleanall::
381         $(VERBOSE)$(RM) bootstrap_* bootstrap.*
382
383 ifeq ($(ARCH),amd64)
384
385 vpath %.c             $(SRC_DIR)/ARCH-amd64
386 vpath %.S             $(SRC_DIR)/ARCH-amd64
387 vpath %.c             $(SRC_DIR)/ARCH-amd64/boot32
388 vpath %.S             $(SRC_DIR)/ARCH-amd64/boot32
389 vpath bootstrap.ld.in $(SRC_DIR)/ARCH-x86
390
391 SRC32_C          = boot_cpu.c boot_kernel.c load_elf.c minilibc_support.c
392 SRC32_S          = boot.S boot_idt.S
393 OBJ32            = $(SRC32_S:.S=.o32) $(SRC32_C:.c=.o32)
394 CC32             = $(filter-out -m64, $(CC)) -m32
395 CFLAGS32        := $(filter-out -m64, $(CFLAGS)) -m32
396
397 $(OBJ_DIR)/ARCH-amd64/libc32/OBJ-$(ARCH)_$(CPU)/libc32.a: FORCE
398         $(VERBOSE)$(MAKE) O=$(OBJ_BASE) -C $(SRC_DIR)/ARCH-amd64/libc32
399
400 bootstrap32.elf: $(OBJ32) bootstrap32.bin $(OBJ_DIR)/ARCH-amd64/libc32/OBJ-$(ARCH)_$(CPU)/libc32.a
401         @$(LINK_MESSAGE)
402         $(VERBOSE)$(CC32) -o $@ -nostdlib -static \
403           -Wl,-T,$(SRC_DIR)/ARCH-amd64/boot32/bootstrap32.ld,--gc-sections $^ -lgcc
404         $(VERBOSE)chmod 755 $@
405
406 bootstrap: bootstrap32.elf
407         $(VERBOSE)$(LN) -f $^ $@
408
409 bootstrap32.bin: $(BOOTSTRAP_ELF_NAME)
410         @$(GEN_MESSAGE)
411         $(VERBOSE)$(OBJCOPY) -S $< bootstrap64.bin
412         $(VERBOSE)chmod -x bootstrap64.bin
413         $(VERBOSE)$(OBJCOPY) -B i386 -I binary -O elf32-i386 bootstrap64.bin $@
414
415 %.o32: %.c
416         @$(COMP_MESSAGE)
417         $(VERBOSE)$(CC32) -o $@ -c $(DEPEND_FLAG) \
418           $(CPPFLAGS) $(CFLAGS32) $(call absfilename,$<)
419
420 %.o32: %.S
421         @$(COMP_MESSAGE)
422         $(VERBOSE)$(CC32) -o $@ -c $(DEPEND_FLAG) \
423           $(CPPFLAGS) $(CFLAGS32) $(call absfilename,$<)
424
425 clean cleanall::
426         $(VERBOSE)PWD=$(call absfilename,$(SRC_DIR)/ARCH-amd64/libc32) \
427           $(MAKE) -C $(SRC_DIR)/ARCH-amd64/libc32 $@
428
429 else
430 bootstrap: $(BOOTSTRAP_ELF_NAME)
431         $(VERBOSE)$(LN) -f $^ $@
432 endif