Skip to content

Commit

Permalink
Removed knowledge of the bootloader size from BOSSA. That is the user's
Browse files Browse the repository at this point in the history
concern, not BOSSA's.  The flash offset now applies to erases to
support not erasing bootloaders or any other code before the offset.
The NvmFlash now supports on the fly auto-erase like the other flashes.
The GUI now only attempts to set flags if the flash indicates it can.
  • Loading branch information
shumatech committed Mar 5, 2018
1 parent deecb80 commit dbdd088
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 76 deletions.
11 changes: 7 additions & 4 deletions src/BossaThread.cpp
Expand Up @@ -123,7 +123,7 @@ WriteThread::Entry()

if (_eraseAll)
{
flash->eraseAll();
flash->eraseAll(_offset);
flash->eraseAuto(false);
}
else
Expand All @@ -133,9 +133,12 @@ WriteThread::Entry()

flasher.write(_filename.mb_str(), _offset);

flash->setBootFlash(_bootFlash);
flash->setBod(_bod);
flash->setBor(_bor);
if (flash->canBootFlash())
flash->setBootFlash(_bootFlash);
if (flash->canBod())
flash->setBod(_bod);
if (flash->canBor())
flash->setBor(_bor);
if (_lock)
flash->lockAll();
if (_security)
Expand Down
15 changes: 10 additions & 5 deletions src/Command.cpp
Expand Up @@ -444,18 +444,23 @@ CommandDump::invoke(char* argv[], int argc)

CommandErase::CommandErase() :
Command("erase",
"Erase the entire flash.",
"erase")
"Erase the flash to the end.",
"erase <offset>"
" OFFSET -- (optional) start erase operation at flash OFFSET\n"
" OFFSET must be aligned to a flash page boundary")
{}

