Clean up compiler warnings when compiling on 64-bit systems. These are mostly fixing...
[ffado.git] / libffado / src / fireworks / fireworks_firmware.h
blob09b5649ef4eefca9ce452b00e01fc69b982a7a4b
1 /*
2 * Copyright (C) 2005-2008 by Pieter Palmers
4 * This file is part of FFADO
5 * FFADO = Free Firewire (pro-)audio drivers for linux
7 * FFADO is based upon FreeBoB.
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.
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.
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/>.
24 #ifndef FIREWORKS_FIRMWARE_H
25 #define FIREWORKS_FIRMWARE_H
27 #include "debugmodule/debugmodule.h"
29 #include "efc/efc_cmd.h"
30 #include "efc/efc_cmds_hardware.h"
31 #include "efc/efc_cmds_flash.h"
33 #include "IntelFlashMap.h"
35 #include <string>
37 class ConfigRom;
38 class Ieee1394Service;
40 namespace FireWorks {
42 #define ECHO_FIRMWARE_MAGIC "1651 1 0 0 0"
43 #define ECHO_FIRMWARE_MAGIC_LENGTH_BYTES 14
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 )
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)
54 #define ECHO_FIRMWARE_NUM_BOXTYPES 4
56 class Firmware
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,
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);
75 virtual bool loadFile(std::string filename);
76 virtual bool loadFromMemory(uint32_t *data, uint32_t addr, uint32_t len);
78 virtual bool isValid() {return m_valid;};
80 virtual std::string getSourceString() {return m_source;};
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
88 bool operator==(const Firmware& x);
90 /**
91 * @brief get base address of the firmware image
92 * @return base address of the firmware image
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)
99 virtual uint32_t getLength() {return m_length_quads;};
102 * @brief get length of data to be written to the device (in quadlets)
103 * @return length (in quadlets)
105 virtual uint32_t getWriteDataLen();
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
111 virtual bool getWriteData(uint32_t *buff);
113 virtual void show();
114 virtual void setVerboseLevel(int l)
115 {setDebugLevel(l);};
116 void dumpData();
118 protected:
119 // filename
120 std::string m_source;
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;
132 std::string m_magic;
133 uint32_t m_header[ECHO_FIRMWARE_HEADER_LENGTH_QUADLETS];
134 uint32_t *m_data;
136 bool m_valid;
138 private:
139 DECLARE_DEBUG_MODULE;
142 class FirmwareUtil
145 public:
146 FirmwareUtil(FireWorks::Device& parent);
147 virtual ~FirmwareUtil();
149 virtual void show();
150 virtual void setVerboseLevel(int l)
151 {setDebugLevel(l);};
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
159 Firmware getFirmwareFromDevice(uint32_t start, uint32_t length);
163 * @brief writes a firmware to the device
164 * @param f firmware to write
165 * @return true if successful
167 bool writeFirmwareToDevice(Firmware f);
170 * @brief erases the flash memory starting at addr
171 * @param address
172 * @param nb_quads
173 * @return true if successful, false otherwise
175 bool eraseBlocks(unsigned int address, unsigned int nb_quads);
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
182 bool isValidForDevice(Firmware f);
184 protected:
185 FireWorks::Device& m_Parent;
187 private:
188 struct dat_list
190 uint32_t vendorid;
191 uint32_t boxtype;
192 uint32_t minversion;
193 int count;
194 const char **filenames;
197 struct dat_list m_datlists[ECHO_FIRMWARE_NUM_BOXTYPES];
199 private:
200 DECLARE_DEBUG_MODULE;
203 } // namespace FireWorks
205 #endif