From 8fb36f9ba97cc8c6fce10dba4ec9309cc8b95b33 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Wed, 7 Oct 2020 07:47:46 +0200 Subject: [PATCH] main: improve flash direct access --- src/main.cpp | 63 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8dbfd27..72d7338 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,7 @@ #include "jtag.hpp" #include "part.hpp" #include "spiFlash.hpp" +#include "rawParser.hpp" #include "xilinx.hpp" using namespace std; @@ -86,22 +87,6 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } - /* FLASH direct access */ - if (args.spi) { - FTDIpp_MPSSE::mpsse_bit_config spi_cable = cable_list["ft2232"].config; - int mapping[] = {INTERFACE_A, INTERFACE_B, INTERFACE_C, INTERFACE_D}; - spi_cable.interface = mapping[args.ftdi_channel]; - cout << spi_cable.interface << endl; - FtdiSpi *spi = new FtdiSpi(spi_cable, 6000000, args.verbose); - SPIFlash flash((SPIInterface *)spi, args.verbose); - flash.power_up(); - flash.reset(); - flash.read_id(); - - delete spi; - return EXIT_SUCCESS; - } - /* if a board name is specified try to use this to determine cable */ if (args.board[0] != '-' && board_list.find(args.board) != board_list.end()) { /* set pins config (only when user has not already provided @@ -152,6 +137,52 @@ int main(int argc, char **argv) } } + /* FLASH direct access */ + if (args.spi) { + FtdiSpi *spi = NULL; + RawParser *bit = NULL; + + try { + spi = new FtdiSpi(cable.config, args.freq, args.verbose); + } catch (std::exception &e) { + printError("Error: Failed to claim cable"); + return EXIT_FAILURE; + } + + SPIFlash flash((SPIInterface *)spi, args.verbose); + flash.power_up(); + flash.reset(); + flash.read_id(); + + if (!args.bit_file.empty()) { + printInfo("Open file " + args.bit_file + " ", false); + try { + bit = new RawParser(args.bit_file, false); + printSuccess("DONE"); + } catch (std::exception &e) { + printError("FAIL"); + delete spi; + return EXIT_FAILURE; + } + + printInfo("Parse file ", false); + if (bit->parse() == EXIT_FAILURE) { + printError("FAIL"); + delete spi; + return EXIT_FAILURE; + } else { + printSuccess("DONE"); + } + + flash.erase_and_prog(args.offset, bit->getData(), bit->getLength()/8); + } + + delete bit; + delete spi; + + return EXIT_SUCCESS; + } + /* jtag base */ Jtag *jtag; try {