1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 23:22:37 +02:00

layout: Kill the global layout

Change-Id: Ic302e9c5faf1368e5ca244ce461e55e14f916ab8
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/54286
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
Nico Huber 2021-05-14 01:07:28 +02:00
parent 7f48053172
commit d855351ce7
4 changed files with 11 additions and 27 deletions

View File

@ -519,12 +519,12 @@ int main(int argc, char *argv[])
} }
msg_gdbg("\n"); msg_gdbg("\n");
if (layoutfile && read_romlayout(layoutfile)) { if (layoutfile && layout_from_file(&layout, layoutfile)) {
ret = 1; ret = 1;
goto out; goto out;
} }
if (!ifd && !fmap && process_include_args(get_global_layout(), include_args)) { if (!ifd && !fmap && process_include_args(layout, include_args)) {
ret = 1; ret = 1;
goto out; goto out;
} }
@ -716,9 +716,7 @@ int main(int argc, char *argv[])
goto out_shutdown; goto out_shutdown;
} }
if (layoutfile) { if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) ||
layout = get_global_layout();
} else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) ||
process_include_args(layout, include_args))) { process_include_args(layout, include_args))) {
ret = 1; ret = 1;
goto out_shutdown; goto out_shutdown;

View File

@ -419,7 +419,6 @@ __attribute__((format(printf, 2, 3)));
/* layout.c */ /* layout.c */
int register_include_arg(struct layout_include_args **args, const char *arg); int register_include_arg(struct layout_include_args **args, const char *arg);
int read_romlayout(const char *name);
void layout_cleanup(struct layout_include_args **args); void layout_cleanup(struct layout_include_args **args);
/* spi.c */ /* spi.c */

View File

@ -35,15 +35,6 @@ struct layout_include_args {
struct layout_include_args *next; struct layout_include_args *next;
}; };
static struct flashrom_layout *global_layout;
struct flashrom_layout *get_global_layout(void)
{
if (!global_layout)
flashrom_layout_new(&global_layout);
return global_layout;
}
const struct flashrom_layout *get_default_layout(const struct flashrom_flashctx *const flashctx) const struct flashrom_layout *get_default_layout(const struct flashrom_flashctx *const flashctx)
{ {
return flashctx->default_layout; return flashctx->default_layout;
@ -75,13 +66,15 @@ static struct romentry *_layout_entry_by_name(
} }
#ifndef __LIBPAYLOAD__ #ifndef __LIBPAYLOAD__
int read_romlayout(const char *name) int layout_from_file(struct flashrom_layout **layout, const char *name)
{ {
struct flashrom_layout *const layout = get_global_layout();
FILE *romlayout; FILE *romlayout;
char tempstr[256], tempname[256]; char tempstr[256], tempname[256];
int ret = 1; int ret = 1;
if (flashrom_layout_new(layout))
return 1;
romlayout = fopen(name, "r"); romlayout = fopen(name, "r");
if (!romlayout) { if (!romlayout) {
@ -107,7 +100,7 @@ int read_romlayout(const char *name)
msg_gerr("Error parsing layout file. Offending string: \"%s\"\n", tempstr); msg_gerr("Error parsing layout file. Offending string: \"%s\"\n", tempstr);
goto _close_ret; goto _close_ret;
} }
if (flashrom_layout_add_region(layout, if (flashrom_layout_add_region(*layout,
strtol(tstr1, NULL, 16), strtol(tstr2, NULL, 16), tempname)) strtol(tstr1, NULL, 16), strtol(tstr2, NULL, 16), tempname))
goto _close_ret; goto _close_ret;
} }
@ -219,7 +212,7 @@ int process_include_args(struct flashrom_layout *l, const struct layout_include_
return 0; return 0;
/* User has specified an include argument, but no layout is loaded. */ /* User has specified an include argument, but no layout is loaded. */
if (!l->head) { if (!l || !l->head) {
msg_gerr("Region requested (with -i \"%s\"), " msg_gerr("Region requested (with -i \"%s\"), "
"but no layout data is available.\n", "but no layout data is available.\n",
args->name); args->name);
@ -283,7 +276,6 @@ int included_regions_overlap(const struct flashrom_layout *const l)
void layout_cleanup(struct layout_include_args **args) void layout_cleanup(struct layout_include_args **args)
{ {
struct flashrom_layout *const layout = get_global_layout();
struct layout_include_args *tmp; struct layout_include_args *tmp;
while (*args) { while (*args) {
@ -293,9 +285,6 @@ void layout_cleanup(struct layout_include_args **args)
free(*args); free(*args);
*args = tmp; *args = tmp;
} }
global_layout = NULL;
flashrom_layout_release(layout);
} }
int layout_sanity_checks(const struct flashrom_flashctx *const flash) int layout_sanity_checks(const struct flashrom_flashctx *const flash)
@ -462,9 +451,6 @@ int flashrom_layout_include_region(struct flashrom_layout *const layout, const c
*/ */
void flashrom_layout_release(struct flashrom_layout *const layout) void flashrom_layout_release(struct flashrom_layout *const layout)
{ {
if (layout == global_layout)
return;
if (!layout) if (!layout)
return; return;

View File

@ -50,10 +50,11 @@ struct flashrom_layout;
struct layout_include_args; struct layout_include_args;
struct flashrom_flashctx; struct flashrom_flashctx;
struct flashrom_layout *get_global_layout(void);
const struct flashrom_layout *get_default_layout(const struct flashrom_flashctx *); const struct flashrom_layout *get_default_layout(const 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 layout_from_file(struct flashrom_layout **, const char *name);
int get_region_range(struct flashrom_layout *const l, const char *name, int get_region_range(struct flashrom_layout *const l, const char *name,
unsigned int *start, unsigned int *len); unsigned int *start, unsigned int *len);
int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args); int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args);