Fix mis-recognize that Windows-formatted SD card has valid partitions

For Windows-formatted SD card, it is not partitioned (no MBR), but its PBR has the
same boot signature (0xaa55) as MBR. We would easily mis-recognize this SD card has valid
partitions if we only check partition type. We add check by only accepting 0x00 (inactive)
/0x80 (active) for valid partition status.
pull/8346/head
ccli8 2018-10-09 10:58:43 +08:00
parent fd4f47d18f
commit 8ef23ff54d
1 changed files with 20 additions and 0 deletions

View File

@ -97,6 +97,18 @@ static int partition_absolute(
memset(table->entries, 0, sizeof(table->entries));
}
// For Windows-formatted SD card, it is not partitioned (no MBR), but its PBR has the
// same boot signature (0xaa55) as MBR. We would easily mis-recognize this SD card has valid
// partitions if we only check partition type. We add check by only accepting 0x00 (inactive)
// /0x80 (active) for valid partition status.
for (int i = 1; i <= 4; i++) {
if (table->entries[i-1].status != 0x00 &&
table->entries[i-1].status != 0x80) {
memset(table->entries, 0, sizeof(table->entries));
break;
}
}
// Setup new partition
MBED_ASSERT(part >= 1 && part <= 4);
table->entries[part-1].status = 0x00; // inactive (not bootable)
@ -241,6 +253,14 @@ int MBRBlockDevice::init()
goto fail;
}
// Check for valid partition status
// Same reason as in partition_absolute regarding Windows-formatted SD card
if (table->entries[_part-1].status != 0x00 &&
table->entries[_part-1].status != 0x80) {
err = BD_ERROR_INVALID_PARTITION;
goto fail;
}
// Check for valid entry
// 0x00 = no entry
// 0x05, 0x0f = extended partitions, currently not supported