]> git.ipfire.org Git - people/ms/u-boot.git/blob - include/dfu.h
dfu: ram support
[people/ms/u-boot.git] / include / dfu.h
1 /*
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 *
8 * SPDX-License-Identifier: GPL-2.0+
9 */
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
18 enum dfu_device_type {
19 DFU_DEV_MMC = 1,
20 DFU_DEV_ONENAND,
21 DFU_DEV_NAND,
22 DFU_DEV_RAM,
23 };
24
25 enum dfu_layout {
26 DFU_RAW_ADDR = 1,
27 DFU_FS_FAT,
28 DFU_FS_EXT2,
29 DFU_FS_EXT3,
30 DFU_FS_EXT4,
31 DFU_RAM_ADDR,
32 };
33
34 enum dfu_op {
35 DFU_OP_READ = 1,
36 DFU_OP_WRITE,
37 };
38
39 struct mmc_internal_data {
40 /* RAW programming */
41 unsigned int lba_start;
42 unsigned int lba_size;
43 unsigned int lba_blk_size;
44
45 /* FAT/EXT */
46 unsigned int dev;
47 unsigned int part;
48 };
49
50 struct nand_internal_data {
51 /* RAW programming */
52 u64 start;
53 u64 size;
54
55 unsigned int dev;
56 unsigned int part;
57 /* for nand/ubi use */
58 unsigned int ubi;
59 };
60
61 struct ram_internal_data {
62 void *start;
63 unsigned int size;
64 };
65
66 static inline unsigned int get_mmc_blk_size(int dev)
67 {
68 return find_mmc_device(dev)->read_bl_len;
69 }
70
71 #define DFU_NAME_SIZE 32
72 #define DFU_CMD_BUF_SIZE 128
73 #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
74 #define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */
75 #endif
76 #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
77 #define CONFIG_SYS_DFU_MAX_FILE_SIZE CONFIG_SYS_DFU_DATA_BUF_SIZE
78 #endif
79
80 struct dfu_entity {
81 char name[DFU_NAME_SIZE];
82 int alt;
83 void *dev_private;
84 int dev_num;
85 enum dfu_device_type dev_type;
86 enum dfu_layout layout;
87
88 union {
89 struct mmc_internal_data mmc;
90 struct nand_internal_data nand;
91 struct ram_internal_data ram;
92 } data;
93
94 int (*read_medium)(struct dfu_entity *dfu,
95 u64 offset, void *buf, long *len);
96
97 int (*write_medium)(struct dfu_entity *dfu,
98 u64 offset, void *buf, long *len);
99
100 int (*flush_medium)(struct dfu_entity *dfu);
101
102 struct list_head list;
103
104 /* on the fly state */
105 u32 crc;
106 u64 offset;
107 int i_blk_seq_num;
108 u8 *i_buf;
109 u8 *i_buf_start;
110 u8 *i_buf_end;
111 long r_left;
112 long b_left;
113
114 u32 bad_skip; /* for nand use */
115
116 unsigned int inited:1;
117 };
118
119 int dfu_config_entities(char *s, char *interface, int num);
120 void dfu_free_entities(void);
121 void dfu_show_entities(void);
122 int dfu_get_alt_number(void);
123 const char *dfu_get_dev_type(enum dfu_device_type t);
124 const char *dfu_get_layout(enum dfu_layout l);
125 struct dfu_entity *dfu_get_entity(int alt);
126 char *dfu_extract_token(char** e, int *n);
127 void dfu_trigger_reset(void);
128 bool dfu_reset(void);
129 int dfu_init_env_entities(char *interface, int dev);
130
131 int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
132 int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
133 /* Device specific */
134 #ifdef CONFIG_DFU_MMC
135 extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s);
136 #else
137 static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
138 {
139 puts("MMC support not available!\n");
140 return -1;
141 }
142 #endif
143
144 #ifdef CONFIG_DFU_NAND
145 extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
146 #else
147 static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
148 {
149 puts("NAND support not available!\n");
150 return -1;
151 }
152 #endif
153
154 #ifdef CONFIG_DFU_RAM
155 extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s);
156 #else
157 static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s)
158 {
159 puts("RAM support not available!\n");
160 return -1;
161 }
162 #endif
163
164 #endif /* __DFU_ENTITY_H_ */