@@ -192,6 +192,21 @@ std::unique_ptr<block> find_first_block(std::vector<uint8_t> bin, uint32_t stora
192
192
}
193
193
194
194
195
+ void set_block_ignored (elf_file *elf, uint32_t block_addr) {
196
+ auto seg = elf->segment_from_physical_address (block_addr);
197
+ if (seg == nullptr ) {
198
+ fail (ERROR_NOT_POSSIBLE, " The ELF file does not contain the block address %x" , block_addr);
199
+ }
200
+ std::vector<uint8_t > content = elf->content (*seg);
201
+ uint32_t offset = block_addr + 4 - seg->physical_address ();
202
+ if ((content[offset] & 0x7f ) != PICOBIN_BLOCK_ITEM_PARTITION_TABLE) {
203
+ DEBUG_LOG (" setting block at %08x to ignored\n " , block_addr);
204
+ content[offset] = 0x7e ;
205
+ }
206
+ elf->content (*seg, content);
207
+ }
208
+
209
+
195
210
void set_next_block (elf_file *elf, std::unique_ptr<block> &first_block, uint32_t highest_address) {
196
211
// todo this isn't right, but virtual should be physical for now
197
212
auto seg = elf->segment_from_physical_address (first_block->physical_addr );
@@ -214,6 +229,15 @@ void set_next_block(elf_file *elf, std::unique_ptr<block> &first_block, uint32_t
214
229
}
215
230
216
231
232
+ void set_block_ignored (std::vector<uint8_t > &bin, uint32_t storage_addr, uint32_t block_addr) {
233
+ uint32_t offset = block_addr + 4 - storage_addr;
234
+ if ((bin[offset] & 0x7f ) != PICOBIN_BLOCK_ITEM_PARTITION_TABLE) {
235
+ DEBUG_LOG (" setting block at %08x to ignored\n " , block_addr);
236
+ bin[offset] = 0x7e ;
237
+ }
238
+ }
239
+
240
+
217
241
void set_next_block (std::vector<uint8_t > &bin, uint32_t storage_addr, std::unique_ptr<block> &first_block, uint32_t highest_address) {
218
242
// todo this isn't right, but virtual should be physical for now
219
243
uint32_t offset = first_block->physical_addr + first_block->next_block_rel_index * 4 - storage_addr;
@@ -230,7 +254,7 @@ void set_next_block(std::vector<uint8_t> &bin, uint32_t storage_addr, std::uniqu
230
254
}
231
255
232
256
233
- block place_new_block (elf_file *elf, std::unique_ptr<block> &first_block) {
257
+ block place_new_block (elf_file *elf, std::unique_ptr<block> &first_block, bool set_others_ignored ) {
234
258
uint32_t highest_ram_address = 0 ;
235
259
uint32_t highest_flash_address = 0 ;
236
260
bool no_flash = false ;
@@ -265,8 +289,10 @@ block place_new_block(elf_file *elf, std::unique_ptr<block> &first_block) {
265
289
set_next_block (elf, first_block, highest_address);
266
290
loop_start_rel = -first_block->next_block_rel ;
267
291
new_block_addr = first_block->physical_addr + first_block->next_block_rel ;
292
+ if (set_others_ignored) set_block_ignored (elf, first_block->physical_addr );
268
293
} else {
269
294
DEBUG_LOG (" There is already a block loop\n " );
295
+ if (set_others_ignored) set_block_ignored (elf, first_block->physical_addr );
270
296
uint32_t next_block_addr = first_block->physical_addr + first_block->next_block_rel ;
271
297
while (true ) {
272
298
auto segment = elf->segment_from_physical_address (next_block_addr);
@@ -300,6 +326,7 @@ block place_new_block(elf_file *elf, std::unique_ptr<block> &first_block) {
300
326
break ;
301
327
} else {
302
328
DEBUG_LOG (" Continue looping\n " );
329
+ if (set_others_ignored) set_block_ignored (elf, new_first_block->physical_addr );
303
330
next_block_addr = new_first_block->physical_addr + new_first_block->next_block_rel ;
304
331
new_first_block.reset ();
305
332
}
@@ -399,7 +426,7 @@ std::unique_ptr<block> get_last_block(std::vector<uint8_t> &bin, uint32_t storag
399
426
}
400
427
401
428
402
- block place_new_block (std::vector<uint8_t > &bin, uint32_t storage_addr, std::unique_ptr<block> &first_block) {
429
+ block place_new_block (std::vector<uint8_t > &bin, uint32_t storage_addr, std::unique_ptr<block> &first_block, bool set_others_ignored ) {
403
430
uint32_t highest_ram_address = 0 ;
404
431
uint32_t highest_flash_address = 0 ;
405
432
bool no_flash = false ;
@@ -431,9 +458,14 @@ block place_new_block(std::vector<uint8_t> &bin, uint32_t storage_addr, std::uni
431
458
set_next_block (bin, storage_addr, first_block, highest_address);
432
459
loop_start_rel = -first_block->next_block_rel ;
433
460
new_block_addr = first_block->physical_addr + first_block->next_block_rel ;
461
+ if (set_others_ignored) set_block_ignored (bin, storage_addr, first_block->physical_addr );
434
462
} else {
435
463
DEBUG_LOG (" Ooh, there is already a block loop - lets find it's end\n " );
436
- new_first_block = get_last_block (bin, storage_addr, first_block);
464
+ auto all_blocks = get_all_blocks (bin, storage_addr, first_block);
465
+ for (auto &block : all_blocks) {
466
+ if (set_others_ignored) set_block_ignored (bin, storage_addr, block->physical_addr );
467
+ }
468
+ new_first_block = std::move (all_blocks.back ());
437
469
set_next_block (bin, storage_addr, new_first_block, highest_address);
438
470
new_block_addr = new_first_block->physical_addr + new_first_block->next_block_rel ;
439
471
loop_start_rel = first_block->physical_addr - new_block_addr;
0 commit comments