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