flash write range check

This commit is contained in:
NIIBE Yutaka
2012-05-28 13:00:58 +09:00
parent ba8609be41
commit 1576b8303e
2 changed files with 10 additions and 2 deletions

View File

@@ -4,6 +4,7 @@
* boards/common/hwinit.c (hwinit0): ... and define here.
(hwinit0) [DFU_SUPPORT]: Don't set SCB->VTOR here.
* src/sys.c (reset) [DFU_SUPPORT]: Set SCB->VTOR here.
(flash_write): Range check.
* polarssl-0.14.0/library/aes.c (FT0, FT1, FT2): Specify the
section ".sys", so that we will have more room for flash ROM.

View File

@@ -4,6 +4,10 @@
#include "board.h"
#include "usb_lld.h"
extern uint8_t __flash_start__, __flash_end__;
extern uint8_t _regnual_start;
static const uint8_t *
unique_device_id (void)
{
@@ -126,6 +130,11 @@ static int
flash_write (uint32_t dst_addr, const uint8_t *src, size_t len)
{
int status;
uint32_t flash_start = (uint32_t)&__flash_start__;
uint32_t flash_end = (uint32_t)&__flash_end__;
if (dst_addr < flash_start || dst_addr + len > flash_end)
return 0;
while (len)
{
@@ -174,8 +183,6 @@ flash_protect (void)
return (option_bytes_value & 0xff) == 0xff ? 1 : 0;
}
extern uint8_t __flash_start__, __flash_end__;
extern uint8_t _regnual_start;
static void __attribute__((naked))
flash_mass_erase_and_exec (void)