1CMDLINE_SIZE ?= 0x400
2BOOTSTUB_SIZE ?= 8192
3
4BOOTSTUB_SRC_FILES := bootstub.c sfi.c ssp-uart.c imr_toc.c spi-uart.c
5BOOTSTUB_SRC_FILES_x86 := head.S e820_bios.S
6
7ifeq ($(TARGET_IS_64_BIT),true)
8BOOTSTUB_2ND_ARCH_VAR_PREFIX := $(TARGET_2ND_ARCH_VAR_PREFIX)
9else
10BOOTSTUB_2ND_ARCH_VAR_PREFIX :=
11endif
12
13LOCAL_SRC_FILES := $(BOOTSTUB_SRC_FILES)
14LOCAL_SRC_FILES_x86 := $(BOOTSTUB_SRC_FILES_x86)
15ANDROID_TOOLCHAIN_FLAGS := -m32 -ffreestanding
16LOCAL_CFLAGS := $(ANDROID_TOOLCHAIN_FLAGS) -Wall -O1 -DCMDLINE_SIZE=${CMDLINE_SIZE} -DAOSP_HEADER_ADDRESS=$(BOOTSTUB_AOSP_HEADER_ADDRESS) $(BOOTSTUB_CFLAGS)
17LOCAL_ASFLAGS := -DSTACK_OFFSET=$(BOOTSTUB_STACK_OFFSET)
18LOCAL_C_INCLUDES = system/core/mkbootimg
19LOCAL_MODULE := $(BOOTSTUB_BINARY).bin
20LOCAL_MODULE_TAGS := optional
21LOCAL_MULTILIB := 32
22LOCAL_MODULE_PATH := $(PRODUCT_OUT)
23LOCAL_MODULE_CLASS := EXECUTABLES
24LOCAL_FORCE_STATIC_EXECUTABLE := true
25LOCAL_2ND_ARCH_VAR_PREFIX := $(BOOTSTUB_2ND_ARCH_VAR_PREFIX)
26
27include $(BUILD_SYSTEM)/binary.mk
28
29$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TARGET_GLOBAL_CFLAGS := $(LOCAL_CFLAGS)
30$(LOCAL_BUILT_MODULE) : PRIVATE_ELF_FILE := $(intermediates)/$(PRIVATE_MODULE).elf
31$(LOCAL_BUILT_MODULE) : PRIVATE_LINK_SCRIPT := $(LOCAL_PATH)/2ndbootloader.lds
32$(LOCAL_BUILT_MODULE) : BOOTSTUB_OBJS := $(patsubst %.c, %.o , $(LOCAL_SRC_FILES))
33$(LOCAL_BUILT_MODULE) : BOOTSTUB_OBJS += $(patsubst %.S, %.o , $(LOCAL_SRC_FILES_x86))
34$(LOCAL_BUILT_MODULE) : BOOTSTUB_OBJS := $(addprefix $(intermediates)/, $(BOOTSTUB_OBJS))
35$(LOCAL_BUILT_MODULE) : BOOTSTUB_ENTRY := $(BOOTSTUB_ENTRY)
36
37$(LOCAL_BUILT_MODULE): $(all_objects)
38	$(hide) mkdir -p $(dir $@)
39	@echo "Generating bootstub.bin: $@"
40	$(hide) $(TARGET_LD) \
41		-m elf_i386 \
42		-T $(PRIVATE_LINK_SCRIPT) --defsym=BOOTSTUB_ENTRY=$(BOOTSTUB_ENTRY) \
43		$(BOOTSTUB_OBJS) \
44		-o $(PRIVATE_ELF_FILE)
45	$(hide) $(TARGET_OBJCOPY) -O binary -R .note -R .comment -S $(PRIVATE_ELF_FILE) $@
46
47$(LOCAL_BUILT_MODULE).size_check: $(LOCAL_BUILT_MODULE)
48	$(hide) ACTUAL_SIZE=`$(call get-file-size,$<)`; \
49	if [ "$$ACTUAL_SIZE" -gt "$(BOOTSTUB_SIZE)" ]; then \
50		echo "$<: $$ACTUAL_SIZE exceeds size limit of $(BOOTSTUB_SIZE) bytes, aborting."; \
51		exit 1; \
52	fi
53	$(hide) touch $@
54
55# Then assemble the final bootstub file
56bootstub_full := $(PRODUCT_OUT)/$(BOOTSTUB_BINARY)
57$(bootstub_full) : $(LOCAL_BUILT_MODULE) $(LOCAL_BUILT_MODULE).size_check
58	@echo "Generating bootstub: $@"
59	$(hide) cat $< /dev/zero | dd bs=$(BOOTSTUB_SIZE) count=1 > $@
60
61