mirror of
https://review.coreboot.org/flashrom.git
synced 2025-05-13 14:50:59 +02:00
flashrom.c:Add function to align region to sector boundaries
Add a function to align start and end address of the region (in struct walk_info) to some erase sector boundaries and modify the region start and end addresses to match nearest erase sector boundaries. This function will be used in the new algorithm for erase function selection. Change-Id: I215ea4986aa23360fc65ff761f4e49c6069160ac Signed-off-by: Aarya Chaumal <aarya.chaumal@gmail.com>
This commit is contained in:
parent
22c621aed2
commit
26e98f6f06
26
flashrom.c
26
flashrom.c
@ -22,6 +22,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -1010,6 +1011,31 @@ static int walk_eraseblocks(struct flashctx *const flashctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void align_region(const struct erase_layout *layout, struct flashctx *const flashctx, chipoff_t *region_start, chipoff_t *region_end);
|
||||||
|
|
||||||
|
void align_region(const struct erase_layout *layout, struct flashctx *const flashctx, chipoff_t *region_start, chipoff_t *region_end)
|
||||||
|
{
|
||||||
|
chipoff_t start_diff = UINT_MAX, end_diff = UINT_MAX;
|
||||||
|
int erasefn_count = count_usable_erasers(flashctx);
|
||||||
|
for (int i = 0; i < erasefn_count; i++) {
|
||||||
|
for (size_t j = 0; j < layout[i].block_count; j++) {
|
||||||
|
if (layout[i].layout_list[j].start_addr <= *region_start)
|
||||||
|
start_diff = (*region_start - layout[i].layout_list[j].start_addr) > start_diff ? start_diff : (*region_start - layout[i].layout_list[j].start_addr);
|
||||||
|
if (layout[i].layout_list[j].end_addr >= *region_end)
|
||||||
|
end_diff = (layout[i].layout_list[j].end_addr - *region_end) > end_diff ? end_diff : (layout[i].layout_list[j].end_addr - *region_end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_diff) {
|
||||||
|
msg_cinfo("Region start not sector aligned!! Extending start boundaries...\n");
|
||||||
|
*region_start = *region_start - start_diff;
|
||||||
|
}
|
||||||
|
if (end_diff) {
|
||||||
|
msg_cinfo("Region end not sector aligned!! Extending end boundaries...\n");
|
||||||
|
*region_end = *region_end + end_diff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int walk_by_layout(struct flashctx *const flashctx, struct walk_info *const info,
|
static int walk_by_layout(struct flashctx *const flashctx, struct walk_info *const info,
|
||||||
const per_blockfn_t per_blockfn)
|
const per_blockfn_t per_blockfn)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user