Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 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 | |
Afzal Mohammed | 5a127c8 | 2013-09-18 01:14:50 +0530 | [diff] [blame^] | 32 | enum dfu_op { |
| 33 | DFU_OP_READ = 1, |
| 34 | DFU_OP_WRITE, |
| 35 | }; |
| 36 | |
Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 37 | struct mmc_internal_data { |
| 38 | /* RAW programming */ |
| 39 | unsigned int lba_start; |
| 40 | unsigned int lba_size; |
| 41 | unsigned int lba_blk_size; |
| 42 | |
| 43 | /* FAT/EXT */ |
| 44 | unsigned int dev; |
| 45 | unsigned int part; |
| 46 | }; |
| 47 | |
Pantelis Antoniou | c663176 | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 48 | struct nand_internal_data { |
| 49 | /* RAW programming */ |
| 50 | u64 start; |
| 51 | u64 size; |
| 52 | |
| 53 | unsigned int dev; |
| 54 | unsigned int part; |
Heiko Schocher | 815c30b | 2013-07-25 06:43:11 +0200 | [diff] [blame] | 55 | /* for nand/ubi use */ |
| 56 | unsigned int ubi; |
Pantelis Antoniou | c663176 | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 59 | static inline unsigned int get_mmc_blk_size(int dev) |
| 60 | { |
| 61 | return find_mmc_device(dev)->read_bl_len; |
| 62 | } |
| 63 | |
Tom Rini | a24c315 | 2013-03-14 05:32:49 +0000 | [diff] [blame] | 64 | #define DFU_NAME_SIZE 32 |
| 65 | #define DFU_CMD_BUF_SIZE 128 |
Heiko Schocher | e7e75c7 | 2013-06-12 06:05:51 +0200 | [diff] [blame] | 66 | #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE |
| 67 | #define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */ |
| 68 | #endif |
Pantelis Antoniou | ea2453d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 69 | #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE |
Lukasz Majewski | 7a813d5 | 2013-09-10 15:29:23 +0200 | [diff] [blame] | 70 | #define CONFIG_SYS_DFU_MAX_FILE_SIZE CONFIG_SYS_DFU_DATA_BUF_SIZE |
Pantelis Antoniou | ea2453d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 71 | #endif |
Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 72 | |
| 73 | struct dfu_entity { |
| 74 | char name[DFU_NAME_SIZE]; |
| 75 | int alt; |
| 76 | void *dev_private; |
| 77 | int dev_num; |
| 78 | enum dfu_device_type dev_type; |
| 79 | enum dfu_layout layout; |
| 80 | |
| 81 | union { |
| 82 | struct mmc_internal_data mmc; |
Pantelis Antoniou | c663176 | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 83 | struct nand_internal_data nand; |
Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 84 | } data; |
| 85 | |
Pantelis Antoniou | ea2453d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 86 | int (*read_medium)(struct dfu_entity *dfu, |
| 87 | u64 offset, void *buf, long *len); |
| 88 | |
| 89 | int (*write_medium)(struct dfu_entity *dfu, |
| 90 | u64 offset, void *buf, long *len); |
| 91 | |
| 92 | int (*flush_medium)(struct dfu_entity *dfu); |
Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 93 | |
| 94 | struct list_head list; |
Pantelis Antoniou | ea2453d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 95 | |
| 96 | /* on the fly state */ |
| 97 | u32 crc; |
| 98 | u64 offset; |
| 99 | int i_blk_seq_num; |
| 100 | u8 *i_buf; |
| 101 | u8 *i_buf_start; |
| 102 | u8 *i_buf_end; |
| 103 | long r_left; |
| 104 | long b_left; |
| 105 | |
Pantelis Antoniou | c663176 | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 106 | u32 bad_skip; /* for nand use */ |
| 107 | |
Pantelis Antoniou | ea2453d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 108 | unsigned int inited:1; |
Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | int dfu_config_entities(char *s, char *interface, int num); |
| 112 | void dfu_free_entities(void); |
| 113 | void dfu_show_entities(void); |
| 114 | int dfu_get_alt_number(void); |
| 115 | const char *dfu_get_dev_type(enum dfu_device_type t); |
| 116 | const char *dfu_get_layout(enum dfu_layout l); |
| 117 | struct dfu_entity *dfu_get_entity(int alt); |
| 118 | char *dfu_extract_token(char** e, int *n); |
Lukasz Majewski | 6bed7ce | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 119 | void dfu_trigger_reset(void); |
| 120 | bool dfu_reset(void); |
Lukasz Majewski | 765c5ae | 2013-09-11 14:53:35 +0200 | [diff] [blame] | 121 | int dfu_init_env_entities(char *interface, int dev); |
Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 122 | |
| 123 | int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |
| 124 | int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |
| 125 | /* Device specific */ |
| 126 | #ifdef CONFIG_DFU_MMC |
| 127 | extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s); |
| 128 | #else |
| 129 | static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s) |
| 130 | { |
| 131 | puts("MMC support not available!\n"); |
| 132 | return -1; |
| 133 | } |
| 134 | #endif |
Pantelis Antoniou | c663176 | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 135 | |
| 136 | #ifdef CONFIG_DFU_NAND |
| 137 | extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s); |
| 138 | #else |
| 139 | static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s) |
| 140 | { |
| 141 | puts("NAND support not available!\n"); |
| 142 | return -1; |
| 143 | } |
| 144 | #endif |
| 145 | |
Lukasz Majewski | f22b11c | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 146 | #endif /* __DFU_ENTITY_H_ */ |