[U-Boot] [PATCH v2 3/4] api: FreeBSD: flush cache before starting loader/kernel

Emmanuel Vadot manu at bidouilliste.com
Tue Jan 17 16:50:18 CET 2017


From: Warner Losh <imp at freebsd.org>

FreeBSD loader(8) just loaded code to some random location that may
contain stale icache entries.
FreeBSD Kernel needs the icache and dcache flushed.
Before running either one of them, flush the icache and dcache.

Signed-off-by: Emmanuel Vadot <manu at bidouilliste.com>
---
 api/api.c  | 5 +++++
 cmd/boot.c | 5 +++++
 cmd/elf.c  | 8 +++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/api/api.c b/api/api.c
index 8a1433af78..cc25deca09 100644
--- a/api/api.c
+++ b/api/api.c
@@ -290,6 +290,11 @@ static int API_dev_close(va_list ap)
 	if (!err)
 		di->state = DEV_STA_CLOSED;
 
+#ifdef CONFIG_FREEBSD
+	flush_dcache_all();
+	invalidate_icache_all();
+#endif
+
 	return err;
 }
 
diff --git a/cmd/boot.c b/cmd/boot.c
index 72f2cf362d..a1a91fbf0a 100644
--- a/cmd/boot.c
+++ b/cmd/boot.c
@@ -19,6 +19,11 @@ __attribute__((weak))
 unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc,
 				 char * const argv[])
 {
+#ifdef CONFIG_FREEBSD
+	flush_dcache_all();
+	invalidate_icache_all();
+#endif
+
 	return entry (argc, argv);
 }
 
diff --git a/cmd/elf.c b/cmd/elf.c
index 5190cc6c0f..b2827fa042 100644
--- a/cmd/elf.c
+++ b/cmd/elf.c
@@ -109,6 +109,7 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
 {
 	unsigned long ret;
 
+#ifndef CONFIG_FREEBSD
 	/*
 	 * QNX images require the data cache is disabled.
 	 * Data cache is already flushed, so just turn it off.
@@ -116,15 +117,20 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
 	int dcache = dcache_status();
 	if (dcache)
 		dcache_disable();
-
+#else
+	flush_dcache_all();
+	invalidate_icache_all();
+#endif
 	/*
 	 * pass address parameter as argv[0] (aka command name),
 	 * and all remaining args
 	 */
 	ret = entry(argc, argv);
 
+#ifndef CONFIG_FREEBSD
 	if (dcache)
 		dcache_enable();
+#endif
 
 	return ret;
 }
-- 
2.11.0



More information about the U-Boot mailing list