Buildable boot drive support, not sure it works.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23379 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol
2008-01-11 01:41:37 +00:00
parent 2e99fa6ed4
commit 89ae49c791
+36 -24
View File
@@ -12,6 +12,7 @@
#include <string.h> #include <string.h>
#include "Handle.h"
#include "toscalls.h" #include "toscalls.h"
//#define TRACE_DEVICES //#define TRACE_DEVICES
@@ -30,7 +31,7 @@ extern uint32 gBootPartitionOffset;
#define SCRATCH_SIZE (2*4096) #define SCRATCH_SIZE (2*4096)
static uint8 gScratchBuffer[4096]; static uint8 gScratchBuffer[4096];
static const uint16 kParametersSizeVersion1 = 0x1a; static const uint16 kParametersSizeVersion1 = sizeof(struct tosbpb);
static const uint16 kParametersSizeVersion2 = 0x1e; static const uint16 kParametersSizeVersion2 = 0x1e;
static const uint16 kParametersSizeVersion3 = 0x42; static const uint16 kParametersSizeVersion3 = 0x42;
@@ -144,19 +145,25 @@ class BlockHandle : public Handle {
static bool sBlockDevicesAdded = false; static bool sBlockDevicesAdded = false;
static status_t
read_bpb(uint8 drive, struct tosbpb *bpb)
{
struct tosbpb *p;
p = Getbpb(drive);
memcpy(bpb, p, sizeof(struct tosbpb));
/* Getbpb is buggy so we must force a media change */
//XXX: docs seems to assume we should loop until it works
Mediach(drive);
return B_OK;
}
static status_t static status_t
get_drive_parameters(uint8 drive, drive_parameters *parameters) get_drive_parameters(uint8 drive, drive_parameters *parameters)
{ {
struct bios_regs regs; status_t err;
regs.eax = BIOS_GET_DRIVE_PARAMETERS; err = read_bpb(drive, &parameters->bpb);
regs.edx = drive;
regs.es = 0;
regs.edi = 0; // guard against faulty BIOS, see Ralf Brown's interrupt list
call_bios(0x13, &regs);
if ((regs.flags & CARRY_FLAG) != 0 || (regs.ecx & 0x3f) == 0)
return B_ERROR;
#if 0
// fill drive_parameters structure with useful values // fill drive_parameters structure with useful values
parameters->parameters_size = kParametersSizeVersion1; parameters->parameters_size = kParametersSizeVersion1;
parameters->flags = 0; parameters->flags = 0;
@@ -167,11 +174,12 @@ get_drive_parameters(uint8 drive, drive_parameters *parameters)
parameters->sectors = parameters->cylinders * parameters->heads parameters->sectors = parameters->cylinders * parameters->heads
* parameters->sectors_per_track; * parameters->sectors_per_track;
parameters->bytes_per_sector = 512; parameters->bytes_per_sector = 512;
#endif
return B_OK; return B_OK;
} }
#if 0
/** parse EDD 3.0 drive path information */ /** parse EDD 3.0 drive path information */
static status_t static status_t
@@ -250,7 +258,7 @@ fill_disk_identifier_v2(disk_identifier &disk, const drive_parameters &parameter
return B_OK; return B_OK;
} }
#endif
static off_t static off_t
get_next_check_sum_offset(int32 index, off_t maxSize) get_next_check_sum_offset(int32 index, off_t maxSize)
@@ -387,7 +395,7 @@ add_block_devices(NodeList *devicesList, bool identifierMissing)
{ {
int32 map; int32 map;
uint8 driveID; uint8 driveID;
uint8 driveCount; uint8 driveCount = 0;
if (sBlockDevicesAdded) if (sBlockDevicesAdded)
return B_OK; return B_OK;
@@ -410,6 +418,7 @@ add_block_devices(NodeList *devicesList, bool identifierMissing)
} }
devicesList->Add(drive); devicesList->Add(drive);
driveCount++;
if (drive->FillIdentifier() != B_OK) if (drive->FillIdentifier() != B_OK)
identifierMissing = true; identifierMissing = true;
@@ -444,6 +453,15 @@ BlockHandle::BlockHandle(int handle)
} }
//XXX: check size //XXX: check size
if (get_drive_parameters(fHandle, &fParameters) != B_OK) {
dprintf("getting drive parameters for: %u failed!\n", fHandle);
return;
}
fBlockSize = 512;
fSize = fParameters.sectors * fBlockSize;
fHasParameters = false;
#if 0
if (get_ext_drive_parameters(driveID, &fParameters) != B_OK) { if (get_ext_drive_parameters(driveID, &fParameters) != B_OK) {
// old style CHS support // old style CHS support
@@ -476,6 +494,7 @@ BlockHandle::BlockHandle(int handle)
fLBA = true; fLBA = true;
fHasParameters = true; fHasParameters = true;
} }
#endif
} }
@@ -564,6 +583,7 @@ BlockHandle::Size() const
status_t status_t
BlockHandle::FillIdentifier() BlockHandle::FillIdentifier()
{ {
#if 0
if (HasParameters()) { if (HasParameters()) {
// try all drive_parameters versions, beginning from the most informative // try all drive_parameters versions, beginning from the most informative
@@ -595,22 +615,12 @@ BlockHandle::FillIdentifier()
fIdentifier.device.unknown.check_sums[i].offset = -1; fIdentifier.device.unknown.check_sums[i].offset = -1;
fIdentifier.device.unknown.check_sums[i].sum = 0; fIdentifier.device.unknown.check_sums[i].sum = 0;
} }
#endif
return B_ERROR; return B_ERROR;
} }
status_t
BlockHandle::ReadBPB(struct tosbpb *bpb)
{
struct tosbpb *p;
p = Getbpb(fHandle);
memcpy(bpb, p, sizeof(struct tosbpb));
/* Getbpb is buggy so we must force a media change */
//XXX: docs seems to assume we should loop until it works
Mediach(fHandle);
return B_OK;
}
// #pragma mark - // #pragma mark -
@@ -681,7 +691,9 @@ platform_register_boot_device(Node *device)
{ {
BlockHandle *drive = (BlockHandle *)device; BlockHandle *drive = (BlockHandle *)device;
#if 0
check_cd_boot(drive); check_cd_boot(drive);
#endif
gKernelArgs.boot_volume.SetInt64("boot drive number", drive->DriveID()); gKernelArgs.boot_volume.SetInt64("boot drive number", drive->DriveID());
gKernelArgs.boot_volume.SetData(BOOT_VOLUME_DISK_IDENTIFIER, B_RAW_TYPE, gKernelArgs.boot_volume.SetData(BOOT_VOLUME_DISK_IDENTIFIER, B_RAW_TYPE,