From eab505d95ce7b2afacac4bcee282dbbbe23269b9 Mon Sep 17 00:00:00 2001 From: Frank Voorburg Date: Mon, 23 Apr 2018 12:54:57 +0000 Subject: [PATCH] Refs #520. Updated BootCommander to perform erase operation in steps of 32kb. git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@481 5dc33758-31d5-4daf-9ae8-b24bf3d40d73 --- Doc/doxygen/DoxyfileBootCommander | 2 +- Host/Source/BootCommander/main.c | 50 +++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Doc/doxygen/DoxyfileBootCommander b/Doc/doxygen/DoxyfileBootCommander index a79e3411..327866fd 100644 --- a/Doc/doxygen/DoxyfileBootCommander +++ b/Doc/doxygen/DoxyfileBootCommander @@ -38,7 +38,7 @@ PROJECT_NAME = "BootCommander - Reference Manual" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.3.0 +PROJECT_NUMBER = 1.4.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/Host/Source/BootCommander/main.c b/Host/Source/BootCommander/main.c index 41520928..26af01fe 100644 --- a/Host/Source/BootCommander/main.c +++ b/Host/Source/BootCommander/main.c @@ -298,12 +298,51 @@ int main(int argc, char const * const argv[]) if ((segmentData != NULL) && (segmentLen > 0)) /*lint !e774 */ { /* Perform erase operation. */ - printf("Erasing %u bytes starting at 0x%08x...", segmentLen, segmentBase); + printf("Erasing %u bytes starting at 0x%08x...%s", segmentLen, segmentBase, + GetLineTrailerByPercentage(0)); (void)fflush(stdout); - if (BltSessionClearMemory(segmentBase, segmentLen) != BLT_RESULT_OK) + /* Perform erase operation in chunks, so that a progress update can be shown + * and no erase timeout occurs due to erasing too big of a memory range. + */ + uint32_t const eraseChunkSize = 32768; + uint32_t currentEraseCnt; + uint32_t currentEraseBase; + uint32_t currentEraseResult; + uint32_t stillToEraseCnt; + + stillToEraseCnt = segmentLen; + currentEraseBase = segmentBase; + while (stillToEraseCnt > 0) { - /* Set error code. */ - result = RESULT_ERROR_MEMORY_ERASE; + /* Determine chunk size. */ + if (stillToEraseCnt >= eraseChunkSize) + { + currentEraseCnt = eraseChunkSize; + } + else + { + currentEraseCnt = stillToEraseCnt; + } + /* Erase the next chunk from the target's memory. */ + currentEraseResult = BltSessionClearMemory(currentEraseBase, currentEraseCnt); + if (currentEraseResult != BLT_RESULT_OK) + { + /* Set error code. */ + result = RESULT_ERROR_MEMORY_ERASE; + /* Error detected so abort erase operation. */ + break; + } + /* Update loop variables. */ + currentEraseBase += currentEraseCnt; + stillToEraseCnt -= currentEraseCnt; + /* Display progress. */ + uint8_t progressPct; + + /* First backspace the old percentage trailer. */ + ErasePercentageTrailer(); + /* Now add the new percentage trailer. */ + progressPct = (uint8_t)(((segmentLen - stillToEraseCnt) * 100ul) / segmentLen); + printf("%s", GetLineTrailerByPercentage(progressPct)); (void)fflush(stdout); } } else @@ -311,6 +350,7 @@ int main(int argc, char const * const argv[]) /* Set error code because sanity check failed. */ result = RESULT_ERROR_MEMORY_ERASE; } + ErasePercentageTrailer(); printf("%s\n", GetLineTrailerByResult((bool)(result != RESULT_OK))); /* Do not continue loop if an error was detected. */ if (result != RESULT_OK) @@ -431,7 +471,7 @@ int main(int argc, char const * const argv[]) static void DisplayProgramInfo(void) { printf("--------------------------------------------------------------------------\n"); - printf("BootCommander version 1.03. Performs firmware updates on a microcontroller\n"); + printf("BootCommander version 1.04. Performs firmware updates on a microcontroller\n"); printf("based system that runs the OpenBLT bootloader.\n\n"); printf("Copyright (c) 2017 by Feaser http://www.feaser.com\n"); printf("-------------------------------------------------------------------------\n");