mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #8346 from OpenNuvoton/nuvoton_fix_mbr
storage: fix valid partion check with windows formatted sd cardpull/8556/head
commit
fc741f03a1
|
@ -99,6 +99,18 @@ static int partition_absolute(
|
||||||
memset(table->entries, 0, sizeof(table->entries));
|
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
|
// Setup new partition
|
||||||
MBED_ASSERT(part >= 1 && part <= 4);
|
MBED_ASSERT(part >= 1 && part <= 4);
|
||||||
table->entries[part-1].status = 0x00; // inactive (not bootable)
|
table->entries[part-1].status = 0x00; // inactive (not bootable)
|
||||||
|
@ -243,6 +255,14 @@ int MBRBlockDevice::init()
|
||||||
goto fail;
|
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
|
// Check for valid entry
|
||||||
// 0x00 = no entry
|
// 0x00 = no entry
|
||||||
// 0x05, 0x0f = extended partitions, currently not supported
|
// 0x05, 0x0f = extended partitions, currently not supported
|
||||||
|
|
Loading…
Reference in New Issue