flash 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. .TH FLASH 3
  2. .SH NAME
  3. flash \- flash memory
  4. .SH SYNOPSYS
  5. .nf
  6. .BI "bind -a #F" \fR[\fPn\fR]\fP " /dev"
  7. .sp 0.3v
  8. .B /dev/flash
  9. .BI /dev/flash/ part
  10. .BI /dev/flash/ part ctl
  11. .fi
  12. .SH DESCRIPTION
  13. The flash memory device serves a two-level directory,
  14. giving access to files representing part or all of a bank of flash memory.
  15. A platform might have more than one bank of flash, numbered starting from 0.
  16. The attach specifier
  17. .I n
  18. is a decimal integer that selects a particular bank of flash (default: 0).
  19. Both NOR and NAND flash is supported.
  20. For both types of flash,
  21. the driver gives a read/write/erase interface to the raw flash device,
  22. which can impose constraints on operations beyond those imposed by the driver.
  23. Other drivers such as
  24. .IR ftl (3)
  25. or
  26. .IR logfs (3)
  27. implement any higher-level format required,
  28. including ECC for NAND flash, for instance.
  29. .PP
  30. The top level directory contains a single directory named
  31. .B flash
  32. for bank 0, and
  33. .BI flash n
  34. for each other bank
  35. .IR n .
  36. It contains two files for each partition:
  37. a data file
  38. .I part
  39. and an associated control file
  40. .IB part ctl ,
  41. where
  42. .I part
  43. is the name of the partition.
  44. Each partition represents a region of flash memory that starts and ends
  45. on a flash segment (erase unit) boundary.
  46. The system initially creates a single standard partition
  47. .B flash
  48. representing the whole of flash memory, and the corresponding control file
  49. .BR flashctl .
  50. Other partitions can be created by writing to
  51. .B flashctl
  52. as described below.
  53. .PP
  54. The data file
  55. .I part
  56. provides read and write access to the bytes on the system's flash memory.
  57. Bytes can be read and written on any byte boundary:
  58. the interface hides any alignment restrictions.
  59. A read returns the value of the bytes at the current file offset,
  60. where zero is the start of the partition.
  61. A write reprograms the flash to the given byte values, at the current
  62. file offset (relative to the start of the partition), using the physical
  63. device's reprogramming algorithm.
  64. An erased flash byte is logically
  65. .B 0xFF
  66. (regardless of the conventions of the physical flash device).
  67. A write can change a bit with value 1 to a 0,
  68. but cannot change a 0 bit to 1;
  69. that can only be done by erasing one or more flash segments.
  70. NAND flash typically has restrictions on the number of writes
  71. allowed to a page before requiring a block erase.
  72. Reads and writes are unbuffered.
  73. .PP
  74. The control file
  75. .BI part ctl
  76. can be read and written.
  77. A read returns several lines containing decimal and hexadecimal numbers
  78. (separated by white space)
  79. revealing the characteristics of memory within the partition.
  80. The first line gives the
  81. the manufacturer ID, the flash device ID, the memory width in bytes,
  82. and a string giving the flash type
  83. (currently either
  84. .B nor
  85. or
  86. .BR nand ).
  87. Subsequent lines give characteristics of each group of erase units
  88. within the partition,
  89. where the erase units within a group have the same properties.
  90. Each line gives the start and end (as byte addresses)
  91. of the erase units in the region
  92. that lie within the partition,
  93. followed by the size in bytes of each erase unit, which is followed
  94. for NAND flash by the size in bytes of a page.
  95. The sizes for NAND flash include the extra bytes per page
  96. typically used to hold an ECC and block status.
  97. A write contains one of the following textual commands:
  98. .TF "erase al"
  99. .TP
  100. .BI add " name start end"
  101. Create a new partition that ranges from
  102. .I start
  103. to
  104. .I end
  105. within the current partition.
  106. Each value must be numeric (decimal, octal or hexadecimal)
  107. and a multiple of the erase unit size.
  108. .I Name
  109. must not be the name of an existing partition.
  110. On success, new files
  111. .I name
  112. and
  113. .IB name ctl
  114. will appear in the parent
  115. .B flash
  116. directory.
  117. .TP
  118. .B erase all
  119. Erase the whole flash partition, setting all bytes to
  120. .BR 0xFF ,
  121. except those that are hardware write-protected.
  122. .TP
  123. .BI erase " offset"
  124. Erase the segment that begins at the given
  125. .I offset
  126. within the partition,
  127. setting all bytes to
  128. .BR 0xFF ,
  129. except those that are hardware write-protected.
  130. The
  131. .I offset
  132. is given in bytes, but must be a multiple
  133. of the segment (erase unit) size.
  134. .TP
  135. .BR protectboot " [ " off " ]"
  136. By default the system prevents erase unit 0 of the flash from being
  137. erased or written, assuming it
  138. contains the primary bootstrap.
  139. Writing this command with parameter
  140. .B off
  141. removes that protection.
  142. Writing
  143. .B protectboot
  144. with any other parameter (or none) restores the protection.
  145. Note that a manufacturer might also have locked the flash in hardware,
  146. and that protection must be removed in a device-dependent way.
  147. .TP
  148. .B sync
  149. If the underlying device must buffer or cache (current devices do not),
  150. flush the buffer(s).
  151. .PD
  152. .PP
  153. The syntax of all numbers is that of
  154. .I strtoul
  155. (in
  156. .IR atof (2));
  157. the default base is 10.
  158. .SH SOURCE
  159. .B /sys/src/*/devflash.c
  160. .br
  161. .B /sys/src/*/flash*.c
  162. .SH SEE ALSO
  163. .IR paqfs (4)
  164. .\" .IR ftl (3)
  165. .SH DIAGNOSTICS
  166. A write will return an error if
  167. an attempt is made to change a 0 bit to 1,
  168. or if the flash memory fails to be programmed correctly.
  169. .SH BUGS
  170. The flash cannot be written if the kernel is executing directly from flash,
  171. because the physical flash cannot be read during programming,
  172. and the driver does not copy the programming code to DRAM.