From 33e35e1c2219c36f98a37e9ca9598cc075a865f1 Mon Sep 17 00:00:00 2001 From: Frank Voorburg Date: Thu, 19 Jan 2012 13:21:10 +0000 Subject: [PATCH] - Fixed bug where the checksum was incorrectly programmed during a programming sequence that doesn't include data for the bootblock. git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@21 5dc33758-31d5-4daf-9ae8-b24bf3d40d73 --- Target/Source/ARM7_LPC2000/Crossworks/flash.c | 19 +++++++++---------- Target/Source/ARM7_LPC2000/GCC/flash.c | 19 +++++++++---------- Target/Source/ARMCM3_STM32/flash.c | 19 +++++++++---------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Target/Source/ARM7_LPC2000/Crossworks/flash.c b/Target/Source/ARM7_LPC2000/Crossworks/flash.c index f8fe1ab7..dc311ba2 100644 --- a/Target/Source/ARM7_LPC2000/Crossworks/flash.c +++ b/Target/Source/ARM7_LPC2000/Crossworks/flash.c @@ -297,6 +297,15 @@ blt_bool FlashWriteChecksum(void) * signature_checksum = Two's complement of (SUM(exception address values)) */ + /* first check that the bootblock contains valid data. if not, this means the + * bootblock is not part of the reprogramming this time and therefore no + * new checksum needs to be written + */ + if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS) + { + return BLT_TRUE; + } + /* compute the checksum. note that the user program's vectors are not yet written * to flash but are present in the bootblock data structure at this point. */ @@ -310,16 +319,6 @@ blt_bool FlashWriteChecksum(void) signature_checksum = ~signature_checksum; /* one's complement */ signature_checksum += 1; /* two's complement */ - /* check that this value of the checksum is not already present, which means - * the program area with the vector table was not programmed, so the checksum - * also doesn't need to be written. this check is important because it allows - * for additional data to be programmed, such as calibration parameters, in - * which case the checksum doesn't not need to be rewritten - */ - if (signature_checksum == FlashVerifyChecksum()) - { - return BLT_TRUE; - } /* write the checksum */ return FlashWrite(flashLayout[0].sector_start+0x14, sizeof(blt_addr), (blt_int8u*)&signature_checksum); diff --git a/Target/Source/ARM7_LPC2000/GCC/flash.c b/Target/Source/ARM7_LPC2000/GCC/flash.c index f8fe1ab7..dc311ba2 100644 --- a/Target/Source/ARM7_LPC2000/GCC/flash.c +++ b/Target/Source/ARM7_LPC2000/GCC/flash.c @@ -297,6 +297,15 @@ blt_bool FlashWriteChecksum(void) * signature_checksum = Two's complement of (SUM(exception address values)) */ + /* first check that the bootblock contains valid data. if not, this means the + * bootblock is not part of the reprogramming this time and therefore no + * new checksum needs to be written + */ + if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS) + { + return BLT_TRUE; + } + /* compute the checksum. note that the user program's vectors are not yet written * to flash but are present in the bootblock data structure at this point. */ @@ -310,16 +319,6 @@ blt_bool FlashWriteChecksum(void) signature_checksum = ~signature_checksum; /* one's complement */ signature_checksum += 1; /* two's complement */ - /* check that this value of the checksum is not already present, which means - * the program area with the vector table was not programmed, so the checksum - * also doesn't need to be written. this check is important because it allows - * for additional data to be programmed, such as calibration parameters, in - * which case the checksum doesn't not need to be rewritten - */ - if (signature_checksum == FlashVerifyChecksum()) - { - return BLT_TRUE; - } /* write the checksum */ return FlashWrite(flashLayout[0].sector_start+0x14, sizeof(blt_addr), (blt_int8u*)&signature_checksum); diff --git a/Target/Source/ARMCM3_STM32/flash.c b/Target/Source/ARMCM3_STM32/flash.c index f137e1ca..e0e554ad 100644 --- a/Target/Source/ARMCM3_STM32/flash.c +++ b/Target/Source/ARMCM3_STM32/flash.c @@ -317,6 +317,15 @@ blt_bool FlashWriteChecksum(void) * checksum. */ + /* first check that the bootblock contains valid data. if not, this means the + * bootblock is not part of the reprogramming this time and therefore no + * new checksum needs to be written + */ + if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS) + { + return BLT_TRUE; + } + /* compute the checksum. note that the user program's vectors are not yet written * to flash but are present in the bootblock data structure at this point. */ @@ -330,16 +339,6 @@ blt_bool FlashWriteChecksum(void) signature_checksum = ~signature_checksum; /* one's complement */ signature_checksum += 1; /* two's complement */ - /* check that this value of the checksum is not already present, which means - * the program area with the vector table was not programmed, so the checksum - * also doesn't need to be written. this check is important because it allows - * for additional data to be programmed, such as calibration parameters, in - * which case the checksum doesn't not need to be rewritten - */ - if (signature_checksum == FlashVerifyChecksum()) - { - return BLT_TRUE; - } /* write the checksum */ return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET, sizeof(blt_addr), (blt_int8u*)&signature_checksum);