dfu.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifndef __DFU_ENTITY_H_
  23. #define __DFU_ENTITY_H_
  24. #include <common.h>
  25. #include <linux/list.h>
  26. #include <mmc.h>
  27. enum dfu_device_type {
  28. DFU_DEV_MMC = 1,
  29. DFU_DEV_ONENAND,
  30. DFU_DEV_NAND,
  31. };
  32. enum dfu_layout {
  33. DFU_RAW_ADDR = 1,
  34. DFU_FS_FAT,
  35. DFU_FS_EXT2,
  36. DFU_FS_EXT3,
  37. DFU_FS_EXT4,
  38. };
  39. struct mmc_internal_data {
  40. /* RAW programming */
  41. unsigned int lba_start;
  42. unsigned int lba_size;
  43. unsigned int lba_blk_size;
  44. /* FAT/EXT */
  45. unsigned int dev;
  46. unsigned int part;
  47. };
  48. struct nand_internal_data {
  49. /* RAW programming */
  50. u64 start;
  51. u64 size;
  52. unsigned int dev;
  53. unsigned int part;
  54. };
  55. static inline unsigned int get_mmc_blk_size(int dev)
  56. {
  57. return find_mmc_device(dev)->read_bl_len;
  58. }
  59. #define DFU_NAME_SIZE 32
  60. #define DFU_CMD_BUF_SIZE 128
  61. #define DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */
  62. #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE
  63. #define CONFIG_SYS_DFU_MAX_FILE_SIZE (4 << 20) /* 4 MiB */
  64. #endif
  65. struct dfu_entity {
  66. char name[DFU_NAME_SIZE];
  67. int alt;
  68. void *dev_private;
  69. int dev_num;
  70. enum dfu_device_type dev_type;
  71. enum dfu_layout layout;
  72. union {
  73. struct mmc_internal_data mmc;
  74. struct nand_internal_data nand;
  75. } data;
  76. int (*read_medium)(struct dfu_entity *dfu,
  77. u64 offset, void *buf, long *len);
  78. int (*write_medium)(struct dfu_entity *dfu,
  79. u64 offset, void *buf, long *len);
  80. int (*flush_medium)(struct dfu_entity *dfu);
  81. struct list_head list;
  82. /* on the fly state */
  83. u32 crc;
  84. u64 offset;
  85. int i_blk_seq_num;
  86. u8 *i_buf;
  87. u8 *i_buf_start;
  88. u8 *i_buf_end;
  89. long r_left;
  90. long b_left;
  91. u32 bad_skip; /* for nand use */
  92. unsigned int inited:1;
  93. };
  94. int dfu_config_entities(char *s, char *interface, int num);
  95. void dfu_free_entities(void);
  96. void dfu_show_entities(void);
  97. int dfu_get_alt_number(void);
  98. const char *dfu_get_dev_type(enum dfu_device_type t);
  99. const char *dfu_get_layout(enum dfu_layout l);
  100. struct dfu_entity *dfu_get_entity(int alt);
  101. char *dfu_extract_token(char** e, int *n);
  102. int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
  103. int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num);
  104. /* Device specific */
  105. #ifdef CONFIG_DFU_MMC
  106. extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s);
  107. #else
  108. static inline int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s)
  109. {
  110. puts("MMC support not available!\n");
  111. return -1;
  112. }
  113. #endif
  114. #ifdef CONFIG_DFU_NAND
  115. extern int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s);
  116. #else
  117. static inline int dfu_fill_entity_nand(struct dfu_entity *dfu, char *s)
  118. {
  119. puts("NAND support not available!\n");
  120. return -1;
  121. }
  122. #endif
  123. #endif /* __DFU_ENTITY_H_ */