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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | d311c6e | 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 | |
| 32 | struct 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 Antoniou | cf14d0d | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 43 | struct nand_internal_data { |
| 44 | /* RAW programming */ |
| 45 | u64 start; |
| 46 | u64 size; |
| 47 | |
| 48 | unsigned int dev; |
| 49 | unsigned int part; |
| 50 | }; |
| 51 | |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 52 | static inline unsigned int get_mmc_blk_size(int dev) |
| 53 | { |
| 54 | return find_mmc_device(dev)->read_bl_len; |
| 55 | } |
| 56 | |
Tom Rini | 7384b5a | 2013-03-14 05:32:49 +0000 | [diff] [blame] | 57 | #define DFU_NAME_SIZE 32 |
| 58 | #define DFU_CMD_BUF_SIZE 128 |
Heiko Schocher | a2f831e | 2013-06-12 06:05:51 +0200 | [diff] [blame] | 59 | #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE |
| 60 | #define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */ |
| 61 | #endif |
Pantelis Antoniou | a6e788d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 62 | #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE |
| 63 | #define CONFIG_SYS_DFU_MAX_FILE_SIZE (4 << 20) /* 4 MiB */ |
| 64 | #endif |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 65 | |
| 66 | struct 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 Antoniou | cf14d0d | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 76 | struct nand_internal_data nand; |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 77 | } data; |
| 78 | |
Pantelis Antoniou | a6e788d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 79 | 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 Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 86 | |
| 87 | struct list_head list; |
Pantelis Antoniou | a6e788d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 88 | |
| 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 Antoniou | cf14d0d | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 99 | u32 bad_skip; /* for nand use */ |
| 100 | |
Pantelis Antoniou | a6e788d | 2013-03-14 05:32:48 +0000 | [diff] [blame] | 101 | unsigned int inited:1; |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | int dfu_config_entities(char *s, char *interface, int num); |
| 105 | void dfu_free_entities(void); |
| 106 | void dfu_show_entities(void); |
| 107 | int dfu_get_alt_number(void); |
| 108 | const char *dfu_get_dev_type(enum dfu_device_type t); |
| 109 | const char *dfu_get_layout(enum dfu_layout l); |
| 110 | struct dfu_entity *dfu_get_entity(int alt); |
| 111 | char *dfu_extract_token(char** e, int *n); |
Lukasz Majewski | 2968aa2 | 2013-07-18 13:19:14 +0200 | [diff] [blame^] | 112 | void dfu_trigger_reset(void); |
| 113 | bool dfu_reset(void); |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 114 | |
| 115 | int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |
| 116 | int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |
| 117 | /* Device specific */ |
| 118 | #ifdef CONFIG_DFU_MMC |
| 119 | extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s); |
| 120 | #else |
| 121 | static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s) |
| 122 | { |
| 123 | puts("MMC support not available!\n"); |
| 124 | return -1; |
| 125 | } |
| 126 | #endif |
Pantelis Antoniou | cf14d0d | 2013-03-14 05:32:52 +0000 | [diff] [blame] | 127 | |
| 128 | #ifdef CONFIG_DFU_NAND |
| 129 | extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s); |
| 130 | #else |
| 131 | static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s) |
| 132 | { |
| 133 | puts("NAND support not available!\n"); |
| 134 | return -1; |
| 135 | } |
| 136 | #endif |
| 137 | |
Lukasz Majewski | d311c6e | 2012-08-06 14:41:07 +0200 | [diff] [blame] | 138 | #endif /* __DFU_ENTITY_H_ */ |