Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mac sanity checks when Apple quirks mode is enabled #303

Merged
merged 3 commits into from
Sep 21, 2023

Conversation

morio
Copy link
Collaborator

@morio morio commented Sep 19, 2023

The main purpose of this code is to emit warnings when Mac quirks are turned on and the image(s) are disks.

The warnings are emitted if any of the following checks fail:
- The disk image contain Apple Magic signature
- The HFS block size is correct
- The Mac SCSI driver is smaller than or equal to the max size
- The MAC SCSI driver is smaller than or equal to the image size
- The Lido driver is not installed

The original implementation put the sanity checks under platform code. Since none of the code is platform specific, it has been moved to the root src directory so all build targets can take advantage of the sanity checks.

Initial code authored by Eric Helgeson and taken from: BlueSCSI/BlueSCSI-v2@cc1ff5f BlueSCSI/BlueSCSI-v2@d00ebe0

The main purpose of this code is to emit warnings when Mac quirks are
turned on and the image(s) are disks.

The warnings are emitted if any of the following checks fail:
    - The disk image contain Apple Magic signature
    - The HFS block size is correct
    - The Mac SCSI driver is smaller than or equal to the max size
    - The MAC SCSI driver is smaller than or equal to the image size
    - The Lido driver is not installed

The original implementation put the sanity checks under platform code.
Since none of the code is platform specific, it has been moved
to the root src directory so all build targets can take advantage
of the sanity checks.

Initial code authored by Eric Helgeson and taken from:
BlueSCSI/BlueSCSI-v2@cc1ff5f
BlueSCSI/BlueSCSI-v2@d00ebe0

Co-authored-by:  Eric Helgeson <[email protected]>
Copy link
Collaborator

@PetteriAimonen PetteriAimonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think currently this doesn't check any continuous image file, because they get converted to raw mapping.


void quirksCheck(image_config_t *img)
{
macQuirksSanityCheck(img);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to have if (img->quirks == S2S_CFG_QUIRKS_APPLE) { macQuirksSanityCheck(img); } here, instead of checking it on line 96.

That way there won't be any spurious debug messages when the quirks aren't enabled for the device.

dbgmsg("---- Skipping Mac sanity check due to DisableMacSanityCheck");
return;
}
if(img->file.isRom() || img->file.isRaw())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImageBackingStore constructor converts contiguous files to raw mappings. So this check will skip most image files.

Is there a particular reason to skip the check for raw mappings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think BlueSCSI wanted to skip raw pass through and neither of us understood what m_israw actually means. Getting rid of it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got it seeking and reading on SD_SECTOR_SIZE blocks, that means we can actually do a sanity check for ROM images too?


// Check for Apple Magic
img->file.seek(0);
img->file.read(tmp, 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason why raw mappings are excluded in the macQuirksSanityCheck() is these unaligned accesses, which won't work because raw access must be in whole SD blocks. This ends up excluding any continuous image file.

This could be modified to be uint8_t tmp[SD_SECTOR_SIZE]; img->file.seek(0); img.file.read(tmp, SD_SECTOR_SIZE); and then comparing against specific bytes in the tmp array.

Comment on lines 2 to 3
* Portions - Copyright (C) 2023 Eric Helgeson
* ZuluSCSI™ - Copyright (c) 2022-2023 Rabbit Hole Computing™
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order of copyright notices seems wrong, most of the code in this file is from Rabbit Hole Computing.

src/ImageBackingStore.cpp Show resolved Hide resolved
@morio
Copy link
Collaborator Author

morio commented Sep 20, 2023

Thanks for the feedback @PetteriAimonen, I'll implement the changes.

Addressed recommendation from code review in the pull request:
#303

The main issue was the ImageBackingStore store driver
seeks and reads weren't being accessed by SD card blocks of 512 bytes.

After remedying the issue, both raw and rom mode can go through
the sanity checks.
@morio
Copy link
Collaborator Author

morio commented Sep 20, 2023

@PetteriAimonen I think I addressed all the issues. I also removed the isRom() check because all reads and seeks are on SD_SECTOR_SIZE boundaries.

@aperezbios
Copy link
Collaborator

@morio I noticed that the CI builds for ZuluSCSI V1.x are failing:

ZuluSCSIv1_0           FAILED    00:00:19.653
ZuluSCSIv1_0_mini      FAILED    00:00:01.305
ZuluSCSIv1_1           FAILED    00:00:01.583

Copy link
Collaborator

@PetteriAimonen PetteriAimonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good now.

The build failure is a missing #include <assert.h> in QuirksCheck.cpp.

ZuluSCSI's based on the GD32F205 were failing to build because
of a missing assert.h include in src/QuirksCheck.cpp.

Added the include and the builds were successful.
@aperezbios aperezbios changed the title Add Mac sanity checks Add Mac sanity checks when Apple quirks mode is enabled Sep 21, 2023
@aperezbios aperezbios merged commit f8c47a2 into main Sep 21, 2023
@aperezbios aperezbios deleted the mac-sanity-checks branch September 21, 2023 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants