3 # User definable variables for bootstrap:
4 # - BOOTSTRAP_SEARCH_PATH
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
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
24 EXTRA_GENERAL_D_DEP += .redo-change-tracker $(BID_RAM_BASE_DEP) \
25 $(wildcard $(L4DIR)/conf/Makeconf.boot $(OBJ_BASE)/conf/Makeconf.boot) \
27 INCLUDE_MAKE_RULES = $(SRC_DIR)/*/Make.rules
28 BOOTSTRAP_LD_dep := $(SRC_DIR)/ldscript.inc
29 #REQUIRES_LIBS = libbsd-lite
31 include $(L4DIR)/mk/Makeconf
32 -include $(OBJ_DIR)/Makeconf.local
33 -include $(L4DIR)/conf/Makeconf.boot
34 -include $(OBJ_BASE)/conf/Makeconf.boot
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)
40 ifneq ($(wildcard $(OBJ_BASE)/Makeconf.bootstrap),)
41 $(error $(OBJ_BASE)/Makeconf.bootstrap not used anymore. Please use $(OBJ_BASE)/conf/Makeconf.boot now)
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
49 BOOTSTRAP_UIMAGE_COMPRESSION ?= none
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
55 BOOTSTRAP_ELF_NAME := bootstrap.auto-build-useless.elf
57 ENTRY := auto-build-entry
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)/)
63 PRIVATE_INCDIR = $(SRC_DIR) $(SRC_DIR)/ARCH-$(ARCH)
65 TARGET := $(od)$(BOOTSTRAP_ELF_NAME)
66 TARGET_BIN = $(od)$(BOOTSTRAP_ELF_NAME)
69 include $(SRC_DIR)/Makefile.platform
71 ifneq ($(DEFAULT_RELOC_arm-$(PLATFORM_TYPE)),)
72 DEFAULT_RELOC_arm := $(DEFAULT_RELOC_arm-$(PLATFORM_TYPE))
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
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 \
86 SRC_CC_sparc += ARCH-sparc/reboot.cc
87 SRC_CC += $(SUPPORT_CC_$(ARCH)-$(PLATFORM_TYPE))
88 SRC_S += ARCH-$(ARCH)/crt0.S
90 OPTS = -g -Os $(CARCHFLAGS_$(ARCH)) $(CARCHFLAGS_$(ARCH)_$(CPU)) \
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)
99 CPPFLAGS += $(CPPFLAGS_$(ARCH)-$(PLATFORM_TYPE))
100 CPPFLAGS += $(BID_PKG_CONFIG_CFLAGS)
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)
110 DRV_LIBS-ppc32 = -ldrivers_of
111 DRV_LIBS = -ldrivers_uart $(DRV_LIBS-$(ARCH))
113 LDSCRIPT = bootstrap.ld
116 vpath bootstrap.ld.in $(SRC_DIR)/ARCH-$(ARCH)
118 # can be overwritten by Makeconf.local
121 REALMODE_LOADING ?= 0
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
132 CPPFLAGS += -DSINGLE_SECTION
149 ENTRY_FN := $(shell echo "$(ENTRY)" | tr '[ ]' '[_]' )
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))
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 \
176 INSTALL_FILES = $(BOOTSTRAP_ELF_NAME) bootstrap_$(ENTRY_FN) bootstrap_$(ENTRY_FN).elf
178 INSTALL_FILES += bootstrap32.elf
179 BOOTSTRAP_LINK_SOURCE = bootstrap32.elf
181 BOOTSTRAP_LINK_SOURCE = $(BOOTSTRAP_ELF_NAME)
184 $(od)bootstrap_$(ENTRY_FN): $(od)$(BOOTSTRAP_LINK_SOURCE)
185 $(VERBOSE)$(LN) -f $< $@
187 $(od)bootstrap_$(ENTRY_FN).elf: $(od)$(BOOTSTRAP_LINK_SOURCE)
188 $(VERBOSE)$(LN) -f $< $@
190 $(od)bootstrap_$(ENTRY_FN).raw: $(od)bootstrap.raw
191 $(VERBOSE)$(LN) -f $< $@
193 $(od)bootstrap_$(ENTRY_FN).uimage: $(od)bootstrap.uimage
194 $(VERBOSE)$(LN) -f $< $@
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) $@)
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
212 $(error mkimage($(MKIMAGE)) host tool missing, cannot build bootstrap.uimage)
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"; \
223 $(if $(LDFLAGS_bootstrap.elf),$(VERBOSE)echo " Start address: $(patsubst --defsym=__executable_start=%,%,$(LDFLAGS_bootstrap.elf))")
224 $(VERBOSE)echo " --> Build-Nr: $$(cat .build_nr)"
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)/)$<); \
233 INSTALL_FILES = bootstrap
236 ifneq ($(REALMODE_LOADING),0)
238 CPPFLAGS += -DREALMODE_LOADING -DSINGLE_SECTION
239 # don't install bootstrap_$(ENTRY_FN).elf
240 INSTALL_FILES = bootstrap.load
241 MOD_ADDR = 0x00150000
244 ifneq ($(LOADER_MBI),0)
245 SRC_CC += loader_mbi.cc
246 CPPFLAGS += -DLOADER_MBI
249 ifneq ($(COMPRESS),0)
250 SRC_C += uncompress.c gunzip.c
251 CPPFLAGS += -DCOMPRESS
253 CPPFLAGS += -DPLACE_MODULES_AT_MODADDR
256 ifneq ($(RAM_SIZE_MB),)
257 CPPFLAGS += -DRAM_SIZE_MB=$(RAM_SIZE_MB)
260 CXXFLAGS += -fno-rtti -fno-exceptions
261 CXXFLAGS += $(call checkcxx,-fno-threadsafe-statics)
263 ifneq ($(BUILD_MOD_CMD),)
264 ifeq ($(filter clean cleanall,$(MAKECMDGOALS)),)
266 processing-of-module-list-failed:
268 @echo " Processing of $(BOOTSTRAP_MODULES_LIST) failed!"
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)
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)
282 CPPFLAGS += -DIMAGE_MODE
285 CPPFLAGS += -DMODADDR=$(MOD_ADDR)
288 L4_LIBS = -static -nostdlib $(DRV_LIBS) -lcxx_base -lcxx_io
289 L4_LIBS += -luc_c_minimal $(GCCLIB)
291 all:: $(BOOTSTRAP_RAW)
293 # image for use with pxelinux
294 bootstrap.load: $(TARGET_BIN) bootsect.o.img setup.o.img
296 $(VERBOSE)objcopy -O binary -R .note -R .comment -S $< $<.load.bin
297 $(VERBOSE)cat bootsect.o.img setup.o.img $<.load.bin > $@
299 bootsect.o.img: ARCH-x86/bootsect.S Makefile
301 $(VERBOSE)$(CC) -traditional -nostdinc -nostdlib -c $<
302 $(VERBOSE)$(LD) -m elf_i386 -Ttext 0x0 -o $@ -s --oformat binary \
304 $(VERBOSE)chmod -x $@
306 setup.o.img: ARCH-x86/setup.S Makefile
308 $(VERBOSE)$(CC) -traditional -nostdinc -nostdlib -DARCH_$(ARCH) -c $<
309 $(VERBOSE)$(LD) -m elf_i386 -Ttext 0x0 -o $@ -s --oformat binary \
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 $@
314 # raw version without ELF, primarily useful for ARM
315 $(BOOTSTRAP_RAW): $(TARGET_BIN)
317 $(VERBOSE)cp $< $@.tmp
318 $(VERBOSE)$(OBJCOPY) -O binary $@.tmp $@
319 $(VERBOSE)chmod -x $@
320 $(VERBOSE)$(RM) $@.tmp
331 MKIMAGE_ARCH = $(if $(filter ppc32,$(ARCH)),ppc,$(ARCH))
333 # u-boot image, based on raw-version
334 $(BOOTSTRAP_UIMAGE): $(BOOTSTRAP_RAW).$(BOOTSTRAP_UIMAGE_COMPRESSION)
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)" \
342 $(TARGET): $(LDSCRIPT) $(OBJS_$(TARGET))
345 increment_build_nr = \
346 $(shell if [ -e .build_nr ]; then \
347 nr=$$(($$(cat .build_nr) + 1)); \
351 echo $$nr > .build_nr; echo $$nr)
354 startup.o: $(STARTUP_C_dep)
355 startup.o: CPPFLAGS += -DBUILD_DATE="\"$(shell date)\"" -DBUILD_NR=\"$(call increment_build_nr)\"
357 $(LDSCRIPT): $(LDSCRIPT).in $(GENERAL_D_LOC) $(BOOTSTRAP_LD_dep)
359 $(VERBOSE)$(SYSTEM_TARGET)cpp -P $(CPPFLAGS) -DLINKADDR=$(strip $(call default_reloc,$(ARCH))) $< $@;
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
369 $(VERBOSE)$(RM) $(od)bootstrap_* $(od)bootstrap.*
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
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
385 $(OBJ_DIR)/ARCH-amd64/libc32/OBJ-$(ARCH)_$(CPU)/libc32.a: FORCE
386 $(VERBOSE)$(MAKE) O=$(OBJ_BASE) -C $(SRC_DIR)/ARCH-amd64/libc32
388 bootstrap32.elf: $(OBJ32) bootstrap32.bin $(OBJ_DIR)/ARCH-amd64/libc32/OBJ-$(ARCH)_$(CPU)/libc32.a
390 $(VERBOSE)$(CC32) -o $@ -nostdlib -static \
391 -Wl,-T,$(SRC_DIR)/ARCH-amd64/boot32/bootstrap32.ld,--gc-sections $^ -lgcc
392 $(VERBOSE)chmod 755 $@
394 bootstrap: bootstrap32.elf
395 $(VERBOSE)$(LN) -f $^ $@
397 bootstrap32.bin: $(BOOTSTRAP_ELF_NAME)
399 $(VERBOSE)$(OBJCOPY) -S $< bootstrap64.bin
400 $(VERBOSE)chmod -x bootstrap64.bin
401 $(VERBOSE)$(OBJCOPY) -B i386 -I binary -O elf32-i386 bootstrap64.bin $@
405 $(VERBOSE)$(CC32) -o $@ -c $(DEPEND_FLAG) \
406 $(CPPFLAGS) $(CFLAGS32) $(call absfilename,$<)
410 $(VERBOSE)$(CC32) -o $@ -c $(DEPEND_FLAG) \
411 $(CPPFLAGS) $(CFLAGS32) $(call absfilename,$<)
414 $(VERBOSE)PWD=$(call absfilename,$(SRC_DIR)/ARCH-amd64/libc32) \
415 $(MAKE) -C $(SRC_DIR)/ARCH-amd64/libc32 $@
418 bootstrap: $(BOOTSTRAP_ELF_NAME)
419 $(VERBOSE)$(LN) -f $^ $@
422 INSTALL_TARGET := $(if $(od),,$(INSTALL_FILES))