]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/tools/nanobsd/FlashDevice.sub
nanobsd: fix typo in utility function call name
[FreeBSD/FreeBSD.git] / tools / tools / nanobsd / FlashDevice.sub
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Poul-Henning Kamp.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26 #
27 #
28 # Convenience function for commonly used Flash devices.
29 #
30 # There is a hook over in nanobsd.sh which allows you to call into
31 # this function simply with a line like:
32 #
33 #       FlashDevice Sandisk 256
34 #
35 # This file will then set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you.
36 #
37
38 sub_FlashDevice () {
39
40         a1=`echo $1 | tr '[:upper:]' '[:lower:]'`
41         a2=`echo $2 | tr '[:upper:]' '[:lower:]'`
42         case $a1 in
43         hitachi)
44                 case $a2 in
45                 256|256mb)
46                         NANO_MEDIASIZE=`expr 256204800 / 512`
47                         NANO_HEADS=15
48                         NANO_SECTS=48
49                         ;;
50                 *)
51                         echo "Unknown Hitachi Flash capacity"
52                         exit 2
53                         ;;
54                 esac
55                 ;;
56         integral)
57                 # Source: mich@FreeBSD.org
58                 case $a2 in
59                 256|256mb)
60                         NANO_MEDIASIZE=`expr 259596288 / 512`
61                         NANO_HEADS=16
62                         NANO_SECTS=63
63                         ;;
64                 *)
65                         echo "Unknown Integral i-Pro Flash capacity"
66                         exit 2
67                         ;;
68                 esac
69                 ;;
70         kodak)
71                 # Source: mwlucas@FreeBSD.org
72                 case $a2 in
73                 64|64mb)
74                         NANO_MEDIASIZE=`expr 64487424 / 512`
75                         NANO_HEADS=4
76                         NANO_SECTS=32
77                         ;;
78                 *)
79                         echo "Unknown Kodak Flash capacity"
80                         exit 2
81                         ;;
82                 esac
83                 ;;
84         memorycorp)
85                 # Source: simon@FreeBSD.org
86                 case $a2 in
87                 512|512mb)
88                         # MC512CFLS2
89                         NANO_MEDIASIZE=`expr 519192576 / 512`
90                         NANO_HEADS=16
91                         NANO_SECTS=63
92                         ;;
93                 *)
94                         echo "Unknown Memory Corp Flash capacity"
95                         exit 2
96                         ;;
97                 esac
98                 ;;
99         sandisk)
100                 # Source:
101                 #       SanDisk CompactFlash Memory Card
102                 #       Product Manual
103                 #       Version 10.9
104                 #       Document No. 20-10-00038
105                 #       April 2005
106                 # Table 2-7 
107                 # NB: notice math error in SDCFJ-4096-388 line.
108                 #
109                 case $a2 in
110                 32|32mb)
111                         NANO_MEDIASIZE=`expr 32112640 / 512`
112                         NANO_HEADS=4
113                         NANO_SECTS=32
114                         ;;
115                 64|64mb)
116                         NANO_MEDIASIZE=`expr 64225280 / 512`
117                         NANO_HEADS=8
118                         NANO_SECTS=32
119                         ;;
120                 128|128mb)
121                         NANO_MEDIASIZE=`expr 128450560 / 512`
122                         NANO_HEADS=8
123                         NANO_SECTS=32
124                         ;;
125                 256|256mb)
126                         NANO_MEDIASIZE=`expr 256901120 / 512`
127                         NANO_HEADS=16
128                         NANO_SECTS=32
129                         ;;
130                 512|512mb)
131                         NANO_MEDIASIZE=`expr 512483328 / 512`
132                         NANO_HEADS=16
133                         NANO_SECTS=63
134                         ;;
135                 1024|1024mb|1g)
136                         NANO_MEDIASIZE=`expr 1024966656 / 512`
137                         NANO_HEADS=16
138                         NANO_SECTS=63
139                         ;;
140                 2048|2048mb|2g)
141                         NANO_MEDIASIZE=`expr 2048901120 / 512`
142                         NANO_HEADS=16
143                         NANO_SECTS=63
144                         ;;
145                 4096|4096mb|4g)
146                         NANO_MEDIASIZE=`expr -e 4097802240 / 512`
147                         NANO_HEADS=16
148                         NANO_SECTS=63
149                         ;;
150                 *)
151                         echo "Unknown Sandisk Flash capacity"
152                         exit 2
153                         ;;
154                 esac
155                 ;;
156         siliconsystems)
157                 case $a2 in
158                 256|256mb)
159                         NANO_MEDIASIZE=`expr 260571136 / 512`
160                         NANO_HEADS=16
161                         NANO_SECTS=32
162                         ;;
163                 4096|4g)
164                         NANO_MEDIASIZE=`expr -e 4224761856 / 512`
165                         NANO_HEADS=16
166                         NANO_SECTS=63
167                         ;;
168                 *)
169                         echo "Unknown SiliconSystems Flash capacity"
170                         exit 2
171                         ;;
172                 esac
173                 ;;
174         soekris)
175                 case $a2 in
176                 net4526 | 4526 | net4826 | 4826 | 64 | 64mb)
177                         NANO_MEDIASIZE=125056
178                         NANO_HEADS=4
179                         NANO_SECTS=32
180                         ;;
181                 *)
182                         echo "Unknown Soekris Flash capacity"
183                         exit 2
184                         ;;
185                 esac
186                 ;;
187         transcend)
188                 case $a2 in
189                 dom064m)
190                         NANO_MEDIASIZE=125184
191                         NANO_HEADS=4
192                         NANO_SECTS=32
193                         ;;
194                 2048|2g)
195                         NANO_MEDIASIZE=4061232
196                         NANO_HEADS=16
197                         NANO_SECTS=32
198                         ;;
199                 *)
200                         echo "Unknown Transcend Flash capacity"
201                         exit 2
202                         ;;
203                 esac
204                 ;;
205         # Generic flash media.  It assumes that we're booting using packet
206         # mode so the HEADS and SECTS don't matter.  The truncation of the
207         # size to a slightly lower number is intentional to be conservative
208         # (eg, 1 sector smaller than N GB is always smaller than any flash
209         # claiming to be N GB, but wastes a little space sometimes when 1GB
210         # really means 1GiB).  This is intended to be used when producing
211         # generic images for anybody to boot.  Media sizes are specified 'Xg'
212         # for X GB (10^9 bytes) flash or Xm for X MB (10^6 bytes) flash.
213         # Power of 2 variants can be specified with gi or mi for GiB and MiB
214         # sizeed flash and don't try to be conservative (use with caution).
215         generic)
216                 case $a2 in
217                 *.*)    # Catch unsupported 1.5g case, since expr can't
218                         # cope with floats.
219                         echo "Unsupported generic size $a2"
220                         exit 2
221                         ;;
222                 *m)
223                         NANO_HEADS=16
224                         NANO_SECTS=63
225                         NANO_MEDIASIZE=`expr -e ${a2%m} \* 1000000 / 512`
226                         ;;
227                 *g)
228                         NANO_HEADS=16
229                         NANO_SECTS=63
230                         NANO_MEDIASIZE=`expr -e ${a2%g} \* 1000000000 / 512`
231                         ;;
232                 *mi)
233                         NANO_HEADS=16
234                         NANO_SECTS=63
235                         NANO_MEDIASIZE=`expr -e ${a2%mi} \* 1024 \* 1024 / 512`
236                         ;;
237                 *gi)
238                         NANO_HEADS=16
239                         NANO_SECTS=63
240                         NANO_MEDIASIZE=`expr -e ${a2%gi} \* 1024 \* 1024 \* 1024 / 512`
241                         ;;
242                 *)
243                         echo "Unsupported generic size $a2"
244                         exit 2
245                         ;;
246                 esac
247                 ;;
248         *)
249                 echo "Unknown Flash manufacturer"
250                 exit 2
251                 ;;
252         esac
253 }