dfu.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. };
  34. struct mmc_internal_data {
  35. /* RAW programming */
  36. unsigned int lba_start;
  37. unsigned int lba_size;
  38. unsigned int lba_blk_size;
  39. /* FAT/EXT */
  40. unsigned int dev;
  41. unsigned int part;
  42. };
  43. struct nand_internal_data {
  44. /* RAW programming */
  45. u64 start;
  46. u64 size;
  47. unsigned int dev;
  48. unsigned int part;
  49. /* for nand/ubi use */
  50. unsigned int ubi;
  51. };
  52. struct ram_internal_data {
  53. void *start;
  54. unsigned int size;
  55. };
  56. static inline unsigned int get_mmc_blk_size(int dev)
  57. {
  58. return find_mmc_device(dev)->read_bl_len;
  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. struct dfu_entity {
  69. char name[DFU_NAME_SIZE];
  70. int alt;
  71. void *dev_private;
  72. int dev_num;
  73. enum dfu_device_type dev_type;
  74. enum dfu_layout layout;
  75. union {
  76. struct mmc_internal_data mmc;
  77. struct nand_internal_data nand;
  78. struct ram_internal_data ram;
  79. } data;
  80. int (*read_medium)(struct dfu_entity *dfu,
  81. u64 offset, void *buf, long *len);
  82. int (*write_medium)(struct dfu_entity *dfu,
  83. u64 offset, void *buf, long *len);
  84. int (*flush_medium)(struct dfu_entity *dfu);
  85. struct list_head list;
  86. /* on the fly state */
  87. u32 crc;
  88. u64 offset;
  89. int i_blk_seq_num;
  90. u8 *i_buf;
  91. u8 *i_buf_start;
  92. u8 *i_buf_end;
  93. long r_left;
  94. long b_left;
  95. u32 bad_skip; /* for nand use */
  96. unsigned int inited:1;
  97. };
  98. int dfu_config_entities(char *s, char *interface, int num);
  99. void dfu_free_entities(void);
  100. void dfu_show_entities(void);
  101. int dfu_get_alt_number(void);
  102. const char *dfu_get_dev_type(enum dfu_device_type t);
  103. const char *dfu_get_layout(enum dfu_layout l);
  104. struct dfu_entity *dfu_get_entity(int alt);
  105. char *dfu_extract_token(char** e, int *n);
  106. void dfu_trigger_reset(void);
  107. bool dfu_reset(void);
  108. int dfu_init_env_entities(char *interface, int dev);
  109. int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
  110. int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
  111. /* Device specific */
  112. #ifdef CONFIG_DFU_MMC
  113. extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s);
  114. #else
  115. static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
  116. {
  117. puts("MMC support not available!\n");
  118. return -1;
  119. }
  120. #endif
  121. #ifdef CONFIG_DFU_NAND
  122. extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
  123. #else
  124. static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
  125. {
  126. puts("NAND support not available!\n");
  127. return -1;
  128. }
  129. #endif
  130. #ifdef CONFIG_DFU_RAM
  131. extern int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s);
  132. #else
  133. static inline int dfu_fill_entity_ram(struct dfu_entity *dfu, char *s)
  134. {
  135. puts("RAM support not available!\n");
  136. return -1;
  137. }
  138. #endif
  139. #ifdef CONFIG_DFU_FUNCTION
  140. int dfu_add(struct usb_configuration *c);
  141. #else
  142. int dfu_add(struct usb_configuration *c)
  143. {
  144. return 0;
  145. }
  146. #endif
  147. #endif /* __DFU_ENTITY_H_ */