├── .gitignore ├── LICENSE.txt ├── Makefile ├── README ├── appletgen ├── bin └── bossash ├── install ├── Info.plist ├── background.png ├── background.xcf ├── banner.bmp ├── bossa-difx.wxs ├── bossa-dpinst.wxs ├── 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 ├── 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 ├── Driver.h ├── EefcFlash.cpp ├── EefcFlash.h ├── EfcFlash.cpp ├── EfcFlash.h ├── FileError.h ├── Flash.cpp ├── Flash.h ├── FlashFactory.cpp ├── FlashFactory.h ├── Flasher.cpp ├── Flasher.h ├── LinuxPortFactory.cpp ├── LinuxPortFactory.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 ├── arm-dis ├── ansidecl.h ├── arm-dis.cpp ├── arm-dis.h ├── arm.h ├── bfd.h ├── dis-asm.h ├── floatformat.cpp ├── floatformat.h ├── libiberty.h ├── symcat.h └── sysdep.h ├── bossac.cpp └── bossash.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | obj 3 | *.exe 4 | *~ 5 | bossa 6 | bossac 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := all 2 | 3 | # 4 | # Version 5 | # 6 | VERSION=1.3a 7 | WXVERSION=2.8 8 | 9 | # 10 | # Source files 11 | # 12 | COMMON_SRCS=Samba.cpp Flash.cpp EfcFlash.cpp EefcFlash.cpp FlashFactory.cpp Applet.cpp WordCopyApplet.cpp Flasher.cpp 13 | APPLET_SRCS=WordCopyArm.asm 14 | BOSSA_SRCS=BossaForm.cpp BossaWindow.cpp BossaAbout.cpp BossaApp.cpp BossaBitmaps.cpp BossaInfo.cpp BossaThread.cpp BossaProgress.cpp 15 | BOSSA_BMPS=BossaLogo.bmp BossaIcon.bmp ShumaTechLogo.bmp 16 | BOSSAC_SRCS=bossac.cpp CmdOpts.cpp 17 | BOSSASH_SRCS=bossash.cpp Shell.cpp Command.cpp arm-dis/arm-dis.cpp arm-dis/floatformat.cpp 18 | 19 | # 20 | # Build directories 21 | # 22 | BINDIR=bin 23 | OBJDIR=obj 24 | SRCDIR=src 25 | RESDIR=res 26 | INSTALLDIR=install 27 | 28 | # 29 | # Determine OS 30 | # 31 | OS:=$(shell uname -s | cut -c -7) 32 | 33 | # 34 | # Windows rules 35 | # 36 | ifeq ($(OS),MINGW32) 37 | EXE=.exe 38 | COMMON_SRCS+=WinSerialPort.cpp WinPortFactory.cpp 39 | COMMON_LDFLAGS=-Wl,--enable-auto-import -static -static-libstdc++ -static-libgcc 40 | COMMON_LIBS=-Wl,--as-needed -lsetupapi -ltermcap 41 | BOSSA_RC=BossaRes.rc 42 | WIXDIR="C:\Program Files (x86)\Windows Installer XML v3.5\bin" 43 | 44 | $(OBJDIR)\\bossa-$(VERSION).wixobj: $(INSTALLDIR)\\bossa.wxs 45 | $(WIXDIR)\\candle.exe -dVersion=$(VERSION) -arch x86 -out $@ -ext $(WIXDIR)\\WixUIExtension.dll -ext $(WIXDIR)\\WixDifxAppExtension.dll $< 46 | 47 | $(OBJDIR)\\bossa64-$(VERSION).wixobj: $(INSTALLDIR)\\bossa.wxs 48 | $(WIXDIR)\\candle.exe -dVersion=$(VERSION) -arch x64 -out $@ -ext $(WIXDIR)\\WixUIExtension.dll -ext $(WIXDIR)\\WixDifxAppExtension.dll $< 49 | 50 | $(BINDIR)\\bossa-$(VERSION).msi: $(OBJDIR)\\bossa-$(VERSION).wixobj 51 | $(WIXDIR)\\light.exe -cultures:null -out $@ -pdbout $(OBJDIR)\\bossa.wixpdb -sice:ICE57 -ext $(WIXDIR)\\WixUIExtension.dll -ext $(WIXDIR)\\WixDifxAppExtension.dll $(WIXDIR)\\difxapp_x86.wixlib $< 52 | 53 | $(BINDIR)\\bossa64-$(VERSION).msi: $(OBJDIR)\\bossa64-$(VERSION).wixobj 54 | $(WIXDIR)\\light.exe -cultures:null -out $@ -pdbout $(OBJDIR)\\bossa64.wixpdb -sice:ICE57 -ext $(WIXDIR)\\WixUIExtension.dll -ext $(WIXDIR)\\WixDifxAppExtension.dll $(WIXDIR)\\difxapp_x64.wixlib $< 55 | 56 | install32: $(BINDIR)\\bossa-$(VERSION).msi 57 | install64: $(BINDIR)\\bossa64-$(VERSION).msi 58 | .PHONY: install 59 | install: strip install32 install64 60 | 61 | endif 62 | 63 | # 64 | # Linux rules 65 | # 66 | ifeq ($(OS),Linux) 67 | COMMON_SRCS+=PosixSerialPort.cpp LinuxPortFactory.cpp 68 | COMMON_LIBS=-Wl,--as-needed 69 | WX_LIBS+=-lX11 70 | 71 | MACHINE:=$(shell uname -m) 72 | 73 | install: strip 74 | tar cvzf $(BINDIR)/bossa-$(MACHINE)-$(VERSION).tgz -C $(BINDIR) bossa$(EXE) bossac$(EXE) bossash$(EXE) 75 | endif 76 | 77 | # 78 | # OS X rules 79 | # 80 | ifeq ($(OS),Darwin) 81 | COMMON_SRCS+=PosixSerialPort.cpp OSXPortFactory.cpp 82 | COMMON_CXXFLAGS=-arch i386 83 | COMMON_LDFLAGS=-arch i386 84 | APP=BOSSA.app 85 | DMG=bossa-$(VERSION).dmg 86 | VOLUME=BOSSA 87 | BACKGROUND=$(INSTALLDIR)/background.png 88 | .PHONY: install 89 | app: 90 | mkdir -p $(BINDIR)/$(APP)/Contents/MacOS 91 | mkdir -p $(BINDIR)/$(APP)/Contents/Resources 92 | cp -f $(INSTALLDIR)/Info.plist $(BINDIR)/$(APP)/Contents 93 | echo -n "APPL????" > $(BINDIR)/$(APP)/Contents/PkgInfo 94 | ln -f $(BINDIR)/bossa $(BINDIR)/$(APP)/Contents/MacOS/bossa 95 | cp -f $(RESDIR)/BossaIcon.icns $(BINDIR)/$(APP)/Contents/Resources 96 | install: strip app 97 | hdiutil create -ov -megabytes 5 -fs HFS+ -volname $(VOLUME) $(BINDIR)/$(DMG) 98 | hdiutil attach -noautoopen $(BINDIR)/$(DMG) 99 | cp -R $(BINDIR)/$(APP) /Volumes/$(VOLUME)/ 100 | cp $(BINDIR)/bossac$(EXE) /Volumes/$(VOLUME)/ 101 | cp $(BINDIR)/bossash$(EXE) /Volumes/$(VOLUME)/ 102 | ln -s /Applications /Volumes/$(VOLUME)/Applications 103 | ln -s /usr/bin /Volumes/$(VOLUME)/bin 104 | mkdir /Volumes/$(VOLUME)/.background 105 | cp $(BACKGROUND) /Volumes/$(VOLUME)/.background 106 | osascript < $(INSTALLDIR)/dmgwin.osa 107 | hdiutil detach /Volumes/$(VOLUME)/ 108 | hdiutil convert -format UDBZ -o $(BINDIR)/tmp$(DMG) $(BINDIR)/$(DMG) 109 | mv -f $(BINDIR)/tmp$(DMG) $(BINDIR)/$(DMG) 110 | endif 111 | 112 | # 113 | # Object files 114 | # 115 | COMMON_OBJS=$(foreach src,$(COMMON_SRCS),$(OBJDIR)/$(src:%.cpp=%.o)) 116 | APPLET_OBJS=$(foreach src,$(APPLET_SRCS),$(OBJDIR)/$(src:%.asm=%.o)) 117 | BOSSA_OBJS=$(APPLET_OBJS) $(COMMON_OBJS) $(foreach src,$(BOSSA_SRCS),$(OBJDIR)/$(src:%.cpp=%.o)) 118 | ifdef BOSSA_RC 119 | BOSSA_OBJS+=$(OBJDIR)/$(BOSSA_RC:%.rc=%.o) 120 | endif 121 | BOSSAC_OBJS=$(APPLET_OBJS) $(COMMON_OBJS) $(foreach src,$(BOSSAC_SRCS),$(OBJDIR)/$(src:%.cpp=%.o)) 122 | BOSSASH_OBJS=$(APPLET_OBJS) $(COMMON_OBJS) $(foreach src,$(BOSSASH_SRCS),$(OBJDIR)/$(src:%.cpp=%.o)) 123 | 124 | # 125 | # Dependencies 126 | # 127 | DEPENDS=$(COMMON_SRCS:%.cpp=$(OBJDIR)/%.d) 128 | DEPENDS+=$(APPLET_SRCS:%.asm=$(OBJDIR)/%.d) 129 | DEPENDS+=$(BOSSA_SRCS:%.cpp=$(OBJDIR)/%.d) 130 | DEPENDS+=$(BOSSAC_SRCS:%.cpp=$(OBJDIR)/%.d) 131 | DEPENDS+=$(BOSSASH_SRCS:%.cpp=$(OBJDIR)/%.d) 132 | 133 | # 134 | # Tools 135 | # 136 | #Q=@ 137 | CXX=g++ 138 | ARM=arm-none-eabi- 139 | ARMAS=$(ARM)as 140 | ARMOBJCOPY=$(ARM)objcopy 141 | 142 | # 143 | # CXX Flags 144 | # 145 | COMMON_CXXFLAGS+=-Wall -Wno-error=unused-but-set-variable -MT $@ -MD -MP -MF $(@:%.o=%.d) -DVERSION=\"$(VERSION)\" -g -O2 146 | WX_CXXFLAGS:=$(shell wx-config --cxxflags --version=$(WXVERSION)) -DWX_PRECOMP -Wno-ctor-dtor-privacy -O2 -fno-strict-aliasing 147 | BOSSA_CXXFLAGS=$(COMMON_CXXFLAGS) $(WX_CXXFLAGS) 148 | BOSSAC_CXXFLAGS=$(COMMON_CXXFLAGS) 149 | BOSSASH_CXXFLAGS=$(COMMON_CXXFLAGS) -Isrc/arm-dis 150 | 151 | # 152 | # LD Flags 153 | # 154 | COMMON_LDFLAGS+=-g 155 | BOSSA_LDFLAGS=$(COMMON_LDFLAGS) 156 | BOSSAC_LDFLAGS=$(COMMON_LDFLAGS) 157 | BOSSASH_LDFLAGS=$(COMMON_LDFLAGS) 158 | 159 | # 160 | # Libs 161 | # 162 | COMMON_LIBS+= 163 | WX_LIBS:=$(shell wx-config --libs --version=$(WXVERSION)) $(WX_LIBS) 164 | BOSSA_LIBS=$(COMMON_LIBS) $(WX_LIBS) 165 | BOSSAC_LIBS=$(COMMON_LIBS) 166 | BOSSASH_LIBS=-lreadline $(COMMON_LIBS) 167 | 168 | # 169 | # Main targets 170 | # 171 | all: $(BINDIR)/bossa$(EXE) $(BINDIR)/bossac$(EXE) $(BINDIR)/bossash$(EXE) 172 | 173 | # 174 | # Common rules 175 | # 176 | define common_obj 177 | $(OBJDIR)/$(1:%.cpp=%.o): $(SRCDIR)/$(1) 178 | @echo CPP $$< 179 | $$(Q)$$(CXX) $$(COMMON_CXXFLAGS) -c -o $$@ $$< 180 | endef 181 | $(foreach src,$(COMMON_SRCS),$(eval $(call common_obj,$(src)))) 182 | 183 | # 184 | # Applet rules 185 | # 186 | define applet_obj 187 | $(SRCDIR)/$(1:%.asm=%.cpp): $(SRCDIR)/$(1) 188 | @echo APPLET $(1:%.asm=%) 189 | $$(Q)$$(ARMAS) -o $$(@:%.o=%.obj) $$< 190 | $$(Q)$$(ARMOBJCOPY) -O binary $$(@:%.o=%.obj) $$(@:%.o=%.bin) 191 | $$(Q)appletgen $(1:%.asm=%) $(SRCDIR) $(OBJDIR) 192 | $(OBJDIR)/$(1:%.asm=%.o): $(SRCDIR)/$(1:%.asm=%.cpp) 193 | @echo CPP $$< 194 | $$(Q)$$(CXX) $$(COMMON_CXXFLAGS) -c -o $$(@) $$(<:%.asm=%.cpp) 195 | endef 196 | $(foreach src,$(APPLET_SRCS),$(eval $(call applet_obj,$(src)))) 197 | 198 | # 199 | # BOSSA rules 200 | # 201 | define bossa_obj 202 | $(OBJDIR)/$(1:%.cpp=%.o): $(SRCDIR)/$(1) 203 | @echo CPP $$< 204 | $$(Q)$$(CXX) $$(BOSSA_CXXFLAGS) -c -o $$@ $$< 205 | endef 206 | $(foreach src,$(BOSSA_SRCS),$(eval $(call bossa_obj,$(src)))) 207 | 208 | # 209 | # Resource rules 210 | # 211 | ifeq ($(OS),MINGW32) 212 | $(OBJDIR)/$(BOSSA_RC:%.rc=%.o): $(RESDIR)/$(BOSSA_RC) 213 | @echo RC $< 214 | $(Q)`wx-config --rescomp --version=$(WXVERSION)` -o $@ $< 215 | endif 216 | 217 | # 218 | # BOSSAC rules 219 | # 220 | define bossac_obj 221 | $(OBJDIR)/$(1:%.cpp=%.o): $(SRCDIR)/$(1) 222 | @echo CPP $$< 223 | $$(Q)$$(CXX) $$(BOSSAC_CXXFLAGS) -c -o $$@ $$< 224 | endef 225 | $(foreach src,$(BOSSAC_SRCS),$(eval $(call bossac_obj,$(src)))) 226 | 227 | # 228 | # BOSSASH rules 229 | # 230 | define bossash_obj 231 | $(OBJDIR)/$(1:%.cpp=%.o): $(SRCDIR)/$(1) 232 | @echo CPP $$< 233 | $$(Q)$$(CXX) $$(BOSSASH_CXXFLAGS) -c -o $$@ $$< 234 | endef 235 | $(foreach src,$(BOSSASH_SRCS),$(eval $(call bossash_obj,$(src)))) 236 | 237 | # 238 | # BMP rules 239 | # 240 | define bossa_bmp 241 | $(SRCDIR)/$(1:%.bmp=%.cpp): $(RESDIR)/$(1) 242 | @echo BIN2C $$< 243 | $(Q)bin2c $$< $$@ 244 | endef 245 | $(foreach bmp,$(BOSSA_BMPS),$(eval $(call bossa_bmp,$(bmp)))) 246 | 247 | # 248 | # Directory rules 249 | # 250 | $(OBJDIR): 251 | @mkdir $@ 252 | 253 | $(OBJDIR)/arm-dis: 254 | @mkdir $@ 255 | 256 | $(BINDIR): 257 | @mkdir $@ 258 | 259 | # 260 | # Target rules 261 | # 262 | $(BOSSA_OBJS): | $(OBJDIR) 263 | $(BINDIR)/bossa$(EXE): $(foreach bmp,$(BOSSA_BMPS),$(SRCDIR)/$(bmp:%.bmp=%.cpp)) $(BOSSA_OBJS) | $(BINDIR) 264 | @echo LD $@ 265 | $(Q)$(CXX) $(BOSSA_LDFLAGS) -o $@ $(BOSSA_OBJS) $(BOSSA_LIBS) 266 | 267 | $(BOSSAC_OBJS): | $(OBJDIR) 268 | $(BINDIR)/bossac$(EXE): $(BOSSAC_OBJS) | $(BINDIR) 269 | @echo LD $@ 270 | $(Q)$(CXX) $(BOSSAC_LDFLAGS) -o $@ $(BOSSAC_OBJS) $(BOSSAC_LIBS) 271 | 272 | $(BOSSASH_OBJS): | $(OBJDIR) $(OBJDIR)/arm-dis 273 | $(BINDIR)/bossash$(EXE): $(BOSSASH_OBJS) | $(BINDIR) 274 | @echo LD $@ 275 | $(Q)$(CXX) $(BOSSASH_LDFLAGS) -o $@ $(BOSSASH_OBJS) $(BOSSASH_LIBS) 276 | 277 | strip-bossa: $(BINDIR)/bossa$(EXE) 278 | @echo STRIP $^ 279 | $(Q)strip $^ 280 | 281 | strip-bossac: $(BINDIR)/bossac$(EXE) 282 | @echo STRIP $^ 283 | $(Q)strip $^ 284 | 285 | strip-bossash: $(BINDIR)/bossash$(EXE) 286 | @echo STRIP $^ 287 | $(Q)strip $^ 288 | 289 | strip: strip-bossa strip-bossac strip-bossash 290 | 291 | clean: 292 | @echo CLEAN 293 | $(Q)rm -rf $(BINDIR) $(OBJDIR) 294 | 295 | # 296 | # Include dependencies 297 | # 298 | -include $(DEPENDS) 299 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | BOSSA 1.2 for Arduino Due 2 | 3 | This version of BOSSA is a fork of the original project and contains some 4 | patches specific for the Arduino Due product that are unlike to be accepted 5 | upstream. 6 | 7 | The original software is developed by Scott Shumate and can be found here: 8 | 9 | http://www.shumatech.com/web/products/bossa 10 | 11 | Original README follows. 12 | 13 | 14 | BOSSA 1.2 15 | 16 | FILES 17 | ----- 18 | bossa-1.2.msi -- Windows 2000+ 19 | bossa64-1.2.msi -- Windows 2000+ 64-bit 20 | bossa-i686-1.2.tgz -- Linux GTK 21 | bossa-x86_64-1.2.tgz -- Linux GTK 64-bit 22 | bossa-1.2.dmg -- MAC OS X 10.6+ 23 | 24 | NEW IN THIS RELEASE 25 | ------------------- 26 | * New BOSSA shell command line application to do basic memory, flash, and PIO diagnostics 27 | * Workaround for SAM3U firmware bug 28 | * Fixed a bug with setting boot to flash bit on SAM3 devices 29 | 30 | RELEASE NOTES 31 | ------------- 32 | * The OS X USB driver detects an Atmel device as a USB modem. When prompted about a new network interface, click Cancel to continue. 33 | * Some stability issues have been seen with the OS X USB driver using BOSSA. When running BOSSA a second time to the same Atmel device, the USB driver can lock up causing BOSSA to freeze. As a workaround, always disconnect and reconnect the Atmel device before running BOSSA again. 34 | * The firmware inside of SAM3U devices has a bug where non-word flash reads return zero instead of the real data. BOSSA implements a transparent workaround for flash operations that copies flash to SRAM before reading. Direct reads using the BOSSA shell will see the bug. 35 | * There are reports that the USB controller in some AMD-based systems has difficulty communicating with SAM devices. The only known workaround is to use a different, preferrably Intel-based, system. 36 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /bin/bossash: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/bin/bossash -------------------------------------------------------------------------------- /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/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/install/background.png -------------------------------------------------------------------------------- /install/background.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/install/background.xcf -------------------------------------------------------------------------------- /install/banner.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/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.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 | 8 | [DestinationDirs] ; DestinationDirs section 9 | DefaultDestDir=12 ; Default install directory is \drivers or \IOSubSys 10 | 11 | [Manufacturer] ; Manufacturer section 12 | %SHUMATECH%=ShumaTech,NTamd64 ; Only one manufacturer (SHUMATECH), models section is named 13 | ; ShumaTech 14 | 15 | [ShumaTech] ; Models section corresponding to SHUMATECH 16 | %BOSSA%=BOSSA.Install,USB\VID_03EB&PID_6124 ; Identifies a device with Vendor ID (03EBh) and 17 | ; Product ID equal to 6124h. Corresponding Install section 18 | ; is named BOSSA.Install 19 | 20 | [ShumaTech.NTamd64] ; Models section corresponding to SHUMATECH 21 | %BOSSA%=BOSSA.Install,USB\VID_03EB&PID_6124 ; Identifies a device with Vendor ID (03EBh) and 22 | ; Product ID equal to 6124h. Corresponding Install section 23 | ; is named BOSSA.Install 24 | 25 | [BOSSA.Install] ; Install section 26 | include=mdmcpq.inf 27 | CopyFiles=FakeModemCopyFileSection 28 | AddReg=BOSSA.AddReg ; Registry keys to add are listed in BOSSA.AddReg 29 | 30 | [BOSSA.AddReg] ; AddReg section 31 | HKR,,DevLoader,,*ntkern 32 | HKR,,NTMPDriver,,usbser.sys 33 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 34 | 35 | [BOSSA.Install.Services] ; Services section 36 | AddService=usbser,0x00000002,BOSSA.AddService ; Assign usbser as the PnP driver for the device 37 | 38 | [BOSSA.AddService] ; Service install section 39 | DisplayName=%USBSer% ; Name of the serial driver 40 | ServiceType=1 ; Service kernel driver 41 | StartType=3 ; Driver is started by the PnP manager 42 | ErrorControl=1 ; Warn about errors 43 | ServiceBinary=%12%\usbser.sys ; Driver filename 44 | 45 | [Strings] ; Strings section 46 | SHUMATECH="ShumaTech" ; String value for the SHUMATECH symbol 47 | BOSSA="BOSSA Program Port" ; String value for the BOSSA symbol 48 | USBSer="USB Serial Driver" ; String value for the USBSer symbol 49 | -------------------------------------------------------------------------------- /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 | 95 | 96 | 97 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | NOT VersionNT64 110 | 111 | 112 | 113 | 115 | 116 | 118 | 120 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /install/dialog.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/install/dialog.bmp -------------------------------------------------------------------------------- /install/dialog.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/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, 412} 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{\fonttbl{\f0\fswiss\fcharset0 Arial;}} 2 | {\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 BOSSA - Flash Programmer for Atmel SAM Devices\par 3 | Copyright (C) 2011-2012 ShumaTech\par 4 | \par 5 | This program is free software: you can redistribute it and/or modify\par 6 | it under the terms of the GNU General Public License as published by\par 7 | the Free Software Foundation, either version 3 of the License, or\par 8 | (at your option) any later version.\par 9 | \par 10 | This program is distributed in the hope that it will be useful,\par 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of\par 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\par 13 | See the GNU General Public License for more details.\par 14 | \par 15 | You should have received a copy of the GNU General Public License\par 16 | along with this program. If not, see .\par 17 | \par 18 | } 19 | 20 | -------------------------------------------------------------------------------- /res/BossaIcon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/res/BossaIcon.bmp -------------------------------------------------------------------------------- /res/BossaIcon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/res/BossaIcon.icns -------------------------------------------------------------------------------- /res/BossaIcon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/res/BossaIcon.ico -------------------------------------------------------------------------------- /res/BossaIcon.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/res/BossaIcon.xcf -------------------------------------------------------------------------------- /res/BossaLogo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/res/BossaLogo.bmp -------------------------------------------------------------------------------- /res/BossaLogo.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/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/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/res/ShumaTechLogo.bmp -------------------------------------------------------------------------------- /res/ShumaTechLogo.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flutterwireless/BOSSA-Arduino/4cca55aa6d08b1f21ead41c089f5cef9a9552065/res/ShumaTechLogo.xcf -------------------------------------------------------------------------------- /src/Applet.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "Applet.h" 20 | 21 | Applet::Applet(Samba& samba, 22 | uint32_t addr, 23 | uint8_t* code, 24 | uint32_t size, 25 | uint32_t start, 26 | uint32_t stack, 27 | uint32_t reset) : 28 | _samba(samba), _addr(addr), _size(size), _start(start), _stack(stack), _reset(reset) 29 | { 30 | _samba.write(addr, code, size); 31 | } 32 | 33 | void 34 | Applet::setStack(uint32_t stack) 35 | { 36 | _samba.writeWord(_stack, stack); 37 | } 38 | 39 | void 40 | Applet::run() 41 | { 42 | // Add one to the start address for Thumb mode 43 | _samba.go(_start + 1); 44 | } 45 | 46 | void 47 | Applet::runv() 48 | { 49 | // Add one to the start address for Thumb mode 50 | _samba.writeWord(_reset, _start + 1); 51 | 52 | // The stack is the first reset vector 53 | _samba.go(_stack); 54 | } 55 | -------------------------------------------------------------------------------- /src/Applet.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _APPLET_H 20 | #define _APPLET_H 21 | 22 | #include 23 | 24 | #include "Samba.h" 25 | 26 | class Applet 27 | { 28 | public: 29 | Applet(Samba& samba, 30 | uint32_t addr, 31 | uint8_t* code, 32 | uint32_t size, 33 | uint32_t start, 34 | uint32_t stack, 35 | uint32_t reset); 36 | virtual ~Applet() {} 37 | 38 | virtual uint32_t size() { return _size; } 39 | virtual uint32_t addr() { return _addr; } 40 | 41 | virtual void setStack(uint32_t stack); 42 | 43 | virtual void run(); 44 | virtual void runv(); 45 | 46 | protected: 47 | Samba& _samba; 48 | uint32_t _addr; 49 | uint32_t _size; 50 | uint32_t _start; 51 | uint32_t _stack; 52 | uint32_t _reset; 53 | }; 54 | 55 | #endif // _APPLET_H 56 | -------------------------------------------------------------------------------- /src/BossaAbout.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "BossaAbout.h" 20 | #include "BossaApp.h" 21 | 22 | #include "wx/version.h" 23 | 24 | BossaAbout::BossaAbout(wxWindow* parent) : AboutDialog(parent) 25 | { 26 | BossaApp& app = wxGetApp(); 27 | 28 | _bossaBitmap->SetBitmap(app.bitmaps.getBossaLogo()); 29 | _shumatechBitmap->SetBitmap(app.bitmaps.getShumaTechLogo()); 30 | _versionStaticText->SetLabel(wxString::Format(wxT("Version: %s"), VERSION)); 31 | _wxStaticText->SetLabel(wxString::Format(wxT("Built with %s"), wxVERSION_STRING)); 32 | GetSizer()->Fit(this); 33 | } 34 | -------------------------------------------------------------------------------- /src/BossaAbout.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _BOSSAABOUT_H 20 | #define _BOSSAABOUT_H 21 | 22 | #include "BossaForm.h" 23 | 24 | class BossaAbout : public AboutDialog 25 | { 26 | public: 27 | BossaAbout(wxWindow* parent); 28 | }; 29 | 30 | #endif // _BOSSAABOUT_H 31 | -------------------------------------------------------------------------------- /src/BossaApp.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "BossaApp.h" 20 | 21 | BossaApp::BossaApp() : config(_("Bossa")) 22 | { 23 | } 24 | 25 | bool 26 | BossaApp::OnInit() 27 | { 28 | bitmaps.init(); 29 | _window = new BossaWindow(); 30 | _window->Show(true); 31 | SetTopWindow(_window); 32 | 33 | return true; 34 | } 35 | 36 | IMPLEMENT_APP(BossaApp) 37 | -------------------------------------------------------------------------------- /src/BossaApp.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _BOSSAAPP_H 20 | #define _BOSSAAPP_H 21 | 22 | #include 23 | #include 24 | 25 | #include "PortFactory.h" 26 | #include "Samba.h" 27 | #include "Flash.h" 28 | #include "BossaBitmaps.h" 29 | #include "BossaWindow.h" 30 | 31 | class BossaApp : public wxApp 32 | { 33 | public: 34 | BossaApp(); 35 | 36 | PortFactory portFactory; 37 | Samba samba; 38 | BossaBitmaps bitmaps; 39 | Flash::Ptr flash; 40 | wxConfig config; 41 | 42 | private: 43 | bool OnInit(); 44 | 45 | BossaWindow* _window; 46 | }; 47 | 48 | DECLARE_APP(BossaApp) 49 | 50 | #endif // _BOSSAAPP_H 51 | -------------------------------------------------------------------------------- /src/BossaBitmaps.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "BossaBitmaps.h" 20 | 21 | #include 22 | 23 | #include "BossaLogo.cpp" 24 | #include "BossaIcon.cpp" 25 | #include "ShumaTechLogo.cpp" 26 | 27 | BossaBitmaps::BossaBitmaps() 28 | { 29 | wxImage::AddHandler(new wxBMPHandler); 30 | } 31 | 32 | void 33 | BossaBitmaps::init() 34 | { 35 | _bossaLogo = GetBitmapFromMemory(BossaLogo_bmp, sizeof(BossaLogo_bmp)); 36 | _bossaIcon = GetBitmapFromMemory(BossaIcon_bmp, sizeof(BossaIcon_bmp)); 37 | _shumaTechLogo = GetBitmapFromMemory(ShumaTechLogo_bmp, sizeof(ShumaTechLogo_bmp)); 38 | } 39 | 40 | wxBitmap 41 | BossaBitmaps::GetBitmapFromMemory(const unsigned char *data, int length) 42 | { 43 | wxMemoryInputStream is(data, length); 44 | return wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1); 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/BossaBitmaps.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _BOSSABITMAPS_H 20 | #define _BOSSABITMAPS_H 21 | 22 | #include 23 | 24 | class BossaBitmaps 25 | { 26 | public: 27 | BossaBitmaps(); 28 | 29 | void init(); 30 | 31 | const wxBitmap& getBossaLogo() { return _bossaLogo; } 32 | const wxBitmap& getBossaIcon() { return _bossaIcon; } 33 | const wxBitmap& getShumaTechLogo() { return _shumaTechLogo; } 34 | 35 | private: 36 | wxBitmap GetBitmapFromMemory(const unsigned char *data, int length); 37 | 38 | wxBitmap _bossaLogo; 39 | wxBitmap _bossaIcon; 40 | wxBitmap _shumaTechLogo; 41 | }; 42 | 43 | #endif // _BOSSABITMAPS_H 44 | -------------------------------------------------------------------------------- /src/BossaForm.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////// 2 | // C++ code generated with wxFormBuilder (version Nov 17 2010) 3 | // http://www.wxformbuilder.org/ 4 | // 5 | // PLEASE DO "NOT" EDIT THIS FILE! 6 | /////////////////////////////////////////////////////////////////////////// 7 | 8 | #ifndef __BossaForm__ 9 | #define __BossaForm__ 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 | 35 | /////////////////////////////////////////////////////////////////////////// 36 | 37 | 38 | /////////////////////////////////////////////////////////////////////////////// 39 | /// Class MainFrame 40 | /////////////////////////////////////////////////////////////////////////////// 41 | class MainFrame : public wxFrame 42 | { 43 | private: 44 | 45 | protected: 46 | wxStaticBitmap* _bossaBitmap; 47 | wxStaticText* _titleText; 48 | 49 | wxButton* _aboutButton; 50 | wxComboBox* _portComboBox; 51 | wxButton* _refreshButton; 52 | 53 | wxButton* _autoScanButton; 54 | wxFilePickerCtrl* _filePicker; 55 | wxCheckBox* _eraseCheckBox; 56 | wxCheckBox* _bodCheckBox; 57 | wxCheckBox* _lockCheckBox; 58 | wxCheckBox* _bootCheckBox; 59 | wxCheckBox* _borCheckBox; 60 | wxCheckBox* _securityCheckBox; 61 | wxStaticText* _sizeStaticText; 62 | wxTextCtrl* _sizeTextCtrl; 63 | 64 | wxButton* _writeButton; 65 | 66 | wxButton* _verifyButton; 67 | 68 | wxButton* _readButton; 69 | 70 | wxButton* _infoButton; 71 | 72 | wxButton* _exitButton; 73 | 74 | wxStatusBar* _statusBar; 75 | 76 | public: 77 | 78 | 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 ); 79 | 80 | ~MainFrame(); 81 | 82 | }; 83 | 84 | /////////////////////////////////////////////////////////////////////////////// 85 | /// Class ProgressDialog 86 | /////////////////////////////////////////////////////////////////////////////// 87 | class ProgressDialog : public wxDialog 88 | { 89 | private: 90 | 91 | protected: 92 | 93 | wxStaticText* _infoStaticText; 94 | wxGauge* _statusGauge; 95 | 96 | wxStdDialogButtonSizer* _sdbSizer; 97 | wxButton* _sdbSizerCancel; 98 | 99 | 100 | public: 101 | 102 | 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 ); 103 | ~ProgressDialog(); 104 | 105 | }; 106 | 107 | /////////////////////////////////////////////////////////////////////////////// 108 | /// Class AboutDialog 109 | /////////////////////////////////////////////////////////////////////////////// 110 | class AboutDialog : public wxDialog 111 | { 112 | private: 113 | 114 | protected: 115 | wxStaticBitmap* _bossaBitmap; 116 | wxStaticText* _titleStaticText; 117 | wxStaticText* _versionStaticText; 118 | wxStaticText* _wxStaticText; 119 | wxStaticLine* m_staticline1; 120 | wxStaticBitmap* _shumatechBitmap; 121 | wxStaticText* _copyrightStaticText; 122 | wxHyperlinkCtrl* _shumatechHyperlink; 123 | wxStaticLine* m_staticline2; 124 | wxStaticText* m_disclaimerStaticText; 125 | wxStaticLine* m_staticline3; 126 | wxStdDialogButtonSizer* _sdbSizer; 127 | wxButton* _sdbSizerOK; 128 | 129 | public: 130 | 131 | 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 ); 132 | ~AboutDialog(); 133 | 134 | }; 135 | 136 | /////////////////////////////////////////////////////////////////////////////// 137 | /// Class InfoDialog 138 | /////////////////////////////////////////////////////////////////////////////// 139 | class InfoDialog : public wxDialog 140 | { 141 | private: 142 | 143 | protected: 144 | wxStaticText* _deviceStaticText; 145 | wxTextCtrl* _deviceTextCtrl; 146 | wxStaticText* _chipIdStaticText; 147 | wxTextCtrl* _chipIdTextCtrl; 148 | wxStaticText* _versionStaticText; 149 | wxTextCtrl* _versionTextCtrl; 150 | wxStaticText* _pagesStaticText; 151 | wxTextCtrl* _pagesTextCtrl; 152 | wxStaticText* _pageSizeStaticText; 153 | wxTextCtrl* _pageSizeTextCtrl; 154 | wxStaticText* _totalSizeStaticText; 155 | wxTextCtrl* _totalSizeTextCtrl; 156 | wxStaticText* _planesStaticText; 157 | wxTextCtrl* _planesTextCtrl; 158 | wxCheckBox* _bootCheckBox; 159 | wxCheckBox* _bodCheckBox; 160 | wxCheckBox* _securityCheckBox; 161 | wxCheckBox* _borCheckBox; 162 | wxStaticText* _lockStaticText; 163 | wxCheckBox* _lockCheckBox0; 164 | wxCheckBox* _lockCheckBox1; 165 | wxCheckBox* _lockCheckBox2; 166 | wxCheckBox* _lockCheckBox3; 167 | wxCheckBox* _lockCheckBox4; 168 | wxCheckBox* _lockCheckBox5; 169 | wxCheckBox* _lockCheckBox6; 170 | wxCheckBox* _lockCheckBox7; 171 | wxCheckBox* _lockCheckBox8; 172 | wxCheckBox* _lockCheckBox9; 173 | wxCheckBox* _lockCheckBox10; 174 | wxCheckBox* _lockCheckBox11; 175 | wxCheckBox* _lockCheckBox12; 176 | wxCheckBox* _lockCheckBox13; 177 | wxCheckBox* _lockCheckBox14; 178 | wxCheckBox* _lockCheckBox15; 179 | wxCheckBox* _lockCheckBox16; 180 | wxCheckBox* _lockCheckBox17; 181 | wxCheckBox* _lockCheckBox18; 182 | wxCheckBox* _lockCheckBox19; 183 | wxCheckBox* _lockCheckBox20; 184 | wxCheckBox* _lockCheckBox21; 185 | wxCheckBox* _lockCheckBox22; 186 | wxCheckBox* _lockCheckBox23; 187 | wxCheckBox* _lockCheckBox24; 188 | wxCheckBox* _lockCheckBox25; 189 | wxCheckBox* _lockCheckBox26; 190 | wxCheckBox* _lockCheckBox27; 191 | wxCheckBox* _lockCheckBox28; 192 | wxCheckBox* _lockCheckBox29; 193 | wxCheckBox* _lockCheckBox30; 194 | wxCheckBox* _lockCheckBox31; 195 | wxStdDialogButtonSizer* _sdbSizer; 196 | wxButton* _sdbSizerOK; 197 | 198 | public: 199 | 200 | 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 ); 201 | ~InfoDialog(); 202 | 203 | }; 204 | 205 | #endif //__BossaForm__ 206 | -------------------------------------------------------------------------------- /src/BossaInfo.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "BossaInfo.h" 20 | #include "BossaApp.h" 21 | 22 | #include 23 | 24 | BossaInfo::BossaInfo(wxWindow* parent) : InfoDialog(parent) 25 | { 26 | Samba& samba = wxGetApp().samba; 27 | Flash::Ptr& flash = wxGetApp().flash; 28 | 29 | _deviceTextCtrl->SetValue(wxString(flash->name().c_str(), wxConvUTF8)); 30 | _chipIdTextCtrl->SetValue(wxString::Format(wxT("%08x"), samba.chipId())); 31 | _versionTextCtrl->SetValue(wxString(samba.version().c_str(), wxConvUTF8)); 32 | 33 | _pagesTextCtrl->SetValue(wxString::Format(wxT("%d"), flash->numPages())); 34 | _pageSizeTextCtrl->SetValue(wxString::Format(wxT("%d bytes"), flash->pageSize())); 35 | _totalSizeTextCtrl->SetValue(wxString::Format(wxT("%d KB"),flash->numPages() * flash->pageSize() / 1024)); 36 | _planesTextCtrl->SetValue(wxString::Format(wxT("%d"),flash->numPlanes())); 37 | 38 | _bootCheckBox->Enable(false); 39 | _securityCheckBox->Enable(false); 40 | _bodCheckBox->Enable(false); 41 | _borCheckBox->Enable(false); 42 | 43 | _bootCheckBox->SetValue(flash->getBootFlash()); 44 | _securityCheckBox->SetValue(flash->getSecurity()); 45 | _bodCheckBox->SetValue(flash->getBod()); 46 | _borCheckBox->SetValue(flash->getBor()); 47 | 48 | uint32_t lockRegions = flash->lockRegions(); 49 | wxCheckBox* lockCheckBox[32] = { 50 | _lockCheckBox0, _lockCheckBox1, _lockCheckBox2, _lockCheckBox3, 51 | _lockCheckBox4, _lockCheckBox5, _lockCheckBox6, _lockCheckBox7, 52 | _lockCheckBox8, _lockCheckBox9, _lockCheckBox10, _lockCheckBox11, 53 | _lockCheckBox12, _lockCheckBox13, _lockCheckBox14, _lockCheckBox15, 54 | _lockCheckBox16, _lockCheckBox17, _lockCheckBox18, _lockCheckBox19, 55 | _lockCheckBox20, _lockCheckBox21, _lockCheckBox22, _lockCheckBox23, 56 | _lockCheckBox24, _lockCheckBox25, _lockCheckBox26, _lockCheckBox27, 57 | _lockCheckBox28, _lockCheckBox29, _lockCheckBox30, _lockCheckBox31, 58 | }; 59 | 60 | for (uint32_t i = 0; i < sizeof(lockCheckBox) / sizeof(lockCheckBox[0]); i++) 61 | { 62 | if (i >= lockRegions) 63 | { 64 | lockCheckBox[i]->Destroy(); 65 | } 66 | else 67 | { 68 | lockCheckBox[i]->Enable(false); 69 | lockCheckBox[i]->SetValue(flash->getLockRegion(i)); 70 | } 71 | } 72 | 73 | GetSizer()->Fit(this); 74 | } 75 | -------------------------------------------------------------------------------- /src/BossaInfo.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _BOSSAINFO_H 20 | #define _BOSSAINFO_H 21 | 22 | #include "BossaForm.h" 23 | 24 | class BossaInfo : public InfoDialog 25 | { 26 | public: 27 | BossaInfo(wxWindow* parent); 28 | }; 29 | 30 | #endif // _BOSSAINFO_H 31 | -------------------------------------------------------------------------------- /src/BossaProgress.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "BossaProgress.h" 20 | 21 | DEFINE_EVENT_TYPE(wxEVT_PROGRESS_CANCEL) 22 | 23 | BossaProgress::BossaProgress(wxWindow* parent) : ProgressDialog(parent), _parent(parent) 24 | { 25 | _statusGauge->SetRange(100); 26 | SetValue(0); 27 | 28 | _sdbSizerCancel->Connect(wxEVT_COMMAND_BUTTON_CLICKED, 29 | wxCommandEventHandler(BossaProgress::OnCancel), 30 | NULL, this); 31 | } 32 | 33 | void 34 | BossaProgress::SetValue(int pos) 35 | { 36 | _statusGauge->SetValue(pos); 37 | #if __WIN32 38 | // Work around slow update on Windows 39 | _statusGauge->SetValue(pos - 1); 40 | _statusGauge->SetValue(pos); 41 | #endif 42 | } 43 | 44 | void 45 | BossaProgress::SetLabel(const wxString& label) 46 | { 47 | _infoStaticText->SetLabel(label); 48 | } 49 | 50 | void 51 | BossaProgress::OnCancel(wxCommandEvent& event) 52 | { 53 | wxCommandEvent cmd(wxEVT_PROGRESS_CANCEL); 54 | _parent->AddPendingEvent(cmd); 55 | } 56 | -------------------------------------------------------------------------------- /src/BossaProgress.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _BOSSAPROGRESS_H 20 | #define _BOSSAPROGRESS_H 21 | 22 | #include "BossaForm.h" 23 | 24 | DECLARE_EVENT_TYPE(wxEVT_PROGRESS_CANCEL, wxID_ANY) 25 | 26 | class BossaProgress : public ProgressDialog 27 | { 28 | public: 29 | BossaProgress(wxWindow* parent); 30 | 31 | void SetValue(int pos); 32 | void SetLabel(const wxString& label); 33 | 34 | private: 35 | wxEvtHandler* _parent; 36 | 37 | void OnCancel(wxCommandEvent& event); 38 | }; 39 | 40 | #endif // _BOSSAPROGRESS_H 41 | -------------------------------------------------------------------------------- /src/BossaThread.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "BossaThread.h" 20 | #include "BossaApp.h" 21 | #include "Flash.h" 22 | 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | 28 | DEFINE_EVENT_TYPE(wxEVT_THREAD_PROGRESS) 29 | DEFINE_EVENT_TYPE(wxEVT_THREAD_SUCCESS) 30 | DEFINE_EVENT_TYPE(wxEVT_THREAD_WARNING) 31 | DEFINE_EVENT_TYPE(wxEVT_THREAD_ERROR) 32 | 33 | class FileOpenError : public exception 34 | { 35 | public: 36 | FileOpenError() : exception() {}; 37 | const char* what() const throw() { return "Unable to open file"; } 38 | }; 39 | 40 | class FileIoError : public exception 41 | { 42 | public: 43 | FileIoError() : exception() {}; 44 | const char* what() const throw() { return "File I/O operation failed"; } 45 | }; 46 | 47 | class FileSizeError : public exception 48 | { 49 | public: 50 | FileSizeError() : exception() {}; 51 | const char* what() const throw() { return "File operation exceeds flash size"; } 52 | }; 53 | 54 | BossaThread::BossaThread(wxEvtHandler* parent) : wxThread(), _parent(parent), _stopped(false) 55 | { 56 | } 57 | 58 | void 59 | BossaThread::Progress(const wxString& message, int pos) 60 | { 61 | wxCommandEvent event(wxEVT_THREAD_PROGRESS); 62 | event.SetString(message); 63 | event.SetInt(pos); 64 | _parent->AddPendingEvent(event); 65 | } 66 | 67 | void 68 | BossaThread::Success(const wxString& message) 69 | { 70 | wxCommandEvent event(wxEVT_THREAD_SUCCESS); 71 | event.SetString(message); 72 | _parent->AddPendingEvent(event); 73 | } 74 | 75 | void 76 | BossaThread::Warning(const wxString& message) 77 | { 78 | wxCommandEvent event(wxEVT_THREAD_WARNING); 79 | event.SetString(message); 80 | _parent->AddPendingEvent(event); 81 | } 82 | 83 | void 84 | BossaThread::Error(const wxString& message) 85 | { 86 | wxCommandEvent event(wxEVT_THREAD_ERROR); 87 | event.SetString(message); 88 | _parent->AddPendingEvent(event); 89 | } 90 | 91 | WriteThread::WriteThread(wxEvtHandler* parent, 92 | const wxString& filename, 93 | bool eraseAll, 94 | bool bootFlash, 95 | bool bod, 96 | bool bor, 97 | bool lock, 98 | bool security) : 99 | BossaThread(parent), _filename(filename), _eraseAll(eraseAll), 100 | _bootFlash(bootFlash), _bod(bod), _bor(bor), _lock(lock), _security(security) 101 | 102 | { 103 | } 104 | 105 | wxThread::ExitCode 106 | WriteThread::Entry() 107 | { 108 | FILE* infile = NULL; 109 | Flash& flash = *wxGetApp().flash; 110 | uint32_t pageSize = flash.pageSize(); 111 | uint8_t buffer[pageSize]; 112 | uint32_t pageNum = 0; 113 | uint32_t numPages; 114 | long fsize; 115 | size_t fbytes; 116 | 117 | try 118 | { 119 | if (_eraseAll) 120 | { 121 | flash.eraseAll(); 122 | flash.eraseAuto(false); 123 | } 124 | else 125 | { 126 | flash.eraseAuto(true); 127 | } 128 | 129 | infile = fopen(_filename.mb_str(), "rb"); 130 | if (!infile) 131 | throw FileOpenError(); 132 | 133 | if (fseek(infile, 0, SEEK_END) != 0 || 134 | (fsize = ftell(infile)) < 0) 135 | throw FileIoError(); 136 | rewind(infile); 137 | 138 | numPages = (fsize + pageSize - 1) / pageSize; 139 | if (numPages > flash.numPages()) 140 | throw FileSizeError(); 141 | 142 | while ((fbytes = fread(buffer, 1, pageSize, infile)) > 0) 143 | { 144 | if (_stopped) 145 | { 146 | fclose(infile); 147 | Warning(wxT("Write stopped")); 148 | return 0; 149 | } 150 | 151 | if (pageNum % 10 == 0 || pageNum == numPages - 1) 152 | { 153 | uint32_t percent = (pageNum + 1) * 100 / numPages; 154 | Progress(wxString::Format(wxT("Writing page %d (%d%%)"), pageNum, percent), 155 | percent); 156 | } 157 | 158 | flash.loadBuffer(buffer); 159 | flash.writePage(pageNum); 160 | 161 | pageNum++; 162 | if (pageNum == numPages) 163 | break; 164 | if (fbytes != pageSize) 165 | throw FileIoError(); 166 | } 167 | if (fbytes <= 0) 168 | throw FileIoError(); 169 | 170 | flash.setBootFlash(_bootFlash); 171 | flash.setBod(_bod); 172 | flash.setBor(_bor); 173 | if (_lock) 174 | flash.lockAll(); 175 | if (_security) 176 | flash.setSecurity(); 177 | 178 | fclose(infile); 179 | } 180 | catch(exception& e) 181 | { 182 | if (infile) 183 | fclose(infile); 184 | Error(wxString(e.what(), wxConvUTF8)); 185 | return 0; 186 | } 187 | 188 | Success(_("Write completed successfully")); 189 | return 0; 190 | } 191 | 192 | VerifyThread::VerifyThread(wxEvtHandler* parent, const wxString& filename) : 193 | BossaThread(parent), _filename(filename) 194 | { 195 | } 196 | 197 | wxThread::ExitCode 198 | VerifyThread::Entry() 199 | { 200 | FILE* infile = NULL; 201 | Flash& flash = *wxGetApp().flash; 202 | uint32_t pageSize = flash.pageSize(); 203 | uint8_t bufferA[pageSize]; 204 | uint8_t bufferB[pageSize]; 205 | uint32_t pageNum = 0; 206 | uint32_t numPages; 207 | uint32_t byteErrors = 0; 208 | uint32_t pageErrors = 0; 209 | uint32_t totalErrors = 0; 210 | long fsize; 211 | size_t fbytes; 212 | 213 | try 214 | { 215 | infile = fopen(_filename.mb_str(), "rb"); 216 | if (!infile) 217 | throw FileOpenError(); 218 | 219 | if (fseek(infile, 0, SEEK_END) != 0 || 220 | (fsize = ftell(infile)) < 0) 221 | throw FileIoError(); 222 | rewind(infile); 223 | 224 | numPages = (fsize + pageSize - 1) / pageSize; 225 | if (numPages > flash.numPages()) 226 | throw FileSizeError(); 227 | 228 | while ((fbytes = fread(bufferA, 1, pageSize, infile)) > 0) 229 | { 230 | if (_stopped) 231 | { 232 | fclose(infile); 233 | Warning(wxT("Verify stopped")); 234 | return 0; 235 | } 236 | 237 | if (pageNum % 10 == 0 || pageNum == numPages - 1) 238 | { 239 | uint32_t percent = (pageNum + 1) * 100 / numPages; 240 | Progress(wxString::Format(wxT("Verifying page %d (%d%%)"), pageNum, percent), 241 | percent); 242 | } 243 | 244 | flash.readPage(pageNum, bufferB); 245 | 246 | byteErrors = 0; 247 | for (uint32_t i = 0; i < fbytes; i++) 248 | { 249 | if (bufferA[i] != bufferB[i]) 250 | byteErrors++; 251 | } 252 | if (byteErrors != 0) 253 | { 254 | pageErrors++; 255 | totalErrors += byteErrors; 256 | } 257 | 258 | pageNum++; 259 | if (pageNum == numPages) 260 | break; 261 | if (fbytes != pageSize) 262 | throw FileIoError(); 263 | } 264 | if (fbytes <= 0) 265 | throw FileIoError(); 266 | 267 | fclose(infile); 268 | } 269 | catch(exception& e) 270 | { 271 | if (infile) 272 | fclose(infile); 273 | Error(wxString(e.what(), wxConvUTF8)); 274 | return 0; 275 | } 276 | 277 | if (byteErrors != 0) 278 | { 279 | Warning(wxString::Format(_( 280 | "Verify failed\n" 281 | "Page errors: %d\n" 282 | "Byte errors: %d\n"), 283 | pageErrors, totalErrors)); 284 | return 0; 285 | } 286 | 287 | Success(_("Verify successful\n")); 288 | 289 | return 0; 290 | } 291 | 292 | ReadThread::ReadThread(wxEvtHandler* parent, const wxString& filename, size_t size) : 293 | BossaThread(parent), _filename(filename), _size(size) 294 | { 295 | } 296 | 297 | wxThread::ExitCode 298 | ReadThread::Entry() 299 | { 300 | FILE* outfile = NULL; 301 | Flash& flash = *wxGetApp().flash; 302 | uint32_t pageSize = flash.pageSize(); 303 | uint8_t buffer[pageSize]; 304 | uint32_t pageNum = 0; 305 | uint32_t numPages; 306 | 307 | if (_size == 0) 308 | _size = pageSize * flash.numPages(); 309 | 310 | outfile = fopen(_filename.mb_str(), "wb"); 311 | if (!outfile) 312 | throw FileOpenError(); 313 | 314 | try 315 | { 316 | numPages = (_size + pageSize - 1) / pageSize; 317 | if (numPages > flash.numPages()) 318 | throw FileSizeError(); 319 | 320 | for (pageNum = 0; pageNum < numPages; pageNum++) 321 | { 322 | if (_stopped) 323 | { 324 | fclose(outfile); 325 | Warning(wxT("Read stopped")); 326 | return 0; 327 | } 328 | 329 | if (pageNum % 10 == 0 || pageNum == numPages - 1) 330 | { 331 | uint32_t percent = (pageNum + 1) * 100 / numPages; 332 | Progress(wxString::Format(wxT("Reading page %d (%d%%)"), pageNum, percent), 333 | percent); 334 | } 335 | 336 | flash.readPage(pageNum, buffer); 337 | 338 | if (pageNum == numPages - 1 && _size % pageSize > 0) 339 | pageSize = _size % pageSize; 340 | if (fwrite(buffer, 1, pageSize, outfile) != pageSize) 341 | throw FileIoError(); 342 | } 343 | fclose(outfile); 344 | } 345 | catch(exception& e) 346 | { 347 | if (outfile) 348 | fclose(outfile); 349 | Error(wxString(e.what(), wxConvUTF8)); 350 | return 0; 351 | } 352 | 353 | Success(_("Read completed successfully")); 354 | return 0; 355 | } 356 | 357 | -------------------------------------------------------------------------------- /src/BossaThread.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _BOSSATHREAD_H 20 | #define _BOSSATHREAD_H 21 | 22 | #include 23 | 24 | DECLARE_EVENT_TYPE(wxEVT_THREAD_PROGRESS, wxID_ANY) 25 | DECLARE_EVENT_TYPE(wxEVT_THREAD_SUCCESS, wxID_ANY) 26 | DECLARE_EVENT_TYPE(wxEVT_THREAD_WARNING, wxID_ANY) 27 | DECLARE_EVENT_TYPE(wxEVT_THREAD_ERROR, wxID_ANY) 28 | 29 | class BossaThread : public wxThread 30 | { 31 | public: 32 | BossaThread(wxEvtHandler* parent); 33 | 34 | void stop() { _stopped = true; } 35 | 36 | protected: 37 | wxEvtHandler* _parent; 38 | 39 | bool _stopped; 40 | 41 | void Progress(const wxString& message, int pos); 42 | void Success(const wxString& message); 43 | void Warning(const wxString& message); 44 | void Error(const wxString& message); 45 | }; 46 | 47 | class WriteThread : public BossaThread 48 | { 49 | public: 50 | WriteThread(wxEvtHandler* parent, 51 | const wxString& filename, 52 | bool eraseAll, 53 | bool bootFlash, 54 | bool bod, 55 | bool bor, 56 | bool lock, 57 | bool security); 58 | wxThread::ExitCode Entry(); 59 | 60 | private: 61 | wxString _filename; 62 | bool _eraseAll; 63 | bool _bootFlash; 64 | bool _bod; 65 | bool _bor; 66 | bool _lock; 67 | bool _security; 68 | }; 69 | 70 | class VerifyThread : public BossaThread 71 | { 72 | public: 73 | VerifyThread(wxEvtHandler* parent, 74 | const wxString& filename); 75 | wxThread::ExitCode Entry(); 76 | 77 | private: 78 | wxString _filename; 79 | }; 80 | 81 | class ReadThread : public BossaThread 82 | { 83 | public: 84 | ReadThread(wxEvtHandler* parent, 85 | const wxString& filename, 86 | size_t size); 87 | wxThread::ExitCode Entry(); 88 | 89 | private: 90 | wxString _filename; 91 | size_t _size; 92 | }; 93 | 94 | #endif // _BOSSAINFO_H 95 | -------------------------------------------------------------------------------- /src/BossaWindow.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _BOSSAWINDOW_H 20 | #define _BOSSAWINDOW_H 21 | 22 | #include 23 | 24 | #include "BossaForm.h" 25 | #include "BossaThread.h" 26 | #include "BossaProgress.h" 27 | 28 | class BossaWindow : public MainFrame 29 | { 30 | public: 31 | BossaWindow(); 32 | virtual ~BossaWindow(); 33 | 34 | private: 35 | BossaThread* _thread; 36 | BossaProgress* _progress; 37 | 38 | void RefreshSerial(); 39 | void CreateFlash(); 40 | void Connected(); 41 | void Disconnected(); 42 | 43 | void Error(const wxString& message); 44 | void Warning(const wxString& message); 45 | void Info(const wxString& message); 46 | bool Question(const wxString& message); 47 | 48 | void OnAbout(wxCommandEvent& event); 49 | void OnRefresh(wxCommandEvent& event); 50 | void OnSerial(wxCommandEvent& event); 51 | void OnAutoScan(wxCommandEvent& event); 52 | 53 | void OnWrite(wxCommandEvent& event); 54 | void OnVerify(wxCommandEvent& event); 55 | void OnRead(wxCommandEvent& event); 56 | void OnInfo(wxCommandEvent& event); 57 | void OnExit(wxCommandEvent& event); 58 | 59 | void OnThreadProgress(wxCommandEvent& event); 60 | void OnThreadSuccess(wxCommandEvent& event); 61 | void OnThreadWarning(wxCommandEvent& event); 62 | void OnThreadError(wxCommandEvent& event); 63 | 64 | void OnProgressCancel(wxCommandEvent& event); 65 | }; 66 | 67 | #endif // _BOSSAWINDOW_H 68 | -------------------------------------------------------------------------------- /src/CmdOpts.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "CmdOpts.h" 25 | 26 | CmdOpts::CmdOpts(int argc, char* argv[], int numOpts, Option* opts) : 27 | _argc(argc), _argv(argv), _numOpts(numOpts), _opts(opts) 28 | { 29 | } 30 | 31 | CmdOpts::~CmdOpts() 32 | { 33 | } 34 | 35 | void 36 | CmdOpts::usage(FILE* out) 37 | { 38 | int optIdx; 39 | char name[40]; 40 | const char* start; 41 | const char* end; 42 | 43 | for (optIdx = 0; optIdx < _numOpts; optIdx++) 44 | { 45 | if (_opts[optIdx].arg.has == ArgOptional) 46 | snprintf(name, sizeof(name), " -%c, --%s[=%s]", 47 | _opts[optIdx].letter, 48 | _opts[optIdx].name, 49 | _opts[optIdx].arg.name); 50 | else if (_opts[optIdx].arg.has == ArgRequired) 51 | snprintf(name, sizeof(name), " -%c, --%s=%s", 52 | _opts[optIdx].letter, 53 | _opts[optIdx].name, 54 | _opts[optIdx].arg.name); 55 | else 56 | snprintf(name, sizeof(name), " -%c, --%s", 57 | _opts[optIdx].letter, 58 | _opts[optIdx].name); 59 | 60 | fprintf(out, "%-23s ", name); 61 | 62 | start = _opts[optIdx].help; 63 | while ((end = strchr(start, '\n'))) 64 | { 65 | fwrite(start, end - start + 1, 1, out); 66 | fprintf(out, "%24s", ""); 67 | start = end + 1; 68 | } 69 | fprintf(out, "%s\n", start); 70 | } 71 | } 72 | 73 | int 74 | CmdOpts::parse() 75 | { 76 | struct option long_opts[_numOpts + 1]; 77 | char optstring[_numOpts * 3 + 1]; 78 | char* optPtr = optstring; 79 | int optIdx; 80 | int rc; 81 | 82 | for (optIdx = 0; optIdx < _numOpts; optIdx++) 83 | { 84 | *_opts[optIdx].present = false; 85 | 86 | *optPtr++ = _opts[optIdx].letter; 87 | long_opts[optIdx].name = _opts[optIdx].name; 88 | switch (_opts[optIdx].arg.has) 89 | { 90 | default: 91 | case ArgNone: 92 | long_opts[optIdx].has_arg = no_argument; 93 | break; 94 | case ArgOptional: 95 | long_opts[optIdx].has_arg = optional_argument; 96 | *optPtr++ = ':'; 97 | *optPtr++ = ':'; 98 | break; 99 | case ArgRequired: 100 | long_opts[optIdx].has_arg = required_argument; 101 | *optPtr++ = ':'; 102 | break; 103 | } 104 | long_opts[optIdx].flag = NULL; 105 | long_opts[optIdx].val = 0; 106 | } 107 | 108 | memset(&long_opts[_numOpts], 0, sizeof(long_opts[_numOpts])); 109 | *optPtr = '\0'; 110 | optIdx = 0; 111 | while ((rc = getopt_long(_argc, _argv, optstring, long_opts, &optIdx)) != -1) 112 | { 113 | if (rc == '?') 114 | return -1; 115 | 116 | if (rc != 0) 117 | optIdx = find(rc); 118 | 119 | assert(optIdx >= 0 && optIdx < _numOpts); 120 | *_opts[optIdx].present = true; 121 | if (_opts[optIdx].arg.has != ArgNone && optarg) 122 | { 123 | switch (_opts[optIdx].arg.type) 124 | { 125 | case ArgInt: 126 | *_opts[optIdx].arg.value.intPtr = strtol(optarg, NULL, 0); 127 | break; 128 | default: 129 | case ArgString: 130 | *_opts[optIdx].arg.value.strPtr = optarg; 131 | break; 132 | } 133 | } 134 | } 135 | 136 | return optind; 137 | } 138 | 139 | int 140 | CmdOpts::find(char letter) 141 | { 142 | int optIdx; 143 | 144 | for (optIdx = 0; optIdx < _numOpts; optIdx++) 145 | if (_opts[optIdx].letter == letter) 146 | break; 147 | 148 | return optIdx; 149 | } 150 | -------------------------------------------------------------------------------- /src/CmdOpts.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _OPTION_H 20 | #define _OPTION_H 21 | 22 | #include 23 | #include 24 | 25 | typedef enum 26 | { 27 | ArgNone, 28 | ArgOptional, 29 | ArgRequired 30 | } ArgHas; 31 | 32 | typedef enum 33 | { 34 | ArgInt, 35 | ArgString 36 | } ArgType; 37 | 38 | typedef struct 39 | { 40 | ArgHas has; 41 | ArgType type; 42 | const char* name; 43 | union 44 | { 45 | void* voidPtr; 46 | int* intPtr; 47 | std::string* strPtr; 48 | } value; 49 | } OptArg; 50 | 51 | typedef struct 52 | { 53 | char letter; 54 | const char* name; 55 | bool* present; 56 | OptArg arg; 57 | const char* help; 58 | } Option; 59 | 60 | class CmdOpts 61 | { 62 | public: 63 | CmdOpts(int argc, char* argv[], int numOpts, Option* opts); 64 | virtual ~CmdOpts(); 65 | 66 | void usage(FILE* out); 67 | int parse(); 68 | 69 | private: 70 | int _argc; 71 | char** _argv; 72 | int _numOpts; 73 | Option* _opts; 74 | 75 | int find(char letter); 76 | }; 77 | 78 | #endif // _OPTION_H 79 | -------------------------------------------------------------------------------- /src/Command.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _COMMAND_H 20 | #define _COMMAND_H 21 | 22 | #include 23 | 24 | #include "Shell.h" 25 | #include "Samba.h" 26 | #include "PortFactory.h" 27 | #include "FlashFactory.h" 28 | #include "Flasher.h" 29 | 30 | class Command 31 | { 32 | public: 33 | Command(const char* name, const char* help, const char* usage); 34 | virtual ~Command() {} 35 | 36 | virtual void invoke(char* argv[], int argc) = 0; 37 | const char* name() { return _name; }; 38 | const char* help() { return _help; }; 39 | const char* usage() { return _usage; }; 40 | 41 | static void setShell(Shell* shell) { _shell = shell; } 42 | static void disconnect(); 43 | 44 | bool operator < (const Command& rhs); 45 | 46 | protected: 47 | static Shell* _shell; 48 | static Samba _samba; 49 | static PortFactory _portFactory; 50 | static FlashFactory _flashFactory; 51 | static Flash::Ptr _flash; 52 | static Flasher _flasher; 53 | static bool _connected; 54 | 55 | bool error(const char* fmt, ...); 56 | bool argNum(int argc, int num); 57 | bool argRange(int argc, int min, int max); 58 | bool argUint32(const char* arg, uint32_t* value); 59 | bool argBool(const char* arg, bool* value); 60 | bool argState(const char* arg, bool* value); 61 | 62 | bool createFlash(); 63 | bool connected(); 64 | bool flashable(); 65 | 66 | void hexdump(uint32_t addr, uint8_t *buf, size_t count); 67 | const char* binstr(uint32_t value, int bits, char low = '0', char high = '1'); 68 | 69 | private: 70 | const char* _name; 71 | const char* _help; 72 | const char* _usage; 73 | }; 74 | 75 | class CommandBod : public Command 76 | { 77 | public: 78 | CommandBod(); 79 | virtual void invoke(char* argv[], int argc); 80 | }; 81 | 82 | class CommandBootf : public Command 83 | { 84 | public: 85 | CommandBootf(); 86 | virtual void invoke(char* argv[], int argc); 87 | }; 88 | 89 | class CommandBor : public Command 90 | { 91 | public: 92 | CommandBor(); 93 | virtual void invoke(char* argv[], int argc); 94 | }; 95 | 96 | class CommandConnect : public Command 97 | { 98 | public: 99 | CommandConnect(); 100 | virtual void invoke(char* argv[], int argc); 101 | }; 102 | 103 | class CommandDebug : public Command 104 | { 105 | public: 106 | CommandDebug(); 107 | virtual void invoke(char* argv[], int argc); 108 | }; 109 | 110 | class CommandDisass : public Command 111 | { 112 | public: 113 | CommandDisass(); 114 | virtual void invoke(char* argv[], int argc); 115 | }; 116 | 117 | class CommandDump : public Command 118 | { 119 | public: 120 | CommandDump(); 121 | virtual void invoke(char* argv[], int argc); 122 | }; 123 | class CommandErase : public Command 124 | { 125 | public: 126 | CommandErase(); 127 | virtual void invoke(char* argv[], int argc); 128 | }; 129 | 130 | class CommandExit : public Command 131 | { 132 | public: 133 | CommandExit(); 134 | virtual void invoke(char* argv[], int argc); 135 | }; 136 | 137 | class CommandGo : public Command 138 | { 139 | public: 140 | CommandGo(); 141 | virtual void invoke(char* argv[], int argc); 142 | }; 143 | 144 | class CommandHelp : public Command 145 | { 146 | public: 147 | CommandHelp(); 148 | virtual void invoke(char* argv[], int argc); 149 | }; 150 | 151 | class CommandHistory : public Command 152 | { 153 | public: 154 | CommandHistory(); 155 | virtual void invoke(char* argv[], int argc); 156 | }; 157 | 158 | class CommandInfo : public Command 159 | { 160 | public: 161 | CommandInfo(); 162 | virtual void invoke(char* argv[], int argc); 163 | }; 164 | 165 | class CommandLock : public Command 166 | { 167 | public: 168 | CommandLock(); 169 | virtual void invoke(char* argv[], int argc); 170 | }; 171 | 172 | class CommandMrb : public Command 173 | { 174 | public: 175 | CommandMrb(); 176 | virtual void invoke(char* argv[], int argc); 177 | }; 178 | 179 | class CommandMrf : public Command 180 | { 181 | public: 182 | CommandMrf(); 183 | virtual void invoke(char* argv[], int argc); 184 | }; 185 | 186 | class CommandMrw : public Command 187 | { 188 | public: 189 | CommandMrw(); 190 | virtual void invoke(char* argv[], int argc); 191 | }; 192 | 193 | class CommandMwb : public Command 194 | { 195 | public: 196 | CommandMwb(); 197 | virtual void invoke(char* argv[], int argc); 198 | }; 199 | 200 | class CommandMwf : public Command 201 | { 202 | public: 203 | CommandMwf(); 204 | virtual void invoke(char* argv[], int argc); 205 | }; 206 | 207 | class CommandMww : public Command 208 | { 209 | public: 210 | CommandMww(); 211 | virtual void invoke(char* argv[], int argc); 212 | }; 213 | 214 | class CommandPio : public Command 215 | { 216 | public: 217 | CommandPio(); 218 | virtual void invoke(char* argv[], int argc); 219 | }; 220 | 221 | class CommandRead : public Command 222 | { 223 | public: 224 | CommandRead(); 225 | virtual void invoke(char* argv[], int argc); 226 | }; 227 | 228 | class CommandScan : public Command 229 | { 230 | public: 231 | CommandScan(); 232 | virtual void invoke(char* argv[], int argc); 233 | }; 234 | 235 | class CommandSecurity : public Command 236 | { 237 | public: 238 | CommandSecurity(); 239 | virtual void invoke(char* argv[], int argc); 240 | }; 241 | 242 | class CommandUnlock : public Command 243 | { 244 | public: 245 | CommandUnlock(); 246 | virtual void invoke(char* argv[], int argc); 247 | }; 248 | 249 | class CommandVerify : public Command 250 | { 251 | public: 252 | CommandVerify(); 253 | virtual void invoke(char* argv[], int argc); 254 | }; 255 | 256 | class CommandWrite : public Command 257 | { 258 | public: 259 | CommandWrite(); 260 | virtual void invoke(char* argv[], int argc); 261 | }; 262 | 263 | class CommandReset : public Command 264 | { 265 | public: 266 | CommandReset(); 267 | virtual void invoke(char* argv[], int argc); 268 | }; 269 | 270 | #endif // _COMMAND_H 271 | -------------------------------------------------------------------------------- /src/Driver.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _DRIVER_H 20 | #define _DRIVER_H 21 | 22 | class DriverBase 23 | { 24 | public: 25 | DriverBase() {} 26 | virtual ~DriverBase() {} 27 | 28 | virtual bool isInstalled() = 0; 29 | virtual bool install() = 0; 30 | 31 | virtual bool isUpdated() = 0; 32 | virtual bool update() = 0; 33 | }; 34 | 35 | #ifdef __WIN32__ 36 | #include "WinDriver.h" 37 | typedef WinDriver Driver; 38 | #else 39 | #error "Platform is not supported" 40 | #endif 41 | 42 | #endif // _DRIVER_H 43 | -------------------------------------------------------------------------------- /src/EefcFlash.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "EefcFlash.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #define EEFC_KEY 0x5a 26 | 27 | #define EEFC0_FMR (_regs + 0x00) 28 | #define EEFC0_FCR (_regs + 0x04) 29 | #define EEFC0_FSR (_regs + 0x08) 30 | #define EEFC0_FRR (_regs + 0x0C) 31 | 32 | #define EEFC1_FMR (_regs + 0x200) 33 | #define EEFC1_FCR (_regs + 0x204) 34 | #define EEFC1_FSR (_regs + 0x208) 35 | #define EEFC1_FRR (_regs + 0x20C) 36 | 37 | #define EEFC_FCMD_GETD 0x0 38 | #define EEFC_FCMD_WP 0x1 39 | #define EEFC_FCMD_WPL 0x2 40 | #define EEFC_FCMD_EWP 0x3 41 | #define EEFC_FCMD_EWPL 0x4 42 | #define EEFC_FCMD_EA 0x5 43 | #define EEFC_FCMD_SLB 0x8 44 | #define EEFC_FCMD_CLB 0x9 45 | #define EEFC_FCMD_GLB 0xa 46 | #define EEFC_FCMD_SGPB 0xb 47 | #define EEFC_FCMD_CGPB 0xc 48 | #define EEFC_FCMD_GGPB 0xd 49 | 50 | EefcFlash::EefcFlash(Samba& samba, 51 | const std::string& name, 52 | uint32_t addr, 53 | uint32_t pages, 54 | uint32_t size, 55 | uint32_t planes, 56 | uint32_t lockRegions, 57 | uint32_t user, 58 | uint32_t stack, 59 | uint32_t regs, 60 | bool canBrownout) 61 | : Flash(samba, name, addr, pages, size, planes, lockRegions, user, stack), 62 | _regs(regs), _canBrownout(canBrownout), _eraseAuto(true) 63 | { 64 | assert(planes == 1 || planes == 2); 65 | assert(pages <= 2048); 66 | assert(lockRegions <= 32); 67 | 68 | // SAM3 Errata (FWS must be 6) 69 | _samba.writeWord(EEFC0_FMR, 0x6 << 8); 70 | if (planes == 2) 71 | _samba.writeWord(EEFC1_FMR, 0x6 << 8); 72 | } 73 | 74 | EefcFlash::~EefcFlash() 75 | { 76 | } 77 | 78 | void 79 | EefcFlash::eraseAll() 80 | { 81 | waitFSR(); 82 | writeFCR0(EEFC_FCMD_EA, 0); 83 | if (_planes == 2) 84 | { 85 | waitFSR(); 86 | writeFCR1(EEFC_FCMD_EA, 0); 87 | } 88 | } 89 | 90 | void 91 | EefcFlash::eraseAuto(bool enable) 92 | { 93 | _eraseAuto = enable; 94 | } 95 | 96 | bool 97 | EefcFlash::isLocked() 98 | { 99 | waitFSR(); 100 | writeFCR0(EEFC_FCMD_GLB, 0); 101 | waitFSR(); 102 | if (readFRR0()) 103 | return true; 104 | if (_planes == 2) 105 | { 106 | writeFCR1(EEFC_FCMD_GLB, 0); 107 | waitFSR(); 108 | if (readFRR1()) 109 | return true; 110 | } 111 | 112 | return false; 113 | } 114 | 115 | bool 116 | EefcFlash::getLockRegion(uint32_t region) 117 | { 118 | if (region >= _lockRegions) 119 | throw FlashRegionError(); 120 | 121 | waitFSR(); 122 | if (_planes == 2 && region >= _lockRegions / 2) 123 | { 124 | writeFCR1(EEFC_FCMD_GLB, 0); 125 | waitFSR(); 126 | if (readFRR1() & (1 << (region - _lockRegions / 2))) 127 | return true; 128 | } 129 | else 130 | { 131 | writeFCR0(EEFC_FCMD_GLB, 0); 132 | waitFSR(); 133 | if (readFRR0() & (1 << region)) 134 | return true; 135 | } 136 | 137 | return false; 138 | } 139 | 140 | void 141 | EefcFlash::setLockRegion(uint32_t region, bool enable) 142 | { 143 | uint32_t page; 144 | 145 | if (region >= _lockRegions) 146 | throw FlashRegionError(); 147 | 148 | if (enable != getLockRegion(region)) 149 | { 150 | if (_planes == 2 && region >= _lockRegions / 2) 151 | { 152 | page = (region - _lockRegions / 2) * _pages / _lockRegions; 153 | waitFSR(); 154 | writeFCR1(enable ? EEFC_FCMD_SLB : EEFC_FCMD_CLB, page); 155 | } 156 | else 157 | { 158 | page = region * _pages / _lockRegions; 159 | waitFSR(); 160 | writeFCR0(enable ? EEFC_FCMD_SLB : EEFC_FCMD_CLB, page); 161 | } 162 | } 163 | } 164 | 165 | bool 166 | EefcFlash::getSecurity() 167 | { 168 | waitFSR(); 169 | writeFCR0(EEFC_FCMD_GGPB, 0); 170 | waitFSR(); 171 | return (readFRR0() & (1 << 0)); 172 | } 173 | 174 | void 175 | EefcFlash::setSecurity() 176 | { 177 | waitFSR(); 178 | writeFCR0(EEFC_FCMD_SGPB, 0); 179 | } 180 | 181 | bool 182 | EefcFlash::getBod() 183 | { 184 | if (!_canBrownout) 185 | return false; 186 | 187 | waitFSR(); 188 | writeFCR0(EEFC_FCMD_GGPB, 0); 189 | waitFSR(); 190 | return (readFRR0() & (1 << 1)); 191 | } 192 | 193 | void 194 | EefcFlash::setBod(bool enable) 195 | { 196 | if (!_canBrownout) 197 | return; 198 | 199 | waitFSR(); 200 | writeFCR0(enable ? EEFC_FCMD_SGPB : EEFC_FCMD_CGPB, 1); 201 | } 202 | 203 | bool 204 | EefcFlash::getBor() 205 | { 206 | if (!_canBrownout) 207 | return false; 208 | 209 | waitFSR(); 210 | writeFCR0(EEFC_FCMD_GGPB, 0); 211 | waitFSR(); 212 | return (readFRR0() & (1 << 2)); 213 | } 214 | 215 | void 216 | EefcFlash::setBor(bool enable) 217 | { 218 | if (!_canBrownout) 219 | return; 220 | 221 | waitFSR(); 222 | writeFCR0(enable ? EEFC_FCMD_SGPB : EEFC_FCMD_CGPB, 2); 223 | } 224 | 225 | bool 226 | EefcFlash::getBootFlash() 227 | { 228 | waitFSR(); 229 | writeFCR0(EEFC_FCMD_GGPB, 0); 230 | waitFSR(); 231 | return (readFRR0() & (1 << (_canBrownout ? 3 : 1))); 232 | } 233 | 234 | void 235 | EefcFlash::setBootFlash(bool enable) 236 | { 237 | waitFSR(); 238 | writeFCR0(enable ? EEFC_FCMD_SGPB : EEFC_FCMD_CGPB, (_canBrownout ? 3 : 1)); 239 | waitFSR(); 240 | usleep(10000); 241 | } 242 | 243 | void 244 | EefcFlash::writePage(uint32_t page) 245 | { 246 | if (page >= _pages) 247 | throw FlashPageError(); 248 | 249 | _wordCopy.setDstAddr(_addr + page * _size); 250 | _wordCopy.setSrcAddr(_onBufferA ? _pageBufferA : _pageBufferB); 251 | _onBufferA = !_onBufferA; 252 | waitFSR(); 253 | _wordCopy.runv(); 254 | if (_planes == 2 && page >= _pages / 2) 255 | writeFCR1(_eraseAuto ? EEFC_FCMD_EWP : EEFC_FCMD_WP, page - _pages / 2); 256 | else 257 | writeFCR0(_eraseAuto ? EEFC_FCMD_EWP : EEFC_FCMD_WP, page); 258 | } 259 | 260 | void 261 | EefcFlash::readPage(uint32_t page, uint8_t* data) 262 | { 263 | if (page >= _pages) 264 | throw FlashPageError(); 265 | 266 | // The SAM3 firmware has a bug where it returns all zeros for reads 267 | // directly from the flash so instead, we copy the flash page to 268 | // SRAM and read it from there. 269 | _wordCopy.setDstAddr(_onBufferA ? _pageBufferA : _pageBufferB); 270 | _wordCopy.setSrcAddr(_addr + page * _size); 271 | waitFSR(); 272 | _wordCopy.runv(); 273 | _samba.read(_onBufferA ? _pageBufferA : _pageBufferB, data, _size); 274 | } 275 | 276 | void 277 | EefcFlash::waitFSR() 278 | { 279 | uint32_t tries = 0; 280 | uint32_t fsr0; 281 | uint32_t fsr1 = 0x1; 282 | 283 | while (++tries <= 500) 284 | { 285 | fsr0 = _samba.readWord(EEFC0_FSR); 286 | if (fsr0 & (1 << 2)) 287 | throw FlashLockError(); 288 | 289 | if (_planes == 2) 290 | { 291 | fsr1 = _samba.readWord(EEFC1_FSR); 292 | if (fsr1 & (1 << 2)) 293 | throw FlashLockError(); 294 | } 295 | if (fsr0 & fsr1 & 0x1) 296 | break; 297 | usleep(100); 298 | } 299 | if (tries > 500) 300 | throw FlashCmdError(); 301 | } 302 | 303 | void 304 | EefcFlash::writeFCR0(uint8_t cmd, uint32_t arg) 305 | { 306 | _samba.writeWord(EEFC0_FCR, (EEFC_KEY << 24) | (arg << 8) | cmd); 307 | } 308 | 309 | void 310 | EefcFlash::writeFCR1(uint8_t cmd, uint32_t arg) 311 | { 312 | _samba.writeWord(EEFC1_FCR, (EEFC_KEY << 24) | (arg << 8) | cmd); 313 | } 314 | 315 | uint32_t 316 | EefcFlash::readFRR0() 317 | { 318 | return _samba.readWord(EEFC0_FRR); 319 | } 320 | 321 | uint32_t 322 | EefcFlash::readFRR1() 323 | { 324 | return _samba.readWord(EEFC1_FRR); 325 | } 326 | -------------------------------------------------------------------------------- /src/EefcFlash.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _EEFCFLASH_H 20 | #define _EEFCFLASH_H 21 | 22 | #include 23 | #include 24 | 25 | #include "Flash.h" 26 | 27 | class EefcFlash : public Flash 28 | { 29 | public: 30 | EefcFlash(Samba& samba, 31 | const std::string& name, 32 | uint32_t addr, 33 | uint32_t pages, 34 | uint32_t size, 35 | uint32_t planes, 36 | uint32_t lockRegions, 37 | uint32_t user, 38 | uint32_t stack, 39 | uint32_t regs, 40 | bool canBrownout); 41 | virtual ~EefcFlash(); 42 | 43 | void eraseAll(); 44 | void eraseAuto(bool enable); 45 | 46 | bool isLocked(); 47 | bool getLockRegion(uint32_t region); 48 | void setLockRegion(uint32_t region, bool enable); 49 | 50 | bool getSecurity(); 51 | void setSecurity(); 52 | 53 | bool getBod(); 54 | void setBod(bool enable); 55 | bool canBod() { return _canBrownout; } 56 | 57 | bool getBor(); 58 | void setBor(bool enable); 59 | bool canBor() { return _canBrownout; } 60 | 61 | bool getBootFlash(); 62 | void setBootFlash(bool enable); 63 | bool canBootFlash() { return true; } 64 | 65 | void writePage(uint32_t page); 66 | void readPage(uint32_t page, uint8_t* data); 67 | 68 | private: 69 | uint32_t _regs; 70 | bool _canBrownout; 71 | bool _eraseAuto; 72 | 73 | void waitFSR(); 74 | void writeFCR0(uint8_t cmd, uint32_t arg); 75 | void writeFCR1(uint8_t cmd, uint32_t arg); 76 | uint32_t readFRR0(); 77 | uint32_t readFRR1(); 78 | }; 79 | 80 | #endif // _EEFCFLASH_H 81 | -------------------------------------------------------------------------------- /src/EfcFlash.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "EfcFlash.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #define EFC_KEY 0x5a 26 | 27 | #define EFC0_FMR 0xffffff60 28 | #define EFC0_FCR 0xffffff64 29 | #define EFC0_FSR 0xffffff68 30 | 31 | #define EFC1_FMR 0xffffff70 32 | #define EFC1_FCR 0xffffff74 33 | #define EFC1_FSR 0xffffff78 34 | 35 | #define EFC_FCMD_WP 0x1 36 | #define EFC_FCMD_SLB 0x2 37 | #define EFC_FCMD_WPL 0x3 38 | #define EFC_FCMD_CLB 0x4 39 | #define EFC_FCMD_EA 0x8 40 | #define EFC_FCMD_SGPB 0xb 41 | #define EFC_FCMD_CGPB 0xd 42 | #define EFC_FCMD_SSB 0xf 43 | 44 | EfcFlash::EfcFlash(Samba& samba, 45 | const std::string& name, 46 | uint32_t addr, 47 | uint32_t pages, 48 | uint32_t size, 49 | uint32_t planes, 50 | uint32_t lockRegions, 51 | uint32_t user, 52 | uint32_t stack, 53 | bool canBootFlash) 54 | : Flash(samba, name, addr, pages, size, planes, lockRegions, user, stack), 55 | _canBootFlash(canBootFlash) 56 | { 57 | assert(planes == 1 || planes == 2); 58 | assert(pages <= planes * 1024); 59 | assert(lockRegions <= 32); 60 | 61 | eraseAuto(true); 62 | } 63 | 64 | EfcFlash::~EfcFlash() 65 | { 66 | } 67 | 68 | void 69 | EfcFlash::eraseAll() 70 | { 71 | waitFSR(); 72 | writeFCR0(EFC_FCMD_EA, 0); 73 | if (_planes == 2) 74 | { 75 | waitFSR(); 76 | writeFCR0(EFC_FCMD_EA, _pages / 2); 77 | } 78 | } 79 | 80 | void 81 | EfcFlash::eraseAuto(bool enable) 82 | { 83 | uint32_t fmr; 84 | 85 | waitFSR(); 86 | fmr = _samba.readWord(EFC0_FMR); 87 | if (enable) 88 | fmr &= ~(1 << 7); 89 | else 90 | fmr |= (1 << 7); 91 | 92 | _samba.writeWord(EFC0_FMR, fmr); 93 | if (_planes == 2) 94 | { 95 | waitFSR(); 96 | _samba.writeWord(EFC1_FMR, fmr); 97 | } 98 | } 99 | 100 | bool 101 | EfcFlash::isLocked() 102 | { 103 | if ((readFSR0() & (0xffff << 16)) != 0) 104 | return true; 105 | 106 | if (_planes == 2) 107 | if ((readFSR1() & (0xffff << 16)) != 0) 108 | return true; 109 | 110 | return false; 111 | } 112 | 113 | bool 114 | EfcFlash::getLockRegion(uint32_t region) 115 | { 116 | if (region >= _lockRegions) 117 | throw FlashRegionError(); 118 | 119 | if (_planes == 2 && region >= _lockRegions / 2) 120 | return (readFSR1() & (1 << (16 + region - _lockRegions / 2))); 121 | else 122 | return (readFSR0() & (1 << (16 + region))); 123 | } 124 | 125 | void 126 | EfcFlash::setLockRegion(uint32_t region, bool enable) 127 | { 128 | uint32_t page; 129 | 130 | if (region >= _lockRegions) 131 | throw FlashRegionError(); 132 | 133 | if (enable != getLockRegion(region)) 134 | { 135 | if (_planes == 2 && region >= _lockRegions / 2) 136 | { 137 | page = (region - _lockRegions / 2) * _pages / _lockRegions; 138 | waitFSR(); 139 | writeFCR1(enable ? EFC_FCMD_SLB : EFC_FCMD_CLB, page); 140 | } 141 | else 142 | { 143 | page = region * _pages / _lockRegions; 144 | waitFSR(); 145 | writeFCR0(enable ? EFC_FCMD_SLB : EFC_FCMD_CLB, page); 146 | } 147 | } 148 | } 149 | 150 | bool 151 | EfcFlash::getSecurity() 152 | { 153 | return (readFSR0() & (1 << 4)); 154 | } 155 | 156 | void 157 | EfcFlash::setSecurity() 158 | { 159 | waitFSR(); 160 | writeFCR0(EFC_FCMD_SSB, 0); 161 | } 162 | 163 | bool 164 | EfcFlash::getBod() 165 | { 166 | return (readFSR0() & (1 << 8)); 167 | } 168 | 169 | void 170 | EfcFlash::setBod(bool enable) 171 | { 172 | waitFSR(); 173 | writeFCR0(enable ? EFC_FCMD_SGPB : EFC_FCMD_CGPB, 0); 174 | } 175 | 176 | bool 177 | EfcFlash::getBor() 178 | { 179 | return (readFSR0() & (2 << 8)); 180 | } 181 | 182 | void 183 | EfcFlash::setBor(bool enable) 184 | { 185 | waitFSR(); 186 | writeFCR0(enable ? EFC_FCMD_SGPB : EFC_FCMD_CGPB, 1); 187 | } 188 | 189 | bool 190 | EfcFlash::getBootFlash() 191 | { 192 | if (!_canBootFlash) 193 | return false; 194 | 195 | return (readFSR0() & (1 << 10)); 196 | } 197 | 198 | void 199 | EfcFlash::setBootFlash(bool enable) 200 | { 201 | if (!_canBootFlash) 202 | return; 203 | 204 | waitFSR(); 205 | writeFCR0(enable ? EFC_FCMD_SGPB : EFC_FCMD_CGPB, 2); 206 | } 207 | 208 | void 209 | EfcFlash::writePage(uint32_t page) 210 | { 211 | if (page >= _pages) 212 | throw FlashPageError(); 213 | 214 | _wordCopy.setDstAddr(_addr + page * _size); 215 | _wordCopy.setSrcAddr(_onBufferA ? _pageBufferA : _pageBufferB); 216 | _onBufferA = !_onBufferA; 217 | waitFSR(); 218 | _wordCopy.run(); 219 | if (_planes == 2 && page >= _pages / 2) 220 | writeFCR1(EFC_FCMD_WP, page - _pages / 2); 221 | else 222 | writeFCR0(EFC_FCMD_WP, page); 223 | } 224 | 225 | void 226 | EfcFlash::readPage(uint32_t page, uint8_t* data) 227 | { 228 | if (page >= _pages) 229 | throw FlashPageError(); 230 | 231 | waitFSR(); 232 | _samba.read(_addr + page * _size, data, _size); 233 | } 234 | 235 | void 236 | EfcFlash::waitFSR() 237 | { 238 | uint32_t tries = 0; 239 | uint32_t fsr0; 240 | uint32_t fsr1 = 0x1; 241 | 242 | while (++tries <= 500) 243 | { 244 | fsr0 = readFSR0(); 245 | if (fsr0 & (1 << 2)) 246 | throw FlashLockError(); 247 | 248 | if (_planes == 2) 249 | { 250 | fsr1 = readFSR1(); 251 | if (fsr1 & (1 << 2)) 252 | throw FlashLockError(); 253 | } 254 | if (fsr0 & fsr1 & 0x1) 255 | break; 256 | usleep(100); 257 | } 258 | if (tries > 500) 259 | throw FlashCmdError(); 260 | } 261 | 262 | void 263 | EfcFlash::writeFCR0(uint8_t cmd, uint32_t arg) 264 | { 265 | _samba.writeWord(EFC0_FCR, (EFC_KEY << 24) | (arg << 8) | cmd); 266 | } 267 | 268 | void 269 | EfcFlash::writeFCR1(uint8_t cmd, uint32_t arg) 270 | { 271 | _samba.writeWord(EFC1_FCR, (EFC_KEY << 24) | (arg << 8) | cmd); 272 | } 273 | 274 | uint32_t 275 | EfcFlash::readFSR0() 276 | { 277 | return _samba.readWord(EFC0_FSR); 278 | } 279 | 280 | uint32_t 281 | EfcFlash::readFSR1() 282 | { 283 | return _samba.readWord(EFC1_FSR); 284 | } 285 | -------------------------------------------------------------------------------- /src/EfcFlash.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _EFCFLASH_H 20 | #define _EFCFLASH_H 21 | 22 | #include 23 | #include 24 | 25 | #include "Flash.h" 26 | 27 | class EfcFlash : public Flash 28 | { 29 | public: 30 | EfcFlash(Samba& samba, 31 | const std::string& name, 32 | uint32_t addr, 33 | uint32_t pages, 34 | uint32_t size, 35 | uint32_t planes, 36 | uint32_t lockRegions, 37 | uint32_t user, 38 | uint32_t stack, 39 | bool canBootFlash); 40 | virtual ~EfcFlash(); 41 | 42 | void eraseAll(); 43 | void eraseAuto(bool enable); 44 | 45 | bool isLocked(); 46 | bool getLockRegion(uint32_t region); 47 | void setLockRegion(uint32_t region, bool enable); 48 | 49 | bool getSecurity(); 50 | void setSecurity(); 51 | 52 | bool getBod(); 53 | void setBod(bool enable); 54 | bool canBod() { return true; } 55 | 56 | bool getBor(); 57 | void setBor(bool enable); 58 | bool canBor() { return true; } 59 | 60 | bool getBootFlash(); 61 | void setBootFlash(bool enable); 62 | bool canBootFlash() { return _canBootFlash; } 63 | 64 | void writePage(uint32_t page); 65 | void readPage(uint32_t page, uint8_t* data); 66 | 67 | private: 68 | bool _canBootFlash; 69 | 70 | void waitFSR(); 71 | void writeFCR0(uint8_t cmd, uint32_t arg); 72 | void writeFCR1(uint8_t cmd, uint32_t arg); 73 | uint32_t readFSR0(); 74 | uint32_t readFSR1(); 75 | }; 76 | 77 | #endif // _EFCFLASH_H 78 | -------------------------------------------------------------------------------- /src/FileError.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _FILEERROR_H 20 | #define _FILEERROR_H 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "Flash.h" 27 | #include "Samba.h" 28 | 29 | class FileError : public std::exception 30 | { 31 | public: 32 | FileError() : std::exception() {} 33 | }; 34 | 35 | class FileOpenError : public FileError 36 | { 37 | public: 38 | FileOpenError(int errnum) : FileError(), _errnum(errnum) {}; 39 | const char* what() const throw() { return strerror(_errnum); } 40 | private: 41 | int _errnum; 42 | }; 43 | 44 | class FileIoError : public FileError 45 | { 46 | public: 47 | FileIoError(int errnum) : FileError(), _errnum(errnum) {}; 48 | const char* what() const throw() { return strerror(_errnum); } 49 | private: 50 | int _errnum; 51 | }; 52 | 53 | class FileShortError : public FileError 54 | { 55 | public: 56 | FileShortError() : FileError() {}; 57 | const char* what() const throw() { return "short write"; } 58 | }; 59 | 60 | #endif // _FILEERROR_H 61 | -------------------------------------------------------------------------------- /src/Flash.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "Flash.h" 20 | 21 | #include 22 | 23 | Flash::Flash(Samba& samba, 24 | const std::string& name, 25 | uint32_t addr, 26 | uint32_t pages, 27 | uint32_t size, 28 | uint32_t planes, 29 | uint32_t lockRegions, 30 | uint32_t user, 31 | uint32_t stack) 32 | : _samba(samba), _name(name), _addr(addr), _pages(pages), _size(size), 33 | _planes(planes), _lockRegions(lockRegions), _user(user), _wordCopy(samba, user) 34 | { 35 | assert((size & (size - 1)) == 0); 36 | assert((pages & (pages - 1)) == 0); 37 | assert((lockRegions & (lockRegions - 1)) == 0); 38 | 39 | _wordCopy.setWords(size / sizeof(uint32_t)); 40 | _wordCopy.setStack(stack); 41 | 42 | _onBufferA = true; 43 | _pageBufferA = _user + _wordCopy.size(); 44 | _pageBufferB = _pageBufferA + size; 45 | } 46 | 47 | void 48 | Flash::lockAll() 49 | { 50 | for (uint32_t region = 0; region < _lockRegions; region++) 51 | setLockRegion(region, true); 52 | } 53 | 54 | void 55 | Flash::unlockAll() 56 | { 57 | for (uint32_t region = 0; region < _lockRegions; region++) 58 | setLockRegion(region, false); 59 | } 60 | 61 | void 62 | Flash::loadBuffer(const uint8_t* data) 63 | { 64 | _samba.write(_onBufferA ? _pageBufferA : _pageBufferB, data, _size); 65 | } 66 | -------------------------------------------------------------------------------- /src/Flash.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _FLASH_H 20 | #define _FLASH_H 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "Samba.h" 27 | #include "WordCopyApplet.h" 28 | 29 | class FlashPageError : public std::exception 30 | { 31 | public: 32 | FlashPageError() : exception() {}; 33 | const char* what() const throw() { return "Invalid flash page"; } 34 | }; 35 | 36 | class FlashRegionError : public std::exception 37 | { 38 | public: 39 | FlashRegionError() : exception() {}; 40 | const char* what() const throw() { return "Invalid lock region"; } 41 | }; 42 | 43 | class FlashLockError : public std::exception 44 | { 45 | public: 46 | FlashLockError() : exception() {}; 47 | const char* what() const throw() { return "Flash page is locked"; } 48 | }; 49 | 50 | class FlashCmdError : public std::exception 51 | { 52 | public: 53 | FlashCmdError() : exception() {}; 54 | const char* what() const throw() { return "Flash command failed"; } 55 | }; 56 | 57 | class Flash 58 | { 59 | public: 60 | Flash(Samba& samba, 61 | const std::string& name, 62 | uint32_t addr, 63 | uint32_t pages, 64 | uint32_t size, 65 | uint32_t planes, 66 | uint32_t lockRegions, 67 | uint32_t user, 68 | uint32_t stack); 69 | virtual ~Flash() {} 70 | 71 | const std::string& name() { return _name; } 72 | 73 | virtual uint32_t address() { return _addr; } 74 | virtual uint32_t pageSize() { return _size; } 75 | virtual uint32_t numPages() { return _pages; } 76 | virtual uint32_t numPlanes() { return _planes; } 77 | 78 | virtual void eraseAll() = 0; 79 | virtual void eraseAuto(bool enable) = 0; 80 | 81 | virtual uint32_t lockRegions() { return _lockRegions; } 82 | virtual bool isLocked() = 0; 83 | virtual bool getLockRegion(uint32_t region) = 0; 84 | virtual void setLockRegion(uint32_t region, bool enable) = 0; 85 | virtual void lockAll(); 86 | virtual void unlockAll(); 87 | 88 | virtual bool getSecurity() = 0; 89 | virtual void setSecurity() = 0; 90 | 91 | virtual bool getBod() = 0; 92 | virtual void setBod(bool enable) = 0; 93 | virtual bool canBod() = 0; 94 | 95 | virtual bool getBor() = 0; 96 | virtual void setBor(bool enable) = 0; 97 | virtual bool canBor() = 0; 98 | 99 | virtual bool getBootFlash() = 0; 100 | virtual void setBootFlash(bool enable) = 0; 101 | virtual bool canBootFlash() = 0; 102 | 103 | virtual void loadBuffer(const uint8_t* data); 104 | virtual void writePage(uint32_t page) = 0; 105 | virtual void readPage(uint32_t page, uint8_t* data) = 0; 106 | 107 | typedef std::auto_ptr Ptr; 108 | 109 | protected: 110 | Samba& _samba; 111 | std::string _name; 112 | uint32_t _addr; 113 | uint32_t _pages; 114 | uint32_t _size; 115 | uint32_t _planes; 116 | uint32_t _lockRegions; 117 | uint32_t _user; 118 | WordCopyApplet _wordCopy; 119 | 120 | bool _onBufferA; 121 | uint32_t _pageBufferA; 122 | uint32_t _pageBufferB; 123 | }; 124 | 125 | #endif // _FLASH_H 126 | -------------------------------------------------------------------------------- /src/FlashFactory.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "FlashFactory.h" 20 | 21 | #include "EfcFlash.h" 22 | #include "EefcFlash.h" 23 | #include 24 | 25 | FlashFactory::FlashFactory() 26 | { 27 | } 28 | 29 | FlashFactory::~FlashFactory() 30 | { 31 | } 32 | 33 | Flash::Ptr 34 | FlashFactory::create(Samba& samba, uint32_t chipId) 35 | { 36 | Flash* flash; 37 | 38 | switch (chipId & 0x7fffffe0) 39 | { 40 | // 41 | // SAM7SE 42 | // 43 | case 0x272a0a40: 44 | flash = new EfcFlash(samba, "AT91SAM7SE512", 0x100000, 2048, 256, 2, 32, 0x202000, 0x208000, true); 45 | break; 46 | case 0x272a0940: 47 | flash = new EfcFlash(samba, "AT91SAM7SE256", 0x100000, 1024, 256, 1, 16, 0x202000, 0x208000, true); 48 | break; 49 | case 0x272a0340: 50 | flash = new EfcFlash(samba, "AT91SAM7SE32", 0x100000, 256, 128, 1, 8, 0x201400, 0x201C00, true); 51 | break; 52 | // 53 | // SAM7S 54 | // 55 | case 0x270b0a40: 56 | flash = new EfcFlash(samba, "AT91SAM7S512", 0x100000, 2048, 256, 2, 32, 0x202000, 0x210000, false); 57 | break; 58 | case 0x270d0940: // A 59 | case 0x270b0940: // B/C 60 | flash = new EfcFlash(samba, "AT91SAM7S256", 0x100000, 1024, 256, 1, 16, 0x202000, 0x210000, false); 61 | break; 62 | case 0x270c0740: // A 63 | case 0x270a0740: // B/C 64 | flash = new EfcFlash(samba, "AT91SAM7S128", 0x100000, 512, 256, 1, 8, 0x202000, 0x208000, false); 65 | break; 66 | case 0x27090540: 67 | flash = new EfcFlash(samba, "AT91SAM7S64", 0x100000, 512, 128, 1, 16, 0x202000, 0x204000, false); 68 | break; 69 | case 0x27080340: 70 | flash = new EfcFlash(samba, "AT91SAM7S32", 0x100000, 256, 128, 1, 8, 0x201400, 0x202000, false); 71 | break; 72 | case 0x27050240: 73 | flash = new EfcFlash(samba, "AT91SAM7S16", 0x100000, 256, 64, 1, 8, 0x200000, 0x200e00, false); 74 | break; 75 | // 76 | // SAM7XC 77 | // 78 | case 0x271c0a40: 79 | flash = new EfcFlash(samba, "AT91SAMXC512", 0x100000, 2048, 256, 2, 32, 0x202000, 0x220000, true); 80 | break; 81 | case 0x271b0940: 82 | flash = new EfcFlash(samba, "AT91SAMXC256", 0x100000, 1024, 256, 1, 16, 0x202000, 0x210000, true); 83 | break; 84 | case 0x271a0740: 85 | flash = new EfcFlash(samba, "AT91SAMXC128", 0x100000, 512, 256, 1, 8, 0x202000, 0x208000, true); 86 | break; 87 | // 88 | // SAM7X 89 | // 90 | case 0x275c0a40: 91 | flash = new EfcFlash(samba, "AT91SAMX512", 0x100000, 2048, 256, 2, 32, 0x202000, 0x220000, true); 92 | break; 93 | case 0x275b0940: 94 | flash = new EfcFlash(samba, "AT91SAMX256", 0x100000, 1024, 256, 1, 16, 0x202000, 0x210000, true); 95 | break; 96 | case 0x275a0740: 97 | flash = new EfcFlash(samba, "AT91SAMX128", 0x100000, 512, 256, 1, 8, 0x202000, 0x208000, true); 98 | break; 99 | // 100 | // SAM4S 101 | // 102 | case 0x288c0ce0 : // A 103 | case 0x289c0ce0 : // B 104 | case 0x28ac0ce0 : // C 105 | flash = new EefcFlash(samba, "ATSAM4S16", 0x400000, 2048, 512, 1, 128, 0x20001000, 0x20020000, 0x400e0a00, false); 106 | break; 107 | case 0x288c0ae0 : // A 108 | case 0x289c0ae0 : // B 109 | case 0x28ac0ae0 : // C 110 | flash = new EefcFlash(samba, "ATSAM4S8", 0x400000, 1024, 512, 1, 64, 0x20001000, 0x20020000, 0x400e0a00, false); 111 | break; 112 | // 113 | // SAM3N 114 | // 115 | case 0x29340960 : // A 116 | case 0x29440960 : // B 117 | case 0x29540960 : // C 118 | flash = new EefcFlash(samba, "ATSAM3N4", 0x400000, 1024, 256, 1, 16, 0x20001000, 0x20006000, 0x400e0a00, false); 119 | break; 120 | case 0x29390760 : // A 121 | case 0x29490760 : // B 122 | case 0x29590760 : // C 123 | flash = new EefcFlash(samba, "ATSAM3N2", 0x400000, 512, 256, 1, 8, 0x20001000, 0x20004000, 0x400e0a00, false); 124 | break; 125 | case 0x29380560 : // A 126 | case 0x29480560 : // B 127 | case 0x29580560 : // C 128 | flash = new EefcFlash(samba, "ATSAM3N1", 0x400000, 256, 256, 1, 4, 0x20000800, 0x20002000, 0x400e0a00, false); 129 | break; 130 | // 131 | // SAM3S 132 | // 133 | case 0x28800960 : // A 134 | case 0x28900960 : // B 135 | case 0x28a00960 : // C 136 | flash = new EefcFlash(samba, "ATSAM3S4", 0x400000, 1024, 256, 1, 16, 0x20001000, 0x2000c000, 0x400e0a00, false); 137 | break; 138 | case 0x288a0760 : // A 139 | case 0x289a0760 : // B 140 | case 0x28aa0760 : // C 141 | flash = new EefcFlash(samba, "ATSAM3S2", 0x400000, 512, 256, 1, 8, 0x20000800, 0x20008000, 0x400e0a00, false); 142 | break; 143 | case 0x28890560 : //flutter 144 | case 0x288a0560 : // A 145 | case 0x289a0560 : // B 146 | case 0x28aa0560 : // C 147 | flash = new EefcFlash(samba, "ATSAM3S1", 0x400000, 256, 256, 1, 4, 0x20000800, 0x20004000, 0x400e0a00, false); 148 | break; 149 | // 150 | // SAM3U 151 | // 152 | case 0x28000960 : // C 153 | case 0x28100960 : // E 154 | flash = new EefcFlash(samba, "ATSAM3U4", 0xE0000, 1024, 256, 2, 32, 0x20001000, 0x20008000, 0x400e0800, false); 155 | break; 156 | case 0x280a0760 : // C 157 | case 0x281a0760 : // E 158 | flash = new EefcFlash(samba, "ATSAM3U2", 0x80000, 512, 256, 1, 16, 0x20001000, 0x20004000, 0x400e0800, false); 159 | break; 160 | case 0x28090560 : // C 161 | case 0x28190560 : // E 162 | flash = new EefcFlash(samba, "ATSAM3U1", 0x80000, 256, 256, 1, 8, 0x20001000, 0x20002000, 0x400e0800, false); 163 | break; 164 | // 165 | // SAM3X 166 | // 167 | case 0x286e0a60 : // 8H 168 | case 0x285e0a60 : // 8E 169 | case 0x284e0a60 : // 8C 170 | flash = new EefcFlash(samba, "ATSAM3X8", 0x80000, 2048, 256, 2, 32, 0x20001000, 0x20010000, 0x400e0a00, false); 171 | break; 172 | case 0x285b0960 : // 4E 173 | case 0x284b0960 : // 4C 174 | flash = new EefcFlash(samba, "ATSAM3X4", 0x80000, 1024, 256, 2, 16, 0x20001000, 0x20008000, 0x400e0a00, false); 175 | break; 176 | // 177 | // SAM3A 178 | // 179 | case 0x283e0A60 : // 8C 180 | flash = new EefcFlash(samba, "ATSAM3A8", 0x80000, 2048, 256, 2, 32, 0x20001000, 0x20010000, 0x400e0a00, false); 181 | break; 182 | case 0x283b0960 : // 4C 183 | flash = new EefcFlash(samba, "ATSAM3A4", 0x80000, 1024, 256, 2, 16, 0x20001000, 0x20008000, 0x400e0a00, false); 184 | break; 185 | // 186 | // SAM7L 187 | // 188 | case 0x27330740 : 189 | flash = new EefcFlash(samba, "ATSAM7L128", 0x100000, 512, 256, 1, 16, 0x2ffb40, 0x300700, 0xffffff60, false); 190 | break; 191 | case 0x27330540 : 192 | flash = new EefcFlash(samba, "ATSAM7L64", 0x100000, 256, 256, 1, 8, 0x2ffb40, 0x300700, 0xffffff60, false); 193 | break; 194 | // 195 | // SAM9XE 196 | // 197 | case 0x329aa3a0 : 198 | flash = new EefcFlash(samba, "ATSAM9XE512", 0x200000, 1024, 512, 1, 32, 0x300000, 0x307000, 0xfffffa00, true); 199 | break; 200 | case 0x329a93a0 : 201 | flash = new EefcFlash(samba, "ATSAM9XE256", 0x200000, 512, 512, 1, 16, 0x300000, 0x307000, 0xfffffa00, true); 202 | break; 203 | case 0x329973a0 : 204 | flash = new EefcFlash(samba, "ATSAM9XE128", 0x200000, 256, 512, 1, 8, 0x300000, 0x303000, 0xfffffa00, true); 205 | break; 206 | default: 207 | flash = NULL; 208 | break; 209 | } 210 | 211 | return Flash::Ptr(flash); 212 | } 213 | 214 | -------------------------------------------------------------------------------- /src/FlashFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _FLASHFACTORY_H 20 | #define _FLASHFACTORY_H 21 | 22 | #include 23 | 24 | #include "Samba.h" 25 | #include "Flash.h" 26 | 27 | class FlashFactory 28 | { 29 | public: 30 | FlashFactory(); 31 | virtual ~FlashFactory(); 32 | 33 | Flash::Ptr create(Samba& samba, uint32_t chipId); 34 | }; 35 | 36 | #endif // _FLASHFACTORY_H 37 | -------------------------------------------------------------------------------- /src/Flasher.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "Flasher.h" 27 | 28 | using namespace std; 29 | 30 | void 31 | Flasher::progressBar(int num, int div) 32 | { 33 | int ticks; 34 | int bars = 30; 35 | 36 | printf("\r["); 37 | ticks = num * bars / div; 38 | while (ticks-- > 0) 39 | { 40 | putchar('='); 41 | bars--; 42 | } 43 | while (bars-- > 0) 44 | { 45 | putchar(' '); 46 | } 47 | printf("] %d%% (%d/%d pages)", num * 100 / div, num, div); 48 | fflush(stdout); 49 | } 50 | 51 | void 52 | Flasher::erase() 53 | { 54 | printf("Erase flash\n"); 55 | _flash->eraseAll(); 56 | _flash->eraseAuto(false); 57 | } 58 | 59 | void 60 | Flasher::write(const char* filename) 61 | { 62 | FILE* infile; 63 | uint32_t pageSize = _flash->pageSize(); 64 | uint8_t buffer[pageSize]; 65 | uint32_t pageNum = 0; 66 | uint32_t numPages; 67 | long fsize; 68 | size_t fbytes; 69 | 70 | infile = fopen(filename, "rb"); 71 | if (!infile) 72 | throw FileOpenError(errno); 73 | 74 | try 75 | { 76 | if (fseek(infile, 0, SEEK_END) != 0 || 77 | (fsize = ftell(infile)) < 0) 78 | throw FileIoError(errno); 79 | rewind(infile); 80 | 81 | numPages = (fsize + pageSize - 1) / pageSize; 82 | if (numPages > _flash->numPages()) 83 | throw FileSizeError(); 84 | 85 | printf("Write %ld bytes to flash\n", fsize); 86 | 87 | while ((fbytes = fread(buffer, 1, pageSize, infile)) > 0) 88 | { 89 | if (pageNum % 10 == 0) 90 | progressBar(pageNum, numPages); 91 | 92 | _flash->loadBuffer(buffer); 93 | _flash->writePage(pageNum); 94 | 95 | pageNum++; 96 | if (pageNum == numPages || fbytes != pageSize) 97 | break; 98 | } 99 | if (fbytes < 0) 100 | throw FileIoError(errno); 101 | progressBar(pageNum, numPages); 102 | printf("\n"); 103 | } 104 | catch(...) 105 | { 106 | fclose(infile); 107 | throw; 108 | } 109 | fclose(infile); 110 | } 111 | 112 | bool 113 | Flasher::verify(const char* filename) 114 | { 115 | FILE* infile; 116 | uint32_t pageSize = _flash->pageSize(); 117 | uint8_t bufferA[pageSize]; 118 | uint8_t bufferB[pageSize]; 119 | uint32_t pageNum = 0; 120 | uint32_t numPages; 121 | uint32_t byteErrors = 0; 122 | uint32_t pageErrors = 0; 123 | uint32_t totalErrors = 0; 124 | long fsize; 125 | size_t fbytes; 126 | 127 | infile = fopen(filename, "rb"); 128 | if (!infile) 129 | throw FileOpenError(errno); 130 | 131 | try 132 | { 133 | if (fseek(infile, 0, SEEK_END) != 0 || 134 | (fsize = ftell(infile)) < 0) 135 | throw FileIoError(errno); 136 | rewind(infile); 137 | 138 | numPages = (fsize + pageSize - 1) / pageSize; 139 | if (numPages > _flash->numPages()) 140 | throw FileSizeError(); 141 | 142 | printf("Verify %ld bytes of flash\n", fsize); 143 | 144 | while ((fbytes = fread(bufferA, 1, pageSize, infile)) > 0) 145 | { 146 | if (pageNum % 10 == 0) 147 | progressBar(pageNum, numPages); 148 | 149 | _flash->readPage(pageNum, bufferB); 150 | 151 | byteErrors = 0; 152 | for (uint32_t i = 0; i < fbytes; i++) 153 | { 154 | if (bufferA[i] != bufferB[i]) 155 | byteErrors++; 156 | } 157 | if (byteErrors != 0) 158 | { 159 | pageErrors++; 160 | totalErrors += byteErrors; 161 | } 162 | 163 | pageNum++; 164 | if (pageNum == numPages || fbytes != pageSize) 165 | break; 166 | } 167 | if (fbytes < 0) 168 | throw FileIoError(errno); 169 | progressBar(pageNum, numPages); 170 | printf("\n"); 171 | } 172 | catch(...) 173 | { 174 | fclose(infile); 175 | throw; 176 | } 177 | fclose(infile); 178 | 179 | if (byteErrors != 0) 180 | { 181 | printf("Verify failed\n"); 182 | printf("Page errors: %d\n", pageErrors); 183 | printf("Byte errors: %d\n", totalErrors); 184 | return false; 185 | } 186 | 187 | printf("Verify successful\n"); 188 | return true; 189 | } 190 | 191 | void 192 | Flasher::read(const char* filename, long fsize) 193 | { 194 | FILE* outfile; 195 | uint32_t pageSize = _flash->pageSize(); 196 | uint8_t buffer[pageSize]; 197 | uint32_t pageNum = 0; 198 | uint32_t numPages; 199 | size_t fbytes; 200 | 201 | if (fsize == 0) 202 | fsize = pageSize * _flash->numPages(); 203 | 204 | outfile = fopen(filename, "wb"); 205 | if (!outfile) 206 | throw FileOpenError(errno); 207 | 208 | try 209 | { 210 | numPages = (fsize + pageSize - 1) / pageSize; 211 | if (numPages > _flash->numPages()) 212 | throw FileSizeError(); 213 | 214 | printf("Read %ld bytes from flash\n", fsize); 215 | 216 | for (pageNum = 0; pageNum < numPages; pageNum++) 217 | { 218 | if (pageNum % 10 == 0) 219 | progressBar(pageNum, numPages); 220 | 221 | _flash->readPage(pageNum, buffer); 222 | 223 | if (pageNum == numPages - 1 && fsize % pageSize > 0) 224 | pageSize = fsize % pageSize; 225 | fbytes = fwrite(buffer, 1, pageSize, outfile); 226 | if (fbytes < 0) 227 | throw FileIoError(errno); 228 | if (fbytes != pageSize) 229 | throw FileShortError(); 230 | } 231 | progressBar(pageNum, numPages); 232 | printf("\n"); 233 | } 234 | catch(...) 235 | { 236 | fclose(outfile); 237 | throw; 238 | } 239 | fclose(outfile); 240 | } 241 | 242 | void 243 | Flasher::lock(string& regionArg, bool enable) 244 | { 245 | if (regionArg.empty()) 246 | { 247 | printf("%s all regions\n", enable ? "Lock" : "Unlock"); 248 | if (enable) 249 | _flash->lockAll(); 250 | else 251 | _flash->unlockAll(); 252 | } 253 | else 254 | { 255 | size_t pos = 0; 256 | size_t delim; 257 | uint32_t region; 258 | string sub; 259 | 260 | do 261 | { 262 | delim = regionArg.find(',', pos); 263 | sub = regionArg.substr(pos, delim < 0 ? -1 : delim - pos); 264 | region = strtol(sub.c_str(), NULL, 0); 265 | printf("%s region %d\n", enable ? "Lock" : "Unlock", region); 266 | _flash->setLockRegion(region, enable); 267 | pos = delim + 1; 268 | } while (delim != string::npos); 269 | } 270 | } 271 | 272 | void 273 | Flasher::info(Samba& samba) 274 | { 275 | bool first; 276 | 277 | printf("Device : %s\n", _flash->name().c_str()); 278 | printf("Chip ID : %08x\n", samba.chipId()); 279 | printf("Version : %s\n", samba.version().c_str()); 280 | printf("Address : %d\n", _flash->address()); 281 | printf("Pages : %d\n", _flash->numPages()); 282 | printf("Page Size : %d bytes\n", _flash->pageSize()); 283 | printf("Total Size : %dKB\n", _flash->numPages() * _flash->pageSize() / 1024); 284 | printf("Planes : %d\n", _flash->numPlanes()); 285 | printf("Lock Regions : %d\n", _flash->lockRegions()); 286 | printf("Locked : "); 287 | first = true; 288 | for (uint32_t region = 0; region < _flash->lockRegions(); region++) 289 | { 290 | if (_flash->getLockRegion(region)) 291 | { 292 | printf("%s%d", first ? "" : ",", region); 293 | first = false; 294 | } 295 | } 296 | printf("%s\n", first ? "none" : ""); 297 | printf("Security : %s\n", _flash->getSecurity() ? "true" : "false"); 298 | if (_flash->canBootFlash()) 299 | printf("Boot Flash : %s\n", _flash->getBootFlash() ? "true" : "false"); 300 | if (_flash->canBod()) 301 | printf("BOD : %s\n", _flash->getBod() ? "true" : "false"); 302 | if (_flash->canBor()) 303 | printf("BOR : %s\n", _flash->getBor() ? "true" : "false"); 304 | } 305 | -------------------------------------------------------------------------------- /src/Flasher.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _FLASHER_H 20 | #define _FLASHER_H 21 | 22 | #include 23 | #include 24 | 25 | #include "Flash.h" 26 | #include "Samba.h" 27 | #include "FileError.h" 28 | 29 | class FileSizeError : public FileError 30 | { 31 | public: 32 | FileSizeError() : FileError() {}; 33 | virtual const char* what() const throw() { return "file operation exceeds flash size"; } 34 | }; 35 | 36 | class Flasher 37 | { 38 | public: 39 | Flasher(Flash::Ptr& flash) : _flash(flash) {} 40 | virtual ~Flasher() {} 41 | 42 | void erase(); 43 | void write(const char* filename); 44 | bool verify(const char* filename); 45 | void read(const char* filename, long fsize); 46 | void lock(std::string& regionArg, bool enable); 47 | void info(Samba& samba); 48 | 49 | private: 50 | void progressBar(int num, int div); 51 | 52 | Flash::Ptr& _flash; 53 | }; 54 | 55 | #endif // _FLASHER_H 56 | -------------------------------------------------------------------------------- /src/LinuxPortFactory.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "LinuxPortFactory.h" 20 | #include "PosixSerialPort.h" 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | LinuxPortFactory::LinuxPortFactory() 28 | { 29 | _dir = opendir("/dev"); 30 | } 31 | 32 | LinuxPortFactory::~LinuxPortFactory() 33 | { 34 | if (_dir) 35 | closedir(_dir); 36 | } 37 | 38 | SerialPort::Ptr 39 | LinuxPortFactory::create(const std::string& name) 40 | { 41 | bool isUsb = false; 42 | 43 | if (name.find("ttyUSB") != std::string::npos || 44 | name.find("ttyACM") != std::string::npos) 45 | isUsb = true; 46 | 47 | return create(name, isUsb); 48 | } 49 | 50 | SerialPort::Ptr 51 | LinuxPortFactory::create(const std::string& name, bool isUsb) 52 | { 53 | return SerialPort::Ptr(new PosixSerialPort(name, isUsb)); 54 | } 55 | 56 | std::string 57 | LinuxPortFactory::begin() 58 | { 59 | if (!_dir) 60 | return end(); 61 | 62 | rewinddir(_dir); 63 | 64 | return next(); 65 | } 66 | 67 | std::string 68 | LinuxPortFactory::next() 69 | { 70 | struct dirent* entry; 71 | 72 | if (!_dir) 73 | return end(); 74 | 75 | while ((entry = readdir(_dir))) 76 | { 77 | if (strncmp("ttyUSB", entry->d_name, sizeof("ttyUSB") - 1) == 0) 78 | return std::string(entry->d_name); 79 | else if (strncmp("ttyACM", entry->d_name, sizeof("ttyACM") - 1) == 0) 80 | return std::string(entry->d_name); 81 | else if (strncmp("ttyS", entry->d_name, sizeof("ttyS") - 1) == 0) 82 | return std::string(entry->d_name); 83 | } 84 | 85 | return end(); 86 | } 87 | 88 | std::string 89 | LinuxPortFactory::end() 90 | { 91 | return std::string(); 92 | } 93 | -------------------------------------------------------------------------------- /src/LinuxPortFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _LINUXPORTFACTORY_H 20 | #define _LINUXPORTFACTORY_H 21 | 22 | #include "SerialPort.h" 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | 30 | class LinuxPortFactory 31 | { 32 | public: 33 | LinuxPortFactory(); 34 | virtual ~LinuxPortFactory(); 35 | 36 | virtual std::string begin(); 37 | virtual std::string end(); 38 | virtual std::string next(); 39 | 40 | virtual SerialPort::Ptr create(const std::string& name); 41 | virtual SerialPort::Ptr create(const std::string& name, bool isUsb); 42 | 43 | private: 44 | std::string _empty; 45 | DIR* _dir; 46 | }; 47 | 48 | #endif // _LINUXPORTFACTORY_H 49 | -------------------------------------------------------------------------------- /src/OSXPortFactory.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "OSXPortFactory.h" 20 | #include "PosixSerialPort.h" 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | OSXPortFactory::OSXPortFactory() 28 | { 29 | _dir = opendir("/dev"); 30 | } 31 | 32 | OSXPortFactory::~OSXPortFactory() 33 | { 34 | if (_dir) 35 | closedir(_dir); 36 | } 37 | 38 | SerialPort::Ptr 39 | OSXPortFactory::create(const std::string& name) 40 | { 41 | bool isUsb = false; 42 | 43 | if (name.find("usb") != std::string::npos) 44 | isUsb = true; 45 | 46 | return create(name, isUsb); 47 | } 48 | 49 | SerialPort::Ptr 50 | OSXPortFactory::create(const std::string& name, bool isUsb) 51 | { 52 | PosixSerialPort *p = new PosixSerialPort(name, isUsb); 53 | // Needed to avoid upload errors 54 | p->setAutoFlush(true); 55 | return SerialPort::Ptr(p); 56 | } 57 | 58 | std::string 59 | OSXPortFactory::begin() 60 | { 61 | if (!_dir) 62 | return end(); 63 | 64 | rewinddir(_dir); 65 | 66 | return next(); 67 | } 68 | 69 | std::string 70 | OSXPortFactory::next() 71 | { 72 | struct dirent* entry; 73 | 74 | if (!_dir) 75 | return end(); 76 | 77 | while ((entry = readdir(_dir))) 78 | { 79 | if (strncmp("cu.", entry->d_name, sizeof("cu.") - 1) == 0) 80 | return std::string(entry->d_name); 81 | } 82 | 83 | return end(); 84 | } 85 | 86 | std::string 87 | OSXPortFactory::end() 88 | { 89 | return std::string(); 90 | } 91 | -------------------------------------------------------------------------------- /src/OSXPortFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _OSXPORTFACTORY_H 20 | #define _OSXPORTFACTORY_H 21 | 22 | #include "SerialPort.h" 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | 30 | class OSXPortFactory 31 | { 32 | public: 33 | OSXPortFactory(); 34 | virtual ~OSXPortFactory(); 35 | 36 | virtual std::string begin(); 37 | virtual std::string end(); 38 | virtual std::string next(); 39 | 40 | virtual SerialPort::Ptr create(const std::string& name); 41 | virtual SerialPort::Ptr create(const std::string& name, bool isUsb); 42 | 43 | private: 44 | std::string _empty; 45 | DIR* _dir; 46 | }; 47 | 48 | #endif // _OSXPORTFACTORY_H 49 | -------------------------------------------------------------------------------- /src/PortFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _PORTFACTORY_H 20 | #define _PORTFACTORY_H 21 | 22 | #include 23 | 24 | #include "SerialPort.h" 25 | 26 | class PortFactoryBase 27 | { 28 | public: 29 | PortFactoryBase() {} 30 | virtual ~PortFactoryBase() {} 31 | 32 | virtual std::string begin() = 0; 33 | virtual std::string end() = 0; 34 | virtual std::string next() = 0; 35 | 36 | virtual SerialPort::Ptr create(const std::string& name) = 0; 37 | virtual SerialPort::Ptr create(const std::string& name, bool isUsb) = 0; 38 | }; 39 | 40 | #if defined(__WIN32__) 41 | #include "WinPortFactory.h" 42 | typedef WinPortFactory PortFactory; 43 | #elif defined(__linux__) 44 | #include "LinuxPortFactory.h" 45 | typedef LinuxPortFactory PortFactory; 46 | #elif defined(__APPLE__) 47 | #include "OSXPortFactory.h" 48 | typedef OSXPortFactory PortFactory; 49 | #else 50 | #error "Platform is not supported" 51 | #endif 52 | 53 | #endif // _PORTFACTORY_H 54 | -------------------------------------------------------------------------------- /src/PosixSerialPort.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "PosixSerialPort.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #ifndef B460800 32 | #define B460800 460800 33 | #endif 34 | #ifndef B921600 35 | #define B921600 921600 36 | #endif 37 | 38 | PosixSerialPort::PosixSerialPort(const std::string& name, bool isUsb) : 39 | SerialPort(name), _devfd(-1), _isUsb(isUsb), _timeout(0), 40 | _autoFlush(false) 41 | { 42 | } 43 | 44 | PosixSerialPort::~PosixSerialPort() 45 | { 46 | if (_devfd >= 0) 47 | ::close(_devfd); 48 | } 49 | 50 | bool 51 | PosixSerialPort::open(int baud, 52 | int data, 53 | SerialPort::Parity parity, 54 | SerialPort::StopBit stop) 55 | { 56 | struct termios options; 57 | speed_t speed; 58 | std::string dev("/dev/"); 59 | 60 | dev += _name; 61 | _devfd = ::open(dev.c_str(), O_RDWR | O_NOCTTY | O_NDELAY); 62 | if (_devfd == -1) 63 | return false; 64 | 65 | if (tcgetattr(_devfd, &options) == -1) 66 | { 67 | close(); 68 | return false; 69 | } 70 | 71 | switch (baud) 72 | { 73 | case 9600: 74 | speed = B9600; 75 | break; 76 | case 19200: 77 | speed = B19200; 78 | break; 79 | case 38400: 80 | speed = B38400; 81 | break; 82 | case 57600: 83 | speed = B57600; 84 | break; 85 | case 115200: 86 | speed = B115200; 87 | break; 88 | case 230400: 89 | speed = B230400; 90 | break; 91 | case 460800: 92 | speed = B460800; 93 | break; 94 | case 921600: 95 | speed = B921600; 96 | break; 97 | default: 98 | close(); 99 | return false; 100 | } 101 | 102 | if (cfsetispeed(&options, speed) || cfsetospeed(&options, speed)) 103 | { 104 | close(); 105 | return false; 106 | } 107 | 108 | options.c_cflag |= (CLOCAL | CREAD); 109 | 110 | switch (data) 111 | { 112 | case 8: 113 | options.c_cflag &= ~CSIZE; 114 | options.c_cflag |= CS8; 115 | break; 116 | case 7: 117 | options.c_cflag &= ~CSIZE; 118 | options.c_cflag |= CS7; 119 | break; 120 | default: 121 | close(); 122 | return false; 123 | } 124 | 125 | switch (parity) 126 | { 127 | case SerialPort::ParityNone: 128 | options.c_cflag &= ~PARENB; 129 | options.c_cflag &= ~PARODD; 130 | options.c_iflag &= ~(INPCK | ISTRIP); 131 | break; 132 | case SerialPort::ParityOdd: 133 | options.c_cflag |= PARENB; 134 | options.c_cflag |= PARODD; 135 | options.c_iflag |= (INPCK | ISTRIP); 136 | break; 137 | case SerialPort::ParityEven: 138 | options.c_cflag |= PARENB; 139 | options.c_cflag &= ~PARODD; 140 | options.c_iflag |= (INPCK | ISTRIP); 141 | break; 142 | default: 143 | close(); 144 | return false; 145 | } 146 | 147 | switch (stop) 148 | { 149 | case StopBitOne: 150 | options.c_cflag &= ~CSTOPB; 151 | break; 152 | case StopBitTwo: 153 | options.c_cflag |= CSTOPB; 154 | break; 155 | default: 156 | close(); 157 | return false; 158 | } 159 | 160 | // No hardware flow control 161 | options.c_cflag &= ~CRTSCTS; 162 | 163 | // No software flow control 164 | options.c_iflag &= ~(IXON | IXOFF | IXANY); 165 | 166 | // Raw input 167 | options.c_iflag &= ~(BRKINT | ICRNL); 168 | options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); 169 | 170 | // Raw output 171 | options.c_oflag &= ~OPOST; 172 | 173 | // No wait time 174 | options.c_cc[VMIN] = 0; 175 | options.c_cc[VTIME] = 0; 176 | 177 | if (tcsetattr(_devfd, TCSANOW, &options)) 178 | { 179 | close(); 180 | return false; 181 | } 182 | 183 | return true; 184 | } 185 | 186 | void 187 | PosixSerialPort::close() 188 | { 189 | if (_devfd >= 0) 190 | ::close(_devfd); 191 | _devfd = -1; 192 | } 193 | 194 | int 195 | PosixSerialPort::read(uint8_t* buffer, int len) 196 | { 197 | fd_set fds; 198 | struct timeval tv; 199 | int numread = 0; 200 | int retval; 201 | 202 | if (_devfd == -1) 203 | return -1; 204 | 205 | while (numread < len) 206 | { 207 | FD_ZERO(&fds); 208 | FD_SET(_devfd, &fds); 209 | 210 | tv.tv_sec = _timeout / 1000; 211 | tv.tv_usec = (_timeout % 1000) * 1000; 212 | 213 | retval = select(_devfd + 1, &fds, NULL, NULL, &tv); 214 | 215 | if (retval < 0) 216 | { 217 | return -1; 218 | } 219 | else if (retval == 0) 220 | { 221 | return numread; 222 | } 223 | else if (FD_ISSET(_devfd, &fds)) 224 | { 225 | retval = ::read(_devfd, (uint8_t*) buffer + numread, len - numread); 226 | if (retval < 0) 227 | return -1; 228 | numread += retval; 229 | } 230 | } 231 | 232 | return numread; 233 | } 234 | 235 | int 236 | PosixSerialPort::write(const uint8_t* buffer, int len) 237 | { 238 | if (_devfd == -1) 239 | return -1; 240 | 241 | int res = ::write(_devfd, buffer, len); 242 | // Used on macos to avoid upload errors 243 | if (_autoFlush) 244 | flush(); 245 | return res; 246 | } 247 | 248 | int 249 | PosixSerialPort::get() 250 | { 251 | uint8_t byte; 252 | 253 | if (_devfd == -1) 254 | return -1; 255 | 256 | if (read(&byte, 1) != 1) 257 | return -1; 258 | 259 | return byte; 260 | } 261 | 262 | int 263 | PosixSerialPort::put(int c) 264 | { 265 | uint8_t byte; 266 | 267 | byte = c; 268 | return write(&byte, 1); 269 | } 270 | 271 | void 272 | PosixSerialPort::flush() 273 | { 274 | // There isn't a reliable way to flush on a file descriptor 275 | // so we just wait it out. One millisecond is the USB poll 276 | // interval so that should cover it. 277 | usleep(1000); 278 | } 279 | 280 | bool 281 | PosixSerialPort::timeout(int millisecs) 282 | { 283 | _timeout = millisecs; 284 | return true; 285 | } 286 | 287 | void 288 | PosixSerialPort::setAutoFlush(bool autoflush) 289 | { 290 | _autoFlush = autoflush; 291 | } 292 | -------------------------------------------------------------------------------- /src/PosixSerialPort.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _POSIXSERIALPORT_H 20 | #define _POSIXSERIALPORT_H 21 | 22 | #include "SerialPort.h" 23 | 24 | class PosixSerialPort : public SerialPort 25 | { 26 | public: 27 | PosixSerialPort(const std::string& name, bool isUsb); 28 | virtual ~PosixSerialPort(); 29 | 30 | bool open(int baud = 115200, 31 | int data = 8, 32 | SerialPort::Parity parity = SerialPort::ParityNone, 33 | SerialPort::StopBit stop = SerialPort::StopBitOne); 34 | void close(); 35 | 36 | bool isUsb() { return _isUsb; }; 37 | 38 | int read(uint8_t* data, int size); 39 | int write(const uint8_t* data, int size); 40 | int get(); 41 | int put(int c); 42 | 43 | bool timeout(int millisecs); 44 | void flush(); 45 | void setAutoFlush(bool autoflush); 46 | 47 | private: 48 | int _devfd; 49 | bool _isUsb; 50 | int _timeout; 51 | bool _autoFlush; 52 | }; 53 | 54 | #endif // _POSIXSERIALPORT_H 55 | -------------------------------------------------------------------------------- /src/Samba.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _SAMBA_H 20 | #define _SAMBA_H 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "SerialPort.h" 28 | 29 | class SambaError : public std::exception 30 | { 31 | public: 32 | SambaError() : exception() {}; 33 | const char* what() const throw() { return "SAM-BA operation failed"; } 34 | }; 35 | 36 | class Samba 37 | { 38 | public: 39 | Samba(); 40 | virtual ~Samba(); 41 | 42 | bool connect(SerialPort::Ptr port, int bps=115200); 43 | void disconnect(); 44 | 45 | void writeByte(uint32_t addr, uint8_t value); 46 | uint8_t readByte(uint32_t addr); 47 | 48 | void writeWord(uint32_t addr, uint32_t value); 49 | uint32_t readWord(uint32_t addr); 50 | 51 | void write(uint32_t addr, const uint8_t* buffer, int size); 52 | void read(uint32_t addr, uint8_t* buffer, int size); 53 | 54 | void go(uint32_t addr); 55 | 56 | std::string version(); 57 | 58 | uint32_t chipId(); 59 | 60 | void setDebug(bool debug) { _debug = debug; } 61 | 62 | const SerialPort& getSerialPort() { return *_port; } 63 | 64 | void reset(void); 65 | 66 | private: 67 | bool _debug; 68 | bool _isUsb; 69 | SerialPort::Ptr _port; 70 | 71 | bool init(); 72 | 73 | uint16_t crc16Calc(const uint8_t *data, int len); 74 | bool crc16Check(const uint8_t *blk); 75 | void crc16Add(uint8_t *blk); 76 | void writeXmodem(const uint8_t* buffer, int size); 77 | void readXmodem(uint8_t* buffer, int size); 78 | 79 | void writeBinary(const uint8_t* buffer, int size); 80 | void readBinary(uint8_t* buffer, int size); 81 | }; 82 | 83 | #endif // _SAMBA_H 84 | -------------------------------------------------------------------------------- /src/SerialPort.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _SERIALPORT_H 20 | #define _SERIALPORT_H 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | class SerialPort 27 | { 28 | public: 29 | SerialPort(const std::string& name) : _name(name) {} 30 | virtual ~SerialPort() {} 31 | 32 | enum Parity 33 | { 34 | ParityNone, 35 | ParityOdd, 36 | ParityEven, 37 | }; 38 | 39 | enum StopBit 40 | { 41 | StopBitOne, 42 | StopBitOneFive, 43 | StopBitTwo, 44 | }; 45 | 46 | virtual bool open(int baud = 115200, 47 | int data = 8, 48 | Parity parity = ParityNone, 49 | StopBit stop = StopBitOne) = 0; 50 | virtual void close() = 0; 51 | 52 | virtual bool isUsb() = 0; 53 | 54 | virtual int read(uint8_t* data, int size) = 0; 55 | virtual int write(const uint8_t* data, int size) = 0; 56 | virtual int get() = 0; 57 | virtual int put(int c) = 0; 58 | 59 | virtual bool timeout(int millisecs) = 0; 60 | virtual void flush() = 0; 61 | 62 | virtual std::string name() const { return _name; } 63 | 64 | typedef std::auto_ptr Ptr; 65 | 66 | protected: 67 | std::string _name; 68 | }; 69 | 70 | #endif // _SERIALPORT_H 71 | -------------------------------------------------------------------------------- /src/Shell.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include 20 | #include 21 | 22 | #include "Shell.h" 23 | #include "Command.h" 24 | 25 | using namespace std; 26 | 27 | Shell::Shell() : 28 | _exitFlag(false) 29 | { 30 | Command::setShell(this); 31 | 32 | add(new CommandBod); 33 | add(new CommandBootf); 34 | add(new CommandBor); 35 | add(new CommandConnect); 36 | add(new CommandDebug); 37 | add(new CommandDisass); 38 | add(new CommandDump); 39 | add(new CommandErase); 40 | add(new CommandExit); 41 | add(new CommandGo); 42 | add(new CommandHelp); 43 | add(new CommandHistory); 44 | add(new CommandLock); 45 | add(new CommandInfo); 46 | add(new CommandMrb); 47 | add(new CommandMrf); 48 | add(new CommandMrw); 49 | add(new CommandMwb); 50 | add(new CommandMwf); 51 | add(new CommandMww); 52 | add(new CommandPio); 53 | add(new CommandRead); 54 | add(new CommandScan); 55 | add(new CommandSecurity); 56 | add(new CommandVerify); 57 | add(new CommandWrite); 58 | add(new CommandReset); 59 | 60 | _commandList.sort(); 61 | } 62 | 63 | Shell::~Shell() 64 | { 65 | CommandList::iterator it; 66 | 67 | for (it = _commandList.begin(); 68 | it != _commandList.end(); 69 | it++) 70 | { 71 | delete *it; 72 | } 73 | } 74 | 75 | Command* 76 | Shell::find(const char* name) 77 | { 78 | CommandList::iterator it; 79 | int len; 80 | Command *command = NULL; 81 | 82 | len = strlen(name); 83 | for (it = _commandList.begin(); 84 | it != _commandList.end(); 85 | it++) 86 | { 87 | if (strncmp((*it)->name(), name, len) == 0) 88 | { 89 | if (command) 90 | { 91 | printf("Ambiguous command: \"%s\". Try \"help\".\n", name); 92 | return NULL; 93 | } 94 | command = *it; 95 | } 96 | } 97 | 98 | if (!command) 99 | { 100 | printf("Undefined command: \"%s\". Try \"help\".\n", name); 101 | return NULL; 102 | } 103 | 104 | return command; 105 | } 106 | 107 | void 108 | Shell::invoke(char* argv[], int argc) 109 | { 110 | Command* command; 111 | 112 | command = find(argv[0]); 113 | if (!command) 114 | return; 115 | 116 | try 117 | { 118 | command->invoke(argv, argc); 119 | } 120 | catch (SambaError& e) 121 | { 122 | printf("\n%s.\nPort is disconnected.\n", e.what()); 123 | Command::disconnect(); 124 | } 125 | catch (exception& e) 126 | { 127 | printf("\n%s.\n", e.what()); 128 | } 129 | } 130 | 131 | void 132 | Shell::help() 133 | { 134 | CommandList::iterator it; 135 | 136 | for (it = _commandList.begin(); 137 | it != _commandList.end(); 138 | it++) 139 | { 140 | printf("%s -- %s\n", (*it)->name(), (*it)->help()); 141 | } 142 | } 143 | 144 | void 145 | Shell::usage(const char* name) 146 | { 147 | Command* command; 148 | 149 | command = find(name); 150 | if (!command) 151 | return; 152 | 153 | printf("%s\n", command->help()); 154 | printf("Usage: %s\n", command->usage()); 155 | } 156 | 157 | void 158 | Shell::add(Command* command) 159 | { 160 | _commandList.push_back(command); 161 | } 162 | -------------------------------------------------------------------------------- /src/Shell.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _Shell_H 20 | #define _Shell_H 21 | 22 | #include 23 | #include 24 | 25 | 26 | class Command; 27 | 28 | class Shell 29 | { 30 | public: 31 | virtual ~Shell(); 32 | Shell(); 33 | 34 | void invoke(char* argv[], int argc); 35 | void help(); 36 | void usage(const char* name); 37 | void add(Command* command); 38 | Command* find(const char* name); 39 | 40 | bool& exitFlag() { return _exitFlag; } 41 | 42 | private: 43 | typedef std::list CommandList; 44 | CommandList _commandList; 45 | bool _exitFlag; 46 | }; 47 | 48 | #endif // _Shell_H 49 | -------------------------------------------------------------------------------- /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-2012 ShumaTech http://www.shumatech.com/ 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 | #include "WinPortFactory.h" 20 | #include "WinSerialPort.h" 21 | 22 | #define USB_DEVICE_NAME "\\Device\\USB" 23 | 24 | WinPortFactory::WinPortFactory() : 25 | _devInfo(INVALID_HANDLE_VALUE), _cfgMgr(NULL), _devNode(NULL), _devNum(0) 26 | { 27 | } 28 | 29 | WinPortFactory::~WinPortFactory() 30 | { 31 | cleanup(); 32 | } 33 | 34 | SerialPort::Ptr 35 | WinPortFactory::create(const std::string& name) 36 | { 37 | bool isUsb = false; 38 | char szNtDeviceName[MAX_PATH]; 39 | 40 | if (QueryDosDevice(name.c_str(), szNtDeviceName, MAX_PATH)) 41 | { 42 | if (strncmp(szNtDeviceName, USB_DEVICE_NAME, sizeof(USB_DEVICE_NAME) - 1) == 0) 43 | { 44 | isUsb = true; 45 | } 46 | } 47 | 48 | return create(name, isUsb); 49 | } 50 | 51 | SerialPort::Ptr 52 | WinPortFactory::create(const std::string& name, bool isUsb) 53 | { 54 | return SerialPort::Ptr(new WinSerialPort(name, isUsb)); 55 | } 56 | 57 | void 58 | WinPortFactory::cleanup() 59 | { 60 | _devNum = 0; 61 | _devNode = NULL; 62 | 63 | if (_cfgMgr == NULL) 64 | { 65 | FreeLibrary(_cfgMgr); 66 | _cfgMgr = NULL; 67 | } 68 | 69 | if (_devInfo != INVALID_HANDLE_VALUE) 70 | { 71 | SetupDiDestroyDeviceInfoList(_devInfo); 72 | _devInfo = INVALID_HANDLE_VALUE; 73 | } 74 | } 75 | 76 | std::string 77 | WinPortFactory::error() 78 | { 79 | cleanup(); 80 | return end(); 81 | } 82 | 83 | std::string 84 | WinPortFactory::begin() 85 | { 86 | DWORD size = 0; 87 | 88 | if (_devInfo != INVALID_HANDLE_VALUE) 89 | cleanup(); 90 | 91 | SetupDiClassGuidsFromNameA("Ports", 0, 0, &size); 92 | if (size < 1) 93 | return error(); 94 | 95 | GUID guids[size]; 96 | 97 | if (!SetupDiClassGuidsFromNameA("Ports", guids, size * sizeof(GUID), &size)) 98 | { 99 | return error(); 100 | } 101 | 102 | _devInfo = SetupDiGetClassDevs(guids, NULL, NULL, DIGCF_PRESENT); 103 | if(_devInfo == INVALID_HANDLE_VALUE) 104 | return error(); 105 | 106 | _cfgMgr = LoadLibrary("cfgmgr32"); 107 | if (!_cfgMgr) 108 | return error(); 109 | 110 | _devNode = (CM_Open_DevNode_Key) GetProcAddress(_cfgMgr, "CM_Open_DevNode_Key"); 111 | if (!_devNode) 112 | return error(); 113 | 114 | return next(); 115 | } 116 | 117 | std::string 118 | WinPortFactory::end() 119 | { 120 | return std::string(); 121 | } 122 | 123 | std::string 124 | WinPortFactory::next() 125 | { 126 | int rc; 127 | BYTE devName[16]; 128 | SP_DEVINFO_DATA devData; 129 | HKEY devKey; 130 | DWORD len; 131 | 132 | if (_devInfo == INVALID_HANDLE_VALUE) 133 | return end(); 134 | 135 | while (1) 136 | { 137 | devData.cbSize = sizeof(SP_DEVINFO_DATA); 138 | if (!SetupDiEnumDeviceInfo(_devInfo, _devNum, &devData)) 139 | return error(); 140 | 141 | rc = _devNode(devData.DevInst, 142 | KEY_QUERY_VALUE, 143 | 0, 144 | 1, 145 | &devKey, 146 | 0); 147 | 148 | if (rc != ERROR_SUCCESS) 149 | return error(); 150 | 151 | len = sizeof(devName); 152 | rc = RegQueryValueEx(devKey, 153 | "portname", 154 | NULL, 155 | NULL, 156 | devName, 157 | &len); 158 | 159 | RegCloseKey(devKey); 160 | if (rc != ERROR_SUCCESS) 161 | return error(); 162 | 163 | _devNum++; 164 | 165 | if (strncmp("COM", (char*) devName, 3) == 0) 166 | break; 167 | } 168 | 169 | return std::string((char*) devName, len); 170 | } 171 | -------------------------------------------------------------------------------- /src/WinPortFactory.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _WINPORTFACTORY_H 20 | #define _WINPORTFACTORY_H 21 | 22 | class WinPortFactory; 23 | #include "PortFactory.h" 24 | 25 | #include 26 | #include 27 | 28 | class WinPortFactory : public PortFactoryBase 29 | { 30 | public: 31 | WinPortFactory(); 32 | virtual ~WinPortFactory(); 33 | 34 | std::string begin(); 35 | std::string end(); 36 | std::string next(); 37 | 38 | SerialPort::Ptr create(const std::string& name); 39 | SerialPort::Ptr create(const std::string& name, bool isUsb); 40 | 41 | private: 42 | typedef DWORD WINAPI (*CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, ::PHKEY, DWORD); 43 | 44 | HDEVINFO _devInfo; 45 | HINSTANCE _cfgMgr; 46 | CM_Open_DevNode_Key _devNode; 47 | int _devNum; 48 | 49 | void cleanup(); 50 | std::string error(); 51 | }; 52 | 53 | #endif // _WINPORTFACTORY_H 54 | -------------------------------------------------------------------------------- /src/WinSerialPort.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "WinSerialPort.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | WinSerialPort::WinSerialPort(const std::string& name, bool isUsb) : 27 | SerialPort(name), _handle(INVALID_HANDLE_VALUE), _isUsb(isUsb) 28 | { 29 | } 30 | 31 | WinSerialPort::~WinSerialPort() 32 | { 33 | close(); 34 | } 35 | 36 | #ifdef DEBUG 37 | static void 38 | printLastError() 39 | { 40 | char buffer[100]; 41 | DWORD dw = GetLastError(); 42 | 43 | if (FormatMessage( 44 | FORMAT_MESSAGE_FROM_SYSTEM | 45 | FORMAT_MESSAGE_IGNORE_INSERTS, 46 | NULL, 47 | dw, 48 | 0, 49 | buffer, 50 | sizeof(buffer), 51 | NULL )) 52 | { 53 | printf("Error (%d): %s", (int) dw, (LPSTR) buffer); 54 | } 55 | else 56 | { 57 | printf("Error (%d)\n", (int) dw); 58 | } 59 | } 60 | #endif 61 | 62 | bool 63 | WinSerialPort::open(int baud, int data, SerialPort::Parity parity, SerialPort::StopBit stop) 64 | { 65 | DCB dcbSerialParams; 66 | 67 | if (_handle != INVALID_HANDLE_VALUE) 68 | return false; 69 | 70 | std::string device = "\\\\.\\" + _name; 71 | _handle = CreateFile(device.c_str(), 72 | GENERIC_READ | GENERIC_WRITE, 73 | 0, 74 | 0, 75 | OPEN_EXISTING, 76 | FILE_ATTRIBUTE_NORMAL, 77 | 0); 78 | 79 | if (_handle == INVALID_HANDLE_VALUE) 80 | return false; 81 | 82 | dcbSerialParams.DCBlength = sizeof(dcbSerialParams); 83 | 84 | if (!GetCommState(_handle, &dcbSerialParams)) 85 | { 86 | CloseHandle(_handle); 87 | return false; 88 | } 89 | 90 | dcbSerialParams.BaudRate = baud; 91 | 92 | dcbSerialParams.ByteSize = data; 93 | 94 | switch (parity) 95 | { 96 | case ParityNone: 97 | dcbSerialParams.Parity = NOPARITY; 98 | break; 99 | case ParityOdd: 100 | dcbSerialParams.Parity = ODDPARITY; 101 | break; 102 | case ParityEven: 103 | dcbSerialParams.Parity = EVENPARITY; 104 | break; 105 | default: 106 | CloseHandle(_handle); 107 | return false; 108 | } 109 | 110 | switch (stop) 111 | { 112 | case StopBitOne: 113 | dcbSerialParams.StopBits = ONESTOPBIT; 114 | break; 115 | case StopBitOneFive: 116 | dcbSerialParams.StopBits = ONE5STOPBITS; 117 | break; 118 | case StopBitTwo: 119 | dcbSerialParams.StopBits = TWOSTOPBITS; 120 | break; 121 | default: 122 | CloseHandle(_handle); 123 | return false; 124 | } 125 | 126 | if (!SetCommState(_handle, &dcbSerialParams)) 127 | { 128 | CloseHandle(_handle); 129 | return false; 130 | } 131 | 132 | timeout(INT_MAX); 133 | 134 | return true; 135 | } 136 | 137 | void 138 | WinSerialPort::close() 139 | { 140 | if (_handle != INVALID_HANDLE_VALUE) 141 | CloseHandle(_handle); 142 | _handle = INVALID_HANDLE_VALUE; 143 | } 144 | 145 | bool 146 | WinSerialPort::timeout(int millisecs) 147 | { 148 | COMMTIMEOUTS timeouts; 149 | 150 | if (_handle == INVALID_HANDLE_VALUE) 151 | return false; 152 | 153 | timeouts.ReadIntervalTimeout = MAXDWORD; 154 | timeouts.ReadTotalTimeoutConstant = millisecs; 155 | timeouts.ReadTotalTimeoutMultiplier = 0; 156 | 157 | timeouts.WriteTotalTimeoutConstant = MAXDWORD; 158 | timeouts.WriteTotalTimeoutMultiplier = 0; 159 | 160 | if (!SetCommTimeouts(_handle, &timeouts)) 161 | return false; 162 | 163 | return true; 164 | } 165 | 166 | int 167 | WinSerialPort::read(uint8_t* data, int size) 168 | { 169 | DWORD bytes; 170 | int total = 0; 171 | 172 | if (_handle == INVALID_HANDLE_VALUE) 173 | return -1; 174 | 175 | while (size > 0) 176 | { 177 | if (!ReadFile(_handle, data, size, &bytes, NULL)) 178 | return -1; 179 | if (bytes == 0) 180 | break; 181 | size -= bytes; 182 | data += bytes; 183 | total += bytes; 184 | } 185 | 186 | return total; 187 | } 188 | 189 | int 190 | WinSerialPort::write(const uint8_t* data, int size) 191 | { 192 | DWORD bytes; 193 | 194 | if (_handle == INVALID_HANDLE_VALUE) 195 | return -1; 196 | 197 | if (!WriteFile(_handle, data, size, &bytes, NULL)) 198 | return -1; 199 | 200 | return bytes; 201 | } 202 | 203 | int 204 | WinSerialPort::get() 205 | { 206 | uint8_t val; 207 | DWORD bytes; 208 | 209 | if (_handle == INVALID_HANDLE_VALUE) 210 | return -1; 211 | 212 | if (!ReadFile(_handle, &val, 1, &bytes, NULL)) 213 | return -1; 214 | 215 | if (bytes != 1) 216 | return -1; 217 | 218 | return val; 219 | } 220 | 221 | int 222 | WinSerialPort::put(int c) 223 | { 224 | uint8_t val = c; 225 | DWORD bytes; 226 | 227 | if (_handle == INVALID_HANDLE_VALUE) 228 | return -1; 229 | 230 | if (!WriteFile(_handle, &val, 1, &bytes, NULL)) 231 | return -1; 232 | 233 | if (bytes != 1) 234 | return -1; 235 | 236 | return val; 237 | } 238 | 239 | void 240 | WinSerialPort::flush() 241 | { 242 | Sleep(1); 243 | } 244 | -------------------------------------------------------------------------------- /src/WinSerialPort.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _WINSERIALPORT_H 20 | #define _WINSERIALPORT_H 21 | 22 | #include "SerialPort.h" 23 | 24 | #include 25 | #include 26 | 27 | class WinSerialPort : public SerialPort 28 | { 29 | public: 30 | WinSerialPort(const std::string& name, bool isUsb); 31 | virtual ~WinSerialPort(); 32 | 33 | bool open(int baud = 115200, 34 | int data = 8, 35 | SerialPort::Parity parity = SerialPort::ParityNone, 36 | SerialPort::StopBit stop = SerialPort::StopBitOne); 37 | void close(); 38 | 39 | bool isUsb() { return _isUsb; }; 40 | 41 | int read(uint8_t* data, int size); 42 | int write(const uint8_t* data, int size); 43 | int get(); 44 | int put(int c); 45 | 46 | bool timeout(int millisecs); 47 | void flush(); 48 | 49 | private: 50 | HANDLE _handle; 51 | bool _isUsb; 52 | }; 53 | 54 | #endif // _WINSERIALPORT_H 55 | -------------------------------------------------------------------------------- /src/WordCopyApplet.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include "WordCopyApplet.h" 20 | 21 | WordCopyApplet::WordCopyApplet(Samba& samba, uint32_t addr) 22 | : Applet(samba, 23 | addr, 24 | applet.code, 25 | sizeof(applet.code), 26 | addr + applet.start, 27 | addr + applet.stack, 28 | addr + applet.reset) 29 | { 30 | } 31 | 32 | WordCopyApplet::~WordCopyApplet() 33 | { 34 | } 35 | 36 | void 37 | WordCopyApplet::setDstAddr(uint32_t dstAddr) 38 | { 39 | _samba.writeWord(_addr + applet.dst_addr, dstAddr); 40 | } 41 | 42 | void 43 | WordCopyApplet::setSrcAddr(uint32_t srcAddr) 44 | { 45 | _samba.writeWord(_addr + applet.src_addr, srcAddr); 46 | } 47 | 48 | void 49 | WordCopyApplet::setWords(uint32_t words) 50 | { 51 | _samba.writeWord(_addr + applet.words, words); 52 | } 53 | -------------------------------------------------------------------------------- /src/WordCopyApplet.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #ifndef _WORDCOPYAPPLET_H 20 | #define _WORDCOPYAPPLET_H 21 | 22 | #include "Applet.h" 23 | #include "WordCopyArm.h" 24 | 25 | class WordCopyApplet : public Applet 26 | { 27 | public: 28 | WordCopyApplet(Samba& samba, uint32_t addr); 29 | virtual ~WordCopyApplet(); 30 | 31 | void setDstAddr(uint32_t dstAddr); 32 | void setSrcAddr(uint32_t srcAddr); 33 | void setWords(uint32_t words); 34 | 35 | private: 36 | static WordCopyArm applet; 37 | }; 38 | 39 | #endif // _WORDCOPYAPPLET_H 40 | -------------------------------------------------------------------------------- /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/arm-dis/arm-dis.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARM_DIS_H 2 | #define _ARM_DIS_H 3 | 4 | #include 5 | 6 | int 7 | arm_dis_buf(unsigned char *b, int len, bfd_vma pc, int is_thumb, int little_code); 8 | 9 | #endif // _ARM_DIS_H 10 | 11 | -------------------------------------------------------------------------------- /src/arm-dis/floatformat.h: -------------------------------------------------------------------------------- 1 | /* IEEE floating point support declarations, for GDB, the GNU Debugger. 2 | Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2005, 2010 3 | Free Software Foundation, Inc. 4 | 5 | This file is part of GDB. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 20 | 21 | #if !defined (FLOATFORMAT_H) 22 | #define FLOATFORMAT_H 1 23 | 24 | #include "ansidecl.h" 25 | 26 | /* A floatformat consists of a sign bit, an exponent and a mantissa. Once the 27 | bytes are concatenated according to the byteorder flag, then each of those 28 | fields is contiguous. We number the bits with 0 being the most significant 29 | (i.e. BITS_BIG_ENDIAN type numbering), and specify which bits each field 30 | contains with the *_start and *_len fields. */ 31 | 32 | /* What is the order of the bytes? */ 33 | 34 | enum floatformat_byteorders { 35 | /* Standard little endian byte order. 36 | EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */ 37 | floatformat_little, 38 | 39 | /* Standard big endian byte order. 40 | EX: 1.2345678e10 => 42 06 fe e0 c5 80 00 00 */ 41 | floatformat_big, 42 | 43 | /* Little endian byte order but big endian word order. 44 | EX: 1.2345678e10 => e0 fe 06 42 00 00 80 c5 */ 45 | floatformat_littlebyte_bigword, 46 | 47 | /* VAX byte order. Little endian byte order with 16-bit words. The 48 | following example is an illustration of the byte order only; VAX 49 | doesn't have a fully IEEE compliant floating-point format. 50 | EX: 1.2345678e10 => 80 c5 00 00 06 42 e0 fe */ 51 | floatformat_vax 52 | }; 53 | 54 | enum floatformat_intbit { floatformat_intbit_yes, floatformat_intbit_no }; 55 | 56 | struct floatformat 57 | { 58 | enum floatformat_byteorders byteorder; 59 | unsigned int totalsize; /* Total size of number in bits */ 60 | 61 | /* Sign bit is always one bit long. 1 means negative, 0 means positive. */ 62 | unsigned int sign_start; 63 | 64 | unsigned int exp_start; 65 | unsigned int exp_len; 66 | /* Bias added to a "true" exponent to form the biased exponent. It 67 | is intentionally signed as, otherwize, -exp_bias can turn into a 68 | very large number (e.g., given the exp_bias of 0x3fff and a 64 69 | bit long, the equation (long)(1 - exp_bias) evaluates to 70 | 4294950914) instead of -16382). */ 71 | int exp_bias; 72 | /* Exponent value which indicates NaN. This is the actual value stored in 73 | the float, not adjusted by the exp_bias. This usually consists of all 74 | one bits. */ 75 | unsigned int exp_nan; 76 | 77 | unsigned int man_start; 78 | unsigned int man_len; 79 | 80 | /* Is the integer bit explicit or implicit? */ 81 | enum floatformat_intbit intbit; 82 | 83 | /* Internal name for debugging. */ 84 | const char *name; 85 | 86 | /* Validator method. */ 87 | int (*is_valid) (const struct floatformat *fmt, const void *from); 88 | 89 | /* Is the format actually the sum of two smaller floating point 90 | formats (IBM long double, as described in 91 | gcc/config/rs6000/darwin-ldouble-format)? If so, this is the 92 | smaller format in question, and the fields sign_start through 93 | intbit describe the first half. If not, this is NULL. */ 94 | const struct floatformat *split_half; 95 | }; 96 | 97 | /* floatformats for IEEE single and double, big and little endian. */ 98 | 99 | extern const struct floatformat floatformat_ieee_half_big; 100 | extern const struct floatformat floatformat_ieee_half_little; 101 | extern const struct floatformat floatformat_ieee_single_big; 102 | extern const struct floatformat floatformat_ieee_single_little; 103 | extern const struct floatformat floatformat_ieee_double_big; 104 | extern const struct floatformat floatformat_ieee_double_little; 105 | 106 | /* floatformat for ARM IEEE double, little endian bytes and big endian words */ 107 | 108 | extern const struct floatformat floatformat_ieee_double_littlebyte_bigword; 109 | 110 | /* floatformats for VAX. */ 111 | 112 | extern const struct floatformat floatformat_vax_f; 113 | extern const struct floatformat floatformat_vax_d; 114 | extern const struct floatformat floatformat_vax_g; 115 | 116 | /* floatformats for various extendeds. */ 117 | 118 | extern const struct floatformat floatformat_i387_ext; 119 | extern const struct floatformat floatformat_m68881_ext; 120 | extern const struct floatformat floatformat_i960_ext; 121 | extern const struct floatformat floatformat_m88110_ext; 122 | extern const struct floatformat floatformat_m88110_harris_ext; 123 | extern const struct floatformat floatformat_arm_ext_big; 124 | extern const struct floatformat floatformat_arm_ext_littlebyte_bigword; 125 | /* IA-64 Floating Point register spilt into memory. */ 126 | extern const struct floatformat floatformat_ia64_spill_big; 127 | extern const struct floatformat floatformat_ia64_spill_little; 128 | extern const struct floatformat floatformat_ia64_quad_big; 129 | extern const struct floatformat floatformat_ia64_quad_little; 130 | /* IBM long double (double+double). */ 131 | extern const struct floatformat floatformat_ibm_long_double; 132 | 133 | /* Convert from FMT to a double. 134 | FROM is the address of the extended float. 135 | Store the double in *TO. */ 136 | 137 | extern void 138 | floatformat_to_double (const struct floatformat *, const void *, double *); 139 | 140 | /* The converse: convert the double *FROM to FMT 141 | and store where TO points. */ 142 | 143 | extern void 144 | floatformat_from_double (const struct floatformat *, const double *, void *); 145 | 146 | /* Return non-zero iff the data at FROM is a valid number in format FMT. */ 147 | 148 | extern int 149 | floatformat_is_valid (const struct floatformat *fmt, const void *from); 150 | 151 | #endif /* defined (FLOATFORMAT_H) */ 152 | -------------------------------------------------------------------------------- /src/arm-dis/symcat.h: -------------------------------------------------------------------------------- 1 | /* Symbol concatenation utilities. 2 | 3 | Copyright (C) 1998, 2000, 2010 Free Software Foundation, Inc. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program; if not, write to the Free Software Foundation, Inc., 17 | 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 18 | 19 | #ifndef SYM_CAT_H 20 | #define SYM_CAT_H 21 | 22 | #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE) 23 | #define CONCAT2(a,b) a##b 24 | #define CONCAT3(a,b,c) a##b##c 25 | #define CONCAT4(a,b,c,d) a##b##c##d 26 | #define CONCAT5(a,b,c,d,e) a##b##c##d##e 27 | #define CONCAT6(a,b,c,d,e,f) a##b##c##d##e##f 28 | #define STRINGX(s) #s 29 | #else 30 | /* Note one should never pass extra whitespace to the CONCATn macros, 31 | e.g. CONCAT2(foo, bar) because traditonal C will keep the space between 32 | the two labels instead of concatenating them. Instead, make sure to 33 | write CONCAT2(foo,bar). */ 34 | #define CONCAT2(a,b) a/**/b 35 | #define CONCAT3(a,b,c) a/**/b/**/c 36 | #define CONCAT4(a,b,c,d) a/**/b/**/c/**/d 37 | #define CONCAT5(a,b,c,d,e) a/**/b/**/c/**/d/**/e 38 | #define CONCAT6(a,b,c,d,e,f) a/**/b/**/c/**/d/**/e/**/f 39 | #define STRINGX(s) "s" 40 | #endif 41 | 42 | #define XCONCAT2(a,b) CONCAT2(a,b) 43 | #define XCONCAT3(a,b,c) CONCAT3(a,b,c) 44 | #define XCONCAT4(a,b,c,d) CONCAT4(a,b,c,d) 45 | #define XCONCAT5(a,b,c,d,e) CONCAT5(a,b,c,d,e) 46 | #define XCONCAT6(a,b,c,d,e,f) CONCAT6(a,b,c,d,e,f) 47 | 48 | /* Note the layer of indirection here is typically used to allow 49 | stringification of the expansion of macros. I.e. "#define foo 50 | bar", "XSTRING(foo)", to yield "bar". Be aware that this only 51 | works for __STDC__, not for traditional C which will still resolve 52 | to "foo". */ 53 | #define XSTRING(s) STRINGX(s) 54 | 55 | #endif /* SYM_CAT_H */ 56 | -------------------------------------------------------------------------------- /src/arm-dis/sysdep.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define _(x) x 6 | -------------------------------------------------------------------------------- /src/bossac.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "CmdOpts.h" 26 | #include "Samba.h" 27 | #include "PortFactory.h" 28 | #include "FlashFactory.h" 29 | #include "Flasher.h" 30 | 31 | using namespace std; 32 | 33 | class BossaConfig 34 | { 35 | public: 36 | BossaConfig(); 37 | virtual ~BossaConfig() {} 38 | 39 | bool erase; 40 | bool write; 41 | bool read; 42 | bool verify; 43 | bool reset; 44 | bool port; 45 | bool boot; 46 | bool bor; 47 | bool bod; 48 | bool lock; 49 | bool unlock; 50 | bool security; 51 | bool info; 52 | bool debug; 53 | bool help; 54 | bool forceUsb; 55 | string forceUsbArg; 56 | 57 | int readArg; 58 | string portArg; 59 | int bootArg; 60 | int bodArg; 61 | int borArg; 62 | string lockArg; 63 | string unlockArg; 64 | }; 65 | 66 | BossaConfig::BossaConfig() 67 | { 68 | erase = false; 69 | write = false; 70 | read = false; 71 | verify = false; 72 | port = false; 73 | boot = false; 74 | bod = false; 75 | bor = false; 76 | lock = false; 77 | security = false; 78 | info = false; 79 | help = false; 80 | forceUsb = false; 81 | 82 | readArg = 0; 83 | bootArg = 1; 84 | bodArg = 1; 85 | borArg = 1; 86 | 87 | reset = false; 88 | } 89 | 90 | static BossaConfig config; 91 | static Option opts[] = 92 | { 93 | { 94 | 'e', "erase", &config.erase, 95 | { ArgNone }, 96 | "erase the entire flash" 97 | }, 98 | { 99 | 'w', "write", &config.write, 100 | { ArgNone }, 101 | "write FILE to the flash; accelerated when\n" 102 | "combined with erase option" 103 | }, 104 | { 105 | 'r', "read", &config.read, 106 | { ArgOptional, ArgInt, "SIZE", { &config.readArg } }, 107 | "read SIZE from flash and store in FILE;\n" 108 | "read entire flash if SIZE not specified" 109 | }, 110 | { 111 | 'v', "verify", &config.verify, 112 | { ArgNone }, 113 | "verify FILE matches flash contents" 114 | }, 115 | { 116 | 'p', "port", &config.port, 117 | { ArgRequired, ArgString, "PORT", { &config.portArg } }, 118 | "use serial PORT to communicate to device;\n" 119 | "default behavior is to auto-scan all serial ports" 120 | }, 121 | { 122 | 'b', "boot", &config.boot, 123 | { ArgOptional, ArgInt, "BOOL", { &config.bootArg } }, 124 | "boot from ROM if BOOL is 0;\n" 125 | "boot from FLASH if BOOL is 1 [default];\n" 126 | "option is ignored on unsupported devices" 127 | }, 128 | { 129 | 'c', "bod", &config.bod, 130 | { ArgOptional, ArgInt, "BOOL", { &config.bodArg } }, 131 | "no brownout detection if BOOL is 0;\n" 132 | "brownout detection is on if BOOL is 1 [default]" 133 | }, 134 | { 135 | 't', "bor", &config.bor, 136 | { ArgOptional, ArgInt, "BOOL", { &config.borArg } }, 137 | "no brownout reset if BOOL is 0;\n" 138 | "brownout reset is on if BOOL is 1 [default]" 139 | }, 140 | { 141 | 'l', "lock", &config.lock, 142 | { ArgOptional, ArgString, "REGION", { &config.lockArg } }, 143 | "lock the flash REGION as a comma-separated list;\n" 144 | "lock all if not given [default]" 145 | }, 146 | { 147 | 'u', "unlock", &config.unlock, 148 | { ArgOptional, ArgString, "REGION", { &config.unlockArg } }, 149 | "unlock the flash REGION as a comma-separated list;\n" 150 | "unlock all if not given [default]" 151 | }, 152 | { 153 | 's', "security", &config.security, 154 | { ArgNone }, 155 | "set the flash security flag" 156 | }, 157 | { 158 | 'i', "info", &config.info, 159 | { ArgNone }, 160 | "display device information" 161 | }, 162 | { 163 | 'd', "debug", &config.debug, 164 | { ArgNone }, 165 | "print debug messages" 166 | }, 167 | { 168 | 'h', "help", &config.help, 169 | { ArgNone }, 170 | "display this help text" 171 | }, 172 | { 173 | 'U', "force_usb_port", &config.forceUsb, 174 | { ArgRequired, ArgString, "true/false", { &config.forceUsbArg } }, 175 | "override USB port autodetection" 176 | }, 177 | { 178 | 'R', "reset", &config.reset, 179 | { ArgNone }, 180 | "reset CPU (if supported)" 181 | } 182 | }; 183 | 184 | bool 185 | autoScan(Samba& samba, PortFactory& portFactory, string& port) 186 | { 187 | for (port = portFactory.begin(); 188 | port != portFactory.end(); 189 | port = portFactory.next()) 190 | { 191 | if (config.debug) 192 | printf("Trying to connect on %s\n", port.c_str()); 193 | if (samba.connect(portFactory.create(port))) 194 | return true; 195 | } 196 | 197 | return false; 198 | } 199 | 200 | int 201 | help(const char* program) 202 | { 203 | fprintf(stderr, "Try '%s -h' or '%s --help' for more information\n", program, program); 204 | return 1; 205 | } 206 | 207 | int 208 | main(int argc, char* argv[]) 209 | { 210 | int args; 211 | char* pos; 212 | CmdOpts cmd(argc, argv, sizeof(opts) / sizeof(opts[0]), opts); 213 | 214 | if ((pos = strrchr(argv[0], '/')) || (pos = strrchr(argv[0], '\\'))) 215 | argv[0] = pos + 1; 216 | 217 | if (argc <= 1) 218 | { 219 | fprintf(stderr, "%s: you must specify at least one option\n", argv[0]); 220 | return help(argv[0]); 221 | } 222 | 223 | args = cmd.parse(); 224 | if (args < 0) 225 | return help(argv[0]); 226 | 227 | if (config.read && (config.write || config.verify)) 228 | { 229 | fprintf(stderr, "%s: read option is exclusive of write or verify\n", argv[0]); 230 | return help(argv[0]); 231 | } 232 | 233 | if (config.read || config.write || config.verify) 234 | { 235 | if (args == argc) 236 | { 237 | fprintf(stderr, "%s: missing file\n", argv[0]); 238 | return help(argv[0]); 239 | } 240 | argc--; 241 | } 242 | if (args != argc) 243 | { 244 | fprintf(stderr, "%s: extra arguments found\n", argv[0]); 245 | return help(argv[0]); 246 | } 247 | 248 | if (config.help) 249 | { 250 | printf("Usage: %s [OPTION...] [FILE]\n", argv[0]); 251 | printf("Basic Open Source SAM-BA Application (BOSSA) Version " VERSION "\n" 252 | "Flash programmer for Atmel SAM devices.\n" 253 | "Copyright (c) 2011-2012 ShumaTech (http://www.shumatech.com)\n" 254 | "\n" 255 | "Examples:\n" 256 | " bossac -e -w -v -b image.bin # Erase flash, write flash with image.bin,\n" 257 | " # verify the write, and set boot from flash\n" 258 | " bossac -r0x10000 image.bin # Read 64KB from flash and store in image.bin\n" 259 | ); 260 | printf("\nOptions:\n"); 261 | cmd.usage(stdout); 262 | printf("\nReport bugs to \n"); 263 | return 1; 264 | } 265 | 266 | try 267 | { 268 | Samba samba; 269 | PortFactory portFactory; 270 | FlashFactory flashFactory; 271 | 272 | if (config.debug) 273 | samba.setDebug(true); 274 | 275 | bool isUsb = false; 276 | if (config.forceUsb) 277 | { 278 | if (config.forceUsbArg.compare("true")==0) 279 | isUsb = true; 280 | else if (config.forceUsbArg.compare("false")==0) 281 | isUsb = false; 282 | else 283 | { 284 | fprintf(stderr, "Invalid USB value: %s\n", config.forceUsbArg.c_str()); 285 | return 1; 286 | } 287 | } 288 | 289 | if (config.port) 290 | { 291 | bool res; 292 | if (config.forceUsb) 293 | res = samba.connect(portFactory.create(config.portArg, isUsb)); 294 | else 295 | res = samba.connect(portFactory.create(config.portArg)); 296 | if (!res) 297 | { 298 | fprintf(stderr, "No device found on %s\n", config.portArg.c_str()); 299 | return 1; 300 | } 301 | } 302 | else 303 | { 304 | string port; 305 | if (!autoScan(samba, portFactory, port)) 306 | { 307 | fprintf(stderr, "Auto scan for device failed\n"); 308 | fprintf(stderr, "Try specifying a serial port with the '-p' option\n"); 309 | return 1; 310 | } 311 | printf("Device found on %s\n", port.c_str()); 312 | } 313 | 314 | uint32_t chipId = samba.chipId(); 315 | Flash::Ptr flash = flashFactory.create(samba, chipId); 316 | if (flash.get() == NULL) 317 | { 318 | fprintf(stderr, "Flash for chip ID %08x is not supported\n", chipId); 319 | return 1; 320 | } 321 | 322 | Flasher flasher(flash); 323 | 324 | if (config.unlock) 325 | flasher.lock(config.unlockArg, false); 326 | 327 | if (config.erase) 328 | flasher.erase(); 329 | 330 | if (config.write) 331 | flasher.write(argv[args]); 332 | 333 | if (config.verify) 334 | if (!flasher.verify(argv[args])) 335 | return 2; 336 | 337 | if (config.read) 338 | flasher.read(argv[args], config.readArg); 339 | 340 | if (config.boot) 341 | { 342 | printf("Set boot flash %s\n", config.bootArg ? "true" : "false"); 343 | flash->setBootFlash(config.bootArg); 344 | } 345 | 346 | if (config.bod) 347 | { 348 | printf("Set brownout detect %s\n", config.bodArg ? "true" : "false"); 349 | flash->setBod(config.bodArg); 350 | } 351 | 352 | if (config.bor) 353 | { 354 | printf("Set brownout reset %s\n", config.borArg ? "true" : "false"); 355 | flash->setBor(config.borArg); 356 | } 357 | 358 | if (config.security) 359 | { 360 | printf("Set security\n"); 361 | flash->setSecurity(); 362 | } 363 | 364 | if (config.lock) 365 | flasher.lock(config.lockArg, true); 366 | 367 | if (config.info) 368 | flasher.info(samba); 369 | 370 | if (config.reset) 371 | samba.reset(); 372 | } 373 | catch (exception& e) 374 | { 375 | fprintf(stderr, "\n%s\n", e.what()); 376 | return 1; 377 | } 378 | catch(...) 379 | { 380 | fprintf(stderr, "\nUnhandled exception\n"); 381 | return 1; 382 | } 383 | 384 | return 0; 385 | } 386 | 387 | -------------------------------------------------------------------------------- /src/bossash.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // BOSSA 3 | // 4 | // Copyright (C) 2011-2012 ShumaTech http://www.shumatech.com/ 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 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "Shell.h" 27 | 28 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 29 | 30 | static int 31 | split(char* str, char* tokv[], int tokn) 32 | { 33 | int tokc; 34 | 35 | for (tokc = 0; tokc < tokn - 1; tokc++) 36 | { 37 | while (*str && isspace(*str)) 38 | str++; 39 | 40 | if (!*str) 41 | break; 42 | 43 | tokv[tokc] = str; 44 | 45 | while (*str && !isspace(*str)) 46 | str++; 47 | 48 | if (*str) 49 | *str++ = '\0'; 50 | } 51 | 52 | if (*str) 53 | tokv[tokc++] = str; 54 | 55 | return tokc; 56 | } 57 | 58 | int 59 | main(int argc, char* argv[]) 60 | { 61 | char *input; 62 | char *str; 63 | char *tokv[5]; 64 | int tokc; 65 | char *expansion; 66 | int result; 67 | 68 | printf("Press Ctrl-D or enter \"exit\" to end session.\n" 69 | "Enter \"help\" to display a command list.\n"); 70 | 71 | using_history(); 72 | 73 | try 74 | { 75 | Shell shell; 76 | 77 | while (!shell.exitFlag()) 78 | { 79 | input = readline("bossa> "); 80 | if (!input) 81 | { 82 | printf("\n"); 83 | break; 84 | } 85 | 86 | for (str = input; *str && isspace(*str); str++); 87 | 88 | if (*str) 89 | { 90 | result = history_expand(input, &expansion); 91 | if (result >= 0 && result != 2) 92 | { 93 | add_history(expansion); 94 | tokc = split(expansion, tokv, ARRAY_SIZE(tokv)); 95 | shell.invoke(tokv, tokc); 96 | } 97 | free(expansion); 98 | } 99 | free(input); 100 | } 101 | } 102 | catch(...) 103 | { 104 | printf("\nUnhandled exception\n"); 105 | return 1; 106 | } 107 | 108 | return 0; 109 | } 110 | --------------------------------------------------------------------------------