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