Corrected CDC class bootloader to fix a few bugs, changed address counter to store x2 addresses for convenience.

pull/1469/head
Dean Camera 16 years ago
parent 904ad3abd2
commit ceb68a0640

@ -52,7 +52,7 @@ CDC_Line_Coding_t LineCoding = { BaudRateBPS: 9600,
* and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued * and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued
* command.) * command.)
*/ */
uint16_t CurrAddress; uint32_t CurrAddress;
/** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run /** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run
* via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application * via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application
@ -223,101 +223,101 @@ static void ReadWriteMemoryBlock(const uint8_t Command)
MemoryType = FetchNextCommandByte(); MemoryType = FetchNextCommandByte();
if ((MemoryType == 'E') || (MemoryType == 'F')) if ((MemoryType != 'E') && (MemoryType != 'F'))
{ {
/* Check if command is to read memory */ /* Send error byte back to the host */
if (Command == 'g') WriteNextResponseByte('?');
{
/* Re-enable RWW section */ return;
boot_rww_enable(); }
while (BlockSize--) /* Check if command is to read memory */
if (Command == 'g')
{
/* Re-enable RWW section */
boot_rww_enable();
while (BlockSize--)
{
if (MemoryType == 'E')
{ {
if (MemoryType == 'E') /* Read the next EEPROM byte into the endpoint */
{ WriteNextResponseByte(eeprom_read_byte((uint8_t*)(uint16_t)(CurrAddress >> 1)));
/* Read the next EEPROM byte into the endpoint */
WriteNextResponseByte(eeprom_read_byte((uint8_t*)CurrAddress));
/* Increment the address counter after use */ /* Increment the address counter after use */
CurrAddress++; CurrAddress += 2;
} }
else else
{ {
/* Read the next FLASH byte from the current FLASH page */ /* Read the next FLASH byte from the current FLASH page */
#if defined(RAMPZ) #if defined(RAMPZ)
WriteNextResponseByte(pgm_read_byte_far(((uint32_t)CurrAddress << 1) + HighByte)); WriteNextResponseByte(pgm_read_byte_far(CurrAddress | HighByte));
#else #else
WriteNextResponseByte(pgm_read_byte((CurrAddress << 1) + HighByte)); WriteNextResponseByte(pgm_read_byte(CurrAddress | HighByte));
#endif #endif
/* If both bytes in current word have been read, increment the address counter */ /* If both bytes in current word have been read, increment the address counter */
if (HighByte) if (HighByte)
CurrAddress++; CurrAddress += 2;
HighByte ^= 1; HighByte = !HighByte;
}
} }
} }
else }
else
{
uint32_t PageStartAddress = CurrAddress;
if (MemoryType == 'F')
{
boot_page_erase(PageStartAddress);
boot_spm_busy_wait();
}
while (BlockSize--)
{ {
uint32_t PageStartAddress = ((uint32_t)CurrAddress << 1);
if (MemoryType == 'F') if (MemoryType == 'F')
{ {
boot_page_erase(PageStartAddress); /* If both bytes in current word have been written, increment the address counter */
boot_spm_busy_wait(); if (HighByte)
}
while (BlockSize--)
{
if (MemoryType == 'E')
{ {
/* Write the next EEPROM byte from the endpoint */ /* Write the next FLASH word to the current FLASH page */
eeprom_write_byte((uint8_t*)CurrAddress, FetchNextCommandByte()); boot_page_fill(CurrAddress, ((FetchNextCommandByte() << 8) | LowByte));
/* Increment the address counter after use */ /* Increment the address counter after use */
CurrAddress++; CurrAddress += 2;
HighByte = false;
} }
else else
{ {
/* If both bytes in current word have been written, increment the address counter */ LowByte = FetchNextCommandByte();
if (HighByte)
{ HighByte = true;
/* Write the next FLASH word to the current FLASH page */
boot_page_fill(((uint32_t)CurrAddress << 1), ((FetchNextCommandByte() << 8) | LowByte));
HighByte = false;
/* Increment the address counter after use */
CurrAddress++;
}
else
{
LowByte = FetchNextCommandByte();
HighByte = true;
}
} }
} }
else
/* If in FLASH programming mode, commit the page after writing */
if (MemoryType == 'F')
{ {
/* Commit the flash page to memory */ /* Write the next EEPROM byte from the endpoint */
boot_page_write(PageStartAddress); eeprom_write_byte((uint8_t*)(uint16_t)(CurrAddress >> 1), FetchNextCommandByte());
/* Wait until write operation has completed */ /* Increment the address counter after use */
boot_spm_busy_wait(); CurrAddress += 2;
} }
/* Send response byte back to the host */
WriteNextResponseByte('\r');
} }
}
else /* If in FLASH programming mode, commit the page after writing */
{ if (MemoryType == 'F')
/* Send error byte back to the host */ {
WriteNextResponseByte('?'); /* Commit the flash page to memory */
boot_page_write(PageStartAddress);
/* Wait until write operation has completed */
boot_spm_busy_wait();
}
/* Send response byte back to the host */
WriteNextResponseByte('\r');
} }
} }
@ -402,8 +402,8 @@ TASK(CDC_Task)
else if (Command == 'A') else if (Command == 'A')
{ {
/* Set the current address to that given by the host */ /* Set the current address to that given by the host */
CurrAddress = (FetchNextCommandByte() << 8); CurrAddress = (FetchNextCommandByte() << 9);
CurrAddress |= FetchNextCommandByte(); CurrAddress |= (FetchNextCommandByte() << 1);
/* Send confirmation byte back to the host */ /* Send confirmation byte back to the host */
WriteNextResponseByte('\r'); WriteNextResponseByte('\r');
@ -426,9 +426,9 @@ TASK(CDC_Task)
} }
else if (Command == 's') else if (Command == 's')
{ {
WriteNextResponseByte(boot_signature_byte_get(4)); WriteNextResponseByte(SIGNATURE_0);
WriteNextResponseByte(boot_signature_byte_get(2)); WriteNextResponseByte(SIGNATURE_1);
WriteNextResponseByte(boot_signature_byte_get(0)); WriteNextResponseByte(SIGNATURE_2);
} }
else if (Command == 'b') else if (Command == 'b')
{ {
@ -478,24 +478,29 @@ TASK(CDC_Task)
{ {
WriteNextResponseByte(boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS)); WriteNextResponseByte(boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS));
} }
else if ((Command == 'C') || (Command == 'c')) else if (Command == 'C')
{ {
if (Command == 'c')
{
/* Increment the address if the second byte is being written */
CurrAddress++;
}
/* Write the high byte to the current flash page */ /* Write the high byte to the current flash page */
boot_page_fill(((uint32_t)CurrAddress << 1), FetchNextCommandByte()); boot_page_fill(CurrAddress, FetchNextCommandByte());
/* Send confirmation byte back to the host */
WriteNextResponseByte('\r');
}
else if (Command == 'c')
{
/* Write the low byte to the current flash page */
boot_page_fill(CurrAddress | 1, FetchNextCommandByte());
/* Increment the address */
CurrAddress += 2;
/* Send confirmation byte back to the host */ /* Send confirmation byte back to the host */
WriteNextResponseByte('\r'); WriteNextResponseByte('\r');
} }
else if (Command == 'm') else if (Command == 'm')
{ {
/* Commit the flash page to memory */ /* Commit the flash page to memory */
boot_page_write((uint32_t)CurrAddress << 1); boot_page_write(CurrAddress);
/* Wait until write operation has completed */ /* Wait until write operation has completed */
boot_spm_busy_wait(); boot_spm_busy_wait();
@ -511,9 +516,9 @@ TASK(CDC_Task)
else if (Command == 'R') else if (Command == 'R')
{ {
#if defined(RAMPZ) #if defined(RAMPZ)
uint16_t ProgramWord = pgm_read_word_far(((uint32_t)CurrAddress << 1)); uint16_t ProgramWord = pgm_read_word_far(CurrAddress);
#else #else
uint16_t ProgramWord = pgm_read_word(CurrAddress << 1); uint16_t ProgramWord = pgm_read_word(CurrAddress);
#endif #endif
WriteNextResponseByte(ProgramWord >> 8); WriteNextResponseByte(ProgramWord >> 8);
@ -522,10 +527,10 @@ TASK(CDC_Task)
else if (Command == 'D') else if (Command == 'D')
{ {
/* Read the byte from the endpoint and write it to the EEPROM */ /* Read the byte from the endpoint and write it to the EEPROM */
eeprom_write_byte((uint8_t*)CurrAddress, FetchNextCommandByte()); eeprom_write_byte((uint8_t*)(uint16_t)(CurrAddress >> 1), FetchNextCommandByte());
/* Increment the address after use */ /* Increment the address after use */
CurrAddress++; CurrAddress += 2;
/* Send confirmation byte back to the host */ /* Send confirmation byte back to the host */
WriteNextResponseByte('\r'); WriteNextResponseByte('\r');
@ -533,10 +538,10 @@ TASK(CDC_Task)
else if (Command == 'd') else if (Command == 'd')
{ {
/* Read the EEPROM byte and write it to the endpoint */ /* Read the EEPROM byte and write it to the endpoint */
WriteNextResponseByte(eeprom_read_byte((uint8_t*)CurrAddress)); WriteNextResponseByte(eeprom_read_byte((uint8_t*)(uint16_t)(CurrAddress >> 1)));
/* Increment the address after use */ /* Increment the address after use */
CurrAddress++; CurrAddress += 2;
} }
else if (Command == 27) else if (Command == 27)
{ {

@ -32,13 +32,6 @@
* *
* Main source file for the DFU class bootloader. This file contains the complete bootloader logic. * Main source file for the DFU class bootloader. This file contains the complete bootloader logic.
*/ */
/** Configuration define. Define this token to true to case the bootloader to reject all memory commands
* until a memory erase has been performed. When used in conjunction with the lockbits of the AVR, this
* can protect the AVR's firmware from being dumped from a secured AVR. When false, memory operations are
* allowed at any time.
*/
#define SECURE_MODE false
#define INCLUDE_FROM_BOOTLOADER_C #define INCLUDE_FROM_BOOTLOADER_C
#include "BootloaderDFU.h" #include "BootloaderDFU.h"

@ -50,6 +50,13 @@
#include <LUFA/Drivers/USB/USB.h> // USB Functionality #include <LUFA/Drivers/USB/USB.h> // USB Functionality
/* Macros: */ /* Macros: */
/** Configuration define. Define this token to true to case the bootloader to reject all memory commands
* until a memory erase has been performed. When used in conjunction with the lockbits of the AVR, this
* can protect the AVR's firmware from being dumped from a secured AVR. When false, memory operations are
* allowed at any time.
*/
#define SECURE_MODE false
/** Major bootloader version number. */ /** Major bootloader version number. */
#define BOOTLOADER_VERSION_MINOR 2 #define BOOTLOADER_VERSION_MINOR 2

@ -113,6 +113,9 @@ EVENT_HANDLER(USB_Connect)
/* Indicate USB enumerating */ /* Indicate USB enumerating */
UpdateStatus(Status_USBEnumerating); UpdateStatus(Status_USBEnumerating);
/* Default to report protocol on connect */
UsingReportProtocol = true;
} }
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
@ -141,9 +144,6 @@ EVENT_HANDLER(USB_ConfigurationChanged)
/* Indicate USB connected and ready */ /* Indicate USB connected and ready */
UpdateStatus(Status_USBReady); UpdateStatus(Status_USBReady);
/* Default to report protocol on connect */
UsingReportProtocol = true;
/* Start running mouse reporting task */ /* Start running mouse reporting task */
Scheduler_SetTaskMode(USB_Mouse_Report, TASK_RUN); Scheduler_SetTaskMode(USB_Mouse_Report, TASK_RUN);
} }

File diff suppressed because one or more lines are too long

@ -38,6 +38,7 @@
* - Added DataflashManager_WriteBlocks_RAM() and DataflashManager_ReadBlocks_RAM() functions to the MassStorage demo, to allow for easy * - Added DataflashManager_WriteBlocks_RAM() and DataflashManager_ReadBlocks_RAM() functions to the MassStorage demo, to allow for easy
* interfacing with a FAT library for dataflash file level access * interfacing with a FAT library for dataflash file level access
* - Incomplete non-functional BluetoothHost demo removed until it has reached a stable state to prevent confusion * - Incomplete non-functional BluetoothHost demo removed until it has reached a stable state to prevent confusion
* - Corrected CDC class bootloader to fix a few bugs, changed address counter to store x2 addresses for convenience
* *
* \section Sec_ChangeLog090209 Version 090209 * \section Sec_ChangeLog090209 Version 090209
* *

Loading…
Cancel
Save