Refs #476. Added evaluation of the len-parameter in functions FlashErase and FlashWrite of all ports.

git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@422 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
Frank Voorburg 2018-02-05 16:43:55 +00:00
parent 5528bcbac7
commit 59a909fca2
14 changed files with 206 additions and 3 deletions

View File

@ -43,6 +43,9 @@
#define FLASH_WRITE_BLOCK_SIZE (512) #define FLASH_WRITE_BLOCK_SIZE (512)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
/** \brief Entry address for the IAP algorithms, enabling a switch to thumb mode. */ /** \brief Entry address for the IAP algorithms, enabling a switch to thumb mode. */
#define IAP_ENTRY_ADDRESS (0x7ffffff1) #define IAP_ENTRY_ADDRESS (0x7ffffff1)
/** \brief IAP prepare sectos command code. */ /** \brief IAP prepare sectos command code. */
@ -276,6 +279,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -309,6 +318,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -44,6 +44,9 @@
#define FLASH_WRITE_BLOCK_SIZE (512) #define FLASH_WRITE_BLOCK_SIZE (512)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
#if (BOOT_NVM_SIZE_KB > 64) #if (BOOT_NVM_SIZE_KB > 64)
/** \brief Number of bytes to erase per erase operation. */ /** \brief Number of bytes to erase per erase operation. */
#define FLASH_ERASE_BLOCK_SIZE (0x800) #define FLASH_ERASE_BLOCK_SIZE (0x800)
@ -269,6 +272,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -302,6 +311,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -47,6 +47,9 @@
#define FLASH_WRITE_BLOCK_SIZE (256) #define FLASH_WRITE_BLOCK_SIZE (256)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
/** \brief Offset into the user program's vector table where the checksum is located. /** \brief Offset into the user program's vector table where the checksum is located.
* For this target it is set to the end of the vector table. Note that the * For this target it is set to the end of the vector table. Note that the
* value can be overriden in blt_conf.h, because the size of the vector table * value can be overriden in blt_conf.h, because the size of the vector table
@ -295,6 +298,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -328,6 +337,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -44,6 +44,9 @@
#define FLASH_WRITE_BLOCK_SIZE (512) #define FLASH_WRITE_BLOCK_SIZE (512)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
/** \brief Offset into the user program's vector table where the checksum is located. /** \brief Offset into the user program's vector table where the checksum is located.
* For this target it is set to the end of the vector table. Note that the * For this target it is set to the end of the vector table. Note that the
* value can be overriden in blt_conf.h, because the size of the vector table * value can be overriden in blt_conf.h, because the size of the vector table
@ -266,6 +269,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -299,6 +308,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -46,6 +46,9 @@
#define FLASH_WRITE_BLOCK_SIZE (512) #define FLASH_WRITE_BLOCK_SIZE (512)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
/** \brief Number of bytes to erase per erase operation. */ /** \brief Number of bytes to erase per erase operation. */
#define FLASH_ERASE_BLOCK_SIZE (0x400) #define FLASH_ERASE_BLOCK_SIZE (0x400)
/** \brief Offset into the user program's vector table where the checksum is located. /** \brief Offset into the user program's vector table where the checksum is located.
@ -267,6 +270,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -300,6 +309,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -43,6 +43,9 @@
#define FLASH_WRITE_BLOCK_SIZE (512) #define FLASH_WRITE_BLOCK_SIZE (512)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
#if (BOOT_NVM_SIZE_KB > 128) #if (BOOT_NVM_SIZE_KB > 128)
/** \brief Number of bytes to erase per erase operation. */ /** \brief Number of bytes to erase per erase operation. */
#define FLASH_ERASE_BLOCK_SIZE (0x800) #define FLASH_ERASE_BLOCK_SIZE (0x800)
@ -298,6 +301,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -331,6 +340,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -44,6 +44,9 @@
#define FLASH_WRITE_BLOCK_SIZE (512) #define FLASH_WRITE_BLOCK_SIZE (512)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
/** \brief Offset into the user program's vector table where the checksum is located. /** \brief Offset into the user program's vector table where the checksum is located.
* For this target it is set to the end of the vector table. Note that the * For this target it is set to the end of the vector table. Note that the
* value can be overriden in blt_conf.h, because the size of the vector table * value can be overriden in blt_conf.h, because the size of the vector table
@ -259,6 +262,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -292,6 +301,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -254,6 +254,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS)) if ((addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS))
{ {
@ -291,11 +297,17 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
FLASH_EraseInitTypeDef eraseInitStruct; FLASH_EraseInitTypeDef eraseInitStruct;
blt_bool result = BLT_TRUE; blt_bool result = BLT_TRUE;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* determine the base address for the erase operation, by aligning to /* determine the base address for the erase operation, by aligning to
* FLASH_ERASE_SECTOR_SIZE. * FLASH_ERASE_SECTOR_SIZE.
*/ */
erase_base_addr = (addr/FLASH_ERASE_SECTOR_SIZE)*FLASH_ERASE_SECTOR_SIZE; erase_base_addr = (addr/FLASH_ERASE_SECTOR_SIZE)*FLASH_ERASE_SECTOR_SIZE;
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((erase_base_addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS)) if ((erase_base_addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS))
{ {

View File

@ -45,6 +45,9 @@
#define FLASH_WRITE_BLOCK_SIZE (512) #define FLASH_WRITE_BLOCK_SIZE (512)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
/** \brief Offset into the user program's vector table where the checksum is located. /** \brief Offset into the user program's vector table where the checksum is located.
* For this target it is set to the end of the vector table. Note that the * For this target it is set to the end of the vector table. Note that the
* value can be overriden in blt_conf.h, because the size of the vector table * value can be overriden in blt_conf.h, because the size of the vector table
@ -282,6 +285,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -315,6 +324,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -30,7 +30,8 @@
* Include files * Include files
****************************************************************************************/ ****************************************************************************************/
#include "boot.h" /* bootloader generic header */ #include "boot.h" /* bootloader generic header */
#include "stm32l4xx.h" /* STM32 CPU and HAL header */ #include "stm32l4xx.h" /* STM32 CPU and HAL header */
/**************************************************************************************** /****************************************************************************************
@ -268,6 +269,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS)) if ((addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS))
{ {
@ -307,6 +314,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int32u dummy; blt_int32u dummy;
FLASH_EraseInitTypeDef eraseInitStruct; FLASH_EraseInitTypeDef eraseInitStruct;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* determine the base address for the erase operation, by aligning to /* determine the base address for the erase operation, by aligning to
* FLASH_ERASE_SECTOR_SIZE. * FLASH_ERASE_SECTOR_SIZE.
*/ */

View File

@ -48,6 +48,9 @@
#define FLASH_WRITE_BLOCK_SIZE (1024) #define FLASH_WRITE_BLOCK_SIZE (1024)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
/** \brief Number of bytes to erase per erase operation. */ /** \brief Number of bytes to erase per erase operation. */
#define FLASH_ERASE_BLOCK_SIZE (0x400) #define FLASH_ERASE_BLOCK_SIZE (0x400)
/** \brief Offset into the user program's vector table where the checksum is located. /** \brief Offset into the user program's vector table where the checksum is located.
@ -269,6 +272,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -302,6 +311,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -46,6 +46,9 @@
#define FLASH_WRITE_BLOCK_SIZE (1024) #define FLASH_WRITE_BLOCK_SIZE (1024)
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
/** \brief Offset into the user program's vector table where the checksum is located. /** \brief Offset into the user program's vector table where the checksum is located.
* For this target it is set to the end of the vector table. Note that the * For this target it is set to the end of the vector table. Note that the
* value can be overriden in blt_conf.h, because the size of the vector table * value can be overriden in blt_conf.h, because the size of the vector table
@ -281,6 +284,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/* automatically translate cached memory addresses to non-cached */ /* automatically translate cached memory addresses to non-cached */
addr = FlashTranslateToNonCachedAddress(addr); addr = FlashTranslateToNonCachedAddress(addr);
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -317,6 +326,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
/* automatically translate cached memory addresses to non-cached */ /* automatically translate cached memory addresses to non-cached */
addr = FlashTranslateToNonCachedAddress(addr); addr = FlashTranslateToNonCachedAddress(addr);
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);

View File

@ -444,11 +444,17 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
blt_addr base_addr; blt_addr base_addr;
blt_addr last_block_base_addr; blt_addr last_block_base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS)) if ((addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS))
{ {
return BLT_FALSE; return BLT_FALSE;
} }
/* determine the start address of the last block in flash */ /* determine the start address of the last block in flash */
last_block_base_addr = flashLayout[FLASH_LAST_SECTOR_IDX].sector_start + \ last_block_base_addr = flashLayout[FLASH_LAST_SECTOR_IDX].sector_start + \
@ -483,6 +489,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int32u total_erase_len; blt_int32u total_erase_len;
blt_int16u block_cnt; blt_int16u block_cnt;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* determine the base address for the erase operation, by aligning to /* determine the base address for the erase operation, by aligning to
* FLASH_ERASE_BLOCK_SIZE. * FLASH_ERASE_BLOCK_SIZE.
*/ */

