2021-06-26 15:24:07 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2019-11-18 16:03:59 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2021-11-20 16:07:53 +01:00
|
|
|
#ifndef SRC_LATTICE_HPP_
|
|
|
|
|
#define SRC_LATTICE_HPP_
|
2019-11-18 16:03:59 +01:00
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-03-06 09:05:57 +01:00
|
|
|
#include "jtag.hpp"
|
2019-11-18 16:03:59 +01:00
|
|
|
#include "device.hpp"
|
|
|
|
|
#include "jedParser.hpp"
|
2021-11-09 09:54:09 +01:00
|
|
|
#include "feaparser.hpp"
|
2019-12-20 09:09:38 +01:00
|
|
|
#include "latticeBitParser.hpp"
|
2020-04-22 15:21:01 +02:00
|
|
|
#include "spiInterface.hpp"
|
2019-11-18 16:03:59 +01:00
|
|
|
|
2020-04-22 15:21:01 +02:00
|
|
|
class Lattice: public Device, SPIInterface {
|
2019-11-18 16:03:59 +01:00
|
|
|
public:
|
2021-02-21 18:30:13 +01:00
|
|
|
Lattice(Jtag *jtag, std::string filename, const std::string &file_type,
|
2021-11-09 09:54:09 +01:00
|
|
|
Device::prog_type_t prg_type, std::string flash_sector, bool verify,
|
2023-09-11 05:46:08 +02:00
|
|
|
int8_t verbose, bool skip_load_bridge, bool skip_reset);
|
2023-08-10 12:50:26 +02:00
|
|
|
uint32_t idCode() override;
|
2019-12-20 09:09:38 +01:00
|
|
|
int userCode();
|
2019-11-18 16:03:59 +01:00
|
|
|
void reset() override {}
|
2021-12-22 19:11:35 +01:00
|
|
|
void program(unsigned int offset, bool unprotect_flash) override;
|
2019-12-20 09:09:38 +01:00
|
|
|
bool program_mem();
|
2021-12-22 19:11:35 +01:00
|
|
|
bool program_flash(unsigned int offset, bool unprotect_flash);
|
2021-11-20 16:07:53 +01:00
|
|
|
bool Verify(std::vector<std::string> data, bool unlock = false,
|
|
|
|
|
uint32_t flash_area = 0);
|
2021-12-22 19:11:35 +01:00
|
|
|
bool dumpFlash(uint32_t base_addr, uint32_t len) override {
|
|
|
|
|
return SPIInterface::dump(base_addr, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief protect SPI flash blocks
|
|
|
|
|
*/
|
|
|
|
|
bool protect_flash(uint32_t len) override {
|
|
|
|
|
return SPIInterface::protect_flash(len);
|
|
|
|
|
}
|
|
|
|
|
/*!
|
|
|
|
|
* \brief protect 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();
|
|
|
|
|
}
|
2019-11-18 16:03:59 +01:00
|
|
|
|
2020-04-22 15:21:01 +02:00
|
|
|
/* spi interface */
|
2023-08-08 15:54:27 +02:00
|
|
|
int spi_put(uint8_t cmd, const uint8_t *tx, uint8_t *rx,
|
2020-08-23 17:16:21 +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;
|
2020-04-22 15:21:01 +02:00
|
|
|
int spi_wait(uint8_t cmd, uint8_t mask, uint8_t cond,
|
2021-11-20 16:07:53 +01:00
|
|
|
uint32_t timeout, bool verbose = false) override;
|
2020-04-22 15:21:01 +02:00
|
|
|
|
2019-11-18 16:03:59 +01:00
|
|
|
private:
|
2020-09-26 08:40:43 +02:00
|
|
|
enum lattice_family_t {
|
|
|
|
|
MACHXO2_FAMILY = 0,
|
|
|
|
|
MACHXO3_FAMILY = 1,
|
2020-10-16 08:03:45 +02:00
|
|
|
MACHXO3D_FAMILY = 2,
|
|
|
|
|
ECP5_FAMILY = 3,
|
|
|
|
|
NEXUS_FAMILY = 4,
|
2020-09-26 08:40:43 +02:00
|
|
|
UNKNOWN_FAMILY = 999
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
lattice_family_t _fpga_family;
|
|
|
|
|
|
2022-11-26 12:07:36 +01:00
|
|
|
bool program_intFlash(ConfigBitstreamParser *_cbp);
|
2021-12-22 19:11:35 +01:00
|
|
|
bool program_extFlash(unsigned int offset, bool unprotect_flash);
|
2019-11-18 16:03:59 +01:00
|
|
|
bool wr_rd(uint8_t cmd, uint8_t *tx, int tx_len,
|
|
|
|
|
uint8_t *rx, int rx_len, bool verbose = false);
|
2021-12-22 19:11:35 +01:00
|
|
|
/*!
|
|
|
|
|
* \brief move device to SPI access
|
|
|
|
|
*/
|
|
|
|
|
bool prepare_flash_access() override;
|
|
|
|
|
/*!
|
|
|
|
|
* \brief end of device to SPI access
|
|
|
|
|
* reload btistream from flash
|
|
|
|
|
*/
|
|
|
|
|
bool post_flash_access() override;
|
|
|
|
|
/*!
|
|
|
|
|
* \brief erase SRAM
|
|
|
|
|
*/
|
|
|
|
|
bool clearSRAM();
|
2019-11-18 16:03:59 +01:00
|
|
|
void unlock();
|
|
|
|
|
bool EnableISC(uint8_t flash_mode);
|
|
|
|
|
bool DisableISC();
|
|
|
|
|
bool EnableCfgIf();
|
|
|
|
|
bool DisableCfg();
|
|
|
|
|
bool pollBusyFlag(bool verbose = false);
|
|
|
|
|
bool flashEraseAll();
|
2021-11-09 09:54:09 +01:00
|
|
|
bool flashErase(uint32_t mask);
|
2020-08-19 17:00:44 +02:00
|
|
|
bool flashProg(uint32_t start_addr, const std::string &name,
|
2020-05-02 09:47:41 +02:00
|
|
|
std::vector<std::string> data);
|
2019-11-20 07:30:54 +01:00
|
|
|
bool checkStatus(uint32_t val, uint32_t mask);
|
|
|
|
|
void displayReadReg(uint32_t dev);
|
2019-11-18 16:03:59 +01:00
|
|
|
uint32_t readStatusReg();
|
2019-11-20 07:30:54 +01:00
|
|
|
uint64_t readFeaturesRow();
|
|
|
|
|
bool writeFeaturesRow(uint64_t features, bool verify);
|
|
|
|
|
uint16_t readFeabits();
|
|
|
|
|
bool writeFeabits(uint16_t feabits, bool verify);
|
2019-11-18 16:03:59 +01:00
|
|
|
bool writeProgramDone();
|
|
|
|
|
bool loadConfiguration();
|
2023-05-01 00:50:16 +02:00
|
|
|
uint16_t getUFMStartPageFromJEDEC(JedParser *_jed, int id);
|
2019-11-18 16:03:59 +01:00
|
|
|
|
|
|
|
|
/* test */
|
|
|
|
|
bool checkID();
|
2021-11-09 09:54:09 +01:00
|
|
|
|
|
|
|
|
/*********************** MODS FOR MacXO3D *****************************/
|
|
|
|
|
enum lattice_flash_sector_t {
|
|
|
|
|
LATTICE_FLASH_UNDEFINED = 0,
|
|
|
|
|
LATTICE_FLASH_CFG0,
|
|
|
|
|
LATTICE_FLASH_CFG1,
|
|
|
|
|
LATTICE_FLASH_UFM0,
|
|
|
|
|
LATTICE_FLASH_UFM1,
|
|
|
|
|
LATTICE_FLASH_UFM2,
|
|
|
|
|
LATTICE_FLASH_UFM3,
|
|
|
|
|
LATTICE_FLASH_FEA,
|
|
|
|
|
LATTICE_FLASH_PKEY,
|
|
|
|
|
LATTICE_FLASH_AKEY,
|
|
|
|
|
LATTICE_FLASH_CSEC,
|
|
|
|
|
LATTICE_FLASH_USEC
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
lattice_flash_sector_t _flash_sector;
|
|
|
|
|
bool programFeatureRow_MachXO3D(uint8_t* feature_row);
|
|
|
|
|
bool programFeabits_MachXO3D(uint32_t feabits);
|
2021-11-25 15:13:17 +01:00
|
|
|
bool programPubKey_MachXO3D(uint8_t* pubkey);
|
|
|
|
|
|
|
|
|
|
bool program_intFlash_MachXO3D(JedParser& _jed);
|
|
|
|
|
bool program_fea_MachXO3D();
|
|
|
|
|
bool program_pubkey_MachXO3D();
|
2019-11-18 16:03:59 +01:00
|
|
|
};
|
2021-11-20 16:07:53 +01:00
|
|
|
#endif // SRC_LATTICE_HPP_
|