bootloader: add capability to override advertised flash size
This commit is contained in:
parent
c0c6b8f0af
commit
f05ab20021
|
@ -1,6 +1,6 @@
|
|||
/* linker script for application running on STM32F103x8 micro-controller
|
||||
* the STM32F103xC has 256kB of flash starting at 0x0800 0000, and 20kB of RAM starting at 0x2000 0000
|
||||
* the USB DFU bootloader will take the first 8 kB of flash, followed by the application
|
||||
* the STM32F103xC has 256 KB of flash starting at 0x0800 0000, and 20 KB of RAM starting at 0x2000 0000
|
||||
* the USB DFU bootloader will take the first 8 KB of flash, followed by the application
|
||||
*/
|
||||
|
||||
/* Define memory regions. */
|
||||
|
@ -10,7 +10,11 @@ MEMORY
|
|||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
PROVIDE(__application_beginning = ORIGIN(rom));
|
||||
/* only provide application end if you want to force a flash size
|
||||
i.e. STM32F103x8 most often have if fact 128 KB instead of the specified and advertised 64 KB
|
||||
PROVIDE(__application_end = ORIGIN(rom) + LENGTH(rom));
|
||||
PROVIDE(__flash_end = ORIGIN(rom) + LENGTH(rom));
|
||||
*/
|
||||
|
||||
/* include rest of the definitions for the STM32F1 family */
|
||||
INCLUDE libopencm3_stm32f1.ld
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* linker script for application running on STM32F103x8 micro-controller
|
||||
* the STM32F103xC has 256kB of flash starting at 0x0800 0000, and 20kB of RAM starting at 0x2000 0000
|
||||
* the USB DFU bootloader will take the first 8 kB of flash, followed by the application
|
||||
* the STM32F103xC has 256 KB of flash starting at 0x0800 0000, and 20 KB of RAM starting at 0x2000 0000
|
||||
* the USB DFU bootloader will take the first 8 KB of flash, followed by the application
|
||||
*/
|
||||
|
||||
/* Define memory regions. */
|
||||
|
@ -10,7 +10,11 @@ MEMORY
|
|||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
||||
PROVIDE(__application_beginning = ORIGIN(rom) + LENGTH(rom));
|
||||
/* only provide application end if you want to force a flash size
|
||||
i.e. STM32F103x8 most often have if fact 128 KB instead of the specified and advertised 64 KB
|
||||
PROVIDE(__application_end = __application_beginning + 248K);
|
||||
PROVIDE(__flash_end = __application_beginning + 248K);
|
||||
*/
|
||||
|
||||
/* include rest of the definitions for the STM32F1 family */
|
||||
INCLUDE libopencm3_stm32f1.ld
|
||||
|
|
|
@ -34,8 +34,18 @@
|
|||
|
||||
bool flash_internal_read(uint32_t address, uint8_t *buffer, size_t size)
|
||||
{
|
||||
// verify it's in the flash area and do other sanity checks
|
||||
if (address<FLASH_BASE || address>(UINT32_MAX-size) || (address+size)>(FLASH_BASE+DESIG_FLASH_SIZE*1024) || buffer==NULL || size==0) {
|
||||
// sanity checks
|
||||
if (address<FLASH_BASE || address>(UINT32_MAX-size) || buffer==NULL || size==0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// verify if it's in the flash area
|
||||
#if defined(__flash_end)
|
||||
if (address<FLASH_BASE || (address+size)>(uint32_t)&__flash_end)
|
||||
#else
|
||||
if (address<FLASH_BASE || (address+size)>(FLASH_BASE+DESIG_FLASH_SIZE*1024))
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -49,8 +59,18 @@ bool flash_internal_read(uint32_t address, uint8_t *buffer, size_t size)
|
|||
|
||||
bool flash_internal_write(uint32_t address, uint8_t *buffer, size_t size)
|
||||
{
|
||||
// verify it's in the flash area and do other sanity checks
|
||||
if (address<FLASH_BASE || address>(UINT32_MAX-size) || (address+size)>(FLASH_BASE+DESIG_FLASH_SIZE*1024) || buffer==NULL || size==0 || size%2) {
|
||||
// sanity checks
|
||||
if (address<FLASH_BASE || address>(UINT32_MAX-size) || buffer==NULL || size==0 || size%2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// verify if it's in the flash area
|
||||
#if defined(__flash_end)
|
||||
if (address<FLASH_BASE || (address+size)>(uint32_t)&__flash_end)
|
||||
#else
|
||||
if (address<FLASH_BASE || (address+size)>(FLASH_BASE+DESIG_FLASH_SIZE*1024))
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <libopencm3/cm3/scb.h> // reset utilities
|
||||
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
||||
#include <libopencm3/stm32/gpio.h> // general purpose input output library
|
||||
#include <libopencm3/stm32/desig.h> // flash size definition
|
||||
#include <libopencm3/usb/usbd.h> // USB library
|
||||
#include <libopencm3/usb/dfu.h> // USB DFU library
|
||||
|
||||
|
@ -223,7 +224,11 @@ static int usb_dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data
|
|||
// we can only write half words
|
||||
usb_dfu_status = DFU_STATUS_ERR_PROG;
|
||||
usb_dfu_state = STATE_DFU_ERROR;
|
||||
#if defined(__application_end)
|
||||
} else if (flash_pointer+*len>=(uint32_t)&__application_end) {
|
||||
#else
|
||||
} else if (flash_pointer+*len>=(uint32_t)(FLASH_BASE+DESIG_FLASH_SIZE*1024)) {
|
||||
#endif
|
||||
// application data is too large
|
||||
usb_dfu_status = DFU_STATUS_ERR_ADDRESS;
|
||||
usb_dfu_state = STATE_DFU_ERROR;
|
||||
|
|
Loading…
Reference in New Issue