Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for efinix .bit/.hex files (input only) #51

Merged
merged 9 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The SRecord package understands a number of file formats:
* **COE**: output only; Extension `.coe`; also known as **Xilinx Coefficient File** format
* **Cosmac**: input/output; also known as **RCA Cosmac Elf** format
* **DEC Binary (XXDP)**: input/output
* **Efinix hex/bit**: input;
* **Elektor Monitor (EMON52)**: input/output
* **Fairchild Fairbug**: input/output
* **Formatted Binary**: input/output
Expand Down
1 change: 1 addition & 0 deletions doc/dictionaries/names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Doxygen
dpkg
diffutils
Dragonball
Efinix
Elektor
Elektuur
EPROM
Expand Down
58 changes: 58 additions & 0 deletions doc/man5/srec_efinix.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'\" t
.\" srecord - manipulate eprom load files
.\" Copyright (C) 2023 Daniel Anselmi
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation; either version 3 of the License, or
.\" (at your option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program. If not, see
.\" <http://www.gnu.org/licenses/>.
.\"
.ds n) srec_efinix
.TH \*(n) 5 SRecord "Reference Manual"
.SH NAME
srec_efinix \- Efinix bitstream file format
.if require_index \{
.XX "srec_efinix(5)" "Efinix bitstream file format"
.\}
.SH DESCRIPTION
This format is the Efinix bitstream file format.
This is a hex format generated by the IDE from Efinix to program their FPGAs.

The text file to be read contains two hex-chars (one binary byte) on each line.

There is no addressing and no checksum in this format.

No comments are allowed in this format.

sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
Here is an example Efinix bit file.
It contains the data \[lq]Hello, World\[rq].
.RS
.nf
.ft CW
48
65
6C
6C
6F
2C
20
57
6F
72
6C
64
.ft P
.fi
.RE

.ds n) srec_cat
.so man1/z_copyright.so
2 changes: 2 additions & 0 deletions srecord/arglex/tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ srecord::arglex_tool::arglex_tool(int argc, char **argv) :
{ "-Disable_Sequence_Warnings", token_sequence_warnings_disable, },
{ "-Dot_STyle", token_style_dot, },
{ "-EEPROM", token_eeprom, },
{ "-EFinix_bit", token_efinix_bit, },
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
{ "-EFinix_hex", token_efinix_bit, },
{ "-Elektor_Monitor52", token_emon52, },
{ "-Enable_Sequence_Warnings", token_sequence_warnings_enable, },
{ "-Exclude", token_exclude, },
Expand Down
1 change: 1 addition & 0 deletions srecord/arglex/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class arglex_tool:
token_crop,
token_dec_binary,
token_eeprom,
token_efinix_bit,
token_emon52,
token_exclude,
token_exclusive_length,
Expand Down
6 changes: 6 additions & 0 deletions srecord/arglex/tool/input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <srecord/input/file/fastload.h>
#include <srecord/input/file/formatted_binary.h>
#include <srecord/input/file/four_packed_code.h>
#include <srecord/input/file/efinix_bit.h>
#include <srecord/input/file/hexdump.h>
#include <srecord/input/file/hp64k.h>
#include <srecord/input/file/idt.h>
Expand Down Expand Up @@ -315,6 +316,11 @@ srecord::arglex_tool::get_simple_input()
ifp = input_file_dec_binary::create(fn);
break;

case token_efinix_bit:
token_next();
ifp = input_file_efinix_bit::create(fn);
break;

case token_emon52:
token_next();
ifp = input_file_emon52::create(fn);
Expand Down
90 changes: 90 additions & 0 deletions srecord/input/file/efinix_bit.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// srecord - manipulate eprom load files
// Copyright (C) 2023 Daniel Anselmi
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#include <iostream>
#include <cctype>

#include <srecord/arglex/tool.h>
#include <srecord/input/file/efinix_bit.h>
#include <srecord/record.h>


srecord::input_file_efinix_bit::input_file_efinix_bit(
const std::string &a_filename
) :
input_file(a_filename),
address(0),
done(false)
{
}


