diff options
-rw-r--r-- | Makefile | 63 | ||||
-rw-r--r-- | Makefile.rules | 98 | ||||
-rw-r--r-- | Makefile.toolchain | 7 | ||||
-rw-r--r-- | board/glados_pd/build.mk | 3 | ||||
-rw-r--r-- | board/oak_pd/build.mk | 3 | ||||
-rw-r--r-- | board/ryu_sh/build.mk | 4 | ||||
-rw-r--r-- | board/zinger/build.mk | 3 | ||||
-rw-r--r-- | chip/mec1322/build.mk | 15 | ||||
-rw-r--r-- | common/ec.libsharedobjs.ld | 15 | ||||
-rw-r--r-- | common/firmware_image.S | 10 | ||||
-rw-r--r-- | common/firmware_image.lds.S | 6 | ||||
-rw-r--r-- | core/cortex-m/ec.lds.S | 9 | ||||
-rw-r--r-- | core/cortex-m0/ec.lds.S | 8 | ||||
-rw-r--r-- | include/config.h | 15 | ||||
-rw-r--r-- | include/config_std_internal_flash.h | 19 |
15 files changed, 222 insertions, 56 deletions
@@ -124,27 +124,62 @@ include util/lock/build.mk includes+=$(includes-y) -objs_from_dir=$(sort $(foreach obj, $($(2)-y), \ - $(out)/$(1)/$(firstword $($(2)-mock-$(PROJECT)-$(obj)) $(obj)))) +ro-objs_from_dir=$(sort $(foreach obj, $($(2)-y), \ + $(out)/RO/$(1)/$(firstword $($(2)-mock-$(PROJECT)-$(obj)) $(obj)))) # Get all sources to build -all-y=$(call objs_from_dir,core/$(CORE),core) -all-y+=$(call objs_from_dir,chip/$(CHIP),chip) -all-y+=$(call objs_from_dir,board/$(BOARD),board) -all-y+=$(call objs_from_dir,private,private) -all-y+=$(call objs_from_dir,private-cr51,private-cr51) -all-y+=$(call objs_from_dir,common,common) -all-y+=$(call objs_from_dir,driver,driver) -all-y+=$(call objs_from_dir,power,power) -all-y+=$(call objs_from_dir,test,$(PROJECT)) -dirs=core/$(CORE) chip/$(CHIP) board/$(BOARD) common power test util -dirs+=private private-cr51 +all-ro-y=$(call ro-objs_from_dir,core/$(CORE),core) +all-ro-y+=$(call ro-objs_from_dir,chip/$(CHIP),chip) +all-ro-y+=$(call ro-objs_from_dir,board/$(BOARD),board) +all-ro-y+=$(call ro-objs_from_dir,private,private) +all-ro-y+=$(call ro-objs_from_dir,private-cr51,private-cr51) +all-ro-y+=$(call ro-objs_from_dir,common,common) +all-ro-y+=$(call ro-objs_from_dir,driver,driver) +all-ro-y+=$(call ro-objs_from_dir,power,power) +all-ro-y+=$(call ro-objs_from_dir,test,$(PROJECT)) +dirs=core/$(CORE) chip/$(CHIP) board/$(BOARD) common power test +dirs+= private private-cr51 dirs+=$(shell find driver -type d) +common_dirs=util +ro-objs := $(all-ro-y) +# Don't include the shared objects in the RO/RW image if we're enabling +# the shared objects library. +ifeq ($(CONFIG_SHAREDLIB),y) +ro-objs := $(filter-out %_sharedlib.o, $(ro-objs)) +endif +rw-objs := $(ro-objs:$(out)/RO/%=$(out)/RW/%) +ro-deps := $(ro-objs:%.o=%.o.d) +rw-deps := $(rw-objs:%.o=%.o.d) +deps := $(ro-deps) $(rw-deps) + +.PHONY: ro rw $(config): $(out)/$(PROJECT).bin @printf '%s=y\n' $(_tsk_cfg) $(_flag_cfg) > $@ -all: $(config) utils ${PROJECT_EXTRA} +def_all_deps:=utils ro rw $(config) $(PROJECT_EXTRA) +all_deps?=$(def_all_deps) +all: $(all_deps) + +ro: override BLD:=RO +ro: $(libsharedobjs_elf-y) $(out)/RO/$(PROJECT).RO.flat + +rw: override BLD:=RW +rw: $(libsharedobjs_elf-y) $(out)/RW/$(PROJECT).RW.flat + +# Shared objects library +SHOBJLIB := libsharedobjs +sharedlib-objs := $(filter %_sharedlib.o, $(all-ro-y)) +sharedlib-objs := $(sharedlib-objs:$(out)/RO/%=$(out)/$(SHOBJLIB)/%) +sharedlib-deps := $(sharedlib-objs:%.o=%.o.d) +deps += $(sharedlib-deps) +def_libsharedobjs_deps := $(sharedlib-objs) +libsharedobjs_deps ?= $(def_libsharedobjs_deps) + +libsharedobjs-$(CONFIG_SHAREDLIB) := $(out)/$(SHOBJLIB)/$(SHOBJLIB).flat +libsharedobjs_elf-$(CONFIG_SHAREDLIB) := \ + $(libsharedobjs-$(CONFIG_SHAREDLIB):%.flat=%.elf) +libsharedobjs: $(libsharedobjs-y) include Makefile.rules diff --git a/Makefile.rules b/Makefile.rules index 8ccb54540a..4b3b64f12c 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -7,8 +7,6 @@ # Embedded Controller firmware build system - common targets # -objs := $(all-y) -deps := $(objs:%.o=%.o.d) build-utils := $(foreach u,$(build-util-bin),$(out)/util/$(u)) host-utils := $(foreach u,$(host-util-bin),$(out)/util/$(u)) build-srcs := $(foreach u,$(build-util-bin),$(sort $($(u)-objs:%.o=util/%.c) util/$(u).c)) @@ -19,10 +17,14 @@ skip_boards = OWNERS host it8380dev boards := $(filter-out $(skip_boards),$(subst board/,,$(wildcard board/*))) # Create output directories if necessary -_dir_create := $(foreach d,$(dirs),$(shell [ -d $(out)/$(d) ] || \ - mkdir -p $(out)/$(d))) -_dir_y_create := $(foreach d,$(dirs-y),$(shell [ -d $(out)/$(d) ] || \ +_common_dir_create := $(foreach d,$(common_dirs),$(shell [ -d $(out)/$(d) ] || \ mkdir -p $(out)/$(d))) +_sharedlib_dir_create := $(foreach d,$(dirs),$(shell \ + [ -d $(out)/$(SHOBJLIB)/$(d) ] || mkdir -p $(out)/$(SHOBJLIB)/$(d))) +_dir_create := $(foreach d,$(dirs),$(shell [ -d $(out)/$(BLD)/$(d) ] || \ + mkdir -p $(out)/RO/$(d); mkdir -p $(out)/RW/$(d))) +_dir_y_create := $(foreach d,$(dirs-y),$(shell [ -d $(out)/$(BLD)/$(d) ] || \ + mkdir -p $(out)/RO/$(d); mkdir -p $(out)/RW/$(d))) section = $(subst .,,$(suffix $(1))) section_is = $(subst .,,SECTION_IS_$(suffix $(1))) @@ -40,15 +42,19 @@ cmd_lds = $(CPP) -P -C -MMD -MF $@.d -MT $@ $(CPPFLAGS) \ cmd_obj_to_bin ?= $(OBJCOPY) --gap-fill=0xff -O binary $^ $(out)/$*.bin.tmp cmd_flat_to_obj = $(CC) -T $(out)/firmware_image.lds -nostdlib $(CPPFLAGS) \ -Wl,--build-id=none -o $@ $< -cmd_elf_to_flat = $(OBJCOPY) -O binary $< $@ +cmd_elf_to_flat = $(OBJCOPY) -O binary $(patsubst %.flat,%.elf,$@) $@ +# Allow the .roshared section to overlap other sections (itself) +cmd_ec_elf_to_flat = $(OBJCOPY) --set-section-flags .roshared=share \ + -O binary $(patsubst %.flat,%.elf,$@) $@ cmd_elf_to_dis = $(OBJDUMP) -D $< > $@ cmd_elf_to_hex = $(OBJCOPY) -O ihex $< $@ cmd_bin_to_hex = $(OBJCOPY) -I binary -O ihex \ --change-addresses $(_flash_base) $^ $@ -cmd_elf = $(CC) $(objs) $(LDFLAGS) -o $@ -Wl,-T,$< -Wl,-Map,$(out)/$*.map cmd_smap = $(NM) $< | sort > $@ -cmd_exe = $(CC) $(objs) $(HOST_TEST_LDFLAGS) -o $@ -cmd_c_to_o = $(CC) $(CFLAGS) -MMD -MF $@.d -c $< -o $@ +cmd_elf = $(CC) $(objs) $(libsharedobjs_elf-y) $(LDFLAGS) \ + -o $@ -Wl,-T,$< -Wl,-Map,$(patsubst %.elf,%.map,$@) +cmd_exe = $(CC) $(ro-objs) $(HOST_TEST_LDFLAGS) -o $@ +cmd_c_to_o = $(CC) $(CFLAGS) -MMD -MF $@.d -c $< -o $(@D)/$(@F) cmd_c_to_build = $(BUILDCC) $(BUILD_CFLAGS) \ $(sort $(foreach c,$($(*F)-objs),util/$(c:%.o=%.c)) $*.c) \ $(BUILD_LDFLAGS) \ @@ -61,7 +67,11 @@ cmd_version = ./util/getversion.sh > $@ cmd_mv_from_tmp = mv $(out)/$*.bin.tmp $(out)/$*.bin cmd_extractrw-y = dd if=$(out)/$(PROJECT).bin.tmp of=$(out)/$(PROJECT).RW.bin \ bs=1 count=$(_rw_size) skip=$(_rw_off) $(silent_err) -cmd_copyrw-y = cd $(out) && cp $(PROJECT).RW.flat $(PROJECT).RW.bin +cmd_copyrw-y = cd $(out) && cp RW/$(PROJECT).RW.flat RW/$(PROJECT).RW.bin +cmd_sharedlib_elf = $(CC) $(libsharedobjs_deps) \ + -Wl,-T,common/ec.$(SHOBJLIB).ld $(LDFLAGS) \ + -o $(out)/$(SHOBJLIB)/$(SHOBJLIB).elf \ + -Wl,-Map,$(out)/$(SHOBJLIB)/$(SHOBJLIB).map # commands for RSA signature cmd_pubkey = ./util/pem_extract_pubkey.py $(PEM) > $@ @@ -83,12 +93,13 @@ proj-%: @echo "======= building $*"; \ $(MAKE) --no-print-directory BOARD=$* V=$(V) -dis-y = $(out)/$(PROJECT).RW.dis -dis-$(CONFIG_FW_INCLUDE_RO) += $(out)/$(PROJECT).RO.dis +dis-y := $(out)/RW/$(PROJECT).RW.dis +dis-$(CONFIG_FW_INCLUDE_RO) += $(out)/RO/$(PROJECT).RO.dis +dis-$(CONFIG_SHAREDLIB) += $(out)/$(SHOBJLIB)/$(SHOBJLIB).dis dis: $(dis-y) .PHONY: dis -hex-y = $(out)/$(PROJECT).RO.hex $(out)/$(PROJECT).RW.hex $(out)/$(PROJECT).hex +hex-y := $(out)/RO/$(PROJECT).RO.hex $(out)/RW/$(PROJECT).RW.hex $(out)/$(PROJECT).hex hex: $(hex-y) .PHONY: hex @@ -165,12 +176,15 @@ $(out)/%.bin: $(out)/%.obj $(call quiet,copyrw-y,COPY_RW)) $(call quiet,mv_from_tmp,MV ) -flat-y = $(out)/$(PROJECT).RW.flat -flat-$(CONFIG_FW_INCLUDE_RO) += $(out)/$(PROJECT).RO.flat +flat-y := $(out)/RW/$(PROJECT).RW.flat +flat-$(CONFIG_FW_INCLUDE_RO) += $(out)/RO/$(PROJECT).RO.flat deps += $(out)/firmware_image.lds.d $(flat-y:%.flat=%.lds.d) -$(out)/%.obj: common/firmware_image.S $(out)/firmware_image.lds $(flat-y) +flat-$(CONFIG_SHAREDLIB) += $(libsharedobjs-y) + +$(out)/$(PROJECT).obj: common/firmware_image.S $(out)/firmware_image.lds \ + $(flat-y) $(call quiet,flat_to_obj,CAT ) $(out)/%.dis: $(out)/%.elf @@ -179,29 +193,58 @@ $(out)/%.dis: $(out)/%.elf $(out)/%.flat: $(out)/%.elf $(out)/%.smap $(call quiet,elf_to_flat,OBJCOPY) -$(out)/%.hex: $(out)/%.elf $(out)/%.smap +$(out)/RW/ec.RW.flat: $(out)/RW/ec.RW.elf $(out)/RW/ec.RW.smap + $(call quiet,ec_elf_to_flat,OBJCOPY) +$(out)/RO/ec.RO.flat: $(out)/RO/ec.RO.elf $(out)/RO/ec.RO.smap + $(call quiet,ec_elf_to_flat,OBJCOPY) + +$(out)/RW/%.hex: $(out)/RW/%.elf $(out)/RW/%.smap + $(call quiet,elf_to_hex,OBJCOPY) +$(out)/RO/%.hex: $(out)/RO/%.elf $(out)/RO/%.smap $(call quiet,elf_to_hex,OBJCOPY) $(out)/$(PROJECT).hex: $(out)/$(PROJECT).bin $(call quiet,bin_to_hex,OBJCOPY) +$(out)/RW/%.elf: override BLD:=RW +$(out)/RW/%.elf: private objs := $(rw-objs) +$(out)/RW/%.elf: $(out)/RW/%.lds $(rw-objs) $(libsharedobjs_elf-y) + $(call quiet,elf,LD ) + +$(out)/RO/%.elf: override BLD:=RO +$(out)/RO/%.elf: private objs := $(ro-objs) +$(out)/RO/%.elf: $(out)/RO/%.lds $(ro-objs) $(libsharedobjs_elf-y) + $(call quiet,elf,LD ) + $(out)/%.elf: $(out)/%.lds $(objs) $(call quiet,elf,LD ) +$(out)/$(SHOBJLIB)/$(SHOBJLIB).elf: $(sharedlib-objs) + @mkdir -p $(out)/$(SHOBJLIB) + $(call quiet,sharedlib_elf,LD ) + $(out)/%.smap: $(out)/%.elf $(call quiet,smap,NM ) -$(out)/$(PROJECT).exe: $(objs) +$(out)/$(PROJECT).exe: $(ro-objs) $(call quiet,exe,EXE ) -$(out)/%.o:%.c +$(out)/RO/%.o:%.c + $(call quiet,c_to_o,CC ) +$(out)/RW/%.o:%.c + $(call quiet,c_to_o,CC ) +$(out)/$(SHOBJLIB)/%.o: override LATE_CFLAGS_DEFINE:=-DSHAREDLIB_IMAGE +$(out)/$(SHOBJLIB)/%.o:%.c $(call quiet,c_to_o,CC ) $(out)/vboot/%.o:$(VBOOT_SOURCE)/%.c $(call quiet,c_to_o,CC ) -$(out)/%.o:%.S +$(out)/RO/%.o:%.S $(call quiet,c_to_o,AS ) +$(out)/RW/%.o:%.S + $(call quiet,c_to_o,AS ) + # Conditionally force the rebuilding of ec_version.h only if it would be # changed. @@ -215,25 +258,30 @@ endif # All of the objects have an order only dependency on the ec_version header. # This ensures that if ec_version.h needs to be build (because it was marked # PHONY above) then it will be rebuilt before any objects. This is important -# because some source files will include ev_version.h and fail to compile if +# because some source files will include ec_version.h and fail to compile if # it doesn't already exist. This dependency shouldn't be a normal dependency # because that would cause every object to be rebuilt when ec_version.h # changes, instead of just the ones that actually depend on it. The objects # that truly depend on ec_version.h will have that information encoded in their # .d file. -$(objs): | $(out)/ec_version.h +$(ro-objs): | $(out)/ec_version.h +$(rw-objs): | $(out)/ec_version.h +$(sharedlib-objs): | $(out)/ec_version.h $(out)/ec_version.h: $(call quiet,version,VERSION) -$(out)/common/version.o: $(out)/ec_date.h -$(out)/ec_date.h: $(filter-out $(out)/common/version.o,$(objs)) +$(out)/RO/common/version.o: $(out)/ec_date.h +$(out)/RW/common/version.o: $(out)/ec_date.h + +$(out)/ec_date.h: $(filter-out $(out)/%/common/version.o,$(objs)) $(call quiet,date,DATE ) $(out)/gen_pub_key.h: $(PEM) $(call quiet,pubkey,PUBKEY ) -$(out)/common/rwsig.o: $(out)/gen_pub_key.h +$(out)/RO/common/rwsig.o: $(out)/gen_pub_key.h +$(out)/RW/common/rwsig.o: $(out)/gen_pub_key.h $(build-utils): $(out)/%:$(build-srcs) $(call quiet,c_to_build,BUILDCC) diff --git a/Makefile.toolchain b/Makefile.toolchain index f875751115..9b317c89e3 100644 --- a/Makefile.toolchain +++ b/Makefile.toolchain @@ -32,13 +32,14 @@ CFLAGS_TEST=$(if $(TEST_BUILD),-DTEST_BUILD \ -DTEST_$(PROJECT) -DTEST_$(UC_PROJECT) CFLAGS_COVERAGE=$(if $(TEST_COVERAGE),-fprofile-arcs -ftest-coverage \ -DTEST_COVERAGE,) -CFLAGS_DEFINE=-DOUTDIR=$(out) -DCHIP=$(CHIP) -DBOARD_TASKFILE=$(_tsk_lst_file) \ +CFLAGS_DEFINE=-DOUTDIR=$(out)/$(BLD) -DCHIP=$(CHIP) -DBOARD_TASKFILE=$(_tsk_lst_file) \ -DBOARD=$(BOARD) -DCORE=$(CORE) -DPROJECT=$(PROJECT) \ -DCHIP_VARIANT=$(CHIP_VARIANT) -DCHIP_FAMILY=$(CHIP_FAMILY) \ -DBOARD_$(UC_BOARD) -DCHIP_$(UC_CHIP) -DCORE_$(UC_CORE) \ - -DCHIP_VARIANT_$(UC_CHIP_VARIANT) -DCHIP_FAMILY_$(UC_CHIP_FAMILY) + -DCHIP_VARIANT_$(UC_CHIP_VARIANT) -DCHIP_FAMILY_$(UC_CHIP_FAMILY) \ + -DFINAL_OUTDIR=$(out) CPPFLAGS=$(CFLAGS_DEFINE) $(CFLAGS_INCLUDE) $(CFLAGS_TEST) \ - $(EXTRA_CFLAGS) $(CFLAGS_COVERAGE) + $(EXTRA_CFLAGS) $(CFLAGS_COVERAGE) $(LATE_CFLAGS_DEFINE) CFLAGS=$(CPPFLAGS) $(CFLAGS_CPU) $(CFLAGS_DEBUG) $(CFLAGS_WARN) $(CFLAGS_y) CFLAGS+= -ffunction-sections -fshort-wchar CFLAGS+= -fno-delete-null-pointer-checks -fconserve-stack diff --git a/board/glados_pd/build.mk b/board/glados_pd/build.mk index 392c3026e3..ef1c9f1a91 100644 --- a/board/glados_pd/build.mk +++ b/board/glados_pd/build.mk @@ -11,3 +11,6 @@ CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f05x board-y=board.o + +# This target builds RW only. Therefore, remove RO from dependencies. +all_deps=$(patsubst ro,,$(def_all_deps)) diff --git a/board/oak_pd/build.mk b/board/oak_pd/build.mk index 392c3026e3..ef1c9f1a91 100644 --- a/board/oak_pd/build.mk +++ b/board/oak_pd/build.mk @@ -11,3 +11,6 @@ CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f05x board-y=board.o + +# This target builds RW only. Therefore, remove RO from dependencies. +all_deps=$(patsubst ro,,$(def_all_deps)) diff --git a/board/ryu_sh/build.mk b/board/ryu_sh/build.mk index 76ac52f9e5..b89b8f40b3 100644 --- a/board/ryu_sh/build.mk +++ b/board/ryu_sh/build.mk @@ -1,3 +1,4 @@ +# -*- makefile -*- # Copyright (c) 2014 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -10,3 +11,6 @@ CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f07x board-y=board.o + +# This target builds RW only. Therefore, remove RO from dependencies. +all_deps=$(patsubst ro,,$(def_all_deps)) diff --git a/board/zinger/build.mk b/board/zinger/build.mk index 885b0c5c0a..fd04fe0521 100644 --- a/board/zinger/build.mk +++ b/board/zinger/build.mk @@ -14,4 +14,5 @@ board-y=board.o hardware.o runtime.o usb_pd_policy.o board-$(CONFIG_DEBUG_PRINTF)+=debug.o # Add dependency to generate the public key coefficients header -$(out)/board/$(BOARD)/board.o: $(out)/gen_pub_key.h +$(out)/RO/board/$(BOARD)/board.o: $(out)/gen_pub_key.h +$(out)/RW/board/$(BOARD)/board.o: $(out)/gen_pub_key.h diff --git a/chip/mec1322/build.mk b/chip/mec1322/build.mk index 3b7352fda0..5d20b7d079 100644 --- a/chip/mec1322/build.mk +++ b/chip/mec1322/build.mk @@ -39,27 +39,28 @@ cmd_obj_to_bin = $(OBJCOPY) --gap-fill=0xff -O binary $< $@.tmp1 ; \ --spi_size ${CHIP_SPI_SIZE_KB} ; rm -f $@.tmp1 mec1322-lfw = chip/mec1322/lfw/ec_lfw -mec1322-lfw-flat = $(out)/$(mec1322-lfw)-lfw.flat +mec1322-lfw-flat = $(out)/RW/$(mec1322-lfw)-lfw.flat # build these specifically for lfw with -lfw suffix -objs_lfw = $(patsubst %, $(out)/%-lfw.o, \ +objs_lfw = $(patsubst %, $(out)/RW/%-lfw.o, \ $(addprefix common/, util gpio) \ $(addprefix chip/$(CHIP)/, spi dma gpio clock hwtimer) \ core/$(CORE)/cpu $(mec1322-lfw)) # reuse version.o (and its dependencies) from main board -objs_lfw += $(out)/common/version.o +objs_lfw += $(out)/RW/common/version.o dirs-y+=chip/$(CHIP)/lfw # objs with -lfw suffix are to include lfw's gpio -$(out)/%-lfw.o: private CC+=-Iboard/$(BOARD)/lfw -DLFW -$(out)/%-lfw.o: %.c +$(out)/RW/%-lfw.o: private CC+=-Iboard/$(BOARD)/lfw -DLFW +$(out)/RW/%-lfw.o: %.c $(call quiet,c_to_o,CC ) # let lfw's elf link only with selected objects -$(out)/%-lfw.elf: private objs = $(objs_lfw) -$(out)/%-lfw.elf: %.ld $(objs_lfw) +$(out)/RW/%-lfw.elf: private objs = $(objs_lfw) +$(out)/RW/%-lfw.elf: override shlib := +$(out)/RW/%-lfw.elf: %.ld $(objs_lfw) $(call quiet,elf,LD ) # final image needs lfw loader diff --git a/common/ec.libsharedobjs.ld b/common/ec.libsharedobjs.ld new file mode 100644 index 0000000000..ba4170a07e --- /dev/null +++ b/common/ec.libsharedobjs.ld @@ -0,0 +1,15 @@ +/* Copyright (c) 2015 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +SECTIONS +{ + .roshared : { KEEP(*(.roshared*)) } + /* + * Save the .ARM.atrributes section to make the linker not complain + * about conflicting CPU architectures when linking with the RW objs. + * This section will be discarded by the main EC linker script. + */ + .ARM.attributes : { KEEP(*(.ARM.*)) } +} diff --git a/common/firmware_image.S b/common/firmware_image.S index aaaed19921..8a4fc7f9a2 100644 --- a/common/firmware_image.S +++ b/common/firmware_image.S @@ -8,10 +8,10 @@ #include "config.h" -#define FW_FILE(builddir,proj,sect) builddir##/##proj##.##sect##.flat +#define FW_FILE(builddir,proj,sect) builddir##/##sect##/##proj##.##sect##.flat #define STRINGIFY0(name) #name #define STRINGIFY(name) STRINGIFY0(name) -#define FW_IMAGE(sect) STRINGIFY(FW_FILE(OUTDIR,PROJECT,sect)) +#define FW_IMAGE(sect) STRINGIFY(FW_FILE(FINAL_OUTDIR,PROJECT,sect)) /* Read Only firmware */ #ifdef CONFIG_FW_INCLUDE_RO @@ -19,6 +19,12 @@ .incbin FW_IMAGE(RO) #endif +/* Shared objects library */ +#ifdef CONFIG_SHAREDLIB +.section .image.libsharedobjs, "ax" +.incbin STRINGIFY(FINAL_OUTDIR/libsharedobjs/libsharedobjs.flat) +#endif + /* Read Write firmware */ .section .image.RW, "ax" .incbin FW_IMAGE(RW) diff --git a/common/firmware_image.lds.S b/common/firmware_image.lds.S index 089e032d57..d956a3471d 100644 --- a/common/firmware_image.lds.S +++ b/common/firmware_image.lds.S @@ -24,6 +24,12 @@ SECTIONS *(.image.RO) } > FLASH =0xff . = ALIGN(CONFIG_FLASH_BANK_SIZE); +#ifdef CONFIG_SHAREDLIB + .image.libsharedobjs : AT(CONFIG_FLASH_BASE + CONFIG_SHAREDLIB_MEM_OFF) { + *(.image.libsharedobjs) + } > FLASH =0xff + . = ALIGN(CONFIG_FLASH_BANK_SIZE); +#endif #if (CONFIG_RO_MEM_OFF == CONFIG_RW_MEM_OFF) /* This is applicable to ECs in which RO and RW execution is mapped to the same location but we still have to generate an ec.bin with RO diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index d637860329..dc9e829fa1 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -27,6 +27,9 @@ MEMORY */ FLASH_HDR (rx) : ORIGIN = FW_OFF(RO_HDR), LENGTH = FW_SIZE(RO_HDR) #endif +#ifdef CONFIG_SHAREDLIB + SHARED_LIB (rx) : ORIGIN = FW_OFF(SHAREDLIB), LENGTH = FW_SIZE_(SHAREDLIB) +#endif FLASH (rx) : ORIGIN = FW_OFF(SECTION), LENGTH = FW_SIZE(SECTION) IRAM (rw) : ORIGIN = CONFIG_RAM_BASE, LENGTH = CONFIG_RAM_SIZE #ifdef CONFIG_CODERAM_ARCH @@ -59,6 +62,11 @@ SECTIONS KEEP(*(.header)) } > FLASH_HDR #endif +#ifdef CONFIG_SHAREDLIB + .roshared : { + KEEP(*(.roshared*)) + } > SHARED_LIB +#endif .text : { OUTDIR/core/CORE/init.o (.text.vecttable) . = ALIGN(4); @@ -89,7 +97,6 @@ SECTIONS #endif #endif . = ALIGN(4); - .rodata : { /* Symbols defined here are declared in link_defs.h */ __irqprio = .; diff --git a/core/cortex-m0/ec.lds.S b/core/cortex-m0/ec.lds.S index 48144a4b9d..594fcfff50 100644 --- a/core/cortex-m0/ec.lds.S +++ b/core/cortex-m0/ec.lds.S @@ -17,6 +17,9 @@ OUTPUT_ARCH(BFD_ARCH) ENTRY(reset) MEMORY { +#ifdef CONFIG_SHAREDLIB + SHARED_LIB (rx) : ORIGIN = FW_OFF(SHAREDLIB), LENGTH = FW_SIZE_(SHAREDLIB) +#endif FLASH (rx) : ORIGIN = FW_OFF(SECTION), LENGTH = FW_SIZE(SECTION) IRAM (rw) : ORIGIN = CONFIG_RAM_BASE, LENGTH = CONFIG_RAM_SIZE #ifdef RSA_PUBLIC_KEY_SIZE @@ -31,6 +34,11 @@ MEMORY } SECTIONS { +#ifdef CONFIG_SHAREDLIB + .roshared : { + KEEP(*(.roshared*)) + } > SHARED_LIB +#endif .text : { OUTDIR/core/CORE/init.o (.text.vecttable) . = ALIGN(4); diff --git a/include/config.h b/include/config.h index 999083d776..0058391ac4 100644 --- a/include/config.h +++ b/include/config.h @@ -1280,6 +1280,21 @@ */ #undef CONFIG_RWSIG +/****************************************************************************/ +/* Shared objects library. */ + +/* Support shared objects library between RO and RW. */ +#undef CONFIG_SHAREDLIB + +/* Size of shared objects library. */ +#undef CONFIG_SHAREDLIB_SIZE + +/* Program memory offset of shared objects library. */ +#undef CONFIG_SHAREDLIB_MEM_OFF + +/* Storage offset of sharedobjects library. */ +#undef CONFIG_SHAREDLIB_STORAGE_OFF + /* * If defined, the hash module will save its last computed hash when jumping * between EC images. diff --git a/include/config_std_internal_flash.h b/include/config_std_internal_flash.h index c0df3d4199..d918e8a813 100644 --- a/include/config_std_internal_flash.h +++ b/include/config_std_internal_flash.h @@ -22,14 +22,27 @@ #define CONFIG_FW_PSTATE_OFF (CONFIG_FW_IMAGE_SIZE - CONFIG_FW_PSTATE_SIZE) /* Size of one firmware image in flash */ -#define CONFIG_FW_IMAGE_SIZE (CONFIG_FLASH_PHYSICAL_SIZE / 2) +#define CONFIG_FW_IMAGE_SIZE ((CONFIG_FLASH_PHYSICAL_SIZE - \ + CONFIG_SHAREDLIB_SIZE) / 2) #define CONFIG_FLASH_SIZE CONFIG_FLASH_PHYSICAL_SIZE +/* + * By default, there is no shared objects library. However, if configured, the + * shared objects library will be placed after the RO image. + */ +#define CONFIG_SHAREDLIB_MEM_OFF (CONFIG_RO_MEM_OFF + \ + CONFIG_FW_IMAGE_SIZE) +#define CONFIG_SHAREDLIB_STORAGE_OFF (CONFIG_RO_STORAGE_OFF + \ + CONFIG_FW_IMAGE_SIZE) +#define CONFIG_SHAREDLIB_SIZE 0 + #define CONFIG_RO_MEM_OFF 0 #define CONFIG_RO_STORAGE_OFF 0 #define CONFIG_RO_SIZE (CONFIG_FW_IMAGE_SIZE - CONFIG_FW_PSTATE_SIZE) -#define CONFIG_RW_MEM_OFF CONFIG_FW_IMAGE_SIZE -#define CONFIG_RW_STORAGE_OFF CONFIG_FW_IMAGE_SIZE +#define CONFIG_RW_MEM_OFF (CONFIG_SHAREDLIB_MEM_OFF + \ + CONFIG_SHAREDLIB_SIZE) +#define CONFIG_RW_STORAGE_OFF (CONFIG_SHAREDLIB_STORAGE_OFF + \ + CONFIG_SHAREDLIB_SIZE) #define CONFIG_RW_SIZE CONFIG_FW_IMAGE_SIZE #define CONFIG_WP_OFF CONFIG_RO_STORAGE_OFF |