blob: 6f4bba455b131016c1d5c0de213106101002e85a [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,
Afzal Mohammede3c687a2013-09-18 01:15:24 +053022 DFU_DEV_RAM,
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020023};
24
25enum dfu_layout {
26 DFU_RAW_ADDR = 1,
27 DFU_FS_FAT,
28 DFU_FS_EXT2,
29 DFU_FS_EXT3,
30 DFU_FS_EXT4,
Afzal Mohammede3c687a2013-09-18 01:15:24 +053031 DFU_RAM_ADDR,
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020032};
33
Afzal Mohammedb9a4a6b2013-09-18 01:14:50 +053034enum dfu_op {
35 DFU_OP_READ = 1,
36 DFU_OP_WRITE,
37};
38
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020039struct 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
Pantelis Antonioucf14d0d2013-03-14 05:32:52 +000050struct nand_internal_data {
51 /* RAW programming */
52 u64 start;
53 u64 size;
54
55 unsigned int dev;
56 unsigned int part;
Heiko Schocherad401392013-07-25 06:43:11 +020057 /* for nand/ubi use */
58 unsigned int ubi;
Pantelis Antonioucf14d0d2013-03-14 05:32:52 +000059};
60
Afzal Mohammede3c687a2013-09-18 01:15:24 +053061struct ram_internal_data {
62 void *start;
63 unsigned int size;
64};
65
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020066static inline unsigned int get_mmc_blk_size(int dev)
67{
68 return find_mmc_device(dev)->read_bl_len;
69}
70
Tom Rini7384b5a2013-03-14 05:32:49 +000071#define DFU_NAME_SIZE 32
72#define DFU_CMD_BUF_SIZE 128
Heiko Schochera2f831e2013-06-12 06:05:51 +020073#ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
74#define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */
75#endif
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000076#ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
Lukasz Majewski3dda2202013-09-10 15:29:23 +020077#define CONFIG_SYS_DFU_MAX_FILE_SIZE CONFIG_SYS_DFU_DATA_BUF_SIZE
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000078#endif
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020079
80struct 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;
Pantelis Antonioucf14d0d2013-03-14 05:32:52 +000090 struct nand_internal_data nand;
Afzal Mohammede3c687a2013-09-18 01:15:24 +053091 struct ram_internal_data ram;
Lukasz Majewskid311c6e2012-08-06 14:41:07 +020092 } data;
93
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000094 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);
Lukasz Majewskid311c6e2012-08-06 14:41:07 +0200101
102 struct list_head list;
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000103
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
Pantelis Antonioucf14d0d2013-03-14 05:32:52 +0000114 u32 bad_skip; /* for nand use */
115
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000116 unsigned int inited:1;
Lukasz Majewskid311c6e2012-08-06 14:41:07 +0200117};
118
119int dfu_config_entities(char *s, char *interface, int num);
120void dfu_free_entities(void);
121void dfu_show_entities(void);
122int dfu_get_alt_number(void);
123const char *dfu_get_dev_type(enum dfu_device_type t);
124const char *dfu_get_layout(enum dfu_layout l);
125struct dfu_entity *dfu_get_entity(int alt);
126char *dfu_extract_token(char** e, int *n);
Lukasz Majewski2968aa22013-07-18 13:19:14 +0200127void dfu_trigger_reset(void);
128bool dfu_reset(void);
Lukasz Majewski35e591e2013-09-11 14:53:35 +0200129int dfu_init_env_entities(char *interface, int dev);
Lukasz Majewskid311c6e2012-08-06 14:41:07 +0200130
131int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
132int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
133/* Device specific */
134#ifdef CONFIG_DFU_MMC
135extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s);
136#else
137static 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
Pantelis Antonioucf14d0d2013-03-14 05:32:52 +0000143
144#ifdef CONFIG_DFU_NAND
145extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
146#else
147static 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
Afzal Mohammede3c687a2013-09-18 01:15:24 +0530154#ifdef CONFIG_DFU_RAM
155extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s);
156#else
157static 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
Lukasz Majewskid311c6e2012-08-06 14:41:07 +0200164#endif /* __DFU_ENTITY_H_ */