File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
features/storage/blockdevice Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,18 @@ static int partition_absolute(
99
99
memset (table->entries , 0 , sizeof (table->entries ));
100
100
}
101
101
102
+ // For Windows-formatted SD card, it is not partitioned (no MBR), but its PBR has the
103
+ // same boot signature (0xaa55) as MBR. We would easily mis-recognize this SD card has valid
104
+ // partitions if we only check partition type. We add check by only accepting 0x00 (inactive)
105
+ // /0x80 (active) for valid partition status.
106
+ for (int i = 1 ; i <= 4 ; i++) {
107
+ if (table->entries [i-1 ].status != 0x00 &&
108
+ table->entries [i-1 ].status != 0x80 ) {
109
+ memset (table->entries , 0 , sizeof (table->entries ));
110
+ break ;
111
+ }
112
+ }
113
+
102
114
// Setup new partition
103
115
MBED_ASSERT (part >= 1 && part <= 4 );
104
116
table->entries [part-1 ].status = 0x00 ; // inactive (not bootable)
@@ -243,6 +255,14 @@ int MBRBlockDevice::init()
243
255
goto fail;
244
256
}
245
257
258
+ // Check for valid partition status
259
+ // Same reason as in partition_absolute regarding Windows-formatted SD card
260
+ if (table->entries [_part-1 ].status != 0x00 &&
261
+ table->entries [_part-1 ].status != 0x80 ) {
262
+ err = BD_ERROR_INVALID_PARTITION;
263
+ goto fail;
264
+ }
265
+
246
266
// Check for valid entry
247
267
// 0x00 = no entry
248
268
// 0x05, 0x0f = extended partitions, currently not supported
You can’t perform that action at this time.
0 commit comments