Merge pull request #73 from oscarbailey-xmos/feature/windows-dfu

Update xmosdfu
This commit is contained in:
oscarbailey-xmos
2020-12-02 10:24:30 +00:00
committed by GitHub
18 changed files with 2200 additions and 29 deletions

View File

@@ -1,6 +1,13 @@
lib_xua Change Log
==================
1.2.0
-----
* ADDED: Makefile.Win32 for xmosdfu on Windows
* FIXED: Bump default BCD device number to v1.2.0
* FIXED: xmosdfu now fails with an error when given a directory (#119)
1.1.1
-----

36
Jenkinsfile vendored
View File

@@ -84,6 +84,42 @@ pipeline {
}
}
}
stage('Build Pi host app') {
agent {
label 'pi'
}
steps {
dir("${REPO}") {
checkout scm
dir("${REPO}/host/xmosdfu") {
sh 'make -f Makefile.Pi'
}
}
}
post {
cleanup {
xcoreCleanSandbox()
}
}
}
stage('Build Windows host app') {
agent {
label 'x86_64&&windows'
}
steps {
dir("${REPO}") {
checkout scm
dir("${REPO}/host/xmosdfu") {
runVS('nmake /f Makefile.Win32')
}
}
}
post {
cleanup {
xcoreCleanSandbox()
}
}
}
}
}
stage('Update') {

View File

@@ -1,6 +1,6 @@
Software Release License Agreement
Copyright (c) 2017-2018, XMOS, All rights reserved.
Copyright (c) 2017-2020, XMOS, All rights reserved.
BY ACCESSING, USING, INSTALLING OR DOWNLOADING THE XMOS SOFTWARE, YOU AGREE TO BE BOUND BY THE FOLLOWING TERMS. IF YOU DO NOT AGREE TO THESE, DO NOT ATTEMPT TO DOWNLOAD, ACCESS OR USE THE XMOS Software.

View File

@@ -39,3 +39,18 @@ Raspberry Pi
A makefile is provided for Raspbian. libusb is required and can be installed using the ``apt-get`` command from previous Linux section.
.. literalinclude:: Makefile.Pi
Windows
-------
To build on Windows, you must first install Visual Studio 2019 Build Tools with
C++ support. `This is available from Microsoft's website. <https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019>`_
To build, open a Developer Command Prompt via the start menu and navigate to the
xmosdfu folder. The command to build is as follows:
``nmake /f Makefile.Win32``
This Makefile contains the following:
.. literalinclude:: Makefile.Win32

View File

@@ -4,6 +4,9 @@ Using the DFU loader - macOS (via the XMOS DFU loader)
The XMOS DFU loader is provided as source as part of the XMOS USB Audio software
framework, see :ref:`usb_audiosec_building_xmos_dfu`.
NOTE: Windows requires the installation of libusbK drivers on the DFU endpoint.
We recommend using `Zadig <https://zadig.akeo.ie/>`_.
Set up the image loader
-----------------------
@@ -18,7 +21,7 @@ Download new firmware
To program the new firmware run the command:
``./xmosdfu XMOS_L2_AUDIO2_PID --download new_firmware.bin``
``./bin/xmosdfu XMOS_L2_AUDIO2_PID --download new_firmware.bin``
Replace ``XMOS_L2_AUDIO2_PID`` with product ID of your target device. Invoke
``xmosdfu`` with no arguments to get a list of all supported product IDs.
@@ -35,7 +38,7 @@ present.
Run the command:
``./xmosdfu XMOS_L2_AUDIO2_PID --upload currentfirmware.bin``
``./bin/xmosdfu XMOS_L2_AUDIO2_PID --upload currentfirmware.bin``
The file ``currentfirmware.bin`` contains the latest upgrade image. This file is
an exact copy of the data from the flash and can be downloaded to the device
@@ -47,6 +50,6 @@ Reverting firmware to factory image
To revert the device back to its factory (i.e XFLASH) installed state from the
new firmware, run the command:
``./xmosdfu XMOS_L2_AUDIO2_PID --revertfactory``
``./bin/xmosdfu XMOS_L2_AUDIO2_PID --revertfactory``
The device will now be running, and only contain the factory firmware.

View File

@@ -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
/**

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -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

View File

@@ -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;
}

View File

@@ -1,4 +1,4 @@
VERSION = 1.1.1
VERSION = 1.2.0
DEPENDENT_MODULES = lib_logging(>=3.0.0) \
lib_xassert(>=4.0.0) \