Skip to content

Commit

Permalink
cli: Flash 边界检查
Browse files Browse the repository at this point in the history
  • Loading branch information
xychen committed Aug 8, 2022
1 parent d1fe5f9 commit e90ad86
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cskburn/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,31 @@ serial_burn(cskburn_partition_t *parts, int parts_cnt)
LOGI("chip-id: %016llX", chip_id);
}

uint32_t flash_id = 0;
if (!cskburn_serial_read_flash_id(dev, &flash_id)) {
LOGE("ERROR: Failed detecting flash type");
goto err_enter;
}

LOGD("flash-id: %06X", flash_id);

uint32_t flash_size = 2 << (((flash_id >> 16) & 0xFF) - 1);
LOGI("Detected flash size: %d MB", flash_size >> 20);

for (int i = 0; i < parts_cnt; i++) {
if (parts[i].addr >= flash_size) {
LOGE("ERROR: The starting boundary of partition %d (0x%08X) exceeds the capacity of "
"flash (%d MB)",
i + 1, parts[i].addr, flash_size >> 20);
goto err_enter;
} else if (parts[i].addr + parts[i].size > flash_size) {
LOGE("ERROR: The ending boundary of partition %d (0x%08X) exceeds the capacity of "
"flash (%d MB)",
i + 1, parts[i].addr + parts[i].size, flash_size >> 20);
goto err_enter;
}
}

if (options.verify_count > 0) {
uint8_t md5[MD5_SIZE] = {0};
char md5_str[MD5_SIZE * 2 + 1] = {0};
Expand Down

0 comments on commit e90ad86

Please sign in to comment.