From 242bb90d7476c2ee47d60c50ee18785edeb1a295 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Tue, 22 Jul 2014 15:59:16 -0700 Subject: [PATCH] coreboot classes: Add dynamic classes to coreboot Provide functionality to create dynamic classes based on program name and the architecture for which the program needs to be compiled/linked. define_class takes program_name and arch as its arguments and adds the program_name to classes-y to create dynamic class and compiler toolset is created for the specified arch. All the files for this program can then be added to program_name-y += .. Ensure that define_class is called before any files are added to the class. Check subdirs-y for order of directory inclusion. One such example of dynamic class is rmodules. Multiple rmodules can be used which need to be compiled for different architectures. With dynamic classes, this is possible. BUG=chrome-os-partner:30784 BRANCH=None TEST=Compiles successfully for nyan, rush and link. Change-Id: I3e3aadbe723d432b9b3500c44bcff578c98f5643 Signed-off-by: Furquan Shaikh Reviewed-on: https://chromium-review.googlesource.com/209379 Reviewed-by: Aaron Durbin Tested-by: Furquan Shaikh Commit-Queue: Aaron Durbin --- Makefile.inc | 5 ++++- src/arch/arm/Makefile.inc | 12 +++++------- src/arch/arm/armv7/Makefile.inc | 4 ++-- src/arch/arm64/Makefile.inc | 12 +++++------- src/arch/x86/Makefile.inc | 4 +--- src/arch/x86/lib/Makefile.inc | 6 +++--- src/cpu/x86/Makefile.inc | 6 +++--- src/cpu/x86/smm/Makefile.inc | 4 ++-- src/lib/Makefile.inc | 14 +++++++++----- src/soc/nvidia/tegra124/Makefile.inc | 4 ++-- src/soc/samsung/exynos5420/Makefile.inc | 8 ++++---- src/vendorcode/google/chromeos/Makefile.inc | 18 +++++++++--------- toolchain.inc | 12 ++++++++++++ 13 files changed, 61 insertions(+), 48 deletions(-) diff --git a/Makefile.inc b/Makefile.inc index 3eae768a55..2497007b2a 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -60,8 +60,11 @@ subdirs-y += site-local ####################################################################### # Add source classes and their build options -classes-y := ramstage romstage bootblock smm smmstub cpu_microcode rmodules verstage +classes-y := ramstage romstage bootblock smm smmstub cpu_microcode verstage +# Add dynamic classes for rmodules +$(foreach supported_arch,$(ARCH_SUPPORTED), \ + $(eval $(call define_class,rmodules_$(ARCH_TO_TOOLCHAIN_$(supported_arch)),$(ARCH_TO_TOOLCHAIN_$(supported_arch))))) ####################################################################### # Helper functions for ramstage postprocess spc := diff --git a/src/arch/arm/Makefile.inc b/src/arch/arm/Makefile.inc index 3f42b004b8..6711177124 100644 --- a/src/arch/arm/Makefile.inc +++ b/src/arch/arm/Makefile.inc @@ -122,14 +122,12 @@ ramstage-y += memcpy.S ramstage-y += memmove.S ramstage-y += clock.c -rmodules-y += memset.S -rmodules-y += memcpy.S -rmodules-y += memmove.S -rmodules-y += eabi_compat.c +rmodules_arm-y += memset.S +rmodules_arm-y += memcpy.S +rmodules_arm-y += memmove.S +rmodules_arm-y += eabi_compat.c -VBOOT_STUB_DEPS += $(obj)/arch/arm/eabi_compat.rmodules.o - -$(eval $(call create_class_compiler,rmodules,arm)) +VBOOT_STUB_DEPS += $(obj)/arch/arm/eabi_compat.rmodules_arm.o ramstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c diff --git a/src/arch/arm/armv7/Makefile.inc b/src/arch/arm/armv7/Makefile.inc index 354776a931..ad8ddf0856 100644 --- a/src/arch/arm/armv7/Makefile.inc +++ b/src/arch/arm/armv7/Makefile.inc @@ -85,7 +85,7 @@ ramstage-c-ccopts += $(armv7_flags) ramstage-S-ccopts += $(armv7_asm_flags) # All rmodule code is armv7 if ramstage is armv7. -rmodules-c-ccopts += $(armv7_flags) -rmodules-S-ccopts += $(armv7_asm_flags) +rmodules_arm-c-ccopts += $(armv7_flags) +rmodules_arm-S-ccopts += $(armv7_asm_flags) endif diff --git a/src/arch/arm64/Makefile.inc b/src/arch/arm64/Makefile.inc index cad6964a5b..59293c11a7 100644 --- a/src/arch/arm64/Makefile.inc +++ b/src/arch/arm64/Makefile.inc @@ -117,14 +117,12 @@ ramstage-y += ../../lib/memcpy.c ramstage-y += ../../lib/memmove.c ramstage-y += stage_entry.S -rmodules-y += ../../lib/memset.c -rmodules-y += ../../lib/memcpy.c -rmodules-y += ../../lib/memmove.c -rmodules-y += eabi_compat.c +rmodules_arm64-y += ../../lib/memset.c +rmodules_arm64-y += ../../lib/memcpy.c +rmodules_arm64-y += ../../lib/memmove.c +rmodules_arm64-y += eabi_compat.c -VBOOT_STUB_DEPS += $(obj)/arch/arm64/eabi_compat.rmodules.o - -$(eval $(call create_class_compiler,rmodules,arm64)) +VBOOT_STUB_DEPS += $(obj)/arch/arm64/eabi_compat.rmodules_arm64.o ramstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc index 460db66287..4cfa9ad316 100644 --- a/src/arch/x86/Makefile.inc +++ b/src/arch/x86/Makefile.inc @@ -309,11 +309,9 @@ ifneq ($(wildcard src/mainboard/$(MAINBOARDDIR)/get_bus_conf.c),) ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/get_bus_conf.c endif -$(eval $(call create_class_compiler,rmodules,x86_32)) - ifeq ($(CONFIG_RELOCATABLE_RAMSTAGE),y) -$(eval $(call rmodule_link,$(objcbfs)/ramstage.debug, $(objgenerated)/ramstage.o, $(CONFIG_HEAP_SIZE))) +$(eval $(call rmodule_link,$(objcbfs)/ramstage.debug, $(objgenerated)/ramstage.o, $(CONFIG_HEAP_SIZE),x86_32)) # The rmodule_link defintion creates an elf file with .rmod extension. $(objcbfs)/ramstage.elf: $(objcbfs)/ramstage.debug.rmod diff --git a/src/arch/x86/lib/Makefile.inc b/src/arch/x86/lib/Makefile.inc index 0803e2a16f..fe1b379b9c 100644 --- a/src/arch/x86/lib/Makefile.inc +++ b/src/arch/x86/lib/Makefile.inc @@ -32,9 +32,9 @@ smm-y += memcpy.c smm-y += memmove.c smm-y += rom_media.c -rmodules-y += memset.c -rmodules-y += memcpy.c -rmodules-y += memmove.c +rmodules_x86_32-y += memset.c +rmodules_x86_32-y += memcpy.c +rmodules_x86_32-y += memmove.c $(obj)/arch/x86/lib/console.ramstage.o :: $(obj)/build.h diff --git a/src/cpu/x86/Makefile.inc b/src/cpu/x86/Makefile.inc index 4c506007ab..16b8c0ab47 100644 --- a/src/cpu/x86/Makefile.inc +++ b/src/cpu/x86/Makefile.inc @@ -11,12 +11,12 @@ SIPI_DOTO=$(SIPI_ELF:.elf=.o) ifeq ($(CONFIG_PARALLEL_MP),y) ramstage-srcs += $(SIPI_BIN) endif -rmodules-$(CONFIG_PARALLEL_MP) += sipi_vector.S +rmodules_$(ARCH-RAMSTAGE-y)-$(CONFIG_PARALLEL_MP) += sipi_vector.S -$(SIPI_DOTO): $(dir $(SIPI_ELF))sipi_vector.rmodules.o +$(SIPI_DOTO): $(dir $(SIPI_ELF))sipi_vector.rmodules_$(ARCH-RAMSTAGE-y).o $(CC_ramstage) $(LDFLAGS) -nostdlib -r -o $@ $^ -$(eval $(call rmodule_link,$(SIPI_ELF), $(SIPI_ELF:.elf=.o), 0)) +$(eval $(call rmodule_link,$(SIPI_ELF), $(SIPI_ELF:.elf=.o), 0,x86_32)) $(SIPI_BIN): $(SIPI_RMOD) $(OBJCOPY_ramstage) -O binary $< $@ diff --git a/src/cpu/x86/smm/Makefile.inc b/src/cpu/x86/smm/Makefile.inc index 6bdeebeb19..64e1c2cd70 100644 --- a/src/cpu/x86/smm/Makefile.inc +++ b/src/cpu/x86/smm/Makefile.inc @@ -39,7 +39,7 @@ $(obj)/cpu/x86/smm/smmstub.o: $$(smmstub-objs) $(CC_smmstub) $(LDFLAGS) -nostdlib -r -o $@ $^ # Link the SMM stub module with a 0-byte heap. -$(eval $(call rmodule_link,$(obj)/cpu/x86/smm/smmstub.elf, $(obj)/cpu/x86/smm/smmstub.o, 0)) +$(eval $(call rmodule_link,$(obj)/cpu/x86/smm/smmstub.elf, $(obj)/cpu/x86/smm/smmstub.o, 0,x86_32)) $(obj)/cpu/x86/smm/smmstub: $(obj)/cpu/x86/smm/smmstub.elf.rmod $(OBJCOPY_smmstub) -O binary $< $@ @@ -54,7 +54,7 @@ $(obj)/cpu/x86/smm/smm.o: $$(smm-objs) $(LIBGCC_FILE_NAME_smm) $(CC_smm) $(LDFLAGS) -nostdlib -r -o $@ -Wl,--wrap,__divdi3 -Wl,--wrap,__udivdi3 -Wl,--wrap,__moddi3 -Wl,--wrap,__umoddi3 -Wl,--start-group $(smm-objs) $(LIBGCC_FILE_NAME_smm) -Wl,--end-group -$(eval $(call rmodule_link,$(obj)/cpu/x86/smm/smm.elf, $(obj)/cpu/x86/smm/smm.o, $(CONFIG_SMM_MODULE_HEAP_SIZE))) +$(eval $(call rmodule_link,$(obj)/cpu/x86/smm/smm.elf, $(obj)/cpu/x86/smm/smm.o, $(CONFIG_SMM_MODULE_HEAP_SIZE),x86_32)) $(obj)/cpu/x86/smm/smm: $(obj)/cpu/x86/smm/smm.elf.rmod $(OBJCOPY_smm) -O binary $< $@ diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc index ab59ec45e1..09dd75723b 100644 --- a/src/lib/Makefile.inc +++ b/src/lib/Makefile.inc @@ -31,7 +31,9 @@ endif romstage-y += memchr.c romstage-y += memcmp.c -rmodules-y += memcmp.c + +$(foreach arch,$(ARCH_SUPPORTED),\ + $(eval rmodules_$(ARCH_TO_TOOLCHAIN_$(arch))-y += memcmp.c)) verstage-y += delay.c verstage-y += cbfs.c @@ -138,12 +140,13 @@ RMODULE_LDFLAGS := -nostartfiles -Wl,--emit-relocs -Wl,-z,defs -Wl,-Bsymbolic - # (1) the object name to link # (2) the dependencies # (3) heap size of the relocatable module +# (4) arch for which the rmodules are to be linked # It will create the necessary Make rules to create a rmodule. The resulting # rmdoule is named $(1).rmod define rmodule_link $(strip $(1)): $(strip $(2)) $$(RMODULE_LDSCRIPT) $$(obj)/ldoptions - $$(LD_rmodules) $$(RMODULE_LDFLAGS) --defsym=__heap_size=$(strip $(3)) -o $$@ --start-group $(strip $(2)) $$(LIBGCC_FILE_NAME_rmodules) --end-group - $$(NM_rmodules) -n $$@ > $$(basename $$@).map + $$(LD_rmodules_$(4)) -y $$(RMODULE_LDFLAGS) --defsym=__heap_size=$(strip $(3)) -o $$@ --start-group $(strip $(2)) $$(LIBGCC_FILE_NAME_rmodules_$(4)) --end-group + $$(NM_rmodules_$(4)) -n $$@ > $$(basename $$@).map $(strip $(1)).rmod: $(strip $(1)) $$(RMODTOOL) -i $$^ -o $$@ @@ -157,12 +160,13 @@ RMODULE_LDFLAGS := -nostartfiles -Wl,--emit-relocs -Wl,-z,defs -Wl,-Bsymbolic - # (1) the object name to link # (2) the dependencies # (3) heap size of the relocatable module +# (4) arch for which the rmodules are to be linked # It will create the necessary Make rules to create a rmodule. The resulting # rmdoule is named $(1).rmod define rmodule_link $(strip $(1)): $(strip $(2)) $$(RMODULE_LDSCRIPT) $$(obj)/ldoptions $$(RMODTOOL) - $$(CC_rmodules) $$(CFLAGS_rmodules) $$(RMODULE_LDFLAGS) -Wl,--defsym=__heap_size=$(strip $(3)) -o $$@ -Wl,--start-group $(strip $(2)) $$(LIBGCC_FILE_NAME_rmodules) -Wl,--end-group - $$(NM_rmodules) -n $$@ > $$(basename $$@).map + $$(CC_rmodules_$(4)) $$(CFLAGS_rmodules_$(4)) $$(RMODULE_LDFLAGS) -Wl,--defsym=__heap_size=$(strip $(3)) -o $$@ -Wl,--start-group $(strip $(2)) $$(LIBGCC_FILE_NAME_rmodules_$(4)) -Wl,--end-group + $$(NM_rmodules_$(4)) -n $$@ > $$(basename $$@).map $(strip $(1)).rmod: $(strip $(1)) $$(RMODTOOL) -i $$^ -o $$@ diff --git a/src/soc/nvidia/tegra124/Makefile.inc b/src/soc/nvidia/tegra124/Makefile.inc index 97c4e2260a..fe749ba8e1 100644 --- a/src/soc/nvidia/tegra124/Makefile.inc +++ b/src/soc/nvidia/tegra124/Makefile.inc @@ -75,8 +75,8 @@ ramstage-y += ../tegra/usb.c ramstage-y += timer.c ramstage-$(CONFIG_CONSOLE_SERIAL_UART) += uart.c -rmodules-y += monotonic_timer.c -VBOOT_STUB_DEPS += $(obj)/soc/nvidia/tegra124/monotonic_timer.rmodules.o +rmodules_$(ARCH-ROMSTAGE-y)-y += monotonic_timer.c +VBOOT_STUB_DEPS += $(obj)/soc/nvidia/tegra124/monotonic_timer.rmodules_$(ARCH-ROMSTAGE-y).o INCLUDES += -Isrc/soc/nvidia/tegra124/include/ diff --git a/src/soc/samsung/exynos5420/Makefile.inc b/src/soc/samsung/exynos5420/Makefile.inc index caacc21b54..b64e2db234 100644 --- a/src/soc/samsung/exynos5420/Makefile.inc +++ b/src/soc/samsung/exynos5420/Makefile.inc @@ -50,11 +50,11 @@ ramstage-y += dp.c dp_lowlevel.c fimd.c ramstage-y += usb.c ramstage-y += cbmem.c -rmodules-y += monotonic_timer.c -rmodules-y += mct.c +rmodules_$(ARCH-ROMSTAGE-y)-y += monotonic_timer.c +rmodules_$(ARCH-ROMSTAGE-y)-y += mct.c -VBOOT_STUB_DEPS += $(obj)/soc/samsung/exynos5420/monotonic_timer.rmodules.o -VBOOT_STUB_DEPS += $(obj)/soc/samsung/exynos5420/mct.rmodules.o +VBOOT_STUB_DEPS += $(obj)/soc/samsung/exynos5420/monotonic_timer.rmodules_$(ARCH-ROMSTAGE-y).o +VBOOT_STUB_DEPS += $(obj)/soc/samsung/exynos5420/mct.rmodules_$(ARCH-ROMSTAGE-y).o $(objcbfs)/bootblock.raw.elf: $(objcbfs)/bootblock.elf cp $< $@ diff --git a/src/vendorcode/google/chromeos/Makefile.inc b/src/vendorcode/google/chromeos/Makefile.inc index 96c2180700..45a62f3b77 100644 --- a/src/vendorcode/google/chromeos/Makefile.inc +++ b/src/vendorcode/google/chromeos/Makefile.inc @@ -45,7 +45,7 @@ endif ifeq ($(CONFIG_VBOOT_VERIFY_FIRMWARE),y) romstage-y += vboot_loader.c -rmodules-y += vboot_wrapper.c +rmodules_$(ARCH-ROMSTAGE-y)-y += vboot_wrapper.c ifneq ($(CONFIG_SPI_FLASH_MEMORY_MAPPED),y) VBOOT_MAKEFLAGS = REGION_READ=1 @@ -69,15 +69,15 @@ VBOOT_STUB = $(VBOOT_STUB_ELF).rmod VBOOT_STUB_DOTO = $(VBOOT_STUB_ELF:.elf=.o) # Dependency for the vboot rmodules. Ordering matters. -VBOOT_STUB_DEPS += $(obj)/vendorcode/google/chromeos/vboot_wrapper.rmodules.o -VBOOT_STUB_DEPS += $(obj)/lib/memcmp.rmodules.o +VBOOT_STUB_DEPS += $(obj)/vendorcode/google/chromeos/vboot_wrapper.rmodules_$(ARCH-ROMSTAGE-y).o +VBOOT_STUB_DEPS += $(obj)/lib/memcmp.rmodules_$(ARCH-ROMSTAGE-y).o ifeq ($(CONFIG_ARCH_ROMSTAGE_X86_32),y) -VBOOT_STUB_DEPS += $(obj)/arch/x86/lib/memset.rmodules.o -VBOOT_STUB_DEPS += $(obj)/arch/x86/lib/memcpy.rmodules.o +VBOOT_STUB_DEPS += $(obj)/arch/x86/lib/memset.rmodules_$(ARCH-ROMSTAGE-y).o +VBOOT_STUB_DEPS += $(obj)/arch/x86/lib/memcpy.rmodules_$(ARCH-ROMSTAGE-y).o endif ifeq ($(CONFIG_ARCH_ROMSTAGE_ARM),y) -VBOOT_STUB_DEPS += $(obj)/arch/arm/memset.rmodules.o -VBOOT_STUB_DEPS += $(obj)/arch/arm/memcpy.rmodules.o +VBOOT_STUB_DEPS += $(obj)/arch/arm/memset.rmodules_$(ARCH-ROMSTAGE-y).o +VBOOT_STUB_DEPS += $(obj)/arch/arm/memcpy.rmodules_$(ARCH-ROMSTAGE-y).o endif VBOOT_STUB_DEPS += $(VB_LIB) # Remove the '-include' option since that will break vboot's build and ensure @@ -86,10 +86,10 @@ VBOOT_CFLAGS += $(patsubst -I%,-I../%,$(filter-out -include $(src)/include/kconf VBOOT_CFLAGS += -DVBOOT_DEBUG $(VBOOT_STUB_DOTO): $(VBOOT_STUB_DEPS) - $(CC_romstage) $(CFLAGS_romstage) $(LDFLAGS) -nostdlib -r -o $@ $^ + $(CC_rmodules_$(ARCH-ROMSTAGE-y)) $(CFLAGS_rmodules_$(ARCH-ROMSTAGE-y)) $(LDFLAGS) -nostdlib -r -o $@ $^ # Link the vbootstub module with a 64KiB-byte heap. -$(eval $(call rmodule_link,$(VBOOT_STUB_ELF), $(VBOOT_STUB_DOTO), 0x10000)) +$(eval $(call rmodule_link,$(VBOOT_STUB_ELF), $(VBOOT_STUB_DOTO), 0x10000,$(ARCH-ROMSTAGE-y))) # Build vboot library without the default includes from coreboot proper. $(VB_LIB): diff --git a/toolchain.inc b/toolchain.inc index 6dd88c3611..fca09126a9 100644 --- a/toolchain.inc +++ b/toolchain.inc @@ -76,6 +76,18 @@ LIBGCC_FILE_NAME_$(1) = $(shell test -n "$(CC_$(2))" && \ $(CC_$(2)) -print-libgcc-file-name) endef +# define_class: Allows defining any program as dynamic class and compiler tool +# set for the same based on the architecture for which the program is to be +# compiled +# @1: program (class name) +# @2: architecture for which the program needs to be compiled +# IMP: Ensure that define_class is called before any .c or .S files are added to +# the class of the program. Check subdirs-y for order of subdirectory inclusions +define define_class +classes-y += $(1) +$(eval $(call create_class_compiler,$(1),$(2))) +endef + # initialize standard toolchain (CC,AS and others) for given stage # @1 : stage for which the toolchain is to be initialized init_standard_toolchain = \