summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2019-01-23 15:13:01 +0800
committerchrome-bot <chrome-bot@chromium.org>2019-02-18 08:51:20 -0800
commit0528c46598c8c89f04b7129722de50e178b62aa2 (patch)
tree9afe729c302f433174b1f8bcecfeaf206d5cb554
parent80020d90d17ac1507abcefe9004ed6ae8cb9728d (diff)
downloadchrome-ec-0528c46598c8c89f04b7129722de50e178b62aa2.tar.gz
core: Allow .bss and .data sections in DRAM
We manually copy other .data from the original section on boot, and clear DRAM .bss. This way, a single object file (or archive) can be moved fully to DRAM. BRANCH=none BUG=b:122058243 TEST=With next CL, dram_test works Change-Id: I1a434bbd8a4135d16b3f49b0d1b75b96506e3e24 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1445652 Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--Makefile.rules4
-rw-r--r--common/main.c11
-rw-r--r--core/cortex-m/ec.lds.S27
-rw-r--r--include/link_defs.h7
4 files changed, 46 insertions, 3 deletions
diff --git a/Makefile.rules b/Makefile.rules
index 8ea3c7cac0..7c158ffcad 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -61,9 +61,9 @@ cmd_obj_to_bin ?= $(OBJCOPY) --gap-fill=0xff -O binary $^ $(out)/$*.bin.tmp
cmd_flat_to_obj = $(CC) -Wl,-T $(out)/firmware_image.lds -nostdlib $(CPPFLAGS) \
-Wl,--build-id=none -o $@ $<
# Allow the .roshared section to overlap other sections (itself)
-cmd_ec_elf_to_flat ?= $(OBJCOPY) --set-section-flags .roshared=share -R .dram \
+cmd_ec_elf_to_flat ?= $(OBJCOPY) --set-section-flags .roshared=share -R .dram* \
-O binary $< $@
-cmd_ec_elf_to_flat_dram ?= $(OBJCOPY) -j .dram -O binary $< $@
+cmd_ec_elf_to_flat_dram ?= $(OBJCOPY) -j .dram* -O binary $< $@
cmd_elf_to_signed ?= $(SIGNER) --key=util/signer/$(3) \
--b --input=$< --format=bin --output=$@.signed $(SIGNER_EXTRAS) \
&& sudo chown $(shell whoami) $@.signed && mv $@.signed $@
diff --git a/common/main.c b/common/main.c
index 6adea9b049..0a222b23ca 100644
--- a/common/main.c
+++ b/common/main.c
@@ -17,8 +17,9 @@
#include "flash.h"
#include "gpio.h"
#include "hooks.h"
-#include "lpc.h"
#include "keyboard_scan.h"
+#include "link_defs.h"
+#include "lpc.h"
#ifdef CONFIG_MPU
#include "mpu.h"
#endif
@@ -84,6 +85,14 @@ test_mockable __keep int main(void)
system_pre_init();
system_common_pre_init();
+#ifdef CONFIG_DRAM_BASE
+ /* Now that DRAM is initialized, clear up DRAM .bss, copy .data over. */
+ memset(&__dram_bss_start, 0,
+ (uintptr_t)(&__dram_bss_end) - (uintptr_t)(&__dram_bss_start));
+ memcpy(&__dram_data_start, &__dram_data_lma_start,
+ (uintptr_t)(&__dram_data_end) - (uintptr_t)(&__dram_data_start));
+#endif
+
#if defined(CONFIG_FLASH_PHYSICAL)
/*
* Initialize flash and apply write protect if necessary. Requires
diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S
index 06bd83a30d..28c3e691cd 100644
--- a/core/cortex-m/ec.lds.S
+++ b/core/cortex-m/ec.lds.S
@@ -444,7 +444,34 @@ SECTIONS
#endif /* CONFIG_CHIP_MEMORY_REGIONS */
#ifdef CONFIG_DRAM_BASE
+ /* Allocate space for original copy of .data.dram (see .data_lma above). */
+ .dram.data_lma : {
+ __dram_data_lma_start = .;
+ . += __dram_data_end - __dram_data_start;
+ } > DRAM
+
+ /*
+ * TODO(b:122058243): Both .dram.data and .dram.bss do not actually
+ * need to be in the final image, as we have a second copy of the data
+ * (just above), and dram.bss is zeroed anyway.
+ */
+ .dram.data : AT(ADDR(.dram.data_lma)) {
+ . = ALIGN(4);
+ __dram_data_start = .;
+ *(.dram.data*)
+ __dram_data_end = .;
+ } > DRAM
+
+ .dram.bss : {
+ . = ALIGN(4);
+ __dram_bss_start = .;
+ *(SORT(.dram.bss*))
+ __dram_bss_end = .;
+ } > DRAM
+
+ /* Rest of DRAM sections, e.g. text. */
.dram : {
+ . = ALIGN(4);
KEEP(*(SORT(.dram.keep.*)))
*(SORT(.dram.*))
} > DRAM
diff --git a/include/link_defs.h b/include/link_defs.h
index 37049a36eb..a9bd0bcf9b 100644
--- a/include/link_defs.h
+++ b/include/link_defs.h
@@ -108,6 +108,13 @@ extern const void *__data_lma_start;
extern const void *__data_start;
extern const void *__data_end;
+/* DRAM image sections. */
+extern const void *__dram_data_lma_start;
+extern void *__dram_data_start;
+extern void *__dram_data_end;
+extern void *__dram_bss_start;
+extern void *__dram_bss_end;
+
/* Helper for special chip-specific memory sections */
#ifdef CONFIG_CHIP_MEMORY_REGIONS
#define __SECTION(name) __attribute__((section("." STRINGIFY(name) ".50_auto")))