devices: simplify write RAM/Flash
This commit is contained in:
parent
48e65fa0ad
commit
5f9a8835da
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
31
src/main.cpp
31
src/main.cpp
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue