feat: aarch64 port - Raspberry Pi 4/400 SD boot (SDHCI, ext2 root + first-boot grow), USB hubs, PCI INTx routing, SMP, DMA fences
This commit is contained in:
1 parent
8c09ccef66
commit
808e1d66fd
66 files changed
+3690
-196
No files matched your search
@@ -107,6 +107,8 @@ namespace Drivers::Storage::Gpt {
|
||||
return GUID_LINUX_SWAP;
|
||||
case 0x83:
|
||||
return GUID_LINUX_FS;
|
||||
case 0xEF:
|
||||
return GUID_EFI_SYSTEM;
|
||||
default:
|
||||
return GUID_BASIC_DATA;
|
||||
}
|
||||
@@ -551,6 +553,78 @@ namespace Drivers::Storage::Gpt {
|
||||
return removed;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// MBR partition resize
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// Read sector 0 into mbr and return the primary slot that holds `part`, or
|
||||
// -1 when the device is GPT (protective MBR) or `part` is not a primary
|
||||
// entry (a logical partition inside an extended one).
|
||||
static int FindMbrSlot(const PartitionInfo& part, ProtectiveMbr& mbr) {
|
||||
const BlockDevice* dev = GetBlockDevice(part.BlockDevIndex);
|
||||
if (!dev || !dev->ReadSectors(dev->Ctx, 0, 1, &mbr)) return -1;
|
||||
if (mbr.Signature != 0xAA55 || ValidateProtectiveMbr((const uint8_t*)&mbr)) return -1;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const MbrPartitionEntry& e = mbr.Partitions[i];
|
||||
if (e.Type == 0 || IsExtendedMbrType(e.Type)) continue;
|
||||
if (e.LbaFirst == part.StartLba && e.SectorCount == part.SectorCount) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint64_t GetMbrPartitionMaxSectors(int index) {
|
||||
const PartitionInfo* part = GetPartition(index);
|
||||
if (!part) return 0;
|
||||
|
||||
ProtectiveMbr mbr;
|
||||
if (FindMbrSlot(*part, mbr) < 0) return 0;
|
||||
const BlockDevice* dev = GetBlockDevice(part->BlockDevIndex);
|
||||
|
||||
// Stop at whichever primary entry starts next (an extended entry covers
|
||||
// every logical partition inside it), else at the end of the device.
|
||||
uint64_t end = dev->SectorCount;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const MbrPartitionEntry& e = mbr.Partitions[i];
|
||||
if (e.Type == 0 || e.SectorCount == 0) continue;
|
||||
if (e.LbaFirst > part->StartLba && e.LbaFirst < end) end = e.LbaFirst;
|
||||
}
|
||||
|
||||
// The entry stores a 32-bit sector count; keep the end addressable too.
|
||||
if (end > 0xFFFFFFFFull) end = 0xFFFFFFFFull;
|
||||
return end > part->StartLba ? end - part->StartLba : 0;
|
||||
}
|
||||
|
||||
int ResizeMbrPartition(int index, uint64_t sectorCount) {
|
||||
if (index < 0 || index >= g_partitionCount) return -1;
|
||||
PartitionInfo& part = g_partitions[index];
|
||||
if (sectorCount < part.SectorCount) return -1;
|
||||
if (sectorCount > GetMbrPartitionMaxSectors(index)) return -1;
|
||||
if (sectorCount == part.SectorCount) return 0;
|
||||
|
||||
ProtectiveMbr mbr;
|
||||
int slot = FindMbrSlot(part, mbr);
|
||||
if (slot < 0) return -1;
|
||||
|
||||
MbrPartitionEntry& e = mbr.Partitions[slot];
|
||||
e.SectorCount = (uint32_t)sectorCount;
|
||||
// CHS cannot address past 8 GiB; FE FF FF tells CHS-era tools to use
|
||||
// the LBA fields instead.
|
||||
e.ChsLast[0] = 0xFE;
|
||||
e.ChsLast[1] = 0xFF;
|
||||
e.ChsLast[2] = 0xFF;
|
||||
|
||||
const BlockDevice* dev = GetBlockDevice(part.BlockDevIndex);
|
||||
if (!dev->WriteSectors(dev->Ctx, 0, 1, &mbr)) return -1;
|
||||
if (dev->Flush) dev->Flush(dev->Ctx);
|
||||
|
||||
KernelLogStream(OK, "MBR") << "Partition " << index << " grown from "
|
||||
<< part.SectorCount << " to " << sectorCount << " sectors";
|
||||
part.SectorCount = sectorCount;
|
||||
part.EndLba = part.StartLba + sectorCount - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// ASCII to UTF-16LE for partition names
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user