mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
Fix verification with sparse layouts
The full verification step was not accounting for sparse layouts. Instead of the old contents, combine_image_by_layout() implicitly assumed the new contents for unspecified regions. Change-Id: I44e0cea621f2a3d4dc70fa7e93c52ed95e54014a Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/flashrom/+/30370 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
This commit is contained in:
parent
0cacb11c62
commit
3d7b1e3b5c
24
flashrom.c
24
flashrom.c
@ -2430,17 +2430,23 @@ static void combine_image_by_layout(const struct flashctx *const flashctx,
|
|||||||
uint8_t *const newcontents, const uint8_t *const oldcontents)
|
uint8_t *const newcontents, const uint8_t *const oldcontents)
|
||||||
{
|
{
|
||||||
const struct flashrom_layout *const layout = get_layout(flashctx);
|
const struct flashrom_layout *const layout = get_layout(flashctx);
|
||||||
|
const struct romentry *included;
|
||||||
|
chipoff_t start = 0;
|
||||||
|
|
||||||
size_t i;
|
while ((included = layout_next_included_region(layout, start))) {
|
||||||
for (i = 0; i < layout->num_entries; ++i) {
|
if (included->start > start) {
|
||||||
if (layout->entries[i].included)
|
/* copy everything up to the start of this included region */
|
||||||
continue;
|
memcpy(newcontents + start, oldcontents + start, included->start - start);
|
||||||
|
}
|
||||||
const chipoff_t region_start = layout->entries[i].start;
|
/* skip this included region */
|
||||||
const chipsize_t region_len = layout->entries[i].end - layout->entries[i].start + 1;
|
start = included->end + 1;
|
||||||
|
if (start == 0)
|
||||||
memcpy(newcontents + region_start, oldcontents + region_start, region_len);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* copy the rest of the chip */
|
||||||
|
const chipsize_t copy_len = flashctx->chip->total_size * 1024 - start;
|
||||||
|
memcpy(newcontents + start, oldcontents + start, copy_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
18
layout.c
18
layout.c
@ -227,3 +227,21 @@ int normalize_romentries(const struct flashctx *flash)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct romentry *layout_next_included_region(
|
||||||
|
const struct flashrom_layout *const l, const chipoff_t where)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
const struct romentry *lowest = NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < l->num_entries; ++i) {
|
||||||
|
if (!l->entries[i].included)
|
||||||
|
continue;
|
||||||
|
if (l->entries[i].end < where)
|
||||||
|
continue;
|
||||||
|
if (!lowest || lowest->start > l->entries[i].start)
|
||||||
|
lowest = &l->entries[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return lowest;
|
||||||
|
}
|
||||||
|
1
layout.h
1
layout.h
@ -59,5 +59,6 @@ struct flashrom_flashctx;
|
|||||||
const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx);
|
const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx);
|
||||||
|
|
||||||
int process_include_args(struct flashrom_layout *);
|
int process_include_args(struct flashrom_layout *);
|
||||||
|
const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
|
||||||
|
|
||||||
#endif /* !__LAYOUT_H__ */
|
#endif /* !__LAYOUT_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user