devices: simplify write RAM/Flash
This commit is contained in:
parent
48e65fa0ad
commit
5f9a8835da
|
|
@ -34,15 +34,14 @@
|
||||||
#define IRLENGTH 8
|
#define IRLENGTH 8
|
||||||
|
|
||||||
Anlogic::Anlogic(Jtag *jtag, const std::string &filename,
|
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)
|
Device(jtag, filename, verbose), _svf(_jtag, _verbose)
|
||||||
{
|
{
|
||||||
(void)flash_wr;
|
|
||||||
if (_filename != "") {
|
if (_filename != "") {
|
||||||
if (_file_extension == "svf")
|
if (_file_extension == "svf")
|
||||||
_mode = Device::MEM_MODE;
|
_mode = Device::MEM_MODE;
|
||||||
else if (_file_extension == "bit") {
|
else if (_file_extension == "bit") {
|
||||||
if (sram_wr)
|
if (prg_type == Device::WR_SRAM)
|
||||||
_mode = Device::MEM_MODE;
|
_mode = Device::MEM_MODE;
|
||||||
else
|
else
|
||||||
_mode = Device::SPI_MODE;
|
_mode = Device::SPI_MODE;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
class Anlogic: public Device, SPIInterface {
|
class Anlogic: public Device, SPIInterface {
|
||||||
public:
|
public:
|
||||||
Anlogic(Jtag *jtag, const std::string &filename,
|
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();
|
~Anlogic();
|
||||||
|
|
||||||
void program(unsigned int offset = 0) override;
|
void program(unsigned int offset = 0) override;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define DEVICE_HPP
|
#define DEVICE_HPP
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "jtag.hpp"
|
#include "jtag.hpp"
|
||||||
|
|
||||||
|
|
@ -18,11 +19,18 @@ class Device {
|
||||||
FLASH_MODE = 1,
|
FLASH_MODE = 1,
|
||||||
MEM_MODE = 2
|
MEM_MODE = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
WR_SRAM = 0,
|
||||||
|
WR_FLASH = 1
|
||||||
|
} prog_type_t;
|
||||||
|
|
||||||
Device(Jtag *jtag, std::string filename, int8_t verbose = false);
|
Device(Jtag *jtag, std::string filename, int8_t verbose = false);
|
||||||
virtual ~Device();
|
virtual ~Device();
|
||||||
virtual void program(unsigned int offset = 0) = 0;
|
virtual void program(unsigned int offset = 0) = 0;
|
||||||
virtual int idCode() = 0;
|
virtual int idCode() = 0;
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Jtag *_jtag;
|
Jtag *_jtag;
|
||||||
std::string _filename;
|
std::string _filename;
|
||||||
|
|
|
||||||
|
|
@ -69,15 +69,13 @@ using namespace std;
|
||||||
#define EF_PROGRAM 0x71
|
#define EF_PROGRAM 0x71
|
||||||
#define EFLASH_ERASE 0x75
|
#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)
|
int8_t verbose): Device(jtag, filename, verbose), is_gw1n1(false)
|
||||||
{
|
{
|
||||||
_fs = NULL;
|
_fs = NULL;
|
||||||
if (_filename != "") {
|
if (_filename != "") {
|
||||||
if (_file_extension == "fs") {
|
if (_file_extension == "fs") {
|
||||||
if (flash_wr && sram_wr)
|
if (prg_type == Device::WR_FLASH)
|
||||||
throw std::runtime_error("both write-flash and write-sram can't be set");
|
|
||||||
if (flash_wr)
|
|
||||||
_mode = Device::FLASH_MODE;
|
_mode = Device::FLASH_MODE;
|
||||||
else
|
else
|
||||||
_mode = Device::MEM_MODE;
|
_mode = Device::MEM_MODE;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
class Gowin: public Device {
|
class Gowin: public Device {
|
||||||
public:
|
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);
|
int8_t verbose);
|
||||||
~Gowin();
|
~Gowin();
|
||||||
int idCode() override;
|
int idCode() override;
|
||||||
|
|
|
||||||
|
|
@ -68,19 +68,19 @@ using namespace std;
|
||||||
# define REG_STATUS_EXEC_ERR (1 << 26)
|
# define REG_STATUS_EXEC_ERR (1 << 26)
|
||||||
|
|
||||||
Lattice::Lattice(Jtag *jtag, const string filename,
|
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)
|
Device(jtag, filename, verbose), _fpga_family(UNKNOWN_FAMILY)
|
||||||
{
|
{
|
||||||
(void)sram_wr;
|
|
||||||
if (_filename != "") {
|
if (_filename != "") {
|
||||||
if (_file_extension == "jed" || _file_extension == "mcs") {
|
if (_file_extension == "jed" || _file_extension == "mcs") {
|
||||||
_mode = Device::FLASH_MODE;
|
_mode = Device::FLASH_MODE;
|
||||||
} else if (_file_extension == "bit") {
|
} else if (_file_extension == "bit") {
|
||||||
if (flash_wr)
|
if (prg_type == Device::WR_FLASH)
|
||||||
_mode = Device::FLASH_MODE;
|
_mode = Device::FLASH_MODE;
|
||||||
else
|
else
|
||||||
_mode = Device::MEM_MODE;
|
_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;
|
_mode = Device::FLASH_MODE;
|
||||||
} else {
|
} else {
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
class Lattice: public Device, SPIInterface {
|
class Lattice: public Device, SPIInterface {
|
||||||
public:
|
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);
|
int8_t verbose);
|
||||||
int idCode() override;
|
int idCode() override;
|
||||||
int userCode();
|
int userCode();
|
||||||
|
|
|
||||||
31
src/main.cpp
31
src/main.cpp
|
|
@ -58,8 +58,7 @@ struct arguments {
|
||||||
bool list_cables;
|
bool list_cables;
|
||||||
bool list_boards;
|
bool list_boards;
|
||||||
bool list_fpga;
|
bool list_fpga;
|
||||||
bool write_flash;
|
Device::prog_type_t prg_type;
|
||||||
bool write_sram;
|
|
||||||
bool is_list_command;
|
bool is_list_command;
|
||||||
bool spi;
|
bool spi;
|
||||||
};
|
};
|
||||||
|
|
@ -76,7 +75,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* command line args. */
|
/* command line args. */
|
||||||
struct arguments args = {0, false, false, 0, "", "", "-", "", -1, 6000000, "-",
|
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 */
|
/* parse arguments */
|
||||||
try {
|
try {
|
||||||
if (parse_opt(argc, argv, &args, &pins_config))
|
if (parse_opt(argc, argv, &args, &pins_config))
|
||||||
|
|
@ -91,6 +90,11 @@ int main(int argc, char **argv)
|
||||||
return EXIT_SUCCESS;
|
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()) {
|
if (args.board[0] != '-' && board_list.find(args.board) != board_list.end()) {
|
||||||
board = &(board_list[args.board]);
|
board = &(board_list[args.board]);
|
||||||
}
|
}
|
||||||
|
|
@ -263,18 +267,18 @@ int main(int argc, char **argv)
|
||||||
Device *fpga;
|
Device *fpga;
|
||||||
try {
|
try {
|
||||||
if (fab == "xilinx") {
|
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);
|
args.verbose);
|
||||||
} else if (fab == "altera") {
|
} else if (fab == "altera") {
|
||||||
fpga = new Altera(jtag, args.bit_file, args.verbose);
|
fpga = new Altera(jtag, args.bit_file, args.verbose);
|
||||||
} else if (fab == "anlogic") {
|
} 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);
|
args.verbose);
|
||||||
} else if (fab == "Gowin") {
|
} 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);
|
args.verbose);
|
||||||
} else if (fab == "lattice") {
|
} 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);
|
args.verbose);
|
||||||
} else {
|
} else {
|
||||||
printError("Error: manufacturer " + fab + " not supported");
|
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();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.count("write-flash")) {
|
if (result.count("write-flash"))
|
||||||
args->write_flash = true;
|
args->prg_type = Device::WR_FLASH;
|
||||||
args->write_sram = false;
|
else if (result.count("write-sram"))
|
||||||
}
|
args->prg_type = Device::WR_SRAM;
|
||||||
|
|
||||||
if (result.count("write-sram")) {
|
|
||||||
args->write_flash = false;
|
|
||||||
args->write_sram = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.count("freq")) {
|
if (result.count("freq")) {
|
||||||
double freq;
|
double freq;
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,14 @@
|
||||||
#include "progressBar.hpp"
|
#include "progressBar.hpp"
|
||||||
|
|
||||||
Xilinx::Xilinx(Jtag *jtag, const std::string &filename,
|
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)
|
Device(jtag, filename, verbose)
|
||||||
{
|
{
|
||||||
if (_filename != ""){
|
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") {
|
if (_file_extension == "mcs") {
|
||||||
_mode = Device::SPI_MODE;
|
_mode = Device::SPI_MODE;
|
||||||
} else if (_file_extension == "bit" || _file_extension == "bin") {
|
} else if (_file_extension == "bit" || _file_extension == "bin") {
|
||||||
if (sram_wr)
|
if (prg_type == Device::WR_SRAM)
|
||||||
_mode = Device::MEM_MODE;
|
_mode = Device::MEM_MODE;
|
||||||
else
|
else
|
||||||
_mode = Device::SPI_MODE;
|
_mode = Device::SPI_MODE;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
class Xilinx: public Device, SPIInterface {
|
class Xilinx: public Device, SPIInterface {
|
||||||
public:
|
public:
|
||||||
Xilinx(Jtag *jtag, const std::string &filename,
|
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();
|
~Xilinx();
|
||||||
|
|
||||||
void program(unsigned int offset = 0) override;
|
void program(unsigned int offset = 0) override;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue