Browse Source

Adding DFU check to validate that we aren't trying to flash too far

- Add _app_rom_end address location that points to the end of flash
- Check when flashing each page whether the end of the page exceeds the end of the flash
blockKey
Jacob Alexander 7 years ago
parent
commit
2f03f34877

+ 7
- 1
Bootloader/main.c View File

@@ -1,5 +1,5 @@
/* Copyright (c) 2011,2012 Simon Schubert <[email protected]>.
* Modifications by Jacob Alexander 2014-2015 <[email protected]>
* Modifications by Jacob Alexander 2014-2016 <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -141,9 +141,15 @@ static enum dfu_status setup_write( size_t off, size_t len, void **buf )
static enum dfu_status finish_write( void *buf, size_t off, size_t len )
{
void *target;

// If nothing left to flash, this is still ok
if ( len == 0 )
return (DFU_STATUS_OK);

// If the binary is larger than the internal flash, error
if ( off + (uintptr_t)&_app_rom + len > (uintptr_t)&_app_rom_end )
return (DFU_STATUS_errADDRESS);

target = flash_get_staging_area( off + (uintptr_t)&_app_rom, USB_DFU_TRANSFER_SIZE );
if ( !target )
return (DFU_STATUS_errADDRESS);

+ 7
- 5
Lib/mk20dx128vlf5.bootloader.ld View File

@@ -1,7 +1,7 @@
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
* Modifications by Jacob Alexander 2014 for use with McHCK
* Modifications by Jacob Alexander 2014,2016 for use with McHCK
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -31,13 +31,15 @@

MEMORY
{
FLASH (rx) : ORIGIN = 0x0, LENGTH = 128K
FLASH_APP (rx) : ORIGIN = 4K, LENGTH = 128K-4K
RAM (rwx) : ORIGIN = 0x20000000 - 16K / 2, LENGTH = 16K
FLASH (rx) : ORIGIN = 0x0, LENGTH = 128K
FLASH_APP (rx) : ORIGIN = 4K, LENGTH = 128K - 4K
RAM (rwx) : ORIGIN = 0x20000000 - 16K / 2, LENGTH = 16K
}

/* Starting Address of the application ROM */
_app_rom = ORIGIN( FLASH_APP );
_bootloader = ORIGIN( FLASH );
_app_rom = ORIGIN( FLASH_APP );
_app_rom_end = ORIGIN( FLASH ) + LENGTH( FLASH );

FlexRAM = 0x14000000;
FTFL = 0x40020000;

+ 6
- 2
Lib/mk20dx128vlf5.ld View File

@@ -1,7 +1,7 @@
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
* Modifications by Jacob Alexander 2014 for use with McHCK
* Modifications by Jacob Alexander 2014,2016 for use with McHCK
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -31,10 +31,14 @@

MEMORY
{
FLASH (rx) : ORIGIN = 4K, LENGTH = 128K-4K
FLASH (rx) : ORIGIN = 4K, LENGTH = 128K - 4K
RAM (rwx) : ORIGIN = 0x20000000 - 16K / 2, LENGTH = 16K
}

/* Starting Address of the application ROM */
_app_rom = ORIGIN( FLASH );
_app_rom_end = ORIGIN( FLASH ) + LENGTH( FLASH );

/* Section Definitions */
SECTIONS
{

+ 7
- 6
Lib/mk20dx256vlh7.bootloader.ld View File

@@ -1,7 +1,7 @@
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
* Modifications by Jacob Alexander 2014-2015 for use with McHCK and Kiibohd-dfu
* Modifications by Jacob Alexander 2014-2016 for use with McHCK and Kiibohd-dfu
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -31,14 +31,15 @@

MEMORY
{
FLASH (rx) : ORIGIN = 0x0, LENGTH = 256K
FLASH_APP (rx) : ORIGIN = 8K, LENGTH = 256K-8K
RAM (rwx) : ORIGIN = 0x20000000 - 64K / 2, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x0, LENGTH = 256K
FLASH_APP (rx) : ORIGIN = 8K, LENGTH = 256K - 8K
RAM (rwx) : ORIGIN = 0x20000000 - 64K / 2, LENGTH = 64K
}

/* Starting Address of the application ROM */
_bootloader = ORIGIN( FLASH );
_app_rom = ORIGIN( FLASH_APP );
_bootloader = ORIGIN( FLASH );
_app_rom = ORIGIN( FLASH_APP );
_app_rom_end = ORIGIN( FLASH ) + LENGTH( FLASH );

FlexRAM = 0x14000000;
FTFL = 0x40020000;

+ 6
- 2
Lib/mk20dx256vlh7.ld View File

@@ -1,7 +1,7 @@
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2013 PJRC.COM, LLC.
* Modifications by Jacob Alexander 2014-2015 for use with McHCK and Kiibohd-dfu
* Modifications by Jacob Alexander 2014-2016 for use with McHCK and Kiibohd-dfu
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -31,10 +31,14 @@

MEMORY
{
FLASH (rx) : ORIGIN = 8K, LENGTH = 256K-8K
FLASH (rx) : ORIGIN = 8K, LENGTH = 256K - 8K
RAM (rwx) : ORIGIN = 0x20000000 - 64K / 2, LENGTH = 64K
}

/* Starting Address of the application ROM */
_app_rom = ORIGIN( FLASH );
_app_rom_end = ORIGIN( FLASH ) + LENGTH( FLASH );

/* Section Definitions */
SECTIONS
{