summaryrefslogtreecommitdiff
path: root/sys/arch/i386
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1997-10-24 22:22:58 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1997-10-24 22:22:58 +0000
commit827306a31a907dbc5f7d70266ecaa69365799bec (patch)
treed351ae52fa09963d648371c3f718a97158523f10 /sys/arch/i386
parent7ae8e04243646e3289cc73db68915e88382906f1 (diff)
checksumming stuff from niklas
Diffstat (limited to 'sys/arch/i386')
-rw-r--r--sys/arch/i386/stand/libsa/cmd_i386.c20
-rw-r--r--sys/arch/i386/stand/libsa/diskprobe.c113
-rw-r--r--sys/arch/i386/stand/libsa/libsa.h3
3 files changed, 74 insertions, 62 deletions
diff --git a/sys/arch/i386/stand/libsa/cmd_i386.c b/sys/arch/i386/stand/libsa/cmd_i386.c
index 30e10bc23f9..2e641f00094 100644
--- a/sys/arch/i386/stand/libsa/cmd_i386.c
+++ b/sys/arch/i386/stand/libsa/cmd_i386.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd_i386.c,v 1.16 1997/10/23 15:13:27 weingart Exp $ */
+/* $OpenBSD: cmd_i386.c,v 1.17 1997/10/24 22:22:56 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff, Tobias Weingartner
@@ -61,18 +61,18 @@ Xdiskinfo()
{
int i;
- printf("Disk\tBIOS#\t BSD#\tCylinders\tHeads\tSectors\tChecksum\n");
+ printf(
+ "Disk\tBIOS#\tBSD#\t\tCyls\tHeads\tSecs\tFlags\tChecksum(%d)\n",
+ bios_cksumlen);
for(i = 0; bios_diskinfo[i].bios_number != -1 && i < 10; i++){
int d = bios_diskinfo[i].bios_number;
- printf("%cd%d\t 0x%x\t0x%x\t %s%d \t%d\t%d\t0x%x[%d]\n",
- (d & 0x80)?'h':'f', (d & 0x80)?d - 128:d, d,
- bios_diskinfo[i].bsd_dev,
- (bios_diskinfo[i].bios_cylinders < 100)?" ":" ",
- bios_diskinfo[i].bios_cylinders,
- bios_diskinfo[i].bios_heads,
- bios_diskinfo[i].bios_sectors,
- bios_diskinfo[i].checksum, bios_diskinfo[i].checklen);
+ printf(
+ "%cd%d\t0x%x\t0x%x\t%d\t%d\t%d\t0x%x\t0x%x\n",
+ (d & 0x80)?'h':'f', (d & 0x80)?d - 128:d, d,
+ bios_diskinfo[i].bsd_dev, bios_diskinfo[i].bios_cylinders,
+ bios_diskinfo[i].bios_heads, bios_diskinfo[i].bios_sectors,
+ bios_diskinfo[i].flags, bios_diskinfo[i].checksum);
}
return 0;
diff --git a/sys/arch/i386/stand/libsa/diskprobe.c b/sys/arch/i386/stand/libsa/diskprobe.c
index 080871da11a..317ca36f348 100644
--- a/sys/arch/i386/stand/libsa/diskprobe.c
+++ b/sys/arch/i386/stand/libsa/diskprobe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diskprobe.c,v 1.5 1997/10/24 01:38:51 weingart Exp $ */
+/* $OpenBSD: diskprobe.c,v 1.6 1997/10/24 22:22:57 mickey Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -41,12 +41,14 @@
#include "biosdev.h"
#include "libsa.h"
+#define MAX_CKSUMLEN 32 /* Max amount of diskblocks used in cksum */
/* Local Prototypes */
-static void disksum __P((bios_diskinfo_t*));
+static int disksum __P((int));
/* These get passed to kernel */
bios_diskinfo_t bios_diskinfo[16];
+u_int32_t bios_cksumlen;
/* Probe for all BIOS disks */
void
@@ -62,7 +64,12 @@ diskprobe()
for(drive = 0; drive < 4; drive++) {
rv = bios_getinfo(drive, &bios_diskinfo[i]);
- if(rv) break;
+ if(rv) {
+#ifdef BIOS_DEBUG
+ printf(" <!fd%u>", drive);
+#endif
+ break;
+ }
printf(" fd%u", drive);
@@ -75,7 +82,12 @@ diskprobe()
for(drive = 0x80; drive < 0x88; drive++) {
rv = bios_getinfo(drive, &bios_diskinfo[i]);
- if(rv) break;
+ if(rv) {
+#ifdef BIOS_DEBUG
+ printf(" <!hd%u>", drive);
+#endif
+ break;
+ }
unit = drive - 0x80;
printf(" hd%u%s", unit, (bios_diskinfo[i].bios_edd > 0?"+":""));
@@ -86,15 +98,26 @@ diskprobe()
type = 0; /* XXX let it be IDE */
} else {
/* Best guess */
- if (label.d_type == DTYPE_SCSI)
+ switch (label.d_type) {
+ case DTYPE_SCSI:
type = 4;
- else
+ bios_diskinfo[i].flags |= BDI_GOODLABEL;
+ break;
+
+ case DTYPE_ESDI:
+ case DTYPE_ST506:
type = 0;
+ bios_diskinfo[i].flags |= BDI_GOODLABEL;
+ break;
+
+ default:
+ bios_diskinfo[i].flags |= BDI_BADLABEL;
+ type = 0; /* XXX Suggest IDE */
+ }
}
/* Fill out best we can */
bios_diskinfo[i].bsd_dev = MAKEBOOTDEV(type, 0, 0, unit, 0);
- disksum(&bios_diskinfo[i]);
i++;
}
@@ -103,6 +126,12 @@ diskprobe()
addbootarg(BOOTARG_DISKINFO,
(i + 1) * sizeof(bios_diskinfo[0]), bios_diskinfo);
+ /* Checksumming of hard disks */
+ for (i = 0; disksum(i) && i < MAX_CKSUMLEN; i++)
+ ;
+ bios_cksumlen = i + 1;
+ addbootarg(BOOTARG_CKSUMLEN, sizeof(u_int32_t), &bios_cksumlen);
+
printf("\n");
}
@@ -120,63 +149,45 @@ bios_dklookup(dev)
return(NULL);
}
-/* Find given sum in diskinfo array */
-static bios_diskinfo_t *
-find_sum(sum)
- u_int32_t sum;
-{
- int i;
-
- for(i = 0; bios_diskinfo[i].bios_number != -1; i++)
- if(bios_diskinfo[i].checksum == sum)
- return(&bios_diskinfo[i]);
-
- return(NULL);
-}
-
-/* Checksum given drive until different
+/*
+ * Checksum one more block on all harddrives
*
* Use the adler32() function from libz,
* as it is quick, small, and available.
*/
-static void
-disksum(bdi)
- bios_diskinfo_t *bdi;
+static int
+disksum(blk)
+ int blk;
{
- u_int32_t sum;
- int len, st;
+ bios_diskinfo_t *bdi, *bd;
+ int st, reprobe = 0;
int hpc, spt, dev;
char *buf;
+ int cyl, head, sect;
buf = alloca(DEV_BSIZE);
- dev = bdi->bios_number;
- hpc = bdi->bios_heads;
- spt = bdi->bios_sectors;
-
- /* Adler32 checksum */
- sum = adler32(0, NULL, 0);
- for(len = 0; len < 32; len++){
- int cyl, head, sect;
- bios_diskinfo_t *bd;
+ for (bdi = bios_diskinfo; bdi->bios_number != -1; bdi++) {
+ /* Skip this disk if it is not a HD or has had an I/O error */
+ if (!(bdi->bios_number & 0x80) || bdi->flags & BDI_INVALID)
+ continue;
- btochs(len, cyl, head, sect, hpc, spt);
+ dev = bdi->bios_number;
+ hpc = bdi->bios_heads;
+ spt = bdi->bios_sectors;
+ /* Adler32 checksum */
+ btochs(blk, cyl, head, sect, hpc, spt);
st = biosd_io(F_READ, dev, cyl, head, sect, 1, buf);
- if(st) break;
-
- sum = adler32(sum, buf, DEV_BSIZE);
+ if (st) {
+ bdi->flags |= BDI_INVALID;
+ continue;
+ }
+ bdi->checksum = adler32(bdi->checksum, buf, DEV_BSIZE);
- /* Do a minimum of 8 sectors */
- if((len >= 8) && ((bd = find_sum(sum)) == NULL))
- break;
+ for (bd = bios_diskinfo; bd != bdi; bd++)
+ if (bdi->checksum == bd->checksum)
+ reprobe = 1;
}
- if(st) {
- bdi->checksum = 0;
- bdi->checklen = 0;
- } else {
- bdi->checksum = sum;
- bdi->checklen = len;
- }
+ return (reprobe);
}
-
diff --git a/sys/arch/i386/stand/libsa/libsa.h b/sys/arch/i386/stand/libsa/libsa.h
index dba1ac8ae9f..4f0da047c1f 100644
--- a/sys/arch/i386/stand/libsa/libsa.h
+++ b/sys/arch/i386/stand/libsa/libsa.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: libsa.h,v 1.21 1997/10/22 23:34:39 mickey Exp $ */
+/* $OpenBSD: libsa.h,v 1.22 1997/10/24 22:22:57 mickey Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -54,6 +54,7 @@ extern u_int cnvmem, extmem; /* XXX global pass memprobe()->machdep_start() */
/* diskprobe.c */
extern bios_diskinfo_t bios_diskinfo[];
+extern u_int32_t bios_cksumlen;
/* memprobe.c */
extern bios_memmap_t *memory_map;