Remove compile errors/warnings and document compile/usage in FPGA-README
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
diff --git a/FPGA-README b/FPGA-README
index 6526031..137bcad 100644
--- a/FPGA-README
+++ b/FPGA-README
@@ -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
diff --git a/bitforce-firmware-flash.c b/bitforce-firmware-flash.c
index fff27e4..b4f6aca 100644
--- a/bitforce-firmware-flash.c
+++ b/bitforce-firmware-flash.c
@@ -18,9 +18,9 @@
#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; \
} \
@@ -28,13 +28,14 @@
#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);
@@ -79,15 +80,14 @@ 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");
@@ -95,12 +95,14 @@ main(int argc, char**argv) {
}
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;
}