aboutsummaryrefslogtreecommitdiffstats
path: root/Bootloaders/MassStorage/Lib/VirtualFAT.c
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2013-03-18 17:18:11 +0000
committerDean Camera <dean@fourwalledcubicle.com>2013-03-18 17:18:11 +0000
commitbe33d3a5156ea3fde221c9e174ad0405eb8d1f8d (patch)
treeb027f4af999f39ed4554270c089a003479be7af7 /Bootloaders/MassStorage/Lib/VirtualFAT.c
parentf8a1dc7424cd83f2f3e87274010d379a661b76e4 (diff)
downloadlufa-be33d3a5156ea3fde221c9e174ad0405eb8d1f8d.tar.gz
lufa-be33d3a5156ea3fde221c9e174ad0405eb8d1f8d.tar.bz2
lufa-be33d3a5156ea3fde221c9e174ad0405eb8d1f8d.zip
Update Mass Storage bootloader so that it can support devices with only 4KB bootloader sections by creating a special AUX section before the real bootloader section to store part of the bootloader code.
Diffstat (limited to 'Bootloaders/MassStorage/Lib/VirtualFAT.c')
-rw-r--r--Bootloaders/MassStorage/Lib/VirtualFAT.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/Bootloaders/MassStorage/Lib/VirtualFAT.c b/Bootloaders/MassStorage/Lib/VirtualFAT.c
index ee0107c1b..41c661ed3 100644
--- a/Bootloaders/MassStorage/Lib/VirtualFAT.c
+++ b/Bootloaders/MassStorage/Lib/VirtualFAT.c
@@ -151,26 +151,28 @@ static void WriteVirtualBlock(const uint16_t BlockNumber)
if ((BlockNumber >= 4) && (BlockNumber < (4 + FILE_SECTORS(FIRMWARE_FILE_SIZE_BYTES))))
{
+ #if (FLASHEND > 0xFFFF)
uint32_t WriteFlashAddress = (uint32_t)(BlockNumber - 4) * SECTOR_SIZE_BYTES;
+ #else
+ uint16_t WriteFlashAddress = (uint16_t)(BlockNumber - 4) * SECTOR_SIZE_BYTES;
+ #endif
for (uint16_t i = 0; i < SECTOR_SIZE_BYTES; i += 2)
{
if ((WriteFlashAddress % SPM_PAGESIZE) == 0)
{
/* Erase the given FLASH page, ready to be programmed */
- boot_page_erase(WriteFlashAddress);
- boot_spm_busy_wait();
+ BootloaderAPI_ErasePage(WriteFlashAddress);
}
/* Write the next data word to the FLASH page */
- boot_page_fill(WriteFlashAddress, (BlockBuffer[i + 1] << 8) | BlockBuffer[i]);
+ BootloaderAPI_FillWord(WriteFlashAddress, (BlockBuffer[i + 1] << 8) | BlockBuffer[i]);
WriteFlashAddress += 2;
if ((WriteFlashAddress % SPM_PAGESIZE) == 0)
{
/* Write the filled FLASH page to memory */
- boot_page_write(WriteFlashAddress - SPM_PAGESIZE);
- boot_spm_busy_wait();
+ BootloaderAPI_WritePage(WriteFlashAddress - SPM_PAGESIZE);
}
}
}
@@ -219,10 +221,17 @@ static void ReadVirtualBlock(const uint16_t BlockNumber)
default: /* Blocks 4 onwards: Data allocation section */
if ((BlockNumber >= 4) && (BlockNumber < (4 + FILE_SECTORS(FIRMWARE_FILE_SIZE_BYTES))))
{
+ #if (FLASHEND > 0xFFFF)
uint32_t ReadFlashAddress = (uint32_t)(BlockNumber - 4) * SECTOR_SIZE_BYTES;
for (uint16_t i = 0; i < SECTOR_SIZE_BYTES; i++)
BlockBuffer[i] = pgm_read_byte_far(ReadFlashAddress++);
+ #else
+ uint16_t ReadFlashAddress = (uint16_t)(BlockNumber - 4) * SECTOR_SIZE_BYTES;
+
+ for (uint16_t i = 0; i < SECTOR_SIZE_BYTES; i++)
+ BlockBuffer[i] = pgm_read_byte(ReadFlashAddress++);
+ #endif
}
break;
@@ -237,8 +246,8 @@ static void ReadVirtualBlock(const uint16_t BlockNumber)
* PC via the USB Mass Storage interface.
*
* \param[in] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state
- * \param[in] BlockAddress Data block starting address for the write sequence
- * \param[in] TotalBlocks Number of blocks of data to write
+ * \param[in] BlockAddress Data block starting address for the write sequence
+ * \param[in] TotalBlocks Number of blocks of data to write
*/
void VirtualFAT_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
const uint32_t BlockAddress,
@@ -256,8 +265,8 @@ void VirtualFAT_WriteBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
* to the host PC via the USB Mass Storage interface.
*
* \param[in] MSInterfaceInfo Pointer to a structure containing a Mass Storage Class configuration and state
- * \param[in] BlockAddress Data block starting address for the read sequence
- * \param[in] TotalBlocks Number of blocks of data to read
+ * \param[in] BlockAddress Data block starting address for the read sequence
+ * \param[in] TotalBlocks Number of blocks of data to read
*/
void VirtualFAT_ReadBlocks(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
const uint32_t BlockAddress,