View File

@ -48,6 +48,10 @@
/** \brief Total numbers of sectors in array flashLayout[]. */ /** \brief Total numbers of sectors in array flashLayout[]. */
#define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0])) #define FLASH_TOTAL_SECTORS (sizeof(flashLayout)/sizeof(flashLayout[0]))
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_TOTAL_SECTORS-1].sector_start + \
flashLayout[FLASH_TOTAL_SECTORS-1].sector_size - 1)
/** \brief The flash driver is setup to operate on the cached PFLASH addresses, whereas /** \brief The flash driver is setup to operate on the cached PFLASH addresses, whereas
* the actual PFLASH commands should operate on non-cached addresses. This * the actual PFLASH commands should operate on non-cached addresses. This
* macro defines the offset between cached (80xxxxxxh) and non-cached * macro defines the offset between cached (80xxxxxxh) and non-cached
@ -278,6 +282,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{ {
blt_addr base_addr; blt_addr base_addr;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* make sure the addresses are within the flash device */ /* make sure the addresses are within the flash device */
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \ if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR)) (FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
@ -311,6 +321,12 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int8u first_sector; blt_int8u first_sector;
blt_int8u last_sector; blt_int8u last_sector;
/* validate the len parameter */
if ((len - 1) > (FLASH_END_ADDRESS - addr))
{
return BLT_FALSE;
}
/* obtain the first and last sector number */ /* obtain the first and last sector number */
first_sector = FlashGetSector(addr); first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1); last_sector = FlashGetSector(addr+len-1);