├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── appletgen ├── install ├── Info.plist ├── background.png ├── background.xcf ├── banner.bmp ├── bossa-difx.wxs ├── bossa-dpinst.wxs ├── bossa.cat ├── bossa.inf ├── bossa.wxs ├── dialog.bmp ├── dialog.xcf ├── dmgwin.osa └── license.rtf ├── res ├── BossaIcon.bmp ├── BossaIcon.icns ├── BossaIcon.ico ├── BossaIcon.xcf ├── BossaLogo.bmp ├── BossaLogo.xcf ├── BossaRes.rc ├── ShumaTechLogo.bmp └── ShumaTechLogo.xcf └── src ├── Applet.cpp ├── Applet.h ├── BSDPortFactory.cpp ├── BSDPortFactory.h ├── BossaAbout.cpp ├── BossaAbout.h ├── BossaApp.cpp ├── BossaApp.h ├── BossaBitmaps.cpp ├── BossaBitmaps.h ├── BossaForm.cpp ├── BossaForm.fbp ├── BossaForm.h ├── BossaIcon.cpp ├── BossaInfo.cpp ├── BossaInfo.h ├── BossaLogo.cpp ├── BossaProgress.cpp ├── BossaProgress.h ├── BossaThread.cpp ├── BossaThread.h ├── BossaWindow.cpp ├── BossaWindow.h ├── CmdOpts.cpp ├── CmdOpts.h ├── Command.cpp ├── Command.h ├── D2xNvmFlash.cpp ├── D2xNvmFlash.h ├── D5xNvmFlash.cpp ├── D5xNvmFlash.h ├── Device.cpp ├── Device.h ├── Driver.h ├── EefcFlash.cpp ├── EefcFlash.h ├── EfcFlash.cpp ├── EfcFlash.h ├── FileError.h ├── Flash.cpp ├── Flash.h ├── Flasher.cpp ├── Flasher.h ├── LinuxPortFactory.cpp ├── LinuxPortFactory.h ├── NullFlash.cpp ├── NullFlash.h ├── OSXPortFactory.cpp ├── OSXPortFactory.h ├── PortFactory.h ├── PosixSerialPort.cpp ├── PosixSerialPort.h ├── Samba.cpp ├── Samba.h ├── SerialPort.h ├── Shell.cpp ├── Shell.h ├── ShumaTechLogo.cpp ├── TemplateArm.asm ├── WinPortFactory.cpp ├── WinPortFactory.h ├── WinSerialPort.cpp ├── WinSerialPort.h ├── WordCopyApplet.cpp ├── WordCopyApplet.h ├── WordCopyArm.asm ├── WordCopyArm.cpp ├── WordCopyArm.h ├── bossac.cpp └── bossash.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | obj 3 | *.exe 4 | *~ 5 | bossa 6 | bossac 7 | bin 8 | *.swp 9 | tags 10 | *.bak 11 | install/*.crt 12 | install/*.p12 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2016, ShumaTech 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BOSSA 1.9.1 2 | ----------- 3 | 4 | BOSSA is a flash programming utility for Atmel's SAM family of flash-based ARM microcontrollers. 5 | The motivation behind BOSSA is to create a simple, easy-to-use, open source utility to replace Atmel's SAM-BA software. 6 | BOSSA is an acronym for Basic Open Source SAM-BA Application to reflect that goal. 7 | 8 | The software was created by Scott Shumate with contributions from several 9 | [contributors](https://github.com/shumatech/BOSSA/graphs/contributors). 10 | 11 | The software is released under the terms of the BSD license as specified in the LICENSE file. 12 | 13 | Supported Device Families 14 | ------------------------- 15 | * SAM7S 16 | * SAM7SE 17 | * SAM7X 18 | * SAM7XC 19 | * SAM3N 20 | * SAM3S 21 | * SAM3U 22 | * SAM4E 23 | * SAM4S 24 | * SAMD21 25 | * SAMD51 26 | * SAM3X\* 27 | * SAM3A\* 28 | * SAM7L\* 29 | * SAM9XE\* 30 | * SAMR21\* 31 | * SAML21\* 32 | * SAME51\* 33 | * SAME53\* 34 | * SAME54\* 35 | * SAME70\* 36 | * SAMS70\* 37 | * SAMV70\* 38 | * SAMV71\* 39 | 40 | \* Device families which are not tested for each release and could stop working. 41 | 42 | Do you want to help make sure a device family is tested or do you want to see a new device family added? Then contribute a development board with a device from that family to the BOSSA project to make it happen. Contact scott at shumatech.com if you are interested in helping the project. 43 | 44 | The following individuals and companies graciously provided development boards to assist the BOSSA project. 45 | * Atmel Corporation (SAM3N, SAM3S, SAM3U) 46 | * David Crocker (SAM4E, SAM4S) 47 | * Adafruit Industries (SAMD21, SAMD51) 48 | -------------------------------------------------------------------------------- /appletgen: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -ne 3 ]; then 4 | echo "Usage: $0 " 5 | exit 1; 6 | fi 7 | 8 | ARM=$1 9 | SRCDIR=$2 10 | OBJDIR=$3 11 | 12 | APPLET=${ARM/%Arm/Applet} 13 | BINFILE=$OBJDIR/$ARM.bin 14 | OBJFILE=$OBJDIR/$ARM.obj 15 | CPPFILE=$SRCDIR/$ARM.cpp 16 | HFILE=$SRCDIR/$ARM.h 17 | SIZE=$(stat -c%s $BINFILE) 18 | 19 | if [ ! -f $BINFILE ]; then 20 | echo "$BINFILE does not exist" 21 | exit -1 22 | fi 23 | 24 | if [ ! -f $OBJFILE ]; then 25 | echo "$OBJFILE does not exist" 26 | exit -1 27 | fi 28 | 29 | # Generate the header file 30 | DEFINE=_$(echo $1 | tr '[:lower:]' '[:upper:]')_H 31 | cat > $HFILE << EOF 32 | // WARNING!!! DO NOT EDIT - FILE GENERATED BY APPLETGEN 33 | #ifndef $DEFINE 34 | #define $DEFINE 35 | 36 | #include 37 | 38 | typedef struct 39 | { 40 | EOF 41 | nm -g $OBJFILE | awk '{print " uint32_t "$3";"}' >> $HFILE 42 | cat >> $HFILE << EOF 43 | uint8_t code[$SIZE]; 44 | } $1; 45 | 46 | #endif // $DEFINE 47 | EOF 48 | 49 | # Generate the C file 50 | cat > $CPPFILE << EOF 51 | // WARNING!!! DO NOT EDIT - FILE GENERATED BY APPLETGEN 52 | #include "$ARM.h" 53 | #include "$APPLET.h" 54 | 55 | $ARM $APPLET::applet = { 56 | EOF 57 | nm -g $OBJFILE | awk '{print "// "$3"\n0x"$1","}' >> $CPPFILE 58 | cat >> $CPPFILE << EOF 59 | // code 60 | { 61 | EOF 62 | od -t x1 $BINFILE | awk '{for(n=2;n<=NF;n++){printf("0x"$n", ")}if(NF>1)print""}' >> $CPPFILE 63 | cat >> $CPPFILE << EOF 64 | } 65 | }; 66 | EOF 67 | 68 | -------------------------------------------------------------------------------- /install/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | bossa 9 | CFBundleIconFile 10 | BossaIcon.icns 11 | CFBundleIdentifier 12 | ShumaTech.BOSSA 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | BOSSA 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.1 25 | LSMinimumSystemVersion 26 | 10.6 27 | NSPrincipalClass 28 | NSApplication 29 | CFBundleGetInfoString 30 | BOSSA version 1.1, (c) 2011-2012 ShumaTech 31 | CFBundleLongVersionString 32 | 1.1, (c) 2011-2012 ShumaTech 33 | NSHumanReadableCopyright 34 | Copyright 20011-2012 ShumaTech 35 | LSRequiresCarbon 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /install/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/install/background.png -------------------------------------------------------------------------------- /install/background.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/install/background.xcf -------------------------------------------------------------------------------- /install/banner.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/install/banner.bmp -------------------------------------------------------------------------------- /install/bossa-difx.wxs: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 16 | 20 | 21 | 24 | 25 | 27 | 28 | 30 | 33 | 37 | 41 | 42 | 45 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 64 | 69 | 74 | 76 | 82 | 83 | 84 | 85 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 97 | 98 | 100 | 102 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /install/bossa-dpinst.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 19 | 20 | 23 | 24 | 26 | 27 | 29 | 32 | 36 | 40 | 41 | 43 | 47 | 48 | 50 | 54 | NOT VersionNT64 55 | 56 | 58 | 62 | VersionNT64 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 74 | 79 | 84 | 86 | 92 | 93 | 94 | 95 | 98 | 100 | 101 | NOT VersionNT64 102 | 103 | 105 | 106 | VersionNT64 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 121 | 127 | 128 | 130 | 131 | 133 | 135 | 137 | 138 | 139 | 140 | 141 | 142 | NOT Installed 143 | Installed 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /install/bossa.cat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/install/bossa.cat -------------------------------------------------------------------------------- /install/bossa.inf: -------------------------------------------------------------------------------- 1 | [Version] ; Version section 2 | Signature="$Chicago$" ; All Windows versions 3 | Class=Ports ; This is a serial port driver 4 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} ; Associated GUID 5 | Provider=%SHUMATECH% ; Driver is provided by SHUMATECH 6 | DriverVer=05/18/2011,1.0 ; Driver version 7 | CatalogFile=bossa.cat ; Catalog file 8 | DriverPackageDisplayName=%BOSSA% ; Driver display name 9 | 10 | [DestinationDirs] ; DestinationDirs section 11 | DefaultDestDir=12 ; Default install directory is \drivers or \IOSubSys 12 | 13 | [Manufacturer] ; Manufacturer section 14 | %SHUMATECH%=ShumaTech,NTamd64 ; Only one manufacturer (SHUMATECH), models section is named 15 | ; ShumaTech 16 | 17 | [ShumaTech] ; Models section corresponding to SHUMATECH 18 | %BOSSA%=BOSSA.Install,USB\VID_03EB&PID_6124 ; Identifies a device with Vendor ID (03EBh) and 19 | ; Product ID equal to 6124h. Corresponding Install section 20 | ; is named BOSSA.Install 21 | 22 | [ShumaTech.NTamd64] ; Models section corresponding to SHUMATECH 23 | %BOSSA%=BOSSA.Install,USB\VID_03EB&PID_6124 ; Identifies a device with Vendor ID (03EBh) and 24 | ; Product ID equal to 6124h. Corresponding Install section 25 | ; is named BOSSA.Install 26 | 27 | [BOSSA.Install] ; Install section 28 | include=mdmcpq.inf 29 | CopyFiles=FakeModemCopyFileSection 30 | AddReg=BOSSA.AddReg ; Registry keys to add are listed in BOSSA.AddReg 31 | 32 | [BOSSA.AddReg] ; AddReg section 33 | HKR,,DevLoader,,*ntkern 34 | HKR,,NTMPDriver,,usbser.sys 35 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 36 | 37 | [BOSSA.Install.Services] ; Services section 38 | AddService=usbser,0x00000002,BOSSA.AddService ; Assign usbser as the PnP driver for the device 39 | 40 | [BOSSA.AddService] ; Service install section 41 | DisplayName=%USBSer% ; Name of the serial driver 42 | ServiceType=1 ; Service kernel driver 43 | StartType=3 ; Driver is started by the PnP manager 44 | ErrorControl=1 ; Warn about errors 45 | ServiceBinary=%12%\usbser.sys ; Driver filename 46 | 47 | [Strings] ; Strings section 48 | SHUMATECH="ShumaTech" ; String value for the SHUMATECH symbol 49 | BOSSA="BOSSA Program Port" ; String value for the BOSSA symbol 50 | USBSer="USB Serial Driver" ; String value for the USBSer symbol 51 | -------------------------------------------------------------------------------- /install/bossa.wxs: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 19 | 20 | 23 | 24 | 26 | 27 | 29 | 32 | 36 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 62 | 67 | 72 | 74 | 80 | 81 | 82 | 83 | 84 | 86 | 90 | 94 | 98 | 99 | 100 | 101 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | NOT VersionNT64 114 | 115 | 116 | 117 | 119 | 120 | 122 | 124 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /install/dialog.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/install/dialog.bmp -------------------------------------------------------------------------------- /install/dialog.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/install/dialog.xcf -------------------------------------------------------------------------------- /install/dmgwin.osa: -------------------------------------------------------------------------------- 1 | tell application "Finder" 2 | tell disk "BOSSA" 3 | open 4 | set current view of container window to icon view 5 | set toolbar visible of container window to false 6 | set statusbar visible of container window to false 7 | set the bounds of container window to {400, 100, 893, 432} 8 | set theViewOptions to the icon view options of container window 9 | set arrangement of theViewOptions to not arranged 10 | set icon size of theViewOptions to 64 11 | set text size of theViewOptions to 16 12 | set background picture of theViewOptions to file ".background:background.png" 13 | set position of item "BOSSA" of container window to {220, 40} 14 | set position of item "bossac" of container window to {220, 150} 15 | set position of item "bossash" of container window to {220, 250} 16 | set position of item "Applications" of container window to {420, 40} 17 | set position of item "bin" of container window to {420, 200} 18 | update without registering applications 19 | delay 2 20 | end tell 21 | end tell 22 | -------------------------------------------------------------------------------- /install/license.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\fmodern\fprq1\fcharset0 Lucida Console;}{\f1\fswiss\fprq2\fcharset0 Arial;}} 2 | {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\nowidctlpar\f0\fs18 BOSSA - Flash Programmer for Atmel SAM Devices\par 3 | Copyright (c) 2011-2018, ShumaTech\par 4 | All rights reserved.\par 5 | \par 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\par 7 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\par 8 | * 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.\par 9 | * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\par 10 | \par 11 | 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 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.\f1\fs20\par 12 | } 13 | 14 | -------------------------------------------------------------------------------- /res/BossaIcon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/res/BossaIcon.bmp -------------------------------------------------------------------------------- /res/BossaIcon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/res/BossaIcon.icns -------------------------------------------------------------------------------- /res/BossaIcon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/res/BossaIcon.ico -------------------------------------------------------------------------------- /res/BossaIcon.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/res/BossaIcon.xcf -------------------------------------------------------------------------------- /res/BossaLogo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/res/BossaLogo.bmp -------------------------------------------------------------------------------- /res/BossaLogo.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/res/BossaLogo.xcf -------------------------------------------------------------------------------- /res/BossaRes.rc: -------------------------------------------------------------------------------- 1 | BOSSA_ICON ICON BossaIcon.ico 2 | 3 | #include "wx/msw/wx.rc" 4 | -------------------------------------------------------------------------------- /res/ShumaTechLogo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/res/ShumaTechLogo.bmp -------------------------------------------------------------------------------- /res/ShumaTechLogo.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BOSSA/37600d1635f830cc0cdf7c56e586a021272c4e35/res/ShumaTechLogo.xcf -------------------------------------------------------------------------------- /src/Applet.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "Applet.h" 30 | 31 | Applet::Applet(Samba& samba, 32 | uint32_t addr, 33 | uint8_t* code, 34 | uint32_t size, 35 | uint32_t start, 36 | uint32_t stack, 37 | uint32_t reset) : 38 | _samba(samba), _addr(addr), _size(size), _start(start), _stack(stack), _reset(reset) 39 | { 40 | _samba.write(addr, code, size); 41 | } 42 | 43 | void 44 | Applet::setStack(uint32_t stack) 45 | { 46 | _samba.writeWord(_stack, stack); 47 | } 48 | 49 | void 50 | Applet::run() 51 | { 52 | // Add one to the start address for Thumb mode 53 | _samba.go(_start + 1); 54 | } 55 | 56 | void 57 | Applet::runv() 58 | { 59 | // Add one to the start address for Thumb mode 60 | _samba.writeWord(_reset, _start + 1); 61 | 62 | // The stack is the first reset vector 63 | _samba.go(_stack); 64 | } 65 | -------------------------------------------------------------------------------- /src/Applet.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _APPLET_H 30 | #define _APPLET_H 31 | 32 | #include 33 | 34 | #include "Samba.h" 35 | 36 | class Applet 37 | { 38 | public: 39 | Applet(Samba& samba, 40 | uint32_t addr, 41 | uint8_t* code, 42 | uint32_t size, 43 | uint32_t start, 44 | uint32_t stack, 45 | uint32_t reset); 46 | virtual ~Applet() {} 47 | 48 | virtual uint32_t size() { return _size; } 49 | virtual uint32_t addr() { return _addr; } 50 | 51 | virtual void setStack(uint32_t stack); 52 | 53 | virtual void run(); // To be used for Thumb-1 based devices (ARM7TDMI, ARM9) 54 | virtual void runv(); // To be used for Thumb-2 based devices (Cortex-Mx) 55 | 56 | protected: 57 | Samba& _samba; 58 | uint32_t _addr; // Address in device SRAM where will be placed the applet 59 | uint32_t _size; // Applet size 60 | uint32_t _start; // 61 | uint32_t _stack; // Applet stack address in device SRAM 62 | uint32_t _reset; 63 | }; 64 | 65 | #endif // _APPLET_H 66 | -------------------------------------------------------------------------------- /src/BSDPortFactory.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "BSDPortFactory.h" 30 | #include "PosixSerialPort.h" 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | BSDPortFactory::BSDPortFactory() 38 | { 39 | _dir = opendir("/dev"); 40 | } 41 | 42 | BSDPortFactory::~BSDPortFactory() 43 | { 44 | if (_dir) 45 | closedir(_dir); 46 | } 47 | 48 | SerialPort::Ptr 49 | BSDPortFactory::create(const std::string& name) 50 | { 51 | bool isUsb = false; 52 | 53 | if (name.find("U") != std::string::npos) 54 | isUsb = true; 55 | 56 | return create(name, isUsb); 57 | } 58 | 59 | SerialPort::Ptr 60 | BSDPortFactory::create(const std::string& name, bool isUsb) 61 | { 62 | PosixSerialPort *p = new PosixSerialPort(name, isUsb); 63 | // Needed to avoid upload errors 64 | p->setAutoFlush(true); 65 | return SerialPort::Ptr(p); 66 | } 67 | 68 | std::string 69 | BSDPortFactory::begin() 70 | { 71 | if (!_dir) 72 | return end(); 73 | 74 | rewinddir(_dir); 75 | 76 | return next(); 77 | } 78 | 79 | std::string 80 | BSDPortFactory::next() 81 | { 82 | struct dirent* entry; 83 | 84 | if (!_dir) 85 | return end(); 86 | 87 | while ((entry = readdir(_dir))) 88 | { 89 | if (strncmp("cua", entry->d_name, sizeof("cua") - 1) == 0) 90 | return std::string(entry->d_name); 91 | } 92 | 93 | return end(); 94 | } 95 | 96 | std::string 97 | BSDPortFactory::end() 98 | { 99 | return std::string(); 100 | } 101 | 102 | std::string 103 | BSDPortFactory::def() 104 | { 105 | return std::string("/dev/cuaU0"); 106 | } 107 | -------------------------------------------------------------------------------- /src/BSDPortFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _BSDPORTFACTORY_H 30 | #define _BSDPORTFACTORY_H 31 | 32 | class BSDPortFactory; 33 | #include "PortFactory.h" 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | 41 | class BSDPortFactory : public PortFactoryBase 42 | { 43 | public: 44 | BSDPortFactory(); 45 | virtual ~BSDPortFactory(); 46 | 47 | virtual std::string begin(); 48 | virtual std::string end(); 49 | virtual std::string next(); 50 | virtual std::string def(); 51 | 52 | virtual SerialPort::Ptr create(const std::string& name); 53 | virtual SerialPort::Ptr create(const std::string& name, bool isUsb); 54 | 55 | private: 56 | std::string _empty; 57 | DIR* _dir; 58 | }; 59 | 60 | #endif // _BSDPORTFACTORY_H 61 | -------------------------------------------------------------------------------- /src/BossaAbout.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "BossaAbout.h" 30 | #include "BossaApp.h" 31 | 32 | #include "wx/version.h" 33 | 34 | BossaAbout::BossaAbout(wxWindow* parent) : AboutDialog(parent) 35 | { 36 | BossaApp& app = wxGetApp(); 37 | 38 | _bossaBitmap->SetBitmap(app.bitmaps.getBossaLogo()); 39 | _shumatechBitmap->SetBitmap(app.bitmaps.getShumaTechLogo()); 40 | _versionStaticText->SetLabel(wxString::Format(wxT("Version: %s"), VERSION)); 41 | _wxStaticText->SetLabel(wxString::Format(wxT("Built with %s"), wxVERSION_STRING)); 42 | GetSizer()->Fit(this); 43 | } 44 | -------------------------------------------------------------------------------- /src/BossaAbout.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _BOSSAABOUT_H 30 | #define _BOSSAABOUT_H 31 | 32 | #include "BossaForm.h" 33 | 34 | class BossaAbout : public AboutDialog 35 | { 36 | public: 37 | BossaAbout(wxWindow* parent); 38 | }; 39 | 40 | #endif // _BOSSAABOUT_H 41 | -------------------------------------------------------------------------------- /src/BossaApp.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "BossaApp.h" 30 | 31 | BossaApp::BossaApp() : config(_("Bossa")), device(samba) 32 | { 33 | } 34 | 35 | bool 36 | BossaApp::OnInit() 37 | { 38 | bitmaps.init(); 39 | _window = new BossaWindow(); 40 | _window->Show(true); 41 | SetTopWindow(_window); 42 | 43 | return true; 44 | } 45 | 46 | IMPLEMENT_APP(BossaApp) 47 | -------------------------------------------------------------------------------- /src/BossaApp.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _BOSSAAPP_H 30 | #define _BOSSAAPP_H 31 | 32 | #include 33 | #include 34 | 35 | #include "PortFactory.h" 36 | #include "Samba.h" 37 | #include "Flash.h" 38 | #include "BossaBitmaps.h" 39 | #include "BossaWindow.h" 40 | 41 | class BossaApp : public wxApp 42 | { 43 | public: 44 | BossaApp(); 45 | 46 | wxConfig config; 47 | PortFactory portFactory; 48 | Samba samba; 49 | BossaBitmaps bitmaps; 50 | Device device; 51 | 52 | private: 53 | bool OnInit(); 54 | 55 | BossaWindow* _window; 56 | }; 57 | 58 | DECLARE_APP(BossaApp) 59 | 60 | #endif // _BOSSAAPP_H 61 | -------------------------------------------------------------------------------- /src/BossaBitmaps.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "BossaBitmaps.h" 30 | 31 | #include 32 | 33 | #include "BossaLogo.cpp" 34 | #include "BossaIcon.cpp" 35 | #include "ShumaTechLogo.cpp" 36 | 37 | BossaBitmaps::BossaBitmaps() 38 | { 39 | } 40 | 41 | void 42 | BossaBitmaps::init() 43 | { 44 | _bossaLogo = GetBitmapFromMemory(BossaLogo_bmp, sizeof(BossaLogo_bmp)); 45 | _bossaIcon = GetBitmapFromMemory(BossaIcon_bmp, sizeof(BossaIcon_bmp)); 46 | _shumaTechLogo = GetBitmapFromMemory(ShumaTechLogo_bmp, sizeof(ShumaTechLogo_bmp)); 47 | } 48 | 49 | wxBitmap 50 | BossaBitmaps::GetBitmapFromMemory(const unsigned char *data, int length) 51 | { 52 | wxMemoryInputStream is(data, length); 53 | return wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1); 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/BossaBitmaps.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _BOSSABITMAPS_H 30 | #define _BOSSABITMAPS_H 31 | 32 | #include 33 | 34 | class BossaBitmaps 35 | { 36 | public: 37 | BossaBitmaps(); 38 | 39 | void init(); 40 | 41 | const wxBitmap& getBossaLogo() { return _bossaLogo; } 42 | const wxBitmap& getBossaIcon() { return _bossaIcon; } 43 | const wxBitmap& getShumaTechLogo() { return _shumaTechLogo; } 44 | 45 | private: 46 | wxBitmap GetBitmapFromMemory(const unsigned char *data, int length); 47 | 48 | wxBitmap _bossaLogo; 49 | wxBitmap _bossaIcon; 50 | wxBitmap _shumaTechLogo; 51 | }; 52 | 53 | #endif // _BOSSABITMAPS_H 54 | -------------------------------------------------------------------------------- /src/BossaForm.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // C++ code generated with wxFormBuilder (version Apr 13 2017) 3 | // http://www.wxformbuilder.org/ 4 | // 5 | // PLEASE DO "NOT" EDIT THIS FILE! 6 | /////////////////////////////////////////////////////////////////////////// 7 | 8 | #ifndef __BOSSAFORM_H__ 9 | #define __BOSSAFORM_H__ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | /////////////////////////////////////////////////////////////////////////// 38 | 39 | 40 | /////////////////////////////////////////////////////////////////////////////// 41 | /// Class MainFrame 42 | /////////////////////////////////////////////////////////////////////////////// 43 | class MainFrame : public wxFrame 44 | { 45 | private: 46 | 47 | protected: 48 | wxStaticBitmap* _bossaBitmap; 49 | wxStaticText* _titleText; 50 | wxButton* _aboutButton; 51 | wxComboBox* _portComboBox; 52 | wxButton* _refreshButton; 53 | wxFilePickerCtrl* _filePicker; 54 | wxCheckBox* _eraseCheckBox; 55 | wxCheckBox* _bootCheckBox; 56 | wxCheckBox* _bodCheckBox; 57 | wxCheckBox* _borCheckBox; 58 | wxCheckBox* _lockCheckBox; 59 | wxCheckBox* _securityCheckBox; 60 | wxStaticText* _sizeStaticText; 61 | wxTextCtrl* _sizeTextCtrl; 62 | wxStaticText* _offsetStaticText; 63 | wxTextCtrl* _offsetTextCtrl; 64 | wxButton* _writeButton; 65 | wxButton* _verifyButton; 66 | wxButton* _readButton; 67 | wxButton* _infoButton; 68 | wxButton* _exitButton; 69 | wxStatusBar* _statusBar; 70 | 71 | public: 72 | 73 | MainFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("BOSSA"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 550,400 ), long style = wxCAPTION|wxCLOSE_BOX|wxICONIZE|wxMINIMIZE|wxMINIMIZE_BOX|wxSYSTEM_MENU|wxTAB_TRAVERSAL ); 74 | 75 | ~MainFrame(); 76 | 77 | }; 78 | 79 | /////////////////////////////////////////////////////////////////////////////// 80 | /// Class ProgressDialog 81 | /////////////////////////////////////////////////////////////////////////////// 82 | class ProgressDialog : public wxDialog 83 | { 84 | private: 85 | 86 | protected: 87 | wxStaticText* _infoStaticText; 88 | wxGauge* _statusGauge; 89 | wxStdDialogButtonSizer* _sdbSizer; 90 | wxButton* _sdbSizerCancel; 91 | 92 | public: 93 | 94 | ProgressDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Progress"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 300,150 ), long style = wxCAPTION ); 95 | ~ProgressDialog(); 96 | 97 | }; 98 | 99 | /////////////////////////////////////////////////////////////////////////////// 100 | /// Class AboutDialog 101 | /////////////////////////////////////////////////////////////////////////////// 102 | class AboutDialog : public wxDialog 103 | { 104 | private: 105 | 106 | protected: 107 | wxStaticBitmap* _bossaBitmap; 108 | wxStaticText* _titleStaticText; 109 | wxStaticText* _versionStaticText; 110 | wxStaticText* _wxStaticText; 111 | wxStaticLine* m_staticline1; 112 | wxStaticBitmap* _shumatechBitmap; 113 | wxStaticText* _copyrightStaticText; 114 | wxHyperlinkCtrl* _shumatechHyperlink; 115 | wxStaticLine* m_staticline2; 116 | wxStaticText* m_disclaimerStaticText; 117 | wxStaticLine* m_staticline3; 118 | wxStdDialogButtonSizer* _sdbSizer; 119 | wxButton* _sdbSizerOK; 120 | 121 | public: 122 | 123 | AboutDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("About BOSSA"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 300,-1 ), long style = wxDEFAULT_DIALOG_STYLE ); 124 | ~AboutDialog(); 125 | 126 | }; 127 | 128 | /////////////////////////////////////////////////////////////////////////////// 129 | /// Class InfoDialog 130 | /////////////////////////////////////////////////////////////////////////////// 131 | class InfoDialog : public wxDialog 132 | { 133 | private: 134 | 135 | protected: 136 | wxStaticText* _deviceStaticText; 137 | wxTextCtrl* _deviceTextCtrl; 138 | wxStaticText* _versionStaticText; 139 | wxTextCtrl* _versionTextCtrl; 140 | wxStaticText* _pagesStaticText; 141 | wxTextCtrl* _pagesTextCtrl; 142 | wxStaticText* _pageSizeStaticText; 143 | wxTextCtrl* _pageSizeTextCtrl; 144 | wxStaticText* _totalSizeStaticText; 145 | wxTextCtrl* _totalSizeTextCtrl; 146 | wxStaticText* _planesStaticText; 147 | wxTextCtrl* _planesTextCtrl; 148 | wxCheckBox* _bootCheckBox; 149 | wxCheckBox* _bodCheckBox; 150 | wxCheckBox* _securityCheckBox; 151 | wxCheckBox* _borCheckBox; 152 | wxStaticText* _lockStaticText; 153 | wxTextCtrl* _lockTextCtrl; 154 | wxStdDialogButtonSizer* _sdbSizer; 155 | wxButton* _sdbSizerOK; 156 | 157 | public: 158 | 159 | InfoDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Info"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); 160 | ~InfoDialog(); 161 | 162 | }; 163 | 164 | #endif //__BOSSAFORM_H__ 165 | -------------------------------------------------------------------------------- /src/BossaInfo.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "BossaInfo.h" 30 | #include "BossaApp.h" 31 | 32 | #include 33 | 34 | BossaInfo::BossaInfo(wxWindow* parent) : InfoDialog(parent) 35 | { 36 | Samba& samba = wxGetApp().samba; 37 | Device::FlashPtr& flash = wxGetApp().device.getFlash(); 38 | 39 | _deviceTextCtrl->SetValue(wxString(flash->name().c_str(), wxConvUTF8)); 40 | _versionTextCtrl->SetValue(wxString(samba.version().c_str(), wxConvUTF8)); 41 | 42 | _pagesTextCtrl->SetValue(wxString::Format(wxT("%d"), flash->numPages())); 43 | _pageSizeTextCtrl->SetValue(wxString::Format(wxT("%d bytes"), flash->pageSize())); 44 | _totalSizeTextCtrl->SetValue(wxString::Format(wxT("%d KB"),flash->numPages() * flash->pageSize() / 1024)); 45 | _planesTextCtrl->SetValue(wxString::Format(wxT("%d"),flash->numPlanes())); 46 | 47 | _bootCheckBox->Enable(false); 48 | _securityCheckBox->Enable(false); 49 | _bodCheckBox->Enable(false); 50 | _borCheckBox->Enable(false); 51 | 52 | _bootCheckBox->SetValue(flash->getBootFlash()); 53 | _securityCheckBox->SetValue(flash->getSecurity()); 54 | _bodCheckBox->SetValue(flash->getBod()); 55 | _borCheckBox->SetValue(flash->getBor()); 56 | 57 | std::vector lockRegions = flash->getLockRegions(); 58 | bool hasLockRegion = false; 59 | for (uint32_t i = 0; i < lockRegions.size(); i++) 60 | { 61 | if (lockRegions[i]) 62 | { 63 | _lockTextCtrl->AppendText(wxString::Format(wxT("%s%d"), hasLockRegion ? "," : "", i)); 64 | hasLockRegion = true; 65 | } 66 | } 67 | 68 | GetSizer()->Fit(this); 69 | } 70 | -------------------------------------------------------------------------------- /src/BossaInfo.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _BOSSAINFO_H 30 | #define _BOSSAINFO_H 31 | 32 | #include "BossaForm.h" 33 | 34 | class BossaInfo : public InfoDialog 35 | { 36 | public: 37 | BossaInfo(wxWindow* parent); 38 | }; 39 | 40 | #endif // _BOSSAINFO_H 41 | -------------------------------------------------------------------------------- /src/BossaProgress.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "BossaProgress.h" 30 | 31 | DEFINE_LOCAL_EVENT_TYPE(wxEVT_PROGRESS_CANCEL) 32 | 33 | BossaProgress::BossaProgress(wxWindow* parent) : ProgressDialog(parent), _parent(parent) 34 | { 35 | _statusGauge->SetRange(100); 36 | SetValue(0); 37 | 38 | _sdbSizerCancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, 39 | wxCommandEventHandler(BossaProgress::OnCancel), 40 | NULL, this); 41 | } 42 | 43 | void 44 | BossaProgress::SetValue(int pos) 45 | { 46 | _statusGauge->SetValue(pos); 47 | #if __WIN32 48 | // Work around slow update on Windows 49 | _statusGauge->SetValue(pos - 1); 50 | _statusGauge->SetValue(pos); 51 | #endif 52 | } 53 | 54 | void 55 | BossaProgress::SetLabel(const wxString& label) 56 | { 57 | _infoStaticText->SetLabel(label); 58 | } 59 | 60 | void 61 | BossaProgress::OnCancel(wxCommandEvent& event) 62 | { 63 | wxCommandEvent cmd(wxEVT_PROGRESS_CANCEL); 64 | _parent->AddPendingEvent(cmd); 65 | } 66 | -------------------------------------------------------------------------------- /src/BossaProgress.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _BOSSAPROGRESS_H 30 | #define _BOSSAPROGRESS_H 31 | 32 | #include "BossaForm.h" 33 | 34 | DECLARE_LOCAL_EVENT_TYPE(wxEVT_PROGRESS_CANCEL, wxID_ANY) 35 | 36 | class BossaProgress : public ProgressDialog 37 | { 38 | public: 39 | BossaProgress(wxWindow* parent); 40 | 41 | void SetValue(int pos); 42 | void SetLabel(const wxString& label); 43 | 44 | private: 45 | wxEvtHandler* _parent; 46 | 47 | void OnCancel(wxCommandEvent& event); 48 | }; 49 | 50 | #endif // _BOSSAPROGRESS_H 51 | -------------------------------------------------------------------------------- /src/BossaThread.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "BossaThread.h" 30 | #include "BossaApp.h" 31 | #include "Flash.h" 32 | 33 | #include 34 | #include 35 | 36 | using namespace std; 37 | 38 | DEFINE_LOCAL_EVENT_TYPE(wxEVT_THREAD_PROGRESS) 39 | DEFINE_LOCAL_EVENT_TYPE(wxEVT_THREAD_SUCCESS) 40 | DEFINE_LOCAL_EVENT_TYPE(wxEVT_THREAD_WARNING) 41 | DEFINE_LOCAL_EVENT_TYPE(wxEVT_THREAD_ERROR) 42 | 43 | BossaThread::BossaThread(wxEvtHandler* parent) : wxThread(), _parent(parent), _stopped(false) 44 | { 45 | } 46 | 47 | void 48 | BossaThread::Progress(const wxString& message, int pos) 49 | { 50 | wxCommandEvent event(wxEVT_THREAD_PROGRESS); 51 | event.SetString(message); 52 | event.SetInt(pos); 53 | _parent->AddPendingEvent(event); 54 | } 55 | 56 | void 57 | BossaThread::Success(const wxString& message) 58 | { 59 | wxCommandEvent event(wxEVT_THREAD_SUCCESS); 60 | event.SetString(message); 61 | _parent->AddPendingEvent(event); 62 | } 63 | 64 | void 65 | BossaThread::Warning(const wxString& message) 66 | { 67 | wxCommandEvent event(wxEVT_THREAD_WARNING); 68 | event.SetString(message); 69 | _parent->AddPendingEvent(event); 70 | } 71 | 72 | void 73 | BossaThread::Error(const wxString& message) 74 | { 75 | wxCommandEvent event(wxEVT_THREAD_ERROR); 76 | event.SetString(message); 77 | _parent->AddPendingEvent(event); 78 | } 79 | 80 | void 81 | ThreadObserver::onStatus(const char *message, ...) 82 | { 83 | } 84 | 85 | void 86 | ThreadObserver::onProgress(int num, int div) 87 | { 88 | int percent = num * 100 / div; 89 | 90 | if (percent != _lastPercent) 91 | { 92 | _thread->Progress(wxString::Format(wxT("%s page %d (%d%%)"), _operation.mb_str(), num, percent), percent); 93 | _lastPercent = percent; 94 | } 95 | } 96 | 97 | WriteThread::WriteThread(wxEvtHandler* parent, 98 | const wxString& filename, 99 | bool eraseAll, 100 | bool bootFlash, 101 | bool bod, 102 | bool bor, 103 | bool lock, 104 | bool security, 105 | uint32_t offset) : 106 | BossaThread(parent), _filename(filename), _eraseAll(eraseAll), 107 | _bootFlash(bootFlash), _bod(bod), _bor(bor), _lock(lock), _security(security), _offset(offset) 108 | 109 | { 110 | } 111 | 112 | wxThread::ExitCode 113 | WriteThread::Entry() 114 | { 115 | Device& device = wxGetApp().device; 116 | Device::FlashPtr& flash = device.getFlash(); 117 | Samba& samba = wxGetApp().samba; 118 | 119 | try 120 | { 121 | ThreadObserver observer(this, "Writing"); 122 | Flasher flasher(samba, device, observer); 123 | 124 | if (_eraseAll) 125 | { 126 | flash->eraseAll(_offset); 127 | flash->eraseAuto(false); 128 | } 129 | else 130 | { 131 | flash->eraseAuto(true); 132 | } 133 | 134 | flasher.write(_filename.mb_str(), _offset); 135 | 136 | if (flash->canBootFlash()) 137 | flash->setBootFlash(_bootFlash); 138 | if (flash->canBod()) 139 | flash->setBod(_bod); 140 | if (flash->canBor()) 141 | flash->setBor(_bor); 142 | if (_lock) 143 | flash->setLockRegions(std::vector(flash->lockRegions(), true)); 144 | if (_security) 145 | flash->setSecurity(); 146 | flash->writeOptions(); 147 | } 148 | catch(exception& e) 149 | { 150 | Error(wxString(e.what(), wxConvUTF8)); 151 | return 0; 152 | } 153 | 154 | Success(_("Write completed successfully")); 155 | 156 | return 0; 157 | } 158 | 159 | VerifyThread::VerifyThread(wxEvtHandler* parent, const wxString& filename, uint32_t offset) : 160 | BossaThread(parent), _filename(filename), _offset(offset) 161 | { 162 | } 163 | 164 | wxThread::ExitCode 165 | VerifyThread::Entry() 166 | { 167 | Device& device = wxGetApp().device; 168 | Samba& samba = wxGetApp().samba; 169 | uint32_t pageErrors; 170 | uint32_t totalErrors; 171 | 172 | try 173 | { 174 | ThreadObserver observer(this, "Verifying"); 175 | Flasher flasher(samba, device, observer); 176 | 177 | if (!flasher.verify(_filename.mb_str(), pageErrors, totalErrors, _offset)) 178 | { 179 | Warning(wxString::Format(_( 180 | "Verify failed\n" 181 | "Page errors: %d\n" 182 | "Byte errors: %d\n"), 183 | pageErrors, totalErrors)); 184 | return 0; 185 | } 186 | 187 | } 188 | catch(exception& e) 189 | { 190 | Error(wxString(e.what(), wxConvUTF8)); 191 | return 0; 192 | } 193 | 194 | Success(_("Verify successful\n")); 195 | 196 | return 0; 197 | } 198 | 199 | ReadThread::ReadThread(wxEvtHandler* parent, const wxString& filename, size_t size, uint32_t offset) : 200 | BossaThread(parent), _filename(filename), _size(size), _offset(offset) 201 | { 202 | } 203 | 204 | wxThread::ExitCode 205 | ReadThread::Entry() 206 | { 207 | Device& device = wxGetApp().device; 208 | Samba& samba = wxGetApp().samba; 209 | 210 | try 211 | { 212 | ThreadObserver observer(this, "Reading"); 213 | Flasher flasher(samba, device, observer); 214 | 215 | flasher.read(_filename.mb_str(), _size, _offset); 216 | 217 | } 218 | catch(exception& e) 219 | { 220 | Error(wxString(e.what(), wxConvUTF8)); 221 | return 0; 222 | } 223 | 224 | Success(_("Read completed successfully")); 225 | 226 | return 0; 227 | } 228 | -------------------------------------------------------------------------------- /src/BossaThread.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _BOSSATHREAD_H 30 | #define _BOSSATHREAD_H 31 | 32 | #include 33 | 34 | #include "Flasher.h" 35 | 36 | DECLARE_LOCAL_EVENT_TYPE(wxEVT_THREAD_PROGRESS, wxID_ANY) 37 | DECLARE_LOCAL_EVENT_TYPE(wxEVT_THREAD_SUCCESS, wxID_ANY) 38 | DECLARE_LOCAL_EVENT_TYPE(wxEVT_THREAD_WARNING, wxID_ANY) 39 | DECLARE_LOCAL_EVENT_TYPE(wxEVT_THREAD_ERROR, wxID_ANY) 40 | 41 | class BossaThread : public wxThread 42 | { 43 | public: 44 | BossaThread(wxEvtHandler* parent); 45 | 46 | void stop() { _stopped = true; } 47 | 48 | void Progress(const wxString& message, int pos); 49 | void Success(const wxString& message); 50 | void Warning(const wxString& message); 51 | void Error(const wxString& message); 52 | 53 | protected: 54 | wxEvtHandler* _parent; 55 | 56 | bool _stopped; 57 | }; 58 | 59 | class ThreadObserver : public FlasherObserver 60 | { 61 | public: 62 | ThreadObserver(BossaThread* thread, const wxString& operation) : 63 | _thread(thread), _operation(operation), _lastPercent(-1) {} 64 | virtual ~ThreadObserver() {} 65 | 66 | virtual void onStatus(const char *message, ...); 67 | virtual void onProgress(int num, int div); 68 | 69 | private: 70 | BossaThread *_thread; 71 | wxString _operation; 72 | int _lastPercent; 73 | }; 74 | 75 | class WriteThread : public BossaThread 76 | { 77 | public: 78 | WriteThread(wxEvtHandler* parent, 79 | const wxString& filename, 80 | bool eraseAll, 81 | bool bootFlash, 82 | bool bod, 83 | bool bor, 84 | bool lock, 85 | bool security, 86 | uint32_t offset); 87 | wxThread::ExitCode Entry(); 88 | 89 | private: 90 | wxString _filename; 91 | bool _eraseAll; 92 | bool _bootFlash; 93 | bool _bod; 94 | bool _bor; 95 | bool _lock; 96 | bool _security; 97 | uint32_t _offset; 98 | }; 99 | 100 | class VerifyThread : public BossaThread 101 | { 102 | public: 103 | VerifyThread(wxEvtHandler* parent, 104 | const wxString& filename, 105 | uint32_t offset); 106 | wxThread::ExitCode Entry(); 107 | 108 | private: 109 | wxString _filename; 110 | uint32_t _offset; 111 | }; 112 | 113 | class ReadThread : public BossaThread 114 | { 115 | public: 116 | ReadThread(wxEvtHandler* parent, 117 | const wxString& filename, 118 | size_t size, 119 | uint32_t offset); 120 | wxThread::ExitCode Entry(); 121 | 122 | private: 123 | wxString _filename; 124 | size_t _size; 125 | uint32_t _offset; 126 | }; 127 | 128 | #endif // _BOSSAINFO_H 129 | -------------------------------------------------------------------------------- /src/BossaWindow.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _BOSSAWINDOW_H 30 | #define _BOSSAWINDOW_H 31 | 32 | #include 33 | 34 | #include "BossaForm.h" 35 | #include "BossaThread.h" 36 | #include "BossaProgress.h" 37 | 38 | class BossaWindow : public MainFrame 39 | { 40 | public: 41 | BossaWindow(); 42 | virtual ~BossaWindow(); 43 | 44 | private: 45 | BossaThread* _thread; 46 | BossaProgress* _progress; 47 | 48 | void RefreshSerial(); 49 | void CreateDevice(); 50 | void Connected(); 51 | void Disconnected(); 52 | 53 | bool GetOffset(uint32_t& offset); 54 | 55 | void Error(const wxString& message); 56 | void Warning(const wxString& message); 57 | void Info(const wxString& message); 58 | bool Question(const wxString& message); 59 | 60 | void OnAbout(wxCommandEvent& event); 61 | void OnRefresh(wxCommandEvent& event); 62 | void OnSerial(wxCommandEvent& event); 63 | 64 | void OnWrite(wxCommandEvent& event); 65 | void OnVerify(wxCommandEvent& event); 66 | void OnRead(wxCommandEvent& event); 67 | void OnInfo(wxCommandEvent& event); 68 | void OnExit(wxCommandEvent& event); 69 | 70 | void OnThreadProgress(wxCommandEvent& event); 71 | void OnThreadSuccess(wxCommandEvent& event); 72 | void OnThreadWarning(wxCommandEvent& event); 73 | void OnThreadError(wxCommandEvent& event); 74 | 75 | void OnProgressCancel(wxCommandEvent& event); 76 | }; 77 | 78 | #endif // _BOSSAWINDOW_H 79 | -------------------------------------------------------------------------------- /src/CmdOpts.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "CmdOpts.h" 35 | 36 | CmdOpts::CmdOpts(int argc, char* argv[], int numOpts, Option* opts) : 37 | _argc(argc), _argv(argv), _numOpts(numOpts), _opts(opts) 38 | { 39 | } 40 | 41 | CmdOpts::~CmdOpts() 42 | { 43 | } 44 | 45 | void 46 | CmdOpts::usage(FILE* out) 47 | { 48 | int optIdx; 49 | char name[40]; 50 | const char* start; 51 | const char* end; 52 | 53 | for (optIdx = 0; optIdx < _numOpts; optIdx++) 54 | { 55 | if (_opts[optIdx].arg.has == ArgOptional) 56 | snprintf(name, sizeof(name), " -%c, --%s[=%s]", 57 | _opts[optIdx].letter, 58 | _opts[optIdx].name, 59 | _opts[optIdx].arg.name); 60 | else if (_opts[optIdx].arg.has == ArgRequired) 61 | snprintf(name, sizeof(name), " -%c, --%s=%s", 62 | _opts[optIdx].letter, 63 | _opts[optIdx].name, 64 | _opts[optIdx].arg.name); 65 | else 66 | snprintf(name, sizeof(name), " -%c, --%s", 67 | _opts[optIdx].letter, 68 | _opts[optIdx].name); 69 | 70 | fprintf(out, "%-23s ", name); 71 | 72 | start = _opts[optIdx].help; 73 | while ((end = strchr(start, '\n'))) 74 | { 75 | fwrite(start, end - start + 1, 1, out); 76 | fprintf(out, "%24s", ""); 77 | start = end + 1; 78 | } 79 | fprintf(out, "%s\n", start); 80 | } 81 | } 82 | 83 | int 84 | CmdOpts::parse() 85 | { 86 | struct option long_opts[_numOpts + 1]; 87 | char optstring[_numOpts * 3 + 1]; 88 | char* optPtr = optstring; 89 | int optIdx; 90 | int rc; 91 | 92 | for (optIdx = 0; optIdx < _numOpts; optIdx++) 93 | { 94 | *_opts[optIdx].present = false; 95 | 96 | *optPtr++ = _opts[optIdx].letter; 97 | long_opts[optIdx].name = _opts[optIdx].name; 98 | switch (_opts[optIdx].arg.has) 99 | { 100 | default: 101 | case ArgNone: 102 | long_opts[optIdx].has_arg = no_argument; 103 | break; 104 | case ArgOptional: 105 | long_opts[optIdx].has_arg = optional_argument; 106 | *optPtr++ = ':'; 107 | *optPtr++ = ':'; 108 | break; 109 | case ArgRequired: 110 | long_opts[optIdx].has_arg = required_argument; 111 | *optPtr++ = ':'; 112 | break; 113 | } 114 | long_opts[optIdx].flag = NULL; 115 | long_opts[optIdx].val = 0; 116 | } 117 | 118 | memset(&long_opts[_numOpts], 0, sizeof(long_opts[_numOpts])); 119 | *optPtr = '\0'; 120 | optIdx = 0; 121 | while ((rc = getopt_long(_argc, _argv, optstring, long_opts, &optIdx)) != -1) 122 | { 123 | if (rc == '?') 124 | return -1; 125 | 126 | if (rc != 0) 127 | optIdx = find(rc); 128 | 129 | assert(optIdx >= 0 && optIdx < _numOpts); 130 | *_opts[optIdx].present = true; 131 | if (_opts[optIdx].arg.has != ArgNone && optarg) 132 | { 133 | switch (_opts[optIdx].arg.type) 134 | { 135 | case ArgInt: 136 | *_opts[optIdx].arg.value.intPtr = strtol(optarg, NULL, 0); 137 | break; 138 | default: 139 | case ArgString: 140 | *_opts[optIdx].arg.value.strPtr = optarg; 141 | break; 142 | } 143 | } 144 | } 145 | 146 | return optind; 147 | } 148 | 149 | int 150 | CmdOpts::find(char letter) 151 | { 152 | int optIdx; 153 | 154 | for (optIdx = 0; optIdx < _numOpts; optIdx++) 155 | if (_opts[optIdx].letter == letter) 156 | break; 157 | 158 | return optIdx; 159 | } 160 | -------------------------------------------------------------------------------- /src/CmdOpts.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _OPTION_H 30 | #define _OPTION_H 31 | 32 | #include 33 | #include 34 | 35 | typedef enum 36 | { 37 | ArgNone, 38 | ArgOptional, 39 | ArgRequired 40 | } ArgHas; 41 | 42 | typedef enum 43 | { 44 | ArgInt, 45 | ArgString 46 | } ArgType; 47 | 48 | typedef struct 49 | { 50 | ArgHas has; 51 | ArgType type; 52 | const char* name; 53 | union 54 | { 55 | void* voidPtr; 56 | int* intPtr; 57 | std::string* strPtr; 58 | } value; 59 | } OptArg; 60 | 61 | typedef struct 62 | { 63 | char letter; 64 | const char* name; 65 | bool* present; 66 | OptArg arg; 67 | const char* help; 68 | } Option; 69 | 70 | class CmdOpts 71 | { 72 | public: 73 | CmdOpts(int argc, char* argv[], int numOpts, Option* opts); 74 | virtual ~CmdOpts(); 75 | 76 | void usage(FILE* out); 77 | int parse(); 78 | 79 | private: 80 | int _argc; 81 | char** _argv; 82 | int _numOpts; 83 | Option* _opts; 84 | 85 | int find(char letter); 86 | }; 87 | 88 | #endif // _OPTION_H 89 | -------------------------------------------------------------------------------- /src/Command.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _COMMAND_H 30 | #define _COMMAND_H 31 | 32 | #include 33 | 34 | #include "Shell.h" 35 | #include "Samba.h" 36 | #include "PortFactory.h" 37 | #include "Device.h" 38 | #include "Flasher.h" 39 | 40 | class CommandObserver : public FlasherObserver 41 | { 42 | public: 43 | CommandObserver() : _lastTicks(-1) {} 44 | virtual ~CommandObserver() {} 45 | 46 | virtual void onStatus(const char *message, ...); 47 | virtual void onProgress(int num, int div); 48 | private: 49 | int _lastTicks; 50 | }; 51 | 52 | class Command 53 | { 54 | public: 55 | Command(const char* name, const char* help, const char* usage); 56 | virtual ~Command() {} 57 | 58 | virtual void invoke(char* argv[], int argc) = 0; 59 | const char* name() { return _name; }; 60 | const char* help() { return _help; }; 61 | const char* usage() { return _usage; }; 62 | 63 | static void setShell(Shell* shell) { _shell = shell; } 64 | static void disconnect(); 65 | 66 | bool operator < (const Command& rhs); 67 | 68 | protected: 69 | static Shell* _shell; 70 | static Samba _samba; 71 | static PortFactory _portFactory; 72 | static Device _device; 73 | static Device::FlashPtr& _flash; 74 | static Flasher _flasher; 75 | static CommandObserver _observer; 76 | static bool _connected; 77 | 78 | bool error(const char* fmt, ...); 79 | bool argNum(int argc, int num); 80 | bool argRange(int argc, int min, int max); 81 | bool argUint32(const char* arg, uint32_t* value); 82 | bool argBool(const char* arg, bool* value); 83 | bool argState(const char* arg, bool* value); 84 | 85 | bool createDevice(); 86 | bool connected(); 87 | bool flashable(); 88 | 89 | void hexdump(uint32_t addr, uint8_t *buf, size_t count); 90 | const char* binstr(uint32_t value, int bits, char low = '0', char high = '1'); 91 | 92 | private: 93 | const char* _name; 94 | const char* _help; 95 | const char* _usage; 96 | }; 97 | 98 | class CommandBod : public Command 99 | { 100 | public: 101 | CommandBod(); 102 | virtual void invoke(char* argv[], int argc); 103 | }; 104 | 105 | class CommandBootf : public Command 106 | { 107 | public: 108 | CommandBootf(); 109 | virtual void invoke(char* argv[], int argc); 110 | }; 111 | 112 | class CommandBor : public Command 113 | { 114 | public: 115 | CommandBor(); 116 | virtual void invoke(char* argv[], int argc); 117 | }; 118 | 119 | class CommandConnect : public Command 120 | { 121 | public: 122 | CommandConnect(); 123 | virtual void invoke(char* argv[], int argc); 124 | }; 125 | 126 | class CommandDebug : public Command 127 | { 128 | public: 129 | CommandDebug(); 130 | virtual void invoke(char* argv[], int argc); 131 | }; 132 | 133 | class CommandDump : public Command 134 | { 135 | public: 136 | CommandDump(); 137 | virtual void invoke(char* argv[], int argc); 138 | }; 139 | class CommandErase : public Command 140 | { 141 | public: 142 | CommandErase(); 143 | virtual void invoke(char* argv[], int argc); 144 | }; 145 | 146 | class CommandExit : public Command 147 | { 148 | public: 149 | CommandExit(); 150 | virtual void invoke(char* argv[], int argc); 151 | }; 152 | 153 | class CommandGo : public Command 154 | { 155 | public: 156 | CommandGo(); 157 | virtual void invoke(char* argv[], int argc); 158 | }; 159 | 160 | class CommandHelp : public Command 161 | { 162 | public: 163 | CommandHelp(); 164 | virtual void invoke(char* argv[], int argc); 165 | }; 166 | 167 | class CommandHistory : public Command 168 | { 169 | public: 170 | CommandHistory(); 171 | virtual void invoke(char* argv[], int argc); 172 | }; 173 | 174 | class CommandInfo : public Command 175 | { 176 | public: 177 | CommandInfo(); 178 | virtual void invoke(char* argv[], int argc); 179 | }; 180 | 181 | class CommandLock : public Command 182 | { 183 | public: 184 | CommandLock(); 185 | virtual void invoke(char* argv[], int argc); 186 | }; 187 | 188 | class CommandMrb : public Command 189 | { 190 | public: 191 | CommandMrb(); 192 | virtual void invoke(char* argv[], int argc); 193 | }; 194 | 195 | class CommandMrf : public Command 196 | { 197 | public: 198 | CommandMrf(); 199 | virtual void invoke(char* argv[], int argc); 200 | }; 201 | 202 | class CommandMrw : public Command 203 | { 204 | public: 205 | CommandMrw(); 206 | virtual void invoke(char* argv[], int argc); 207 | }; 208 | 209 | class CommandMwb : public Command 210 | { 211 | public: 212 | CommandMwb(); 213 | virtual void invoke(char* argv[], int argc); 214 | }; 215 | 216 | class CommandMwf : public Command 217 | { 218 | public: 219 | CommandMwf(); 220 | virtual void invoke(char* argv[], int argc); 221 | }; 222 | 223 | class CommandMww : public Command 224 | { 225 | public: 226 | CommandMww(); 227 | virtual void invoke(char* argv[], int argc); 228 | }; 229 | 230 | class CommandPio : public Command 231 | { 232 | public: 233 | CommandPio(); 234 | virtual void invoke(char* argv[], int argc); 235 | }; 236 | 237 | class CommandRead : public Command 238 | { 239 | public: 240 | CommandRead(); 241 | virtual void invoke(char* argv[], int argc); 242 | }; 243 | 244 | class CommandSecurity : public Command 245 | { 246 | public: 247 | CommandSecurity(); 248 | virtual void invoke(char* argv[], int argc); 249 | }; 250 | 251 | class CommandUnlock : public Command 252 | { 253 | public: 254 | CommandUnlock(); 255 | virtual void invoke(char* argv[], int argc); 256 | }; 257 | 258 | class CommandVerify : public Command 259 | { 260 | public: 261 | CommandVerify(); 262 | virtual void invoke(char* argv[], int argc); 263 | }; 264 | 265 | class CommandWrite : public Command 266 | { 267 | public: 268 | CommandWrite(); 269 | virtual void invoke(char* argv[], int argc); 270 | }; 271 | 272 | class CommandReset : public Command 273 | { 274 | public: 275 | CommandReset(); 276 | virtual void invoke(char* argv[], int argc); 277 | }; 278 | 279 | class CommandOptions : public Command 280 | { 281 | public: 282 | CommandOptions(); 283 | virtual void invoke(char* argv[], int argc); 284 | }; 285 | 286 | #endif // _COMMAND_H 287 | -------------------------------------------------------------------------------- /src/D2xNvmFlash.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2018, ShumaTech 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | #ifndef _D2XNVMFLASH_H 21 | #define _D2XNVMFLASH_H 22 | 23 | #include 24 | #include 25 | 26 | #include "Flash.h" 27 | 28 | class D2xNvmFlash : public Flash 29 | { 30 | public: 31 | D2xNvmFlash( 32 | Samba& samba, 33 | const std::string& name, 34 | uint32_t pages, 35 | uint32_t size, 36 | uint32_t user, 37 | uint32_t stack); 38 | 39 | virtual ~D2xNvmFlash(); 40 | 41 | void eraseAll(uint32_t offset); 42 | void eraseAuto(bool enable); 43 | 44 | std::vector getLockRegions(); 45 | 46 | bool getSecurity(); 47 | 48 | bool getBod(); 49 | bool canBod() { return true; } 50 | 51 | bool getBor(); 52 | bool canBor() { return true; } 53 | 54 | bool getBootFlash(); 55 | bool canBootFlash() { return false; } 56 | 57 | void writeOptions(); 58 | 59 | void writePage(uint32_t page); 60 | void readPage(uint32_t page, uint8_t* data); 61 | 62 | void writeBuffer(uint32_t dst_addr, uint32_t size); 63 | 64 | protected: 65 | bool _eraseAuto; 66 | 67 | uint32_t readReg(uint8_t reg); 68 | void writeReg(uint8_t reg, uint32_t value); 69 | 70 | void waitReady(); 71 | void command(uint8_t cmd); 72 | void erase(uint32_t offset, uint32_t size); 73 | void readUserRow(std::unique_ptr& userRow); 74 | }; 75 | 76 | #endif // _D2XNVMFLASH_H 77 | -------------------------------------------------------------------------------- /src/D5xNvmFlash.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2018, ShumaTech 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | #ifndef _D5XNVMFLASH_H 21 | #define _D5XNVMFLASH_H 22 | 23 | #include 24 | #include 25 | 26 | #include "Flash.h" 27 | 28 | class D5xNvmFlash : public Flash 29 | { 30 | public: 31 | D5xNvmFlash( 32 | Samba& samba, 33 | const std::string& name, 34 | uint32_t pages, 35 | uint32_t size, 36 | uint32_t user, 37 | uint32_t stack); 38 | 39 | virtual ~D5xNvmFlash(); 40 | 41 | void eraseAll(uint32_t offset); 42 | void eraseAuto(bool enable); 43 | 44 | std::vector getLockRegions(); 45 | 46 | bool getSecurity(); 47 | 48 | bool getBod(); 49 | bool canBod() { return true; } 50 | 51 | bool getBor(); 52 | bool canBor() { return true; } 53 | 54 | bool getBootFlash(); 55 | bool canBootFlash() { return false; } 56 | 57 | void writeOptions(); 58 | 59 | void writePage(uint32_t page); 60 | void readPage(uint32_t page, uint8_t* data); 61 | 62 | void writeBuffer(uint32_t dst_addr, uint32_t size); 63 | 64 | protected: 65 | bool _eraseAuto; 66 | 67 | uint16_t readRegU16(uint8_t reg); 68 | void writeRegU16(uint8_t reg, uint16_t value); 69 | uint32_t readRegU32(uint8_t reg); 70 | void writeRegU32(uint8_t reg, uint32_t value); 71 | 72 | void waitReady(); 73 | void command(uint8_t cmd); 74 | void erase(uint32_t offset, uint32_t size); 75 | void checkError(); 76 | void readUserPage(std::unique_ptr& userPage); 77 | }; 78 | 79 | #endif // _D5XNVMFLASH_H 80 | -------------------------------------------------------------------------------- /src/Device.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _DEVICE_H 30 | #define _DEVICE_H 31 | 32 | #include 33 | 34 | #include "Samba.h" 35 | #include "Flash.h" 36 | 37 | class DeviceUnsupportedError : public std::exception 38 | { 39 | public: 40 | DeviceUnsupportedError() : exception() {}; 41 | const char* what() const throw() { return "Device unsupported"; } 42 | }; 43 | 44 | class Device 45 | { 46 | public: 47 | enum Family { 48 | FAMILY_NONE, 49 | 50 | FAMILY_SAM7S, 51 | FAMILY_SAM7SE, 52 | FAMILY_SAM7X, 53 | FAMILY_SAM7XC, 54 | FAMILY_SAM7L, 55 | 56 | FAMILY_SAM3N, 57 | FAMILY_SAM3S, 58 | FAMILY_SAM3U, 59 | FAMILY_SAM3X, 60 | FAMILY_SAM3A, 61 | 62 | FAMILY_SAM4S, 63 | FAMILY_SAM4E, 64 | 65 | FAMILY_SAM9XE, 66 | 67 | FAMILY_SAMD21, 68 | FAMILY_SAMR21, 69 | FAMILY_SAML21, 70 | 71 | FAMILY_SAMD51, 72 | FAMILY_SAME51, 73 | FAMILY_SAME53, 74 | FAMILY_SAME54, 75 | 76 | FAMILY_SAME70, 77 | FAMILY_SAMS70, 78 | FAMILY_SAMV70, 79 | FAMILY_SAMV71, 80 | 81 | FAMILY_NRF52, 82 | }; 83 | 84 | Device(Samba& samba) : _samba(samba), _flash(nullptr), _family(FAMILY_NONE) {} 85 | virtual ~Device() {} 86 | 87 | void create(); 88 | 89 | Family getFamily() { return _family; } 90 | 91 | typedef std::unique_ptr const FlashPtr; 92 | 93 | FlashPtr& getFlash() { return _flash; } 94 | 95 | void reset(); 96 | 97 | private: 98 | Samba& _samba; 99 | std::unique_ptr _flash; 100 | Family _family; 101 | 102 | void readChipId(uint32_t& chipId, uint32_t& extChipId); 103 | }; 104 | 105 | #endif // _DEVICE_H 106 | 107 | -------------------------------------------------------------------------------- /src/Driver.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _DRIVER_H 30 | #define _DRIVER_H 31 | 32 | class DriverBase 33 | { 34 | public: 35 | DriverBase() {} 36 | virtual ~DriverBase() {} 37 | 38 | virtual bool isInstalled() = 0; 39 | virtual bool install() = 0; 40 | 41 | virtual bool isUpdated() = 0; 42 | virtual bool update() = 0; 43 | }; 44 | 45 | #ifdef __WIN32__ 46 | #include "WinDriver.h" 47 | typedef WinDriver Driver; 48 | #else 49 | #error "Platform is not supported" 50 | #endif 51 | 52 | #endif // _DRIVER_H 53 | -------------------------------------------------------------------------------- /src/EefcFlash.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _EEFCFLASH_H 30 | #define _EEFCFLASH_H 31 | 32 | #include 33 | #include 34 | 35 | #include "Flash.h" 36 | 37 | class EefcFlash : public Flash 38 | { 39 | public: 40 | EefcFlash(Samba& samba, 41 | const std::string& name, 42 | uint32_t addr, 43 | uint32_t pages, 44 | uint32_t size, 45 | uint32_t planes, 46 | uint32_t lockRegions, 47 | uint32_t user, 48 | uint32_t stack, 49 | uint32_t regs, 50 | bool canBrownout); 51 | virtual ~EefcFlash(); 52 | 53 | void eraseAll(uint32_t offset); 54 | void eraseAuto(bool enable); 55 | 56 | std::vector getLockRegions(); 57 | 58 | bool getSecurity(); 59 | 60 | bool getBod(); 61 | bool canBod() { return _canBrownout; } 62 | 63 | bool getBor(); 64 | bool canBor() { return _canBrownout; } 65 | 66 | bool getBootFlash(); 67 | bool canBootFlash() { return true; } 68 | 69 | void writeOptions(); 70 | 71 | void writePage(uint32_t page); 72 | void readPage(uint32_t page, uint8_t* data); 73 | 74 | static const uint32_t PagesPerErase; 75 | 76 | private: 77 | uint32_t _regs; 78 | bool _canBrownout; 79 | bool _eraseAuto; 80 | 81 | void waitFSR(int seconds = 1); 82 | void writeFCR0(uint8_t cmd, uint32_t arg); 83 | void writeFCR1(uint8_t cmd, uint32_t arg); 84 | uint32_t readFRR0(); 85 | uint32_t readFRR1(); 86 | }; 87 | 88 | #endif // _EEFCFLASH_H 89 | -------------------------------------------------------------------------------- /src/EfcFlash.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "EfcFlash.h" 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #define EFC_KEY 0x5a 36 | 37 | #define EFC0_FMR 0xffffff60 38 | #define EFC0_FCR 0xffffff64 39 | #define EFC0_FSR 0xffffff68 40 | 41 | #define EFC1_FMR 0xffffff70 42 | #define EFC1_FCR 0xffffff74 43 | #define EFC1_FSR 0xffffff78 44 | 45 | #define EFC_FCMD_WP 0x1 46 | #define EFC_FCMD_SLB 0x2 47 | #define EFC_FCMD_WPL 0x3 48 | #define EFC_FCMD_CLB 0x4 49 | #define EFC_FCMD_EA 0x8 50 | #define EFC_FCMD_SGPB 0xb 51 | #define EFC_FCMD_CGPB 0xd 52 | #define EFC_FCMD_SSB 0xf 53 | 54 | EfcFlash::EfcFlash(Samba& samba, 55 | const std::string& name, 56 | uint32_t addr, 57 | uint32_t pages, 58 | uint32_t size, 59 | uint32_t planes, 60 | uint32_t lockRegions, 61 | uint32_t user, 62 | uint32_t stack, 63 | bool canBootFlash) 64 | : Flash(samba, name, addr, pages, size, planes, lockRegions, user, stack), 65 | _canBootFlash(canBootFlash) 66 | { 67 | assert(planes == 1 || planes == 2); 68 | assert(pages <= planes * 1024); 69 | assert(lockRegions <= 32); 70 | 71 | eraseAuto(true); 72 | } 73 | 74 | EfcFlash::~EfcFlash() 75 | { 76 | } 77 | 78 | void 79 | EfcFlash::eraseAll(uint32_t offset) 80 | { 81 | if (offset != 0) 82 | throw FlashEraseError(); 83 | 84 | waitFSR(); 85 | writeFCR0(EFC_FCMD_EA, 0); 86 | if (_planes == 2) 87 | { 88 | waitFSR(); 89 | writeFCR0(EFC_FCMD_EA, _pages / 2); 90 | } 91 | } 92 | 93 | void 94 | EfcFlash::eraseAuto(bool enable) 95 | { 96 | uint32_t fmr; 97 | 98 | waitFSR(); 99 | fmr = _samba.readWord(EFC0_FMR); 100 | if (enable) 101 | fmr &= ~(1 << 7); 102 | else 103 | fmr |= (1 << 7); 104 | 105 | _samba.writeWord(EFC0_FMR, fmr); 106 | if (_planes == 2) 107 | { 108 | waitFSR(); 109 | _samba.writeWord(EFC1_FMR, fmr); 110 | } 111 | } 112 | 113 | std::vector 114 | EfcFlash::getLockRegions() 115 | { 116 | std::vector regions(_lockRegions); 117 | uint32_t fsr0; 118 | uint32_t fsr1; 119 | 120 | fsr0 = readFSR0(); 121 | if (_planes == 2) 122 | fsr1 = readFSR1(); 123 | else 124 | fsr1 = 0; 125 | 126 | for (uint32_t region = 0; region < _lockRegions; region++) 127 | { 128 | if (_planes == 2 && region >= _lockRegions / 2) 129 | regions[region] = (fsr1 & (1 << (16 + region - _lockRegions / 2))) != 0; 130 | else 131 | regions[region] = (fsr0 & (1 << (16 + region))) != 0; 132 | } 133 | 134 | return regions; 135 | } 136 | 137 | bool 138 | EfcFlash::getSecurity() 139 | { 140 | return (readFSR0() & (1 << 4)); 141 | } 142 | 143 | bool 144 | EfcFlash::getBod() 145 | { 146 | return (readFSR0() & (1 << 8)); 147 | } 148 | 149 | bool 150 | EfcFlash::getBor() 151 | { 152 | return (readFSR0() & (2 << 8)); 153 | } 154 | 155 | bool 156 | EfcFlash::getBootFlash() 157 | { 158 | if (!_canBootFlash) 159 | return false; 160 | 161 | return (readFSR0() & (1 << 10)); 162 | } 163 | 164 | void 165 | EfcFlash::writeOptions() 166 | { 167 | if (canBootFlash() && _bootFlash.isDirty() && _bootFlash.get() != getBootFlash()) 168 | { 169 | waitFSR(); 170 | writeFCR0(_bootFlash.get() ? EFC_FCMD_SGPB : EFC_FCMD_CGPB, 2); 171 | } 172 | if (canBor() && _bor.isDirty() && _bor.get() != getBor()) 173 | { 174 | waitFSR(); 175 | writeFCR0(_bor.get() ? EFC_FCMD_SGPB : EFC_FCMD_CGPB, 1); 176 | } 177 | if (canBod() && _bod.isDirty() && _bod.get() != getBod()) 178 | { 179 | waitFSR(); 180 | writeFCR0(_bod.get() ? EFC_FCMD_SGPB : EFC_FCMD_CGPB, 0); 181 | } 182 | if (_regions.isDirty()) 183 | { 184 | uint32_t page; 185 | std::vector current; 186 | 187 | current = getLockRegions(); 188 | 189 | for (uint32_t region = 0; region < _regions.get().size(); region++) 190 | { 191 | if (_regions.get()[region] != current[region]) 192 | { 193 | if (_planes == 2 && region >= _lockRegions / 2) 194 | { 195 | page = (region - _lockRegions / 2) * _pages / _lockRegions; 196 | waitFSR(); 197 | writeFCR1(_regions.get()[region] ? EFC_FCMD_SLB : EFC_FCMD_CLB, page); 198 | } 199 | else 200 | { 201 | page = region * _pages / _lockRegions; 202 | waitFSR(); 203 | writeFCR0(_regions.get()[region] ? EFC_FCMD_SLB : EFC_FCMD_CLB, page); 204 | } 205 | } 206 | } 207 | } 208 | if (_security.isDirty() && _security.get() == true && _security.get() != getSecurity()) 209 | { 210 | waitFSR(); 211 | writeFCR0(EFC_FCMD_SSB, 0); 212 | } 213 | } 214 | 215 | void 216 | EfcFlash::writePage(uint32_t page) 217 | { 218 | if (page >= _pages) 219 | throw FlashPageError(); 220 | 221 | _wordCopy.setDstAddr(_addr + page * _size); 222 | _wordCopy.setSrcAddr(_onBufferA ? _pageBufferA : _pageBufferB); 223 | _onBufferA = !_onBufferA; 224 | waitFSR(); 225 | _wordCopy.run(); 226 | if (_planes == 2 && page >= _pages / 2) 227 | writeFCR1(EFC_FCMD_WP, page - _pages / 2); 228 | else 229 | writeFCR0(EFC_FCMD_WP, page); 230 | } 231 | 232 | void 233 | EfcFlash::readPage(uint32_t page, uint8_t* data) 234 | { 235 | if (page >= _pages) 236 | throw FlashPageError(); 237 | 238 | waitFSR(); 239 | _samba.read(_addr + page * _size, data, _size); 240 | } 241 | 242 | void 243 | EfcFlash::waitFSR(int seconds) 244 | { 245 | int tries = seconds * 1000; 246 | uint32_t fsr0; 247 | uint32_t fsr1 = 0x1; 248 | 249 | while (tries-- > 0) 250 | { 251 | fsr0 = readFSR0(); 252 | if (fsr0 & 0x2) 253 | throw FlashCmdError(); 254 | if (fsr0 & 0x4) 255 | throw FlashLockError(); 256 | 257 | if (_planes == 2) 258 | { 259 | fsr1 = readFSR1(); 260 | if (fsr1 & 0x2) 261 | throw FlashCmdError(); 262 | if (fsr1 & 0x4) 263 | throw FlashLockError(); 264 | } 265 | if (fsr0 & fsr1 & 0x1) 266 | break; 267 | usleep(1000); 268 | } 269 | if (tries == 0) 270 | throw FlashTimeoutError(); 271 | } 272 | 273 | void 274 | EfcFlash::writeFCR0(uint8_t cmd, uint32_t arg) 275 | { 276 | _samba.writeWord(EFC0_FCR, (EFC_KEY << 24) | (arg << 8) | cmd); 277 | } 278 | 279 | void 280 | EfcFlash::writeFCR1(uint8_t cmd, uint32_t arg) 281 | { 282 | _samba.writeWord(EFC1_FCR, (EFC_KEY << 24) | (arg << 8) | cmd); 283 | } 284 | 285 | uint32_t 286 | EfcFlash::readFSR0() 287 | { 288 | return _samba.readWord(EFC0_FSR); 289 | } 290 | 291 | uint32_t 292 | EfcFlash::readFSR1() 293 | { 294 | return _samba.readWord(EFC1_FSR); 295 | } 296 | -------------------------------------------------------------------------------- /src/EfcFlash.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _EFCFLASH_H 30 | #define _EFCFLASH_H 31 | 32 | #include 33 | #include 34 | 35 | #include "Flash.h" 36 | 37 | class EfcFlash : public Flash 38 | { 39 | public: 40 | EfcFlash(Samba& samba, 41 | const std::string& name, 42 | uint32_t addr, 43 | uint32_t pages, 44 | uint32_t size, 45 | uint32_t planes, 46 | uint32_t lockRegions, 47 | uint32_t user, 48 | uint32_t stack, 49 | bool canBootFlash); 50 | virtual ~EfcFlash(); 51 | 52 | void eraseAll(uint32_t offset); 53 | void eraseAuto(bool enable); 54 | 55 | std::vector getLockRegions(); 56 | 57 | bool getSecurity(); 58 | 59 | bool getBod(); 60 | bool canBod() { return true; } 61 | 62 | bool getBor(); 63 | bool canBor() { return true; } 64 | 65 | bool getBootFlash(); 66 | bool canBootFlash() { return _canBootFlash; } 67 | 68 | void writeOptions(); 69 | 70 | void writePage(uint32_t page); 71 | void readPage(uint32_t page, uint8_t* data); 72 | 73 | private: 74 | bool _canBootFlash; 75 | 76 | void waitFSR(int seconds = 1); 77 | void writeFCR0(uint8_t cmd, uint32_t arg); 78 | void writeFCR1(uint8_t cmd, uint32_t arg); 79 | uint32_t readFSR0(); 80 | uint32_t readFSR1(); 81 | }; 82 | 83 | #endif // _EFCFLASH_H 84 | -------------------------------------------------------------------------------- /src/FileError.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _FILEERROR_H 30 | #define _FILEERROR_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "Flash.h" 37 | #include "Samba.h" 38 | 39 | class FileError : public std::exception 40 | { 41 | public: 42 | FileError() : std::exception() {} 43 | }; 44 | 45 | class FileOpenError : public FileError 46 | { 47 | public: 48 | FileOpenError() : FileError(), _errnum(0) {}; 49 | FileOpenError(int errnum) : FileError(), _errnum(errnum) {}; 50 | const char* what() const throw() 51 | { 52 | if (_errnum == 0) 53 | return "Unable to open file"; 54 | else 55 | return strerror(_errnum); 56 | } 57 | private: 58 | int _errnum; 59 | }; 60 | 61 | class FileIoError : public FileError 62 | { 63 | public: 64 | FileIoError() : FileError(), _errnum(0) {}; 65 | FileIoError(int errnum) : FileError(), _errnum(errnum) {}; 66 | const char* what() const throw() 67 | { 68 | if (_errnum == 0) 69 | return "File I/O operation failed"; 70 | else 71 | return strerror(_errnum); 72 | } 73 | private: 74 | int _errnum; 75 | }; 76 | 77 | class FileShortError : public FileError 78 | { 79 | public: 80 | FileShortError() : FileError() {}; 81 | const char* what() const throw() 82 | { 83 | return "Operation ended with a short write"; 84 | } 85 | }; 86 | 87 | class FileSizeError : public FileError 88 | { 89 | public: 90 | FileSizeError() {}; 91 | const char* what() const throw() { return "File operation exceeds flash size"; } 92 | }; 93 | 94 | #endif // _FILEERROR_H 95 | -------------------------------------------------------------------------------- /src/Flash.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "Flash.h" 30 | 31 | #include 32 | 33 | Flash::Flash(Samba& samba, 34 | const std::string& name, 35 | uint32_t addr, 36 | uint32_t pages, 37 | uint32_t size, 38 | uint32_t planes, 39 | uint32_t lockRegions, 40 | uint32_t user, 41 | uint32_t stack) 42 | : _samba(samba), _name(name), _addr(addr), _pages(pages), _size(size), 43 | _planes(planes), _lockRegions(lockRegions), _user(user), _wordCopy(samba, user) 44 | { 45 | assert((size & (size - 1)) == 0); 46 | assert((pages & (pages - 1)) == 0); 47 | assert((lockRegions & (lockRegions - 1)) == 0); 48 | 49 | _wordCopy.setWords(size / sizeof(uint32_t)); 50 | _wordCopy.setStack(stack); 51 | 52 | _onBufferA = true; 53 | 54 | // page buffers will have the size of a physical page and will be situated right after the applet 55 | _pageBufferA = ((_user + _wordCopy.size() + 3) / 4) * 4; // we need to avoid non 32bits aligned access on Cortex-M0+ 56 | _pageBufferB = _pageBufferA + size; 57 | } 58 | 59 | void 60 | Flash::setLockRegions(const std::vector& regions) 61 | { 62 | if (regions.size() > _lockRegions) 63 | throw FlashRegionError(); 64 | 65 | _regions.set(regions); 66 | } 67 | 68 | void 69 | Flash::setSecurity() 70 | { 71 | _security.set(true); 72 | } 73 | 74 | void 75 | Flash::setBor(bool enable) 76 | { 77 | if (canBor()) 78 | _bor.set(enable); 79 | } 80 | 81 | void 82 | Flash::setBod(bool enable) 83 | { 84 | if (canBod()) 85 | _bod.set(enable); 86 | } 87 | 88 | void 89 | Flash::setBootFlash(bool enable) 90 | { 91 | if (canBootFlash()) 92 | _bootFlash.set(enable); 93 | } 94 | 95 | void 96 | Flash::loadBuffer(const uint8_t* data, uint16_t bufferSize) 97 | { 98 | _samba.write(_onBufferA ? _pageBufferA : _pageBufferB, data, bufferSize); 99 | } 100 | 101 | void 102 | Flash::writeBuffer(uint32_t dst_addr, uint32_t size) 103 | { 104 | _samba.writeBuffer(_onBufferA ? _pageBufferA : _pageBufferB, dst_addr + _addr, size); 105 | } 106 | 107 | -------------------------------------------------------------------------------- /src/Flash.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _FLASH_H 30 | #define _FLASH_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "Samba.h" 38 | #include "WordCopyApplet.h" 39 | 40 | class FlashPageError : public std::exception 41 | { 42 | public: 43 | FlashPageError() : exception() {}; 44 | const char* what() const throw() { return "Invalid flash page"; } 45 | }; 46 | 47 | class FlashRegionError : public std::exception 48 | { 49 | public: 50 | FlashRegionError() : exception() {}; 51 | const char* what() const throw() { return "Invalid lock region"; } 52 | }; 53 | 54 | class FlashLockError : public std::exception 55 | { 56 | public: 57 | FlashLockError() : exception() {}; 58 | const char* what() const throw() { return "Flash page is locked"; } 59 | }; 60 | 61 | class FlashCmdError : public std::exception 62 | { 63 | public: 64 | FlashCmdError() : exception() {}; 65 | const char* what() const throw() { return "Flash command failed"; } 66 | }; 67 | 68 | class FlashTimeoutError : public std::exception 69 | { 70 | public: 71 | FlashTimeoutError() : exception() {}; 72 | const char* what() const throw() { return "Flash command timeout"; } 73 | }; 74 | 75 | class BootFlashError : public std::exception 76 | { 77 | public: 78 | BootFlashError() : exception() {}; 79 | const char* what() const throw() { return "Unable to clear boot flash for this device"; } 80 | 81 | }; 82 | 83 | class FlashEraseError : public std::exception 84 | { 85 | public: 86 | FlashEraseError() : exception() {}; 87 | const char* what() const throw() { return "Flash erase failed"; } 88 | 89 | }; 90 | 91 | template 92 | class FlashOption 93 | { 94 | public: 95 | FlashOption() : _dirty(false) {} 96 | virtual ~FlashOption() {} 97 | void set(const T& value) { _value = value; _dirty = true; } 98 | const T& get() { return _value; } 99 | bool isDirty() { return _dirty; } 100 | 101 | private: 102 | T _value; 103 | bool _dirty; 104 | }; 105 | 106 | class Flash 107 | { 108 | public: 109 | Flash(Samba& samba, 110 | const std::string& name, 111 | uint32_t addr, // Flash base address 112 | uint32_t pages, // Number of pages 113 | uint32_t size, // Page size in bytes 114 | uint32_t planes, // Number of flash planes 115 | uint32_t lockRegions, // Number of flash lock regions 116 | uint32_t user, // Address in SRAM where the applet and buffers will be placed 117 | uint32_t stack); // Address in SRAM where the applet stack will be placed 118 | virtual ~Flash() {} 119 | 120 | const std::string& name() { return _name; } 121 | 122 | virtual uint32_t address() { return _addr; } 123 | virtual uint32_t pageSize() { return _size; } 124 | virtual uint32_t numPages() { return _pages; } 125 | virtual uint32_t numPlanes() { return _planes; } 126 | virtual uint32_t totalSize() { return _size * _pages; } 127 | virtual uint32_t lockRegions() { return _lockRegions; } 128 | 129 | virtual void eraseAll(uint32_t offset) = 0; 130 | virtual void eraseAuto(bool enable) = 0; 131 | 132 | virtual std::vector getLockRegions() = 0; 133 | virtual void setLockRegions(const std::vector& regions); 134 | 135 | virtual bool getSecurity() = 0; 136 | virtual void setSecurity(); 137 | 138 | virtual bool getBod() = 0; 139 | virtual void setBod(bool enable); 140 | virtual bool canBod() = 0; 141 | 142 | virtual bool getBor() = 0; 143 | virtual void setBor(bool enable); 144 | virtual bool canBor() = 0; 145 | 146 | virtual bool getBootFlash() = 0; 147 | virtual void setBootFlash(bool enable); 148 | virtual bool canBootFlash() = 0; 149 | 150 | virtual void writeOptions() = 0; 151 | 152 | virtual void writePage(uint32_t page) = 0; 153 | virtual void readPage(uint32_t page, uint8_t* data) = 0; 154 | 155 | virtual void writeBuffer(uint32_t dst_addr, uint32_t size); 156 | virtual void loadBuffer(const uint8_t* data, uint16_t size); 157 | 158 | protected: 159 | Samba& _samba; 160 | std::string _name; 161 | uint32_t _addr; 162 | uint32_t _pages; 163 | uint32_t _size; 164 | uint32_t _planes; 165 | uint32_t _lockRegions; 166 | uint32_t _user; 167 | WordCopyApplet _wordCopy; 168 | 169 | FlashOption _bootFlash; 170 | FlashOption< std::vector > _regions; 171 | FlashOption _bod; 172 | FlashOption _bor; 173 | FlashOption _security; 174 | 175 | bool _onBufferA; 176 | uint32_t _pageBufferA; 177 | uint32_t _pageBufferB; 178 | }; 179 | 180 | #endif // _FLASH_H 181 | -------------------------------------------------------------------------------- /src/Flasher.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _FLASHER_H 30 | #define _FLASHER_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "Device.h" 37 | #include "Flash.h" 38 | #include "Samba.h" 39 | #include "FileError.h" 40 | 41 | class FlashOffsetError : public std::exception 42 | { 43 | public: 44 | FlashOffsetError() : std::exception() {}; 45 | virtual const char* what() const throw() { return "Flash offset is invalid"; } 46 | }; 47 | 48 | class FlasherObserver 49 | { 50 | public: 51 | FlasherObserver() {} 52 | virtual ~FlasherObserver() {} 53 | 54 | virtual void onStatus(const char *message, ...) = 0; 55 | virtual void onProgress(int num, int div) = 0; 56 | }; 57 | 58 | class FlasherInfo 59 | { 60 | public: 61 | FlasherInfo() {} 62 | virtual ~FlasherInfo() {} 63 | 64 | void print(); 65 | 66 | std::string name; 67 | uint32_t chipId; 68 | uint32_t extChipId; 69 | std::string version; 70 | uint32_t address; 71 | uint32_t numPages; 72 | uint32_t pageSize; 73 | uint32_t totalSize; 74 | uint32_t numPlanes; 75 | 76 | bool security; 77 | bool bootFlash; 78 | bool bod; 79 | bool bor; 80 | 81 | bool canBootFlash; 82 | bool canBod; 83 | bool canBor; 84 | bool canChipErase; 85 | bool canWriteBuffer; 86 | bool canChecksumBuffer; 87 | 88 | std::vector lockRegions; 89 | }; 90 | 91 | class Flasher 92 | { 93 | public: 94 | Flasher(Samba& samba, Device& device, FlasherObserver& observer) : _samba(samba), _flash(device.getFlash()), _observer(observer) {} 95 | virtual ~Flasher() {} 96 | 97 | void erase(uint32_t foffset); 98 | void write(const char* filename, uint32_t foffset = 0); 99 | bool verify(const char* filename, uint32_t& pageErrors, uint32_t& totalErrors, uint32_t foffset = 0); 100 | void read(const char* filename, uint32_t fsize, uint32_t foffset = 0); 101 | void lock(std::string& regionArg, bool enable); 102 | void info(FlasherInfo& info); 103 | 104 | private: 105 | Samba& _samba; 106 | Device::FlashPtr& _flash; 107 | FlasherObserver& _observer; 108 | }; 109 | 110 | #endif // _FLASHER_H 111 | -------------------------------------------------------------------------------- /src/LinuxPortFactory.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "LinuxPortFactory.h" 30 | #include "PosixSerialPort.h" 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | LinuxPortFactory::LinuxPortFactory() 38 | { 39 | _dir = opendir("/dev"); 40 | } 41 | 42 | LinuxPortFactory::~LinuxPortFactory() 43 | { 44 | if (_dir) 45 | closedir(_dir); 46 | } 47 | 48 | SerialPort::Ptr 49 | LinuxPortFactory::create(const std::string& name) 50 | { 51 | bool isUsb = false; 52 | 53 | if (name.find("ttyUSB") != std::string::npos || 54 | name.find("ttyACM") != std::string::npos) 55 | isUsb = true; 56 | 57 | return create(name, isUsb); 58 | } 59 | 60 | SerialPort::Ptr 61 | LinuxPortFactory::create(const std::string& name, bool isUsb) 62 | { 63 | return SerialPort::Ptr(new PosixSerialPort(name, isUsb)); 64 | } 65 | 66 | std::string 67 | LinuxPortFactory::begin() 68 | { 69 | if (!_dir) 70 | return end(); 71 | 72 | rewinddir(_dir); 73 | 74 | return next(); 75 | } 76 | 77 | std::string 78 | LinuxPortFactory::next() 79 | { 80 | struct dirent* entry; 81 | 82 | if (!_dir) 83 | return end(); 84 | 85 | while ((entry = readdir(_dir))) 86 | { 87 | if (strncmp("ttyUSB", entry->d_name, sizeof("ttyUSB") - 1) == 0) 88 | return std::string(entry->d_name); 89 | else if (strncmp("ttyACM", entry->d_name, sizeof("ttyACM") - 1) == 0) 90 | return std::string(entry->d_name); 91 | else if (strncmp("ttyS", entry->d_name, sizeof("ttyS") - 1) == 0) 92 | return std::string(entry->d_name); 93 | } 94 | 95 | return end(); 96 | } 97 | 98 | std::string 99 | LinuxPortFactory::end() 100 | { 101 | return std::string(); 102 | } 103 | 104 | std::string 105 | LinuxPortFactory::def() 106 | { 107 | return std::string("/dev/ttyACM0"); 108 | } 109 | 110 | -------------------------------------------------------------------------------- /src/LinuxPortFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _LINUXPORTFACTORY_H 30 | #define _LINUXPORTFACTORY_H 31 | 32 | class LinuxPortFactory; 33 | #include "PortFactory.h" 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | 41 | class LinuxPortFactory : public PortFactoryBase 42 | { 43 | public: 44 | LinuxPortFactory(); 45 | virtual ~LinuxPortFactory(); 46 | 47 | virtual std::string begin(); 48 | virtual std::string end(); 49 | virtual std::string next(); 50 | virtual std::string def(); 51 | 52 | virtual SerialPort::Ptr create(const std::string& name); 53 | virtual SerialPort::Ptr create(const std::string& name, bool isUsb); 54 | 55 | private: 56 | std::string _empty; 57 | DIR* _dir; 58 | }; 59 | 60 | #endif // _LINUXPORTFACTORY_H 61 | -------------------------------------------------------------------------------- /src/NullFlash.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2018, ShumaTech 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | #include "NullFlash.h" 21 | 22 | NullFlash::NullFlash( 23 | Samba& samba, 24 | const std::string& name, 25 | uint32_t pages, 26 | uint32_t size, 27 | uint32_t user, 28 | uint32_t stack) 29 | : 30 | Flash(samba, name, 0, pages, size, 1, 0, user, stack) 31 | { 32 | } 33 | 34 | NullFlash::~NullFlash() 35 | { 36 | } 37 | 38 | void 39 | NullFlash::erase(uint32_t offset, uint32_t size) 40 | { 41 | throw FlashEraseError(); 42 | } 43 | 44 | void 45 | NullFlash::eraseAll(uint32_t offset) 46 | { 47 | // Use the extended Samba command if available 48 | if (_samba.canChipErase()) 49 | { 50 | _samba.chipErase(offset); 51 | } 52 | else 53 | { 54 | erase(offset, totalSize() - offset); 55 | } 56 | } 57 | 58 | void 59 | NullFlash::eraseAuto(bool enable) 60 | { 61 | _eraseAuto = enable; 62 | } 63 | 64 | std::vector 65 | NullFlash::getLockRegions() 66 | { 67 | std::vector regions(0); 68 | return regions; 69 | } 70 | 71 | bool 72 | NullFlash::getSecurity() 73 | { 74 | return false; 75 | } 76 | 77 | bool 78 | NullFlash::getBod() 79 | { 80 | return false; 81 | } 82 | 83 | bool 84 | NullFlash::getBor() 85 | { 86 | return false; 87 | } 88 | 89 | bool 90 | NullFlash::getBootFlash() 91 | { 92 | return true; 93 | } 94 | 95 | void 96 | NullFlash::writeOptions() 97 | { 98 | return; 99 | } 100 | 101 | void 102 | NullFlash::writePage(uint32_t page) 103 | { 104 | throw FlashPageError(); 105 | } 106 | 107 | void 108 | NullFlash::readPage(uint32_t page, uint8_t* buf) 109 | { 110 | if (page >= _pages) 111 | { 112 | throw FlashPageError(); 113 | } 114 | 115 | _samba.read(_addr + (page * _size), buf, _size); 116 | } 117 | 118 | void 119 | NullFlash::writeBuffer(uint32_t dst_addr, uint32_t size) 120 | { 121 | // Auto-erase if enabled 122 | if (_eraseAuto) 123 | erase(dst_addr, size); 124 | 125 | // Call the base class method 126 | Flash::writeBuffer(dst_addr, size); 127 | } 128 | -------------------------------------------------------------------------------- /src/NullFlash.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2018, ShumaTech 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | /////////////////////////////////////////////////////////////////////////////// 19 | 20 | #ifndef _NULLFLASH_H 21 | #define _NULLFLASH_H 22 | 23 | #include 24 | #include 25 | 26 | #include "Flash.h" 27 | 28 | class NullFlash : public Flash 29 | { 30 | public: 31 | NullFlash( 32 | Samba& samba, 33 | const std::string& name, 34 | uint32_t pages, 35 | uint32_t size, 36 | uint32_t user, 37 | uint32_t stack); 38 | 39 | virtual ~NullFlash(); 40 | 41 | void eraseAll(uint32_t offset); 42 | void eraseAuto(bool enable); 43 | 44 | std::vector getLockRegions(); 45 | 46 | bool getSecurity(); 47 | 48 | bool getBod(); 49 | bool canBod() { return false; } 50 | 51 | bool getBor(); 52 | bool canBor() { return false; } 53 | 54 | bool getBootFlash(); 55 | bool canBootFlash() { return false; } 56 | 57 | void writeOptions(); 58 | 59 | void writePage(uint32_t page); 60 | void readPage(uint32_t page, uint8_t* data); 61 | 62 | void writeBuffer(uint32_t dst_addr, uint32_t size); 63 | 64 | protected: 65 | bool _eraseAuto; 66 | void erase(uint32_t offset, uint32_t size); 67 | }; 68 | 69 | #endif // _NULLFLASH_H 70 | -------------------------------------------------------------------------------- /src/OSXPortFactory.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "OSXPortFactory.h" 30 | #include "PosixSerialPort.h" 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | OSXPortFactory::OSXPortFactory() 38 | { 39 | _dir = opendir("/dev"); 40 | } 41 | 42 | OSXPortFactory::~OSXPortFactory() 43 | { 44 | if (_dir) 45 | closedir(_dir); 46 | } 47 | 48 | SerialPort::Ptr 49 | OSXPortFactory::create(const std::string& name) 50 | { 51 | bool isUsb = false; 52 | 53 | if (name.find("usb") != std::string::npos) 54 | isUsb = true; 55 | 56 | return create(name, isUsb); 57 | } 58 | 59 | SerialPort::Ptr 60 | OSXPortFactory::create(const std::string& name, bool isUsb) 61 | { 62 | PosixSerialPort *p = new PosixSerialPort(name, isUsb); 63 | // Needed to avoid upload errors 64 | p->setAutoFlush(true); 65 | return SerialPort::Ptr(p); 66 | } 67 | 68 | std::string 69 | OSXPortFactory::begin() 70 | { 71 | if (!_dir) 72 | return end(); 73 | 74 | rewinddir(_dir); 75 | 76 | return next(); 77 | } 78 | 79 | std::string 80 | OSXPortFactory::next() 81 | { 82 | struct dirent* entry; 83 | 84 | if (!_dir) 85 | return end(); 86 | 87 | while ((entry = readdir(_dir))) 88 | { 89 | if (strncmp("cu.", entry->d_name, sizeof("cu.") - 1) == 0) 90 | return std::string(entry->d_name); 91 | } 92 | 93 | return end(); 94 | } 95 | 96 | std::string 97 | OSXPortFactory::end() 98 | { 99 | return std::string(); 100 | } 101 | 102 | std::string 103 | OSXPortFactory::def() 104 | { 105 | return begin(); 106 | } 107 | 108 | -------------------------------------------------------------------------------- /src/OSXPortFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _OSXPORTFACTORY_H 30 | #define _OSXPORTFACTORY_H 31 | 32 | class OSXPortFactory; 33 | #include "PortFactory.h" 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | 41 | class OSXPortFactory : public PortFactoryBase 42 | { 43 | public: 44 | OSXPortFactory(); 45 | virtual ~OSXPortFactory(); 46 | 47 | virtual std::string begin(); 48 | virtual std::string end(); 49 | virtual std::string next(); 50 | virtual std::string def(); 51 | 52 | virtual SerialPort::Ptr create(const std::string& name); 53 | virtual SerialPort::Ptr create(const std::string& name, bool isUsb); 54 | 55 | private: 56 | std::string _empty; 57 | DIR* _dir; 58 | }; 59 | 60 | #endif // _OSXPORTFACTORY_H 61 | -------------------------------------------------------------------------------- /src/PortFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _PORTFACTORY_H 30 | #define _PORTFACTORY_H 31 | 32 | #include 33 | 34 | #include "SerialPort.h" 35 | 36 | class PortFactoryBase 37 | { 38 | public: 39 | PortFactoryBase() {} 40 | virtual ~PortFactoryBase() {} 41 | 42 | virtual std::string begin() = 0; 43 | virtual std::string end() = 0; 44 | virtual std::string next() = 0; 45 | virtual std::string def() = 0; 46 | 47 | virtual SerialPort::Ptr create(const std::string& name) = 0; 48 | virtual SerialPort::Ptr create(const std::string& name, bool isUsb) = 0; 49 | }; 50 | 51 | #if defined(__WIN32__) 52 | #include "WinPortFactory.h" 53 | typedef WinPortFactory PortFactory; 54 | #elif defined(__linux__) 55 | #include "LinuxPortFactory.h" 56 | typedef LinuxPortFactory PortFactory; 57 | #elif defined(__APPLE__) 58 | #include "OSXPortFactory.h" 59 | typedef OSXPortFactory PortFactory; 60 | #elif defined(__OpenBSD__) || defined(__FreeBSD__) 61 | // This is likely to work (but not tested) for the other BSDs as well 62 | #include "BSDPortFactory.h" 63 | typedef BSDPortFactory PortFactory; 64 | #else 65 | #error "Platform is not supported" 66 | #endif 67 | 68 | #endif // _PORTFACTORY_H 69 | -------------------------------------------------------------------------------- /src/PosixSerialPort.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _POSIXSERIALPORT_H 30 | #define _POSIXSERIALPORT_H 31 | 32 | #include "SerialPort.h" 33 | 34 | class PosixSerialPort : public SerialPort 35 | { 36 | public: 37 | PosixSerialPort(const std::string& name, bool isUsb); 38 | virtual ~PosixSerialPort(); 39 | 40 | bool open(int baud = 115200, 41 | int data = 8, 42 | SerialPort::Parity parity = SerialPort::ParityNone, 43 | SerialPort::StopBit stop = SerialPort::StopBitOne); 44 | void close(); 45 | 46 | bool isUsb() { return _isUsb; }; 47 | 48 | int read(uint8_t* data, int size); 49 | int write(const uint8_t* data, int size); 50 | int get(); 51 | int put(int c); 52 | 53 | bool timeout(int millisecs); 54 | void flush(); 55 | void setDTR(bool dtr); 56 | void setRTS(bool rts); 57 | void setAutoFlush(bool autoflush); 58 | 59 | private: 60 | int _devfd; 61 | bool _isUsb; 62 | int _timeout; 63 | bool _autoFlush; 64 | }; 65 | 66 | #endif // _POSIXSERIALPORT_H 67 | -------------------------------------------------------------------------------- /src/Samba.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | 30 | #ifndef _SAMBA_H 31 | #define _SAMBA_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "SerialPort.h" 39 | 40 | class SambaError : public std::exception 41 | { 42 | public: 43 | SambaError() : exception() {}; 44 | const char* what() const throw() { return "SAM-BA operation failed"; } 45 | }; 46 | 47 | 48 | 49 | class Samba 50 | { 51 | public: 52 | Samba(); 53 | virtual ~Samba(); 54 | 55 | bool connect(SerialPort::Ptr port, int bps = 115200); 56 | void disconnect(); 57 | 58 | void writeByte(uint32_t addr, uint8_t value); 59 | uint8_t readByte(uint32_t addr); 60 | 61 | void writeWord(uint32_t addr, uint32_t value); 62 | uint32_t readWord(uint32_t addr); 63 | 64 | void write(uint32_t addr, const uint8_t* buffer, int size); 65 | void read(uint32_t addr, uint8_t* buffer, int size); 66 | 67 | void go(uint32_t addr); 68 | 69 | std::string version(); 70 | 71 | void chipId(uint32_t& chipId, uint32_t& extChipId); 72 | 73 | void setDebug(bool debug) { _debug = debug; } 74 | 75 | const SerialPort& getSerialPort() { return *_port; } 76 | 77 | // Extended SAM-BA functions 78 | bool canChipErase() { return _canChipErase; } 79 | void chipErase(uint32_t start_addr); 80 | 81 | bool canWriteBuffer() { return _canWriteBuffer; } 82 | void writeBuffer(uint32_t src_addr, uint32_t dst_addr, uint32_t size); 83 | uint32_t writeBufferSize() { return 4096; } 84 | 85 | bool canChecksumBuffer() { return _canChecksumBuffer; } 86 | uint16_t checksumBuffer(uint32_t start_addr, uint32_t size); 87 | uint32_t checksumBufferSize() { return 4096; } 88 | uint16_t checksumCalc(uint8_t c, uint16_t crc); 89 | 90 | bool canIdentifyChip() { return _canIdentifyChip; } 91 | std::string identifyChip(); 92 | 93 | bool canReset() { return _canReset; } 94 | void reset(); 95 | 96 | private: 97 | bool _canChipErase; 98 | bool _canWriteBuffer; 99 | bool _canChecksumBuffer; 100 | bool _canIdentifyChip; 101 | bool _canReset; 102 | int _readBufferSize; 103 | bool _debug; 104 | bool _isUsb; 105 | SerialPort::Ptr _port; 106 | 107 | bool init(); 108 | 109 | uint16_t crc16Calc(const uint8_t *data, int len); 110 | bool crc16Check(const uint8_t *blk); 111 | void crc16Add(uint8_t *blk); 112 | void writeXmodem(const uint8_t* buffer, int size); 113 | void readXmodem(uint8_t* buffer, int size); 114 | 115 | void writeBinary(const uint8_t* buffer, int size); 116 | void readBinary(uint8_t* buffer, int size); 117 | 118 | }; 119 | 120 | 121 | #endif // _SAMBA_H 122 | -------------------------------------------------------------------------------- /src/SerialPort.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _SERIALPORT_H 30 | #define _SERIALPORT_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | class SerialPort 37 | { 38 | public: 39 | SerialPort(const std::string& name) : _name(name) {} 40 | virtual ~SerialPort() {} 41 | 42 | enum Parity 43 | { 44 | ParityNone, 45 | ParityOdd, 46 | ParityEven, 47 | }; 48 | 49 | enum StopBit 50 | { 51 | StopBitOne, 52 | StopBitOneFive, 53 | StopBitTwo, 54 | }; 55 | 56 | virtual bool open(int baud = 115200, 57 | int data = 8, 58 | Parity parity = ParityNone, 59 | StopBit stop = StopBitOne) = 0; 60 | virtual void close() = 0; 61 | 62 | virtual bool isUsb() = 0; 63 | 64 | virtual int read(uint8_t* data, int size) = 0; 65 | virtual int write(const uint8_t* data, int size) = 0; 66 | virtual int get() = 0; 67 | virtual int put(int c) = 0; 68 | 69 | virtual bool timeout(int millisecs) = 0; 70 | virtual void flush() = 0; 71 | virtual void setDTR(bool dtr) = 0; 72 | virtual void setRTS(bool rts) = 0; 73 | 74 | virtual std::string name() const { return _name; } 75 | 76 | typedef std::unique_ptr Ptr; 77 | 78 | protected: 79 | std::string _name; 80 | }; 81 | 82 | #endif // _SERIALPORT_H 83 | -------------------------------------------------------------------------------- /src/Shell.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include 30 | #include 31 | 32 | #include "Shell.h" 33 | #include "Command.h" 34 | 35 | using namespace std; 36 | 37 | Shell::Shell() : 38 | _exitFlag(false) 39 | { 40 | Command::setShell(this); 41 | 42 | add(new CommandBod); 43 | add(new CommandBootf); 44 | add(new CommandBor); 45 | add(new CommandConnect); 46 | add(new CommandDebug); 47 | add(new CommandDump); 48 | add(new CommandErase); 49 | add(new CommandExit); 50 | add(new CommandGo); 51 | add(new CommandHelp); 52 | add(new CommandHistory); 53 | add(new CommandLock); 54 | add(new CommandInfo); 55 | add(new CommandMrb); 56 | add(new CommandMrf); 57 | add(new CommandMrw); 58 | add(new CommandMwb); 59 | add(new CommandMwf); 60 | add(new CommandMww); 61 | add(new CommandPio); 62 | add(new CommandRead); 63 | add(new CommandSecurity); 64 | add(new CommandVerify); 65 | add(new CommandWrite); 66 | add(new CommandReset); 67 | add(new CommandOptions); 68 | 69 | _commandList.sort(); 70 | } 71 | 72 | Shell::~Shell() 73 | { 74 | CommandList::iterator it; 75 | 76 | for (it = _commandList.begin(); 77 | it != _commandList.end(); 78 | it++) 79 | { 80 | delete *it; 81 | } 82 | } 83 | 84 | Command* 85 | Shell::find(const char* name) 86 | { 87 | CommandList::iterator it; 88 | int len; 89 | Command *command = NULL; 90 | 91 | len = strlen(name); 92 | for (it = _commandList.begin(); 93 | it != _commandList.end(); 94 | it++) 95 | { 96 | if (strncmp((*it)->name(), name, len) == 0) 97 | { 98 | if (command) 99 | { 100 | printf("Ambiguous command: \"%s\". Try \"help\".\n", name); 101 | return NULL; 102 | } 103 | command = *it; 104 | } 105 | } 106 | 107 | if (!command) 108 | { 109 | printf("Undefined command: \"%s\". Try \"help\".\n", name); 110 | return NULL; 111 | } 112 | 113 | return command; 114 | } 115 | 116 | void 117 | Shell::invoke(char* argv[], int argc) 118 | { 119 | Command* command; 120 | 121 | command = find(argv[0]); 122 | if (!command) 123 | return; 124 | 125 | try 126 | { 127 | command->invoke(argv, argc); 128 | } 129 | catch (SambaError& e) 130 | { 131 | printf("\n%s.\nPort is disconnected.\n", e.what()); 132 | Command::disconnect(); 133 | } 134 | catch (exception& e) 135 | { 136 | printf("\n%s.\n", e.what()); 137 | } 138 | } 139 | 140 | void 141 | Shell::help() 142 | { 143 | CommandList::iterator it; 144 | 145 | for (it = _commandList.begin(); 146 | it != _commandList.end(); 147 | it++) 148 | { 149 | printf("%s -- %s\n", (*it)->name(), (*it)->help()); 150 | } 151 | } 152 | 153 | void 154 | Shell::usage(const char* name) 155 | { 156 | Command* command; 157 | 158 | command = find(name); 159 | if (!command) 160 | return; 161 | 162 | printf("%s\n", command->help()); 163 | printf("Usage: %s\n", command->usage()); 164 | } 165 | 166 | void 167 | Shell::add(Command* command) 168 | { 169 | _commandList.push_back(command); 170 | } 171 | -------------------------------------------------------------------------------- /src/Shell.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _Shell_H 30 | #define _Shell_H 31 | 32 | #include 33 | #include 34 | 35 | 36 | class Command; 37 | 38 | class Shell 39 | { 40 | public: 41 | virtual ~Shell(); 42 | Shell(); 43 | 44 | void invoke(char* argv[], int argc); 45 | void help(); 46 | void usage(const char* name); 47 | void add(Command* command); 48 | Command* find(const char* name); 49 | 50 | bool& exitFlag() { return _exitFlag; } 51 | 52 | private: 53 | typedef std::list CommandList; 54 | CommandList _commandList; 55 | bool _exitFlag; 56 | }; 57 | 58 | #endif // _Shell_H 59 | -------------------------------------------------------------------------------- /src/TemplateArm.asm: -------------------------------------------------------------------------------- 1 | .global start 2 | .global stack 3 | .global reset 4 | 5 | .text 6 | .thumb 7 | .align 0 8 | 9 | start: 10 | @ 11 | @ Insert code 12 | @ 13 | 14 | @ Fix for SAM-BA stack bug 15 | ldr r0, reset 16 | cmp r0, #0 17 | bne return 18 | ldr r0, stack 19 | mov sp, r0 20 | 21 | return: 22 | bx lr 23 | 24 | .align 0 25 | stack: 26 | .word 0 27 | reset: 28 | .word 0 29 | @ 30 | @ Insert variables 31 | @ 32 | -------------------------------------------------------------------------------- /src/WinPortFactory.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "WinPortFactory.h" 30 | #include "WinSerialPort.h" 31 | 32 | #define USB_DEVICE_NAME "\\Device\\USB" 33 | 34 | WinPortFactory::WinPortFactory() : 35 | _devInfo(INVALID_HANDLE_VALUE), _cfgMgr(NULL), _devNode(NULL), _devNum(0) 36 | { 37 | } 38 | 39 | WinPortFactory::~WinPortFactory() 40 | { 41 | cleanup(); 42 | } 43 | 44 | SerialPort::Ptr 45 | WinPortFactory::create(const std::string& name) 46 | { 47 | bool isUsb = false; 48 | char szNtDeviceName[MAX_PATH]; 49 | 50 | if (QueryDosDevice(name.c_str(), szNtDeviceName, MAX_PATH)) 51 | { 52 | if (strncmp(szNtDeviceName, USB_DEVICE_NAME, sizeof(USB_DEVICE_NAME) - 1) == 0) 53 | { 54 | isUsb = true; 55 | } 56 | } 57 | 58 | return create(name, isUsb); 59 | } 60 | 61 | SerialPort::Ptr 62 | WinPortFactory::create(const std::string& name, bool isUsb) 63 | { 64 | return SerialPort::Ptr(new WinSerialPort(name, isUsb)); 65 | } 66 | 67 | void 68 | WinPortFactory::cleanup() 69 | { 70 | _devNum = 0; 71 | _devNode = NULL; 72 | 73 | if (_cfgMgr == NULL) 74 | { 75 | FreeLibrary(_cfgMgr); 76 | _cfgMgr = NULL; 77 | } 78 | 79 | if (_devInfo != INVALID_HANDLE_VALUE) 80 | { 81 | SetupDiDestroyDeviceInfoList(_devInfo); 82 | _devInfo = INVALID_HANDLE_VALUE; 83 | } 84 | } 85 | 86 | std::string 87 | WinPortFactory::error() 88 | { 89 | cleanup(); 90 | return end(); 91 | } 92 | 93 | std::string 94 | WinPortFactory::begin() 95 | { 96 | DWORD size = 0; 97 | 98 | if (_devInfo != INVALID_HANDLE_VALUE) 99 | cleanup(); 100 | 101 | SetupDiClassGuidsFromNameA("Ports", 0, 0, &size); 102 | if (size < 1) 103 | return error(); 104 | 105 | GUID guids[size]; 106 | 107 | if (!SetupDiClassGuidsFromNameA("Ports", guids, size * sizeof(GUID), &size)) 108 | { 109 | return error(); 110 | } 111 | 112 | _devInfo = SetupDiGetClassDevs(guids, NULL, NULL, DIGCF_PRESENT); 113 | if(_devInfo == INVALID_HANDLE_VALUE) 114 | return error(); 115 | 116 | _cfgMgr = LoadLibrary("cfgmgr32"); 117 | if (!_cfgMgr) 118 | return error(); 119 | 120 | _devNode = (CM_Open_DevNode_Key) GetProcAddress(_cfgMgr, "CM_Open_DevNode_Key"); 121 | if (!_devNode) 122 | return error(); 123 | 124 | return next(); 125 | } 126 | 127 | std::string 128 | WinPortFactory::end() 129 | { 130 | return std::string(); 131 | } 132 | 133 | std::string 134 | WinPortFactory::next() 135 | { 136 | int rc; 137 | BYTE devName[16]; 138 | SP_DEVINFO_DATA devData; 139 | HKEY devKey; 140 | DWORD len; 141 | 142 | if (_devInfo == INVALID_HANDLE_VALUE) 143 | return end(); 144 | 145 | while (1) 146 | { 147 | devData.cbSize = sizeof(SP_DEVINFO_DATA); 148 | if (!SetupDiEnumDeviceInfo(_devInfo, _devNum, &devData)) 149 | return error(); 150 | 151 | rc = _devNode(devData.DevInst, 152 | KEY_QUERY_VALUE, 153 | 0, 154 | 1, 155 | &devKey, 156 | 0); 157 | 158 | if (rc != ERROR_SUCCESS) 159 | return error(); 160 | 161 | len = sizeof(devName); 162 | rc = RegQueryValueEx(devKey, 163 | "portname", 164 | NULL, 165 | NULL, 166 | devName, 167 | &len); 168 | 169 | RegCloseKey(devKey); 170 | if (rc != ERROR_SUCCESS) 171 | return error(); 172 | 173 | _devNum++; 174 | 175 | if (strncmp("COM", (char*) devName, 3) == 0) 176 | break; 177 | } 178 | 179 | return std::string((char*) devName, len); 180 | } 181 | 182 | std::string 183 | WinPortFactory::def() 184 | { 185 | return begin(); 186 | } 187 | 188 | -------------------------------------------------------------------------------- /src/WinPortFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _WINPORTFACTORY_H 30 | #define _WINPORTFACTORY_H 31 | 32 | class WinPortFactory; 33 | #include "PortFactory.h" 34 | 35 | #include 36 | #include 37 | 38 | class WinPortFactory : public PortFactoryBase 39 | { 40 | public: 41 | WinPortFactory(); 42 | virtual ~WinPortFactory(); 43 | 44 | std::string begin(); 45 | std::string end(); 46 | std::string next(); 47 | std::string def(); 48 | 49 | SerialPort::Ptr create(const std::string& name); 50 | SerialPort::Ptr create(const std::string& name, bool isUsb); 51 | 52 | private: 53 | typedef DWORD WINAPI (*CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, ::PHKEY, DWORD); 54 | 55 | HDEVINFO _devInfo; 56 | HINSTANCE _cfgMgr; 57 | CM_Open_DevNode_Key _devNode; 58 | int _devNum; 59 | 60 | void cleanup(); 61 | std::string error(); 62 | }; 63 | 64 | #endif // _WINPORTFACTORY_H 65 | -------------------------------------------------------------------------------- /src/WinSerialPort.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "WinSerialPort.h" 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | WinSerialPort::WinSerialPort(const std::string& name, bool isUsb) : 37 | SerialPort(name), _handle(INVALID_HANDLE_VALUE), _isUsb(isUsb) 38 | { 39 | } 40 | 41 | WinSerialPort::~WinSerialPort() 42 | { 43 | close(); 44 | } 45 | 46 | #ifdef DEBUG 47 | static void 48 | printLastError() 49 | { 50 | char buffer[100]; 51 | DWORD dw = GetLastError(); 52 | 53 | if (FormatMessage( 54 | FORMAT_MESSAGE_FROM_SYSTEM | 55 | FORMAT_MESSAGE_IGNORE_INSERTS, 56 | NULL, 57 | dw, 58 | 0, 59 | buffer, 60 | sizeof(buffer), 61 | NULL )) 62 | { 63 | printf("Error (%d): %s", (int) dw, (LPSTR) buffer); 64 | } 65 | else 66 | { 67 | printf("Error (%d)\n", (int) dw); 68 | } 69 | } 70 | #endif 71 | 72 | bool 73 | WinSerialPort::open(int baud, int data, SerialPort::Parity parity, SerialPort::StopBit stop) 74 | { 75 | DCB dcbSerialParams; 76 | 77 | if (_handle != INVALID_HANDLE_VALUE) 78 | return false; 79 | 80 | std::string device = "\\\\.\\" + _name; 81 | _handle = CreateFile(device.c_str(), 82 | GENERIC_READ | GENERIC_WRITE, 83 | 0, 84 | 0, 85 | OPEN_EXISTING, 86 | FILE_ATTRIBUTE_NORMAL, 87 | 0); 88 | 89 | if (_handle == INVALID_HANDLE_VALUE) 90 | return false; 91 | 92 | dcbSerialParams.DCBlength = sizeof(dcbSerialParams); 93 | 94 | if (!GetCommState(_handle, &dcbSerialParams)) 95 | { 96 | CloseHandle(_handle); 97 | return false; 98 | } 99 | 100 | dcbSerialParams.BaudRate = baud; 101 | 102 | dcbSerialParams.ByteSize = data; 103 | 104 | switch (parity) 105 | { 106 | case ParityNone: 107 | dcbSerialParams.Parity = NOPARITY; 108 | break; 109 | case ParityOdd: 110 | dcbSerialParams.Parity = ODDPARITY; 111 | break; 112 | case ParityEven: 113 | dcbSerialParams.Parity = EVENPARITY; 114 | break; 115 | default: 116 | CloseHandle(_handle); 117 | return false; 118 | } 119 | 120 | switch (stop) 121 | { 122 | case StopBitOne: 123 | dcbSerialParams.StopBits = ONESTOPBIT; 124 | break; 125 | case StopBitOneFive: 126 | dcbSerialParams.StopBits = ONE5STOPBITS; 127 | break; 128 | case StopBitTwo: 129 | dcbSerialParams.StopBits = TWOSTOPBITS; 130 | break; 131 | default: 132 | CloseHandle(_handle); 133 | return false; 134 | } 135 | 136 | if (!SetCommState(_handle, &dcbSerialParams)) 137 | { 138 | CloseHandle(_handle); 139 | return false; 140 | } 141 | 142 | timeout(INT_MAX); 143 | 144 | return true; 145 | } 146 | 147 | void 148 | WinSerialPort::close() 149 | { 150 | if (_handle != INVALID_HANDLE_VALUE) 151 | CloseHandle(_handle); 152 | _handle = INVALID_HANDLE_VALUE; 153 | } 154 | 155 | bool 156 | WinSerialPort::timeout(int millisecs) 157 | { 158 | COMMTIMEOUTS timeouts; 159 | 160 | if (_handle == INVALID_HANDLE_VALUE) 161 | return false; 162 | 163 | timeouts.ReadIntervalTimeout = MAXDWORD; 164 | timeouts.ReadTotalTimeoutConstant = millisecs; 165 | timeouts.ReadTotalTimeoutMultiplier = 0; 166 | 167 | timeouts.WriteTotalTimeoutConstant = MAXDWORD; 168 | timeouts.WriteTotalTimeoutMultiplier = 0; 169 | 170 | if (!SetCommTimeouts(_handle, &timeouts)) 171 | return false; 172 | 173 | return true; 174 | } 175 | 176 | int 177 | WinSerialPort::read(uint8_t* data, int size) 178 | { 179 | DWORD bytes; 180 | int total = 0; 181 | 182 | if (_handle == INVALID_HANDLE_VALUE) 183 | return -1; 184 | 185 | while (size > 0) 186 | { 187 | if (!ReadFile(_handle, data, size, &bytes, NULL)) 188 | return -1; 189 | if (bytes == 0) 190 | break; 191 | size -= bytes; 192 | data += bytes; 193 | total += bytes; 194 | } 195 | 196 | return total; 197 | } 198 | 199 | int 200 | WinSerialPort::write(const uint8_t* data, int size) 201 | { 202 | DWORD bytes; 203 | 204 | if (_handle == INVALID_HANDLE_VALUE) 205 | return -1; 206 | 207 | if (!WriteFile(_handle, data, size, &bytes, NULL)) 208 | return -1; 209 | 210 | return bytes; 211 | } 212 | 213 | int 214 | WinSerialPort::get() 215 | { 216 | uint8_t val; 217 | DWORD bytes; 218 | 219 | if (_handle == INVALID_HANDLE_VALUE) 220 | return -1; 221 | 222 | if (!ReadFile(_handle, &val, 1, &bytes, NULL)) 223 | return -1; 224 | 225 | if (bytes != 1) 226 | return -1; 227 | 228 | return val; 229 | } 230 | 231 | int 232 | WinSerialPort::put(int c) 233 | { 234 | uint8_t val = c; 235 | DWORD bytes; 236 | 237 | if (_handle == INVALID_HANDLE_VALUE) 238 | return -1; 239 | 240 | if (!WriteFile(_handle, &val, 1, &bytes, NULL)) 241 | return -1; 242 | 243 | if (bytes != 1) 244 | return -1; 245 | 246 | return val; 247 | } 248 | 249 | void 250 | WinSerialPort::flush() 251 | { 252 | Sleep(1); 253 | } 254 | 255 | void 256 | WinSerialPort::setDTR(bool dtr) 257 | { 258 | if (_handle == INVALID_HANDLE_VALUE) 259 | return; 260 | 261 | EscapeCommFunction(_handle, dtr ? SETDTR : CLRDTR); 262 | } 263 | 264 | void 265 | WinSerialPort::setRTS(bool rts) 266 | { 267 | if (_handle == INVALID_HANDLE_VALUE) 268 | return; 269 | 270 | EscapeCommFunction(_handle, rts ? SETRTS : CLRRTS); 271 | } 272 | -------------------------------------------------------------------------------- /src/WinSerialPort.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _WINSERIALPORT_H 30 | #define _WINSERIALPORT_H 31 | 32 | #include "SerialPort.h" 33 | 34 | #include 35 | #include 36 | 37 | class WinSerialPort : public SerialPort 38 | { 39 | public: 40 | WinSerialPort(const std::string& name, bool isUsb); 41 | virtual ~WinSerialPort(); 42 | 43 | bool open(int baud = 115200, 44 | int data = 8, 45 | SerialPort::Parity parity = SerialPort::ParityNone, 46 | SerialPort::StopBit stop = SerialPort::StopBitOne); 47 | void close(); 48 | 49 | bool isUsb() { return _isUsb; }; 50 | 51 | int read(uint8_t* data, int size); 52 | int write(const uint8_t* data, int size); 53 | int get(); 54 | int put(int c); 55 | 56 | bool timeout(int millisecs); 57 | void flush(); 58 | void setDTR(bool dtr); 59 | void setRTS(bool rts); 60 | 61 | private: 62 | HANDLE _handle; 63 | bool _isUsb; 64 | }; 65 | 66 | #endif // _WINSERIALPORT_H 67 | -------------------------------------------------------------------------------- /src/WordCopyApplet.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include "WordCopyApplet.h" 30 | 31 | WordCopyApplet::WordCopyApplet(Samba& samba, uint32_t addr) 32 | : Applet(samba, 33 | addr, 34 | applet.code, 35 | sizeof(applet.code), 36 | addr + applet.start, 37 | addr + applet.stack, 38 | addr + applet.reset) 39 | { 40 | } 41 | 42 | WordCopyApplet::~WordCopyApplet() 43 | { 44 | } 45 | 46 | void 47 | WordCopyApplet::setDstAddr(uint32_t dstAddr) 48 | { 49 | _samba.writeWord(_addr + applet.dst_addr, dstAddr); 50 | } 51 | 52 | void 53 | WordCopyApplet::setSrcAddr(uint32_t srcAddr) 54 | { 55 | _samba.writeWord(_addr + applet.src_addr, srcAddr); 56 | } 57 | 58 | void 59 | WordCopyApplet::setWords(uint32_t words) 60 | { 61 | _samba.writeWord(_addr + applet.words, words); 62 | } 63 | -------------------------------------------------------------------------------- /src/WordCopyApplet.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #ifndef _WORDCOPYAPPLET_H 30 | #define _WORDCOPYAPPLET_H 31 | 32 | #include "Applet.h" 33 | #include "WordCopyArm.h" 34 | 35 | class WordCopyApplet : public Applet 36 | { 37 | public: 38 | WordCopyApplet(Samba& samba, uint32_t addr); 39 | virtual ~WordCopyApplet(); 40 | 41 | void setDstAddr(uint32_t dstAddr); 42 | void setSrcAddr(uint32_t srcAddr); 43 | void setWords(uint32_t words); 44 | 45 | private: 46 | static WordCopyArm applet; 47 | }; 48 | 49 | #endif // _WORDCOPYAPPLET_H 50 | -------------------------------------------------------------------------------- /src/WordCopyArm.asm: -------------------------------------------------------------------------------- 1 | .global start 2 | .global stack 3 | .global reset 4 | .global dst_addr 5 | .global src_addr 6 | .global words 7 | 8 | .text 9 | .thumb 10 | .align 0 11 | 12 | start: 13 | ldr r0, dst_addr 14 | ldr r1, src_addr 15 | ldr r2, words 16 | b check 17 | 18 | copy: 19 | ldmia r1!, {r3} 20 | stmia r0!, {r3} 21 | sub r2, #1 22 | 23 | check: 24 | cmp r2, #0 25 | bne copy 26 | 27 | @ Fix for SAM-BA stack bug 28 | ldr r0, reset 29 | cmp r0, #0 30 | bne return 31 | ldr r0, stack 32 | mov sp, r0 33 | 34 | return: 35 | bx lr 36 | 37 | .align 0 38 | stack: 39 | .word 0 40 | reset: 41 | .word 0 42 | dst_addr: 43 | .word 0 44 | src_addr: 45 | .word 0 46 | words: 47 | .word 0 48 | -------------------------------------------------------------------------------- /src/WordCopyArm.cpp: -------------------------------------------------------------------------------- 1 | // WARNING!!! DO NOT EDIT - FILE GENERATED BY APPLETGEN 2 | #include "WordCopyArm.h" 3 | #include "WordCopyApplet.h" 4 | 5 | WordCopyArm WordCopyApplet::applet = { 6 | // dst_addr 7 | 0x00000028, 8 | // reset 9 | 0x00000024, 10 | // src_addr 11 | 0x0000002c, 12 | // stack 13 | 0x00000020, 14 | // start 15 | 0x00000000, 16 | // words 17 | 0x00000030, 18 | // code 19 | { 20 | 0x09, 0x48, 0x0a, 0x49, 0x0a, 0x4a, 0x02, 0xe0, 0x08, 0xc9, 0x08, 0xc0, 0x01, 0x3a, 0x00, 0x2a, 21 | 0xfa, 0xd1, 0x04, 0x48, 0x00, 0x28, 0x01, 0xd1, 0x01, 0x48, 0x85, 0x46, 0x70, 0x47, 0xc0, 0x46, 22 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /src/WordCopyArm.h: -------------------------------------------------------------------------------- 1 | // WARNING!!! DO NOT EDIT - FILE GENERATED BY APPLETGEN 2 | #ifndef _WORDCOPYARM_H 3 | #define _WORDCOPYARM_H 4 | 5 | #include 6 | 7 | typedef struct 8 | { 9 | uint32_t dst_addr; 10 | uint32_t reset; 11 | uint32_t src_addr; 12 | uint32_t stack; 13 | uint32_t start; 14 | uint32_t words; 15 | uint8_t code[52]; 16 | } WordCopyArm; 17 | 18 | #endif // _WORDCOPYARM_H 19 | -------------------------------------------------------------------------------- /src/bossash.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (c) 2011-2018, ShumaTech 5 | // All rights reserved. 6 | // 7 | // Redistribution and use in source and binary forms, with or without 8 | // modification, are permitted provided that the following conditions are met: 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above copyright 12 | // notice, this list of conditions and the following disclaimer in the 13 | // documentation and/or other materials provided with the distribution. 14 | // * Neither the name of the nor the 15 | // names of its contributors may be used to endorse or promote products 16 | // derived from this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | // DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | /////////////////////////////////////////////////////////////////////////////// 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "Shell.h" 37 | 38 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 39 | 40 | static int 41 | split(char* str, char* tokv[], int tokn) 42 | { 43 | int tokc; 44 | 45 | for (tokc = 0; tokc < tokn - 1; tokc++) 46 | { 47 | while (*str && isspace(*str)) 48 | str++; 49 | 50 | if (!*str) 51 | break; 52 | 53 | tokv[tokc] = str; 54 | 55 | while (*str && !isspace(*str)) 56 | str++; 57 | 58 | if (*str) 59 | *str++ = '\0'; 60 | } 61 | 62 | if (*str) 63 | tokv[tokc++] = str; 64 | 65 | return tokc; 66 | } 67 | 68 | int 69 | main(int argc, char* argv[]) 70 | { 71 | char *input; 72 | char *str; 73 | char *tokv[5]; 74 | int tokc; 75 | char *expansion; 76 | int result; 77 | 78 | printf("Press Ctrl-D or enter \"exit\" to end session.\n" 79 | "Enter \"help\" to display a command list.\n"); 80 | 81 | using_history(); 82 | 83 | try 84 | { 85 | Shell shell; 86 | 87 | while (!shell.exitFlag()) 88 | { 89 | input = readline("bossa> "); 90 | if (!input) 91 | { 92 | printf("\n"); 93 | break; 94 | } 95 | 96 | for (str = input; *str && isspace(*str); str++); 97 | 98 | if (*str) 99 | { 100 | result = history_expand(input, &expansion); 101 | if (result >= 0 && result != 2) 102 | { 103 | add_history(expansion); 104 | tokc = split(expansion, tokv, ARRAY_SIZE(tokv)); 105 | shell.invoke(tokv, tokc); 106 | } 107 | free(expansion); 108 | } 109 | free(input); 110 | } 111 | } 112 | catch(...) 113 | { 114 | printf("\nUnhandled exception\n"); 115 | return 1; 116 | } 117 | 118 | return 0; 119 | } 120 | --------------------------------------------------------------------------------