diff options
author | Nico Huber <nico.h@gmx.de> | 2019-06-15 15:55:11 +0200 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2021-06-26 15:54:22 +0000 |
commit | f394fcec0da2fd4a9d1bd7a7911065344e67ce34 (patch) | |
tree | cdce7e8fe9c980df3602711cc7de9881f2deaf3e /layout.c | |
parent | 7ebd578100e6526ef46c98cb9978d692160d8179 (diff) | |
download | flashrom-f394fcec0da2fd4a9d1bd7a7911065344e67ce34.tar.gz flashrom-f394fcec0da2fd4a9d1bd7a7911065344e67ce34.tar.bz2 flashrom-f394fcec0da2fd4a9d1bd7a7911065344e67ce34.zip |
layout: Introduce flashrom_layout_add_region()
Adds a region to an existing layout, as long as there is space.
Change-Id: I50d473d0d5d1fb38bd6f9ae3d7127e9ea66a94e1
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/33517
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'layout.c')
-rw-r--r-- | layout.c | 56 |
1 files changed, 39 insertions, 17 deletions
@@ -73,7 +73,6 @@ int read_romlayout(const char *name) struct flashrom_layout *const layout = get_global_layout(); FILE *romlayout; char tempstr[256], tempname[256]; - unsigned int i; int ret = 1; romlayout = fopen(name, "r"); @@ -106,24 +105,10 @@ int read_romlayout(const char *name) msg_gerr("Error parsing layout file. Offending string: \"%s\"\n", tempstr); goto _close_ret; } - 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].included = false; - layout->entries[layout->num_entries].file = NULL; - 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)); + if (flashrom_layout_add_region(layout, + strtol(tstr1, NULL, 16), strtol(tstr2, NULL, 16), tempname)) goto _close_ret; - } - layout->num_entries++; - } - - for (i = 0; i < layout->num_entries; i++) { - msg_gdbg("romlayout %08x - %08x named %s\n", - layout->entries[i].start, - layout->entries[i].end, layout->entries[i].name); } - ret = 0; _close_ret: @@ -399,6 +384,43 @@ const struct romentry *layout_next( */ /** + * @brief Add another region to an existing layout. + * + * @param layout The existing layout. + * @param start Start address of the region. + * @param end End address (inclusive) of the region. + * @param name Name of the region. + * + * @return 0 on success, + * 1 if out of memory, + * 2 if the layout is full already. + */ +int flashrom_layout_add_region( + struct flashrom_layout *const layout, + const size_t start, const size_t end, const char *const name) +{ + if (layout->num_entries >= layout->capacity) { + msg_gerr("Error adding layout entry: No space left\n"); + return 2; + } + + struct romentry *const entry = &layout->entries[layout->num_entries]; + entry->start = start; + entry->end = end; + entry->included = false; + entry->name = strdup(name); + entry->file = NULL; + if (!entry->name) { + msg_gerr("Error adding layout entry: %s\n", strerror(errno)); + return 1; + } + + msg_gdbg("Added layout entry %08zx - %08zx named %s\n", start, end, name); + ++layout->num_entries; + return 0; +} + +/** * @brief Mark given region as included. * * @param layout The layout to alter. |