mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
layout: Make romentry.name
a pointer
This should provide more flexibility while we don't have to allocate 256B extra per layout entry. Change-Id: Ibb903113550ec13f43cbbd0a412c8f35fe1cf454 Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/flashrom/+/33515 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
This commit is contained in:
parent
4f213285d7
commit
70461a9524
@ -1338,7 +1338,11 @@ notfound:
|
|||||||
fallback->entry.start = 0;
|
fallback->entry.start = 0;
|
||||||
fallback->entry.end = flash->chip->total_size * 1024 - 1;
|
fallback->entry.end = flash->chip->total_size * 1024 - 1;
|
||||||
fallback->entry.included = true;
|
fallback->entry.included = true;
|
||||||
strcpy(fallback->entry.name, "complete flash");
|
fallback->entry.name = strdup("complete flash");
|
||||||
|
if (!fallback->entry.name) {
|
||||||
|
msg_cerr("Failed to probe chip: %s\n", strerror(errno));
|
||||||
|
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",
|
||||||
|
@ -1153,7 +1153,8 @@ int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_d
|
|||||||
* @param len The length of the descriptor dump.
|
* @param len The length of the descriptor dump.
|
||||||
*
|
*
|
||||||
* @return 0 on success,
|
* @return 0 on success,
|
||||||
* 1 if the descriptor couldn't be parsed.
|
* 1 if the descriptor couldn't be parsed,
|
||||||
|
* 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 ich_layout *const layout, const void *const dump, const size_t len)
|
||||||
{
|
{
|
||||||
@ -1178,7 +1179,9 @@ int layout_from_ich_descriptors(struct ich_layout *const layout, const void *con
|
|||||||
layout->entries[j].start = base;
|
layout->entries[j].start = base;
|
||||||
layout->entries[j].end = limit;
|
layout->entries[j].end = limit;
|
||||||
layout->entries[j].included = false;
|
layout->entries[j].included = false;
|
||||||
snprintf(layout->entries[j].name, sizeof(layout->entries[j].name), "%s", regions[i]);
|
layout->entries[j].name = strdup(regions[i]);
|
||||||
|
if (!layout->entries[j].name)
|
||||||
|
return 2;
|
||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
layout->base.entries = layout->entries;
|
layout->base.entries = layout->entries;
|
||||||
|
31
layout.c
31
layout.c
@ -15,6 +15,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -44,8 +45,8 @@ int read_romlayout(const char *name)
|
|||||||
{
|
{
|
||||||
struct flashrom_layout *const layout = get_global_layout();
|
struct flashrom_layout *const layout = get_global_layout();
|
||||||
FILE *romlayout;
|
FILE *romlayout;
|
||||||
char tempstr[256];
|
char tempstr[256], tempname[256];
|
||||||
int i;
|
int i, ret = 1;
|
||||||
|
|
||||||
romlayout = fopen(name, "r");
|
romlayout = fopen(name, "r");
|
||||||
|
|
||||||
@ -61,10 +62,9 @@ int read_romlayout(const char *name)
|
|||||||
if (layout->num_entries >= MAX_ROMLAYOUT) {
|
if (layout->num_entries >= MAX_ROMLAYOUT) {
|
||||||
msg_gerr("Maximum number of ROM images (%i) in layout "
|
msg_gerr("Maximum number of ROM images (%i) in layout "
|
||||||
"file reached.\n", MAX_ROMLAYOUT);
|
"file reached.\n", MAX_ROMLAYOUT);
|
||||||
(void)fclose(romlayout);
|
goto _close_ret;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, layout->entries[layout->num_entries].name))
|
if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, tempname))
|
||||||
continue;
|
continue;
|
||||||
#if 0
|
#if 0
|
||||||
// fscanf does not like arbitrary comments like that :( later
|
// fscanf does not like arbitrary comments like that :( later
|
||||||
@ -76,12 +76,16 @@ int read_romlayout(const char *name)
|
|||||||
tstr2 = strtok(NULL, ":");
|
tstr2 = strtok(NULL, ":");
|
||||||
if (!tstr1 || !tstr2) {
|
if (!tstr1 || !tstr2) {
|
||||||
msg_gerr("Error parsing layout file. Offending string: \"%s\"\n", tempstr);
|
msg_gerr("Error parsing layout file. Offending string: \"%s\"\n", tempstr);
|
||||||
(void)fclose(romlayout);
|
goto _close_ret;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
layout->entries[layout->num_entries].start = strtol(tstr1, (char **)NULL, 16);
|
layout->entries[layout->num_entries].start = strtol(tstr1, (char **)NULL, 16);
|
||||||
layout->entries[layout->num_entries].end = strtol(tstr2, (char **)NULL, 16);
|
layout->entries[layout->num_entries].end = strtol(tstr2, (char **)NULL, 16);
|
||||||
layout->entries[layout->num_entries].included = 0;
|
layout->entries[layout->num_entries].included = 0;
|
||||||
|
layout->entries[layout->num_entries].name = strdup(tempname);
|
||||||
|
if (!layout->entries[layout->num_entries].name) {
|
||||||
|
msg_gerr("Error adding layout entry: %s\n", strerror(errno));
|
||||||
|
goto _close_ret;
|
||||||
|
}
|
||||||
layout->num_entries++;
|
layout->num_entries++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,9 +95,11 @@ int read_romlayout(const char *name)
|
|||||||
layout->entries[i].end, layout->entries[i].name);
|
layout->entries[i].end, layout->entries[i].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fclose(romlayout);
|
ret = 0;
|
||||||
|
|
||||||
return 0;
|
_close_ret:
|
||||||
|
(void)fclose(romlayout);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -197,6 +203,7 @@ void layout_cleanup(struct layout_include_args **args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < layout->num_entries; i++) {
|
for (i = 0; i < layout->num_entries; i++) {
|
||||||
|
free(layout->entries[i].name);
|
||||||
layout->entries[i].included = 0;
|
layout->entries[i].included = 0;
|
||||||
}
|
}
|
||||||
layout->num_entries = 0;
|
layout->num_entries = 0;
|
||||||
@ -278,9 +285,13 @@ 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 == get_global_layout())
|
unsigned int i;
|
||||||
|
|
||||||
|
if (!layout || layout == get_global_layout())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < layout->num_entries; ++i)
|
||||||
|
free(layout->entries[i].name);
|
||||||
free(layout);
|
free(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
layout.h
2
layout.h
@ -39,7 +39,7 @@ struct romentry {
|
|||||||
chipoff_t start;
|
chipoff_t start;
|
||||||
chipoff_t end;
|
chipoff_t end;
|
||||||
bool included;
|
bool included;
|
||||||
char name[256];
|
char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct flashrom_layout {
|
struct flashrom_layout {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
* Have a look at the Modules section for a function reference.
|
* Have a look at the Modules section for a function reference.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -384,9 +385,12 @@ static int flashrom_layout_parse_fmap(struct flashrom_layout **layout,
|
|||||||
l->entries[l->num_entries].start = fmap->areas[i].offset;
|
l->entries[l->num_entries].start = fmap->areas[i].offset;
|
||||||
l->entries[l->num_entries].end = fmap->areas[i].offset + fmap->areas[i].size - 1;
|
l->entries[l->num_entries].end = fmap->areas[i].offset + fmap->areas[i].size - 1;
|
||||||
l->entries[l->num_entries].included = false;
|
l->entries[l->num_entries].included = false;
|
||||||
memset(l->entries[l->num_entries].name, 0, sizeof(l->entries[i].name));
|
l->entries[l->num_entries].name =
|
||||||
memcpy(l->entries[l->num_entries].name, fmap->areas[i].name,
|
strndup((const char *)fmap->areas[i].name, FMAP_STRLEN);
|
||||||
min(FMAP_STRLEN, sizeof(l->entries[i].name)));
|
if (!l->entries[l->num_entries].name) {
|
||||||
|
msg_gerr("Error adding layout entry: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
msg_gdbg("fmap %08x - %08x named %s\n",
|
msg_gdbg("fmap %08x - %08x named %s\n",
|
||||||
l->entries[l->num_entries].start,
|
l->entries[l->num_entries].start,
|
||||||
l->entries[l->num_entries].end,
|
l->entries[l->num_entries].end,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user