andreiw / RaspberryPiPkg

DEPRECATED - DO NOT USE | Go here instead ->
https://github.com/tianocore/edk2-platforms/tree/master/Platform/RaspberryPi/RPi3
744 stars 143 forks source link

Write tool to support booting hybrid GPT/MBR disks in UEFI (for Windows) #36

Closed andreiw closed 4 years ago

andreiw commented 5 years ago

Merge https://github.com/Googulator/RaspberryPiPkg/commit/844a02a473b147e621e8d4709b6eaababd8fa2d9 in a TBD fashion

Googulator commented 5 years ago

Looks like this won't be needed after all, see my comment in the megathread.

andreiw commented 5 years ago

According to @Googulator:

OK, looks like we won't need that ugly SD driver hack at all.

**The Pi, in addition to MBR, can also boot from a so-called "superfloppy" SD card, which has no partition table, just the file system header (VBR) right at the beginning. Additionally, the only thing it actually checks for is the FAT32 BPB (BIOS parameter block), located at address 0x0B-0x56 (inclusive) in the VBR sector. Since the partition table is in 0x1BE-0x1EE, you can have both a BPB and a protective MBR in sector 0. In such a scenario, Windows and UEFI give precedence to the protective MBR and the GPT, while the boot ROM prefers the BPB.

Additionally, FAT32 allows having an arbitrary number of reserved sectors between the VBR and the beginning of the file system proper.

So, assuming that the first GPT partition on the drive is the ESP formatted to FAT32, beginning in sector #2048 (Windows typically creates the ESP there), it's possible to copy the BPB from sector 2048 to sector 0 (copy offset 0x10000B-0x100056 to offset 0x0B-0x56), and then add 2048 to the "reserved sector count" value (a 16-bit little-endian integer at offset 0x0E-0x0F - the boot ROM uses it to find the FAT). This way, the boot ROM will see a superfloppy, and everything else will parse the GPT, as intended.**

andreiw commented 5 years ago

Basically at this point this issue tracks the development of a tool to patch a a GPT SD image/device into a Pi-bootable "superfloppy"

Googulator commented 5 years ago

So, all that the tool needs to do is this (assuming ESP at sector 2048):

  1. Copy 76 bytes from offset 0x10000B to offset 0xB
  2. Increment byte at offset 0xF by 8

On Linux, this is trivial. On Windows, it's a PITA due to how Windows handles physical device writes.

mariobalanica commented 5 years ago

Setting the FAT32 boot MBR partition as active also fixes the first boot error. The only issue is that after Windows finishes the configuration it will hang at a black screen and restart if any USB device is plugged in. After that it will boot normally.

andreiw commented 5 years ago

So there is no need for a hybrid GPT?

A

On Jul 8, 2018, at 11:48 AM, Mario Bălănică notifications@github.com wrote:

Setting the FAT32 boot MBR partition as active also fixes the first boot error. The only issue is that after Windows finishes the configuration it will hang at a black screen and restart if any USB device is plugged in. After that it will boot normally.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

mariobalanica commented 5 years ago

No.