Lukasz Majewski | d311c6e | 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 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #ifndef __DFU_ENTITY_H_ |
| 24 | #define __DFU_ENTITY_H_ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <linux/list.h> |
| 28 | #include <mmc.h> |
| 29 | |
| 30 | enum dfu_device_type { |
| 31 | DFU_DEV_MMC = 1, |
| 32 | DFU_DEV_ONENAND, |
| 33 | DFU_DEV_NAND, |
| 34 | }; |
| 35 | |
| 36 | enum dfu_layout { |
| 37 | DFU_RAW_ADDR = 1, |
| 38 | DFU_FS_FAT, |
| 39 | DFU_FS_EXT2, |
| 40 | DFU_FS_EXT3, |
| 41 | DFU_FS_EXT4, |
| 42 | }; |
| 43 | |
| 44 | struct mmc_internal_data { |
| 45 | /* RAW programming */ |
| 46 | unsigned int lba_start; |
| 47 | unsigned int lba_size; |
| 48 | unsigned int lba_blk_size; |
| 49 | |
| 50 | /* FAT/EXT */ |
| 51 | unsigned int dev; |
| 52 | unsigned int part; |
| 53 | }; |
| 54 | |
Pantelis Antoniou | cf14d0d | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 55 | struct nand_internal_data { |
| 56 | /* RAW programming */ |
| 57 | u64 start; |
| 58 | u64 size; |
| 59 | |
| 60 | unsigned int dev; |
| 61 | unsigned int part; |
| 62 | }; |
| 63 | |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 64 | static inline unsigned int get_mmc_blk_size(int dev) |
| 65 | { |
| 66 | return find_mmc_device(dev)->read_bl_len; |
| 67 | } |
| 68 | |
Tom Rini | 7384b5a | 2013-03-14 05:32:49 +0000 | [diff] [blame] | 69 | #define DFU_NAME_SIZE 32 |
| 70 | #define DFU_CMD_BUF_SIZE 128 |
| 71 | #define DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */ |
Pantelis Antoniou | a6e788d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 72 | #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE |
| 73 | #define CONFIG_SYS_DFU_MAX_FILE_SIZE (4 << 20) /* 4 MiB */ |
| 74 | #endif |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 75 | |
| 76 | struct dfu_entity { |
| 77 | char name[DFU_NAME_SIZE]; |
| 78 | int alt; |
| 79 | void *dev_private; |
| 80 | int dev_num; |
| 81 | enum dfu_device_type dev_type; |
| 82 | enum dfu_layout layout; |
| 83 | |
| 84 | union { |
| 85 | struct mmc_internal_data mmc; |
Pantelis Antoniou | cf14d0d | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 86 | struct nand_internal_data nand; |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 87 | } data; |
| 88 | |
Pantelis Antoniou | a6e788d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 89 | int (*read_medium)(struct dfu_entity *dfu, |
| 90 | u64 offset, void *buf, long *len); |
| 91 | |
| 92 | int (*write_medium)(struct dfu_entity *dfu, |
| 93 | u64 offset, void *buf, long *len); |
| 94 | |
| 95 | int (*flush_medium)(struct dfu_entity *dfu); |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 96 | |
| 97 | struct list_head list; |
Pantelis Antoniou | a6e788d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 98 | |
| 99 | /* on the fly state */ |
| 100 | u32 crc; |
| 101 | u64 offset; |
| 102 | int i_blk_seq_num; |
| 103 | u8 *i_buf; |
| 104 | u8 *i_buf_start; |
| 105 | u8 *i_buf_end; |
| 106 | long r_left; |
| 107 | long b_left; |
| 108 | |
Pantelis Antoniou | cf14d0d | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 109 | u32 bad_skip; /* for nand use */ |
| 110 | |
Pantelis Antoniou | a6e788d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 111 | unsigned int inited:1; |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | int dfu_config_entities(char *s, char *interface, int num); |
| 115 | void dfu_free_entities(void); |
| 116 | void dfu_show_entities(void); |
| 117 | int dfu_get_alt_number(void); |
| 118 | const char *dfu_get_dev_type(enum dfu_device_type t); |
| 119 | const char *dfu_get_layout(enum dfu_layout l); |
| 120 | struct dfu_entity *dfu_get_entity(int alt); |
| 121 | char *dfu_extract_token(char** e, int *n); |
| 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 | cf14d0d | 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 | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 146 | #endif /* __DFU_ENTITY_H_ */ |