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"
38 class Ieee1394Service
;
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
67 static const char *eDatTypeToString(const enum eDatType target
);
68 static const enum eDatType
intToeDatType(int type
);
71 Firmware(const Firmware
& f
);
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
;};
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
);
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
;};
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
);
114 virtual void setVerboseLevel(int l
)
120 std::string m_source
;
123 enum eDatType m_Type
;
124 uint32_t m_flash_offset_address
;
125 uint32_t m_length_quads
;
129 bool m_append_crc
; // true to append
130 uint32_t m_footprint_quads
;
133 uint32_t m_header
[ECHO_FIRMWARE_HEADER_LENGTH_QUADLETS
];
139 DECLARE_DEBUG_MODULE
;
146 FirmwareUtil(FireWorks::Device
& parent
);
147 virtual ~FirmwareUtil();
150 virtual void setVerboseLevel(int 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
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
);
185 FireWorks::Device
& m_Parent
;
194 const char **filenames
;
197 struct dat_list m_datlists
[ECHO_FIRMWARE_NUM_BOXTYPES
];
200 DECLARE_DEBUG_MODULE
;
203 } // namespace FireWorks