aboutsummaryrefslogtreecommitdiffstats
path: root/Bootloaders/DFU
diff options
context:
space:
mode:
Diffstat (limited to 'Bootloaders/DFU')
-rw-r--r--Bootloaders/DFU/BootloaderAPI.c43
-rw-r--r--Bootloaders/DFU/BootloaderAPI.h5
-rw-r--r--Bootloaders/DFU/BootloaderAPITable.S4
-rw-r--r--Bootloaders/DFU/BootloaderDFU.c39
-rw-r--r--Bootloaders/DFU/BootloaderDFU.h4
-rw-r--r--Bootloaders/DFU/Config/AppConfig.h4
-rw-r--r--Bootloaders/DFU/Config/LUFAConfig.h4
-rw-r--r--Bootloaders/DFU/Descriptors.c5
-rw-r--r--Bootloaders/DFU/Descriptors.h4
-rw-r--r--Bootloaders/DFU/makefile2
10 files changed, 61 insertions, 53 deletions
diff --git a/Bootloaders/DFU/BootloaderAPI.c b/Bootloaders/DFU/BootloaderAPI.c
index 491c506d0..21d13bbe3 100644
--- a/Bootloaders/DFU/BootloaderAPI.c
+++ b/Bootloaders/DFU/BootloaderAPI.c
@@ -1,13 +1,13 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2019.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
@@ -35,18 +35,39 @@
#include "BootloaderAPI.h"
+static bool IsPageAddressValid(const uint32_t Address)
+{
+ /* Determine if the given page address is correctly aligned to the
+ start of a flash page. */
+ bool PageAddressIsAligned = !(Address & (SPM_PAGESIZE - 1));
+
+ return (Address < BOOT_START_ADDR) && PageAddressIsAligned;
+}
+
void BootloaderAPI_ErasePage(const uint32_t Address)
{
- boot_page_erase_safe(Address);
- boot_spm_busy_wait();
- boot_rww_enable();
+ if (! IsPageAddressValid(Address))
+ return;
+
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+ {
+ boot_page_erase_safe(Address);
+ boot_spm_busy_wait();
+ boot_rww_enable();
+ }
}
void BootloaderAPI_WritePage(const uint32_t Address)
{
- boot_page_write_safe(Address);
- boot_spm_busy_wait();
- boot_rww_enable();
+ if (! IsPageAddressValid(Address))
+ return;
+
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+ {
+ boot_page_write_safe(Address);
+ boot_spm_busy_wait();
+ boot_rww_enable();
+ }
}
void BootloaderAPI_FillWord(const uint32_t Address, const uint16_t Word)
@@ -71,6 +92,8 @@ uint8_t BootloaderAPI_ReadLock(void)
void BootloaderAPI_WriteLock(const uint8_t LockBits)
{
- boot_lock_bits_set_safe(LockBits);
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+ {
+ boot_lock_bits_set_safe(LockBits);
+ }
}
-
diff --git a/Bootloaders/DFU/BootloaderAPI.h b/Bootloaders/DFU/BootloaderAPI.h
index 5169bbc3c..d00645b5a 100644
--- a/Bootloaders/DFU/BootloaderAPI.h
+++ b/Bootloaders/DFU/BootloaderAPI.h
@@ -1,13 +1,13 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2019.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
@@ -39,6 +39,7 @@
/* Includes: */
#include <avr/io.h>
#include <avr/boot.h>
+ #include <util/atomic.h>
#include <stdbool.h>
#include <LUFA/Common/Common.h>
diff --git a/Bootloaders/DFU/BootloaderAPITable.S b/Bootloaders/DFU/BootloaderAPITable.S
index 95fd8e5c3..24208fb6c 100644
--- a/Bootloaders/DFU/BootloaderAPITable.S
+++ b/Bootloaders/DFU/BootloaderAPITable.S
@@ -1,13 +1,13 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2019.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c
index 928cf6fe3..10396f012 100644
--- a/Bootloaders/DFU/BootloaderDFU.c
+++ b/Bootloaders/DFU/BootloaderDFU.c
@@ -1,13 +1,13 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2019.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
@@ -133,7 +133,7 @@ void Application_Jump_Check(void)
JTAG_ENABLE();
#else
/* Check if the device's BOOTRST fuse is set */
- if (boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS) & FUSE_BOOTRST)
+ if (!(BootloaderAPI_ReadFuse(GET_HIGH_FUSE_BITS) & ~FUSE_BOOTRST))
{
/* If the reset source was not an external reset or the key is correct, clear it and jump to the application */
//if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY))
@@ -209,6 +209,9 @@ int main(void)
#endif
}
+ /* Wait a short time to end all USB transactions and then disconnect */
+ _delay_us(1000);
+
/* Reset configured hardware back to their original states for the user application */
ResetHardware();
@@ -383,7 +386,7 @@ void EVENT_USB_Device_ControlRequest(void)
}
/* Write the next word into the current flash page */
- boot_page_fill(CurrFlashAddress.Long, Endpoint_Read_16_LE());
+ BootloaderAPI_FillWord(CurrFlashAddress.Long, Endpoint_Read_16_LE());
/* Adjust counters */
WordsInFlashPage += 1;
@@ -393,8 +396,7 @@ void EVENT_USB_Device_ControlRequest(void)
if ((WordsInFlashPage == (SPM_PAGESIZE >> 1)) || !(WordsRemaining))
{
/* Commit the flash page to memory */
- boot_page_write(CurrFlashPageStartAddress);
- boot_spm_busy_wait();
+ BootloaderAPI_WritePage(CurrFlashPageStartAddress);
/* Check if programming incomplete */
if (WordsRemaining)
@@ -403,17 +405,13 @@ void EVENT_USB_Device_ControlRequest(void)
WordsInFlashPage = 0;
/* Erase next page's temp buffer */
- boot_page_erase(CurrFlashAddress.Long);
- boot_spm_busy_wait();
+ BootloaderAPI_ErasePage(CurrFlashAddress.Long);
}
}
}
/* Once programming complete, start address equals the end address */
StartAddr = EndAddr;
-
- /* Re-enable the RWW section of flash */
- boot_rww_enable();
}
else // Write EEPROM
{
@@ -723,8 +721,7 @@ static void ProcessMemProgCommand(void)
} CurrFlashAddress = {.Words = {StartAddr, Flash64KBPage}};
/* Erase the current page's temp buffer */
- boot_page_erase(CurrFlashAddress.Long);
- boot_spm_busy_wait();
+ BootloaderAPI_ErasePage(CurrFlashAddress.Long);
}
/* Set the state so that the next DNLOAD requests reads in the firmware */
@@ -821,21 +818,9 @@ static void ProcessWriteCommand(void)
}
else if (IS_TWOBYTE_COMMAND(SentCommand.Data, 0x00, 0xFF)) // Erase flash
{
- uint32_t CurrFlashAddress = 0;
-
/* Clear the application section of flash */
- while (CurrFlashAddress < (uint32_t)BOOT_START_ADDR)
- {
- boot_page_erase(CurrFlashAddress);
- boot_spm_busy_wait();
- boot_page_write(CurrFlashAddress);
- boot_spm_busy_wait();
-
- CurrFlashAddress += SPM_PAGESIZE;
- }
-
- /* Re-enable the RWW section of flash as writing to the flash locks it out */
- boot_rww_enable();
+ for (uint32_t CurrFlashAddress = 0; CurrFlashAddress < (uint32_t)BOOT_START_ADDR; CurrFlashAddress += SPM_PAGESIZE)
+ BootloaderAPI_ErasePage(CurrFlashAddress);
/* Memory has been erased, reset the security bit so that programming/reading is allowed */
IsSecure = false;
diff --git a/Bootloaders/DFU/BootloaderDFU.h b/Bootloaders/DFU/BootloaderDFU.h
index a97ba6c7e..bef122c72 100644
--- a/Bootloaders/DFU/BootloaderDFU.h
+++ b/Bootloaders/DFU/BootloaderDFU.h
@@ -1,13 +1,13 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2019.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
diff --git a/Bootloaders/DFU/Config/AppConfig.h b/Bootloaders/DFU/Config/AppConfig.h
index 3acf33c7e..db580c2b4 100644
--- a/Bootloaders/DFU/Config/AppConfig.h
+++ b/Bootloaders/DFU/Config/AppConfig.h
@@ -1,13 +1,13 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2019.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
diff --git a/Bootloaders/DFU/Config/LUFAConfig.h b/Bootloaders/DFU/Config/LUFAConfig.h
index 59ae519e4..cbe773b42 100644
--- a/Bootloaders/DFU/Config/LUFAConfig.h
+++ b/Bootloaders/DFU/Config/LUFAConfig.h
@@ -1,13 +1,13 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2019.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
diff --git a/Bootloaders/DFU/Descriptors.c b/Bootloaders/DFU/Descriptors.c
index 6b7b6d490..37c36dcc3 100644
--- a/Bootloaders/DFU/Descriptors.c
+++ b/Bootloaders/DFU/Descriptors.c
@@ -1,13 +1,13 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2019.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
@@ -182,4 +182,3 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
*DescriptorAddress = Address;
return Size;
}
-
diff --git a/Bootloaders/DFU/Descriptors.h b/Bootloaders/DFU/Descriptors.h
index 5487f88f3..d70b477dc 100644
--- a/Bootloaders/DFU/Descriptors.h
+++ b/Bootloaders/DFU/Descriptors.h
@@ -1,13 +1,13 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2017.
+ Copyright (C) Dean Camera, 2019.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
- Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
+ Copyright 2019 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
diff --git a/Bootloaders/DFU/makefile b/Bootloaders/DFU/makefile
index 0d2014015..53c2b1a03 100644
--- a/Bootloaders/DFU/makefile
+++ b/Bootloaders/DFU/makefile
@@ -1,6 +1,6 @@
#
# LUFA Library
-# Copyright (C) Dean Camera, 2017.
+# Copyright (C) Dean Camera, 2019.
#
# dean [at] fourwalledcubicle [dot] com
# www.lufa-lib.org