Uwe Hermann | 75f5107 | 2008-03-04 16:29:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2005-2008 coresystems GmbH |
| 5 | * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH) |
Stefan Tauner | 949ccc8 | 2013-09-15 14:01:06 +0000 | [diff] [blame] | 6 | * Copyright (C) 2011-2013 Stefan Tauner |
Uwe Hermann | 75f5107 | 2008-03-04 16:29:54 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Uwe Hermann | 75f5107 | 2008-03-04 16:29:54 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 18 | #include <errno.h> |
Carl-Daniel Hailfinger | 831e8f4 | 2010-05-30 22:24:40 +0000 | [diff] [blame] | 19 | #include <stdio.h> |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
Carl-Daniel Hailfinger | cb6ad16 | 2010-11-02 03:12:51 +0000 | [diff] [blame] | 22 | #include <limits.h> |
Uwe Hermann | 0846f89 | 2007-08-23 13:34:59 +0000 | [diff] [blame] | 23 | #include "flash.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 24 | #include "programmer.h" |
Nico Huber | 3a9939b | 2016-04-27 15:56:14 +0200 | [diff] [blame] | 25 | #include "layout.h" |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 26 | |
Nico Huber | 3a9939b | 2016-04-27 15:56:14 +0200 | [diff] [blame] | 27 | struct romentry entries[MAX_ROMLAYOUT]; |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 28 | static struct flashrom_layout global_layout = { entries, 0 }; |
Stefan Tauner | c70bc8a | 2013-08-30 22:22:57 +0000 | [diff] [blame] | 29 | |
Nico Huber | 305f417 | 2013-06-14 11:55:26 +0200 | [diff] [blame] | 30 | struct flashrom_layout *get_global_layout(void) |
Nico Huber | 3a9939b | 2016-04-27 15:56:14 +0200 | [diff] [blame] | 31 | { |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 32 | return &global_layout; |
Nico Huber | 3a9939b | 2016-04-27 15:56:14 +0200 | [diff] [blame] | 33 | } |
| 34 | |
dhendrix | beaefe0 | 2017-09-03 18:06:53 -0700 | [diff] [blame] | 35 | const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx) |
| 36 | { |
| 37 | if (flashctx->layout && flashctx->layout->num_entries) |
| 38 | return flashctx->layout; |
| 39 | else |
| 40 | return &flashctx->fallback_layout.base; |
| 41 | } |
| 42 | |
Patrick Georgi | a9095a9 | 2010-09-30 17:03:32 +0000 | [diff] [blame] | 43 | #ifndef __LIBPAYLOAD__ |
Mark Marshall | f20b7be | 2014-05-09 21:16:21 +0000 | [diff] [blame] | 44 | int read_romlayout(const char *name) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 45 | { |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 46 | struct flashrom_layout *const layout = get_global_layout(); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 47 | FILE *romlayout; |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 48 | char tempstr[256], tempname[256]; |
| 49 | int i, ret = 1; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 50 | |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 51 | romlayout = fopen(name, "r"); |
| 52 | |
| 53 | if (!romlayout) { |
Carl-Daniel Hailfinger | 831e8f4 | 2010-05-30 22:24:40 +0000 | [diff] [blame] | 54 | msg_gerr("ERROR: Could not open ROM layout (%s).\n", |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 55 | name); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 56 | return -1; |
| 57 | } |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 58 | |
| 59 | while (!feof(romlayout)) { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 60 | char *tstr1, *tstr2; |
Carl-Daniel Hailfinger | da53ada | 2010-12-04 11:56:52 +0000 | [diff] [blame] | 61 | |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 62 | if (layout->num_entries >= MAX_ROMLAYOUT) { |
Carl-Daniel Hailfinger | da53ada | 2010-12-04 11:56:52 +0000 | [diff] [blame] | 63 | msg_gerr("Maximum number of ROM images (%i) in layout " |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 64 | "file reached.\n", MAX_ROMLAYOUT); |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 65 | goto _close_ret; |
Carl-Daniel Hailfinger | da53ada | 2010-12-04 11:56:52 +0000 | [diff] [blame] | 66 | } |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 67 | if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, tempname)) |
Peter Stuge | 1fec0f3 | 2009-01-12 21:00:35 +0000 | [diff] [blame] | 68 | continue; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 69 | #if 0 |
| 70 | // fscanf does not like arbitrary comments like that :( later |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 71 | if (tempstr[0] == '#') { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 72 | continue; |
| 73 | } |
| 74 | #endif |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 75 | tstr1 = strtok(tempstr, ":"); |
| 76 | tstr2 = strtok(NULL, ":"); |
Uwe Hermann | 58783e3 | 2008-12-22 16:42:59 +0000 | [diff] [blame] | 77 | if (!tstr1 || !tstr2) { |
Stefan Tauner | eb58257 | 2012-09-21 12:52:50 +0000 | [diff] [blame] | 78 | msg_gerr("Error parsing layout file. Offending string: \"%s\"\n", tempstr); |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 79 | goto _close_ret; |
Uwe Hermann | 58783e3 | 2008-12-22 16:42:59 +0000 | [diff] [blame] | 80 | } |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 81 | layout->entries[layout->num_entries].start = strtol(tstr1, (char **)NULL, 16); |
| 82 | layout->entries[layout->num_entries].end = strtol(tstr2, (char **)NULL, 16); |
| 83 | layout->entries[layout->num_entries].included = 0; |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 84 | layout->entries[layout->num_entries].name = strdup(tempname); |
| 85 | if (!layout->entries[layout->num_entries].name) { |
| 86 | msg_gerr("Error adding layout entry: %s\n", strerror(errno)); |
| 87 | goto _close_ret; |
| 88 | } |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 89 | layout->num_entries++; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 90 | } |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 91 | |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 92 | for (i = 0; i < layout->num_entries; i++) { |
Carl-Daniel Hailfinger | 831e8f4 | 2010-05-30 22:24:40 +0000 | [diff] [blame] | 93 | msg_gdbg("romlayout %08x - %08x named %s\n", |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 94 | layout->entries[i].start, |
| 95 | layout->entries[i].end, layout->entries[i].name); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 98 | ret = 0; |
Uwe Hermann | ffec5f3 | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 99 | |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 100 | _close_ret: |
| 101 | (void)fclose(romlayout); |
| 102 | return ret; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 103 | } |
Patrick Georgi | a9095a9 | 2010-09-30 17:03:32 +0000 | [diff] [blame] | 104 | #endif |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 105 | |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 106 | /* register an include argument (-i) for later processing */ |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 107 | int register_include_arg(struct layout_include_args **args, char *name) |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 108 | { |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 109 | struct layout_include_args *tmp; |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 110 | if (name == NULL) { |
| 111 | msg_gerr("<NULL> is a bad region name.\n"); |
| 112 | return 1; |
| 113 | } |
| 114 | |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 115 | tmp = *args; |
| 116 | while (tmp) { |
| 117 | if (!strcmp(tmp->name, name)) { |
| 118 | msg_gerr("Duplicate region name: \"%s\".\n", name); |
| 119 | return 1; |
| 120 | } |
| 121 | tmp = tmp->next; |
| 122 | } |
| 123 | |
| 124 | tmp = malloc(sizeof(struct layout_include_args)); |
| 125 | if (tmp == NULL) { |
| 126 | msg_gerr("Could not allocate memory"); |
Stefan Tauner | 23bb6d5 | 2012-04-15 14:09:16 +0000 | [diff] [blame] | 127 | return 1; |
| 128 | } |
| 129 | |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 130 | tmp->name = name; |
| 131 | tmp->next = *args; |
| 132 | *args = tmp; |
| 133 | |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
Arthur Heymans | 32b9f5c | 2019-02-05 16:14:55 +0100 | [diff] [blame] | 137 | /* returns -1 if an entry is not found, 0 if found. */ |
Nico Huber | 305f417 | 2013-06-14 11:55:26 +0200 | [diff] [blame] | 138 | static int find_romentry(struct flashrom_layout *const l, char *name) |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 139 | { |
Nico Huber | 305f417 | 2013-06-14 11:55:26 +0200 | [diff] [blame] | 140 | if (l->num_entries == 0) |
Uwe Hermann | a7e0548 | 2007-05-09 10:17:44 +0000 | [diff] [blame] | 141 | return -1; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 142 | |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 143 | msg_gspew("Looking for region \"%s\"... ", name); |
Arthur Heymans | 32b9f5c | 2019-02-05 16:14:55 +0100 | [diff] [blame] | 144 | if (flashrom_layout_include_region(l, name)) { |
| 145 | msg_gspew("not found.\n"); |
| 146 | return -1; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 147 | } |
Arthur Heymans | 32b9f5c | 2019-02-05 16:14:55 +0100 | [diff] [blame] | 148 | msg_gspew("found.\n"); |
| 149 | return 0; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 152 | /* process -i arguments |
| 153 | * returns 0 to indicate success, >0 to indicate failure |
| 154 | */ |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 155 | int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args) |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 156 | { |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 157 | int found = 0; |
| 158 | const struct layout_include_args *tmp; |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 159 | |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 160 | if (args == NULL) |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 161 | return 0; |
| 162 | |
Stefan Tauner | 23bb6d5 | 2012-04-15 14:09:16 +0000 | [diff] [blame] | 163 | /* User has specified an area, but no layout file is loaded. */ |
Nico Huber | 305f417 | 2013-06-14 11:55:26 +0200 | [diff] [blame] | 164 | if (l->num_entries == 0) { |
Stefan Tauner | 23bb6d5 | 2012-04-15 14:09:16 +0000 | [diff] [blame] | 165 | msg_gerr("Region requested (with -i \"%s\"), " |
| 166 | "but no layout data is available.\n", |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 167 | args->name); |
Stefan Tauner | 23bb6d5 | 2012-04-15 14:09:16 +0000 | [diff] [blame] | 168 | return 1; |
| 169 | } |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 170 | |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 171 | tmp = args; |
| 172 | while (tmp) { |
| 173 | if (find_romentry(l, tmp->name) < 0) { |
Stefan Tauner | 23bb6d5 | 2012-04-15 14:09:16 +0000 | [diff] [blame] | 174 | msg_gerr("Invalid region specified: \"%s\".\n", |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 175 | tmp->name); |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 176 | return 1; |
| 177 | } |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 178 | tmp = tmp->next; |
| 179 | found++; |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 182 | msg_ginfo("Using region%s:", found > 1 ? "s" : ""); |
| 183 | tmp = args; |
| 184 | while (tmp) { |
| 185 | msg_ginfo(" \"%s\"%s", tmp->name, found > 1 ? "," : ""); |
| 186 | found--; |
| 187 | tmp = tmp->next; |
| 188 | } |
Louis Yung-Chieh Lo | 9bcf268 | 2011-12-25 09:12:16 +0000 | [diff] [blame] | 189 | msg_ginfo(".\n"); |
| 190 | return 0; |
| 191 | } |
| 192 | |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 193 | void layout_cleanup(struct layout_include_args **args) |
Stefan Tauner | 949ccc8 | 2013-09-15 14:01:06 +0000 | [diff] [blame] | 194 | { |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 195 | struct flashrom_layout *const layout = get_global_layout(); |
Stefan Tauner | 949ccc8 | 2013-09-15 14:01:06 +0000 | [diff] [blame] | 196 | int i; |
Arthur Heymans | b04fef9 | 2019-02-05 17:35:05 +0100 | [diff] [blame] | 197 | struct layout_include_args *tmp; |
| 198 | |
| 199 | while (*args) { |
| 200 | tmp = (*args)->next; |
| 201 | free(*args); |
| 202 | *args = tmp; |
Stefan Tauner | 949ccc8 | 2013-09-15 14:01:06 +0000 | [diff] [blame] | 203 | } |
Stefan Tauner | 949ccc8 | 2013-09-15 14:01:06 +0000 | [diff] [blame] | 204 | |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 205 | for (i = 0; i < layout->num_entries; i++) { |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 206 | free(layout->entries[i].name); |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 207 | layout->entries[i].included = 0; |
Stefan Tauner | 949ccc8 | 2013-09-15 14:01:06 +0000 | [diff] [blame] | 208 | } |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 209 | layout->num_entries = 0; |
Stefan Tauner | 949ccc8 | 2013-09-15 14:01:06 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Stefan Tauner | 8268fdb | 2013-09-23 14:21:06 +0000 | [diff] [blame] | 212 | /* Validate and - if needed - normalize layout entries. */ |
| 213 | int normalize_romentries(const struct flashctx *flash) |
| 214 | { |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 215 | struct flashrom_layout *const layout = get_global_layout(); |
Stefan Tauner | 8268fdb | 2013-09-23 14:21:06 +0000 | [diff] [blame] | 216 | chipsize_t total_size = flash->chip->total_size * 1024; |
| 217 | int ret = 0; |
| 218 | |
| 219 | int i; |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 220 | for (i = 0; i < layout->num_entries; i++) { |
| 221 | if (layout->entries[i].start >= total_size || layout->entries[i].end >= total_size) { |
Stefan Tauner | 8268fdb | 2013-09-23 14:21:06 +0000 | [diff] [blame] | 222 | msg_gwarn("Warning: Address range of region \"%s\" exceeds the current chip's " |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 223 | "address space.\n", layout->entries[i].name); |
| 224 | if (layout->entries[i].included) |
Stefan Tauner | 8268fdb | 2013-09-23 14:21:06 +0000 | [diff] [blame] | 225 | ret = 1; |
| 226 | } |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 227 | if (layout->entries[i].start > layout->entries[i].end) { |
Stefan Tauner | 8268fdb | 2013-09-23 14:21:06 +0000 | [diff] [blame] | 228 | msg_gerr("Error: Size of the address range of region \"%s\" is not positive.\n", |
Nico Huber | 2b94cdb | 2019-06-15 18:19:26 +0200 | [diff] [blame] | 229 | layout->entries[i].name); |
Stefan Tauner | 8268fdb | 2013-09-23 14:21:06 +0000 | [diff] [blame] | 230 | ret = 1; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | return ret; |
| 235 | } |
Nico Huber | 3d7b1e3 | 2018-12-22 00:53:14 +0100 | [diff] [blame] | 236 | |
| 237 | const struct romentry *layout_next_included_region( |
| 238 | const struct flashrom_layout *const l, const chipoff_t where) |
| 239 | { |
| 240 | unsigned int i; |
| 241 | const struct romentry *lowest = NULL; |
| 242 | |
| 243 | for (i = 0; i < l->num_entries; ++i) { |
| 244 | if (!l->entries[i].included) |
| 245 | continue; |
| 246 | if (l->entries[i].end < where) |
| 247 | continue; |
| 248 | if (!lowest || lowest->start > l->entries[i].start) |
| 249 | lowest = &l->entries[i]; |
| 250 | } |
| 251 | |
| 252 | return lowest; |
| 253 | } |
Nico Huber | 4f21328 | 2019-06-15 17:33:49 +0200 | [diff] [blame] | 254 | |
Nico Huber | 5ca5523 | 2019-06-15 22:29:08 +0200 | [diff] [blame] | 255 | const struct romentry *layout_next_included( |
| 256 | const struct flashrom_layout *const layout, const struct romentry *iterator) |
| 257 | { |
| 258 | const struct romentry *const end = layout->entries + layout->num_entries; |
| 259 | |
| 260 | if (iterator) |
| 261 | ++iterator; |
| 262 | else |
| 263 | iterator = &layout->entries[0]; |
| 264 | |
| 265 | for (; iterator < end; ++iterator) { |
| 266 | if (!iterator->included) |
| 267 | continue; |
| 268 | return iterator; |
| 269 | } |
| 270 | return NULL; |
| 271 | } |
| 272 | |
Nico Huber | 4f21328 | 2019-06-15 17:33:49 +0200 | [diff] [blame] | 273 | /** |
| 274 | * @addtogroup flashrom-layout |
| 275 | * @{ |
| 276 | */ |
| 277 | |
| 278 | /** |
| 279 | * @brief Mark given region as included. |
| 280 | * |
| 281 | * @param layout The layout to alter. |
| 282 | * @param name The name of the region to include. |
| 283 | * |
| 284 | * @return 0 on success, |
| 285 | * 1 if the given name can't be found. |
| 286 | */ |
| 287 | int flashrom_layout_include_region(struct flashrom_layout *const layout, const char *name) |
| 288 | { |
| 289 | size_t i; |
| 290 | for (i = 0; i < layout->num_entries; ++i) { |
| 291 | if (!strcmp(layout->entries[i].name, name)) { |
| 292 | layout->entries[i].included = true; |
| 293 | return 0; |
| 294 | } |
| 295 | } |
| 296 | return 1; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * @brief Free a layout. |
| 301 | * |
| 302 | * @param layout Layout to free. |
| 303 | */ |
| 304 | void flashrom_layout_release(struct flashrom_layout *const layout) |
| 305 | { |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 306 | unsigned int i; |
| 307 | |
| 308 | if (!layout || layout == get_global_layout()) |
Nico Huber | 4f21328 | 2019-06-15 17:33:49 +0200 | [diff] [blame] | 309 | return; |
| 310 | |
Nico Huber | 70461a9 | 2019-06-15 14:56:19 +0200 | [diff] [blame] | 311 | for (i = 0; i < layout->num_entries; ++i) |
| 312 | free(layout->entries[i].name); |
Nico Huber | 4f21328 | 2019-06-15 17:33:49 +0200 | [diff] [blame] | 313 | free(layout); |
| 314 | } |
| 315 | |
| 316 | /** @} */ /* end flashrom-layout */ |