From 47327c39c9379bc5fa71d607ac09e3a7f6d58d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 21 Mar 2019 13:58:27 +0100 Subject: [PATCH] [ion] DFU reallocation: clean DCache after copying the DFU bootloader to the RAM --- ion/src/device/shared/usb/Makefile | 1 + ion/src/device/shared/usb/dfu_relocated.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ion/src/device/shared/usb/Makefile b/ion/src/device/shared/usb/Makefile index fd26a27a7..7c77dff0d 100644 --- a/ion/src/device/shared/usb/Makefile +++ b/ion/src/device/shared/usb/Makefile @@ -47,6 +47,7 @@ dfu_src += liba/src/memset.c dfu_src += liba/src/memcpy.c dfu_src += libaxx/src/cxxabi/pure_virtual.cpp dfu_src += ion/src/device/shared/usb/boot.cpp +dfu_src += ion/src/device/$(MODEL)/drivers/cache.cpp dfu_src += $(addprefix ion/src/device/shared/drivers/, \ base64.cpp \ external_flash.cpp \ diff --git a/ion/src/device/shared/usb/dfu_relocated.cpp b/ion/src/device/shared/usb/dfu_relocated.cpp index a190e6786..f39a1313f 100644 --- a/ion/src/device/shared/usb/dfu_relocated.cpp +++ b/ion/src/device/shared/usb/dfu_relocated.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "../drivers/timing.h" extern char _stack_end; @@ -47,6 +48,12 @@ void DFU() { /* 3- Copy the DFU bootloader from Flash to RAM. */ memcpy(dfu_bootloader_ram_start, &_dfu_bootloader_flash_start, dfu_bootloader_size); + /* The DFU bootloader might have been copied in the DCache. However, when we + * run the instructions from the DFU bootloader, the CPU looks for + * instructions in the ICache and then in the RAM. We thus need to flush the + * DCache to update the RAM. */ + // Flush data cache + Device::Cache::cleanDCache(); /* 4- Disable all interrupts * The interrupt service routines live in the Flash and could be overwritten