void
CommandErase::invoke(char* argv[], int argc)
{
if (!argNum(argc, 1) ||
uint32_t offset = 0;

if (!argRange(argc, 1, 2) ||
(argc >= 2 && !argUint32(argv[1], &offset)) ||
!flashable())
return;

_flasher.erase();
_flasher.erase(offset);
printf("Flash is erased\n");
}

Expand Down Expand Up @@ -1166,7 +1171,7 @@ CommandUnlock::invoke(char* argv[], int argc)
CommandVerify::CommandVerify() :
Command("verify",
"Verify binary file with the flash.",
"verify [FILE]\n"
"verify [FILE] <OFFSET>\n"
" FILE -- file name on host filesystem\n"
" OFFSET -- (optional) start verify operation at flash OFFSET\n"
" OFFSET must be aligned to a flash page boundary")
Expand Down
16 changes: 8 additions & 8 deletions src/Device.cpp
Expand Up @@ -352,7 +352,7 @@ Device::create()
case 0x10010056: // E15B WLCSP
case 0x10010063: // E15C WLCSP
_family = FAMILY_SAMD21;
flashPtr = new NvmFlash(_samba, "ATSAMD21x15", 0x2000, 512, 64, 1, 16, 0x20000800, 0x20001000, 0x41004000, true) ;
flashPtr = new NvmFlash(_samba, "ATSAMD21x15", 0x0, 512, 64, 1, 16, 0x20000800, 0x20001000, 0x41004000, true) ;
break;

case 0x10010002: // J16A
Expand All @@ -364,23 +364,23 @@ Device::create()
case 0x10010055: // E16B WLCSP
case 0x10010062: // E16C WLCSP
_family = FAMILY_SAMD21;
flashPtr = new NvmFlash(_samba, "ATSAMD21x16", 0x2000, 1024, 64, 1, 16, 0x20001000, 0x20002000, 0x41004000, true) ;
flashPtr = new NvmFlash(_samba, "ATSAMD21x16", 0x0, 1024, 64, 1, 16, 0x20001000, 0x20002000, 0x41004000, true) ;
break;

case 0x10010001: // J17A
case 0x10010006: // G17A
case 0x1001000b: // E17A
case 0x10010010: // G17A WLCSP
_family = FAMILY_SAMD21;
flashPtr = new NvmFlash(_samba, "ATSAMD21x17", 0x2000, 2048, 64, 1, 16, 0x20002000, 0x20004000, 0x41004000, true) ;
flashPtr = new NvmFlash(_samba, "ATSAMD21x17", 0x0, 2048, 64, 1, 16, 0x20002000, 0x20004000, 0x41004000, true) ;
break;

case 0x10010000: // J18A
case 0x10010005: // G18A
case 0x1001000a: // E18A
case 0x1001000f: // G18A WLCSP
_family = FAMILY_SAMD21;
flashPtr = new NvmFlash(_samba, "ATSAMD21x18", 0x2000, 4096, 64, 1, 16, 0x20004000, 0x20008000, 0x41004000, true) ;
flashPtr = new NvmFlash(_samba, "ATSAMD21x18", 0x0, 4096, 64, 1, 16, 0x20004000, 0x20008000, 0x41004000, true) ;
break;

//
Expand All @@ -389,24 +389,24 @@ Device::create()
case 0x1001001e: // E16A
case 0x1001001b: // G16A
_family = FAMILY_SAMR21;
flashPtr = new NvmFlash(_samba, "ATSAMR21x16", 0x2000, 1024, 64, 1, 16, 0x20001000, 0x20002000, 0x41004000, true) ;
flashPtr = new NvmFlash(_samba, "ATSAMR21x16", 0x0, 1024, 64, 1, 16, 0x20001000, 0x20002000, 0x41004000, true) ;
break;

case 0x1001001d: // E17A
case 0x1001001a: // G17A
_family = FAMILY_SAMR21;
flashPtr = new NvmFlash(_samba, "ATSAMR21x17", 0x2000, 2048, 64, 1, 16, 0x20002000, 0x20004000, 0x41004000, true) ;
flashPtr = new NvmFlash(_samba, "ATSAMR21x17", 0x0, 2048, 64, 1, 16, 0x20002000, 0x20004000, 0x41004000, true) ;
break;

case 0x1001001c: // E18A
case 0x10010019: // G18A
_family = FAMILY_SAMR21;
flashPtr = new NvmFlash(_samba, "ATSAMR21x18", 0x2000, 4096, 64, 1, 16, 0x20004000, 0x20008000, 0x41004000, true) ;
flashPtr = new NvmFlash(_samba, "ATSAMR21x18", 0x0, 4096, 64, 1, 16, 0x20004000, 0x20008000, 0x41004000, true) ;
break;

case 0x10010018: // E19A
_family = FAMILY_SAMR21;
flashPtr = new NvmFlash(_samba, "ATSAMR21x19", 0x2000, 4096, 64, 1, 16, 0x20004000, 0x20008000, 0x41004000, true) ;
flashPtr = new NvmFlash(_samba, "ATSAMR21x19", 0x0, 4096, 64, 1, 16, 0x20004000, 0x20008000, 0x41004000, true) ;
break;

default:
Expand Down
46 changes: 38 additions & 8 deletions src/EefcFlash.cpp
Expand Up @@ -50,13 +50,17 @@
#define EEFC_FCMD_EWP 0x3
#define EEFC_FCMD_EWPL 0x4
#define EEFC_FCMD_EA 0x5
#define EEFC_FCMD_EPA 0x7
#define EEFC_FCMD_SLB 0x8
#define EEFC_FCMD_CLB 0x9
#define EEFC_FCMD_GLB 0xa
#define EEFC_FCMD_SGPB 0xb
#define EEFC_FCMD_CGPB 0xc
#define EEFC_FCMD_GGPB 0xd

const uint32_t
EefcFlash::PagesPerErase = 8;

EefcFlash::EefcFlash(Samba& samba,
const std::string& name,
uint32_t addr,
Expand Down Expand Up @@ -86,19 +90,45 @@ EefcFlash::~EefcFlash()
}

void
EefcFlash::eraseAll()
EefcFlash::eraseAll(uint32_t offset)
{
waitFSR();
writeFCR0(EEFC_FCMD_EA, 0);
if (_planes == 2)
// Do a full chip erase if the offset is 0
if (offset == 0)
{
waitFSR();
writeFCR1(EEFC_FCMD_EA, 0);
writeFCR0(EEFC_FCMD_EA, 0);
if (_planes == 2)
{
waitFSR();
writeFCR1(EEFC_FCMD_EA, 0);
}

// Erase all can take an exceptionally long time on some devices
// so wait on FSR for up to 30 seconds
waitFSR(30);
}
// Else we must do it by pages
else
{
// Offset must be on an erase page boundary
if (offset % (_size * PagesPerErase))
throw FlashEraseError();

// Erase all can take an exceptionally long time on some devices
// so wait on FSR for up to 30 seconds
waitFSR(30);
// Erase each PagesPerErase set of pages
for (uint32_t pageNum = offset / _size; pageNum < _pages; pageNum += PagesPerErase)
{
if (_planes == 1 || pageNum < _pages / 2)
{
waitFSR();
writeFCR0(EEFC_FCMD_EPA, pageNum | 0x1);
}
else
{
waitFSR();
writeFCR1(EEFC_FCMD_EPA, (pageNum % (_pages / 2)) | 0x1);
}
}
}
}

void
Expand Down
4 changes: 3 additions & 1 deletion src/EefcFlash.h
Expand Up @@ -50,7 +50,7 @@ class EefcFlash : public Flash
bool canBrownout);
virtual ~EefcFlash();

