source: rtems/cpukit/include/rtems/jffs2.h @ 7e86e00

5
Last change on this file since 7e86e00 was 2afb22b, checked in by Chris Johns <chrisj@…>, on 12/23/17 at 07:18:56

Remove make preinstall

A speciality of the RTEMS build system was the make preinstall step. It
copied header files from arbitrary locations into the build tree. The
header files were included via the -Bsome/build/tree/path GCC command
line option.

This has at least seven problems:

  • The make preinstall step itself needs time and disk space.
  • Errors in header files show up in the build tree copy. This makes it hard for editors to open the right file to fix the error.
  • There is no clear relationship between source and build tree header files. This makes an audit of the build process difficult.
  • The visibility of all header files in the build tree makes it difficult to enforce API barriers. For example it is discouraged to use BSP-specifics in the cpukit.
  • An introduction of a new build system is difficult.
  • Include paths specified by the -B option are system headers. This may suppress warnings.
  • The parallel build had sporadic failures on some hosts.

This patch removes the make preinstall step. All installed header
files are moved to dedicated include directories in the source tree.
Let @RTEMS_CPU@ be the target architecture, e.g. arm, powerpc, sparc,
etc. Let @RTEMS_BSP_FAMILIY@ be a BSP family base directory, e.g.
erc32, imx, qoriq, etc.

The new cpukit include directories are:

  • cpukit/include
  • cpukit/score/cpu/@RTEMS_CPU@/include
  • cpukit/libnetworking

The new BSP include directories are:

  • bsps/include
  • bsps/@RTEMS_CPU@/include
  • bsps/@RTEMS_CPU@/@RTEMS_BSP_FAMILIY@/include

There are build tree include directories for generated files.

The include directory order favours the most general header file, e.g.
it is not possible to override general header files via the include path
order.

The "bootstrap -p" option was removed. The new "bootstrap -H" option
should be used to regenerate the "headers.am" files.

Update #3254.

  • Property mode set to 100644
