Blame view
include/dfu.h
4.66 KB
f22b11c10
|
1 2 3 4 5 6 7 |
/* * dfu.h - DFU flashable area description * * Copyright (C) 2012 Samsung Electronics * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com> * Lukasz Majewski <l.majewski@samsung.com> * |
1a4596601
|
8 |
* SPDX-License-Identifier: GPL-2.0+ |
f22b11c10
|
9 10 11 12 13 14 15 16 |
*/ #ifndef __DFU_ENTITY_H_ #define __DFU_ENTITY_H_ #include <common.h> #include <linux/list.h> #include <mmc.h> |
6f12ebf6e
|
17 |
#include <spi_flash.h> |
a6921adcf
|
18 |
#include <linux/usb/composite.h> |
f22b11c10
|
19 20 21 22 23 |
enum dfu_device_type { DFU_DEV_MMC = 1, DFU_DEV_ONENAND, DFU_DEV_NAND, |
a9479f043
|
24 |
DFU_DEV_RAM, |
6f12ebf6e
|
25 |
DFU_DEV_SF, |
f22b11c10
|
26 27 28 29 30 31 32 33 |
}; enum dfu_layout { DFU_RAW_ADDR = 1, DFU_FS_FAT, DFU_FS_EXT2, DFU_FS_EXT3, DFU_FS_EXT4, |
a9479f043
|
34 |
DFU_RAM_ADDR, |
f22b11c10
|
35 |
}; |
5a127c843
|
36 37 38 |
enum dfu_op { DFU_OP_READ = 1, DFU_OP_WRITE, |
0e285b503
|
39 |
DFU_OP_SIZE, |
5a127c843
|
40 |
}; |
f22b11c10
|
41 |
struct mmc_internal_data { |
dd64827eb
|
42 |
int dev_num; |
f22b11c10
|
43 44 45 46 |
/* RAW programming */ unsigned int lba_start; unsigned int lba_size; unsigned int lba_blk_size; |
c8151b4a5
|
47 48 |
/* eMMC HW partition access */ int hw_partition; |
f22b11c10
|
49 50 51 52 |
/* FAT/EXT */ unsigned int dev; unsigned int part; }; |
c6631764c
|
53 54 55 56 57 58 59 |
struct nand_internal_data { /* RAW programming */ u64 start; u64 size; unsigned int dev; unsigned int part; |
815c30b2b
|
60 61 |
/* for nand/ubi use */ unsigned int ubi; |
c6631764c
|
62 |
}; |
a9479f043
|
63 64 65 66 |
struct ram_internal_data { void *start; unsigned int size; }; |
6f12ebf6e
|
67 68 69 70 71 72 73 |
struct sf_internal_data { struct spi_flash *dev; /* RAW programming */ u64 start; u64 size; }; |
a24c3155d
|
74 75 |
#define DFU_NAME_SIZE 32 #define DFU_CMD_BUF_SIZE 128 |
e7e75c70c
|
76 77 78 |
#ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE #define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */ #endif |
ea2453d56
|
79 |
#ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE |
7a813d5b7
|
80 |
#define CONFIG_SYS_DFU_MAX_FILE_SIZE CONFIG_SYS_DFU_DATA_BUF_SIZE |
ea2453d56
|
81 |
#endif |
33fac4a6a
|
82 83 84 |
#ifndef DFU_DEFAULT_POLL_TIMEOUT #define DFU_DEFAULT_POLL_TIMEOUT 0 #endif |
001a83198
|
85 86 87 |
#ifndef DFU_MANIFEST_POLL_TIMEOUT #define DFU_MANIFEST_POLL_TIMEOUT DFU_DEFAULT_POLL_TIMEOUT #endif |
f22b11c10
|
88 89 90 91 92 |
struct dfu_entity { char name[DFU_NAME_SIZE]; int alt; void *dev_private; |
f22b11c10
|
93 94 |
enum dfu_device_type dev_type; enum dfu_layout layout; |
7ac1b410a
|
95 |
unsigned long max_buf_size; |
f22b11c10
|
96 97 98 |
union { struct mmc_internal_data mmc; |
c6631764c
|
99 |
struct nand_internal_data nand; |
a9479f043
|
100 |
struct ram_internal_data ram; |
6f12ebf6e
|
101 |
struct sf_internal_data sf; |
f22b11c10
|
102 |
} data; |
0e285b503
|
103 |
long (*get_medium_size)(struct dfu_entity *dfu); |
ea2453d56
|
104 105 106 107 108 109 110 |
int (*read_medium)(struct dfu_entity *dfu, u64 offset, void *buf, long *len); int (*write_medium)(struct dfu_entity *dfu, u64 offset, void *buf, long *len); int (*flush_medium)(struct dfu_entity *dfu); |
fc25fa27e
|
111 |
unsigned int (*poll_timeout)(struct dfu_entity *dfu); |
f22b11c10
|
112 |
|
cb7bd2e07
|
113 |
void (*free_entity)(struct dfu_entity *dfu); |
f22b11c10
|
114 |
struct list_head list; |
ea2453d56
|
115 116 117 118 119 120 121 122 123 124 |
/* on the fly state */ u32 crc; u64 offset; int i_blk_seq_num; u8 *i_buf; u8 *i_buf_start; u8 *i_buf_end; long r_left; long b_left; |
c6631764c
|
125 |
u32 bad_skip; /* for nand use */ |
ea2453d56
|
126 |
unsigned int inited:1; |
f22b11c10
|
127 |
}; |
dd64827eb
|
128 |
int dfu_config_entities(char *s, char *interface, char *devstr); |
f22b11c10
|
129 130 131 132 133 134 135 |
void dfu_free_entities(void); void dfu_show_entities(void); int dfu_get_alt_number(void); const char *dfu_get_dev_type(enum dfu_device_type t); const char *dfu_get_layout(enum dfu_layout l); struct dfu_entity *dfu_get_entity(int alt); char *dfu_extract_token(char** e, int *n); |
6bed7ce56
|
136 |
void dfu_trigger_reset(void); |
fed936ed8
|
137 |
int dfu_get_alt(char *name); |
1cc03c5c5
|
138 139 140 |
bool dfu_detach(void); void dfu_trigger_detach(void); void dfu_clear_detach(void); |
dd64827eb
|
141 |
int dfu_init_env_entities(char *interface, char *devstr); |
7ac1b410a
|
142 |
unsigned char *dfu_get_buf(struct dfu_entity *dfu); |
d42782631
|
143 |
unsigned char *dfu_free_buf(void); |
4fb127898
|
144 |
unsigned long dfu_get_buf_size(void); |
1cc03c5c5
|
145 |
bool dfu_usb_get_reset(void); |
f22b11c10
|
146 147 148 |
int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num); int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |
a2199afea
|
149 |
int dfu_flush(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |
f22b11c10
|
150 151 |
/* Device specific */ #ifdef CONFIG_DFU_MMC |
dd64827eb
|
152 |
extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s); |
f22b11c10
|
153 |
#else |
dd64827eb
|
154 155 |
static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) |
f22b11c10
|
156 157 158 159 160 161 |
{ puts("MMC support not available! "); return -1; } #endif |
c6631764c
|
162 163 |
#ifdef CONFIG_DFU_NAND |
dd64827eb
|
164 |
extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s); |
c6631764c
|
165 |
#else |
dd64827eb
|
166 167 |
static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) |
c6631764c
|
168 169 170 171 172 173 |
{ puts("NAND support not available! "); return -1; } #endif |
a9479f043
|
174 |
#ifdef CONFIG_DFU_RAM |
dd64827eb
|
175 |
extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s); |
a9479f043
|
176 |
#else |
dd64827eb
|
177 178 |
static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s) |
a9479f043
|
179 180 181 182 183 184 |
{ puts("RAM support not available! "); return -1; } #endif |
6f12ebf6e
|
185 186 187 188 189 190 191 192 193 194 195 |
#ifdef CONFIG_DFU_SF extern int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s); #else static inline int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s) { puts("SF support not available! "); return -1; } #endif |
a6921adcf
|
196 |
int dfu_add(struct usb_configuration *c); |
f22b11c10
|
197 |
#endif /* __DFU_ENTITY_H_ */ |