2021-06-26 15:24:07 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2021-07-08 20:52:46 +02:00
|
|
|
#ifndef SRC_ALTERA_HPP_
|
|
|
|
|
#define SRC_ALTERA_HPP_
|
2019-09-26 18:29:20 +02:00
|
|
|
|
2020-10-17 18:40:16 +02:00
|
|
|
#include <string>
|
|
|
|
|
|
2019-09-26 18:29:20 +02:00
|
|
|
#include "device.hpp"
|
2020-03-06 09:05:57 +01:00
|
|
|
#include "jtag.hpp"
|
2021-07-08 20:52:46 +02:00
|
|
|
#include "rawParser.hpp"
|
|
|
|
|
#include "spiInterface.hpp"
|
2019-09-28 15:31:43 +02:00
|
|
|
#include "svf_jtag.hpp"
|
2019-09-26 18:29:20 +02:00
|
|
|
|
2021-07-08 20:52:46 +02:00
|
|
|
class Altera: public Device, SPIInterface {
|
2019-09-26 18:29:20 +02:00
|
|
|
public:
|
2021-02-21 18:30:13 +01:00
|
|
|
Altera(Jtag *jtag, const std::string &filename,
|
2021-07-08 20:52:46 +02:00
|
|
|
const std::string &file_type,
|
|
|
|
|
Device::prog_type_t prg_type,
|
|
|
|
|
const std::string &device_package,
|
2022-12-10 22:05:37 +01:00
|
|
|
const std::string &spiOverJtagPath,
|
2022-05-11 14:29:08 +02:00
|
|
|
bool verify, int8_t verbose,
|
2022-05-24 07:29:35 +02:00
|
|
|
bool skip_load_bridge, bool skip_reset);
|
2019-09-26 18:29:20 +02:00
|
|
|
~Altera();
|
|
|
|
|
|
2021-07-08 20:52:46 +02:00
|
|
|
void programMem(RawParser &_bit);
|
2021-12-22 19:11:35 +01:00
|
|
|
void program(unsigned int offset, bool unprotect_flash) override;
|
2021-07-11 11:32:35 +02:00
|
|
|
/*!
|
|
|
|
|
* \brief read len Byte starting at base_addr and store
|
|
|
|
|
* into filename
|
|
|
|
|
* \param[in] filename: file name
|
|
|
|
|
* \param[in] base_addr: starting address in flash memory
|
|
|
|
|
* \param[in] len: length (in Byte)
|
|
|
|
|
* \return false if read fails or filename can't be open, true otherwise
|
|
|
|
|
*/
|
2021-12-22 19:11:35 +01:00
|
|
|
bool dumpFlash(uint32_t base_addr, uint32_t len) override {
|
|
|
|
|
return SPIInterface::dump(base_addr, len);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 12:50:26 +02:00
|
|
|
uint32_t idCode() override;
|
2019-09-28 15:31:43 +02:00
|
|
|
void reset() override;
|
2021-07-08 20:52:46 +02:00
|
|
|
|
2021-12-22 19:11:35 +01:00
|
|
|
/*************************/
|
|
|
|
|
/* spi interface */
|
|
|
|
|
/*************************/
|
|
|
|
|
|
2024-06-09 09:28:52 +02:00
|
|
|
/*!
|
|
|
|
|
* \brief display SPI flash ID and status register
|
|
|
|
|
*/
|
|
|
|
|
bool detect_flash() override {
|
|
|
|
|
return SPIInterface::detect_flash();
|
|
|
|
|
}
|
2021-12-22 19:11:35 +01:00
|
|
|
/*!
|
|
|
|
|
* \brief protect SPI flash blocks
|
|
|
|
|
*/
|
|
|
|
|
bool protect_flash(uint32_t len) override {
|
|
|
|
|
return SPIInterface::protect_flash(len);
|
|
|
|
|
}
|
|
|
|
|
/*!
|
|
|
|
|
* \brief unprotect SPI flash blocks
|
|
|
|
|
*/
|
|
|
|
|
bool unprotect_flash() override {
|
|
|
|
|
return SPIInterface::unprotect_flash();
|
|
|
|
|
}
|
2022-03-10 08:51:54 +01:00
|
|
|
/*!
|
|
|
|
|
* \brief bulk erase SPI flash
|
|
|
|
|
*/
|
|
|
|
|
bool bulk_erase_flash() override {
|
|
|
|
|
return SPIInterface::bulk_erase_flash();
|
|
|
|
|
}
|
2021-12-22 19:11:35 +01:00
|
|
|
|
2023-08-08 15:54:27 +02:00
|
|
|
int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx,
|
2021-07-08 20:52:46 +02:00
|
|
|
uint32_t len) override;
|
2023-08-08 15:54:27 +02:00
|
|
|
int spi_put(const uint8_t *tx, uint8_t *rx, uint32_t len) override;
|
2021-07-08 20:52:46 +02:00
|
|
|
int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
|
|
|
|
|
uint32_t timeout, bool verbose = false) override;
|
|
|
|
|
|
2021-12-22 19:11:35 +01:00
|
|
|
protected:
|
2022-05-11 14:29:08 +02:00
|
|
|
bool prepare_flash_access() override;
|
2022-05-24 07:29:35 +02:00
|
|
|
bool post_flash_access() override;
|
2021-12-22 19:11:35 +01:00
|
|
|
|
2019-09-26 18:29:20 +02:00
|
|
|
private:
|
2024-12-31 18:42:52 +01:00
|
|
|
enum altera_family_t {
|
|
|
|
|
MAX2_FAMILY = 0,
|
|
|
|
|
MAX10_FAMILY = 1,
|
|
|
|
|
CYCLONE5_FAMILY = 2,
|
|
|
|
|
CYCLONE10_FAMILY = 3,
|
|
|
|
|
STRATIXV_FAMILY = 3,
|
|
|
|
|
CYCLONE_MISC = 10, // Fixme: idcode shared
|
|
|
|
|
UNKNOWN_FAMILY = 999
|
|
|
|
|
};
|
|
|
|
|
/*************************/
|
|
|
|
|
/* max10 specific */
|
|
|
|
|
/*************************/
|
|
|
|
|
void max10_program();
|
|
|
|
|
void writeXFM(const uint8_t *cfg_data, uint32_t base_addr, uint32_t offset, uint32_t len);
|
|
|
|
|
uint32_t verifyxFM(const uint8_t *cfg_data, uint32_t base_addr, uint32_t offset,
|
|
|
|
|
uint32_t len);
|
|
|
|
|
void max10_dsm_program_success();
|
|
|
|
|
void max10_flow_program_donebit();
|
|
|
|
|
void max10_addr_shift(uint32_t addr);
|
|
|
|
|
void max_10_flow_enable();
|
|
|
|
|
void max_10_flow_disable();
|
|
|
|
|
void max10_flow_erase();
|
|
|
|
|
void max10_dsm_program(const uint8_t *dsm_data, const uint32_t dsm_len);
|
|
|
|
|
bool max10_dsm_verify();
|
|
|
|
|
|
2021-07-08 20:52:46 +02:00
|
|
|
/*!
|
|
|
|
|
* \brief with intel devices SPI flash direct access is not possible
|
|
|
|
|
* so a bridge must be loaded in RAM to access flash
|
|
|
|
|
* \return false if missing device mode, true otherwise
|
|
|
|
|
*/
|
|
|
|
|
bool load_bridge();
|
|
|
|
|
/* virtual JTAG access */
|
|
|
|
|
/*!
|
|
|
|
|
* \brief virtual IR: send USER0 IR followed, in DR, by
|
|
|
|
|
* address (_vir_addr) in a burst of _vir_length
|
|
|
|
|
* \param[in] reg: data to send in shiftDR mode with addr
|
|
|
|
|
*/
|
|
|
|
|
void shiftVIR(uint32_t reg);
|
|
|
|
|
/*!
|
|
|
|
|
* \brief virtual IR: send USER1 IR followed by
|
|
|
|
|
* data in DR with an optional read
|
|
|
|
|
* \param[in] tx: data to send in shiftDR mode
|
|
|
|
|
* \param[in] rx: data to read in shiftDR mode
|
|
|
|
|
* \param[in] len: len of tx & rx
|
|
|
|
|
* \param[in] end_state: next state at the end of xfer
|
|
|
|
|
*/
|
|
|
|
|
void shiftVDR(uint8_t * tx, uint8_t * rx, uint32_t len,
|
2023-08-10 16:36:18 +02:00
|
|
|
Jtag::tapState_t end_state = Jtag::UPDATE_DR, bool debug = false);
|
2021-07-08 20:52:46 +02:00
|
|
|
|
|
|
|
|
std::string _device_package;
|
2022-12-10 22:05:37 +01:00
|
|
|
std::string _spiOverJtagPath; /**< spiOverJtag explicit path */
|
2021-07-08 20:52:46 +02:00
|
|
|
uint32_t _vir_addr; /**< addr affected to virtual jtag */
|
|
|
|
|
uint32_t _vir_length; /**< length of virtual jtag IR */
|
2024-12-31 18:42:52 +01:00
|
|
|
uint32_t _clk_period; /**< JTAG clock period */
|
|
|
|
|
|
|
|
|
|
altera_family_t _fpga_family;
|
|
|
|
|
uint32_t _idcode;
|
2019-09-26 18:29:20 +02:00
|
|
|
};
|
|
|
|
|
|
2021-07-08 20:52:46 +02:00
|
|
|
#endif // SRC_ALTERA_HPP_
|