Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Remove compile errors/warnings and document compile/usage in FPGA-README
Browse files Browse the repository at this point in the history
  • Loading branch information
kanoi committed Aug 23, 2012
1 parent 87f8b15 commit 6bf04bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions FPGA-README
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ C source is included for a bitforce firmware flash utility on Linux only:
bitforce-firmware-flash.c
Using this, you can change the bitstream firmware on bitforce singles.
It is untested with other devices. Use at your own risk!
To compile:
make bitforce-firmware-flash
To run, specify the BFL port and the flash file e.g.:
./bitforce-firmware-flash /dev/ttyUSB0 alphaminer_832.bfl
It takes a bit under 3 minutes to flash a BFL and shows a progress % counter


Icarus
Expand Down
30 changes: 16 additions & 14 deletions bitforce-firmware-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@
#define BFL_FILE_MAGIC "BFLDATA"
#define BFL_UPLOAD_MAGIC "NGH-STREAM"

#define myassert(expr, n, ...) do { \
if (!(expr)) \
{ \
#define myassert(expr, n, ...) \
do { \
if (!(expr)) { \
fprintf(stderr, __VA_ARGS__); \
return n; \
} \
} while(0)

#define ERRRESP(buf) buf, (buf[strlen(buf)-1] == '\n' ? "" : "\n")

#define WAITFOROK(n, msg) do { \
#define WAITFOROK(n, msg) \
do { \
myassert(fgets(buf, sizeof(buf), BFL), n, "Error reading response from " msg "\n"); \
myassert(!strcmp(buf, "OK\n"), n, "Invalid response from " msg ": %s%s", ERRRESP(buf)); \
} while(0)

int
main(int argc, char**argv) {
int main(int argc, char**argv)
{
myassert(argc == 3, 1, "Usage: %s <serialdev> <firmware.bfl>\n", argv[0]);
setbuf(stdout, NULL);

Expand Down Expand Up @@ -79,28 +80,29 @@ main(int argc, char**argv) {
printf("OK, sending...\n");

// Actual firmware upload
for (long i = 0, j = 0; i < FWlen; ++i)
{
long i, j;
for (i = 0, j = 0; i < FWlen; ++i) {
myassert(1 == fread(&n8, sizeof(n8), 1, FW), 0x30, "Error reading data from firmware file\n");
if (5 == i % 6)
continue;
n8 ^= 0x2f;
myassert(1 == fwrite(&n8, sizeof(n8), 1, BFL), 0x31, "Error sending data to device\n");
if (!(++j % 0x400))
{
if (!(++j % 0x400)) {
myassert(1 == fwrite(">>>>>>>>", 8, 1, BFL), 0x32, "Error sending block-finish to device\n");
printf("\r%5.2f%% complete", (double)i * 100. / (double)FWlen);
WAITFOROK(0x32, "block-finish");
}
}
printf("\r100%% complete :)\n");
myassert(1 == fwrite(">>>>>>>>", 8, 1, BFL), 0x3f, "Error sending upload-finished to device\n");
myassert(fgets(buf, sizeof(buf), BFL), 0x3f, "Error reading response from upload-finished\n"); \
myassert(!strcmp(buf, "DONE\n"), 0x3f, "Invalid response from upload-finished: %s%s", ERRRESP(buf)); \
myassert(fgets(buf, sizeof(buf), BFL), 0x3f, "Error reading response from upload-finished\n");
myassert(!strcmp(buf, "DONE\n"), 0x3f, "Invalid response from upload-finished: %s%s", ERRRESP(buf));

// ZBX: Finish programming
printf("Waiting for device... ");
myassert(1 == fwrite("ZBX", 3, 1, BFL), 0x40, "Failed to issue ZBX command\n");
WAITFOROK(0x40, "ZBX");
printf("ALL DONE!\n");
printf("All done! Try mining to test the flash succeeded.\n");

return 0;
}

0 comments on commit 6bf04bc

Please sign in to comment.