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