diff --git a/CMakeLists.txt b/CMakeLists.txt index 312073efc1..4b6ba62db7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,7 @@ set(OPENFPGALOADER_SOURCE src/anlogicBitParser.cpp src/anlogicCable.cpp src/ch552_jtag.cpp + src/common.cpp src/dfu.cpp src/dfuFileParser.cpp src/dirtyJtag.cpp @@ -140,6 +141,7 @@ set(OPENFPGALOADER_HEADERS src/anlogicBitParser.hpp src/anlogicCable.hpp src/ch552_jtag.hpp + src/common.hpp src/cxxopts.hpp src/dfu.hpp src/dfuFileParser.hpp diff --git a/README.md b/README.md index 480c5e1ae0..390f6b65f1 100644 --- a/README.md +++ b/README.md @@ -124,3 +124,21 @@ for any corresponding short options. Report bugs to . ``` + +By default **spiOverJtag** are search into `${CMAKE_INSTALL_FULL_DATAROOTDIR}` +(*/usr/local/share/* by default). It's possible to change this behaviour by +using an environment variable: + +```bash +export OPENFPGALOADER_SOJ_DIR=/somewhere +openFPGALoader xxxx +``` + +or + +``` +OPENFPGALOADER_SOJ_DIR=/somewhere openFPGALoader xxxx +``` + +`OPENFPGALOADER_SOJ_DIR` must point to directory containing **spiOverJtag** +bitstreams. diff --git a/doc/guide/advanced.rst b/doc/guide/advanced.rst index f717151599..c375a86e36 100644 --- a/doc/guide/advanced.rst +++ b/doc/guide/advanced.rst @@ -82,3 +82,20 @@ Writing to an arbitrary address in flash memory With FPGA using an external SPI flash (*xilinx*, *lattice ECP5/nexus/ice40*, *anlogic*, *efinix*) option ``-o`` allows one to write raw binary file to an arbitrary adress in FLASH. + +Using an alternative directory for *spiOverJtag* +================================================ + +By setting ``OPENFPGALOADER_SOJ_DIR`` it's possible to override default +*spiOverJtag* bitstreams directory: + +.. code-block:: bash + + export OPENFPGALOADER_SOJ_DIR=/somewhere + openFPGALoader xxxx + +or + +.. code-block:: bash + + OPENFPGALOADER_SOJ_DIR=/somewhere openFPGALoader xxxx diff --git a/src/altera.cpp b/src/altera.cpp index 4537af1bb0..ad1febbdfa 100644 --- a/src/altera.cpp +++ b/src/altera.cpp @@ -9,6 +9,7 @@ #include +#include "common.hpp" #include "jtag.hpp" #include "device.hpp" #include "epcq.hpp" @@ -181,12 +182,11 @@ bool Altera::load_bridge() return false; } - // DATA_DIR is defined at compile time. - bitname = DATA_DIR "/openFPGALoader/spiOverJtag_"; + bitname = get_shell_env_var("OPENFPGALOADER_SOJ_DIR", DATA_DIR "/openFPGALoader"); #ifdef HAS_ZLIB - bitname += _device_package + ".rbf.gz"; + bitname += "/spiOverJtag_" + _device_package + ".rbf.gz"; #else - bitname += _device_package + ".rbf"; + bitname += "/spiOverJtag_" + _device_package + ".rbf"; #endif } diff --git a/src/common.cpp b/src/common.cpp new file mode 100644 index 0000000000..fcf6975520 --- /dev/null +++ b/src/common.cpp @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + * Copyright (C) 2023 Gwenhael Goavec-Merou + */ + + +#include "common.hpp" + +#include +#include + +/*! + * \brief return shell environment variable value + * \param[in] key: variable name + * \return variable value or "" + */ +const std::string get_shell_env_var(const char* key, + const char *def_val) noexcept { + const char* ret = std::getenv(key); + return std::string(ret ? ret : def_val); +} diff --git a/src/common.hpp b/src/common.hpp new file mode 100644 index 0000000000..d85ded85bd --- /dev/null +++ b/src/common.hpp @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + * Copyright (C) 2023 Gwenhael Goavec-Merou + */ + +#ifndef SRC_COMMON_HPP_ +#define SRC_COMMON_HPP_ + +#include + +/*! + * \brief return shell environment variable value + * \param[in] key: variable name + * \param[in] def_val: value to return when not found + * \return variable value or def_val + */ +const std::string get_shell_env_var(const char* key, + const char *def_val="") noexcept; + +#endif // SRC_COMMON_HPP_ diff --git a/src/xilinx.cpp b/src/xilinx.cpp index 2f0f6e8824..0fc5795823 100644 --- a/src/xilinx.cpp +++ b/src/xilinx.cpp @@ -13,6 +13,7 @@ #include "jtag.hpp" #include "bitparser.hpp" +#include "common.hpp" #include "configBitstreamParser.hpp" #include "jedParser.hpp" #include "mcsParser.hpp" @@ -468,9 +469,8 @@ bool Xilinx::load_bridge() return false; } - // DATA_DIR is defined at compile time. - bitname = DATA_DIR "/openFPGALoader/spiOverJtag_"; - bitname += _device_package + ".bit.gz"; + bitname = get_shell_env_var("OPENFPGALOADER_SOJ_DIR", DATA_DIR "/openFPGALoader"); + bitname += "/spiOverJtag_" + _device_package + ".bit.gz"; } #if defined (_WIN64) || defined (_WIN32)