Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 64-bit Windows builds of Bossa and bossac using Visual Studio 2019 #160

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ tags
*.bak
install/*.crt
install/*.p12

# Extras for building with MSVC
x64/
ipch/
*.sdf
*.suo
*.user
*.filters
*.unsuccessfulbuild
*.cache
*.lastbuildstate
43 changes: 43 additions & 0 deletions Bossa.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32002.261
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Bossa", "Bossa.vcxproj", "{51FD357A-201B-79B1-66FC-17DB8D3027E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
bossac-Debug|Win32 = bossac-Debug|Win32
bossac-Debug|x64 = bossac-Debug|x64
bossac-Release|Win32 = bossac-Release|Win32
bossac-Release|x64 = bossac-Release|x64
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.bossac-Debug|Win32.ActiveCfg = bossac-Debug|Win32
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.bossac-Debug|Win32.Build.0 = bossac-Debug|Win32
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.bossac-Debug|x64.ActiveCfg = bossac-Debug|x64
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.bossac-Debug|x64.Build.0 = bossac-Debug|x64
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.bossac-Release|Win32.ActiveCfg = bossac-Release|Win32
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.bossac-Release|Win32.Build.0 = bossac-Release|Win32
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.bossac-Release|x64.ActiveCfg = bossac-Release|x64
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.bossac-Release|x64.Build.0 = bossac-Release|x64
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.Debug|Win32.ActiveCfg = Debug|Win32
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.Debug|Win32.Build.0 = Debug|Win32
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.Debug|x64.ActiveCfg = Debug|x64
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.Debug|x64.Build.0 = Debug|x64
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.Release|Win32.ActiveCfg = Release|Win32
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.Release|Win32.Build.0 = Release|Win32
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.Release|x64.ActiveCfg = Release|x64
{51FD357A-201B-79B1-66FC-17DB8D3027E6}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B309DC9E-03CE-4FAD-9EE3-8AC9318C2FF8}
EndGlobalSection
EndGlobal
383 changes: 383 additions & 0 deletions Bossa.vcxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/BossaForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ ProgressDialog::ProgressDialog( wxWindow* parent, wxWindowID id, const wxString&

_infoStaticText = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
_infoStaticText->Wrap( -1 );
_progressBoxSizer->Add( _infoStaticText, 0, wxALIGN_CENTER|wxALL|wxEXPAND, 5 );
_progressBoxSizer->Add( _infoStaticText, 0, wxALL|wxEXPAND, 5 ); // DC do not use wxALIGN_CENTER with wxEXPAND, it triggers an assertion failure in wxWidgets

_statusGauge = new wxGauge( this, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL );
_statusGauge->SetValue( 0 );
Expand Down
4 changes: 4 additions & 0 deletions src/BossaWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include <string>
#include <algorithm>

#if defined(_WIN32) || defined(_WIN64)
#define F_OK 0 // test file for existence only when calling access()
#define access(...) _access(__VA_ARGS__)
#endif

using namespace std;

Expand Down
9 changes: 5 additions & 4 deletions src/CmdOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <getopt.h>
#include <string.h>
#include <assert.h>
#include <vector>

#include "CmdOpts.h"

Expand Down Expand Up @@ -83,9 +84,9 @@ CmdOpts::usage(FILE* out)
int
CmdOpts::parse()
{
struct option long_opts[_numOpts + 1];
char optstring[_numOpts * 3 + 1];
char* optPtr = optstring;
std::vector<option> long_opts(_numOpts + 1);
std::vector<char> optstring(_numOpts * 3 + 1);
char* optPtr = optstring.data();
int optIdx;
int rc;

Expand Down Expand Up @@ -118,7 +119,7 @@ CmdOpts::parse()
memset(&long_opts[_numOpts], 0, sizeof(long_opts[_numOpts]));
*optPtr = '\0';
optIdx = 0;
while ((rc = getopt_long(_argc, _argv, optstring, long_opts, &optIdx)) != -1)
while ((rc = getopt_long(_argc, _argv, optstring.data(), long_opts.data(), &optIdx)) != -1)
{
if (rc == '?')
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ Device::reset()
break;
}
}
catch (std::exception& expected)
catch (const std::exception&)
{ // writeWord will most likely throw an exception when the CPU is reset
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/Flasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,34 +112,34 @@ Flasher::write(const char* filename, uint32_t foffset)
{
uint32_t offset = 0;
uint32_t bufferSize = _samba.writeBufferSize();
uint8_t buffer[bufferSize];
std::vector<uint8_t> buffer(bufferSize);

while ((fbytes = fread(buffer, 1, bufferSize, infile)) > 0)
while ((fbytes = fread(buffer.data(), 1, bufferSize, infile)) > 0)
{
_observer.onProgress(offset / pageSize, numPages);

if (fbytes < bufferSize)
{
memset(buffer + fbytes, 0, bufferSize - fbytes);
memset(buffer.data() + fbytes, 0, bufferSize - fbytes);
fbytes = (fbytes + pageSize - 1) / pageSize * pageSize;
}

_flash->loadBuffer(buffer, fbytes);
_flash->writeBuffer(foffset + offset, fbytes);
offset += fbytes;
_flash->loadBuffer(buffer.data(), (uint16_t)fbytes);
_flash->writeBuffer(foffset + offset, (uint32_t)fbytes);
offset += (uint32_t)fbytes;
}

}
else
{
uint8_t buffer[pageSize];
std::vector<uint8_t> buffer(pageSize);
uint32_t pageOffset = foffset / pageSize;

while ((fbytes = fread(buffer, 1, pageSize, infile)) > 0)
while ((fbytes = fread(buffer.data(), 1, pageSize, infile)) > 0)
{
_observer.onProgress(pageNum, numPages);

_flash->loadBuffer(buffer, fbytes);
_flash->loadBuffer(buffer.data(), (uint16_t)fbytes);
_flash->writePage(pageOffset + pageNum);

pageNum++;
Expand All @@ -164,8 +164,8 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError
{
FILE* infile;
uint32_t pageSize = _flash->pageSize();
uint8_t bufferA[pageSize];
uint8_t bufferB[pageSize];
std::vector<uint8_t> bufferA(pageSize);
std::vector<uint8_t> bufferB(pageSize);
uint32_t pageNum = 0;
uint32_t numPages;
uint32_t pageOffset;
Expand Down Expand Up @@ -199,7 +199,7 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError

_observer.onStatus("Verify %ld bytes of flash\n", fsize);

while ((fbytes = fread(bufferA, 1, pageSize, infile)) > 0)
while ((fbytes = fread(bufferA.data(), 1, pageSize, infile)) > 0)
{
byteErrors = 0;

Expand All @@ -211,11 +211,11 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError
for (uint32_t i = 0; i < fbytes; i++)
calcCrc = _samba.checksumCalc(bufferA[i], calcCrc);

flashCrc = _samba.checksumBuffer((pageOffset + pageNum) * pageSize, fbytes);
flashCrc = _samba.checksumBuffer((pageOffset + pageNum) * pageSize, (uint32_t)fbytes);

if (flashCrc != calcCrc)
{
_flash->readPage(pageOffset + pageNum, bufferB);
_flash->readPage(pageOffset + pageNum, bufferB.data());

for (uint32_t i = 0; i < fbytes; i++)
{
Expand All @@ -226,7 +226,7 @@ Flasher::verify(const char* filename, uint32_t& pageErrors, uint32_t& totalError
}
else
{
_flash->readPage(pageOffset + pageNum, bufferB);
_flash->readPage(pageOffset + pageNum, bufferB.data());

for (uint32_t i = 0; i < fbytes; i++)
{
Expand Down Expand Up @@ -267,7 +267,7 @@ Flasher::read(const char* filename, uint32_t fsize, uint32_t foffset)
{
FILE* outfile;
uint32_t pageSize = _flash->pageSize();
uint8_t buffer[pageSize];
std::vector<uint8_t> buffer(pageSize);
uint32_t pageNum = 0;
uint32_t pageOffset;
uint32_t numPages;
Expand Down Expand Up @@ -297,11 +297,11 @@ Flasher::read(const char* filename, uint32_t fsize, uint32_t foffset)
{
_observer.onProgress(pageNum, numPages);

_flash->readPage(pageOffset + pageNum, buffer);
_flash->readPage(pageOffset + pageNum, buffer.data());

if (pageNum == numPages - 1 && fsize % pageSize > 0)
pageSize = fsize % pageSize;
fbytes = fwrite(buffer, 1, pageSize, outfile);
fbytes = fwrite(buffer.data(), 1, pageSize, outfile);
if (fbytes != pageSize)
throw FileShortError();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PortFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PortFactoryBase
virtual SerialPort::Ptr create(const std::string& name, bool isUsb) = 0;
};

#if defined(__WIN32__)
#if defined(__WIN32__) || defined(_WIN64)
#include "WinPortFactory.h"
typedef WinPortFactory PortFactory;
#elif defined(__linux__)
Expand Down
4 changes: 3 additions & 1 deletion src/Samba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ using namespace std;
#define TIMEOUT_NORMAL 1000
#define TIMEOUT_LONG 5000

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif

Samba::Samba() :
_canChipErase(false),
Expand Down Expand Up @@ -106,7 +108,7 @@ Samba::init()
{
ver = version();
}
catch(SambaError& err)
catch(const SambaError&)
{
return false;
}
Expand Down
7 changes: 4 additions & 3 deletions src/WinPortFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
///////////////////////////////////////////////////////////////////////////////
#include "WinPortFactory.h"
#include "WinSerialPort.h"
#include <vector>

#define USB_DEVICE_NAME "\\Device\\USB"

Expand Down Expand Up @@ -102,14 +103,14 @@ WinPortFactory::begin()
if (size < 1)
return error();

GUID guids[size];
std::vector<GUID> guids(size);

if (!SetupDiClassGuidsFromNameA("Ports", guids, size * sizeof(GUID), &size))
if (!SetupDiClassGuidsFromNameA("Ports", guids.data(), size * sizeof(GUID), &size))
{
return error();
}

_devInfo = SetupDiGetClassDevs(guids, NULL, NULL, DIGCF_PRESENT);
_devInfo = SetupDiGetClassDevs(guids.data(), NULL, NULL, DIGCF_PRESENT);
if(_devInfo == INVALID_HANDLE_VALUE)
return error();

Expand Down
2 changes: 1 addition & 1 deletion src/WinPortFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class WinPortFactory : public PortFactoryBase
SerialPort::Ptr create(const std::string& name, bool isUsb);

private:
typedef DWORD WINAPI (*CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, ::PHKEY, DWORD);
typedef DWORD (WINAPI *CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, ::PHKEY, DWORD) ;

HDEVINFO _devInfo;
HINSTANCE _cfgMgr;
Expand Down
8 changes: 4 additions & 4 deletions src/bossac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ timer_stop()
{
struct timeval end;
gettimeofday(&end, NULL);
return (end.tv_sec - start_time.tv_sec) + (end.tv_usec - start_time.tv_usec) / 1000000.0;
return (float)((end.tv_sec - start_time.tv_sec) + (end.tv_usec - start_time.tv_usec) / 1000000.0);
}

int
Expand Down Expand Up @@ -464,19 +464,19 @@ main(int argc, char* argv[])
if (config.boot)
{
printf("Set boot flash %s\n", config.bootArg ? "true" : "false");
flash->setBootFlash(config.bootArg);
flash->setBootFlash(config.bootArg != 0);
}

if (config.bod)
{
printf("Set brownout detect %s\n", config.bodArg ? "true" : "false");
flash->setBod(config.bodArg);
flash->setBod(config.bodArg != 0);
}

if (config.bor)
{
printf("Set brownout reset %s\n", config.borArg ? "true" : "false");
flash->setBor(config.borArg);
flash->setBor(config.borArg != 0);
}

if (config.security)
Expand Down
Loading