QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
Bootloader.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4
5#include <QtSerialPort/QSerialPort>
6
7class FirmwareImage;
8
11class Bootloader : public QObject
12{
13 Q_OBJECT
14
15public:
16 explicit Bootloader(bool sikRadio, QObject *parent = 0);
17
18 QString errorString(void) { return _errorString; }
19
20 bool open (const QString portName);
21 void close (void) { _port.close(); }
22 bool getBoardInfo (uint32_t& bootloaderVersion, uint32_t& boardID, uint32_t& flashSize);
23 bool initFlashSequence (void);
24 bool erase (void);
25 bool program (const FirmwareImage* image);
26 bool verify (const FirmwareImage* image);
27 bool reboot (void);
28
29 static const int boardIDSiKRadio1000 = 78;
30 static const int boardIDSiKRadio1060 = 80;
31
34 static const int boardIDPX4FMUV2 = 9;
35 static const int boardIDPX4FMUV3 = 255;
36
37signals:
39 void updateProgress(int curr, int total);
40
41private:
42 bool _sync (void);
43 bool _syncWorker (void);
44 bool _binProgram (const FirmwareImage* image);
45 bool _ihxProgram (const FirmwareImage* image);
46 bool _write (const uint8_t* data, qint64 maxSize);
47 bool _write (const uint8_t byte);
48 bool _write (const char* data);
49 bool _read (uint8_t* data, qint64 cBytesExpected, int readTimeout = _readTimout);
50 bool _sendCommand (uint8_t cmd, int responseTimeout = _responseTimeout);
51 bool _getCommandResponse (const int responseTimeout = _responseTimeout);
52 bool _protoGetDevice (uint8_t param, uint32_t& value);
53 bool _verifyBytes (const FirmwareImage* image);
54 bool _binVerifyBytes (const FirmwareImage* image);
55 bool _ihxVerifyBytes (const FirmwareImage* image);
56 bool _verifyCRC (void);
57 QString _getNextLine (int timeoutMsecs);
58 bool _get3DRRadioBoardId (uint32_t& boardID);
59
60 enum {
61 // protocol bytes
62 PROTO_INSYNC = 0x12,
63 PROTO_BAD_SILICON_REV = 0x14,
64 PROTO_EOC = 0x20,
65
66 // Reply bytes
67 PROTO_OK = 0x10,
68 PROTO_FAILED = 0x11,
69 PROTO_INVALID = 0x13,
70
71 // Command bytes
72 PROTO_GET_SYNC = 0x21,
73 PROTO_GET_DEVICE = 0x22,
74 PROTO_CHIP_ERASE = 0x23,
75 PROTO_LOAD_ADDRESS = 0x24,
76 PROTO_PROG_MULTI = 0x27,
77 PROTO_GET_CRC = 0x29,
78 PROTO_BOOT = 0x30,
79
80 // Command bytes - Rev 2 boootloader only
81 PROTO_CHIP_VERIFY = 0x24,
82 PROTO_READ_MULTI = 0x28,
83
84 INFO_BL_REV = 1,
85 BL_REV_MIN = 2,
86 BL_REV_MAX = 5,
87 INFO_BOARD_ID = 2,
88 INFO_BOARD_REV = 3,
89 INFO_FLASH_SIZE = 4,
90
91 PROG_MULTI_MAX = 64,
92 READ_MULTI_MAX = 0x28
93 };
94
95 QSerialPort _port;
96 bool _sikRadio = false;
97 bool _inBootloaderMode = false;
98 uint32_t _boardID = 0;
99 uint32_t _boardFlashSize = 0;
100 uint32_t _bootloaderVersion = 0;
101 uint32_t _imageCRC = 0;
102 QString _firmwareFilename;
103 QString _errorString;
104
105 static const int _eraseTimeout = 20000;
106 static const int _rebootTimeout = 10000;
107 static const int _verifyTimeout = 5000;
108 static const int _readTimout = 2000;
109 static const int _responseTimeout = 2000;
110 static const int _flashSizeSmall = 1032192;
111 static const int _bootloaderVersionV2CorrectFlash = 5;
112};
static const int boardIDSiKRadio1060
Newer radio based on SI1060 chip.
Definition Bootloader.h:30
bool program(const FirmwareImage *image)
void updateProgress(int curr, int total)
Signals progress indicator for long running bootloader utility routines.
static const int boardIDSiKRadio1000
Original radio based on SI1000 chip.
Definition Bootloader.h:29
QString errorString(void)
Definition Bootloader.h:18
bool erase(void)
static const int boardIDPX4FMUV2
PX4 V2 board, as from USB PID.
Definition Bootloader.h:34
bool reboot(void)
bool initFlashSequence(void)
static const int boardIDPX4FMUV3
Definition Bootloader.h:35
Bootloader(bool sikRadio, QObject *parent=0)
This class manages interactions with the bootloader.
Definition Bootloader.cc:14
bool open(const QString portName)
Definition Bootloader.cc:21
bool verify(const FirmwareImage *image)
bool getBoardInfo(uint32_t &bootloaderVersion, uint32_t &boardID, uint32_t &flashSize)
Definition Bootloader.cc:68
void close(void)
Definition Bootloader.h:21
Support for Intel Hex firmware file.