aboutsummaryrefslogtreecommitdiff
path: root/src/download.h
blob: c1554cbe8061dba6e74c80771b4192c9290f96d4 (plain)
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
/*
 * Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _DOWNLOAD_H_
#define _DOWNLOAD_H_

#include <stdint.h>
#include <sys/types.h>

#include "lg-downloader.h"

/*
 * Values
 */

#define DOWNLOAD_START_FLASH_WRITE				0x01
#define DOWNLOAD_WRITE						0x02
#define DOWNLOAD_COMPLETE_FLASH_WRITE				0x03
#define DOWNLOAD_ERASE						0x04
#define DOWNLOAD_READ						0x05
#define DOWNLOAD_INITIALIZE_PARTITION				0x06
#define DOWNLOAD_WRITE_ROM_COPY					0x07
#define DOWNLOAD_READY_READ					0x08
#define DOWNLOAD_WRITE_ASYNC					0x09
#define DOWNLOAD_GO						0x20
#define DOWNLOAD_NO_OP						0x21
#define DOWNLOAD_RESET						0x22
#define DOWNLOAD_POWERDOWN					0x23
#define DOWNLOAD_PRE_RESET					0x24
#define DOWNLOAD_CP_USB_SWITCH					0x25
#define DOWNLOAD_SOFTWARE_VER					0x40
#define DOWNLOAD_NOTIFY_START_DL				0x41

#define DOWNLOAD_ACK						0x50
#define DOWNLOAD_NACK						0x51

#define DOWNLOAD_BUFFER_SIZE					1024

/*
 * Structures
 */

struct download_request {
	uint8_t command;
} __attribute__((__packed__));

struct download_write_request {
	uint8_t command;
	uint8_t binary_type;
	uint16_t reserved;
	uint32_t address;
	uint32_t length;
} __attribute__((__packed__));

struct download_erase_request {
	uint8_t command;
	uint8_t reserved[3];
	uint32_t address;
	uint32_t length;
} __attribute__((__packed__));

struct download_read_request {
	uint8_t command;
	uint8_t reserved;
	uint32_t length;
} __attribute__((__packed__));

struct download_initialize_partition_request {
	uint8_t command;
	uint8_t binary_type;
	uint32_t address;
	uint32_t length;
} __attribute__((__packed__));

struct download_ready_read_request {
	uint8_t command;
	uint8_t reserved;
	uint32_t address;
	uint32_t length;
} __attribute__((__packed__));

struct download_write_async_request {
	uint8_t command;
	uint8_t binary_type;
	uint16_t reserved;
	uint32_t total_length;
	uint32_t length;
} __attribute__((__packed__));

struct download_response {
	uint8_t ack;
} __attribute__((__packed__));

/*
 * Functions
 */

int download_start_flash_write(struct context *context);
int download_write(struct context *context, void *buffer, off_t address, size_t length);
int download_erase(struct context *context, off_t address, size_t length);
int download_read(struct context *context, void *buffer, size_t length);
int download_initialize_partition(struct context *context, off_t address, size_t length);
int download_ready_read(struct context *context, off_t address, size_t length);
int download_write_async(struct context *context, void *buffer, size_t length);
int download_reset(struct context *context);
int download_notify_start_dl(struct context *context);


#endif