File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ static int partition_absolute(
96
96
table->entries [part-1 ].type = type;
97
97
98
98
// lba dimensions
99
+ MBED_ASSERT (bd->is_valid_erase (offset, size));
99
100
uint32_t sector = std::max<uint32_t >(bd->get_erase_size (), 512 );
100
101
uint32_t lba_offset = offset / sector;
101
102
uint32_t lba_size = size / sector;
@@ -106,6 +107,19 @@ static int partition_absolute(
106
107
tochs (lba_offset, table->entries [part-1 ].chs_start );
107
108
tochs (lba_offset+lba_size-1 , table->entries [part-1 ].chs_stop );
108
109
110
+ // Check that we don't overlap other entries
111
+ for (int i = 1 ; i <= 4 ; i++) {
112
+ if (i != part && table->entries [i-1 ].type != 0x00 ) {
113
+ uint32_t neighbor_lba_offset = fromle32 (table->entries [i-1 ].lba_offset );
114
+ uint32_t neighbor_lba_size = fromle32 (table->entries [i-1 ].lba_size );
115
+ MBED_ASSERT (
116
+ (lba_offset >= neighbor_lba_offset + neighbor_lba_size) ||
117
+ (lba_offset + lba_size <= neighbor_lba_offset));
118
+ (void )neighbor_lba_offset;
119
+ (void )neighbor_lba_size;
120
+ }
121
+ }
122
+
109
123
// Write out MBR
110
124
err = bd->erase (0 , bd->get_erase_size ());
111
125
if (err) {
You can’t perform that action at this time.
0 commit comments