Blame view
include/dfu.h
8.62 KB
83d290c56 SPDX: Convert all... |
1 |
/* SPDX-License-Identifier: GPL-2.0+ */ |
f22b11c10 dfu: DFU backend ... |
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> |
f22b11c10 dfu: DFU backend ... |
8 9 10 11 12 13 14 15 |
*/ #ifndef __DFU_ENTITY_H_ #define __DFU_ENTITY_H_ #include <common.h> #include <linux/list.h> #include <mmc.h> |
6f12ebf6e dfu: add SF backend |
16 |
#include <spi_flash.h> |
a6921adcf usb:g_dnl:dfu: Do... |
17 |
#include <linux/usb/composite.h> |
f22b11c10 dfu: DFU backend ... |
18 19 20 21 22 |
enum dfu_device_type { DFU_DEV_MMC = 1, DFU_DEV_ONENAND, DFU_DEV_NAND, |
a9479f043 dfu: ram support |
23 |
DFU_DEV_RAM, |
6f12ebf6e dfu: add SF backend |
24 |
DFU_DEV_SF, |
6015af28e dfu: add backend ... |
25 |
DFU_DEV_MTD, |
ec44cace4 dfu: add DFU virt... |
26 |
DFU_DEV_VIRT, |
f22b11c10 dfu: DFU backend ... |
27 28 29 30 31 32 33 34 |
}; enum dfu_layout { DFU_RAW_ADDR = 1, DFU_FS_FAT, DFU_FS_EXT2, DFU_FS_EXT3, DFU_FS_EXT4, |
a9479f043 dfu: ram support |
35 |
DFU_RAM_ADDR, |
f22b11c10 dfu: DFU backend ... |
36 |
}; |
5a127c843 dfu: unify mmc/na... |
37 38 39 |
enum dfu_op { DFU_OP_READ = 1, DFU_OP_WRITE, |
0e285b503 dfu: fix some iss... |
40 |
DFU_OP_SIZE, |
5a127c843 dfu: unify mmc/na... |
41 |
}; |
f22b11c10 dfu: DFU backend ... |
42 |
struct mmc_internal_data { |
dd64827eb dfu: defer parsin... |
43 |
int dev_num; |
f22b11c10 dfu: DFU backend ... |
44 45 46 47 |
/* RAW programming */ unsigned int lba_start; unsigned int lba_size; unsigned int lba_blk_size; |
c8151b4a5 dfu: mmc: Provide... |
48 49 |
/* eMMC HW partition access */ int hw_partition; |
f22b11c10 dfu: DFU backend ... |
50 51 52 53 |
/* FAT/EXT */ unsigned int dev; unsigned int part; }; |
6015af28e dfu: add backend ... |
54 55 56 57 58 59 |
struct mtd_internal_data { struct mtd_info *info; /* RAW programming */ u64 start; u64 size; |
d5640f700 dfu: add partitio... |
60 61 |
/* for ubi partition */ unsigned int ubi; |
6015af28e dfu: add backend ... |
62 |
}; |
c6631764c dfu: NAND specifi... |
63 64 65 66 67 68 69 |
struct nand_internal_data { /* RAW programming */ u64 start; u64 size; unsigned int dev; unsigned int part; |
815c30b2b dfu, nand, ubi: a... |
70 71 |
/* for nand/ubi use */ unsigned int ubi; |
c6631764c dfu: NAND specifi... |
72 |
}; |
a9479f043 dfu: ram support |
73 74 75 76 |
struct ram_internal_data { void *start; unsigned int size; }; |
6f12ebf6e dfu: add SF backend |
77 78 79 80 81 82 |
struct sf_internal_data { struct spi_flash *dev; /* RAW programming */ u64 start; u64 size; |
cb986ba0f dfu: sf: add part... |
83 84 |
/* for sf/ubi use */ unsigned int ubi; |
6f12ebf6e dfu: add SF backend |
85 |
}; |
ec44cace4 dfu: add DFU virt... |
86 87 88 |
struct virt_internal_data { int dev_num; }; |
a24c3155d dfu: Change inden... |
89 |
#define DFU_NAME_SIZE 32 |
e7e75c70c dfu: make data bu... |
90 91 92 |
#ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE #define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */ #endif |
ea2453d56 dfu: Support larg... |
93 |
#ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE |
7a813d5b7 dfu: Make maximum... |
94 |
#define CONFIG_SYS_DFU_MAX_FILE_SIZE CONFIG_SYS_DFU_DATA_BUF_SIZE |
ea2453d56 dfu: Support larg... |
95 |
#endif |
33fac4a6a usb: dfu: f_dfu: ... |
96 97 98 |
#ifndef DFU_DEFAULT_POLL_TIMEOUT #define DFU_DEFAULT_POLL_TIMEOUT 0 #endif |
001a83198 usb: dfu: introdu... |
99 100 101 |
#ifndef DFU_MANIFEST_POLL_TIMEOUT #define DFU_MANIFEST_POLL_TIMEOUT DFU_DEFAULT_POLL_TIMEOUT #endif |
f22b11c10 dfu: DFU backend ... |
102 103 104 105 106 |
struct dfu_entity { char name[DFU_NAME_SIZE]; int alt; void *dev_private; |
f22b11c10 dfu: DFU backend ... |
107 108 |
enum dfu_device_type dev_type; enum dfu_layout layout; |
7ac1b410a dfu: allow backen... |
109 |
unsigned long max_buf_size; |
f22b11c10 dfu: DFU backend ... |
110 111 112 |
union { struct mmc_internal_data mmc; |
6015af28e dfu: add backend ... |
113 |
struct mtd_internal_data mtd; |
c6631764c dfu: NAND specifi... |
114 |
struct nand_internal_data nand; |
a9479f043 dfu: ram support |
115 |
struct ram_internal_data ram; |
6f12ebf6e dfu: add SF backend |
116 |
struct sf_internal_data sf; |
ec44cace4 dfu: add DFU virt... |
117 |
struct virt_internal_data virt; |
f22b11c10 dfu: DFU backend ... |
118 |
} data; |
15970d871 dfu: remove limit... |
119 |
int (*get_medium_size)(struct dfu_entity *dfu, u64 *size); |
0e285b503 dfu: fix some iss... |
120 |
|
ea2453d56 dfu: Support larg... |
121 122 123 124 125 126 127 |
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 dfu, nand: add me... |
128 |
unsigned int (*poll_timeout)(struct dfu_entity *dfu); |
f22b11c10 dfu: DFU backend ... |
129 |
|
cb7bd2e07 dfu: add free_ent... |
130 |
void (*free_entity)(struct dfu_entity *dfu); |
f22b11c10 dfu: DFU backend ... |
131 |
struct list_head list; |
ea2453d56 dfu: Support larg... |
132 133 134 135 136 137 138 139 |
/* on the fly state */ u32 crc; u64 offset; int i_blk_seq_num; u8 *i_buf; u8 *i_buf_start; u8 *i_buf_end; |
15970d871 dfu: remove limit... |
140 |
u64 r_left; |
ea2453d56 dfu: Support larg... |
141 |
long b_left; |
c6631764c dfu: NAND specifi... |
142 |
u32 bad_skip; /* for nand use */ |
ea2453d56 dfu: Support larg... |
143 |
unsigned int inited:1; |
f22b11c10 dfu: DFU backend ... |
144 |
}; |
899a52821 dfu: samsung: mov... |
145 146 147 |
#ifdef CONFIG_SET_DFU_ALT_INFO void set_dfu_alt_info(char *interface, char *devstr); #endif |
9ada68305 dfu: prepare the ... |
148 149 |
int dfu_alt_init(int num, struct dfu_entity **dfu); int dfu_alt_add(struct dfu_entity *dfu, char *interface, char *devstr, char *s); |
dd64827eb dfu: defer parsin... |
150 |
int dfu_config_entities(char *s, char *interface, char *devstr); |
f22b11c10 dfu: DFU backend ... |
151 152 153 154 155 156 157 |
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); |
fed936ed8 dfu:core: Find DF... |
158 |
int dfu_get_alt(char *name); |
dd64827eb dfu: defer parsin... |
159 |
int dfu_init_env_entities(char *interface, char *devstr); |
7ac1b410a dfu: allow backen... |
160 |
unsigned char *dfu_get_buf(struct dfu_entity *dfu); |
d42782631 dfu:core: Export ... |
161 |
unsigned char *dfu_free_buf(void); |
4fb127898 dfu: Export alloc... |
162 |
unsigned long dfu_get_buf_size(void); |
1cc03c5c5 dfu: Provide mean... |
163 |
bool dfu_usb_get_reset(void); |
f22b11c10 dfu: DFU backend ... |
164 |
|
98a8f445f dfu: Add optional... |
165 166 167 168 |
#ifdef CONFIG_DFU_TIMEOUT unsigned long dfu_get_timeout(void); void dfu_set_timeout(unsigned long); #endif |
f22b11c10 dfu: DFU backend ... |
169 170 |
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 usb, dfu: extract... |
171 |
int dfu_flush(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |
2092e4610 dfu: tftp: update... |
172 |
|
067c13c70 dfu: add callback... |
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
/** * dfu_initiated_callback - weak callback called on DFU transaction start * * It is a callback function called by DFU stack when a DFU transaction is * initiated. This function allows to manage some board specific behavior on * DFU targets. * * @param dfu - pointer to the dfu_entity, which should be initialized * */ void dfu_initiated_callback(struct dfu_entity *dfu); /** * dfu_flush_callback - weak callback called at the end of the DFU write * * It is a callback function called by DFU stack after DFU manifestation. * This function allows to manage some board specific behavior on DFU targets * * @param dfu - pointer to the dfu_entity, which should be flushed * */ void dfu_flush_callback(struct dfu_entity *dfu); |
fc18f8d17 dfu: usb: f_dfu: ... |
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
/* * dfu_defer_flush - pointer to store dfu_entity for deferred flashing. * It should be NULL when not used. */ extern struct dfu_entity *dfu_defer_flush; /** * dfu_get_defer_flush - get current value of dfu_defer_flush pointer * * @return - value of the dfu_defer_flush pointer */ static inline struct dfu_entity *dfu_get_defer_flush(void) { return dfu_defer_flush; } /** * dfu_set_defer_flush - set the dfu_defer_flush pointer * * @param dfu - pointer to the dfu_entity, which should be written */ static inline void dfu_set_defer_flush(struct dfu_entity *dfu) { dfu_defer_flush = dfu; } |
2092e4610 dfu: tftp: update... |
218 219 220 221 222 223 224 225 226 227 228 229 230 |
/** * dfu_write_from_mem_addr - write data from memory to DFU managed medium * * This function adds support for writing data starting from fixed memory * address (like $loadaddr) to dfu managed medium (e.g. NAND, MMC, file system) * * @param dfu - dfu entity to which we want to store data * @param buf - fixed memory addres from where data starts * @param size - number of bytes to write * * @return - 0 on success, other value on failure */ int dfu_write_from_mem_addr(struct dfu_entity *dfu, void *buf, int size); |
f22b11c10 dfu: DFU backend ... |
231 |
/* Device specific */ |
2d59ec848 dfu: Make DFU sup... |
232 |
#if CONFIG_IS_ENABLED(DFU_MMC) |
dd64827eb dfu: defer parsin... |
233 |
extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s); |
f22b11c10 dfu: DFU backend ... |
234 |
#else |
dd64827eb dfu: defer parsin... |
235 236 |
static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s) |
f22b11c10 dfu: DFU backend ... |
237 238 239 240 241 242 |
{ puts("MMC support not available! "); return -1; } #endif |
c6631764c dfu: NAND specifi... |
243 |
|
2d59ec848 dfu: Make DFU sup... |
244 |
#if CONFIG_IS_ENABLED(DFU_NAND) |
dd64827eb dfu: defer parsin... |
245 |
extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s); |
c6631764c dfu: NAND specifi... |
246 |
#else |
dd64827eb dfu: defer parsin... |
247 248 |
static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s) |
c6631764c dfu: NAND specifi... |
249 250 251 252 253 254 |
{ puts("NAND support not available! "); return -1; } #endif |
2d59ec848 dfu: Make DFU sup... |
255 |
#if CONFIG_IS_ENABLED(DFU_RAM) |
dd64827eb dfu: defer parsin... |
256 |
extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s); |
a9479f043 dfu: ram support |
257 |
#else |
dd64827eb dfu: defer parsin... |
258 259 |
static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s) |
a9479f043 dfu: ram support |
260 261 262 263 264 265 |
{ puts("RAM support not available! "); return -1; } #endif |
2d59ec848 dfu: Make DFU sup... |
266 |
#if CONFIG_IS_ENABLED(DFU_SF) |
6f12ebf6e dfu: add SF backend |
267 268 269 270 271 272 273 274 275 276 |
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 |
6015af28e dfu: add backend ... |
277 278 279 280 281 282 283 284 285 286 287 |
#if CONFIG_IS_ENABLED(DFU_MTD) int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s); #else static inline int dfu_fill_entity_mtd(struct dfu_entity *dfu, char *devstr, char *s) { puts("MTD support not available! "); return -1; } #endif |
ec44cace4 dfu: add DFU virt... |
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
#ifdef CONFIG_DFU_VIRT int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char *s); int dfu_write_medium_virt(struct dfu_entity *dfu, u64 offset, void *buf, long *len); int dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size); int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset, void *buf, long *len); #else static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char *s) { puts("VIRT support not available! "); return -1; } #endif |
2d50d68a4 dfu: tftp: update... |
304 305 306 307 308 309 310 311 312 313 314 315 316 |
/** * dfu_tftp_write - Write TFTP data to DFU medium * * This function is storing data received via TFTP on DFU supported medium. * * @param dfu_entity_name - name of DFU entity to write * @param addr - address of data buffer to write * @param len - number of bytes * @param interface - destination DFU medium (e.g. "mmc") * @param devstring - instance number of destination DFU medium (e.g. "1") * * @return 0 on success, otherwise error code */ |
2d59ec848 dfu: Make DFU sup... |
317 |
#if CONFIG_IS_ENABLED(DFU_TFTP) |
2d50d68a4 dfu: tftp: update... |
318 319 320 321 322 323 324 325 326 327 328 329 |
int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len, char *interface, char *devstring); #else static inline int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len, char *interface, char *devstring) { puts("TFTP write support for DFU not available! "); return -ENOSYS; } #endif |
a6921adcf usb:g_dnl:dfu: Do... |
330 |
int dfu_add(struct usb_configuration *c); |
f22b11c10 dfu: DFU backend ... |
331 |
#endif /* __DFU_ENTITY_H_ */ |