fb: Add a prototype for board_video_skip()
[platform/kernel/u-boot.git] / fs / fdos / dev.c
1 /*
2  * (C) Copyright 2002
3  * Stäubli Faverges - <www.staubli.com>
4  * Pierre AUBERT  p.aubert@staubli.com
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <common.h>
10 #include <config.h>
11
12 #include "dos.h"
13 #include "fdos.h"
14
15 #define NB_HEADS        2
16 #define NB_TRACKS       80
17 #define NB_SECTORS      18
18
19
20 static int lastwhere;
21
22 /*-----------------------------------------------------------------------------
23  * dev_open --
24  *-----------------------------------------------------------------------------
25  */
26 int dev_open (void)
27 {
28     lastwhere = 0;
29     return (0);
30 }
31
32 /*-----------------------------------------------------------------------------
33  * dev_read -- len and where are sectors number
34  *-----------------------------------------------------------------------------
35  */
36 int dev_read (void *buffer, int where, int len)
37 {
38     PRINTF ("dev_read (len = %d, where = %d)\n", len, where);
39
40     /* Si on ne desire pas lire a la position courante, il faut un seek      */
41     if (where != lastwhere) {
42         if (!fdc_fdos_seek (where)) {
43             PRINTF ("seek error in dev_read");
44             lastwhere = -1;
45             return (-1);
46         }
47     }
48
49     if (!fdc_fdos_read (buffer, len)) {
50         PRINTF ("read error\n");
51         lastwhere = -1;
52         return (-1);
53     }
54     lastwhere = where + len;
55     return (0);
56 }
57 /*-----------------------------------------------------------------------------
58  * check_dev -- verify the diskette format
59  *-----------------------------------------------------------------------------
60  */
61 int check_dev (BootSector_t *boot, Fs_t *fs)
62 {
63     unsigned int heads, sectors, tracks;
64     int BootP, Infp0, InfpX, InfTm;
65     int sect_per_track;
66
67     /* Display Boot header                                                   */
68     PRINTF ("Jump to boot code                  0x%02x 0x%02x 0x%02x\n",
69             boot -> jump [0], boot -> jump [1], boot -> jump[2]);
70     PRINTF ("OEM name & version                 '%*.*s'\n",
71             BANNER_LG, BANNER_LG, boot -> banner );
72     PRINTF ("Bytes per sector hopefully 512     %d\n",
73             __le16_to_cpu (boot -> secsiz));
74     PRINTF ("Cluster size in sectors            %d\n",
75             boot -> clsiz);
76     PRINTF ("Number of reserved (boot) sectors  %d\n",
77             __le16_to_cpu (boot -> nrsvsect));
78     PRINTF ("Number of FAT tables hopefully 2   %d\n",
79             boot -> nfat);
80     PRINTF ("Number of directory slots          %d\n",
81             __le16_to_cpu (boot -> dirents));
82     PRINTF ("Total sectors on disk              %d\n",
83             __le16_to_cpu (boot -> psect));
84     PRINTF ("Media descriptor=first byte of FAT %d\n",
85             boot -> descr);
86     PRINTF ("Sectors in FAT                     %d\n",
87             __le16_to_cpu (boot -> fatlen));
88     PRINTF ("Sectors/track                      %d\n",
89             __le16_to_cpu (boot -> nsect));
90     PRINTF ("Heads                              %d\n",
91             __le16_to_cpu (boot -> nheads));
92     PRINTF ("number of hidden sectors           %d\n",
93             __le32_to_cpu (boot -> nhs));
94     PRINTF ("big total sectors                  %d\n",
95             __le32_to_cpu (boot -> bigsect));
96     PRINTF ("physical drive ?                   %d\n",
97             boot -> physdrive);
98     PRINTF ("reserved                           %d\n",
99             boot -> reserved);
100     PRINTF ("dos > 4.0 diskette                 %d\n",
101             boot -> dos4);
102     PRINTF ("serial number                      %d\n",
103             __le32_to_cpu (boot -> serial));
104     PRINTF ("disk label                         %*.*s\n",
105             LABEL_LG, LABEL_LG, boot -> label);
106     PRINTF ("FAT type                           %8.8s\n",
107             boot -> fat_type);
108     PRINTF ("reserved by 2M                     %d\n",
109             boot -> res_2m);
110     PRINTF ("2M checksum (not used)             %d\n",
111             boot -> CheckSum);
112     PRINTF ("2MF format version                 %d\n",
113             boot -> fmt_2mf);
114     PRINTF ("1 if write track after format      %d\n",
115             boot -> wt);
116     PRINTF ("data transfer rate on track 0      %d\n",
117             boot -> rate_0);
118     PRINTF ("data transfer rate on track<>0     %d\n",
119             boot -> rate_any);
120     PRINTF ("offset to boot program             %d\n",
121             __le16_to_cpu (boot -> BootP));
122     PRINTF ("T1: information for track 0        %d\n",
123             __le16_to_cpu (boot -> Infp0));
124     PRINTF ("T2: information for track<>0       %d\n",
125             __le16_to_cpu (boot -> InfpX));
126     PRINTF ("T3: track sectors size table       %d\n",
127             __le16_to_cpu (boot -> InfTm));
128     PRINTF ("Format date                        0x%04x\n",
129             __le16_to_cpu (boot -> DateF));
130     PRINTF ("Format time                        0x%04x\n",
131             __le16_to_cpu (boot -> TimeF));
132
133
134     /* information is extracted from boot sector                           */
135     heads = __le16_to_cpu (boot -> nheads);
136     sectors = __le16_to_cpu (boot -> nsect);
137     fs -> tot_sectors = __le32_to_cpu (boot -> bigsect);
138     if (__le16_to_cpu (boot -> psect) != 0) {
139         fs -> tot_sectors = __le16_to_cpu (boot -> psect);
140     }
141
142     sect_per_track = heads * sectors;
143     tracks = (fs -> tot_sectors + sect_per_track - 1) / sect_per_track;
144
145     BootP = __le16_to_cpu (boot -> BootP);
146     Infp0 = __le16_to_cpu (boot -> Infp0);
147     InfpX = __le16_to_cpu (boot -> InfpX);
148     InfTm = __le16_to_cpu (boot -> InfTm);
149
150     if (boot -> dos4 == EXTENDED_BOOT &&
151         strncmp( boot->banner,"2M", 2 ) == 0 &&
152         BootP < SZ_STD_SECTOR &&
153         Infp0 < SZ_STD_SECTOR &&
154         InfpX < SZ_STD_SECTOR &&
155         InfTm < SZ_STD_SECTOR &&
156         BootP >= InfTm + 2 &&
157         InfTm >= InfpX &&
158         InfpX >= Infp0 &&
159         Infp0 >= 76 ) {
160
161         return (-1);
162     }
163
164     if (heads != NB_HEADS ||
165         tracks != NB_TRACKS ||
166         sectors != NB_SECTORS ||
167         __le16_to_cpu (boot -> secsiz) != SZ_STD_SECTOR ||
168         fs -> tot_sectors == 0 ||
169         (fs -> tot_sectors % sectors) != 0) {
170         return (-1);
171     }
172
173     return (0);
174 }