File size: 14.3 KB
Line 
1/*
2 * Copyright (c) 2013, 2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifndef RTEMS_JFFS2_H
16#define RTEMS_JFFS2_H
17
18#include <rtems/fs.h>
19#include <sys/param.h>
20#include <sys/ioccom.h>
21#include <zlib.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
27typedef struct rtems_jffs2_flash_control rtems_jffs2_flash_control;
28
29/**
30 * @defgroup JFFS2 Journalling Flash File System Version 2 (JFFS2) Support
31 *
32 * @ingroup FileSystemTypesAndMount
33 *
34 * @brief Mount options for the Journalling Flash File System, Version 2
35 * (JFFS2).
36 *
37 * The application must provide flash device geometry information and flash
38 * device operations in the flash control structure
39 * @ref rtems_jffs2_flash_control.
40 *
41 * The application can optionally provide a compressor control structure to
42 * enable data compression using the selected compression algorithm.
43 *
44 * The application must enable JFFS2 support with rtems_filesystem_register()
45 * or CONFIGURE_FILESYSTEM_JFFS2 via <rtems/confdefs.h>.
46 *
47 * An example mount with a simple memory based flash device simulation follows.
48 * The zlib is used for as the compressor.
49 *
50 * @code
51 * #include <string.h>
52 *
53 * #include <rtems/jffs2.h>
54 * #include <rtems/libio.h>
55 *
56 * #define BLOCK_SIZE (32UL * 1024UL)
57 *
58 * #define FLASH_SIZE (32UL * BLOCK_SIZE)
59 *
60 * typedef struct {
61 *   rtems_jffs2_flash_control super;
62 *   unsigned char area[FLASH_SIZE];
63 * } flash_control;
64 *
65 * static flash_control *get_flash_control(rtems_jffs2_flash_control *super)
66 * {
67 *   return (flash_control *) super;
68 * }
69 *
70 * static int flash_read(
71 *   rtems_jffs2_flash_control *super,
72 *   uint32_t offset,
73 *   unsigned char *buffer,
74 *   size_t size_of_buffer
75 * )
76 * {
77 *   flash_control *self = get_flash_control(super);
78 *   unsigned char *chunk = &self->area[offset];
79 *
80 *   memcpy(buffer, chunk, size_of_buffer);
81 *
82 *   return 0;
83 * }
84 *
85 * static int flash_write(
86 *   rtems_jffs2_flash_control *super,
87 *   uint32_t offset,
88 *   const unsigned char *buffer,
89 *   size_t size_of_buffer
90 * )
91 * {
92 *   flash_control *self = get_flash_control(super);
93 *   unsigned char *chunk = &self->area[offset];
94 *   size_t i;
95 *
96 *   for (i = 0; i < size_of_buffer; ++i) {
97 *     chunk[i] &= buffer[i];
98 *   }
99 *
100 *   return 0;
101 * }
102 *
103 * static int flash_erase(
104 *   rtems_jffs2_flash_control *super,
105 *   uint32_t offset
106 * )
107 * {
108 *   flash_control *self = get_flash_control(super);
109 *   unsigned char *chunk = &self->area[offset];
110 *
111 *   memset(chunk, 0xff, BLOCK_SIZE);
112 *
113 *   return 0;
114 * }
115 *
116 * static flash_control flash_instance = {
117 *   .super = {
118 *     .block_size = BLOCK_SIZE,
119 *     .flash_size = FLASH_SIZE,
120 *     .read = flash_read,
121 *     .write = flash_write,
122 *     .erase = flash_erase,
123 *     .device_identifier = 0xc01dc0fe
124 *   }
125 * };
126 *
127 * static rtems_jffs2_compressor_zlib_control compressor_instance = {
128 *   .super = {
129 *     .compress = rtems_jffs2_compressor_zlib_compress,
130 *     .decompress = rtems_jffs2_compressor_zlib_decompress
131 *   }
132 * };
133 *
134 * static const rtems_jffs2_mount_data mount_data = {
135 *   .flash_control = &flash_instance.super,
136 *   .compressor_control = &compressor_instance.super
137 * };
138 *
139 * static void erase_all(void)
140 * {
141 *   memset(&flash_instance.area[0], 0xff, FLASH_SIZE);
142 * }
143 *
144 * void example_jffs2_mount(const char *mount_dir)
145 * {
146 *   int rv;
147 *
148 *   erase_all();
149 *
150 *   rv = mount_and_make_target_path(
151 *     NULL,
152 *     mount_dir,
153 *     RTEMS_FILESYSTEM_TYPE_JFFS2,
154 *     RTEMS_FILESYSTEM_READ_WRITE,
155 *     &mount_data
156 *   );
157 *   assert(rv == 0);
158 * }
159 * @endcode
160 *
161 * @{
162 */
163
164/**
165 * @brief Read from flash operation.
166 *
167 * @param[in, out] self The flash control.
168 * @param[in] offset The offset to read from the flash begin in bytes.
169 * @param[out] buffer The buffer receiving the data.
170 * @param[in] size_of_buffer The size of the buffer in bytes.
171 *
172 * @retval 0 Successful operation.
173 * @retval -EIO An error occurred.  Please note that the value is negative.
174 * @retval other All other values are reserved and must not be used.
175 */
176typedef int (*rtems_jffs2_flash_read)(
177  rtems_jffs2_flash_control *self,
178  uint32_t offset,
179  unsigned char *buffer,
180  size_t size_of_buffer
181);
182
183/**
184 * @brief Write to flash operation.
185 *
186 * @param[in, out] self The flash control.
187 * @param[in] offset The offset to write from the flash begin in bytes.
188 * @param[in] buffer The buffer containing the data to write.
189 * @param[in] size_of_buffer The size of the buffer in bytes.
190 *
191 * @retval 0 Successful operation.
192 * @retval -EIO An error occurred.  Please note that the value is negative.
193 * @retval other All other values are reserved and must not be used.
194 */
195typedef int (*rtems_jffs2_flash_write)(
196  rtems_jffs2_flash_control *self,
197  uint32_t offset,
198  const unsigned char *buffer,
199  size_t size_of_buffer
200);
201
202/**
203 * @brief Flash erase operation.
204 *
205 * This operation must erase one block specified by the offset.
206 *
207 * @param[in, out] self The flash control.
208 * @param[in] offset The offset to erase from the flash begin in bytes.
209 *
210 * @retval 0 Successful operation.
211 * @retval -EIO An error occurred.  Please note that the value is negative.
212 * @retval other All other values are reserved and must not be used.
213 */
214typedef int (*rtems_jffs2_flash_erase)(
215  rtems_jffs2_flash_control *self,
216  uint32_t offset
217);
218
219/**
220 * @brief Flash destroy operation.
221 *
222 * The flash destroy operation is called during unmount of the file system
223 * instance.  It can be used to free the resources associated with the now
224 * unused flash control
225 *
226 * @param[in, out] self The flash control.
227 */
228typedef void (*rtems_jffs2_flash_destroy)(
229  rtems_jffs2_flash_control *self
230);
231
232/**
233 * @brief Trigger garbage collection operation.
234 *
235 * An optional garbage collection thread may perform now a garbage collection
236 * using the RTEMS_JFFS2_ON_DEMAND_GARBAGE_COLLECTION IO control.
237 *
238 * The garbage collection must not run in the executing context.
239 *
240 * @param[in] self The flash control.
241 */
242typedef void (*rtems_jffs2_trigger_garbage_collection)(
243  rtems_jffs2_flash_control *self
244);
245
246/**
247 * @brief JFFS2 flash device control.
248 */
249struct rtems_jffs2_flash_control {
250  /**
251   * @brief The size in bytes of the erasable unit of the flash device.
252   */
253  uint32_t block_size;
254
255  /**
256   * @brief The size in bytes of the flash device.
257   *
258   * It must be an integral multiple of the block size.  The flash device must
259   * have at least five blocks.
260   */
261  uint32_t flash_size;
262
263  /**
264   * @brief Read from flash operation.
265   */
266  rtems_jffs2_flash_read read;
267
268  /**
269   * @brief Write to flash operation.
270   */
271  rtems_jffs2_flash_write write;
272
273  /**
274   * @brief Flash erase operation.
275   */
276  rtems_jffs2_flash_erase erase;
277
278  /**
279   * @brief Flash destroy operation.
280   *
281   * This operation is optional and the pointer may be @c NULL.
282   */
283  rtems_jffs2_flash_destroy destroy;
284
285  /**
286   * @brief The device identifier of the flash device.
287   *
288   * It is used in combination with the inode number to uniquely identify a
289   * file system node in the system.
290   */
291  dev_t device_identifier;
292
293  /**
294   * @brief Trigger garbage collection operation.
295   *
296   * This operation is optional and may be NULL.  This operation should wake up
297   * a garbage collection thread.  The garbage collection thread should use the
298   * RTEMS_JFFS2_ON_DEMAND_GARBAGE_COLLECTION IO control to carry out the work.
299   */
300  rtems_jffs2_trigger_garbage_collection trigger_garbage_collection;
301};
302
303typedef struct rtems_jffs2_compressor_control rtems_jffs2_compressor_control;
304
305/**
306 * @brief Compress operation.
307 *
308 * @param[in, out] self The compressor control.
309 * @param[in] data_in The uncompressed data.
310 * @param[out] cdata_out Pointer to buffer with the compressed data.
311 * @param[in, out] datalen On entry, the size in bytes of the uncompressed
312 * data.  On exit, the size in bytes of uncompressed data which was actually
313 * compressed.
314 * @param[in, out] cdatalen On entry, the size in bytes available for
315 * compressed data.  On exit, the size in bytes of the actually compressed
316 * data.
317 *
318 * @return The compressor type.
319 */
320typedef uint16_t (*rtems_jffs2_compressor_compress)(
321  rtems_jffs2_compressor_control *self,
322  unsigned char *data_in,
323  unsigned char *cdata_out,
324  uint32_t *datalen,
325  uint32_t *cdatalen
326);
327
328/**
329 * @brief Decompress operation.
330 *
331 * @param[in, out] self The compressor control.
332 * @param[in] comprtype The compressor type.
333 * @param[in] cdata_in The compressed data.
334 * @param[out] data_out The uncompressed data.
335 * @param[in] cdatalen The size in bytes of the compressed data.
336 * @param[in] datalen The size in bytes of the uncompressed data.
337 *
338 * @retval 0 Successful operation.
339 * @retval -EIO An error occurred.  Please note that the value is negative.
340 * @retval other All other values are reserved and must not be used.
341 */
342typedef int (*rtems_jffs2_compressor_decompress)(
343  rtems_jffs2_compressor_control *self,
344  uint16_t comprtype,
345  unsigned char *cdata_in,
346  unsigned char *data_out,
347  uint32_t cdatalen,
348  uint32_t datalen
349);
350
351/**
352 * @brief Compressor destroy operation.
353 *
354 * The compressor destroy operation is called during unmount of the file system
355 * instance.  It can be used to free the resources associated with the now
356 * unused compressor operations.
357 *
358 * @param[in, out] self The compressor control.
359 */
360typedef void (*rtems_jffs2_compressor_destroy)(
361  rtems_jffs2_compressor_control *self
362);
363
364/**
365 * @brief JFFS2 compressor control.
366 */
367struct rtems_jffs2_compressor_control {
368  /**
369   * @brief Compress operation.
370   */
371  rtems_jffs2_compressor_compress compress;
372
373  /**
374   * @brief Decompress operation.
375   */
376  rtems_jffs2_compressor_decompress decompress;
377
378  /**
379   * @brief Compressor destroy operation.
380   *
381   * This operation is optional and the pointer may be @c NULL.
382   */
383  rtems_jffs2_compressor_destroy destroy;
384
385  /**
386   * @brief Compression buffer.
387   */
388  unsigned char buffer[PAGE_SIZE];
389};
390
391/**
392 * @brief RTIME compressor compress operation.
393 */
394uint16_t rtems_jffs2_compressor_rtime_compress(
395  rtems_jffs2_compressor_control *self,
396  unsigned char *data_in,
397  unsigned char *cdata_out,
398  uint32_t *datalen,
399  uint32_t *cdatalen
400);
401
402/**
403 * @brief RTIME compressor decompress operation.
404 */
405int rtems_jffs2_compressor_rtime_decompress(
406  rtems_jffs2_compressor_control *self,
407  uint16_t comprtype,
408  unsigned char *cdata_in,
409  unsigned char *data_out,
410  uint32_t cdatalen,
411  uint32_t datalen
412);
413
414/**
415 * @brief ZLIB compressor control structure.
416 */
417typedef struct {
418  rtems_jffs2_compressor_control super;
419  z_stream stream;
420} rtems_jffs2_compressor_zlib_control;
421
422/**
423 * @brief ZLIB compressor compress operation.
424 */
425uint16_t rtems_jffs2_compressor_zlib_compress(
426  rtems_jffs2_compressor_control *self,
427  unsigned char *data_in,
428  unsigned char *cdata_out,
429  uint32_t *datalen,
430  uint32_t *cdatalen
431);
432
433/**
434 * @brief ZLIB compressor decompress operation.
435 */
436int rtems_jffs2_compressor_zlib_decompress(
437  rtems_jffs2_compressor_control *self,
438  uint16_t comprtype,
439  unsigned char *cdata_in,
440  unsigned char *data_out,
441  uint32_t cdatalen,
442  uint32_t datalen
443);
444
445/**
446 * @brief JFFS2 mount options.
447 *
448 * For JFFS2 the mount options are mandatory.
449 */
450typedef struct {
451  /**
452   * @brief Flash control.
453   */
454  rtems_jffs2_flash_control *flash_control;
455
456  /**
457   * @brief Compressor control.
458   *
459   * The compressor is optional and this pointer may be @c NULL.
460   */
461  rtems_jffs2_compressor_control *compressor_control;
462} rtems_jffs2_mount_data;
463
464/**
465 * @brief Initialization handler of the JFFS2 file system.
466 *
467 * @param[in, out] mt_entry The mount table entry.
468 * @param[in] data The mount options are mandatory for JFFS2 and data must
469 * point to a valid @ref rtems_jffs2_mount_data structure used for this file
470 * system instance.
471 *
472 * @retval 0 Successful operation.
473 * @retval -1 An error occurred.  The @c errno indicates the error.
474 *
475 * @see mount().
476 */
477int rtems_jffs2_initialize(
478  rtems_filesystem_mount_table_entry_t *mt_entry,
479  const void *data
480);
481
482/**
483 * @brief JFFS2 filesystem instance information.
484 *
485 * @see RTEMS_JFFS2_GET_INFO.
486 */
487typedef struct {
488  /**
489   * @brief Flash size in bytes.
490   */
491  uint32_t flash_size;
492
493  /**
494   * @brief Count of flash blocks (erasable units).
495   */
496  uint32_t flash_blocks;
497
498  /**
499   * @brief Size of a flash block in bytes.
500   */
501  uint32_t flash_block_size;
502
503  /**
504   * @brief Used size in bytes.
505   *
506   * Used areas contain valid data.
507   */
508  uint32_t used_size;
509
510  /**
511   * @brief Dirty size in bytes.
512   *
513   * Used areas contain no longer used data.
514   */
515  uint32_t dirty_size;
516
517  /**
518   * @brief Wasted size in bytes.
519   *
520   * Wasted areas are unusable.
521   */
522  uint32_t wasted_size;
523
524  /**
525   * @brief Free size in bytes.
526   *
527   * Free areas may be used to store new data.
528   */
529  uint32_t free_size;
530
531  /**
532   * @brief Bad size in bytes.
533   *
534   * Bad areas indicate damaged flash blocks.
535   */
536  uint32_t bad_size;
537
538  /**
539   * @brief Count of clean blocks.
540   *
541   * Clean blocks contain only used areas.
542   */
543  uint32_t clean_blocks;
544
545  /**
546   * @brief Count of dirty blocks.
547   *
548   * Dirty blocks contain dirty and used areas.
549   */
550  uint32_t dirty_blocks;
551
552  /**
553   * @brief Count of erasable blocks.
554   *
555   * Erase blocks contain only dirty or wasted areas.
556   */
557  uint32_t erasable_blocks;
558
559  /**
560   * @brief Count of free blocks.
561   *
562   * Free blocks contain a free area.
563   */
564  uint32_t free_blocks;
565
566  /**
567   * @brief Count of bad blocks.
568   *
569   * Bad blocks are damaged.
570   */
571  uint32_t bad_blocks;
572} rtems_jffs2_info;
573
574/**
575 * @brief IO control to get the JFFS2 filesystem instance information.
576 *
577 * @see rtems_jffs2_info.
578 */
579#define RTEMS_JFFS2_GET_INFO _IOR('F', 1, rtems_jffs2_info)
580
581/**
582 * @brief IO control to perform an on demand garbage collection in a JFFS2
583 * filesystem instance.
584 *
585 * This operation is intended to be used by an optional garbage collection
586 * thread.  See rtems_jffs2_flash_control::trigger_garbage_collection.
587 */
588#define RTEMS_JFFS2_ON_DEMAND_GARBAGE_COLLECTION _IO('F', 2)
589
590/**
591 * @brief IO control to force a garbage collection in a JFFS2 filesystem
592 * instance.
593 *
594 * Use this operation with care since it may wear out your flash.
595 */
596#define RTEMS_JFFS2_FORCE_GARBAGE_COLLECTION _IO('F', 3)
597
598/** @} */
599
600#ifdef __cplusplus
601}
602#endif /* __cplusplus */
603
604#endif /* RTEMS_JFFS2_H */
Note: See TracBrowser for help on using the repository browser.