forked from PAWPAW-Mirror/lib_xua
Merge branch 'feature/windows-dfu' into feature/fix-hid-compiler-errors
This commit is contained in:
@@ -526,21 +526,21 @@
|
||||
* @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number.
|
||||
*/
|
||||
#ifndef BCD_DEVICE_J
|
||||
#define BCD_DEVICE_J (0)
|
||||
#define BCD_DEVICE_J (1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number.
|
||||
*/
|
||||
#ifndef BCD_DEVICE_M
|
||||
#define BCD_DEVICE_M (1)
|
||||
#define BCD_DEVICE_M (2)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number.
|
||||
*/
|
||||
#ifndef BCD_DEVICE_N
|
||||
#define BCD_DEVICE_N (1)
|
||||
#define BCD_DEVICE_N (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
all:
|
||||
g++ -m32 -Wall -g -o xmosdfu xmosdfu.cpp -Ilibusb/Linux32 -lusb-1.0
|
||||
mkdir -p bin
|
||||
g++ -m32 -Wall -g -o bin/xmosdfu xmosdfu.cpp -Ilibusb/Linux32 -lusb-1.0
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
all:
|
||||
g++ -Wall -g -o xmosdfu xmosdfu.cpp -Ilibusb/Linux32 -lusb-1.0
|
||||
mkdir -p bin
|
||||
g++ -Wall -g -o bin/xmosdfu xmosdfu.cpp -Ilibusb/Linux32 -lusb-1.0
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
all:
|
||||
g++ -g -o xmosdfu xmosdfu.cpp -Ilibusb/OSX32 libusb/OSX32/libusb-1.0.0.dylib -m32 -Wall
|
||||
mkdir -p bin
|
||||
g++ -g -o bin/xmosdfu xmosdfu.cpp -Ilibusb/OSX32 libusb/OSX32/libusb-1.0.0.dylib -m32 -Wall
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
all:
|
||||
g++ -g -o xmosdfu xmosdfu.cpp -Ilibusb/OSX64 libusb/OSX64/libusb-1.0.0.dylib -Wall
|
||||
mkdir -p bin
|
||||
g++ -g -o bin/xmosdfu xmosdfu.cpp -Ilibusb/OSX64 libusb/OSX64/libusb-1.0.0.dylib -Wall
|
||||
|
||||
@@ -5,4 +5,5 @@
|
||||
# vendor and product IDs
|
||||
|
||||
xmosdfu: xmosdfu.cpp
|
||||
g++ -D_GNU_SOURCE -Wall -g -o xmosdfu -Ilibusb/Rasp -lusb-1.0 -x c xmosdfu.cpp -std=c99
|
||||
mkdir -p bin
|
||||
g++ -D_GNU_SOURCE -Wall -g -o bin/xmosdfu -Ilibusb/Rasp -lusb-1.0 -x c xmosdfu.cpp -std=c99
|
||||
|
||||
31
lib_xua/host/xmosdfu/Makefile.Win32
Normal file
31
lib_xua/host/xmosdfu/Makefile.Win32
Normal file
@@ -0,0 +1,31 @@
|
||||
# Build tested with Visual Studio 2017 command prompt
|
||||
#
|
||||
# Run: nmake /f Makefile.Win32
|
||||
#
|
||||
# NOTE: To run xmosdfu on Windows, libusbK drivers must be installed on the DFU endpoint
|
||||
# We recommend using the third-party Zadig tool for this.
|
||||
|
||||
COMMON_FLAGS = \
|
||||
/D BECLEAR_HOST=1 \
|
||||
/I libusb\Win32 \
|
||||
/nologo \
|
||||
/W4 \
|
||||
/WX- \
|
||||
/O2 \
|
||||
/EHa \
|
||||
/D _CRT_SECURE_NO_WARNINGS \
|
||||
xmosdfu.cpp \
|
||||
|
||||
all: xmosdfu
|
||||
|
||||
xmosdfu:
|
||||
if not exist bin mkdir bin
|
||||
CL.exe \
|
||||
$(COMMON_FLAGS) \
|
||||
/Fe"bin\xmosdfu.exe" \
|
||||
/link "libusb\Win32\libusb-1.0.lib""
|
||||
copy libusb-1.0.dll bin
|
||||
del *.obj
|
||||
|
||||
clean:
|
||||
rmdir /s /q bin
|
||||
BIN
lib_xua/host/xmosdfu/libusb-1.0.dll
Normal file
BIN
lib_xua/host/xmosdfu/libusb-1.0.dll
Normal file
Binary file not shown.
BIN
lib_xua/host/xmosdfu/libusb/Win32/libusb-1.0.lib
Normal file
BIN
lib_xua/host/xmosdfu/libusb/Win32/libusb-1.0.lib
Normal file
Binary file not shown.
2039
lib_xua/host/xmosdfu/libusb/Win32/libusb.h
Normal file
2039
lib_xua/host/xmosdfu/libusb/Win32/libusb.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -73,42 +73,42 @@ system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version
|
||||
|
||||
echo ""
|
||||
echo "*** DFU download new firmware 1 ***"
|
||||
$PROGDIR/xmosdfu $device_pid --download $update1
|
||||
$PROGDIR/bin/xmosdfu $device_pid --download $update1
|
||||
sleep 2
|
||||
echo "Version Read:"
|
||||
system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version
|
||||
|
||||
echo ""
|
||||
echo "*** DFU download new firmware 2 ***"
|
||||
$PROGDIR/xmosdfu $device_pid --download $update2
|
||||
$PROGDIR/bin/xmosdfu $device_pid --download $update2
|
||||
sleep 2
|
||||
echo "Version Read:"
|
||||
system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version
|
||||
|
||||
echo ""
|
||||
echo "*** DFU upload existing firmware ***"
|
||||
$PROGDIR/xmosdfu $device_pid --upload upload.bin
|
||||
$PROGDIR/bin/xmosdfu $device_pid --upload upload.bin
|
||||
sleep 2
|
||||
echo "Version Read:"
|
||||
system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version
|
||||
|
||||
echo ""
|
||||
echo "*** DFU revert to factory ***"
|
||||
$PROGDIR/xmosdfu $device_pid --revertfactory
|
||||
$PROGDIR/bin/xmosdfu $device_pid --revertfactory
|
||||
sleep 2
|
||||
echo "Version Read:"
|
||||
system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version
|
||||
|
||||
echo ""
|
||||
echo "*** DFU download uploaded firmware ***"
|
||||
$PROGDIR/xmosdfu $device_pid --download upload.bin
|
||||
$PROGDIR/bin/xmosdfu $device_pid --download upload.bin
|
||||
sleep 2
|
||||
echo "Version Read:"
|
||||
system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version
|
||||
|
||||
echo ""
|
||||
echo "*** DFU revert to factory ***"
|
||||
$PROGDIR/xmosdfu $device_pid --revertfactory
|
||||
$PROGDIR/bin/xmosdfu $device_pid --revertfactory
|
||||
sleep 2
|
||||
echo "Version Read:"
|
||||
system_profiler SPUSBDataType|grep -A10 "$device_grep_string" |grep Version
|
||||
|
||||
@@ -1,7 +1,28 @@
|
||||
// Copyright (c) 2012-2018, XMOS Ltd, All rights reserved
|
||||
// Copyright (c) 2012-2020, XMOS Ltd, All rights reserved
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
// Used for checking if a file is a directory
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
// Aliases for Windows
|
||||
#define stat _stat
|
||||
#define fstat _fstat
|
||||
#define fileno _fileno
|
||||
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
||||
void Sleep(unsigned milliseconds) {
|
||||
usleep(milliseconds * 1000);
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "libusb.h"
|
||||
|
||||
/* the device's vendor and product id */
|
||||
@@ -51,7 +72,7 @@ static int find_xmos_device(unsigned int id, unsigned int pid, unsigned int list
|
||||
libusb_device *dev;
|
||||
libusb_device **devs;
|
||||
int i = 0;
|
||||
int found = 0;
|
||||
unsigned int found = 0;
|
||||
|
||||
size_t count = libusb_get_device_list(NULL, &devs);
|
||||
if ((int)count < 0)
|
||||
@@ -195,7 +216,7 @@ int xmos_dfu_restore_state(unsigned int interface)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dfu_download(unsigned int interface, unsigned int block_num, unsigned int size, unsigned char *data)
|
||||
unsigned int dfu_download(unsigned int interface, unsigned int block_num, unsigned int size, unsigned char *data)
|
||||
{
|
||||
//printf("... Downloading block number %d size %d\r", block_num, size);
|
||||
/* Returns actual data size transferred */
|
||||
@@ -212,7 +233,7 @@ int dfu_upload(unsigned int interface, unsigned int block_num, unsigned int size
|
||||
|
||||
int write_dfu_image(char *file)
|
||||
{
|
||||
int i = 0;
|
||||
unsigned int i = 0;
|
||||
FILE* inFile = NULL;
|
||||
int image_size = 0;
|
||||
unsigned int num_blocks = 0;
|
||||
@@ -225,6 +246,7 @@ int write_dfu_image(char *file)
|
||||
unsigned int timeout = 0;
|
||||
unsigned char strIndex = 0;
|
||||
unsigned int dfuBlockCount = 0;
|
||||
struct stat statbuf;
|
||||
|
||||
inFile = fopen( file, "rb" );
|
||||
if( inFile == NULL )
|
||||
@@ -233,6 +255,19 @@ int write_dfu_image(char *file)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check if file is a directory */
|
||||
int status = fstat(fileno(inFile), &statbuf);
|
||||
if (status != 0)
|
||||
{
|
||||
fprintf(stderr,"Error: Failed to get info on file.\n");
|
||||
return -1;
|
||||
}
|
||||
if ( S_ISDIR(statbuf.st_mode) )
|
||||
{
|
||||
fprintf(stderr,"Error: Specified path is a directory.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Discover the size of the image. */
|
||||
if( 0 != fseek( inFile, 0, SEEK_END ) )
|
||||
{
|
||||
@@ -259,7 +294,7 @@ int write_dfu_image(char *file)
|
||||
{
|
||||
memset(block_data, 0x0, block_size);
|
||||
fread(block_data, 1, block_size, inFile);
|
||||
int transferred = dfu_download(0, dfuBlockCount, block_size, block_data);
|
||||
unsigned int transferred = dfu_download(0, dfuBlockCount, block_size, block_data);
|
||||
if(transferred != block_size)
|
||||
{
|
||||
/* Error */
|
||||
@@ -334,7 +369,7 @@ int read_dfu_image(char *file)
|
||||
|
||||
static void print_device_list(FILE *file, const char *indent)
|
||||
{
|
||||
for (int i = 0; i < sizeof(pidList)/sizeof(pidList[0]); i++)
|
||||
for (long unsigned int i = 0; i < sizeof(pidList)/sizeof(pidList[0]); i++)
|
||||
{
|
||||
fprintf(file, "%s%-30s (0x%0x)\n", indent, pidList[i].device_name, pidList[i].pid);
|
||||
}
|
||||
@@ -371,7 +406,7 @@ static unsigned int select_pid(char *device_pid)
|
||||
}
|
||||
|
||||
// Otherwise do a lookup of names
|
||||
for (int i = 0; i < sizeof(pidList)/sizeof(pidList[0]); i++)
|
||||
for (long unsigned int i = 0; i < sizeof(pidList)/sizeof(pidList[0]); i++)
|
||||
{
|
||||
if (strcmp(device_pid, pidList[i].device_name) == 0)
|
||||
{
|
||||
@@ -501,7 +536,7 @@ int main(int argc, char **argv)
|
||||
printf("Waiting for device to restart and enter DFU mode...\n");
|
||||
|
||||
// Wait for device to enter dfu mode and restart
|
||||
system("sleep 20");
|
||||
Sleep(20 * 1000);
|
||||
#endif
|
||||
|
||||
// NOW IN DFU APPLICATION MODE
|
||||
@@ -556,7 +591,7 @@ int main(int argc, char **argv)
|
||||
printf("... Reverting device to factory image\n");
|
||||
xmos_dfu_revertfactory();
|
||||
// Give device time to revert firmware
|
||||
system("sleep 2");
|
||||
Sleep(2 * 1000);
|
||||
xmos_dfu_resetfromdfu(XMOS_DFU_IF);
|
||||
}
|
||||
else
|
||||
@@ -572,5 +607,5 @@ int main(int argc, char **argv)
|
||||
libusb_close(devh);
|
||||
libusb_exit(NULL);
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
VERSION = 1.1.1
|
||||
VERSION = 1.2.0
|
||||
|
||||
DEPENDENT_MODULES = lib_logging(>=3.0.0) \
|
||||
lib_xassert(>=4.0.0) \
|
||||
|
||||
Reference in New Issue
Block a user