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