diff --git a/anyio.c b/anyio.c index 7cf96df..11378e4 100644 --- a/anyio.c +++ b/anyio.c @@ -205,7 +205,7 @@ board_t *anyio_get_dev(board_access_t *access, int board_number) { return NULL; } -int anyio_dev_write_flash(board_t *board, char *bitfile_name, int fallback_flag) { +int anyio_dev_write_flash(board_t *board, char *bitfile_name, int fallback_flag, int fix_boot_flag) { int ret; if (board == NULL) { @@ -217,7 +217,7 @@ int anyio_dev_write_flash(board_t *board, char *bitfile_name, int fallback_flag) if (fallback_flag == 1) { addr = FALLBACK_ADDRESS; } - ret = board->llio.write_flash(&(board->llio), bitfile_name, addr); + ret = board->llio.write_flash(&(board->llio), bitfile_name, addr, fix_boot_flag); } else { printf("ERROR: Board %s doesn't support flash writing.\n", board->llio.board_name); return -EINVAL; diff --git a/anyio.h b/anyio.h index b804e51..1cad7fe 100644 --- a/anyio.h +++ b/anyio.h @@ -29,7 +29,7 @@ int anyio_init(board_access_t *access); void anyio_cleanup(board_access_t *access); int anyio_find_dev(board_access_t *access); board_t *anyio_get_dev(board_access_t *access, int board_number); -int anyio_dev_write_flash(board_t *board, char *bitfile_name, int fallback_flag); +int anyio_dev_write_flash(board_t *board, char *bitfile_name, int fallback_flag, int fix_boot_flag); int anyio_dev_verify_flash(board_t *board, char *bitfile_name, int fallback_flag); int anyio_dev_program_fpga(board_t *board, char *bitfile_name); int anyio_dev_set_remote_ip(board_t *board, char *lbp16_set_ip_addr); diff --git a/eeprom.c b/eeprom.c index 40a86d9..bb04e39 100644 --- a/eeprom.c +++ b/eeprom.c @@ -149,7 +149,7 @@ int start_programming(llio_t *self, u32 start_address, int fsize) { return 0; } -int eeprom_write(llio_t *self, char *bitfile_name, u32 start_address) { +int eeprom_write(llio_t *self, char *bitfile_name, u32 start_address, int fix_boot_flag) { board_t *board = self->board; int bytesread, i; u32 eeprom_addr; @@ -184,15 +184,21 @@ int eeprom_write(llio_t *self, char *bitfile_name, u32 start_address) { // if board doesn't support fallback there is no boot block if (board->fallback_support == 1) { if (check_boot(self) == -1) { - write_boot(self); + if (fix_boot_flag) { + write_boot(self); + if (check_boot(self) == -1) { + printf("Failed to write valid boot sector\n"); + fclose(fp); + return -1; + } + } else { + printf("Error: BootSector is invalid\n"); + fclose(fp); + return -1; + } } else { printf("Boot sector OK\n"); } - if (check_boot(self) == -1) { - printf("Failed to write valid boot sector\n"); - fclose(fp); - return -1; - } } if (eeprom_access.start_programming(self, start_address, file_stat.st_size) == -1) { diff --git a/eeprom.h b/eeprom.h index 2ffc8fb..8adef37 100644 --- a/eeprom.h +++ b/eeprom.h @@ -55,7 +55,7 @@ char *eeprom_get_flash_type(u8 flash_id); u32 eeprom_calc_user_space(u8 flash_id); void eeprom_prepare_boot_block(u8 flash_id); int start_programming(llio_t *self, u32 start_address, int fsize); -int eeprom_write(llio_t *self, char *bitfile_name, u32 start_address); +int eeprom_write(llio_t *self, char *bitfile_name, u32 start_address, int fix_boot_flag); int eeprom_verify(llio_t *self, char *bitfile_name, u32 start_address); void eeprom_init(llio_t *self); void eeprom_cleanup(llio_t *self); diff --git a/eeprom_local.c b/eeprom_local.c index e7467c7..d13b809 100644 --- a/eeprom_local.c +++ b/eeprom_local.c @@ -419,10 +419,10 @@ static void done_programming(llio_t *self) { // global functions -int local_write_flash(llio_t *self, char *bitfile_name, u32 start_address) { +int local_write_flash(llio_t *self, char *bitfile_name, u32 start_address, int fix_boot_flag) { int ret; - ret = eeprom_write(self, bitfile_name, start_address); + ret = eeprom_write(self, bitfile_name, start_address, fix_boot_flag); done_programming(self); return ret; } diff --git a/eeprom_local.h b/eeprom_local.h index 36eceeb..62c5482 100644 --- a/eeprom_local.h +++ b/eeprom_local.h @@ -44,7 +44,7 @@ #define EPP_SPI_SREG_REG 0x7E u8 read_flash_id(llio_t *self); -int local_write_flash(llio_t *self, char *bitfile_name, u32 start_address); +int local_write_flash(llio_t *self, char *bitfile_name, u32 start_address, int fix_boot_flag); int local_verify_flash(llio_t *self, char *bitfile_name, u32 start_address); void open_spi_access_local(llio_t *self); void close_spi_access_local(llio_t *self); diff --git a/eeprom_remote.c b/eeprom_remote.c index b95700c..d003811 100644 --- a/eeprom_remote.c +++ b/eeprom_remote.c @@ -91,8 +91,8 @@ static int remote_start_programming(llio_t *self, u32 start_address, int fsize) // global functions -int remote_write_flash(llio_t *self, char *bitfile_name, u32 start_address) { - return eeprom_write(self, bitfile_name, start_address); +int remote_write_flash(llio_t *self, char *bitfile_name, u32 start_address, int fix_boot_flag) { + return eeprom_write(self, bitfile_name, start_address, fix_boot_flag); } int remote_verify_flash(llio_t *self, char *bitfile_name, u32 start_address) { diff --git a/eeprom_remote.h b/eeprom_remote.h index e2a1e99..2884d44 100644 --- a/eeprom_remote.h +++ b/eeprom_remote.h @@ -21,7 +21,7 @@ #include "hostmot2.h" -int remote_write_flash(llio_t *self, char *bitfile_name, u32 start_address); +int remote_write_flash(llio_t *self, char *bitfile_name, u32 start_address, int fix_boot_flag); int remote_verify_flash(llio_t *self, char *bitfile_name, u32 start_address); void open_spi_access_remote(llio_t *self); void close_spi_access_remote(llio_t *self); diff --git a/hostmot2.h b/hostmot2.h index 0dcbcc8..984f935 100644 --- a/hostmot2.h +++ b/hostmot2.h @@ -52,7 +52,7 @@ typedef struct { struct llio_struct { int (*read)(llio_t *self, u32 addr, void *buffer, int size); int (*write)(llio_t *self, u32 addr, void *buffer, int size); - int (*write_flash)(llio_t *self, char *bitfile_name, u32 start_address); + int (*write_flash)(llio_t *self, char *bitfile_name, u32 start_address, int fix_boot_flag); int (*verify_flash)(llio_t *self, char *bitfile_name, u32 start_address); int (*program_fpga)(llio_t *self, char *bitfile_name); int (*reset)(llio_t *self); diff --git a/mesaflash.c b/mesaflash.c index af66837..f528690 100644 --- a/mesaflash.c +++ b/mesaflash.c @@ -33,6 +33,7 @@ static int device_flag; static int addr_flag; static int addr_hi_flag; static int write_flag; +static int fix_boot_flag; static int verify_flag; static int fallback_flag; static int recover_flag; @@ -63,6 +64,7 @@ static struct option long_options[] = { {"addr", required_argument, 0, 'a'}, {"addr_hi", required_argument, 0, 'b'}, {"write", required_argument, 0, 'w'}, + {"fix-boot-block", no_argument, &fix_boot_flag, 1}, {"verify", required_argument, 0, 'v'}, {"fallback", no_argument, &fallback_flag, 1}, {"recover", no_argument, &recover_flag, 1}, @@ -122,6 +124,7 @@ void print_usage() { printf(" --verbose print detailed information while running commands\n"); printf("\nCommands:\n"); printf(" --write writes a standard bitfile 'filename' configuration to the userarea of the EEPROM (IMPORTANT! 'filename' must be VALID FPGA configuration file)\n"); + printf(" --fix-boot-block If a write operation does not detect a valid boot block, write one\n"); printf(" --verify verifies the EEPROM configuration against the bitfile 'filename'\n"); printf(" --program writes a standard bitfile 'filename' configuration to the FPGA (IMPORTANT! 'filename' must be VALID FPGA configuration file)\n"); printf(" --readhmid print hostmot2 configuration in PIN file format\n"); @@ -373,7 +376,7 @@ int main(int argc, char *argv[]) { } else if (set_flag == 1) { ret = anyio_dev_set_remote_ip(board, lbp16_set_ip_addr); } else if (write_flag == 1) { - ret = anyio_dev_write_flash(board, bitfile_name, fallback_flag); + ret = anyio_dev_write_flash(board, bitfile_name, fallback_flag, fix_boot_flag); if (ret == 0) { if (reload_flag == 1) {