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>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef LATTICE_HPP_
|
|
|
|
|
#define LATTICE_HPP_
|
|
|
|
|
|
|
|
|
|
#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,
|
2021-01-30 07:57:49 +01:00
|
|
|
int8_t verbose);
|
2019-11-18 16:03:59 +01:00
|
|
|
int idCode() override;
|
2019-12-20 09:09:38 +01:00
|
|
|
int userCode();
|
2019-11-18 16:03:59 +01:00
|
|
|
void reset() override {}
|
|
|
|
|
void program(unsigned int offset) override;
|
2019-12-20 09:09:38 +01:00
|
|
|
bool program_mem();
|
2020-04-22 15:21:01 +02:00
|
|
|
bool program_flash(unsigned int offset);
|
2021-11-09 09:54:09 +01:00
|
|
|
bool Verify(std::vector<std::string> data, bool unlock = false, uint32_t flash_area = 0);
|
2021-06-24 18:19:09 +02:00
|
|
|
bool dumpFlash(const std::string &filename,
|
|
|
|
|
uint32_t base_addr, uint32_t len) override;
|
2019-11-18 16:03:59 +01:00
|
|
|
|
2020-04-22 15:21:01 +02:00
|
|
|
/* spi interface */
|
|
|
|
|
int spi_put(uint8_t cmd, uint8_t *tx, uint8_t *rx,
|
2020-08-23 17:16:21 +02:00
|
|
|
uint32_t len) override;
|
|
|
|
|
int spi_put(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,
|
|
|
|
|
uint32_t timeout, bool verbose=false) override;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2021-11-19 16:21:52 +01:00
|
|
|
bool program_intFlash(JedParser& _jed);
|
2020-04-22 15:21:01 +02:00
|
|
|
bool program_extFlash(unsigned int offset);
|
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);
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
/* 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;
|
2021-11-19 16:21:52 +01:00
|
|
|
bool program_intFlash_MachXO3D(JedParser& _jed);
|
2021-11-09 09:54:09 +01:00
|
|
|
bool program_fea_MachXO3D();
|
|
|
|
|
bool programFeatureRow_MachXO3D(uint8_t* feature_row);
|
|
|
|
|
bool programFeabits_MachXO3D(uint32_t feabits);
|
2019-11-18 16:03:59 +01:00
|
|
|
};
|
|
|
|
|
#endif // LATTICE_HPP_
|