Skip to content

Commit dbdd088

Browse files
committed
Removed knowledge of the bootloader size from BOSSA. That is the user's
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.
1 parent deecb80 commit dbdd088

File tree

14 files changed

+148
-76
lines changed

14 files changed

+148
-76
lines changed

src/BossaThread.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ WriteThread::Entry()
123123

124124
if (_eraseAll)
125125
{
126-
flash->eraseAll();
126+
flash->eraseAll(_offset);
127127
flash->eraseAuto(false);
128128
}
129129
else
@@ -133,9 +133,12 @@ WriteThread::Entry()
133133

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

136-
flash->setBootFlash(_bootFlash);
137-
flash->setBod(_bod);
138-
flash->setBor(_bor);
136+
if (flash->canBootFlash())
137+
flash->setBootFlash(_bootFlash);
138+
if (flash->canBod())
139+
flash->setBod(_bod);
140+
if (flash->canBor())
141+
flash->setBor(_bor);
139142
if (_lock)
140143
flash->lockAll();
141144
if (_security)

src/Command.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,18 +444,23 @@ CommandDump::invoke(char* argv[], int argc)
444444

445445
CommandErase::CommandErase() :
446446
Command("erase",
447-
"Erase the entire flash.",
448-
"erase")
447+
"Erase the flash to the end.",
448+
"erase <offset>"
449+
" OFFSET -- (optional) start erase operation at flash OFFSET\n"
450+
" OFFSET must be aligned to a flash page boundary")
449451
{}
450452

451453
void
452454
CommandErase::invoke(char* argv[], int argc)
453455
{
454-
if (!argNum(argc, 1) ||
456+
uint32_t offset = 0;
457+
458+
if (!argRange(argc, 1, 2) ||
459+
(argc >= 2 && !argUint32(argv[1], &offset)) ||
455460
!flashable())
456461
return;
457462

458-
_flasher.erase();
463+
_flasher.erase(offset);
459464
printf("Flash is erased\n");
460465
}
461466

@@ -1166,7 +1171,7 @@ CommandUnlock::invoke(char* argv[], int argc)
11661171
CommandVerify::CommandVerify() :
11671172
Command("verify",
11681173
"Verify binary file with the flash.",
1169-
"verify [FILE]\n"
1174+
"verify [FILE] <OFFSET>\n"
11701175
" FILE -- file name on host filesystem\n"
11711176
" OFFSET -- (optional) start verify operation at flash OFFSET\n"
11721177
" OFFSET must be aligned to a flash page boundary")

src/Device.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ Device::create()
352352
case 0x10010056: // E15B WLCSP
353353
case 0x10010063: // E15C WLCSP
354354
_family = FAMILY_SAMD21;
355-
flashPtr = new NvmFlash(_samba, "ATSAMD21x15", 0x2000, 512, 64, 1, 16, 0x20000800, 0x20001000, 0x41004000, true) ;
355+
flashPtr = new NvmFlash(_samba, "ATSAMD21x15", 0x0, 512, 64, 1, 16, 0x20000800, 0x20001000, 0x41004000, true) ;
356356
break;
357357

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

370370
case 0x10010001: // J17A
371371
case 0x10010006: // G17A
372372
case 0x1001000b: // E17A
373373
case 0x10010010: // G17A WLCSP
374374
_family = FAMILY_SAMD21;
375-
flashPtr = new NvmFlash(_samba, "ATSAMD21x17", 0x2000, 2048, 64, 1, 16, 0x20002000, 0x20004000, 0x41004000, true) ;
375+
flashPtr = new NvmFlash(_samba, "ATSAMD21x17", 0x0, 2048, 64, 1, 16, 0x20002000, 0x20004000, 0x41004000, true) ;
376376
break;
377377

378378
case 0x10010000: // J18A
379379
case 0x10010005: // G18A
380380
case 0x1001000a: // E18A
381381
case 0x1001000f: // G18A WLCSP
382382
_family = FAMILY_SAMD21;
383-
flashPtr = new NvmFlash(_samba, "ATSAMD21x18", 0x2000, 4096, 64, 1, 16, 0x20004000, 0x20008000, 0x41004000, true) ;
383+
flashPtr = new NvmFlash(_samba, "ATSAMD21x18", 0x0, 4096, 64, 1, 16, 0x20004000, 0x20008000, 0x41004000, true) ;
384384
break;
385385

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

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

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

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

412412
default:

src/EefcFlash.cpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@
5050
#define EEFC_FCMD_EWP 0x3
5151
#define EEFC_FCMD_EWPL 0x4
5252
#define EEFC_FCMD_EA 0x5
53+
#define EEFC_FCMD_EPA 0x7
5354
#define EEFC_FCMD_SLB 0x8
5455
#define EEFC_FCMD_CLB 0x9
5556
#define EEFC_FCMD_GLB 0xa
5657
#define EEFC_FCMD_SGPB 0xb
5758
#define EEFC_FCMD_CGPB 0xc
5859
#define EEFC_FCMD_GGPB 0xd
5960

61+
const uint32_t
62+
EefcFlash::PagesPerErase = 8;
63+
6064
EefcFlash::EefcFlash(Samba& samba,
6165
const std::string& name,
6266
uint32_t addr,
@@ -86,19 +90,45 @@ EefcFlash::~EefcFlash()
8690
}
8791

8892
void
89-
EefcFlash::eraseAll()
93+
EefcFlash::eraseAll(uint32_t offset)
9094
{
91-
waitFSR();
92-
writeFCR0(EEFC_FCMD_EA, 0);
93-
if (_planes == 2)
95+
// Do a full chip erase if the offset is 0
96+
if (offset == 0)
9497
{
9598
waitFSR();
96-
writeFCR1(EEFC_FCMD_EA, 0);
99+
writeFCR0(EEFC_FCMD_EA, 0);
100+
if (_planes == 2)
101+
{
102+
waitFSR();
103+
writeFCR1(EEFC_FCMD_EA, 0);
104+
}
105+
106+
// Erase all can take an exceptionally long time on some devices
107+
// so wait on FSR for up to 30 seconds
108+
waitFSR(30);
97109
}
110+
// Else we must do it by pages
111+
else
112+
{
113+
// Offset must be on an erase page boundary
114+
if (offset % (_size * PagesPerErase))
115+
throw FlashEraseError();
98116

99-
// Erase all can take an exceptionally long time on some devices
100-
// so wait on FSR for up to 30 seconds
101-
waitFSR(30);
117+
// Erase each PagesPerErase set of pages
118+
for (uint32_t pageNum = offset / _size; pageNum < _pages; pageNum += PagesPerErase)
119+
{
120+
if (_planes == 1 || pageNum < _pages / 2)
121+
{
122+
waitFSR();
123+
writeFCR0(EEFC_FCMD_EPA, pageNum | 0x1);
124+
}
125+
else
126+
{
127+
waitFSR();
128+
writeFCR1(EEFC_FCMD_EPA, (pageNum % (_pages / 2)) | 0x1);
129+
}
130+
}
131+
}
102132
}
103133

104134
void

src/EefcFlash.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EefcFlash : public Flash
5050
bool canBrownout);
5151
virtual ~EefcFlash();
5252

