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 iamge
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 SUPPORT_CC_arm-sa1000 := platform/sa1000.cc
70 SUPPORT_CC_arm-pxa := platform/pxa.cc
71 SUPPORT_CC_arm-integrator := platform/integrator.cc
72 SUPPORT_CC_arm-rv := platform/rv.cc
73 SUPPORT_CC_arm-rv_pbx := platform/rv.cc
74 SUPPORT_CC_arm-rv_vexpress := platform/rv_vexpress.cc
75 SUPPORT_CC_arm-omap3evm := platform/omap.cc
76 SUPPORT_CC_arm-omap3_am33xx:= platform/omap.cc
77 SUPPORT_CC_arm-beagleboard := platform/omap.cc
78 SUPPORT_CC_arm-pandaboard := platform/omap.cc
79 SUPPORT_CC_arm-tegra2 := platform/tegra2.cc
80 SUPPORT_CC_arm-imx21 := platform/imx.cc
81 SUPPORT_CC_arm-imx35 := platform/imx.cc
82 SUPPORT_CC_arm-imx51 := platform/imx.cc
83 SUPPORT_CC_arm-imx6 := platform/imx.cc
84 SUPPORT_CC_arm-om := platform/om.cc
85 SUPPORT_CC_arm-kirkwood := platform/kirkwood.cc
86 DEFAULT_RELOC_arm-imx21 := 0x00200000 # because of blob
88 ifneq ($(DEFAULT_RELOC_arm-$(PLATFORM_TYPE)),)
89 DEFAULT_RELOC_arm := $(DEFAULT_RELOC_arm-$(PLATFORM_TYPE))
92 SUPPORT_CC_ppc32-mpc5200 := platform/mpc5200.cc
94 SUPPORT_CC_x86-pc := platform/x86_pc.cc
96 SUPPORT_CC_amd64-pc := platform/x86_pc.cc
98 SUPPORT_CC_sparc-leon3 := platform/leon3.cc
100 SRC_C += exec.c module.c
101 SRC_CC += region.cc startup.cc init_kip_v2.cc init_kip_v4.cc \
102 libc_support+.cc patch.cc koptions.cc
104 SRC_CC_x86 += ARCH-x86/reboot.cc
105 SRC_CC_amd64 += ARCH-x86/reboot.cc
106 SRC_C_x86 += base_critical.c
107 SRC_C_amd64 += base_critical.c
108 SRC_CC_arm += ARCH-arm/reboot.cc
109 SRC_CC_ppc32 += ARCH-ppc32/init_kip_v2-arch.cc \
111 SRC_CC_sparc += ARCH-sparc/reboot.cc
112 SRC_CC += $(SUPPORT_CC_$(ARCH)-$(PLATFORM_TYPE))
113 SRC_S += ARCH-$(ARCH)/crt0.S
115 OPTS = -g -Os $(CARCHFLAGS_$(ARCH)) $(CARCHFLAGS_$(ARCH)_$(CPU)) \
117 DEFINES += -DRAM_BASE=$(RAM_BASE) -DL4_MINIMAL_LIBC=1
118 DEFINES += -DCMDLINE="\"$(BOOTSTRAP_CMDLINE)\""
119 DEFINES += -DPLATFORM_TYPE=\"$(PLATFORM_TYPE)\"
120 DEFINES += -DPLATFORM_TYPE_$(PLATFORM_TYPE)
122 MOD_ADDR = 0x02000000
124 CPPFLAGS += $(CPPFLAGS_$(ARCH)-$(PLATFORM_TYPE))
125 CPPFLAGS += $(BID_PKG_CONFIG_CFLAGS)
127 ifeq ($(filter clean cleanall,$(MAKECMDGOALS)),)
128 ifeq ($(SUPPORT_CC_$(ARCH)-$(PLATFORM_TYPE)),)
129 $(info ERROR: PLATFORM_TYPE=$(PLATFORM_TYPE) has no assigned platform support file)
130 $(info ERROR: A proper PLATFORM_TYPE must be set for a build)
135 DRV_LIBS-ppc32 = -ldrivers_of
136 DRV_LIBS = -ldrivers_uart $(DRV_LIBS-$(ARCH))
138 LDSCRIPT = bootstrap.ld
141 vpath bootstrap.ld.in $(SRC_DIR)/ARCH-$(ARCH)
143 # can be overwritten by Makeconf.local
146 REALMODE_LOADING ?= 0
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
157 CPPFLAGS += -DSINGLE_SECTION
166 ENTRY_FN := $(shell echo "$(ENTRY)" | tr '[ ]' '[_]' )
170 ifeq ($(filter clean cleanall,$(MAKECMDGOALS)),)
171 BUILD_MOD_CMD = ( SEARCHPATH="$(BOOTSTRAP_SEARCH_PATH):$(BOOTSTRAP_MODULE_PATH_BINLIB)" \
172 CROSS_COMPILE=$(SYSTEM_TARGET) MAKE_INC_FILE=$(PWD)/mod.make.inc \
173 OUTPUT_DIR="$(BOOTSTRAP_OUTPUT_DIR)" \
174 OPT_ARCH=$(ARCH) OPT_COMPRESS=$(COMPRESS) L4DIR=$(L4DIR) \
175 $(SRC_DIR)/build.pl $(1) $(BOOTSTRAP_MODULES_LIST) "$(ENTRY)" || \
176 (echo "processing-of-module-list-failed"; exit 1))
181 # we need to re-do if some things change
182 .redo-change-tracker: FORCE
183 $(VERBOSE)echo "$(ENTRY) '$(COMPRESS)' '$(BOOTSTRAP_CMDLINE)' '$(BOOTSTRAP_SEARCH_PATH):$(BOOTSTRAP_MODULE_PATH_BINLIB)' '$(RAM_SIZE_MB)' '$(PLATFORM_TYPE)' '$(LOADER_MBI)' '$(od)'" > $@.tmp
184 $(if $(BUILD_MOD_CMD),$(VERBOSE)$(call BUILD_MOD_CMD,dump) >> $@.tmp)
185 $(VERBOSE)if test ! -r "$@" || ! cmp -s $@ $@.tmp; then \
193 INSTALL_FILES = $(BOOTSTRAP_ELF_NAME) bootstrap_$(ENTRY_FN) bootstrap_$(ENTRY_FN).elf
195 INSTALL_FILES += bootstrap32.elf
196 BOOTSTRAP_LINK_SOURCE = bootstrap32.elf
198 BOOTSTRAP_LINK_SOURCE = $(BOOTSTRAP_ELF_NAME)
201 $(od)bootstrap_$(ENTRY_FN): $(od)$(BOOTSTRAP_LINK_SOURCE)
202 $(VERBOSE)$(LN) -f $< $@
204 $(od)bootstrap_$(ENTRY_FN).elf: $(od)$(BOOTSTRAP_LINK_SOURCE)
205 $(VERBOSE)$(LN) -f $< $@
207 $(od)bootstrap_$(ENTRY_FN).raw: $(od)bootstrap.raw
208 $(VERBOSE)$(LN) -f $< $@
210 $(od)bootstrap_$(ENTRY_FN).uimage: $(od)bootstrap.uimage
211 $(VERBOSE)$(LN) -f $< $@
213 ifeq ($(ARCH),$(filter $(ARCH),arm ppc32))
214 BID_POST_PROG_LINK_MSG_$(BOOTSTRAP_ELF_NAME) = echo -e " ==> Post-processing $@"
215 BID_POST_PROG_LINK_$(BOOTSTRAP_ELF_NAME) = \
216 $(VERBOSE)LANG=C $(NM) -C $@ | \
217 LANG=C $(GREP) -q "V vtable for Platform_base" || \
218 { echo -e "\nERROR: Missing at least one platform instantiation.\n"; \
219 exit 1; } ; $(if $(BOOTSTRAP_NO_STRIP),,$(STRIP) $@)
221 ifneq ($(BOOTSTRAP_DO_RAW_IMAGE)$(BOOTSTRAP_DO_UIMAGE),)
222 BOOTSTRAP_RAW := $(od)bootstrap.raw
223 INSTALL_FILES += bootstrap.raw bootstrap_$(ENTRY_FN).raw
224 ifneq ($(BOOTSTRAP_DO_UIMAGE),)
225 ifneq ($(shell command -v $(MKIMAGE)),)
226 BOOTSTRAP_UIMAGE := $(od)bootstrap.uimage
227 INSTALL_FILES += bootstrap.uimage bootstrap_$(ENTRY_FN).uimage
229 $(error mkimage($(MKIMAGE)) host tool missing, cannot build bootstrap.uimage)
235 all:: $(addprefix $(IMAGES_DIR)/,$(INSTALL_FILES))
236 $(VERBOSE)echo " Image size(s) in bytes:"
237 $(VERBOSE)for f in $(filter bootstrap_$(ENTRY_FN).elf bootstrap.raw bootstrap.uimage, $(INSTALL_FILES)); do \
238 find $(if $(od),$(od),.) -name $$f -printf " %30f: %s\n"; \
240 $(if $(LDFLAGS_bootstrap.elf),$(VERBOSE)echo " Start address: $(patsubst --defsym=__executable_start=%,%,$(LDFLAGS_bootstrap.elf))")
241 $(VERBOSE)echo " --> Build-Nr: $$(cat .build_nr)"
243 # install images into easy to reach directory in build dir
244 $(IMAGES_DIR)/%: $(od)%
245 $(VERBOSE)if [ "$(ENTRY)" != "auto-build-entry" ]; then \
246 echo " ==> Installing $< in image directory"; \
247 (cd $(dir $@) && $(LN) -sf $(if $(od),,$(PWD)/)$<); \
250 INSTALL_FILES = bootstrap
253 ifneq ($(REALMODE_LOADING),0)
255 CPPFLAGS += -DREALMODE_LOADING -DSINGLE_SECTION
256 # don't install bootstrap_$(ENTRY_FN).elf
257 INSTALL_FILES = bootstrap.load
260 ifneq ($(LOADER_MBI),0)
261 SRC_CC += loader_mbi.cc
262 MOD_ADDR = 0x00150000
263 CPPFLAGS += -DLOADER_MBI
266 ifneq ($(COMPRESS),0)
267 SRC_C += uncompress.c gunzip.c
268 CPPFLAGS += -DCOMPRESS
270 CPPFLAGS += -DPLACE_MODULES_AT_MODADDR
273 ifneq ($(RAM_SIZE_MB),)
274 CPPFLAGS += -DRAM_SIZE_MB=$(RAM_SIZE_MB)
277 CXXFLAGS += -fno-rtti -fno-exceptions
278 CXXFLAGS += $(call checkcxx,-fno-threadsafe-statics)
280 ifneq ($(BUILD_MOD_CMD),)
281 ifeq ($(filter clean cleanall,$(MAKECMDGOALS)),)
283 processing-of-module-list-failed:
285 @echo " Processing of $(BOOTSTRAP_MODULES_LIST) failed!"
289 mod.make.inc $(od)mbi_modules.bin: $(GENERAL_D_LOC) $(shell $(call BUILD_MOD_CMD,list))
290 @echo Building entry \""$(ENTRY)"\".
291 $(VERBOSE)$(call BUILD_MOD_CMD,build)
293 -include mod.make.inc
294 BOOTSTRAP_LD_dep += mod.make.inc
295 STARTUP_C_dep := mod.make.inc
296 OBJS_$(od)$(BOOTSTRAP_ELF_NAME) += $(MODULE_OBJECT_FILES)
299 CPPFLAGS += -DIMAGE_MODE
302 CPPFLAGS += -DMODADDR=$(MOD_ADDR)
305 L4_LIBS = -static -nostdlib $(DRV_LIBS) -lcxx_base -lcxx_io
306 L4_LIBS += -luc_c_minimal $(GCCLIB)
308 all:: $(BOOTSTRAP_RAW)
310 # image for use with pxelinux
311 bootstrap.load: $(TARGET_BIN) bootsect.o.img setup.o.img
313 $(VERBOSE)objcopy -O binary -R .note -R .comment -S $< $<.load.bin
314 $(VERBOSE)cat bootsect.o.img setup.o.img $<.load.bin > $@
316 bootsect.o.img: ARCH-x86/bootsect.S Makefile
318 $(VERBOSE)$(CC) -traditional -nostdinc -nostdlib -c $<
319 $(VERBOSE)$(LD) -m elf_i386 -Ttext 0x0 -o $@ -s --oformat binary \
321 $(VERBOSE)chmod -x $@
323 setup.o.img: ARCH-x86/setup.S Makefile
325 $(VERBOSE)$(CC) -traditional -nostdinc -nostdlib -DARCH_$(ARCH) -c $<
326 $(VERBOSE)$(LD) -m elf_i386 -Ttext 0x0 -o $@ -s --oformat binary \
328 $(VERBOSE)dd if=/dev/zero bs=1 count=$$((3072 - `wc -c < setup.o.img`)) >> setup.o.img 2> /dev/null
329 $(VERBOSE)chmod -x $@
331 # raw version without ELF, primarily useful for ARM
332 $(BOOTSTRAP_RAW): $(TARGET_BIN)
334 $(VERBOSE)cp $< $@.tmp
335 $(VERBOSE)$(OBJCOPY) -O binary $@.tmp $@
336 $(VERBOSE)chmod -x $@
337 $(VERBOSE)$(RM) $@.tmp
348 MKIMAGE_ARCH = $(if $(filter ppc32,$(ARCH)),ppc,$(ARCH))
350 # u-boot image, based on raw-version
351 $(BOOTSTRAP_UIMAGE): $(BOOTSTRAP_RAW).$(BOOTSTRAP_UIMAGE_COMPRESSION)
353 $(VERBOSE)$(MKIMAGE) -e $(call default_reloc,$(ARCH)) \
354 -a $(call default_reloc,$(ARCH)) -A $(MKIMAGE_ARCH) \
355 -C $(BOOTSTRAP_UIMAGE_COMPRESSION) \
356 -n "L4 Image #$$(cat .build_nr)" \
359 $(TARGET): $(LDSCRIPT) $(OBJS_$(TARGET))
362 increment_build_nr = \
363 $(shell if [ -e .build_nr ]; then \
364 nr=$$(($$(cat .build_nr) + 1)); \
368 echo $$nr > .build_nr; echo $$nr)
371 startup.o: $(STARTUP_C_dep)
372 startup.o: CPPFLAGS += -DBUILD_DATE="\"$(shell date)\"" -DBUILD_NR=\"$(call increment_build_nr)\"
374 $(LDSCRIPT): $(LDSCRIPT).in $(GENERAL_D_LOC) $(BOOTSTRAP_LD_dep)
376 $(VERBOSE)$(SYSTEM_TARGET)cpp -P $(CPPFLAGS) -DLINKADDR=$(strip $(call default_reloc,$(ARCH))) $< $@;
379 $(VERBOSE)$(RM) mod.make.inc mod*.bin mbi_modules.bin $(LDSCRIPT)
380 $(VERBOSE)$(RM) setup.o.img bootsect.o.img
381 $(VERBOSE)$(RM) mod*.bin
382 $(VERBOSE)$(RM) $(SRC32_C:.c=.o32) $(SRC32_S:.S=.o32)
383 $(VERBOSE)$(RM) .redo-change-tracker
386 $(VERBOSE)$(RM) $(od)bootstrap_* $(od)bootstrap.*
390 vpath %.c $(SRC_DIR)/ARCH-amd64
391 vpath %.S $(SRC_DIR)/ARCH-amd64
392 vpath %.c $(SRC_DIR)/ARCH-amd64/boot32
393 vpath %.S $(SRC_DIR)/ARCH-amd64/boot32
394 vpath bootstrap.ld.in $(SRC_DIR)/ARCH-x86
396 SRC32_C = boot_cpu.c boot_kernel.c load_elf.c minilibc_support.c
397 SRC32_S = boot.S boot_idt.S
398 OBJ32 = $(SRC32_S:.S=.o32) $(SRC32_C:.c=.o32)
399 CC32 = $(filter-out -m64, $(CC)) -m32
400 CFLAGS32 := $(filter-out -m64, $(CFLAGS)) -m32
402 $(OBJ_DIR)/ARCH-amd64/libc32/OBJ-$(ARCH)_$(CPU)/libc32.a: FORCE
403 $(VERBOSE)$(MAKE) O=$(OBJ_BASE) -C $(SRC_DIR)/ARCH-amd64/libc32
405 bootstrap32.elf: $(OBJ32) bootstrap32.bin $(OBJ_DIR)/ARCH-amd64/libc32/OBJ-$(ARCH)_$(CPU)/libc32.a
407 $(VERBOSE)$(CC32) -o $@ -nostdlib -static \
408 -Wl,-T,$(SRC_DIR)/ARCH-amd64/boot32/bootstrap32.ld,--gc-sections $^ -lgcc
409 $(VERBOSE)chmod 755 $@
411 bootstrap: bootstrap32.elf
412 $(VERBOSE)$(LN) -f $^ $@
414 bootstrap32.bin: $(BOOTSTRAP_ELF_NAME)
416 $(VERBOSE)$(OBJCOPY) -S $< bootstrap64.bin
417 $(VERBOSE)chmod -x bootstrap64.bin
418 $(VERBOSE)$(OBJCOPY) -B i386 -I binary -O elf32-i386 bootstrap64.bin $@
422 $(VERBOSE)$(CC32) -o $@ -c $(DEPEND_FLAG) \
423 $(CPPFLAGS) $(CFLAGS32) $(call absfilename,$<)
427 $(VERBOSE)$(CC32) -o $@ -c $(DEPEND_FLAG) \
428 $(CPPFLAGS) $(CFLAGS32) $(call absfilename,$<)
431 $(VERBOSE)PWD=$(call absfilename,$(SRC_DIR)/ARCH-amd64/libc32) \
432 $(MAKE) -C $(SRC_DIR)/ARCH-amd64/libc32 $@
435 bootstrap: $(BOOTSTRAP_ELF_NAME)
436 $(VERBOSE)$(LN) -f $^ $@
439 INSTALL_TARGET := $(if $(od),,$(INSTALL_FILES))