Merge pull request #8346 from OpenNuvoton/nuvoton_fix_mbr

storage: fix valid partion check with windows formatted sd card
pull/8556/head
Martin Kojtal 2018-10-26 09:37:28 +01:00 committed by GitHub
commit fc741f03a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -99,6 +99,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)
@ -243,6 +255,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