From bf287064f3020d5473143790a2cb3101d38bdb37 Mon Sep 17 00:00:00 2001 From: "Chen, Gang G" Date: Fri, 16 Jun 2023 21:14:06 +0800 Subject: [PATCH] build: Support build kernelflinger with Slim Bootloader Build kernelflinger as ELF file Tracked-On: OAM-110589 Signed-off-by: Chen, Gang G --- core/definitions.mk | 49 +++++++++++++++++++++++++++++++++-- core/elf_ia32_sbl.lds | 58 ++++++++++++++++++++++++++++++++++++++++++ core/sbl_executable.mk | 55 +++++++++++++++++++++++++++++++++++++++ tasks/publish.mk | 14 +++++----- 4 files changed, 167 insertions(+), 9 deletions(-) create mode 100644 core/elf_ia32_sbl.lds create mode 100755 core/sbl_executable.mk diff --git a/core/definitions.mk b/core/definitions.mk index 5a4a9f8..83a2f87 100755 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -5,6 +5,7 @@ IAFW_BUILD_SYSTEM := $(INTEL_PATH_BUILD)/core BUILD_EFI_STATIC_LIBRARY := $(IAFW_BUILD_SYSTEM)/iafw_static_library.mk BUILD_IAFW_STATIC_LIBRARY := $(IAFW_BUILD_SYSTEM)/iafw_static_library.mk BUILD_EFI_EXECUTABLE := $(IAFW_BUILD_SYSTEM)/efi_executable.mk +BUILD_SBL_EXECUTABLE := $(IAFW_BUILD_SYSTEM)/sbl_executable.mk # Override default definition CLEAR_VARS := $(IAFW_BUILD_SYSTEM)/clear_vars.mk @@ -15,19 +16,36 @@ GENERATE_VERITY_KEY := $(HOST_OUT_EXECUTABLES)/generate_verity_key$(HOST_EXECUTA OPENSSL := openssl SBSIGN := sbsign MKDOSFS := mkdosfs -MKEXT2IMG := $(HOST_OUT_EXECUTABLES)/mkext2img -DUMPEXT2IMG := $(HOST_OUT_EXECUTABLES)/dumpext2img +#MKEXT2IMG := $(HOST_OUT_EXECUTABLES)/mkext2img +#DUMPEXT2IMG := $(HOST_OUT_EXECUTABLES)/dumpext2img MCOPY := mcopy SESL := sign-efi-sig-list$(HOST_EXECUTABLE_SUFFIX) CTESL := cert-to-efi-sig-list$(HOST_EXECUTABLE_SUFFIX) IASL := $(INTEL_PATH_BUILD)/acpi-tools/linux64/bin/iasl +# Generation +KF4SBL_SYMBOLS_ZIP := $(PRODUCT_OUT)/kf4sbl_symbols.zip +FB4SBL_SYMBOLS_ZIP := $(PRODUCT_OUT)/fb4sbl_symbols.zip + # Extra host tools we need built to use our *_from_target_files # or sign_target_files_* scripts INTEL_OTATOOLS := \ $(GENERATE_VERITY_KEY) \ $(AVBTOOL) +ifeq ($(KERNELFLINGER_SUPPORT_NON_EFI_BOOT),true) +# NON UEFI platform +INTEL_OTATOOLS += \ + # $(MKEXT2IMG) \ + # $(DUMPEXT2IMG) \ + $(FASTBOOT) \ + $(IASL) +endif + +ifeq ($(BOARD_USE_SBL),true) +INTEL_OTATOOLS += abl_toolchain +endif + otatools: $(INTEL_OTATOOLS) # FIXME: may be unsafe to omit -no-sse @@ -73,6 +91,7 @@ GNU_EFI_CRT0 := crt0-efi-$(TARGET_IAFW_ARCH_NAME) LIBPAYLOAD_CRT0 := crt0-libpayload-$(TARGET_IAFW_ARCH_NAME) TARGET_EFI_LDS := $(IAFW_BUILD_SYSTEM)/elf_$(TARGET_IAFW_ARCH_NAME)_efi.lds +TARGET_SBL_LDS := $(IAFW_BUILD_SYSTEM)/elf_$(TARGET_IAFW_ARCH_NAME)_sbl.lds TARGET_IAFW_GLOBAL_OBJCOPY_FLAGS := \ -j .text -j .sdata -j .data \ -j .dynamic -j .dynsym -j .rel \ @@ -125,6 +144,32 @@ $(hide) $(IAFW_OBJCOPY) $(PRIVATE_OBJCOPY_FLAGS) \ $(hide) $(SBSIGN) --key $1 --cert $2 --output $@ $(@:.efi=.efiunsigned) endef +define transform-o-to-sbl-executable +@echo "target SBL Executable: $(PRIVATE_MODULE) ($@)" +$(hide) mkdir -p $(dir $@) +$(hide) $(IAFW_LD) $1 \ + --defsym=CONFIG_LP_BASE_ADDRESS=$(LIBPAYLOAD_BASE_ADDRESS) \ + --defsym=CONFIG_LP_HEAP_SIZE=$(LIBPAYLOAD_HEAP_SIZE) \ + --defsym=CONFIG_LP_STACK_SIZE=$(LIBPAYLOAD_STACK_SIZE) \ + --whole-archive $(call module-built-files,$(LIBPAYLOAD_CRT0)) --no-whole-archive \ + $(PRIVATE_ALL_OBJECTS) --start-group $(PRIVATE_ALL_STATIC_LIBRARIES) --end-group $(IAFW_LIBCLANG) \ + -Map $(@:.sbl=.map) -o $(@:.sbl=.sym.elf) +$(hide)$(IAFW_STRIP) --strip-all $(@:.sbl=.sym.elf) -o $(@:.sbl=.elf) + +$(hide) cp $(@:.sbl=.elf) $@ + + +python3 $(INTEL_PATH_BUILD)/containertool/GenContainer.py create -t NORMAL -cl ELF1:$@ -k $(INTEL_PATH_BUILD)/testkeys/OS1_TestKey_Priv_RSA2048.pem -o $(PRODUCT_OUT)/sbl_os + + +$(hide) if [ "$(PRIVATE_MODULE:debug=)" = fb4sbl-user ]; then \ + zip -juy $(FB4SBL_SYMBOLS_ZIP) $(@:.sbl=.map) $(@:.sbl=.sym.elf); \ + zip -juy $(FB4SBL_SYMBOLS_ZIP) $@; \ +elif [ "$(PRIVATE_MODULE:debug=)" = kf4sbl-user ]; then \ + zip -juy $(KF4SBL_SYMBOLS_ZIP) $(@:.sbl=.map) $(@:.sbl=.sym.elf); \ +fi +endef + # Hook up the prebuilts generation mechanism include $(INTEL_PATH_COMMON)/external/external.mk diff --git a/core/elf_ia32_sbl.lds b/core/elf_ia32_sbl.lds new file mode 100644 index 0000000..8c01393 --- /dev/null +++ b/core/elf_ia32_sbl.lds @@ -0,0 +1,58 @@ +OUTPUT_FORMAT(elf32-i386) +OUTPUT_ARCH(i386) + +ENTRY(_entry) + +SECTIONS +{ + . = CONFIG_LP_BASE_ADDRESS; + + . = ALIGN(16); + _start = .; + + .text : { + *(.text._entry) + *(.text) + *(.text.*) + } + + .rodata : { + *(.rodata) + *(.rodata.*) + } + + .data : { + *(.data) + *(.data.*) + } + + _edata = .; + + .bss : { + *(.sbss) + *(.sbss.*) + *(.bss) + *(.bss.*) + *(COMMON) + + /* Stack and heap */ + + . = ALIGN(16); + _heap = .; + . += CONFIG_LP_HEAP_SIZE; + . = ALIGN(16); + _eheap = .; + + _estack = .; + . += CONFIG_LP_STACK_SIZE; + . = ALIGN(16); + _stack = .; + } + + _end = .; + + /DISCARD/ : { + *(.comment) + *(.note*) + } +} diff --git a/core/sbl_executable.mk b/core/sbl_executable.mk new file mode 100755 index 0000000..b2f9046 --- /dev/null +++ b/core/sbl_executable.mk @@ -0,0 +1,55 @@ +ifeq ($(strip $(LOCAL_MODULE_CLASS)),) +LOCAL_MODULE_CLASS := SBL +endif + +ifeq ($(strip $(LOCAL_MODULE_SUFFIX)),) +LOCAL_MODULE_SUFFIX := .sbl +endif + +ifeq ($(strip $(LOCAL_MODULE_PATH)),) +LOCAL_MODULE_PATH := $(PRODUCT_OUT)/sbl +endif + +LOCAL_CC := $(IAFW_CC) +LOCAL_CLANG := true +LOCAL_SANITIZE := never +LOCAL_NO_DEFAULT_COMPILER_FLAGS := true +LOCAL_CFLAGS += $(TARGET_IAFW_GLOBAL_CFLAGS) +LOCAL_ASFLAGS += $(TARGET_IAFW_ASFLAGS) +LOCAL_LDFLAGS := $(TARGET_IAFW_GLOBAL_LDFLAGS) -static \ + -T $(TARGET_SBL_LDS) $(LOCAL_LDFLAGS) +# If kernel enforce superpages the .text section gets aligned at +# offset 0x200000 which break multiboot compliance. +LOCAL_LDFLAGS += -z max-page-size=0x1000 +LOCAL_SBL_LDFALGS := $(LOCAL_LDFLAGS) +LOCAL_OBJCOPY_FLAGS := $(TARGET_IAFW_GLOBAL_OBJCOPY_FLAGS) $(LOCAL_OBJCOPY_FLAGS) + +skip_build_from_source := +ifdef LOCAL_PREBUILT_MODULE_FILE +ifeq (,$(call if-build-from-source,$(LOCAL_MODULE),$(LOCAL_PATH))) +include $(BUILD_SYSTEM)/prebuilt_internal.mk +skip_build_from_source := true +endif +endif + +ifndef skip_build_from_source + +ifdef LOCAL_IS_HOST_MODULE +$(error This file should not be used to build host binaries. Included by (or near) $(lastword $(filter-out config/%,$(MAKEFILE_LIST)))) +endif + +WITHOUT_LIBCOMPILER_RT := true +include $(BUILD_SYSTEM)/binary.mk +WITHOUT_LIBCOMPILER_RT := + +LIBPAYLOAD_CRT0_LIB := $(call intermediates-dir-for,STATIC_LIBRARIES,$(LIBPAYLOAD_CRT0))/$(LIBPAYLOAD_CRT0).a +all_objects += $(LIBPAYLOAD_CRT0_LIB) + +$(LOCAL_BUILT_MODULE): PRIVATE_OBJCOPY_FLAGS := $(LOCAL_OBJCOPY_FLAGS) + +#$(LOCAL_BUILT_MODULE): $(all_objects) $(all_libraries) $(SBLIMAGE) $(SBLSIGN) +$(LOCAL_BUILT_MODULE): $(all_objects) $(all_libraries) + $(call transform-o-to-sbl-executable,$(LOCAL_SBL_LDFALGS)) + +endif # skip_build_from_source + diff --git a/tasks/publish.mk b/tasks/publish.mk index d4c981e..2c02d83 100644 --- a/tasks/publish.mk +++ b/tasks/publish.mk @@ -94,14 +94,14 @@ $(PUB_OSAGNOSTIC_TAG): publish_mkdir_dest $(OS_AGNOSTIC_INFO) $(hide)($(ACP) $(OS_AGNOSTIC_INFO) $@) endif -# Publish kf4abl symbols files -.PHONY: publish_kf4abl_symbols +# Publish kf4sbl symbols files +.PHONY: publish_kf4sbl_symbols ifeq ($(TARGET_BUILD_VARIANT:debug=)|$(KERNELFLINGER_SUPPORT_NON_EFI_BOOT),user|true) -publish_kf4abl_symbols: publish_mkdir_dest kf4abl-$(TARGET_BUILD_VARIANT) fb4abl-$(TARGET_BUILD_VARIANT) - $(hide)($(ACP) $(KF4ABL_SYMBOLS_ZIP) $(FB4ABL_SYMBOLS_ZIP) $(publish_dest)) +publish_kf4sbl_symbols: publish_mkdir_dest kf4sbl-$(TARGET_BUILD_VARIANT) fb4sbl-$(TARGET_BUILD_VARIANT) + $(hide)($(ACP) $(KF4SBL_SYMBOLS_ZIP) $(FB4SBL_SYMBOLS_ZIP) $(publish_dest)) else -publish_kf4abl_symbols: - @echo "Publish kf4abl symbols: skipped" +publish_kf4sbl_symbols: + @echo "Publish kf4sbl symbols: skipped" endif # Publish Firmware symbols @@ -286,6 +286,6 @@ publish: aic $(hide) mkdir -p $(TOP)/pub/$(TARGET_PRODUCT)/$(TARGET_BUILD_VARIANT) $(hide) cp $(PRODUCT_OUT)/$(TARGET_AIC_FILE_NAME) $(TOP)/pub/$(TARGET_PRODUCT)/$(TARGET_BUILD_VARIANT) else # ANDROID_AS_GUEST -publish: publish_mkdir_dest $(PUBLISH_GOALS) publish_ifwi publish_gptimage_var publish_firmware_symbols $(PUB_OSAGNOSTIC_TAG) publish_kf4abl_symbols $(PUB_CMCC_ZIP) publish_androidia_image publish_grubinstaller +publish: publish_mkdir_dest $(PUBLISH_GOALS) publish_ifwi publish_gptimage_var publish_firmware_symbols $(PUB_OSAGNOSTIC_TAG) publish_kf4sbl_symbols $(PUB_CMCC_ZIP) publish_androidia_image publish_grubinstaller @$(ACP) out/dist/* $(publish_dest) endif # ANDROID_AS_GUEST