forked from zephyrproject-rtos/sdk-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bossa: Pull in Add support to SAM4L SoC Family
Pull in changes from shumatech/BOSSA#143 Signed-off-by: Kumar Gala <[email protected]>
- Loading branch information
Showing
6 changed files
with
513 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ephyr-sdk/recipes-hosttools/bossa/files/0001-Flash.h-Add-flash-override-samba-error.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
From a7c015a628daa1b628f70b7eaf9485f7cbafcf9d Mon Sep 17 00:00:00 2001 | ||
From: Gerson Fernando Budke <[email protected]> | ||
Date: Sat, 26 Sep 2020 18:25:53 -0300 | ||
Subject: [PATCH 1/4] Flash.h: Add flash override samba error | ||
|
||
When a device have bootloader on flash, user can set a offset that may | ||
try erase and/or override the bootloader. Add an exception to abort on | ||
any of that conditions. | ||
|
||
Signed-off-by: Gerson Fernando Budke <[email protected]> | ||
--- | ||
src/Flash.h | 8 ++++++++ | ||
1 file changed, 8 insertions(+) | ||
|
||
diff --git a/src/Flash.h b/src/Flash.h | ||
index 5d3a37b..b396a16 100644 | ||
--- a/src/Flash.h | ||
+++ b/src/Flash.h | ||
@@ -88,6 +88,14 @@ public: | ||
|
||
}; | ||
|
||
+class FlashOverrideSambaError : public std::exception | ||
+{ | ||
+public: | ||
+ FlashOverrideSambaError() : exception() {}; | ||
+ const char* what() const throw() { return "SAM-BA bootloader shouldn't be erased. Check flash start address."; } | ||
+ | ||
+}; | ||
+ | ||
template<class T> | ||
class FlashOption | ||
{ | ||
-- | ||
2.25.4 | ||
|
327 changes: 327 additions & 0 deletions
327
...hyr-sdk/recipes-hosttools/bossa/files/0002-CalwFlash-Add-SAM4L-Flashcalw-controller.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,327 @@ | ||
From ec9bb35ce522419a0f625f6c2e133267691832ef Mon Sep 17 00:00:00 2001 | ||
From: Gerson Fernando Budke <[email protected]> | ||
Date: Sat, 26 Sep 2020 18:31:10 -0300 | ||
Subject: [PATCH 2/4] CalwFlash: Add SAM4L Flashcalw controller | ||
|
||
The SAM4L SoC have a special flash controller on the whole family. Add | ||
CalwFlash controller to allow bossac work with SAM4L SoC family. | ||
|
||
Signed-off-by: Gerson Fernando Budke <[email protected]> | ||
--- | ||
Makefile | 2 +- | ||
src/CalwFlash.cpp | 198 ++++++++++++++++++++++++++++++++++++++++++++++ | ||
src/CalwFlash.h | 84 ++++++++++++++++++++ | ||
3 files changed, 283 insertions(+), 1 deletion(-) | ||
create mode 100644 src/CalwFlash.cpp | ||
create mode 100644 src/CalwFlash.h | ||
|
||
diff --git a/Makefile b/Makefile | ||
index 63b2b01..650fa65 100644 | ||
--- a/Makefile | ||
+++ b/Makefile | ||
@@ -9,7 +9,7 @@ WXVERSION=3.0 | ||
# | ||
# Source files | ||
# | ||
-COMMON_SRCS=Samba.cpp Flash.cpp D5xNvmFlash.cpp D2xNvmFlash.cpp EfcFlash.cpp EefcFlash.cpp Applet.cpp WordCopyApplet.cpp Flasher.cpp Device.cpp | ||
+COMMON_SRCS=Samba.cpp Flash.cpp D5xNvmFlash.cpp D2xNvmFlash.cpp EfcFlash.cpp EefcFlash.cpp CalwFlash.cpp Applet.cpp WordCopyApplet.cpp Flasher.cpp Device.cpp | ||
APPLET_SRCS=WordCopyArm.asm | ||
BOSSA_SRCS=BossaForm.cpp BossaWindow.cpp BossaAbout.cpp BossaApp.cpp BossaBitmaps.cpp BossaInfo.cpp BossaThread.cpp BossaProgress.cpp | ||
BOSSA_BMPS=BossaLogo.bmp BossaIcon.bmp ShumaTechLogo.bmp | ||
diff --git a/src/CalwFlash.cpp b/src/CalwFlash.cpp | ||
new file mode 100644 | ||
index 0000000..db1d684 | ||
--- /dev/null | ||
+++ b/src/CalwFlash.cpp | ||
@@ -0,0 +1,198 @@ | ||
+/////////////////////////////////////////////////////////////////////////////// | ||
+// BOSSA | ||
+// | ||
+// Copyright (c) 2011-2020, ShumaTech | ||
+// All rights reserved. | ||
+// | ||
+// Redistribution and use in source and binary forms, with or without | ||
+// modification, are permitted provided that the following conditions are met: | ||
+// * Redistributions of source code must retain the above copyright | ||
+// notice, this list of conditions and the following disclaimer. | ||
+// * Redistributions in binary form must reproduce the above copyright | ||
+// notice, this list of conditions and the following disclaimer in the | ||
+// documentation and/or other materials provided with the distribution. | ||
+// * Neither the name of the <organization> nor the | ||
+// names of its contributors may be used to endorse or promote products | ||
+// derived from this software without specific prior written permission. | ||
+// | ||
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
+// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | ||
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
+/////////////////////////////////////////////////////////////////////////////// | ||
+#include "CalwFlash.h" | ||
+ | ||
+#include <assert.h> | ||
+#include <unistd.h> | ||
+#include <stdio.h> | ||
+ | ||
+#define CALW_KEY 0xa5 | ||
+ | ||
+#define CALW_FCR (_regs + 0x00) | ||
+#define CALW_FCMD (_regs + 0x04) | ||
+#define CALW_FSR (_regs + 0x08) | ||
+#define CALW_FPR (_regs + 0x0C) | ||
+ | ||
+#define CALW_FCMD_NOP 0x00 | ||
+#define CALW_FCMD_WP 0x01 | ||
+#define CALW_FCMD_EP 0x02 | ||
+#define CALW_FCMD_CPB 0x03 | ||
+#define CALW_FCMD_LP 0x04 | ||
+#define CALW_FCMD_UP 0x05 | ||
+#define CALW_FCMD_EA 0x06 | ||
+#define CALW_FCMD_WGPB 0x07 | ||
+#define CALW_FCMD_EGPB 0x08 | ||
+#define CALW_FCMD_SSB 0x09 | ||
+#define CALW_FCMD_PGPFB 0x0a | ||
+#define CALW_FCMD_EAGPF 0x0b | ||
+#define CALW_FCMD_QPR 0x0c | ||
+#define CALW_FCMD_WUP 0x0d | ||
+#define CALW_FCMD_EUP 0x0e | ||
+#define CALW_FCMD_QPRUP 0x0f | ||
+#define CALW_FCMD_HSEN 0x10 | ||
+#define CALW_FCMD_HSDIS 0x11 | ||
+ | ||
+CalwFlash::CalwFlash(Samba& samba, | ||
+ const std::string& name, | ||
+ uint32_t addr, | ||
+ uint32_t pages, | ||
+ uint32_t size, | ||
+ uint32_t planes, | ||
+ uint32_t lockRegions, | ||
+ uint32_t user, | ||
+ uint32_t stack, | ||
+ uint32_t regs) | ||
+ : Flash(samba, name, addr, pages, size, planes, lockRegions, user, stack), | ||
+ _regs(regs) | ||
+{ | ||
+ assert(planes == 1); | ||
+ assert(pages <= 1024); | ||
+ assert(lockRegions <= 16); | ||
+ | ||
+ // Force 1WS | ||
+ writeFCR(0x40); | ||
+} | ||
+ | ||
+CalwFlash::~CalwFlash() | ||
+{ | ||
+} | ||
+ | ||
+void | ||
+CalwFlash::eraseAll(uint32_t offset) | ||
+{ | ||
+ // Do NOT a full chip erase, SAM-BA bootloader resides at offset lower than 0x4000 | ||
+ if (offset < 0x4000) | ||
+ { | ||
+ throw FlashOverrideSambaError(); | ||
+ } | ||
+ // Else we must do it by pages | ||
+ else | ||
+ { | ||
+ // Offset must be on an erase page boundary | ||
+ if (offset % _size) | ||
+ throw FlashEraseError(); | ||
+ | ||
+ // Erase each PagesPerErase set of pages | ||
+ for (uint32_t pageNum = offset / _size; pageNum < _pages; pageNum++) | ||
+ { | ||
+ waitFSR(); | ||
+ writeFCMD(CALW_FCMD_EP, pageNum); | ||
+ } | ||
+ } | ||
+} | ||
+ | ||
+std::vector<bool> | ||
+CalwFlash::getLockRegions() | ||
+{ | ||
+ std::vector<bool> regions(_lockRegions); | ||
+ uint32_t locks; | ||
+ | ||
+ waitFSR(); | ||
+ locks = readFSR(); | ||
+ locks >>= 16; | ||
+ for (uint32_t region = 0; region < _lockRegions; region++) | ||
+ { | ||
+ regions[region] = locks & (1 << region); | ||
+ } | ||
+ | ||
+ return regions; | ||
+} | ||
+ | ||
+void | ||
+CalwFlash::writePage(uint32_t page) | ||
+{ | ||
+ if (page >= _pages) | ||
+ throw FlashPageError(); | ||
+ | ||
+ waitFSR(); | ||
+ writeFCMD(CALW_FCMD_CPB, 0); | ||
+ | ||
+ _wordCopy.setDstAddr(_addr + (page * _size)); | ||
+ _wordCopy.setSrcAddr(_onBufferA ? _pageBufferA : _pageBufferB); | ||
+ _wordCopy.setWords(_size / sizeof(uint32_t)); | ||
+ _onBufferA = !_onBufferA; | ||
+ waitFSR(); | ||
+ _wordCopy.runv(); | ||
+ writeFCMD(CALW_FCMD_WP, page); | ||
+} | ||
+ | ||
+void | ||
+CalwFlash::readPage(uint32_t page, uint8_t* data) | ||
+{ | ||
+ if (page >= _pages) | ||
+ throw FlashPageError(); | ||
+ | ||
+ waitFSR(); | ||
+ _samba.read(_addr + page * _size, data, _size); | ||
+} | ||
+ | ||
+void | ||
+CalwFlash::resetCPU(void) | ||
+{ | ||
+ printf("Reset CPU\n"); | ||
+} | ||
+ | ||
+void | ||
+CalwFlash::waitFSR(int seconds) | ||
+{ | ||
+ int tries = seconds * 1000; | ||
+ uint32_t fsr0; | ||
+ | ||
+ while (tries-- > 0) | ||
+ { | ||
+ fsr0 = _samba.readWord(CALW_FSR); | ||
+ if (fsr0 & 0x8) | ||
+ throw FlashCmdError(); | ||
+ if (fsr0 & 0x4) | ||
+ throw FlashLockError(); | ||
+ if (fsr0 & 0x1) | ||
+ break; | ||
+ usleep(1000); | ||
+ } | ||
+ if (tries == 0) | ||
+ throw FlashTimeoutError(); | ||
+} | ||
+ | ||
+void | ||
+CalwFlash::writeFCR(uint32_t arg) | ||
+{ | ||
+ _samba.writeWord(CALW_FCR, arg); | ||
+} | ||
+ | ||
+void | ||
+CalwFlash::writeFCMD(uint8_t cmd, uint32_t arg) | ||
+{ | ||
+ _samba.writeWord(CALW_FCMD, (CALW_KEY << 24) | (arg << 8) | cmd); | ||
+} | ||
+ | ||
+uint32_t | ||
+CalwFlash::readFSR() | ||
+{ | ||
+ return _samba.readWord(CALW_FSR); | ||
+} | ||
diff --git a/src/CalwFlash.h b/src/CalwFlash.h | ||
new file mode 100644 | ||
index 0000000..de17a3f | ||
--- /dev/null | ||
+++ b/src/CalwFlash.h | ||
@@ -0,0 +1,84 @@ | ||
+/////////////////////////////////////////////////////////////////////////////// | ||
+// BOSSA | ||
+// | ||
+// Copyright (c) 2011-2020, ShumaTech | ||
+// All rights reserved. | ||
+// | ||
+// Redistribution and use in source and binary forms, with or without | ||
+// modification, are permitted provided that the following conditions are met: | ||
+// * Redistributions of source code must retain the above copyright | ||
+// notice, this list of conditions and the following disclaimer. | ||
+// * Redistributions in binary form must reproduce the above copyright | ||
+// notice, this list of conditions and the following disclaimer in the | ||
+// documentation and/or other materials provided with the distribution. | ||
+// * Neither the name of the <organization> nor the | ||
+// names of its contributors may be used to endorse or promote products | ||
+// derived from this software without specific prior written permission. | ||
+// | ||
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
+// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | ||
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
+/////////////////////////////////////////////////////////////////////////////// | ||
+#ifndef _CALWFLASH_H | ||
+#define _CALWFLASH_H | ||
+ | ||
+#include <stdint.h> | ||
+#include <exception> | ||
+ | ||
+#include "Flash.h" | ||
+ | ||
+class CalwFlash : public Flash | ||
+{ | ||
+public: | ||
+ CalwFlash(Samba& samba, | ||
+ const std::string& name, | ||
+ uint32_t addr, | ||
+ uint32_t pages, | ||
+ uint32_t size, | ||
+ uint32_t planes, | ||
+ uint32_t lockRegions, | ||
+ uint32_t user, | ||
+ uint32_t stack, | ||
+ uint32_t regs); | ||
+ virtual ~CalwFlash(); | ||
+ | ||
+ void eraseAll(uint32_t offset); | ||
+ void eraseAuto(bool enable) { } | ||
+ | ||
+ std::vector<bool> getLockRegions(); | ||
+ | ||
+ bool getSecurity() { return false; } | ||
+ | ||
+ bool getBod() { return false; } | ||
+ bool canBod() { return true; } | ||
+ | ||
+ bool getBor() { return false; } | ||
+ bool canBor() { return false; } | ||
+ | ||
+ bool getBootFlash() { return false; } | ||
+ bool canBootFlash() { return true; } | ||
+ | ||
+ void writeOptions() { } | ||
+ | ||
+ void writePage(uint32_t page); | ||
+ void readPage(uint32_t page, uint8_t* data); | ||
+ | ||
+ void resetCPU(void); | ||
+ | ||
+private: | ||
+ uint32_t _regs; | ||
+ | ||
+ void writeFCR(uint32_t arg); | ||
+ void writeFCMD(uint8_t cmd, uint32_t arg); | ||
+ void waitFSR(int seconds = 1); | ||
+ uint32_t readFSR(); | ||
+}; | ||
+ | ||
+#endif // _CALWFLASH_H | ||
-- | ||
2.25.4 | ||
|
Oops, something went wrong.