blob: 271d0e790b7a1b815a174c77880a9a06bba5765e [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
3 * Stäubli Faverges - <www.staubli.com>
4 * Pierre AUBERT p.aubert@staubli.com
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <config.h>
27
28#include "dos.h"
29#include "fdos.h"
30
Jon Loeliger80eb47c2007-07-09 17:56:50 -050031#if defined(CONFIG_CMD_FDOS)
wdenk591dda52002-11-18 00:14:45 +000032
33#define NB_HEADS 2
34#define NB_TRACKS 80
35#define NB_SECTORS 18
36
37
38static int lastwhere;
39
40/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +000041 * dev_open --
wdenk591dda52002-11-18 00:14:45 +000042 *-----------------------------------------------------------------------------
43 */
44int dev_open (void)
45{
46 lastwhere = 0;
47 return (0);
48}
49
50/*-----------------------------------------------------------------------------
51 * dev_read -- len and where are sectors number
52 *-----------------------------------------------------------------------------
53 */
54int dev_read (void *buffer, int where, int len)
55{
56 PRINTF ("dev_read (len = %d, where = %d)\n", len, where);
57
58 /* Si on ne desire pas lire a la position courante, il faut un seek */
59 if (where != lastwhere) {
wdenk57b2d802003-06-27 21:31:46 +000060 if (!fdc_fdos_seek (where)) {
61 PRINTF ("seek error in dev_read");
62 lastwhere = -1;
63 return (-1);
64 }
wdenk591dda52002-11-18 00:14:45 +000065 }
wdenk57b2d802003-06-27 21:31:46 +000066
wdenk591dda52002-11-18 00:14:45 +000067 if (!fdc_fdos_read (buffer, len)) {
wdenk57b2d802003-06-27 21:31:46 +000068 PRINTF ("read error\n");
69 lastwhere = -1;
70 return (-1);
wdenk591dda52002-11-18 00:14:45 +000071 }
72 lastwhere = where + len;
73 return (0);
74}
75/*-----------------------------------------------------------------------------
76 * check_dev -- verify the diskette format
77 *-----------------------------------------------------------------------------
78 */
79int check_dev (BootSector_t *boot, Fs_t *fs)
80{
81 unsigned int heads, sectors, tracks;
82 int BootP, Infp0, InfpX, InfTm;
83 int sect_per_track;
84
85 /* Display Boot header */
86 PRINTF ("Jump to boot code 0x%02x 0x%02x 0x%02x\n",
wdenk57b2d802003-06-27 21:31:46 +000087 boot -> jump [0], boot -> jump [1], boot -> jump[2]);
wdenk591dda52002-11-18 00:14:45 +000088 PRINTF ("OEM name & version '%*.*s'\n",
wdenk57b2d802003-06-27 21:31:46 +000089 BANNER_LG, BANNER_LG, boot -> banner );
wdenk591dda52002-11-18 00:14:45 +000090 PRINTF ("Bytes per sector hopefully 512 %d\n",
wdenk57b2d802003-06-27 21:31:46 +000091 __le16_to_cpu (boot -> secsiz));
wdenk591dda52002-11-18 00:14:45 +000092 PRINTF ("Cluster size in sectors %d\n",
wdenk57b2d802003-06-27 21:31:46 +000093 boot -> clsiz);
wdenk591dda52002-11-18 00:14:45 +000094 PRINTF ("Number of reserved (boot) sectors %d\n",
wdenk57b2d802003-06-27 21:31:46 +000095 __le16_to_cpu (boot -> nrsvsect));
wdenk591dda52002-11-18 00:14:45 +000096 PRINTF ("Number of FAT tables hopefully 2 %d\n",
wdenk57b2d802003-06-27 21:31:46 +000097 boot -> nfat);
wdenk591dda52002-11-18 00:14:45 +000098 PRINTF ("Number of directory slots %d\n",
wdenk57b2d802003-06-27 21:31:46 +000099 __le16_to_cpu (boot -> dirents));
wdenk591dda52002-11-18 00:14:45 +0000100 PRINTF ("Total sectors on disk %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000101 __le16_to_cpu (boot -> psect));
wdenk591dda52002-11-18 00:14:45 +0000102 PRINTF ("Media descriptor=first byte of FAT %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000103 boot -> descr);
wdenk591dda52002-11-18 00:14:45 +0000104 PRINTF ("Sectors in FAT %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000105 __le16_to_cpu (boot -> fatlen));
wdenk591dda52002-11-18 00:14:45 +0000106 PRINTF ("Sectors/track %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000107 __le16_to_cpu (boot -> nsect));
wdenk591dda52002-11-18 00:14:45 +0000108 PRINTF ("Heads %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000109 __le16_to_cpu (boot -> nheads));
wdenk591dda52002-11-18 00:14:45 +0000110 PRINTF ("number of hidden sectors %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000111 __le32_to_cpu (boot -> nhs));
wdenk591dda52002-11-18 00:14:45 +0000112 PRINTF ("big total sectors %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000113 __le32_to_cpu (boot -> bigsect));
wdenk591dda52002-11-18 00:14:45 +0000114 PRINTF ("physical drive ? %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000115 boot -> physdrive);
wdenk591dda52002-11-18 00:14:45 +0000116 PRINTF ("reserved %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000117 boot -> reserved);
wdenk591dda52002-11-18 00:14:45 +0000118 PRINTF ("dos > 4.0 diskette %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000119 boot -> dos4);
wdenk591dda52002-11-18 00:14:45 +0000120 PRINTF ("serial number %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000121 __le32_to_cpu (boot -> serial));
wdenk591dda52002-11-18 00:14:45 +0000122 PRINTF ("disk label %*.*s\n",
wdenk57b2d802003-06-27 21:31:46 +0000123 LABEL_LG, LABEL_LG, boot -> label);
wdenk591dda52002-11-18 00:14:45 +0000124 PRINTF ("FAT type %8.8s\n",
wdenk57b2d802003-06-27 21:31:46 +0000125 boot -> fat_type);
wdenk591dda52002-11-18 00:14:45 +0000126 PRINTF ("reserved by 2M %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000127 boot -> res_2m);
wdenk591dda52002-11-18 00:14:45 +0000128 PRINTF ("2M checksum (not used) %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000129 boot -> CheckSum);
wdenk591dda52002-11-18 00:14:45 +0000130 PRINTF ("2MF format version %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000131 boot -> fmt_2mf);
wdenk591dda52002-11-18 00:14:45 +0000132 PRINTF ("1 if write track after format %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000133 boot -> wt);
wdenk591dda52002-11-18 00:14:45 +0000134 PRINTF ("data transfer rate on track 0 %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000135 boot -> rate_0);
wdenk591dda52002-11-18 00:14:45 +0000136 PRINTF ("data transfer rate on track<>0 %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000137 boot -> rate_any);
wdenk591dda52002-11-18 00:14:45 +0000138 PRINTF ("offset to boot program %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000139 __le16_to_cpu (boot -> BootP));
wdenk591dda52002-11-18 00:14:45 +0000140 PRINTF ("T1: information for track 0 %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000141 __le16_to_cpu (boot -> Infp0));
wdenk591dda52002-11-18 00:14:45 +0000142 PRINTF ("T2: information for track<>0 %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000143 __le16_to_cpu (boot -> InfpX));
wdenk591dda52002-11-18 00:14:45 +0000144 PRINTF ("T3: track sectors size table %d\n",
wdenk57b2d802003-06-27 21:31:46 +0000145 __le16_to_cpu (boot -> InfTm));
wdenk591dda52002-11-18 00:14:45 +0000146 PRINTF ("Format date 0x%04x\n",
wdenk57b2d802003-06-27 21:31:46 +0000147 __le16_to_cpu (boot -> DateF));
wdenk591dda52002-11-18 00:14:45 +0000148 PRINTF ("Format time 0x%04x\n",
wdenk57b2d802003-06-27 21:31:46 +0000149 __le16_to_cpu (boot -> TimeF));
150
wdenk591dda52002-11-18 00:14:45 +0000151
wdenkcc1e2562003-03-06 13:39:27 +0000152 /* information is extracted from boot sector */
wdenk591dda52002-11-18 00:14:45 +0000153 heads = __le16_to_cpu (boot -> nheads);
154 sectors = __le16_to_cpu (boot -> nsect);
155 fs -> tot_sectors = __le32_to_cpu (boot -> bigsect);
156 if (__le16_to_cpu (boot -> psect) != 0) {
wdenk57b2d802003-06-27 21:31:46 +0000157 fs -> tot_sectors = __le16_to_cpu (boot -> psect);
wdenk591dda52002-11-18 00:14:45 +0000158 }
wdenk57b2d802003-06-27 21:31:46 +0000159
wdenk591dda52002-11-18 00:14:45 +0000160 sect_per_track = heads * sectors;
161 tracks = (fs -> tot_sectors + sect_per_track - 1) / sect_per_track;
wdenk57b2d802003-06-27 21:31:46 +0000162
wdenk591dda52002-11-18 00:14:45 +0000163 BootP = __le16_to_cpu (boot -> BootP);
164 Infp0 = __le16_to_cpu (boot -> Infp0);
165 InfpX = __le16_to_cpu (boot -> InfpX);
166 InfTm = __le16_to_cpu (boot -> InfTm);
wdenk57b2d802003-06-27 21:31:46 +0000167
wdenk591dda52002-11-18 00:14:45 +0000168 if (boot -> dos4 == EXTENDED_BOOT &&
wdenk57b2d802003-06-27 21:31:46 +0000169 strncmp( boot->banner,"2M", 2 ) == 0 &&
170 BootP < SZ_STD_SECTOR &&
171 Infp0 < SZ_STD_SECTOR &&
172 InfpX < SZ_STD_SECTOR &&
173 InfTm < SZ_STD_SECTOR &&
174 BootP >= InfTm + 2 &&
175 InfTm >= InfpX &&
176 InfpX >= Infp0 &&
177 Infp0 >= 76 ) {
wdenk591dda52002-11-18 00:14:45 +0000178
wdenk57b2d802003-06-27 21:31:46 +0000179 return (-1);
wdenk591dda52002-11-18 00:14:45 +0000180 }
181
182 if (heads != NB_HEADS ||
wdenk57b2d802003-06-27 21:31:46 +0000183 tracks != NB_TRACKS ||
184 sectors != NB_SECTORS ||
185 __le16_to_cpu (boot -> secsiz) != SZ_STD_SECTOR ||
186 fs -> tot_sectors == 0 ||
187 (fs -> tot_sectors % sectors) != 0) {
188 return (-1);
wdenk591dda52002-11-18 00:14:45 +0000189 }
wdenk57b2d802003-06-27 21:31:46 +0000190
wdenk591dda52002-11-18 00:14:45 +0000191 return (0);
192}
193
194
195#endif