blob: 6c7d2271371ebfb4f8c2dd52dab8f904e769d920 [file] [log] [blame]
Lukasz Majewskid311c6e2012-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 Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskid311c6e2012-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 Antonioucf14d0d2013-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;
50};
51
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020052static inline unsigned int get_mmc_blk_size(int dev)
53{
54 return find_mmc_device(dev)->read_bl_len;
55}
56
Tom Rini7384b5a2013-03-14 05:32:49 +000057#define DFU_NAME_SIZE 32
58#define DFU_CMD_BUF_SIZE 128
Heiko Schochera2f831e2013-06-12 06:05:51 +020059#ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
60#define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */
61#endif
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000062#ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
63#define CONFIG_SYS_DFU_MAX_FILE_SIZE (4 << 20) /* 4 MiB */
64#endif
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020065
66struct dfu_entity {
67 char name[DFU_NAME_SIZE];
68 int alt;
69 void *dev_private;
70 int dev_num;
71 enum dfu_device_type dev_type;
72 enum dfu_layout layout;
73
74 union {
75 struct mmc_internal_data mmc;
Pantelis Antonioucf14d0d2013-03-14 05:32:52 +000076 struct nand_internal_data nand;
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020077 } data;
78
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000079 int (*read_medium)(struct dfu_entity *dfu,
80 u64 offset, void *buf, long *len);
81
82 int (*write_medium)(struct dfu_entity *dfu,
83 u64 offset, void *buf, long *len);
84
85 int (*flush_medium)(struct dfu_entity *dfu);
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020086
87 struct list_head list;
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000088
89 /* on the fly state */
90 u32 crc;
91 u64 offset;
92 int i_blk_seq_num;
93 u8 *i_buf;
94 u8 *i_buf_start;
95 u8 *i_buf_end;
96 long r_left;
97 long b_left;
98
Pantelis Antonioucf14d0d2013-03-14 05:32:52 +000099 u32 bad_skip; /* for nand use */
100
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000101 unsigned int inited:1;
Lukasz Majewskid311c6e2012-08-06 14:41:07 +0200102};
103
104int dfu_config_entities(char *s, char *interface, int num);
105void dfu_free_entities(void);
106void dfu_show_entities(void);
107int dfu_get_alt_number(void);
108const char *dfu_get_dev_type(enum dfu_device_type t);
109const char *dfu_get_layout(enum dfu_layout l);
110struct dfu_entity *dfu_get_entity(int alt);
111char *dfu_extract_token(char** e, int *n);
112
113int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
114int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
115/* Device specific */
116#ifdef CONFIG_DFU_MMC
117extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s);
118#else
119static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
120{
121 puts("MMC support not available!\n");
122 return -1;
123}
124#endif
Pantelis Antonioucf14d0d2013-03-14 05:32:52 +0000125
126#ifdef CONFIG_DFU_NAND
127extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
128#else
129static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
130{
131 puts("NAND support not available!\n");
132 return -1;
133}
134#endif
135
Lukasz Majewskid311c6e2012-08-06 14:41:07 +0200136#endif /* __DFU_ENTITY_H_ */