diff --git a/src/Makefile b/src/Makefile index 33f8580..1835630 100644 --- a/src/Makefile +++ b/src/Makefile @@ -663,9 +663,18 @@ hostmot2-objs := \ hal/drivers/mesa-hostmot2/raw.o \ hal/drivers/mesa-hostmot2/bitfile.o \ $(MATHSTUB) -hm2_7i43-objs := hal/drivers/mesa-hostmot2/hm2_7i43.o $(MATHSTUB) -hm2_pci-objs := hal/drivers/mesa-hostmot2/hm2_pci.o $(MATHSTUB) -hm2_test-objs := hal/drivers/mesa-hostmot2/hm2_test.o $(MATHSTUB) +hm2_7i43-objs := \ + hal/drivers/mesa-hostmot2/hm2_7i43.o \ + hal/drivers/mesa-hostmot2/bitfile.o \ + $(MATHSTUB) +hm2_pci-objs := \ + hal/drivers/mesa-hostmot2/hm2_pci.o \ + hal/drivers/mesa-hostmot2/bitfile.o \ + $(MATHSTUB) +hm2_test-objs := \ + hal/drivers/mesa-hostmot2/hm2_test.o \ + hal/drivers/mesa-hostmot2/bitfile.o \ + $(MATHSTUB) ifneq "$(filter 2.6.%, $(kernelvers))" "" obj-$(CONFIG_PROBE_PARPORT) += probe_parport.o diff --git a/src/hal/drivers/mesa-hostmot2/bitfile.c b/src/hal/drivers/mesa-hostmot2/bitfile.c index ac10300..5e98656 100644 --- a/src/hal/drivers/mesa-hostmot2/bitfile.c +++ b/src/hal/drivers/mesa-hostmot2/bitfile.c @@ -23,6 +23,8 @@ // +#include + #include "rtapi.h" #include "rtapi_app.h" #include "rtapi_string.h" @@ -94,6 +96,11 @@ static int bitfile_parse_and_verify_chunk(const struct firmware *fw, bitfile_t * tag = fw->data[*i]; (*i) ++; + if ((*i) > fw->size) { + HM2_PRINT_NO_LL("bitfile chunk '%c' size fell off the end!\n", tag); + return -ENODATA; + } + switch (tag) { case 'a': // Design name @@ -216,7 +223,7 @@ int bitfile_parse_and_verify(const struct firmware *fw, bitfile_t *bitfile) { // is based on the serial interface, and the data needs to be reversed // -static u8 bitfile_reverse_bits(u8 data) { +u8 bitfile_reverse_bits(u8 data) { static const u8 swaptab[256] = { 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, diff --git a/src/hal/drivers/mesa-hostmot2/bitfile.h b/src/hal/drivers/mesa-hostmot2/bitfile.h index 9ed664b..dd8db68 100644 --- a/src/hal/drivers/mesa-hostmot2/bitfile.h +++ b/src/hal/drivers/mesa-hostmot2/bitfile.h @@ -44,6 +44,7 @@ typedef struct { int bitfile_parse_and_verify(const struct firmware *fw, bitfile_t *bitfile); void bitfile_reverse_bits_of_chunk(bitfile_chunk_t *chunk); +u8 bitfile_reverse_bits(u8 data); diff --git a/src/hal/drivers/mesa-hostmot2/hm2_7i43.c b/src/hal/drivers/mesa-hostmot2/hm2_7i43.c index 3846556..95f65dd 100644 --- a/src/hal/drivers/mesa-hostmot2/hm2_7i43.c +++ b/src/hal/drivers/mesa-hostmot2/hm2_7i43.c @@ -27,6 +27,7 @@ #include "hal.h" +#include "hal/drivers/mesa-hostmot2/bitfile.h" #include "hal/drivers/mesa-hostmot2/hostmot2-lowlevel.h" #include "hal/drivers/mesa-hostmot2/hm2_7i43.h" @@ -282,12 +283,8 @@ int hm2_7i43_program_fpga(hm2_lowlevel_io_t *this, const bitfile_t *bitfile) { // select the CPLD's data address hm2_7i43_epp_addr8(0, board); - for (i = 0; i < (bitfile->e.size & ~0x3); i += 4, firmware += 4) { - hm2_7i43_epp_write32(*(u32 *)firmware, board); - } - - for (; i < bitfile->e.size; i ++, firmware ++) { - hm2_7i43_epp_write(*(u8 *)firmware, board); + for (i = 0; i < bitfile->e.size; i ++, firmware ++) { + hm2_7i43_epp_write(bitfile_reverse_bits(*(u8 *)firmware), board); } end_time = rtapi_get_time(); diff --git a/src/hal/drivers/mesa-hostmot2/hm2_pci.c b/src/hal/drivers/mesa-hostmot2/hm2_pci.c index 3ae6721..5465d09 100644 --- a/src/hal/drivers/mesa-hostmot2/hm2_pci.c +++ b/src/hal/drivers/mesa-hostmot2/hm2_pci.c @@ -26,6 +26,7 @@ #include "hal.h" +#include "bitfile.h" #include "hostmot2-lowlevel.h" #include "hm2_pci.h" @@ -175,7 +176,7 @@ static int hm2_plx9030_program_fpga(hm2_lowlevel_io_t *this, const bitfile_t *bi // program the FPGA for (i = 0; i < bitfile->e.size; i ++) { - outb(bitfile->e.data[i], board->data_base_addr); + outb(bitfile_reverse_bits(bitfile->e.data[i]), board->data_base_addr); } // all bytes transferred, make sure FPGA is all set up now diff --git a/src/hal/drivers/mesa-hostmot2/hostmot2.c b/src/hal/drivers/mesa-hostmot2/hostmot2.c index 18d7281..bc8fda3 100644 --- a/src/hal/drivers/mesa-hostmot2/hostmot2.c +++ b/src/hal/drivers/mesa-hostmot2/hostmot2.c @@ -908,8 +908,6 @@ int hm2_register(hm2_lowlevel_io_t *llio, char *config_string) { } } - bitfile_reverse_bits_of_chunk(&bitfile.e); - if (llio->reset != NULL) { r = llio->reset(llio); if (r != 0) {