void eraseAll();
void eraseAll(uint32_t offset);
void eraseAuto(bool enable);

bool isLocked();
Expand All @@ -75,6 +75,8 @@ class EefcFlash : public Flash
void writePage(uint32_t page);
void readPage(uint32_t page, uint8_t* data);

static const uint32_t PagesPerErase;

private:
uint32_t _regs;
bool _canBrownout;
Expand Down
5 changes: 4 additions & 1 deletion src/EfcFlash.cpp
Expand Up @@ -76,8 +76,11 @@ EfcFlash::~EfcFlash()
}

void
EfcFlash::eraseAll()
EfcFlash::eraseAll(uint32_t offset)
{
if (offset != 0)
throw FlashEraseError();

waitFSR();
writeFCR0(EFC_FCMD_EA, 0);
if (_planes == 2)
Expand Down
2 changes: 1 addition & 1 deletion src/EfcFlash.h
Expand Up @@ -49,7 +49,7 @@ class EfcFlash : public Flash
bool canBootFlash);
virtual ~EfcFlash();

void eraseAll();
void eraseAll(uint32_t offset);
void eraseAuto(bool enable);

bool isLocked();
Expand Down
12 changes: 10 additions & 2 deletions src/Flash.h
Expand Up @@ -75,7 +75,15 @@ class BootFlashError : public std::exception
{
public:
BootFlashError() : exception() {};
const char* what() const throw() { return "Cannot clear Boot Flash. No ROM boot option available for this device"; }
const char* what() const throw() { return "Unable to clear boot flash for this device"; }

};

class FlashEraseError : public std::exception
{
public:
FlashEraseError() : exception() {};
const char* what() const throw() { return "Flash erase failed"; }

};

Expand All @@ -101,7 +109,7 @@ class Flash
virtual uint32_t numPlanes() { return _planes; }
virtual uint32_t totalSize() { return _size * _pages; }

virtual void eraseAll() = 0;
virtual void eraseAll(uint32_t offset) = 0;
virtual void eraseAuto(bool enable) = 0;

virtual uint32_t lockRegions() { return _lockRegions; }
Expand Down
4 changes: 2 additions & 2 deletions src/Flasher.cpp
Expand Up @@ -78,10 +78,10 @@ FlasherInfo::print()
}

void
Flasher::erase()
Flasher::erase(uint32_t foffset)
{
_observer.onStatus("Erase flash\n");
_flash->eraseAll();
_flash->eraseAll(foffset);
_flash->eraseAuto(false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Flasher.h
Expand Up @@ -94,7 +94,7 @@ class Flasher
Flasher(Samba& samba, Device& device, FlasherObserver& observer) : _samba(samba), _flash(device.getFlash()), _observer(observer) {}
virtual ~Flasher() {}

void erase();
void erase(uint32_t foffset);
void write(const char* filename, uint32_t foffset = 0);
bool verify(const char* filename, uint32_t& pageErrors, uint32_t& totalErrors, uint32_t foffset = 0);
void read(const char* filename, uint32_t fsize, uint32_t foffset = 0);
Expand Down

0 comments on commit dbdd088

Please sign in to comment.