Browse Source

Display a friendly error directing to README.FPGA when bitstream cannot be loaded

Luke Dashjr 12 years ago
parent
commit
0e32b080b9
3 changed files with 16 additions and 12 deletions
  1. 11 8
      fpgautils.c
  2. 3 2
      fpgautils.h
  3. 2 2
      libztex.c

+ 11 - 8
fpgautils.c

@@ -942,6 +942,12 @@ ssize_t _serial_read(int fd, char *buf, size_t bufsiz, char *eol)
 	buf[len] = '\0';  \
 } while(0)
 
+void _bitstream_not_found(const char *repr, const char *fn)
+{
+	applog(LOG_ERR, "ERROR: Unable to load '%s', required for %s to work!", fn, repr);
+	applog(LOG_ERR, "ERROR: Please read README.FPGA for instructions");
+}
+
 FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwfile, unsigned long *out_len)
 {
 	char buf[0x100];
@@ -952,10 +958,7 @@ FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwf
 	FILE *f = open_bitstream(dname, fwfile);
 	if (!f)
 	{
-		applog(LOG_ERR, "%s: Error opening bitstream file %s",
-		        repr, fwfile);
-		applog(LOG_ERR, "%s: Did you install the necessary bitstream package?",
-		       repr);
+		_bitstream_not_found(repr, fwfile);
 		return NULL;
 	}
 	if (1 != fread(buf, 2, 1, f))
@@ -1004,7 +1007,7 @@ FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwf
 	return f;
 }
 
-bool load_bitstream_intelhex(bytes_t *rv, const char *dname, const char *fn)
+bool load_bitstream_intelhex(bytes_t *rv, const char *dname, const char *repr, const char *fn)
 {
 	char buf[0x100];
 	size_t sz;
@@ -1062,7 +1065,7 @@ ihxerr:
 	return false;
 }
 
-bool load_bitstream_bytes(bytes_t *rv, const char *dname, const char *fileprefix)
+bool load_bitstream_bytes(bytes_t *rv, const char *dname, const char *repr, const char *fileprefix)
 {
 	FILE *F;
 	size_t fplen = strlen(fileprefix);
@@ -1092,12 +1095,12 @@ bool load_bitstream_bytes(bytes_t *rv, const char *dname, const char *fileprefix
 	}
 	
 	strcpy(&fnbuf[fplen], ".ihx");
-	if (load_bitstream_intelhex(rv, dname, fnbuf))
+	if (load_bitstream_intelhex(rv, dname, repr, fnbuf))
 		return true;
 	
 	// TODO: Xilinx
 	
-	applog(LOG_ERR, "Failed to load bitstream '%s'", fileprefix);
+	_bitstream_not_found(repr, fnbuf);
 	return false;
 }
 

+ 3 - 2
fpgautils.h

@@ -46,9 +46,10 @@ extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
 	_serial_read(fd, buf, bufsiz, &eol)
 #define serial_close(fd)  close(fd)
 
+extern void _bitstream_not_found(const char *repr, const char *fn);
 extern FILE *open_xilinx_bitstream(const char *dname, const char *repr, const char *fwfile, unsigned long *out_len);
-extern bool load_bitstream_intelhex(bytes_t *out, const char *dname, const char *fn);
-extern bool load_bitstream_bytes(bytes_t *out, const char *dname, const char *fileprefix);
+extern bool load_bitstream_intelhex(bytes_t *out, const char *dname, const char *repr, const char *fn);
+extern bool load_bitstream_bytes(bytes_t *out, const char *dname, const char *repr, const char *fileprefix);
 
 extern int get_serial_cts(int fd);
 extern bool valid_baud(int baud);

+ 2 - 2
libztex.c

@@ -218,7 +218,7 @@ static enum check_result libztex_checkDevice(struct libusb_device *dev)
 	applog(LOG_ERR, "Mining firmware filename: %s", firmware);
 
 	bytes_init(&bsdata);
-	if (!load_bitstream_bytes(&bsdata, "ztex", firmware))
+	if (!load_bitstream_bytes(&bsdata, "ztex", "ZTX *", firmware))
 		goto done;
 
 	// in buf[] is still the identifier of the dummy firmware
@@ -429,7 +429,7 @@ static int libztex_configureFpgaLS(struct libztex_device *ztex, const char* firm
 	for (tries = 10; tries > 0; tries--) {
 		fp = open_bitstream("ztex", firmware);
 		if (!fp) {
-			applog(LOG_ERR, "%"PRIpreprv": failed to read bitstream '%s'", repr, firmware);
+			_bitstream_not_found(repr, firmware);
 			return -2;
 		}