mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 15:12:36 +02:00
layout: Introduce flashrom_layout_new()
It initializes an empty layout. Currently the maximum number of entries has to be specified, which will vanish once we use dynamic allocation per entry. We replace the two special cases `single_layout` and `ich_layout` with dynamically allocated layouts. As a result, we have to take care to release the `default_layout` in a flashctx once we are done with it. Change-Id: I2ae7246493ff592e631cce924777925c7825e398 Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/flashrom/+/33543 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
parent
f394fcec0d
commit
c32c8dc8af
@ -854,8 +854,10 @@ out_release:
|
|||||||
out_shutdown:
|
out_shutdown:
|
||||||
programmer_shutdown();
|
programmer_shutdown();
|
||||||
out:
|
out:
|
||||||
for (i = 0; i < chipcount; i++)
|
for (i = 0; i < chipcount; i++) {
|
||||||
|
flashrom_layout_release(flashes[i].default_layout);
|
||||||
free(flashes[i].chip);
|
free(flashes[i].chip);
|
||||||
|
}
|
||||||
|
|
||||||
layout_cleanup(&include_args);
|
layout_cleanup(&include_args);
|
||||||
free(filename);
|
free(filename);
|
||||||
|
2
flash.h
2
flash.h
@ -265,7 +265,7 @@ struct flashrom_flashctx {
|
|||||||
chipaddr virtual_registers;
|
chipaddr virtual_registers;
|
||||||
struct registered_master *mst;
|
struct registered_master *mst;
|
||||||
const struct flashrom_layout *layout;
|
const struct flashrom_layout *layout;
|
||||||
struct single_layout fallback_layout;
|
struct flashrom_layout *default_layout;
|
||||||
struct {
|
struct {
|
||||||
bool force;
|
bool force;
|
||||||
bool force_boardmismatch;
|
bool force_boardmismatch;
|
||||||
|
13
flashrom.c
13
flashrom.c
@ -822,15 +822,12 @@ notfound:
|
|||||||
if (!flash->chip)
|
if (!flash->chip)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Fill fallback layout covering the whole chip. */
|
/* Fill default layout covering the whole chip. */
|
||||||
struct single_layout *const fallback = &flash->fallback_layout;
|
if (flashrom_layout_new(&flash->default_layout, 1) ||
|
||||||
fallback->base.entries = &fallback->entry;
|
flashrom_layout_add_region(flash->default_layout,
|
||||||
fallback->base.capacity = 1;
|
|
||||||
fallback->base.num_entries = 0;
|
|
||||||
if (flashrom_layout_add_region(&fallback->base,
|
|
||||||
0, flash->chip->total_size * 1024 - 1, "complete flash") ||
|
0, flash->chip->total_size * 1024 - 1, "complete flash") ||
|
||||||
flashrom_layout_include_region(&fallback->base, "complete flash"))
|
flashrom_layout_include_region(flash->default_layout, "complete flash"))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
tmp = flashbuses_to_text(flash->chip->bustype);
|
tmp = flashbuses_to_text(flash->chip->bustype);
|
||||||
msg_cinfo("%s %s flash chip \"%s\" (%d kB, %s) ", force ? "Assuming" : "Found",
|
msg_cinfo("%s %s flash chip \"%s\" (%d kB, %s) ", force ? "Assuming" : "Found",
|
||||||
|
@ -1261,7 +1261,9 @@ int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_d
|
|||||||
* 1 if the descriptor couldn't be parsed,
|
* 1 if the descriptor couldn't be parsed,
|
||||||
* 2 when out of memory.
|
* 2 when out of memory.
|
||||||
*/
|
*/
|
||||||
int layout_from_ich_descriptors(struct ich_layout *const layout, const void *const dump, const size_t len)
|
int layout_from_ich_descriptors(
|
||||||
|
struct flashrom_layout **const layout,
|
||||||
|
const void *const dump, const size_t len)
|
||||||
{
|
{
|
||||||
static const char *const regions[] = {
|
static const char *const regions[] = {
|
||||||
"fd", "bios", "me", "gbe", "pd", "reg5", "bios2", "reg7", "ec", "reg9", "ie",
|
"fd", "bios", "me", "gbe", "pd", "reg5", "bios2", "reg7", "ec", "reg9", "ie",
|
||||||
@ -1277,10 +1279,8 @@ int layout_from_ich_descriptors(struct ich_layout *const layout, const void *con
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(layout, 0x00, sizeof(*layout));
|
if (flashrom_layout_new(layout, ARRAY_SIZE(regions)))
|
||||||
layout->base.entries = layout->entries;
|
return 2;
|
||||||
layout->base.capacity = ARRAY_SIZE(layout->entries);
|
|
||||||
layout->base.num_entries = 0;
|
|
||||||
|
|
||||||
ssize_t i;
|
ssize_t i;
|
||||||
const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
|
const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
|
||||||
@ -1289,8 +1289,11 @@ int layout_from_ich_descriptors(struct ich_layout *const layout, const void *con
|
|||||||
const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
|
const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
|
||||||
if (limit <= base)
|
if (limit <= base)
|
||||||
continue;
|
continue;
|
||||||
if (flashrom_layout_add_region(&layout->base, base, limit, regions[i]))
|
if (flashrom_layout_add_region(*layout, base, limit, regions[i])) {
|
||||||
|
flashrom_layout_release(*layout);
|
||||||
|
*layout = NULL;
|
||||||
return 2;
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -564,11 +564,6 @@ struct ich_descriptors {
|
|||||||
struct ich_desc_upper_map upper;
|
struct ich_desc_upper_map upper;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ich_layout {
|
|
||||||
struct flashrom_layout base;
|
|
||||||
struct romentry entries[MAX_NUM_FLREGS];
|
|
||||||
};
|
|
||||||
|
|
||||||
ssize_t ich_number_of_regions(enum ich_chipset cs, const struct ich_desc_content *content);
|
ssize_t ich_number_of_regions(enum ich_chipset cs, const struct ich_desc_content *content);
|
||||||
ssize_t ich_number_of_masters(enum ich_chipset cs, const struct ich_desc_content *content);
|
ssize_t ich_number_of_masters(enum ich_chipset cs, const struct ich_desc_content *content);
|
||||||
|
|
||||||
@ -587,6 +582,6 @@ int read_ich_descriptors_from_dump(const uint32_t *dump, size_t len, enum ich_ch
|
|||||||
int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc);
|
int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc);
|
||||||
int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx);
|
int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx);
|
||||||
|
|
||||||
int layout_from_ich_descriptors(struct ich_layout *, const void *dump, size_t len);
|
int layout_from_ich_descriptors(struct flashrom_layout **, const void *dump, size_t len);
|
||||||
|
|
||||||
#endif /* __ICH_DESCRIPTORS_H__ */
|
#endif /* __ICH_DESCRIPTORS_H__ */
|
||||||
|
28
layout.c
28
layout.c
@ -38,7 +38,7 @@ const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const f
|
|||||||
if (flashctx->layout && flashctx->layout->num_entries)
|
if (flashctx->layout && flashctx->layout->num_entries)
|
||||||
return flashctx->layout;
|
return flashctx->layout;
|
||||||
else
|
else
|
||||||
return &flashctx->fallback_layout.base;
|
return flashctx->default_layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct romentry *mutable_layout_next(
|
static struct romentry *mutable_layout_next(
|
||||||
@ -383,6 +383,32 @@ const struct romentry *layout_next(
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a new, empty layout.
|
||||||
|
*
|
||||||
|
* @param layout Pointer to returned layout reference.
|
||||||
|
* @param count Number of layout entries to allocate.
|
||||||
|
*
|
||||||
|
* @return 0 on success,
|
||||||
|
* 1 if out of memory.
|
||||||
|
*/
|
||||||
|
int flashrom_layout_new(struct flashrom_layout **const layout, const unsigned int count)
|
||||||
|
{
|
||||||
|
*layout = malloc(sizeof(**layout) + count * sizeof(struct romentry));
|
||||||
|
if (!*layout) {
|
||||||
|
msg_gerr("Error creating layout: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct flashrom_layout tmp = {
|
||||||
|
.entries = (void *)((char *)*layout + sizeof(**layout)),
|
||||||
|
.capacity = count,
|
||||||
|
.num_entries = 0,
|
||||||
|
};
|
||||||
|
**layout = tmp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add another region to an existing layout.
|
* @brief Add another region to an existing layout.
|
||||||
*
|
*
|
||||||
|
5
layout.h
5
layout.h
@ -52,11 +52,6 @@ struct flashrom_layout {
|
|||||||
size_t num_entries;
|
size_t num_entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct single_layout {
|
|
||||||
struct flashrom_layout base;
|
|
||||||
struct romentry entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct layout_include_args {
|
struct layout_include_args {
|
||||||
char *name;
|
char *name;
|
||||||
char *file;
|
char *file;
|
||||||
|
@ -330,13 +330,14 @@ int flashrom_flash_probe(struct flashrom_flashctx **const flashctx,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
/* We found one chip, now check that there is no second match. */
|
/* We found one chip, now check that there is no second match. */
|
||||||
if (probe_flash(®istered_masters[i], flash_idx + 1, &second_flashctx, 0) != -1) {
|
if (probe_flash(®istered_masters[i], flash_idx + 1, &second_flashctx, 0) != -1) {
|
||||||
|
flashrom_layout_release(second_flashctx.default_layout);
|
||||||
ret = 3;
|
ret = 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret) {
|
if (ret) {
|
||||||
free(*flashctx);
|
flashrom_flash_release(*flashctx);
|
||||||
*flashctx = NULL;
|
*flashctx = NULL;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -360,6 +361,7 @@ size_t flashrom_flash_getsize(const struct flashrom_flashctx *const flashctx)
|
|||||||
*/
|
*/
|
||||||
void flashrom_flash_release(struct flashrom_flashctx *const flashctx)
|
void flashrom_flash_release(struct flashrom_flashctx *const flashctx)
|
||||||
{
|
{
|
||||||
|
flashrom_layout_release(flashctx->default_layout);
|
||||||
free(flashctx);
|
free(flashctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,16 +437,10 @@ int flashrom_layout_read_from_ifd(struct flashrom_layout **const layout, struct
|
|||||||
#ifndef __FLASHROM_LITTLE_ENDIAN__
|
#ifndef __FLASHROM_LITTLE_ENDIAN__
|
||||||
return 6;
|
return 6;
|
||||||
#else
|
#else
|
||||||
struct ich_layout dump_layout;
|
struct flashrom_layout *dump_layout, *chip_layout;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
void *const desc = malloc(0x1000);
|
void *const desc = malloc(0x1000);
|
||||||
struct ich_layout *const chip_layout = malloc(sizeof(*chip_layout));
|
|
||||||
if (!desc || !chip_layout) {
|
|
||||||
msg_gerr("Out of memory!\n");
|
|
||||||
goto _free_ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prepare_flash_access(flashctx, true, false, false, false))
|
if (prepare_flash_access(flashctx, true, false, false, false))
|
||||||
goto _free_ret;
|
goto _free_ret;
|
||||||
|
|
||||||
@ -457,7 +453,7 @@ int flashrom_layout_read_from_ifd(struct flashrom_layout **const layout, struct
|
|||||||
}
|
}
|
||||||
msg_cinfo("done.\n");
|
msg_cinfo("done.\n");
|
||||||
|
|
||||||
if (layout_from_ich_descriptors(chip_layout, desc, 0x1000)) {
|
if (layout_from_ich_descriptors(&chip_layout, desc, 0x1000)) {
|
||||||
msg_cerr("Couldn't parse the descriptor!\n");
|
msg_cerr("Couldn't parse the descriptor!\n");
|
||||||
ret = 3;
|
ret = 3;
|
||||||
goto _finalize_ret;
|
goto _finalize_ret;
|
||||||
@ -470,12 +466,13 @@ int flashrom_layout_read_from_ifd(struct flashrom_layout **const layout, struct
|
|||||||
goto _finalize_ret;
|
goto _finalize_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct romentry *chip_entry = layout_next(&chip_layout->base, NULL);
|
const struct romentry *chip_entry = layout_next(chip_layout, NULL);
|
||||||
const struct romentry *dump_entry = layout_next(&dump_layout.base, NULL);
|
const struct romentry *dump_entry = layout_next(dump_layout, NULL);
|
||||||
while (chip_entry && dump_entry && !memcmp(chip_entry, dump_entry, sizeof(*chip_entry))) {
|
while (chip_entry && dump_entry && !memcmp(chip_entry, dump_entry, sizeof(*chip_entry))) {
|
||||||
chip_entry = layout_next(&chip_layout->base, chip_entry);
|
chip_entry = layout_next(chip_layout, chip_entry);
|
||||||
dump_entry = layout_next(&dump_layout.base, dump_entry);
|
dump_entry = layout_next(dump_layout, dump_entry);
|
||||||
}
|
}
|
||||||
|
flashrom_layout_release(dump_layout);
|
||||||
if (chip_entry || dump_entry) {
|
if (chip_entry || dump_entry) {
|
||||||
msg_cerr("Descriptors don't match!\n");
|
msg_cerr("Descriptors don't match!\n");
|
||||||
ret = 5;
|
ret = 5;
|
||||||
@ -490,7 +487,7 @@ _finalize_ret:
|
|||||||
finalize_flash_access(flashctx);
|
finalize_flash_access(flashctx);
|
||||||
_free_ret:
|
_free_ret:
|
||||||
if (ret)
|
if (ret)
|
||||||
free(chip_layout);
|
flashrom_layout_release(chip_layout);
|
||||||
free(desc);
|
free(desc);
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
|
@ -106,6 +106,7 @@ int flashrom_image_write(struct flashrom_flashctx *, void *buffer, size_t buffer
|
|||||||
int flashrom_image_verify(struct flashrom_flashctx *, const void *buffer, size_t buffer_len);
|
int flashrom_image_verify(struct flashrom_flashctx *, const void *buffer, size_t buffer_len);
|
||||||
|
|
||||||
struct flashrom_layout;
|
struct flashrom_layout;
|
||||||
|
int flashrom_layout_new(struct flashrom_layout **, unsigned int count);
|
||||||
int flashrom_layout_read_from_ifd(struct flashrom_layout **, struct flashrom_flashctx *, const void *dump, size_t len);
|
int flashrom_layout_read_from_ifd(struct flashrom_layout **, struct flashrom_flashctx *, const void *dump, size_t len);
|
||||||
int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **,
|
int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **,
|
||||||
struct flashrom_flashctx *, off_t offset, size_t length);
|
struct flashrom_flashctx *, off_t offset, size_t length);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user