blob: 7779710aafc9e97f49a76a57e14f2dd3eb8d1252 [file] [log] [blame]
Lukasz Majewskif22b11c2012-08-06 14:41:07 +02001/*
2 * dfu.h - DFU flashable area description
3 *
4 * Copyright (C) 2012 Samsung Electronics
5 * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
6 * Lukasz Majewski <l.majewski@samsung.com>
7 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskif22b11c2012-08-06 14:41:07 +02009 */
10
11#ifndef __DFU_ENTITY_H_
12#define __DFU_ENTITY_H_
13
14#include <common.h>
15#include <linux/list.h>
16#include <mmc.h>
17
18enum dfu_device_type {
19 DFU_DEV_MMC = 1,
20 DFU_DEV_ONENAND,
21 DFU_DEV_NAND,
22};
23
24enum dfu_layout {
25 DFU_RAW_ADDR = 1,
26 DFU_FS_FAT,
27 DFU_FS_EXT2,
28 DFU_FS_EXT3,
29 DFU_FS_EXT4,
30};
31
32struct mmc_internal_data {
33 /* RAW programming */
34 unsigned int lba_start;
35 unsigned int lba_size;
36 unsigned int lba_blk_size;
37
38 /* FAT/EXT */
39 unsigned int dev;
40 unsigned int part;
41};
42
Pantelis Antoniouc6631762013-03-14 05:32:52 +000043struct nand_internal_data {
44 /* RAW programming */
45 u64 start;
46 u64 size;
47
48 unsigned int dev;
49 unsigned int part;
Heiko Schocher815c30b2013-07-25 06:43:11 +020050 /* for nand/ubi use */
51 unsigned int ubi;
Pantelis Antoniouc6631762013-03-14 05:32:52 +000052};
53
Lukasz Majewskif22b11c2012-08-06 14:41:07 +020054static inline unsigned int get_mmc_blk_size(int dev)
55{
56 return find_mmc_device(dev)->read_bl_len;
57}
58
Tom Rinia24c3152013-03-14 05:32:49 +000059#define DFU_NAME_SIZE 32
60#define DFU_CMD_BUF_SIZE 128
Heiko Schochere7e75c72013-06-12 06:05:51 +020061#ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
62#define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */
63#endif
Pantelis Antoniouea2453d2013-03-14 05:32:48 +000064#ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
Lukasz Majewski7a813d52013-09-10 15:29:23 +020065#define CONFIG_SYS_DFU_MAX_FILE_SIZE CONFIG_SYS_DFU_DATA_BUF_SIZE
Pantelis Antoniouea2453d2013-03-14 05:32:48 +000066#endif
Lukasz Majewskif22b11c2012-08-06 14:41:07 +020067
68struct dfu_entity {
69 char name[DFU_NAME_SIZE];
70 int alt;
71 void *dev_private;
72 int dev_num;
73 enum dfu_device_type dev_type;
74 enum dfu_layout layout;
75
76 union {
77 struct mmc_internal_data mmc;
Pantelis Antoniouc6631762013-03-14 05:32:52 +000078 struct nand_internal_data nand;
Lukasz Majewskif22b11c2012-08-06 14:41:07 +020079 } data;
80
Pantelis Antoniouea2453d2013-03-14 05:32:48 +000081 int (*read_medium)(struct dfu_entity *dfu,
82 u64 offset, void *buf, long *len);
83
84 int (*write_medium)(struct dfu_entity *dfu,
85 u64 offset, void *buf, long *len);
86
87 int (*flush_medium)(struct dfu_entity *dfu);
Lukasz Majewskif22b11c2012-08-06 14:41:07 +020088
89 struct list_head list;
Pantelis Antoniouea2453d2013-03-14 05:32:48 +000090
91 /* on the fly state */
92 u32 crc;
93 u64 offset;
94 int i_blk_seq_num;
95 u8 *i_buf;
96 u8 *i_buf_start;
97 u8 *i_buf_end;
98 long r_left;
99 long b_left;
100
Pantelis Antoniouc6631762013-03-14 05:32:52 +0000101 u32 bad_skip; /* for nand use */
102
Pantelis Antoniouea2453d2013-03-14 05:32:48 +0000103 unsigned int inited:1;
Lukasz Majewskif22b11c2012-08-06 14:41:07 +0200104};
105
106int dfu_config_entities(char *s, char *interface, int num);
107void dfu_free_entities(void);
108void dfu_show_entities(void);
109int dfu_get_alt_number(void);
110const char *dfu_get_dev_type(enum dfu_device_type t);
111const char *dfu_get_layout(enum dfu_layout l);
112struct dfu_entity *dfu_get_entity(int alt);
113char *dfu_extract_token(char** e, int *n);
Lukasz Majewski6bed7ce2013-07-18 13:19:14 +0200114void dfu_trigger_reset(void);
115bool dfu_reset(void);
Lukasz Majewskif22b11c2012-08-06 14:41:07 +0200116
117int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
118int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
119/* Device specific */
120#ifdef CONFIG_DFU_MMC
121extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s);
122#else
123static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
124{
125 puts("MMC support not available!\n");
126 return -1;
127}
128#endif
Pantelis Antoniouc6631762013-03-14 05:32:52 +0000129
130#ifdef CONFIG_DFU_NAND
131extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
132#else
133static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
134{
135 puts("NAND support not available!\n");
136 return -1;
137}
138#endif
139
Lukasz Majewskif22b11c2012-08-06 14:41:07 +0200140#endif /* __DFU_ENTITY_H_ */