Skip to content

Commit

Permalink
Version updated to 0.0.3
Browse files Browse the repository at this point in the history
flash_file() add 64bytes file size alignment(required for cmd_verify())
cmd_verify() fixed
Cleanup/removed unused include
  • Loading branch information
bvernoux committed Jul 17, 2022
1 parent eac9a4b commit f4361f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
7 changes: 0 additions & 7 deletions How_To_Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ GitHub Workflows / CI Build is available on [Build.yml](.github/workflows/Build.
`sudo apt install pkg-config gcc libusb-1.0-0-dev`
#### Automatic build (using Makefile)
`make`
#### Manual build
`gcc -Wall -O3 -I/usr/include/libusb-1.0 -o wch-isp wch-isp.c -lusb-1.0 -DVERSION=\"0.0.2\"`

### Windows MSYS2/mingw64
#### Prerequisites
Expand All @@ -20,8 +18,3 @@ GitHub Workflows / CI Build is available on [Build.yml](.github/workflows/Build.
`ming32-make.exe`
- Optional copy libusb-1.0.dll to same directory as the executable(if it is not in your path)
- `cp /mingw64/bin/libusb-1.0.dll ./`
#### Manual build
`gcc -Wall -O3 -L/mingw64/lib -I/mingw64/include/libusb-1.0 -o wch-isp.exe wch-isp.c -lusb-1.0 -DVERSION=\"0.0.2\"`
- Optional copy libusb-1.0.dll to same directory as the executable(if it is not in your path)
- `cp /mingw64/bin/libusb-1.0.dll ./`

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
VERSION = 0.0.2
VERSION = 0.0.3

# Install paths
PREFIX = /usr/local
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This utility has only be tested on the CH32V103 & CH569W but should work on othe
- ##### Description:
- `Create Flash Image BIN`

### Driver installation for Windows:
### Driver installation for Windows
- Run Zadig (executable can be found on https://zadig.akeo.ie/)
- Install or Reinstall driver for "USB Module" (with USB ID `4348` `55E0`) with `libusb-win32 (v1.2.6.0)`
- Note: After 10s without any activity the device "USB Module" (with USB ID `4348` `55E0`) will disappear as the bootloader timeout so it shall be restarted
Expand Down
29 changes: 10 additions & 19 deletions wch-isp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@

#include <fcntl.h>

#ifndef __WIN32__
#include <sys/mman.h>
#include <sys/stat.h>
#endif

static void usage(void);
#include "arg.h"

Expand Down Expand Up @@ -398,16 +393,9 @@ cmd_verify(uint32_t addr, size_t len, const u8 *data, const u8 key[8])
isp_send_cmd(CMD_VERIFY, len + 5, unk);
isp_recv_cmd(CMD_VERIFY, sizeof(rsp), rsp);

if(bootloader_ver == BTVER_02_70)
{
if (rsp[1] != 0)
die("Fail to verify chunk @ %#x error(rsp[1] != 0): %.2x %.2x (len=%lld)\n", addr, rsp[0], rsp[1], len);
}
else
{
if (rsp[0] != 0 || rsp[1] != 0)
die("Fail to verify chunk @ %#x error: %.2x %.2x (len=%lld)\n", addr, rsp[0], rsp[1], len);
}
if (rsp[0] != 0 || rsp[1] != 0)
die("Fail to verify chunk @ %#x error: %.2x %.2x (len=%lld)\n", addr, rsp[0], rsp[1], len);

return len;
}

Expand Down Expand Up @@ -698,6 +686,7 @@ static void
flash_file(const char *name)
{
size_t size;
size_t size_align;
void *bin;
FILE *fp;
size_t ret;
Expand All @@ -707,12 +696,14 @@ flash_file(const char *name)
die("%s: %s\n", name, strerror(errno));

size = f_size(fp);
bin = malloc(size);
size_align = ALIGN(size, 64);
bin = malloc(size_align);
if (bin == NULL)
{
fclose(fp);
die("flash_file Memory error\n");
}
memset(bin, 0, size_align);
// Copy the file into the buffer bin
ret = fread(bin, 1, size, fp);
if (ret != size)
Expand All @@ -721,10 +712,10 @@ flash_file(const char *name)
die("flash_file reading error\n");
}
printf_timing("Flash file: %s\n", name);
printf_timing("File length: %lld\n", size);
isp_flash(size, bin);
printf_timing("File length: %lld (size aligned: %lld)\n", size, size_align);
isp_flash(size_align, bin);
if (do_verify)
isp_verify(size, bin);
isp_verify(size_align, bin);

free(bin);
fclose(fp);
Expand Down

0 comments on commit f4361f7

Please sign in to comment.