NetBurner 3.1
nbupdate.h
1 #ifndef __NBUPDATE_H
2 #define __NBUPDATE_H
3 
4 /*NB_REVISION*/
5 
6 /*NB_COPYRIGHT*/
7 
8 #include <predef.h>
9 #include <constants.h>
10 
11 #define NBUP_ERR_NO_ERR 0
12 #define NBUP_ERR_BAD_SOCK -1
13 #define NBUP_ERR_TIMEOUT -2
14 #define NBUP_ERR_TOO_LARGE -3
15 #define NBUP_ERR_WRONG_PLAT -4
16 #define NBUP_ERR_BAD_PROG -5
17 
18 #define NBUP_MSFUS_XTRA_RECORD_PAD (16)
19 extern const int EXTRA_RECORD_PAD;
20 struct ModifiedFlashStartUpStruct
21 {
22  // these values will be in the correct order when transmit in the image file
23  // they do not need to be converted between endianess
24  uint32_t dwBlockRamStart ;
25  uint32_t dwExecutionAddr ;
26  uint32_t dwBlockSize ;
27  uint32_t dwSrcBlockSize ;
28  uint32_t dwBlockSum ;
29  uint32_t dwStructSum ;
30  uint8_t ExtraData[NBUP_MSFUS_XTRA_RECORD_PAD];
31 };
32 
33 //States...
34 //Looking for an S....
35 //S getting S record type
36 //Parsing Address up to 8 chars)
37 //Parsing Data
38 //Checking csum....
39 
40 //S0MOD5441X
41 //S315C0040000 40 00 04 00 40 00 05 40 00 05 F6 3C 00 03 AA 5C 1D
42 //S315C0040010 1B 41 90 65 A7 0A 18 11 00 41 FF FF 01 4C 6C 80 73
43 //S7054000054075
44 
45 extern const char PlatformName[];
46 
47 extern const uint16_t FLAG_DOING_S0;
48 extern const uint16_t FLAG_DOING_S3;
49 extern const uint16_t FLAG_DOING_S7;
50 extern const uint16_t FLAG_SUS_VALID;
51 extern const uint16_t FLAG_SAW_FINALS7;
52 extern const uint16_t FLAG_SAW_BINARY;
53 extern const uint16_t FLAG_DOING_BINARY;
54 
55 class AppUpdateRecord
56 {
57  bool m_bWrittenToFlash;
58  uint8_t m_state;
59  uint8_t m_csum;
60  uint8_t m_cnt;
61  uint16_t m_flags;
62  uint32_t tempv;
63 
64  ModifiedFlashStartUpStruct bsus;
65  ModifiedFlashStartUpStruct sus;
66  uint8_t * pRecord;
67  uint32_t DataRead;
68  uint32_t BaseAddress;
69  const char * m_Error;
70  int m_ErrorNum;
71 
72 public:
73  AppUpdateRecord();
74  ~AppUpdateRecord();
75  //Return true when done
76  bool ParseChars(char * chars, int nChars);
77  void ParseOneChar(char c);
78  void PutValue(uint8_t v);
79  bool resp;
80 
81  enum {
82  ERR_NO_ERR,
83  ERR_NO_REC,
84  ERR_BAD_RX,
85  ERR_WRITE_FAIL,
86  ERR_ALREADY_WRITTEN,
87  ERR_BAD_ALLOC,
88  ERR_BAD_PLAT,
89  ERR_BAD_CSUM,
90  };
91 
92  int DoFlashProgram();
93  bool CsumValid();
94  bool ImageReceived()
95  {
96  if( (m_Error) || (m_ErrorNum) || (!pRecord) || (DataRead<sus.dwSrcBlockSize) || (( m_flags&FLAG_SAW_FINALS7)==0) ) return false;
97  return true;
98  };
99 
100  const char * GetError()
101  {
102  return m_Error;
103  };
104 
105  int GetErrorNum()
106  {
107  return m_ErrorNum;
108  }
109 
110  uint32_t GetbaseAddress()
111  {
112  return BaseAddress;
113  };
114 
115  uint32_t GetLength()
116  {
117  return sus.dwSrcBlockSize;
118  };
119 
120  const uint8_t * GetData()
121  {
122  return pRecord;
123  };
124 };
125 
126 int ProgramApplication(uint32_t where,uint8_t * pAppImage);
127 int UpdateFromStream(int fd, AppUpdateRecord *&pu, uint32_t timeout);
128 
129 #endif /* ----- #ifndef __NBUPDATE_H ----- */