AJA NTV2 SDK  18.0.0.2122
NTV2 SDK 18.0.0.2122
ntv2konaflashprogram.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #ifndef NTV2KONAFLASHPROGRAM_H
9 #define NTV2KONAFLASHPROGRAM_H
10 
11 #include "ntv2card.h"
12 #include <fstream>
13 #include <vector>
14 #include <string>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <fcntl.h>
18 #include <iostream>
19 #include "ntv2debug.h"
20 #include "ntv2mcsfile.h"
21 #include "ntv2spiinterface.h"
22 #include "ntv2bitfile.h"
23 
24 #define MAXBITFILE_HEADERSIZE 512
25 #define MAXMCSINFOSIZE 256
26 #define MAXMCSLICENSESIZE 256
27 #define MCS_STEPS 6
28 
29 struct MacAddr
30 {
31  uint8_t mac[6];
32  std::string AsString(void) const;
33 };
34 
35 
37 {
38  public:
40 
42  virtual ~CNTV2FlashProgress() {}
43  virtual bool UpdatePercentage (const size_t inPercentage) {(void) inPercentage; return true;}
44 }; // CNTV2PercentUpdater
45 
46 
48 {
49 public:
51  CNTV2KonaFlashProgram (const UWord boardNumber);
52  virtual ~CNTV2KonaFlashProgram();
53  static std::string FlashBlockIDToString (const FlashBlockID inID, const bool inShortDisplay = false); // New in SDK 16.0
54 
55 public:
56  virtual bool SetBoard (uint32_t index = 0);
57  bool ReadHeader (FlashBlockID flashBlock);
58  bool ReadInfoString();
59  bool SetBitFile (const std::string & inBitfileName, std::ostream & outMsgs, const FlashBlockID blockNumber = AUTO_FLASHBLOCK); // New in SDK 16.0
60  bool SetMCSFile (const std::string & sMCSFileName);
61  std::string Program (bool fullVerify = false);
62  bool ProgramFromMCS(bool verify);
63  bool ProgramSOC(bool verify = true);
64  bool ProgramCustom (const std::string & sCustomFileName, const uint32_t addr, std::ostream & outMsgs);
65  bool ProgramKonaxMB (const std::string & sCustomFileName, const uint32_t addr, std::ostream & outMsgs);
66  bool EraseBlock (FlashBlockID blockNumber);
67  bool EraseChip (UWord chip = 0);
68  bool CreateSRecord (bool bChangeEndian);
69  bool CreateEDIDIntelRecord ();
70  void SetQuietMode ();
71  bool VerifyFlash (FlashBlockID flashBlockNumber, bool fullVerify = false);
72  bool ReadFlash (NTV2Buffer & outBuffer, const FlashBlockID flashID, CNTV2FlashProgress & inFlashProgress = CNTV2FlashProgress::nullUpdater); // New in SDK 16.0
73  bool SetBankSelect (BankSelect bankNumber);
74  bool SetFlashBlockIDBank(FlashBlockID blockID);
75  bool ROMHasBankSelect();
76  uint32_t ReadBankSelect ();
77  bool SetMBReset();
78  bool IsInstalledFWRunning (bool & outIsRunning, std::ostream & outErrorMsgs);
79  bool WriteCommand(_FLASH_COMMAND inCommand);
80 
81  std::string GetDesignName (void) const {return _parser.DesignName();}
82  std::string GetPartName (void) const {return _parser.PartName();}
83  std::string GetDate (void) const {return _parser.Date();}
84  std::string GetTime (void) const {return _parser.Time();}
85  const NTV2BitfileHeaderParser & Parser (void) const {return _parser;}
86  uint32_t GetNumBytes(void) const {return _numBytes;}
87  const std::string & GetMCSInfo (void) const {return _mcsInfo;}
88  void ParsePartitionFromFileLines(uint32_t address, uint16_t & partitionOffset);
89  bool CreateBankRecord(BankSelect bankID);
90 
91  bool ProgramMACAddresses(MacAddr * mac1, MacAddr * mac2);
92  bool ReadMACAddresses(MacAddr & mac1, MacAddr & mac2);
93  bool ProgramLicenseInfo(const std::string & licenseString);
94  bool ReadLicenseInfo(std::string & licenseString);
95  void DisplayData(const uint32_t address, const uint32_t len);
96  bool ProgramInfoFromString(std::string infoString);
97  bool FullProgram(std::vector<uint8_t> & dataBuffer);
98 
99  int32_t NextMcsStep() {return ++_mcsStep;}
100 
101  bool WaitForFlashNOTBusy();
102  bool ProgramFlashValue(uint32_t address, uint32_t value);
103  bool FastProgramFlash256(uint32_t address, uint32_t* buffer);
104  bool EraseSector(uint32_t sectorAddress);
105  bool CheckFlashErasedWithBlockID(FlashBlockID flashBlockNumber);
106  uint32_t ReadDeviceID();
107  bool SetDeviceProperties();
108  void DetermineFlashTypeAndBlockNumberFromFileName(const std::string & bitFileName);
109 
110  uint32_t GetSectorAddressForSector(FlashBlockID flashBlockNumber,uint32_t sectorNumber)
111  {
112  return GetBaseAddressForProgramming(flashBlockNumber)+(sectorNumber*_sectorSize);
113  }
114 
115  uint32_t GetBaseAddressForProgramming(FlashBlockID flashBlockNumber)
116  {
117  switch ( flashBlockNumber )
118  {
119  default:
120  case MAIN_FLASHBLOCK: return _mainOffset;
121  case FAILSAFE_FLASHBLOCK: return _failSafeOffset;
122  case SOC1_FLASHBLOCK: return _soc1Offset;
123  case SOC2_FLASHBLOCK: return _soc2Offset;
124  case MAC_FLASHBLOCK: return _macOffset;
125  case MCS_INFO_BLOCK: return _mcsInfoOffset;
126  case LICENSE_BLOCK: return _licenseOffset;
127  }
128 
129  }
130 
131  uint32_t GetNumberOfSectors(FlashBlockID flashBlockNumber)
132  {
133  switch ( flashBlockNumber )
134  {
135  default:
136  case MAIN_FLASHBLOCK: return _numSectorsMain;
137  case FAILSAFE_FLASHBLOCK: return _numSectorsFailSafe;
138  case SOC1_FLASHBLOCK: return _numSectorsSOC1;
139  case SOC2_FLASHBLOCK: return _numSectorsSOC2;
140  case MAC_FLASHBLOCK: return 1;
141  case MCS_INFO_BLOCK: return 1;
142  case LICENSE_BLOCK: return 1;
143  }
144  }
145 
146  bool VerifySOCPartition(FlashBlockID flashID, uint32_t FlashBlockOffset);
147  bool CheckAndFixMACs();
148  bool MakeMACsFromSerial( const char *sSerialNumber, MacAddr *pMac1, MacAddr *pMac2 );
149 
150 protected:
152  uint8_t * _customFileBuffer;
153  uint32_t _bitFileSize;
155  std::string _bitFileName;
156  std::string _mcsInfo;
157  uint32_t _spiDeviceID;
158  uint32_t _flashSize;
159  uint32_t _bankSize;
160  uint32_t _sectorSize;
161  uint32_t _mainOffset;
162  uint32_t _failSafeOffset;
163  uint32_t _macOffset;
164  uint32_t _mcsInfoOffset;
165  uint32_t _licenseOffset;
166  uint32_t _soc1Offset;
167  uint32_t _soc2Offset;
168  uint32_t _numSectorsMain;
169  uint32_t _numSectorsSOC1;
170  uint32_t _numSectorsSOC2;
172  uint32_t _numBytes;
174  uint32_t _deviceID;
175  bool _bQuiet;
176  int32_t _mcsStep;
178  std::vector<uint8_t> _partitionBuffer;
182 }; // CNTV2KonaFlashProgram
183 
184 #endif // NTV2KONAFLASHPROGRAM_H
uint32_t GetBaseAddressForProgramming(FlashBlockID flashBlockNumber)
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
BankSelect
Definition: ntv2enums.h:4286
_FLASH_COMMAND
Definition: ntv2enums.h:4294
std::string GetDate(void) const
Declares the CNTV2SpiFlash and CNTV2AxiSpiFlash classes.
Knows how to extract information from a bitfile header.
Definition: ntv2bitfile.h:26
FlashBlockID
Definition: ntv2enums.h:4274
std::string GetPartName(void) const
uint32_t GetSectorAddressForSector(FlashBlockID flashBlockNumber, uint32_t sectorNumber)
uint32_t GetNumBytes(void) const
Instances of me can parse an MCS file.
Definition: ntv2mcsfile.h:51
std::string GetDesignName(void) const
Declares the CNTV2MCSfile class.
Describes a user-space buffer on the host computer. I have an address and a length, plus some optional attributes (allocated by SDK?, page-aligned? etc.).
NTV2BitfileHeaderParser _parser
#define AJAExport
Definition: export.h:33
uint32_t GetNumberOfSectors(FlashBlockID flashBlockNumber)
const NTV2BitfileHeaderParser & Parser(void) const
Declares the CNTV2Bitfile class.
uint16_t UWord
Definition: ajatypes.h:221
std::vector< uint8_t > _partitionBuffer
uint8_t mac[6]
const std::string & GetMCSInfo(void) const
std::string GetTime(void) const
Declares the CNTV2Card class.
std::string AsString(void) const
virtual bool UpdatePercentage(const size_t inPercentage)
static CNTV2FlashProgress & nullUpdater