srecord::input_file::pointer
srecord::input_file_efinix_bit::create(const std::string &a_filename)
{
return pointer(new input_file_efinix_bit(a_filename));
}


// See base class for documentation.
bool srecord::input_file_efinix_bit::read(record &record)
{
if (done)
return false;

int length = 0;
srecord::record::data_t data[srecord::record::max_data_length];

for (;;)
{
if (peek_char() == EOF)
{
done = true;
break;
}

srecord::record::data_t c = get_byte(); /* get two hex digits */
data[length++] = c;

c = get_char(); // newline
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
if (c != '\n')
fatal_error("expecting newline at col 3");

if (length >= (int)sizeof(data))
break;
}

record = srecord::record(srecord::record::type_data, address, data, length);
address += length;
return true;
}

const char *
srecord::input_file_efinix_bit::get_file_format_name()
const
{
return "Efinix bitstream";
}


int
srecord::input_file_efinix_bit::format_option_number()
const
{
return arglex_tool::token_efinix_bit;
}
100 changes: 100 additions & 0 deletions srecord/input/file/efinix_bit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// srecord - manipulate eprom load files
// Copyright (C) 2023 Daniel Anselmi
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#ifndef SRECORD_INPUT_EFINIX_BIT_H
#define SRECORD_INPUT_EFINIX_BIT_H

#include <srecord/input/file.h>

namespace srecord {

/**
* The srecord::input_file_efinix_bit class is used to represent the parse
* state when reading an efinix .bit or .hex file.
*/
class input_file_efinix_bit:
public input_file
{
public:
/**
* The destructor.
*/
virtual ~input_file_efinix_bit() = default;

/**
* The create class method is used to create new dynamically
* allocated instances of this class.
*
* @param file_name
* The name of the file to be read.
* @returns
* smart pointer to new instance
*/
static pointer create(const std::string &file_name);

/**
* The default constructor.
*/
input_file_efinix_bit() = delete;

/**
* The copy constructor.
*/
input_file_efinix_bit(const input_file_efinix_bit &) = delete;

/**
* The assignment operator. Do not use.
*/
input_file_efinix_bit &operator=(const input_file_efinix_bit &) = delete;

protected:
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
// See base class for documentation.
bool read(record &record);

// See base class for documentation.
const char *get_file_format_name() const;

// See base class for documentation.
int format_option_number() const;

private:
/**
* The constructor.
*
* @param file_name
* The name of the file to be read.
*/
input_file_efinix_bit(const std::string &file_name);

/**
* The address instance variable is used to remember the current
* address of the next data record. This is set and advanced by
* the #read method.
*/
uint32_t address;

/**
* The done instance variable is used to remember that we
* don't expect more input data.
*/
bool done;
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
};

};

#endif // SRECORD_INPUT_EFINIX_BIT_H
74 changes: 74 additions & 0 deletions test/02/t0265a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh
#
# srecord - Manipulate EPROM load files
# Copyright (C) 2023 Daniel Anselmi
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

TEST_SUBJECT="input efinix"
. test_prelude.sh

cat > test.bit << 'fubar'
FB
0B
D0
70
7D
37
A1
7B
09
40
F8
50
E3
B8
AD
C5
F9
DE
BE
CB
A8
F2
01
C3
80
81
EB
41
A3
B9
fubar
if test $? -ne 0; then no_result; fi

cat > test.ok << 'fubar'
S0220000687474703A2F2F737265636F72642E736F75726365666F7267652E6E65742F1D
S1210000FB0BD0707D37A17B0940F850E3B8ADC5F9DEBECBA8F201C38081EB41A3B9E3
S5030001FB
fubar
if test $? -ne 0; then no_result; fi

srec_cat test.bit -efinix -o test.out
if test $? -ne 0; then fail; fi

diff test.ok test.out
if test $? -ne 0; then fail; fi

#
# The things tested here, worked.
# No other guarantees are made.
#
pass