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-09-26 18:29:20 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
|
|
#include "device.hpp"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2021-02-21 18:30:13 +01:00
|
|
|
Device::Device(Jtag *jtag, string filename, const string &file_type,
|
2021-06-24 18:06:48 +02:00
|
|
|
bool verify, int8_t verbose):
|
2019-09-28 15:26:47 +02:00
|
|
|
_filename(filename),
|
|
|
|
|
_file_extension(filename.substr(filename.find_last_of(".") +1)),
|
2021-06-24 18:06:48 +02:00
|
|
|
_mode(NONE_MODE), _verify(verify), _verbose(verbose > 0),
|
|
|
|
|
_quiet(verbose < 0)
|
2019-09-26 18:29:20 +02:00
|
|
|
{
|
2021-11-26 07:35:03 +01:00
|
|
|
/* extension overwritten by user */
|
|
|
|
|
if (!file_type.empty()) {
|
2021-02-21 18:30:13 +01:00
|
|
|
_file_extension = file_type;
|
2021-11-26 07:35:03 +01:00
|
|
|
/* check if extension and some specific type */
|
|
|
|
|
} else if (!filename.empty()) {
|
|
|
|
|
size_t offset = filename.find_last_of(".");
|
|
|
|
|
/* no extension => consider raw */
|
|
|
|
|
if (offset == string::npos) {
|
|
|
|
|
_file_extension = "raw";
|
|
|
|
|
/* compressed file ? */
|
|
|
|
|
} else if (_file_extension.substr(0, 2) == "gz") {
|
|
|
|
|
size_t offset2 = filename.find_last_of(".", offset - 1);
|
|
|
|
|
/* no more extension -> error */
|
|
|
|
|
if (offset2 == string::npos) {
|
|
|
|
|
char mess[256];
|
|
|
|
|
snprintf(mess, sizeof(mess), "\nfile %s is compressed\n"
|
|
|
|
|
"but can't determine real type\n"
|
|
|
|
|
"please add correct extension or use --file-type",
|
|
|
|
|
filename.c_str());
|
|
|
|
|
throw std::runtime_error(mess);
|
|
|
|
|
} else { /* extract sub extension */
|
|
|
|
|
_file_extension = _filename.substr(offset2 + 1,
|
|
|
|
|
offset - offset2 - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-24 07:35:33 +01:00
|
|
|
|
2019-09-26 18:29:20 +02:00
|
|
|
_jtag = jtag;
|
2021-01-30 07:57:49 +01:00
|
|
|
if (verbose > 0)
|
2019-11-21 08:38:11 +01:00
|
|
|
cout << "File type : " << _file_extension << endl;
|
2019-09-26 18:29:20 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-28 15:26:47 +02:00
|
|
|
Device::~Device() {}
|
2019-09-26 18:29:20 +02:00
|
|
|
|
|
|
|
|
void Device::reset()
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("Not implemented");
|
|
|
|
|
}
|
|
|
|
|
|