]> git.ipfire.org Git - people/ms/u-boot.git/blob - include/dfu.h
Merge branch 'u-boot-imx/master' into 'u-boot-arm/master'
[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 };
23
24 enum 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
32 struct 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
43 struct nand_internal_data {
44 /* RAW programming */
45 u64 start;
46 u64 size;
47
48 unsigned int dev;
49 unsigned int part;
50 /* for nand/ubi use */
51 unsigned int ubi;
52 };
53
54 static inline unsigned int get_mmc_blk_size(int dev)
55 {
56 return find_mmc_device(dev)->read_bl_len;
57 }
58
59 #define DFU_NAME_SIZE 32
60 #define DFU_CMD_BUF_SIZE 128
61 #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
62 #define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */
63 #endif
64 #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
65 #define CONFIG_SYS_DFU_MAX_FILE_SIZE (4 << 20) /* 4 MiB */
66 #endif
67
68 struct 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;
78 struct nand_internal_data nand;
79 } data;
80
81 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);
88
89 struct list_head list;
90
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
101 u32 bad_skip; /* for nand use */
102
103 unsigned int inited:1;
104 };
105
106 int dfu_config_entities(char *s, char *interface, int num);
107 void dfu_free_entities(void);
108 void dfu_show_entities(void);
109 int dfu_get_alt_number(void);
110 const char *dfu_get_dev_type(enum dfu_device_type t);
111 const char *dfu_get_layout(enum dfu_layout l);
112 struct dfu_entity *dfu_get_entity(int alt);
113 char *dfu_extract_token(char** e, int *n);
114 void dfu_trigger_reset(void);
115 bool dfu_reset(void);
116
117 int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
118 int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
119 /* Device specific */
120 #ifdef CONFIG_DFU_MMC
121 extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s);
122 #else
123 static 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
129
130 #ifdef CONFIG_DFU_NAND
131 extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
132 #else
133 static 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
140 #endif /* __DFU_ENTITY_H_ */