mihaip / infinite-mac

A classic Mac loaded with everything you'd want
https://infinitemac.org
Apache License 2.0
1.12k stars 67 forks source link

Allow for importing and exporting of "device" based images #234

Closed erichelgeson closed 7 months ago

erichelgeson commented 9 months ago

A device based image is an image that is bit for bit what would be on a real device, eg, it has a partition map, SCSI driver, and HFS partition. The new SavedHD feature would make building disk images for devices such as the BlueSCSI easy as one could boot up and install or download software and export it right to their SD card. Many people struggle setting up these emulators on their computer.

I saw your patch to minivmac to allow ISO support, and have modified it to also allow booting a device image https://github.com/mihaip/minivmac/pull/1. That should mean all emulators in this project could now handle these types of images.

I believe what we'd need to do next to allow this is to, on export, build a partition map, inject a scsi driver, and then append the hfs partition. @OneGeekArmy might be able to give us a few pointers as this is what his DiskJockey app does.

that-ben commented 9 months ago

Wow. +1 :+1:

mihaip commented 9 months ago

This would also be useful for #219. DingusPPC emulates a raw SCSI device, so the existing boot images do not work because they only have the HFS partition, they would also need to be wrapped with the partition map and SCSI driver.

https://diskjockey.onegeekarmy.eu/help/technicalinfo/ has some details as to how Disk Jockey operates, will need to track down the details of the partition map.

OneGeekArmy commented 9 months ago

I can probably help :)

mihaip commented 9 months ago

@erichelgeson I've merged in your PR and deployed it -- Mini vMac-based instances on infinitemac.org can now have .hda files dragged in and are able to mount them successfully.

@OneGeekArmy if you have any code or tips to share about formatting the partition table or embedding the driver I would appreciate it, otherwise I'll see what I can figure out.

erichelgeson commented 9 months ago

Via my chat with @OneGeekArmy

This file contains a minimum header to get going with a single HFS partition, currently configured for a 1MB device image.

Things you need to change to make it dynamic: Offset 0x0004: the 4 bytes are the size of the device in blocks, in big endian, including this minimum header (which is 96 blocks in size). So, for a 2048 blocks volume, the value here is 2144 (0x00000860). Offset 0x060C: the 4 bytes here are the size of the HFS partition, in blocks, in big endian. In this minimum header, the value is 2048 (0x00000800). Offset 0x0654: put in the same value you put in 0x060C

Your HFS partition must start at offset 0xC000 (49152). Note that an HFS partition starts with 2 empty blocks (full of zeroes) for an eventual boot block (a leftover from the floppy days).

The 0x4244 magic number identifying the HFS volume should therefore appear at offset 0xC400 (50176).

Minimum_header_3.dat.zip

OneGeekArmy commented 9 months ago

Wish I could help more right now but I'm a little tied up with some family issues. Sorry about this.

erichelgeson commented 9 months ago

You can find datastructures in libhfs - https://github.com/JotaRandom/hfsutils/blob/master/libhfs/apple.h

I also made a ImHex Pattern if you want to poke around in a hex editor https://gist.github.com/erichelgeson/138ff8420917e99be57b6ce615f3400b

mihaip commented 9 months ago

I implemented an initial version of this - when exporting the "Saved HD" there is now an option to save it as a device image/.hda file:

image

Disk Jockey at least appears to be happy with the generated file, let me know if you're able to test it with BlueSCSI or other hardware.

that-ben commented 9 months ago

I own a SCSI2SD and a PiSCSI with a range of old 68K and PPC Macs, if any of those are required for testing. Mac models I own include a Mac Plus, a Mac IIci, a few beige PowerMacs, a few G3 and a MDD G4.

mihaip commented 7 months ago

Closing this out -- based on @RonsCompVids's demo this appears to work https://www.youtube.com/watch?v=2KCb7tuE9Io

joevt commented 3 months ago

This might be unrelated: macOS version of SheepShaver only connects the first HFS partition of a device image. Is it the same with Infinite Mac version? I suppose it doesn't matter if you never connect an image with multiple HFS partitions.

Regarding the partition map, you can use my dumpvols.sh script to dump that info.