root/trunk/libffado/src/fireworks/fireworks_firmware.h

Revision 1011, 5.6 kB (checked in by ppalmers, 16 years ago)

finish ECHO firmware tools

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef FIREWORKS_FIRMWARE_H
25 #define FIREWORKS_FIRMWARE_H
26
27 #include "debugmodule/debugmodule.h"
28
29 #include "efc/efc_cmd.h"
30 #include "efc/efc_cmds_hardware.h"
31 #include "efc/efc_cmds_flash.h"
32
33 #include "IntelFlashMap.h"
34
35 #include <string>
36
37 class ConfigRom;
38 class Ieee1394Service;
39
40 namespace FireWorks {
41
42 #define ECHO_FIRMWARE_MAGIC                     "1651 1 0 0 0"
43 #define ECHO_FIRMWARE_MAGIC_LENGTH_BYTES        14
44
45 // the number of quadlets in the file
46 #define ECHO_FIRMWARE_HEADER_LENGTH_QUADLETS    64
47 // note that the dat files are not binary files but have the quadlets
48 // as "0x0ABCDE12\n" lines
49 #define ECHO_FIRMWARE_HEADER_LENGTH_BYTES       ( 12 * ECHO_FIRMWARE_HEADER_LENGTH_QUADLETS )
50
51 #define ECHO_FIRMWARE_FILE_MAX_LENGTH_QUADLETS  ((384 * 1024) / 4)
52 #define ECHO_FIRMWARE_FILE_MAX_LENGTH_BYTES     (ECHO_FIRMWARE_FILE_MAX_LENGTH_QUADLETS * 12 + ECHO_FIRMWARE_HEADER_LENGTH_BYTES)
53
54 #define ECHO_FIRMWARE_NUM_BOXTYPES  4
55
56 class Firmware
57 {
58 public:
59     enum eDatType {
60         eDT_DspCode         = 0,
61         eDT_IceLynxCode     = 1,
62         eDT_Data            = 2,
63         eDT_FPGACode        = 3,
64         eDT_DeviceName      = 4,
65         eDT_Invalid         = 0xFF,
66     };
67     static const char *eDatTypeToString(const enum eDatType target);
68     static const enum eDatType intToeDatType(int type);
69 public:
70     Firmware();
71     Firmware(const Firmware& f);
72     virtual ~Firmware();
73     Firmware& operator=(const Firmware& f);
74
75     virtual bool loadFile(std::string filename);
76     virtual bool loadFromMemory(uint32_t *data, uint32_t addr, uint32_t len);
77
78     virtual bool isValid() {return m_valid;};
79
80     virtual std::string getSourceString() {return m_source;};
81
82     /**
83      * @brief compare two firmwares
84      * compares only the address, length and data content, not the other fields
85      * @param x firmware to be compared to 'this'
86      * @return true if equal
87      */
88     bool operator==(const Firmware& x);
89
90     /**
91      * @brief get base address of the firmware image
92      * @return base address of the firmware image
93      */
94     virtual uint32_t getAddress() {return m_flash_offset_address;};
95     /**
96      * @brief get length of the firmware image (in quadlets)
97      * @return length of the firmware image (in quadlets)
98      */
99     virtual uint32_t getLength() {return m_length_quads;};
100
101     /**
102      * @brief get length of data to be written to the device (in quadlets)
103      * @return length (in quadlets)
104      */
105     virtual uint32_t getWriteDataLen();
106     /**
107      * @brief prepares data to be written to the device
108      * @param buff buffer to copy data into. should be at least getWriteDataLen() quadlets.
109      * @return true if successful
110      */
111     virtual bool getWriteData(uint32_t *buff);
112
113     virtual void show();
114     virtual void setVerboseLevel(int l)
115         {setDebugLevel(l);};
116     void dumpData();
117
118 protected:
119     // filename
120     std::string         m_source;
121
122     // header data
123     enum eDatType       m_Type;
124     uint32_t            m_flash_offset_address;
125     uint32_t            m_length_quads;
126     uint32_t            m_CRC32;
127     uint32_t            m_checksum;
128     uint32_t            m_version;
129     bool                m_append_crc; // true to append
130     uint32_t            m_footprint_quads;
131
132     std::string         m_magic;
133     uint32_t            m_header[ECHO_FIRMWARE_HEADER_LENGTH_QUADLETS];
134     uint32_t            *m_data;
135
136     bool m_valid;
137
138 private:
139     DECLARE_DEBUG_MODULE;
140 };
141
142 class FirmwareUtil
143 {
144
145 public:
146     FirmwareUtil(FireWorks::Device& parent);
147     virtual ~FirmwareUtil();
148
149     virtual void show();
150     virtual void setVerboseLevel(int l)
151         {setDebugLevel(l);};
152    
153     /**
154      * @brief reads firmware block from device
155      * @param start start address
156      * @param length number of quadlets to read
157      * @return Firmware structure containing the read data
158      */
159     Firmware getFirmwareFromDevice(uint32_t start, uint32_t length);
160
161
162     /**
163      * @brief writes a firmware to the device
164      * @param f firmware to write
165      * @return true if successful
166      */
167     bool writeFirmwareToDevice(Firmware f);
168
169     /**
170      * @brief erases the flash memory starting at addr
171      * @param address
172      * @param nb_quads
173      * @return true if successful, false otherwise
174      */
175     bool eraseBlocks(unsigned int address, unsigned int nb_quads);
176
177     /**
178      * @brief checks whether a firmware is valid for this device
179      * @param f firmware to check
180      * @return true if valid, false if not
181      */
182     bool isValidForDevice(Firmware f);
183
184 protected:
185     FireWorks::Device&          m_Parent;
186
187 private:
188     struct dat_list
189     {
190         uint32_t    vendorid;
191         uint32_t    boxtype;
192         uint32_t    minversion;
193         int         count;
194         char        **filenames;
195     };
196
197     struct dat_list m_datlists[ECHO_FIRMWARE_NUM_BOXTYPES];
198
199 private:
200     DECLARE_DEBUG_MODULE;
201 };
202
203 } // namespace FireWorks
204
205 #endif
Note: See TracBrowser for help on using the browser.