dfu.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #ifndef __DFU_ENTITY_H_
  11. #define __DFU_ENTITY_H_
  12. #include <common.h>
  13. #include <linux/list.h>
  14. #include <mmc.h>
  15. #include <linux/usb/composite.h>
  16. enum dfu_device_type {
  17. DFU_DEV_MMC = 1,
  18. DFU_DEV_ONENAND,
  19. DFU_DEV_NAND,
  20. DFU_DEV_RAM,
  21. };
  22. enum dfu_layout {
  23. DFU_RAW_ADDR = 1,
  24. DFU_FS_FAT,
  25. DFU_FS_EXT2,
  26. DFU_FS_EXT3,
  27. DFU_FS_EXT4,
  28. DFU_RAM_ADDR,
  29. };
  30. enum dfu_op {
  31. DFU_OP_READ = 1,
  32. DFU_OP_WRITE,
  33. DFU_OP_SIZE,
  34. };
  35. struct mmc_internal_data {
  36. int dev_num;
  37. /* RAW programming */
  38. unsigned int lba_start;
  39. unsigned int lba_size;
  40. unsigned int lba_blk_size;
  41. /* eMMC HW partition access */
  42. int hw_partition;
  43. /* FAT/EXT */
  44. unsigned int dev;
  45. unsigned int part;
  46. };
  47. struct nand_internal_data {
  48. /* RAW programming */
  49. u64 start;
  50. u64 size;
  51. unsigned int dev;
  52. unsigned int part;
  53. /* for nand/ubi use */
  54. unsigned int ubi;
  55. };
  56. struct ram_internal_data {
  57. void *start;
  58. unsigned int size;
  59. };
  60. #define DFU_NAME_SIZE 32
  61. #define DFU_CMD_BUF_SIZE 128
  62. #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
  63. #define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */
  64. #endif
  65. #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
  66. #define CONFIG_SYS_DFU_MAX_FILE_SIZE CONFIG_SYS_DFU_DATA_BUF_SIZE
  67. #endif
  68. #ifndef DFU_DEFAULT_POLL_TIMEOUT
  69. #define DFU_DEFAULT_POLL_TIMEOUT 0
  70. #endif
  71. #ifndef DFU_MANIFEST_POLL_TIMEOUT
  72. #define DFU_MANIFEST_POLL_TIMEOUT DFU_DEFAULT_POLL_TIMEOUT
  73. #endif
  74. struct dfu_entity {
  75. char name[DFU_NAME_SIZE];
  76. int alt;
  77. void *dev_private;
  78. enum dfu_device_type dev_type;
  79. enum dfu_layout layout;
  80. union {
  81. struct mmc_internal_data mmc;
  82. struct nand_internal_data nand;
  83. struct ram_internal_data ram;
  84. } data;
  85. long (*get_medium_size)(struct dfu_entity *dfu);
  86. int (*read_medium)(struct dfu_entity *dfu,
  87. u64 offset, void *buf, long *len);
  88. int (*write_medium)(struct dfu_entity *dfu,
  89. u64 offset, void *buf, long *len);
  90. int (*flush_medium)(struct dfu_entity *dfu);
  91. unsigned int (*poll_timeout)(struct dfu_entity *dfu);
  92. struct list_head list;
  93. /* on the fly state */
  94. u32 crc;
  95. u64 offset;
  96. int i_blk_seq_num;
  97. u8 *i_buf;
  98. u8 *i_buf_start;
  99. u8 *i_buf_end;
  100. long r_left;
  101. long b_left;
  102. u32 bad_skip; /* for nand use */
  103. unsigned int inited:1;
  104. };
  105. int dfu_config_entities(char *s, char *interface, char *devstr);
  106. void dfu_free_entities(void);
  107. void dfu_show_entities(void);
  108. int dfu_get_alt_number(void);
  109. const char *dfu_get_dev_type(enum dfu_device_type t);
  110. const char *dfu_get_layout(enum dfu_layout l);
  111. struct dfu_entity *dfu_get_entity(int alt);
  112. char *dfu_extract_token(char** e, int *n);
  113. void dfu_trigger_reset(void);
  114. int dfu_get_alt(char *name);
  115. bool dfu_reset(void);
  116. int dfu_init_env_entities(char *interface, char *devstr);
  117. unsigned char *dfu_get_buf(void);
  118. unsigned char *dfu_free_buf(void);
  119. unsigned long dfu_get_buf_size(void);
  120. int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
  121. int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
  122. int dfu_flush(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
  123. /* Device specific */
  124. #ifdef CONFIG_DFU_MMC
  125. extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s);
  126. #else
  127. static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr,
  128. char *s)
  129. {
  130. puts("MMC support not available!\n");
  131. return -1;
  132. }
  133. #endif
  134. #ifdef CONFIG_DFU_NAND
  135. extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr, char *s);
  136. #else
  137. static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *devstr,
  138. char *s)
  139. {
  140. puts("NAND support not available!\n");
  141. return -1;
  142. }
  143. #endif
  144. #ifdef CONFIG_DFU_RAM
  145. extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s);
  146. #else
  147. static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr,
  148. char *s)
  149. {
  150. puts("RAM support not available!\n");
  151. return -1;
  152. }
  153. #endif
  154. int dfu_add(struct usb_configuration *c);
  155. #endif /* __DFU_ENTITY_H_ */