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>
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-05 10:27:35 +02:00
|
|
|
#ifndef CONFIGBITSTREAMPARSER_H
|
|
|
|
|
#define CONFIGBITSTREAMPARSER_H
|
|
|
|
|
|
2021-02-24 06:36:48 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2019-10-05 10:27:35 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <fstream>
|
2021-02-24 06:36:48 +01:00
|
|
|
#include <string>
|
2020-03-20 18:01:48 +01:00
|
|
|
#include <map>
|
2019-10-05 10:27:35 +02:00
|
|
|
|
|
|
|
|
class ConfigBitstreamParser {
|
|
|
|
|
public:
|
2020-08-19 16:53:49 +02:00
|
|
|
ConfigBitstreamParser(const std::string &filename, int mode = ASCII_MODE,
|
2019-11-21 08:36:43 +01:00
|
|
|
bool verbose = false);
|
2019-12-06 07:21:19 +01:00
|
|
|
virtual ~ConfigBitstreamParser();
|
2019-10-05 10:27:35 +02:00
|
|
|
virtual int parse() = 0;
|
|
|
|
|
uint8_t *getData() {return (uint8_t*)_bit_data.c_str();}
|
|
|
|
|
int getLength() {return _bit_length;}
|
2021-02-10 08:02:20 +01:00
|
|
|
|
2021-02-24 06:36:48 +01:00
|
|
|
/**
|
|
|
|
|
* \brief display header informations
|
|
|
|
|
*/
|
|
|
|
|
virtual void displayHeader();
|
|
|
|
|
|
2021-02-10 08:02:20 +01:00
|
|
|
/**
|
|
|
|
|
* \brief get header list of keys/values
|
|
|
|
|
* \return list of couple keys/values
|
|
|
|
|
*/
|
|
|
|
|
std::map<std::string, std::string> getHeader() { return _hdr; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief get value in header list
|
|
|
|
|
* \param[in] key: key value
|
|
|
|
|
* \return associated value for the key
|
|
|
|
|
*/
|
|
|
|
|
std::string getHeaderVal(std::string key);
|
2021-02-24 06:36:48 +01:00
|
|
|
|
2019-10-05 10:27:35 +02:00
|
|
|
enum {
|
|
|
|
|
ASCII_MODE = 0,
|
|
|
|
|
BIN_MODE = std::ifstream::binary
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-20 08:05:32 +01:00
|
|
|
static uint8_t reverseByte(uint8_t src);
|
|
|
|
|
|
2021-11-25 08:11:50 +01:00
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* \brief decompress bitstream in gzip format
|
|
|
|
|
* \param[in] source: raw compressed data
|
|
|
|
|
* \param[out] dest: raw uncompressed data
|
|
|
|
|
* \return false if openFPGALoader is build without zlib or
|
|
|
|
|
* if uncompress fails
|
|
|
|
|
*/
|
|
|
|
|
bool decompress_bitstream(std::string source, std::string *dest);
|
|
|
|
|
|
2019-10-05 10:27:35 +02:00
|
|
|
protected:
|
|
|
|
|
std::string _filename;
|
|
|
|
|
int _bit_length;
|
|
|
|
|
int _file_size;
|
2019-11-21 08:36:43 +01:00
|
|
|
bool _verbose;
|
2019-10-05 10:27:35 +02:00
|
|
|
std::string _bit_data;
|
2021-01-24 18:16:09 +01:00
|
|
|
std::string _raw_data; /**< unprocessed file content */
|
2020-03-20 18:01:48 +01:00
|
|
|
std::map<std::string, std::string> _hdr;
|
2019-10-05 10:27:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|