Subject: Re: restorecd, fdisk problems on cobalt
To: None <port-cobalt@netbsd.org>
From: Eric Auge <eau@phear.org>
List: port-cobalt
Date: 12/30/2007 10:31:48
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigE627D47D72C34079BE1F6C35
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Eric Auge wrote:
> Izumi Tsutsui wrote:
>> eau@phear.org wrote:
>>
>>> Well for now the cd boot i've changed install.sh to do ${SH} -i
>>> in order to have a shell prompt, so they are executing correctly
>>> at boot.. if I made errors, I will be able to correct easily.
>> Diff of install-core.sh might help.
>>
>>> # dd if=3D/dev/zero of=3D/dev/rwd0d count=3D1
>>> 1+0 records in
>>> 1+0 records out
>>> 512 bytes transferred in 0.003 secs (170666 bytes/sec)
>>> # fdisk -S /dev/wd0
>>> [1]   Trace/BPT trap          fdisk -S /dev/wd0
>>> #
>>>
>>> Still not good, MBR cleaned, but still crashing..
>>>
>>> what else could it be?
>> Hmm, You could try
>> - fdisk wd0  (not /dev/wd0)
>> - fdisk -S wd0  (not /dev/wd0)
>> - fdisk -S -b 1024/255/63 wd0
>> - fdisk -0 -u -f -b 1024/255/63 -s 0/0/0 wd0
>> - fdisk -v -0 -u -f -b 1024/255/63 -s 0/0/0 wd0
>> etc?
>>
>> (fdisk(8) man page description for -b, -f and -u seems inconsistent..)=

>>
>>>> fdisk(8) seems problematic on non-x86 ports (which don't have BIOS v=
alues),
>>>> but I have not tracked what triggers it.
>>> I try to look at fdisk srcs ... any starting point is welcome anyway.=

>> I guess the problem is in intuit_translated_geometry()
>> and get_mapping() in src/sbin/fdisk/fdisk.c.
>> Maybe we should add some sanity checks if each parameter
>> read from disk isn't zero, but sprinkling printf()s there
>> might help to track the problem.
>=20
> # ./usr/bin/gdb /sbin/fdisk
> GNU gdb 5.3nb1
> Copyright 2002 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and yo=
u are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for deta=
ils.
> This GDB was configured as "mipsel--netbsd"...(no debugging symbols
> found)...
> (gdb) run -S wd0
> Starting program: /sbin/fdisk -S wd0
> (no debugging symbols found)...(no debugging symbols found)...
> (no debugging symbols found)...
> Program received signal SIGTRAP, Trace/breakpoint trap.
> 0x00402cc4 in intuit_translated_geometry ()
> (gdb) bt
> #0  0x00402cc4 in intuit_translated_geometry ()
> #1  0x00407580 in main ()
> #2  0x00401628 in _start ()
> (gdb)
>=20
> good catch! :)
>=20
> I'm trying to go further...
>=20
(gdb) run -S wd0
Starting program: /sbin/fdisk -S wd0
(no debugging symbols found)...(no debugging symbols found)...
(no debugging symbols found)...
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00402cc4 in intuit_translated_geometry ()
(gdb)
(gdb) disass intuit_translated_geometry
Dump of assembler code for function intuit_translated_geometry:
[...]
0x402cbc <intuit_translated_geometry+1208>:
    bnez        v0,0x402cc8 <intuit_translated_geometry+1220>
0x402cc0 <intuit_translated_geometry+1212>:     divu    zero,s7,v0
0x402cc4 <intuit_translated_geometry+1216>:     break   0x7
0x402cc8 <intuit_translated_geometry+1220>:     mflo    v1
[...]

I don't know MIPS assembly.. yet, but I guess bnez is branch not equal
zero v0, <addr to branch to>, but

(gdb) p $v0
$2 =3D 0

so it will
divu zero, s7, v0

so indeed it looks like a divide by zero, the value in s7 is
(gdb) p $s7
$1 =3D 21168

which seems to be the offset for the swap partition, apparently..
[...]
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:   2097648   1201536     4.2BSD   1024  8192    64  # (Cyl.   1192 -
  3272)
 b:   1180368     21168       swap                     # (Cyl.     21 -
  1191)
[...]

So I guess it's failing in this subpart of intuit_translated_geometry():

[...]
1459     /* Try to deduce the number of heads from two different
mappings. */
1460     for (i =3D 0; i < MBR_PART_COUNT * 2 - 1; i++) {
1461         if (get_mapping(i, &c1, &h1, &s1, &a1) < 0)
1462             continue;
1463         a1 -=3D s1;
1464         for (j =3D i + 1; j < MBR_PART_COUNT * 2; j++) {
1465             if (get_mapping(j, &c2, &h2, &s2, &a2) < 0)
1466                 continue;
1467             a2 -=3D s2;
1468             num =3D (uint64_t)h1 * a2 - (uint64_t)h2 * a1;
1469             denom =3D (uint64_t)c2 * a1 - (uint64_t)c1 * a2;
1470             if (denom !=3D 0 && num % denom =3D=3D 0) {
1471                 xheads =3D num / denom;
1472                 xsectors =3D a1 / (c1 * xheads + h1);
1473                 break;
1474             }
1475         }
1476         if (xheads !=3D -1)
1477             break;
1478     }
[...]

But I'm not sure what it is doing... :/

I keep investigating..

HTH,
Thanks,
Regards,
Eric.

>> ---
>> Izumi Tsutsui
>>
> Eric.
>=20



--------------enigE627D47D72C34079BE1F6C35
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (NetBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHd2WISdZNA80H8MYRAnoZAJ9bCixsqt5JX0g2p/6h2DkjD/h/ogCgpLPx
GrZCeI+kl8ixRmVr0YhtRz0=
=WYQa
-----END PGP SIGNATURE-----

--------------enigE627D47D72C34079BE1F6C35--