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