[ion/device] Access external flash through DFU

This commit is contained in:
Ruben Dashyan
2018-12-03 09:58:35 +01:00
committed by Romain Goyet
parent 0d6317117c
commit e4f70c7be7
4 changed files with 18 additions and 7 deletions

View File

@@ -50,6 +50,7 @@ dfu_objs += ion/src/device/device.o
dfu_objs += ion/src/device/usb.o
dfu_objs += ion/src/device/base64.o
dfu_objs += ion/src/device/flash.o
dfu_objs += ion/src/device/external_flash.o
dfu_objs += ion/src/device/timing.o
ion/src/device/usb/dfu.elf: LDSCRIPT = ion/src/device/usb/dfu.ld

View File

@@ -93,7 +93,7 @@ public:
m_manufacturerStringDescriptor("NumWorks"),
m_productStringDescriptor("NumWorks Calculator"),
m_serialNumberStringDescriptor(serialNumber),
m_interfaceStringDescriptor("@Flash/0x08000000/04*016Kg,01*064Kg,07*128Kg"),
m_interfaceStringDescriptor("@Flash/0x08000000/04*016Kg,01*064Kg,07*128Kg/0x90000000/64*064Kg,64*064Kg"),
//m_interfaceStringDescriptor("@SRAM/0x20000000/01*256Ke"),
/* Switch to this descriptor to use dfu-util to write in the SRAM.
* FIXME Should be an alternate Interface. */

View File

@@ -1,6 +1,7 @@
#include "dfu_interface.h"
#include <string.h>
#include <ion/src/device/flash.h>
#include <ion/src/device/external_flash.h>
namespace Ion {
namespace USB {
@@ -173,7 +174,7 @@ void DFUInterface::eraseCommand(uint8_t * transferBuffer, uint16_t transferBuffe
if (transferBufferLength == 1) {
// Mass erase
m_erasePage = Flash::Device::NumberOfSectors;
m_erasePage = Flash::Device::NumberOfSectors + ExternalFlash::Device::NumberOfSectors;
return;
}
@@ -185,9 +186,11 @@ void DFUInterface::eraseCommand(uint8_t * transferBuffer, uint16_t transferBuffe
+ (transferBuffer[3] << 16)
+ (transferBuffer[4] << 24);
m_erasePage = Flash::Device::SectorAtAddress(eraseAddress);
if (m_erasePage < 0) {
if (eraseAddress >= k_flashStartAddress && eraseAddress <= k_flashEndAddress) {
m_erasePage = Flash::Device::SectorAtAddress(eraseAddress);
} else if (eraseAddress >= k_externalFlashStartAddress && eraseAddress <= k_externalFlashEndAddress) {
m_erasePage = Flash::Device::NumberOfSectors + ExternalFlash::Device::SectorAtAddress(eraseAddress - k_externalFlashStartAddress);
} else {
// Unrecognized sector
m_state = State::dfuERROR;
m_status = Status::errTARGET;
@@ -201,10 +204,13 @@ void DFUInterface::eraseMemoryIfNeeded() {
return;
}
if (m_erasePage == Ion::Flash::Device::NumberOfSectors) {
if (m_erasePage == Flash::Device::NumberOfSectors + ExternalFlash::Device::NumberOfSectors) {
Flash::Device::MassErase();
} else {
ExternalFlash::Device::MassErase();
} else if (m_erasePage < Flash::Device::NumberOfSectors) {
Flash::Device::EraseSector(m_erasePage);
} else {
ExternalFlash::Device::EraseSector(m_erasePage - Flash::Device::NumberOfSectors);
}
/* Put an out of range value in m_erasePage to indicate that no erase is
@@ -222,6 +228,8 @@ void DFUInterface::writeOnMemory() {
// Write on SRAM
// FIXME We should check that we are not overriding the current instructions.
memcpy((void *)m_writeAddress, m_largeBuffer, m_largeBufferLength);
} else if (m_writeAddress >= k_externalFlashStartAddress && m_writeAddress <= k_externalFlashEndAddress) {
ExternalFlash::Device::WriteMemory(m_largeBuffer, reinterpret_cast<uint8_t *>(m_writeAddress) - k_externalFlashStartAddress, m_largeBufferLength);
} else {
// Invalid write address
m_largeBufferLength = 0;

View File

@@ -130,6 +130,8 @@ private:
constexpr static uint32_t k_flashEndAddress = 0x08100000;
constexpr static uint32_t k_sramStartAddress = 0x20000000;
constexpr static uint32_t k_sramEndAddress = 0x20040000;
constexpr static uint32_t k_externalFlashStartAddress = 0x90000000;
constexpr static uint32_t k_externalFlashEndAddress = 0x90800000;
// Download and upload
bool processDownloadRequest(uint16_t wLength, uint16_t * transferBufferLength);