libubigen.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (c) International Business Machines Corp., 2006
  3. * Copyright (C) 2008 Nokia Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. /*
  20. * Authors: Frank Haverkamp
  21. * Artem Bityutskiy
  22. */
  23. #ifndef __LIBUBIGEN_H__
  24. #define __LIBUBIGEN_H__
  25. #include <stdint.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * struct ubigen_info - libubigen information.
  31. * @leb_size: logical eraseblock size
  32. * @peb_size: size of the physical eraseblock
  33. * @min_io_size: minimum input/output unit size
  34. * @vid_hdr_offs: offset of the VID header
  35. * @data_offs: data offset
  36. * @ubi_ver: UBI version
  37. * @vtbl_size: volume table size
  38. * @max_volumes: maximum amount of volumes
  39. * @image_seq: UBI image sequence number
  40. */
  41. struct ubigen_info
  42. {
  43. int leb_size;
  44. int peb_size;
  45. int min_io_size;
  46. int vid_hdr_offs;
  47. int data_offs;
  48. int ubi_ver;
  49. int vtbl_size;
  50. int max_volumes;
  51. uint32_t image_seq;
  52. };
  53. /**
  54. * struct ubigen_vol_info - information about a volume.
  55. * @id: volume id
  56. * @type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC)
  57. * @alignment: volume alignment
  58. * @data_pad: how many bytes are unused at the end of the each physical
  59. * eraseblock to satisfy the requested alignment
  60. * @usable_leb_size: LEB size accessible for volume users
  61. * @name: volume name
  62. * @name_len: volume name length
  63. * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE,
  64. * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT)
  65. * @used_ebs: total number of used logical eraseblocks in this volume (relevant
  66. * for static volumes only)
  67. * @bytes: size of the volume contents in bytes (relevant for static volumes
  68. * only)
  69. * @flags: volume flags (%UBI_VTBL_AUTORESIZE_FLG)
  70. */
  71. struct ubigen_vol_info
  72. {
  73. int id;
  74. int type;
  75. int alignment;
  76. int data_pad;
  77. int usable_leb_size;
  78. const char *name;
  79. int name_len;
  80. int compat;
  81. int used_ebs;
  82. long long bytes;
  83. uint8_t flags;
  84. };
  85. /**
  86. * ubigen_info_init - initialize libubigen.
  87. * @ui: libubigen information
  88. * @peb_size: flash physical eraseblock size
  89. * @min_io_size: flash minimum input/output unit size
  90. * @subpage_size: flash sub-page, if present (has to be equivalent to
  91. * @min_io_size if does not exist)
  92. * @vid_hdr_offs: offset of the VID header
  93. * @ubi_ver: UBI version
  94. * @image_seq: UBI image sequence number
  95. */
  96. void ubigen_info_init(struct ubigen_info *ui, int peb_size, int min_io_size,
  97. int subpage_size, int vid_hdr_offs, int ubi_ver,
  98. uint32_t image_seq);
  99. /**
  100. * ubigen_create_empty_vtbl - creates empty volume table.
  101. * @ui: libubigen information
  102. *
  103. * This function creates an empty volume table and returns a pointer to it in
  104. * case of success and %NULL in case of failure. The returned object has to be
  105. * freed with 'free()' call.
  106. */
  107. struct ubi_vtbl_record *ubigen_create_empty_vtbl(const struct ubigen_info *ui);
  108. /**
  109. * ubigen_init_ec_hdr - initialize EC header.
  110. * @ui: libubigen information
  111. * @hdr: the EC header to initialize
  112. * @ec: erase counter value
  113. */
  114. void ubigen_init_ec_hdr(const struct ubigen_info *ui,
  115. struct ubi_ec_hdr *hdr, long long ec);
  116. /**
  117. * ubigen_init_vid_hdr - initialize VID header.
  118. * @ui: libubigen information
  119. * @vi: volume information
  120. * @hdr: the VID header to initialize
  121. * @lnum: logical eraseblock number
  122. * @data: the contents of the LEB (static volumes only)
  123. * @data_size: amount of data in this LEB (static volumes only)
  124. *
  125. * Note, @used_ebs, @data and @data_size are ignored in case of dynamic
  126. * volumes.
  127. */
  128. void ubigen_init_vid_hdr(const struct ubigen_info *ui,
  129. const struct ubigen_vol_info *vi,
  130. struct ubi_vid_hdr *hdr, int lnum,
  131. const void *data, int data_size);
  132. /**
  133. * ubigen_add_volume - add a volume to the volume table.
  134. * @ui: libubigen information
  135. * @vi: volume information
  136. * @vtbl: volume table to add to
  137. *
  138. * This function adds volume described by input parameters to the volume table
  139. * @vtbl.
  140. */
  141. int ubigen_add_volume(const struct ubigen_info *ui,
  142. const struct ubigen_vol_info *vi,
  143. struct ubi_vtbl_record *vtbl);
  144. /**
  145. * ubigen_write_volume - write UBI volume.
  146. * @ui: libubigen information
  147. * @vi: volume information
  148. * @ec: erase counter value to put to EC headers
  149. * @bytes: volume size in bytes
  150. * @in: input file descriptor (has to be properly seeked)
  151. * @out: output file descriptor
  152. *
  153. * This function reads the contents of the volume from the input file @in and
  154. * writes the UBI volume to the output file @out. Returns zero on success and
  155. * %-1 on failure.
  156. */
  157. int ubigen_write_volume(const struct ubigen_info *ui,
  158. const struct ubigen_vol_info *vi, long long ec,
  159. long long bytes, int in, int out);
  160. /**
  161. * ubigen_write_layout_vol - write UBI layout volume
  162. * @ui: libubigen information
  163. * @peb1: physical eraseblock number to write the first volume table copy
  164. * @peb2: physical eraseblock number to write the second volume table copy
  165. * @ec1: erase counter value for @peb1
  166. * @ec2: erase counter value for @peb1
  167. * @vtbl: volume table
  168. * @fd: output file descriptor seeked to the proper position
  169. *
  170. * This function creates the UBI layout volume which contains 2 copies of the
  171. * volume table. Returns zero in case of success and %-1 in case of failure.
  172. */
  173. int ubigen_write_layout_vol(const struct ubigen_info *ui, int peb1, int peb2,
  174. long long ec1, long long ec2,
  175. struct ubi_vtbl_record *vtbl, int fd);
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #endif /* !__LIBUBIGEN_H__ */