53-
void eraseAll();
53+
void eraseAll(uint32_t offset);
5454
void eraseAuto(bool enable);
5555

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

78+
static const uint32_t PagesPerErase;
79+
7880
private:
7981
uint32_t _regs;
8082
bool _canBrownout;

src/EfcFlash.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ EfcFlash::~EfcFlash()
7676
}
7777

7878
void
79-
EfcFlash::eraseAll()
79+
EfcFlash::eraseAll(uint32_t offset)
8080
{
81+
if (offset != 0)
82+
throw FlashEraseError();
83+
8184
waitFSR();
8285
writeFCR0(EFC_FCMD_EA, 0);
8386
if (_planes == 2)

src/EfcFlash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class EfcFlash : public Flash
4949
bool canBootFlash);
5050
virtual ~EfcFlash();
5151

52-
void eraseAll();
52+
void eraseAll(uint32_t offset);
5353
void eraseAuto(bool enable);
5454

5555
bool isLocked();

src/Flash.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ class BootFlashError : public std::exception
7575
{
7676
public:
7777
BootFlashError() : exception() {};
78-
const char* what() const throw() { return "Cannot clear Boot Flash. No ROM boot option available for this device"; }
78+
const char* what() const throw() { return "Unable to clear boot flash for this device"; }
79+
80+
};
81+
82+
class FlashEraseError : public std::exception
83+
{
84+
public:
85+
FlashEraseError() : exception() {};
86+
const char* what() const throw() { return "Flash erase failed"; }
7987

8088
};
8189

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

104-
virtual void eraseAll() = 0;
112+
virtual void eraseAll(uint32_t offset) = 0;
105113
virtual void eraseAuto(bool enable) = 0;
106114

107115
virtual uint32_t lockRegions() { return _lockRegions; }

src/Flasher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ FlasherInfo::print()
7878
}
7979

8080
void
81-
Flasher::erase()
81+
Flasher::erase(uint32_t foffset)
8282
{
8383
_observer.onStatus("Erase flash\n");
84-
_flash->eraseAll();
84+
_flash->eraseAll(foffset);
8585
_flash->eraseAuto(false);
8686
}
8787

src/Flasher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Flasher
9494
Flasher(Samba& samba, Device& device, FlasherObserver& observer) : _samba(samba), _flash(device.getFlash()), _observer(observer) {}
9595
virtual ~Flasher() {}
9696

97-
void erase();
97+
void erase(uint32_t foffset);
9898
void write(const char* filename, uint32_t foffset = 0);
9999
bool verify(const char* filename, uint32_t& pageErrors, uint32_t& totalErrors, uint32_t foffset = 0);
100100
void read(const char* filename, uint32_t fsize, uint32_t foffset = 0);

0 commit comments

Comments
 (0)