devices: simplify write RAM/Flash

This commit is contained in:
Gwenhael Goavec-Merou 2021-02-18 21:09:34 +01:00
parent 48e65fa0ad
commit 5f9a8835da
10 changed files with 37 additions and 37 deletions

View File

@ -34,15 +34,14 @@
#define IRLENGTH 8
Anlogic::Anlogic(Jtag *jtag, const std::string &filename,
bool flash_wr, bool sram_wr, int8_t verbose):
Device::prog_type_t prg_type, int8_t verbose):
Device(jtag, filename, verbose), _svf(_jtag, _verbose)
{
(void)flash_wr;
if (_filename != "") {
if (_file_extension == "svf")
_mode = Device::MEM_MODE;
else if (_file_extension == "bit") {
if (sram_wr)
if (prg_type == Device::WR_SRAM)
_mode = Device::MEM_MODE;
else
_mode = Device::SPI_MODE;

View File

@ -29,7 +29,7 @@
class Anlogic: public Device, SPIInterface {
public:
Anlogic(Jtag *jtag, const std::string &filename,
bool flash_wr, bool sram_wr, int8_t verbose);
Device::prog_type_t prg_type, int8_t verbose);
~Anlogic();
void program(unsigned int offset = 0) override;

View File

@ -2,6 +2,7 @@
#define DEVICE_HPP
#include <iostream>
#include <string>
#include "jtag.hpp"
@ -18,11 +19,18 @@ class Device {
FLASH_MODE = 1,
MEM_MODE = 2
};
typedef enum {
WR_SRAM = 0,
WR_FLASH = 1
} prog_type_t;
Device(Jtag *jtag, std::string filename, int8_t verbose = false);
virtual ~Device();
virtual void program(unsigned int offset = 0) = 0;
virtual int idCode() = 0;
virtual void reset();
protected:
Jtag *_jtag;
std::string _filename;

View File

@ -69,15 +69,13 @@ using namespace std;
#define EF_PROGRAM 0x71
#define EFLASH_ERASE 0x75
Gowin::Gowin(Jtag *jtag, const string filename, bool flash_wr, bool sram_wr,
Gowin::Gowin(Jtag *jtag, const string filename, Device::prog_type_t prg_type,
int8_t verbose): Device(jtag, filename, verbose), is_gw1n1(false)
{
_fs = NULL;
if (_filename != "") {
if (_file_extension == "fs") {
if (flash_wr && sram_wr)
throw std::runtime_error("both write-flash and write-sram can't be set");
if (flash_wr)
if (prg_type == Device::WR_FLASH)
_mode = Device::FLASH_MODE;
else
_mode = Device::MEM_MODE;

View File

@ -30,7 +30,7 @@
class Gowin: public Device {
public:
Gowin(Jtag *jtag, std::string filename, bool flash_wr, bool sram_wr,
Gowin(Jtag *jtag, std::string filename, Device::prog_type_t prg_type,
int8_t verbose);
~Gowin();
int idCode() override;

View File

@ -68,19 +68,19 @@ using namespace std;
# define REG_STATUS_EXEC_ERR (1 << 26)
Lattice::Lattice(Jtag *jtag, const string filename,
bool flash_wr, bool sram_wr, int8_t verbose):
Device::prog_type_t prg_type, int8_t verbose):
Device(jtag, filename, verbose), _fpga_family(UNKNOWN_FAMILY)
{
(void)sram_wr;
if (_filename != "") {
if (_file_extension == "jed" || _file_extension == "mcs") {
_mode = Device::FLASH_MODE;
} else if (_file_extension == "bit") {
if (flash_wr)
if (prg_type == Device::WR_FLASH)
_mode = Device::FLASH_MODE;
else
_mode = Device::MEM_MODE;
} else if (flash_wr) { // for raw bin to flash at offset != 0
} else if (prg_type == Device::WR_FLASH) {
// for raw bin to flash at offset != 0
_mode = Device::FLASH_MODE;
} else {
throw std::exception();

View File

@ -31,7 +31,7 @@
class Lattice: public Device, SPIInterface {
public:
Lattice(Jtag *jtag, std::string filename, bool flash_wr, bool sram_wr,
Lattice(Jtag *jtag, std::string filename, Device::prog_type_t prg_type,
int8_t verbose);
int idCode() override;
int userCode();

View File

@ -58,8 +58,7 @@ struct arguments {
bool list_cables;
bool list_boards;
bool list_fpga;
bool write_flash;
bool write_sram;
Device::prog_type_t prg_type;
bool is_list_command;
bool spi;
};
@ -76,7 +75,7 @@ int main(int argc, char **argv)
/* command line args. */
struct arguments args = {0, false, false, 0, "", "", "-", "", -1, 6000000, "-",
false, false, false, false, false, true, false, false};
false, false, false, false, Device::WR_SRAM, false, false};
/* parse arguments */
try {
if (parse_opt(argc, argv, &args, &pins_config))
@ -91,6 +90,11 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
if (args.prg_type == Device::WR_SRAM)
cout << "write to ram" << endl;
if (args.prg_type == Device::WR_FLASH)
cout << "write to flash" << endl;
if (args.board[0] != '-' && board_list.find(args.board) != board_list.end()) {
board = &(board_list[args.board]);
}
@ -263,18 +267,18 @@ int main(int argc, char **argv)
Device *fpga;
try {
if (fab == "xilinx") {
fpga = new Xilinx(jtag, args.bit_file, args.write_flash, args.write_sram,
fpga = new Xilinx(jtag, args.bit_file, args.prg_type,
args.verbose);
} else if (fab == "altera") {
fpga = new Altera(jtag, args.bit_file, args.verbose);
} else if (fab == "anlogic") {
fpga = new Anlogic(jtag, args.bit_file, args.write_flash, args.write_sram,
fpga = new Anlogic(jtag, args.bit_file, args.prg_type,
args.verbose);
} else if (fab == "Gowin") {
fpga = new Gowin(jtag, args.bit_file, args.write_flash, args.write_sram,
fpga = new Gowin(jtag, args.bit_file, args.prg_type,
args.verbose);
} else if (fab == "lattice") {
fpga = new Lattice(jtag, args.bit_file, args.write_flash, args.write_sram,
fpga = new Lattice(jtag, args.bit_file, args.prg_type,
args.verbose);
} else {
printError("Error: manufacturer " + fab + " not supported");
@ -414,15 +418,10 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p
throw std::exception();
}
if (result.count("write-flash")) {
args->write_flash = true;
args->write_sram = false;
}
if (result.count("write-sram")) {
args->write_flash = false;
args->write_sram = true;
}
if (result.count("write-flash"))
args->prg_type = Device::WR_FLASH;
else if (result.count("write-sram"))
args->prg_type = Device::WR_SRAM;
if (result.count("freq")) {
double freq;

View File

@ -14,18 +14,14 @@
#include "progressBar.hpp"
Xilinx::Xilinx(Jtag *jtag, const std::string &filename,
bool flash_wr, bool sram_wr, int8_t verbose):
Device::prog_type_t prg_type, int8_t verbose):
Device(jtag, filename, verbose)
{
if (_filename != ""){
if (flash_wr && sram_wr) {
printError("both write-flash and write-sram can't be set");
throw std::exception();
}
if (_file_extension == "mcs") {
_mode = Device::SPI_MODE;
} else if (_file_extension == "bit" || _file_extension == "bin") {
if (sram_wr)
if (prg_type == Device::WR_SRAM)
_mode = Device::MEM_MODE;
else
_mode = Device::SPI_MODE;

View File

@ -11,7 +11,7 @@
class Xilinx: public Device, SPIInterface {
public:
Xilinx(Jtag *jtag, const std::string &filename,
bool flash_wr, bool sram_wr, int8_t verbose);
Device::prog_type_t prg_type, int8_t verbose);
~Xilinx();
void program(unsigned int offset = 0) override;