Merge remote-tracking branch 'sherbszt/gfxboot32'
[profile/ivi/syslinux.git] / memdisk / fdgeo.pl
1 #!/usr/bin/perl
2 #
3 # Try automatic generation of geometries
4 #
5
6 ($k) = @ARGV;
7 $sec = int($k*2+0.5);
8
9 if ($sec < 320*2) {
10     $c = 40;
11     $h = 1;
12     $type = 1;
13 } elsif ($sec < 640*2) {
14     $c = 40;
15     $h = 2;
16     $type = 1;
17 } elsif ($sec < 1200*2) {
18     $c = 80;
19     $h = 2;
20     $type = 3;
21 } elsif ($sec < 1440*2) {
22     $c = 80;
23     $h = 2;
24     $type = 2;
25 } elsif ($sec < 2880*2) {
26     $c = 80;
27     $h = 2;
28     $type = 4;
29 } elsif ($sec < 4096*2) {
30     $c = 80;
31     $h = 2;
32     $type = 6;
33 } else {
34     printf "%.1fK, %d sectors: ", $sec/2, $sec;
35     print "Considered a hard disk\n";
36     exit 2;
37 }
38
39 $ok = 0;
40 while ($c < 256) {
41     $s = int($sec/($c*$h)+0.5);
42     if ($s <= 63 && $sec == $c*$h*$s) {
43         $ok = 1;
44         last;
45     }
46     $c++;
47 }
48
49 printf "%.1fK, %d sectors: ", $sec/2, $sec;
50 if ($ok) {
51     print "c=$c, h=$h, s=$s, type=$type\n";
52     exit 0;
53 } else {
54     print "No valid geometry found (MEMDISK will fake it)\n";
55     exit 1;
56 }