Skip to content

Commit

Permalink
arcfw: show if ramdisk loaded, allow loading it again if it didn't
Browse files Browse the repository at this point in the history
Workaround to the load attempt being too fast for some devices.
  • Loading branch information
Wack0 committed Jul 15, 2024
1 parent cc6fe49 commit f356abf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ NT4 only, currently. NT 3.51 may become compatible if HAL and drivers get ported

### Installing NT

* If ARC firmware does not show `drivers.img ramdisk loaded`, go to `Run firmware setup`, then `Load driver ramdisk` - make sure it succeeds before continuing.
* Eject CD and insert your NT4 CD.
* Go to `Run a program` and enter the path `cd:\ppc\setupldr` - this may be `cd01:` or `cd02:` (...) if you have multiple optical drives present on your system.
* This may error with `The file or device does not exist`, just go back to `Run a program` and try again if so.
Expand Down
20 changes: 12 additions & 8 deletions arcgrackle/source/arcconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,13 @@ static const DEVICE_VECTORS s_RdVectors = {
.GetDirectoryEntry = NULL
};

bool ArcHasRamdiskLoaded(void);
void ArcInitRamDisk(ULONG ControllerKey, PVOID Pointer, ULONG Length);

void ArcDiskInitRamdisk(void) {
ARC_STATUS ArcDiskInitRamdisk(void) {
if (ArcHasRamdiskLoaded()) return _ESUCCESS;
// Ensure there are enough spaces for 3 components (controller, disk, fdisk).
if (g_AdditionalComponentsCount > (MAXIMUM_DEVICE_COUNT - 3)) return;
if (g_AdditionalComponentsCount > (MAXIMUM_DEVICE_COUNT - 3)) return _ENOSPC;

PVENDOR_VECTOR_TABLE Api = ARC_VENDOR_VECTORS();

Expand All @@ -750,6 +752,7 @@ void ArcDiskInitRamdisk(void) {
ArcDiskGetCounts(NULL, &CountCdrom);

// Walk through all CDROMs
ARC_STATUS Status = _EFAULT;
for (ULONG i = 0; i < CountCdrom; i++) {
char CdVar[6];
char Path[1024];
Expand All @@ -759,7 +762,7 @@ void ArcDiskInitRamdisk(void) {

// Open file
U32LE FileId;
ARC_STATUS Status = Api->OpenRoutine(Path, ArcOpenReadOnly, &FileId);
Status = Api->OpenRoutine(Path, ArcOpenReadOnly, &FileId);
if (ARC_FAIL(Status)) continue;

do {
Expand All @@ -786,6 +789,7 @@ void ArcDiskInitRamdisk(void) {
}
if (Count.v != FileSize32) {
FileSize32 = 0;
Status = _EIO;
break;
}

Expand All @@ -795,23 +799,23 @@ void ArcDiskInitRamdisk(void) {
break;
}

if (Ramdisk == NULL || FileSize32 == 0) return;
if (Ramdisk == NULL || FileSize32 == 0) return Status;

// Grab the root device.
PDEVICE_ENTRY Root = ArcGetChild(NULL);
// Add the ramdisk controller and ensure it uses an unused key.
PDEVICE_ENTRY RdControl = (PDEVICE_ENTRY)ArcAddChild(&Root->Component, &s_RamdiskController, NULL);
if (RdControl == NULL) {
printf("ArcAddChild(Root, RamdiskController) failed\r\n");
return;
return _EFAULT;
}
while (ArcConfigKeyExists(RdControl)) RdControl->Component.Key++;
// Same, but for disk controller.
// There is only one child of the rd controller, so no need to search for unused key.
PDEVICE_ENTRY RdDisk = ArcAddChild(&RdControl->Component, &s_RamdiskDisk, NULL);
if (RdDisk == NULL) {
printf("ArcAddChild(RamdiskController, RamdiskDisk) failed\r\n");
return;
return _EFAULT;
}
// Same, but for fixed disk device.
s_RamdiskResource.Descriptors[0].Memory.Length = FileSize32;
Expand All @@ -820,15 +824,15 @@ void ArcDiskInitRamdisk(void) {
PDEVICE_ENTRY RdFdisk = ArcAddChild(&RdDisk->Component, &s_RamdiskFdisk, &s_RamdiskResource);
if (RdFdisk == NULL) {
printf("ArcAddChild(RamdiskDisk, RamdiskFdisk) failed\r\n");
return;
return _EFAULT;
}

// Set up the vectors for fixed disk device.
RdFdisk->Vectors = &s_RdVectors;

// Initialise the runtime descriptor for the NT driver.
ArcInitRamDisk(RdControl->Component.Key, Ramdisk, FileSize32);

return _ESUCCESS;
}

void ArcConfigInit(void) {
Expand Down
2 changes: 1 addition & 1 deletion arcgrackle/source/arcdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ ULONG ArcDiskGetSizeMb(ULONG Disk) {
return s_SizeDiskMb[Disk];
}

void ArcDiskInitRamdisk(void);
ARC_STATUS ArcDiskInitRamdisk(void);

void ArcDiskInit() {
ArcDiskIdeInit();
Expand Down
17 changes: 17 additions & 0 deletions arcgrackle/source/fwsetup.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
enum {
SETUP_MENU_CHOICE_SYSPART,
SETUP_MENU_CHOICE_UPDATE,
SETUP_MENU_CHOICE_LOADRD,
SETUP_MENU_CHOICE_NOMBRBOOT,
SETUP_MENU_CHOICE_EXIT,
SETUP_MENU_CHOICES_COUNT
Expand Down Expand Up @@ -505,13 +506,16 @@ static PCHAR ArcFwGetSystemPartitionDrive(PCHAR SysPart) {
return SysPart;
}

ARC_STATUS ArcDiskInitRamdisk(void);

void ArcFwSetup(void) {
while (1) {
ULONG DefaultChoice = 0;
// Initialise the menu.
PCHAR MenuChoices[SETUP_MENU_CHOICES_COUNT] = {
"Repartition disk for NT installation",
"Update boot partition on disk",
"Load driver ramdisk",
"Reboot to OSX install or OS8/OS9",
"Exit"
};
Expand Down Expand Up @@ -595,6 +599,19 @@ void ArcFwSetup(void) {
return;
}

if (DefaultChoice == SETUP_MENU_CHOICE_LOADRD) {
ARC_STATUS Status = ArcDiskInitRamdisk();
if (ARC_SUCCESS(Status)) {
printf(" Loaded ramdisk successfully\r\n");
}
else {
printf(" Failed to load ramdisk: %s\r\n", ArcGetErrorString(Status));
}
printf(" Press any key to continue...\r\n");
IOSKBD_ReadChar();
return;
}

if (DefaultChoice == SETUP_MENU_CHOICE_NOMBRBOOT) {
PVENDOR_VECTOR_TABLE Api = ARC_VENDOR_VECTORS();
// Get the system partition drive
Expand Down
6 changes: 6 additions & 0 deletions arcgrackle/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ static void PrintDevices(ULONG DiskCount, ULONG CdromCount) {
snprintf(PathName, sizeof(PathName), "cd%02d:", Cd);
printf(" %s - %s\r\n", Cd == 0 ? "cd:" : PathName, ArcEnvGetDevice(PathName));
}
// then ramdisk
if (s_RuntimeRamdisk.Buffer.Length != 0) printf(" drivers.img ramdisk loaded\r\n");
}

bool ArcHasRamdiskLoaded(void) {
return (s_RuntimeRamdisk.Buffer.Length != 0);
}

void ArcInitRamDisk(ULONG ControllerKey, PVOID Pointer, ULONG Length) {
Expand Down

0 comments on commit f356abf

Please sign in to comment.