2 * dfu.h - DFU flashable area description
4 * Copyright (C) 2012 Samsung Electronics
5 * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
6 * Lukasz Majewski <l.majewski@samsung.com>
8 * SPDX-License-Identifier: GPL-2.0+
11 #ifndef __DFU_ENTITY_H_
12 #define __DFU_ENTITY_H_
15 #include <linux/list.h>
18 enum dfu_device_type {
39 struct mmc_internal_data {
41 unsigned int lba_start;
42 unsigned int lba_size;
43 unsigned int lba_blk_size;
50 struct nand_internal_data {
57 /* for nand/ubi use */
61 struct ram_internal_data {
66 static inline unsigned int get_mmc_blk_size(int dev)
68 return find_mmc_device(dev)->read_bl_len;
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 */
76 #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
77 #define CONFIG_SYS_DFU_MAX_FILE_SIZE CONFIG_SYS_DFU_DATA_BUF_SIZE
81 char name[DFU_NAME_SIZE];
85 enum dfu_device_type dev_type;
86 enum dfu_layout layout;
89 struct mmc_internal_data mmc;
90 struct nand_internal_data nand;
91 struct ram_internal_data ram;
94 int (*read_medium)(struct dfu_entity *dfu,
95 u64 offset, void *buf, long *len);
97 int (*write_medium)(struct dfu_entity *dfu,
98 u64 offset, void *buf, long *len);
100 int (*flush_medium)(struct dfu_entity *dfu);
102 struct list_head list;
104 /* on the fly state */
114 u32 bad_skip; /* for nand use */
116 unsigned int inited:1;
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);
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);
137 static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
139 puts("MMC support not available!\n");
144 #ifdef CONFIG_DFU_NAND
145 extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
147 static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
149 puts("NAND support not available!\n");
154 #ifdef CONFIG_DFU_RAM
155 extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s);
157 static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s)
159 puts("RAM support not available!\n");
164 #endif /* __DFU_ENTITY_H_ */