#include <stdexcept>
#include <vector>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <iocsh.h>
#include <epicsThread.h>
#include <epicsStdio.h>
#include "mrfCommon.h"
#include "mrf/spi.h"
#include "mrf/flash.h"
#include <epicsExport.h>
Go to the source code of this file.
◆ epicsExportAddress()
◆ epicsExportRegistrar()
epicsExportRegistrar |
( |
registrarFlashOps |
| ) |
|
◆ flasherase()
void flasherase |
( |
const char * |
name, |
|
|
int |
addrraw, |
|
|
int |
countraw |
|
) |
| |
Definition at line 229 of file flashiocsh.cpp.
234 printf(
"No such device");
237 epicsUInt32
addr = addrraw, count = countraw;
241 mem.erase(addr, count);
245 }
catch(std::exception& e){
246 printf(
"Error: %s\n", e.what());
Handling for Common Flash Interfafce compliant chips.
static bool lookupDev(const std::string &name, SPIDevice *)
◆ flashinfo()
void flashinfo |
( |
const char * |
name | ) |
|
Definition at line 36 of file flashiocsh.cpp.
41 printf(
"No such device");
51 printf(
"Vendor: %02x (%s)\nDevice: %02x\nID: %02x\n",
54 printf(
"Capacity: 0x%x\n", (
unsigned)info.
capacity);
56 printf(
"Sector: 0x%x\n", (
unsigned)info.
sectorSize);
58 printf(
"Page: 0x%x\n", (
unsigned)info.
pageSize);
59 if(!info.
SN.empty()) {
61 for(
size_t i=0; i<info.
SN.size(); i++)
62 printf(
" %02x",
unsigned(info.
SN[i]));
67 printf(
"Warning: Some information about this flash chip is not known.\n" 68 " Please open an issue and include this output of flashinfo()\n" 69 " and if known the flash chip vendor and part number.\n" 70 " https://github.com/epics-modules/mrfioc2/issues\n");
75 std::istream strm(&sbuf);
77 if(image.
read(strm)) {
78 printf(
"Bit Stream found\n Project: %s\n Part: %s\n Build: %s\n",
83 }
catch(std::exception& e){
84 printf(
"Error: %s\n", e.what());
epicsUInt32 pageSize
PAGE PROGRAM (0x02) size in bytes. Always a power of 2.
epicsUInt32 capacity
total capacity in bytes
Attempt to read out the header of a Xilinx bitstream file.
Handling for Common Flash Interfafce compliant chips.
epicsUInt32 sectorSize
SECTOR ERASE (0xd8) size in bytes. Always a power of 2.
std::vector< epicsUInt8 > SN
bool read(std::istream &strm)
static bool lookupDev(const std::string &name, SPIDevice *)
Adapt CFIFlash for use with std::istream.
◆ flashread()
void flashread |
( |
const char * |
name, |
|
|
int |
addrraw, |
|
|
int |
countraw, |
|
|
const char * |
outfile |
|
) |
| |
Definition at line 90 of file flashiocsh.cpp.
95 printf(
"No such device");
98 epicsUInt32
addr = addrraw, count = countraw;
102 std::ostream *strm = &std::cout;
105 fstrm.open(outfile, std::ios_base::out|std::ios_base::binary);
107 throw std::runtime_error(
"Unable to open output file");
112 const epicsUInt32
N = std::min(count, mem.blockSize());
113 std::vector<epicsUInt8> buf(N);
118 (*strm).write((
const char*)&buf[0], buf.size());
121 for(
size_t i=0; i<buf.size(); i++) {
122 printf(
"%02x",
int(buf[i]));
133 printf(
"| %u\n",
unsigned(count));
138 }
catch(std::exception& e){
139 printf(
"Error: %s\n", e.what());
Handling for Common Flash Interfafce compliant chips.
static bool lookupDev(const std::string &name, SPIDevice *)
◆ flashwrite()
void flashwrite |
( |
const char * |
name, |
|
|
int |
addrraw, |
|
|
const char * |
infile |
|
) |
| |
Definition at line 145 of file flashiocsh.cpp.
147 if(!infile || infile[0]==
'\0') {
148 printf(
"Usage: flashwrite <name> <start_address> <filename>\n");
155 printf(
"No such device");
158 epicsUInt32
addr = addrraw;
161 if(!mem.writable()) {
162 printf(
"Device not writable\n");
166 std::ifstream strm(infile, std::ios_base::in|std::ios_base::binary);
168 throw std::runtime_error(
"Unable to open output file");
170 strm.seekg(0, std::ios_base::end);
171 const long fsize = strm.tellg();
181 std::istream mstrm(&sbuf);
187 match &= infile.
part.empty() || infile.
part==inmem.
part;
189 fprintf(stderr,
"Bitstream header mis-match.\nFile: \"%s\", \"%s\"\nROM: \"%s\", \"%s\"\n",
194 fprintf(stderr,
"To override, re-run after setting: var(\"flashAcknowledgeMismatch\", 1)\n");
202 std::vector<epicsUInt8> buf;
206 printf(
"| %u/%u\n", (
unsigned)pos, (
unsigned)fsize);
208 buf.resize(mem.blockSize());
209 buf.resize(strm.read((
char*)&buf[0], buf.size()).gcount());
211 throw std::runtime_error(
"I/O Error");
216 mem.write(addr, buf,
false);
222 }
catch(std::exception& e){
223 printf(
"Error: %s\n", e.what());
int flashAcknowledgeMismatch
Attempt to read out the header of a Xilinx bitstream file.
Handling for Common Flash Interfafce compliant chips.
bool read(std::istream &strm)
static bool lookupDev(const std::string &name, SPIDevice *)
Adapt CFIFlash for use with std::istream.
◆ flashAcknowledgeMismatch
int flashAcknowledgeMismatch |