Message ID | 20170126164612.86684-4-manu@bidouilliste.com |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show |
On Thu, Jan 26, 2017 at 05:46:11PM +0100, Emmanuel Vadot wrote: > From: Warner Losh <imp@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. This could probably be expanded to note that in general it's just always a good idea to flush icache/dcache prior to running whatever we're about to run. This isn't so much a FreeBSD thing as a generic thing. > Signed-off-by: Emmanuel Vadot <manu@bidouilliste.com> Reviewed-by: Tom Rini <trini@konsulko.com>
diff --git a/api/api.c b/api/api.c index c368511704..88b5df77c0 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; + if (dcache_status()) + flush_dcache_all(); + if (icache_status()) + invalidate_icache_all(); + return err; } diff --git a/cmd/boot.c b/cmd/boot.c index 72f2cf362d..b66ae67fcb 100644 --- a/cmd/boot.c +++ b/cmd/boot.c @@ -19,6 +19,10 @@ __attribute__((weak)) unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, char * const argv[]) { + if (dcache_status()) + flush_dcache_all(); + if (icache_status()) + invalidate_icache_all(); return entry (argc, argv); } diff --git a/cmd/elf.c b/cmd/elf.c index e4c6535111..e98a798203 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -109,6 +109,11 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), { unsigned long ret; + if (dcache_status()) + flush_dcache_all(); + if (icache_status()) + invalidate_icache_all(); + /* * pass address parameter as argv[0] (aka command name), * and all remaining args