Skip to contentSkip to conversation

cmd: bootelf: Flush cache before starting

PATCH New Emmanuel Vadot 1 participant 1 message Apr 30, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 5/5 cmd: bootelf: Flush cache before starting

Some application might load some code at location that contain stale cache entries. Before running a elf or raw binary, flush the caches if they are enabled.

---
 cmd/elf.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
cmd/elf.c +11 -0
index 5b59fc6329..f372306de5 100644
@@ -109,6 +109,17 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
 {
 	unsigned long ret;
 
+#if defined(CONFIG_SYS_HAVE_DCACHE_MAINTENANCE) && \
+	!defined(CONFIG_SYS_DCACHE_OFF)
+	if (dcache_status())
+		flush_dcache_all();
+#endif
+#if defined(CONFIG_SYS_HAVE_ICACHE_MAINTENANCE) && \
+	!defined(CONFIG_SYS_ICACHE_OFF)
+	if (icache_status())
+		invalidate_icache_all();
+#endif
+
 	/*
 	 * pass address parameter as argv[0] (aka command name),
 	 * and all remaining args
Signature · 1 line
2.16.3