-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdload.h
158 lines (137 loc) · 5.03 KB
/
dload.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
// dload.h
// dloadtool
//
// Created by Joshua Hill on 1/31/13.
// Modified by Joachim Naulet on 3/10/16
//
//
#ifndef __dloadtool__dload__
#define __dloadtool__dload__
#include <stdint.h>
extern int ack_errno;
//Start Code Address Size CRC End
//7e 0f 20 02 fe 00 01 00 ?? ?? 7e
//7e 05 20 01 20 00 9f 1f 7e
#define DLOAD_WRITE 0x01
#define DLOAD_ACK 0x02
#define DLOAD_NAK 0x03
#define DLOAD_ERASE 0x04
#define DLOAD_EXECUTE 0x05
#define DLOAD_NOP 0x06
#define DLOAD_PARAM_REQ 0x07
#define DLOAD_PARAM_RESP 0x08
#define DLOAD_MEMORY_DUMP 0x09
#define DLOAD_RESET 0x0A
#define DLOAD_UNLOCK 0x0B
#define DLOAD_SW_VER_REQ 0x0C
#define DLOAD_SW_VERS_RESP 0x0D
#define DLOAD_POWERDOWN 0x0E
#define DLOAD_WRITE_ADDR 0x0F
#define DLOAD_MEMORY_DEBUG_QUERY 0x10
#define DLOAD_MEMORY_DEBUG_INFO 0x11
#define DLOAD_MEMORY_READ_REQ 0x12
#define DLOAD_MEMORY_READ 0x13
#define DLOAD_MEMORY_UNFRAMED_READ_REQ 0x14 /* SBL only */
#define DLOAD_PBL_SERIAL_NUMBER_READ_REQ 0x14 /* PBL only */
#define DLOAD_PBL_SERIAL_NUMBER_READ_RESP 0x14 /* PBL only */
#define DLOAD_MEMORY_UNFRAMED_READ_RESP 0x15 /* SBL only */
#define DLOAD_SERIAL_NUMBER_READ_REQ 0x16
#define DLOAD_SERIAL_NUMBER_READ_RESP 0x16
#define DLOAD_HW_ID_READ_REQ 0x17
#define DLOAD_HW_ID_READ_RESP 0x17
#define DLOAD_PUBLIC_KEY_HASH_READ_REQ 0x18
#define DLOAD_PUBLIC_KEY_HASH_READ_RESP 0x18
#define DLOAD_QPST_COOKIE_READ_REQ 0x19
#define DLOAD_QPST_COOKIE_READ_RESP 0x1A
#define DLOAD_SWITCH_TO_DLOAD_CMD 0x3A /* SBL only */
/* NACK codes - Only for information, no use at the moment
* Data is from Gassan Idriss' openPST Project
*/
#define DLOAD_NAK_INVALID_FRAME_FCS 0x01
#define DLOAD_NAK_INVALID_DESTINATION_ADDRESS 0x02
#define DLOAD_NAK_INVALID_LENGTH 0x03
#define DLOAD_NAK_UNEXPECTED_END_OF_PACKET 0x04
#define DLOAD_NAK_DATA_LENGTH_TOO_LARGE 0x05
#define DLOAD_NAK_INVALID_COMMAND 0x06
#define DLOAD_NAK_OPERATION_FAILT 0x07
#define DLOAD_NAK_WRONG_FLASH_INTELLIGENT_ID 0x08
#define DLOAD_NAK_BAD_PROGRAMMING_VOLTAGE 0x09
#define DLOAD_NAK_WRITE_VERIFY_FAILED 0x0A
#define DLOAD_NAK_UNLOCK_REQUIRED 0x0B
#define DLOAD_NAK_INCORRECT_SECURITY_CODE 0x0C
#define DLOAD_NAK_CANNOT_POWER_DOWN_PHONE 0x0D
#define DLOAD_NAK_OPERATION_NOT_PERMITTED 0x0E
#define DLOAD_NAK_INVALID_READ_ADDRESS 0x0F
/* To Be continued ? */
typedef struct {
uint16_t code;
uint16_t sequence;
uint8_t unknown;
uint16_t size;
} __attribute__((packed)) dload_firmware_header;
typedef struct {
uint8_t code;
uint32_t address;
uint16_t size;
uint8_t buffer[0];
} __attribute__((packed)) dload_write_addr;
typedef struct {
uint8_t code;
uint32_t address;
uint16_t size;
} __attribute__((packed)) dload_read_req;
typedef struct {
uint8_t code;
uint8_t address[3];
uint8_t size[3];
} __attribute__ ((packed)) dload_erase;
typedef struct {
uint8_t code;
uint32_t address;
} __attribute__((packed)) dload_execute;
typedef struct {
uint8_t code;
uint8_t length;
uint8_t version[0];
} __attribute__((packed)) dload_sw_version;
typedef struct {
uint8_t code;
uint8_t version;
uint8_t min_version;
uint16_t max_write;
uint8_t model;
uint8_t device_size;
uint8_t device_type;
} __attribute__((packed)) dload_params;
typedef struct {
uint8_t code;
uint64_t security_key;
} __attribute__((packed)) dload_unlock;
typedef struct {
uint8_t code;
uint16_t errno;
} __attribute__((packed)) dload_ack;
extern int nak_errno;
int dload_send_magic(int fd);
int dload_send_reset(int fd);
int dload_send_unlock(int fd, uint64_t key);
int dload_get_params(int fd);
int dload_get_sw_version(int fd);
int dload_send_execute(int fd, uint32_t address);
int dload_upload_firmware(int fd, uint32_t address, const char* path);
int dload_upload_data(int fd, uint32_t addr, const void *data, size_t len);
int dload_memory_read_req(int fd, uint32_t address, size_t len);
int dload_send_erase(int fd, uint32_t address, size_t len);
int dload_read(int fd, void* buffer, uint32_t size);
int dload_write(int fd, void* buffer, uint32_t size);
int dload_request(void* input, uint32_t insize,
uint8_t** output, uint32_t* outsize);
int dload_response(void* input, uint32_t insize,
uint8_t** output, uint32_t* outsize);
int dload_escape(uint8_t* input, uint32_t insize,
uint8_t** output, uint32_t* outsize);
int dload_unescape(uint8_t* input, uint32_t insize,
uint8_t** output, uint32_t* outsize);
const char *dload_strerror(int errno);
#endif /* defined(__dloadtool__dload__) */