| 435 | #define DEFAULT_DECODE_WINDOW_MAX_SIZE (16 * MiB) |
| 436 | |
| 437 | static bool create_mmap_windows(void) |
| 438 | { |
| 439 | static bool done; |
| 440 | |
| 441 | if (done) |
| 442 | return done; |
| 443 | |
| 444 | // No memory map provided, use a default one |
| 445 | if (mmap_window_table_size == 0) { |
| 446 | const size_t image_size = partitioned_file_total_size(param.image_file); |
| 447 | printf("Image SIZE %zu\n", image_size); |
| 448 | const size_t std_window_size = MIN(DEFAULT_DECODE_WINDOW_MAX_SIZE, image_size); |
| 449 | const size_t std_window_flash_offset = image_size - std_window_size; |
| 450 | |
| 451 | /* |
| 452 | * Default decode window lives just below 4G boundary in host space and maps up to a |
| 453 | * maximum of 16MiB. If the window is smaller than 16MiB, the SPI flash window is mapped |
| 454 | * at the top of the host window just below 4G. |
| 455 | */ |
| 456 | if (add_mmap_window(std_window_flash_offset, DEFAULT_DECODE_WINDOW_TOP - std_window_size, std_window_size)) |
| 457 | return false; |
| 458 | } else { |
| 459 | /* |
| 460 | * Check provided memory map |
| 461 | */ |
| 462 | for (int i = 0; i < mmap_window_table_size; i++) { |
| 463 | for (int j = i + 1; j < mmap_window_table_size; j++) { |
| 464 | if (region_overlap(&mmap_window_table[i].flash_space, |
| 465 | &mmap_window_table[j].flash_space)) { |
| 466 | ERROR("Flash space windows (base=0x%zx, limit=0x%zx) and (base=0x%zx, limit=0x%zx) overlap!\n", |
| 467 | region_offset(&mmap_window_table[i].flash_space), |
| 468 | region_last(&mmap_window_table[i].flash_space), |
| 469 | region_offset(&mmap_window_table[j].flash_space), |
| 470 | region_last(&mmap_window_table[j].flash_space)); |
| 471 | return false; |
| 472 | } |
| 473 | |
| 474 | if (region_overlap(&mmap_window_table[i].host_space, |
| 475 | &mmap_window_table[j].host_space)) { |
| 476 | ERROR("Host space windows (base=0x%zx, limit=0x%zx) and (base=0x%zx, limit=0x%zx) overlap!\n", |
| 477 | region_offset(&mmap_window_table[i].flash_space), |
| 478 | region_last(&mmap_window_table[i].flash_space), |
| 479 | region_offset(&mmap_window_table[j].flash_space), |
| 480 | region_last(&mmap_window_table[j].flash_space)); |
| 481 | return false; |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | done = true; |
| 488 | return done; |
| 489 | } |
| 490 | |
| 491 | static unsigned int convert_address(const struct region *to, const struct region *from, |
| 492 | unsigned int addr) |
no test coverage detected