| 1 |
/* |
| 2 |
* This file is part of the flashrom project. |
| 3 |
* |
| 4 |
* Copyright (C) 2010 Google Inc. |
| 5 |
* Copyright (C) 2012 secunet Security Networks AG |
| 6 |
* (Written by Nico Huber <[email protected]> for secunet) |
| 7 |
* Copyright (C) 2025 Dmitry Zhadinets <[email protected]> |
| 8 |
* Copyright (C) 2025 Google LLC |
| 9 |
* |
| 10 |
* This program is free software; you can redistribute it and/or modify |
| 11 |
* it under the terms of the GNU General Public License as published by |
| 12 |
* the Free Software Foundation; either version 2 of the License, or |
| 13 |
* (at your option) any later version. |
| 14 |
* |
| 15 |
* This program is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU General Public License for more details. |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef __LIBFLASHROM_H__ |
| 22 |
#define __LIBFLASHROM_H__ 1 |
| 23 |
|
| 24 |
/** |
| 25 |
* @mainpage |
| 26 |
* |
| 27 |
* Have a look at the Modules section for a function reference. |
| 28 |
*/ |
| 29 |
|
| 30 |
#include <sys/types.h> |
| 31 |
#include <stddef.h> |
| 32 |
#include <stdbool.h> |
| 33 |
#include <stdint.h> |
| 34 |
#include <stdarg.h> |
| 35 |
|
| 36 |
/** |
| 37 |
* @defgroup flashrom-general General |
| 38 |
* @{ |
| 39 |
*/ |
| 40 |
|
| 41 |
/** |
| 42 |
* @brief Initialize libflashrom. |
| 43 |
* |
| 44 |
* @param perform_selfcheck If not zero, perform a self check. |
| 45 |
* @return 0 on success |
| 46 |
*/ |
| 47 |
int flashrom_init(int perform_selfcheck); |
| 48 |
/** |
| 49 |
* @brief Shut down libflashrom. |
| 50 |
* @return 0 on success |
| 51 |
*/ |
| 52 |
int flashrom_shutdown(void); |
| 53 |
enum flashrom_log_level { |
| 54 |
FLASHROM_MSG_ERROR = 0, |
| 55 |
FLASHROM_MSG_WARN = 1, |
| 56 |
FLASHROM_MSG_INFO = 2, |
| 57 |
FLASHROM_MSG_DEBUG = 3, |
| 58 |
FLASHROM_MSG_DEBUG2 = 4, |
| 59 |
FLASHROM_MSG_SPEW = 5, |
| 60 |
}; |
| 61 |
typedef int(flashrom_log_callback)(enum flashrom_log_level, const char *format, va_list); |
| 62 |
|
| 63 |
/** |
| 64 |
* @brief Set the log level. |
| 65 |
* |
| 66 |
* Set a log level for messages from libflashrom. |
| 67 |
* The print callback will be invoked only for messages |
| 68 |
* with a log level less than or equal to the configured value. |
| 69 |
* The default log level is FLASHROM_MSG_INFO. |
| 70 |
* |
| 71 |
* @param level The log level to be set. |
| 72 |
*/ |
| 73 |
|
| 74 |
void flashrom_set_log_level(enum flashrom_log_level level); |
| 75 |
|
| 76 |
/** |
| 77 |
* @brief Set the log callback function. |
| 78 |
* |
| 79 |
* Set a callback function which will be invoked whenever libflashrom wants |
| 80 |
* to output messages. This allows frontends to do whatever they see fit with |
| 81 |
* such messages, e.g. write them to syslog, or to a file, or print them in a |
| 82 |
* GUI window, etc. |
| 83 |
* |
| 84 |
* @param log_callback Pointer to the new log callback function. |
| 85 |
*/ |
| 86 |
void flashrom_set_log_callback(flashrom_log_callback *log_callback); |
| 87 |
|
| 88 |
typedef void (flashrom_log_callback_v2)( |
| 89 |
enum flashrom_log_level, |
| 90 |
const char* message, |
| 91 |
void* user_data); |
| 92 |
/** |
| 93 |
* @brief Set the log callback function. |
| 94 |
* |
| 95 |
* Set a callback function which will be invoked whenever libflashrom wants |
| 96 |
* to output messages. This allows frontends to do whatever they see fit with |
| 97 |
* such messages, e.g. write them to syslog, or to a file, or print them in a |
| 98 |
* GUI window, etc. |
| 99 |
* The message is formatted using vsnprintf |
| 100 |
* |
| 101 |
* @param log_callback Pointer to the new log callback function. |
| 102 |
* @param user_data A pointer to data managed by the caller. |
| 103 |
*/ |
| 104 |
void flashrom_set_log_callback_v2(flashrom_log_callback_v2 *log_callback, void* user_data); |
| 105 |
|
| 106 |
enum flashrom_progress_stage { |
| 107 |
FLASHROM_PROGRESS_READ, |
| 108 |
FLASHROM_PROGRESS_WRITE, |
| 109 |
FLASHROM_PROGRESS_ERASE, |
| 110 |
FLASHROM_PROGRESS_NR, |
| 111 |
}; |
| 112 |
|
| 113 |
struct flashrom_progress { |
| 114 |
enum flashrom_progress_stage stage; |
| 115 |
size_t current; |
| 116 |
size_t total; |
| 117 |
void *user_data; |
| 118 |
}; |
| 119 |
|
| 120 |
struct flashrom_flashctx; |
| 121 |
typedef void(flashrom_progress_callback)(struct flashrom_flashctx *flashctx); |
| 122 |
|
| 123 |
/** |
| 124 |
* @deprecated Use flashrom_set_progress_callback_v2 instead |
| 125 |
*/ |
| 126 |
void flashrom_set_progress_callback( |
| 127 |
struct flashrom_flashctx *const flashctx, |
| 128 |
flashrom_progress_callback *progress_callback, |
| 129 |
struct flashrom_progress *progress_state) |
| 130 |
__attribute__((deprecated("Use flashrom_set_progress_callback_v2 instead"))); |
| 131 |
|
| 132 |
typedef void(flashrom_progress_callback_v2)(enum flashrom_progress_stage stage, |
| 133 |
size_t current, |
| 134 |
size_t total, |
| 135 |
void *user_data); |
| 136 |
|
| 137 |
/** |
| 138 |
* @brief Set the progress callback function. |
| 139 |
* |
| 140 |
* Set a callback function which will be invoked whenever libflashrom wants |
| 141 |
* to indicate the progress has changed. This allows frontends to do whatever |
| 142 |
* they see fit with such values, e.g. update a progress bar in a GUI tool. |
| 143 |
* |
| 144 |
* @param flashrom_progress_callback_v2 Pointer to the new progress callback function. |
| 145 |
* @param user_data A pointer to a piece of data which is managed by progress caller |
| 146 |
*/ |
| 147 |
void flashrom_set_progress_callback_v2(struct flashrom_flashctx *const flashctx, |
| 148 |
flashrom_progress_callback_v2 *progress_callback, |
| 149 |
void* user_data); |
| 150 |
|
| 151 |
/** @} */ /* end flashrom-general */ |
| 152 |
|
| 153 |
/** |
| 154 |
* @defgroup flashrom-query Querying |
| 155 |
* @{ |
| 156 |
*/ |
| 157 |
|
| 158 |
enum flashrom_test_state { |
| 159 |
FLASHROM_TESTED_OK = 0, |
| 160 |
FLASHROM_TESTED_NT = 1, |
| 161 |
FLASHROM_TESTED_BAD = 2, |
| 162 |
FLASHROM_TESTED_DEP = 3, |
| 163 |
FLASHROM_TESTED_NA = 4, |
| 164 |
}; |
| 165 |
|
| 166 |
struct flashrom_flashchip_info { |
| 167 |
const char *vendor; |
| 168 |
const char *name; |
| 169 |
unsigned int total_size; |
| 170 |
struct flashrom_tested { |
| 171 |
enum flashrom_test_state probe; |
| 172 |
enum flashrom_test_state read; |
| 173 |
enum flashrom_test_state erase; |
| 174 |
enum flashrom_test_state write; |
| 175 |
enum flashrom_test_state wp; |
| 176 |
} tested; |
| 177 |
}; |
| 178 |
|
| 179 |
struct flashrom_board_info { |
| 180 |
const char *vendor; |
| 181 |
const char *name; |
| 182 |
enum flashrom_test_state working; |
| 183 |
}; |
| 184 |
|
| 185 |
struct flashrom_chipset_info { |
| 186 |
const char *vendor; |
| 187 |
const char *chipset; |
| 188 |
uint16_t vendor_id; |
| 189 |
uint16_t chipset_id; |
| 190 |
enum flashrom_test_state status; |
| 191 |
}; |
| 192 |
|
| 193 |
/** |
| 194 |
* @brief Returns flashrom version |
| 195 |
* @return flashrom version |
| 196 |
*/ |
| 197 |
const char *flashrom_version_info(void); |
| 198 |
/** |
| 199 |
* @brief Returns list of supported programmers |
| 200 |
* The last entry in the returned list is followed by a NULL. |
| 201 |
* |
| 202 |
* @return List of supported programmers, or NULL if an error occurred. |
| 203 |
* The pointer must be freed after using flashrom_data_free |
| 204 |
*/ |
| 205 |
const char **flashrom_supported_programmers(void); |
| 206 |
/** |
| 207 |
* @brief Returns list of supported flash chips |
| 208 |
* @return List of supported flash chips, or NULL if an error occurred |
| 209 |
*/ |
| 210 |
struct flashrom_flashchip_info *flashrom_supported_flash_chips(void); |
| 211 |
/** |
| 212 |
* @brief Returns list of supported mainboards |
| 213 |
* @return List of supported mainboards, or NULL if an error occurred |
| 214 |
*/ |
| 215 |
struct flashrom_board_info *flashrom_supported_boards(void); |
| 216 |
/** |
| 217 |
* @brief Returns list of supported chipsets |
| 218 |
* @return List of supported chipsets, or NULL if an error occurred |
| 219 |
*/ |
| 220 |
struct flashrom_chipset_info *flashrom_supported_chipsets(void); |
| 221 |
/** |
| 222 |
* @brief Frees memory allocated by libflashrom API |
| 223 |
* @param p Pointer to block of memory which should be freed |
| 224 |
* @return 0 on success |
| 225 |
*/ |
| 226 |
int flashrom_data_free(void *const p); |
| 227 |
|
| 228 |
/** @} */ /* end flashrom-query */ |
| 229 |
|
| 230 |
/** |
| 231 |
* @defgroup flashrom-prog Programmers |
| 232 |
* @{ |
| 233 |
*/ |
| 234 |
struct flashrom_programmer; |
| 235 |
|
| 236 |
/** |
| 237 |
* @brief Initialize the specified programmer. |
| 238 |
* |
| 239 |
* Currently, only one programmer may be initialized at a time. |
| 240 |
* |
| 241 |
* @param[out] flashprog Points to a pointer of type struct flashrom_programmer |
| 242 |
* that will be set if programmer initialization succeeds. |
| 243 |
* *flashprog has to be shutdown by the caller with @ref |
| 244 |
* flashrom_programmer_shutdown. |
| 245 |
* @param[in] prog_name Name of the programmer to initialize. |
| 246 |
* @param[in] prog_params Pointer to programmer specific parameters. |
| 247 |
* @return 0 on success |
| 248 |
*/ |
| 249 |
int flashrom_programmer_init(struct flashrom_programmer **flashprog, const char *prog_name, const char *prog_params); |
| 250 |
/** |
| 251 |
* @brief Shut down the initialized programmer. |
| 252 |
* |
| 253 |
* @param flashprog The programmer to shut down. |
| 254 |
* @return 0 on success |
| 255 |
*/ |
| 256 |
int flashrom_programmer_shutdown(struct flashrom_programmer *flashprog); |
| 257 |
|
| 258 |
/** @} */ /* end flashrom-prog */ |
| 259 |
|
| 260 |
/** |
| 261 |
* @defgroup flashrom-flash Flash chips |
| 262 |
* @{ |
| 263 |
*/ |
| 264 |
|
| 265 |
/** |
| 266 |
* @deprecated Use flashrom_flash_probe_v2 instead |
| 267 |
* |
| 268 |
* @brief Probe for a flash chip. |
| 269 |
* |
| 270 |
* Probes for a flash chip and returns a flash context, that can be used |
| 271 |
* later with flash chip and @ref flashrom-ops "image operations", if |
| 272 |
* exactly one matching chip is found. |
| 273 |
* |
| 274 |
* @param[out] flashctx Points to a pointer of type struct flashrom_flashctx |
| 275 |
* that will be set if exactly one chip is found. *flashctx |
| 276 |
* has to be freed by the caller with @ref flashrom_flash_release. |
| 277 |
* @param[in] flashprog The flash programmer used to access the chip. |
| 278 |
* @param[in] chip_name Name of a chip to probe for, or NULL to probe for |
| 279 |
* all known chips. |
| 280 |
* @return 0 on success, |
| 281 |
* 3 if multiple chips were found, |
| 282 |
* 2 if no chip was found, |
| 283 |
* or 1 on any other error. |
| 284 |
*/ |
| 285 |
int flashrom_flash_probe(struct flashrom_flashctx **flashctx, const struct flashrom_programmer *flashprog, const char *chip_name) |
| 286 |
__attribute__((deprecated("Use flashrom_flash_probe_v2 instead"))); |
| 287 |
|
| 288 |
/** |
| 289 |
* @brief Probe for a flash chip, v2 |
| 290 |
* |
| 291 |
* Probes for a flash chip and returns a flash context, that can be used |
| 292 |
* later with flash chip and @ref flashrom-ops "image operations", if |
| 293 |
* exactly one matching chip is found. |
| 294 |
* |
| 295 |
* Returns the list of names for all chips that matched, and the count of |
| 296 |
* how many chips matched. |
| 297 |
* |
| 298 |
* Memory for the list of chips is dynamically allocated according to the |
| 299 |
* number of chips found, and always needs to be freed with flashrom_data_free |
| 300 |
* afterwards (including when no matches found or error happened). |
| 301 |
* |
| 302 |
* Note that if chip_name param is set, then probing happens only once, only |
| 303 |
* for this one requested chip name. So the number of matches that can be |
| 304 |
* returned in this case will be either 1 or 0 (and -1 for error). |
| 305 |
* |
| 306 |
* @param[out] flashctx Points to a struct flashrom_flashctx |
| 307 |
* that will be set if exactly one chip is found. *flashctx |
| 308 |
* has to be freed by the caller with @ref flashrom_flash_release. |
| 309 |
* @param[out] all_matched_names pointer to an array containing the names of all chips |
| 310 |
* that were successfully probed, terminated with a NULL pointer. |
| 311 |
* If no chips are found, the returned array contains |
| 312 |
* a single NULL element. Callers must free the array once unused |
| 313 |
* by calling `flashrom_data_free`. |
| 314 |
* @param[in] flashprog The flash programmer used to access the chip, |
| 315 |
* currently unused. |
| 316 |
* @param[in] chip_name Name of a chip to probe for, or NULL to probe for |
| 317 |
* all known chips. |
| 318 |
* @return the number of matched chips (which can be 0) on success, |
| 319 |
* -1 if error happened during probing. |
| 320 |
*/ |
| 321 |
int flashrom_flash_probe_v2(struct flashrom_flashctx *flashctx, |
| 322 |
const char *** const all_matched_names, |
| 323 |
const struct flashrom_programmer *flashprog, |
| 324 |
const char *chip_name); |
| 325 |
|
| 326 |
/** |
| 327 |
* @brief Returns the size of the specified flash chip in bytes. |
| 328 |
* |
| 329 |
* @param flashctx The queried flash context. |
| 330 |
* @return Size of flash chip in bytes. |
| 331 |
*/ |
| 332 |
size_t flashrom_flash_getsize(const struct flashrom_flashctx *flashctx); |
| 333 |
/** |
| 334 |
* @brief Erase the specified ROM chip. |
| 335 |
* |
| 336 |
* If a layout is set in the given flash context, only included regions |
| 337 |
* will be erased. |
| 338 |
* |
| 339 |
* @param flashctx The context of the flash chip to erase. |
| 340 |
* @return 0 on success. |
| 341 |
*/ |
| 342 |
int flashrom_flash_erase(struct flashrom_flashctx *flashctx); |
| 343 |
/** |
| 344 |
* @brief Free a flash context. |
| 345 |
* |
| 346 |
* @param flashctx Flash context to free. |
| 347 |
*/ |
| 348 |
void flashrom_flash_release(struct flashrom_flashctx *flashctx); |
| 349 |
|
| 350 |
enum flashrom_flag { |
| 351 |
FLASHROM_FLAG_FORCE, |
| 352 |
FLASHROM_FLAG_FORCE_BOARDMISMATCH, |
| 353 |
FLASHROM_FLAG_VERIFY_AFTER_WRITE, |
| 354 |
FLASHROM_FLAG_VERIFY_WHOLE_CHIP, |
| 355 |
FLASHROM_FLAG_SKIP_UNREADABLE_REGIONS, |
| 356 |
FLASHROM_FLAG_SKIP_UNWRITABLE_REGIONS, |
| 357 |
}; |
| 358 |
|
| 359 |
/** |
| 360 |
* @brief Set a flag in the given flash context. |
| 361 |
* |
| 362 |
* @param flashctx Flash context to alter. |
| 363 |
* @param flag Flag that is to be set / cleared. |
| 364 |
* @param value Value to set. |
| 365 |
*/ |
| 366 |
void flashrom_flag_set(struct flashrom_flashctx *flashctx, enum flashrom_flag flag, bool value); |
| 367 |
/** |
| 368 |
* @brief Return the current value of a flag in the given flash context. |
| 369 |
* |
| 370 |
* @param flashctx Flash context to read from. |
| 371 |
* @param flag Flag to be read. |
| 372 |
* @return Current value of the flag. |
| 373 |
*/ |
| 374 |
bool flashrom_flag_get(const struct flashrom_flashctx *flashctx, enum flashrom_flag flag); |
| 375 |
|
| 376 |
/** @} */ /* end flashrom-flash */ |
| 377 |
|
| 378 |
/** |
| 379 |
* @defgroup flashrom-ops Operations |
| 380 |
* @{ |
| 381 |
*/ |
| 382 |
|
| 383 |
/** |
| 384 |
* @brief Read the current image from the specified ROM chip. |
| 385 |
* |
| 386 |
* If a layout is set in the specified flash context, only included regions |
| 387 |
* will be read. |
| 388 |
* |
| 389 |
* @param flashctx The context of the flash chip. |
| 390 |
* @param buffer Target buffer to write image to. |
| 391 |
* @param buffer_len Size of target buffer in bytes. |
| 392 |
* @return 0 on success, |
| 393 |
* 2 if buffer_len is too small for the flash chip's contents, |
| 394 |
* or 1 on any other failure. |
| 395 |
*/ |
| 396 |
int flashrom_image_read(struct flashrom_flashctx *flashctx, void *buffer, size_t buffer_len); |
| 397 |
/** |
| 398 |
* @brief Write the specified image to the ROM chip. |
| 399 |
* |
| 400 |
* If a layout is set in the specified flash context, only erase blocks |
| 401 |
* containing included regions will be touched. |
| 402 |
* |
| 403 |
* @param flashctx The context of the flash chip. |
| 404 |
* @param buffer Source buffer to read image from (may be altered for full verification). |
| 405 |
* @param buffer_len Size of source buffer in bytes. |
| 406 |
* @param refbuffer If given, assume flash chip contains same data as `refbuffer`. |
| 407 |
* @return 0 on success, |
| 408 |
* 4 if buffer_len doesn't match the size of the flash chip, |
| 409 |
* 3 if write was tried but nothing has changed, |
| 410 |
* 2 if write failed and flash contents changed, |
| 411 |
* or 1 on any other failure. |
| 412 |
*/ |
| 413 |
int flashrom_image_write(struct flashrom_flashctx *flashctx, void *buffer, size_t buffer_len, const void *refbuffer); |
| 414 |
/** |
| 415 |
* @brief Verify the ROM chip's contents with the specified image. |
| 416 |
* |
| 417 |
* If a layout is set in the specified flash context, only included regions |
| 418 |
* will be verified. |
| 419 |
* |
| 420 |
* @param flashctx The context of the flash chip. |
| 421 |
* @param buffer Source buffer to verify with. |
| 422 |
* @param buffer_len Size of source buffer in bytes. |
| 423 |
* @return 0 on success, |
| 424 |
* 3 if the chip's contents don't match, |
| 425 |
* 2 if buffer_len doesn't match the size of the flash chip, |
| 426 |
* or 1 on any other failure. |
| 427 |
*/ |
| 428 |
int flashrom_image_verify(struct flashrom_flashctx *flashctx, const void *buffer, size_t buffer_len); |
| 429 |
|
| 430 |
/** @} */ /* end flashrom-ops */ |
| 431 |
|
| 432 |
/** |
| 433 |
* @defgroup flashrom-layout Layout handling |
| 434 |
* @{ |
| 435 |
*/ |
| 436 |
|
| 437 |
struct flashrom_layout; |
| 438 |
/** |
| 439 |
* @brief Create a new, empty layout. |
| 440 |
* |
| 441 |
* @param layout Pointer to returned layout reference. |
| 442 |
* |
| 443 |
* @return 0 on success, |
| 444 |
* 1 if out of memory. |
| 445 |
*/ |
| 446 |
int flashrom_layout_new(struct flashrom_layout **layout); |
| 447 |
|
| 448 |
/** |
| 449 |
* @brief Read a layout from the Intel ICH descriptor in the flash. |
| 450 |
* |
| 451 |
* Optionally verify that the layout matches the one in the given |
| 452 |
* descriptor dump. |
| 453 |
* |
| 454 |
* @param[out] layout Points to a struct flashrom_layout pointer that |
| 455 |
* gets set if the descriptor is read and parsed |
| 456 |
* successfully. |
| 457 |
* @param[in] flashctx Flash context to read the descriptor from flash. |
| 458 |
* @param[in] dump The descriptor dump to compare to or NULL. |
| 459 |
* @param[in] len The length of the descriptor dump. |
| 460 |
* |
| 461 |
* @return 0 on success, |
| 462 |
* 6 if descriptor parsing isn't implemented for the host, |
| 463 |
* 5 if the descriptors don't match, |
| 464 |
* 4 if the descriptor dump couldn't be parsed, |
| 465 |
* 3 if the descriptor on flash couldn't be parsed, |
| 466 |
* 2 if the descriptor on flash couldn't be read, |
| 467 |
* 1 on any other error. |
| 468 |
*/ |
| 469 |
int flashrom_layout_read_from_ifd(struct flashrom_layout **layout, struct flashrom_flashctx *flashctx, const void *dump, size_t len); |
| 470 |
/** |
| 471 |
* @brief Read a layout by searching the flash chip for fmap. |
| 472 |
* |
| 473 |
* @param[out] layout Points to a struct flashrom_layout pointer that |
| 474 |
* gets set if the fmap is read and parsed successfully. |
| 475 |
* @param[in] flashctx Flash context |
| 476 |
* @param[in] offset Offset to begin searching for fmap. |
| 477 |
* @param[in] length Length of address space to search. |
| 478 |
* |
| 479 |
* @return 0 on success, |
| 480 |
* 3 if fmap parsing isn't implemented for the host, |
| 481 |
* 2 if the fmap couldn't be read, |
| 482 |
* 1 on any other error. |
| 483 |
*/ |
| 484 |
int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **layout, |
| 485 |
struct flashrom_flashctx *flashctx, size_t offset, size_t length); |
| 486 |
/** |
| 487 |
* @brief Read a layout by searching a buffer for fmap. |
| 488 |
* |
| 489 |
* @param[out] layout Points to a struct flashrom_layout pointer that |
| 490 |
* gets set if the fmap is read and parsed successfully. |
| 491 |
* @param[in] flashctx Flash context |
| 492 |
* @param[in] buffer Buffer to search in |
| 493 |
* @param[in] len Size of buffer to search |
| 494 |
* |
| 495 |
* @return 0 on success, |
| 496 |
* 3 if fmap parsing isn't implemented for the host, |
| 497 |
* 2 if the fmap couldn't be read, |
| 498 |
* 1 on any other error. |
| 499 |
*/ |
| 500 |
int flashrom_layout_read_fmap_from_buffer(struct flashrom_layout **layout, |
| 501 |
struct flashrom_flashctx *flashctx, const uint8_t *buffer, size_t len); |
| 502 |
/** |
| 503 |
* @brief Add a region to an existing layout. |
| 504 |
* |
| 505 |
* @param layout The existing layout. |
| 506 |
* @param start Start address of the region. |
| 507 |
* @param end End address (inclusive) of the region. |
| 508 |
* @param name Name of the region. |
| 509 |
* |
| 510 |
* @return 0 on success, |
| 511 |
* 1 if out of memory. |
| 512 |
*/ |
| 513 |
int flashrom_layout_add_region(struct flashrom_layout *layout, size_t start, size_t end, const char *name); |
| 514 |
/** |
| 515 |
* @brief Mark given region as included. |
| 516 |
* |
| 517 |
* @param layout The layout to alter. |
| 518 |
* @param name The name of the region to include. |
| 519 |
* |
| 520 |
* @return 0 on success, |
| 521 |
* 1 if the given name can't be found. |
| 522 |
*/ |
| 523 |
int flashrom_layout_include_region(struct flashrom_layout *layout, const char *name); |
| 524 |
/** |
| 525 |
* @brief Mark given region as not included. |
| 526 |
* |
| 527 |
* @param layout The layout to alter. |
| 528 |
* @param name The name of the region to exclude. |
| 529 |
* |
| 530 |
* @return 0 on success, |
| 531 |
* 1 if the given name can't be found. |
| 532 |
*/ |
| 533 |
int flashrom_layout_exclude_region(struct flashrom_layout *layout, const char *name); |
| 534 |
/** |
| 535 |
* @brief Get given region's offset and length. |
| 536 |
* |
| 537 |
* @param[in] layout The existing layout. |
| 538 |
* @param[in] name The name of the region. |
| 539 |
* @param[out] start The start address to be written. |
| 540 |
* @param[out] len The length of the region to be written. |
| 541 |
* |
| 542 |
* @return 0 on success, |
| 543 |
* 1 if the given name can't be found. |
| 544 |
*/ |
| 545 |
int flashrom_layout_get_region_range(struct flashrom_layout *layout, const char *name, |
| 546 |
unsigned int *start, unsigned int *len); |
| 547 |
/** |
| 548 |
* @brief Free a layout. |
| 549 |
* |
| 550 |
* @param layout Layout to free. |
| 551 |
*/ |
| 552 |
void flashrom_layout_release(struct flashrom_layout *layout); |
| 553 |
/** |
| 554 |
* @brief Set the active layout for a flash context. |
| 555 |
* |
| 556 |
* Note: The caller must not release the layout as long as it is used through |
| 557 |
* the given flash context. |
| 558 |
* |
| 559 |
* @param flashctx Flash context whose layout will be set. |
| 560 |
* @param layout Layout to bet set. |
| 561 |
*/ |
| 562 |
void flashrom_layout_set(struct flashrom_flashctx *flashctx, const struct flashrom_layout *layout); |
| 563 |
|
| 564 |
/** @} */ /* end flashrom-layout */ |
| 565 |
|
| 566 |
/** |
| 567 |
* @defgroup flashrom-wp Write Protect |
| 568 |
* @{ |
| 569 |
*/ |
| 570 |
|
| 571 |
enum flashrom_wp_result { |
| 572 |
FLASHROM_WP_OK = 0, |
| 573 |
FLASHROM_WP_ERR_CHIP_UNSUPPORTED = 1, |
| 574 |
FLASHROM_WP_ERR_OTHER = 2, |
| 575 |
FLASHROM_WP_ERR_READ_FAILED = 3, |
| 576 |
FLASHROM_WP_ERR_WRITE_FAILED = 4, |
| 577 |
FLASHROM_WP_ERR_VERIFY_FAILED = 5, |
| 578 |
FLASHROM_WP_ERR_RANGE_UNSUPPORTED = 6, |
| 579 |
FLASHROM_WP_ERR_MODE_UNSUPPORTED = 7, |
| 580 |
FLASHROM_WP_ERR_RANGE_LIST_UNAVAILABLE = 8, |
| 581 |
FLASHROM_WP_ERR_UNSUPPORTED_STATE = 9 |
| 582 |
}; |
| 583 |
|
| 584 |
enum flashrom_wp_mode { |
| 585 |
FLASHROM_WP_MODE_DISABLED, |
| 586 |
FLASHROM_WP_MODE_HARDWARE, |
| 587 |
FLASHROM_WP_MODE_POWER_CYCLE, |
| 588 |
FLASHROM_WP_MODE_PERMANENT |
| 589 |
}; |
| 590 |
struct flashrom_wp_cfg; |
| 591 |
struct flashrom_wp_ranges; |
| 592 |
/** |
| 593 |
* @brief Create a new empty WP configuration. |
| 594 |
* |
| 595 |
* @param[out] cfg Points to a pointer of type struct flashrom_wp_cfg that will |
| 596 |
* be set if creation succeeds. *cfg has to be freed by the |
| 597 |
* caller with @ref flashrom_wp_cfg_release. |
| 598 |
* @return 0 on success |
| 599 |
* >0 on failure |
| 600 |
*/ |
| 601 |
enum flashrom_wp_result flashrom_wp_cfg_new(struct flashrom_wp_cfg **cfg); |
| 602 |
/** |
| 603 |
* @brief Free a WP configuration. |
| 604 |
* |
| 605 |
* @param[in] cfg Pointer to the flashrom_wp_cfg to free. |
| 606 |
*/ |
| 607 |
void flashrom_wp_cfg_release(struct flashrom_wp_cfg *cfg); |
| 608 |
/** |
| 609 |
* @brief Set the protection mode for a WP configuration. |
| 610 |
* |
| 611 |
* @param[in] mode The protection mode to set. |
| 612 |
* @param[out] cfg Pointer to the flashrom_wp_cfg structure to modify. |
| 613 |
*/ |
| 614 |
void flashrom_wp_set_mode(struct flashrom_wp_cfg *cfg, enum flashrom_wp_mode mode); |
| 615 |
/** |
| 616 |
* @brief Get the protection mode from a WP configuration. |
| 617 |
* |
| 618 |
* @param[in] cfg The WP configuration to get the protection mode from. |
| 619 |
* @return The configuration's protection mode. |
| 620 |
*/ |
| 621 |
enum flashrom_wp_mode flashrom_wp_get_mode(const struct flashrom_wp_cfg *cfg); |
| 622 |
/** |
| 623 |
* @brief Set the protection range for a WP configuration. |
| 624 |
* |
| 625 |
* @param[out] cfg Pointer to the flashrom_wp_cfg structure to modify. |
| 626 |
* @param[in] start The range's start address. |
| 627 |
* @param[in] len The range's length. |
| 628 |
*/ |
| 629 |
void flashrom_wp_set_range(struct flashrom_wp_cfg *cfg, size_t start, size_t len); |
| 630 |
/** |
| 631 |
* @brief Get the protection range from a WP configuration. |
| 632 |
* |
| 633 |
* @param[out] start Points to a size_t to write the range start to. |
| 634 |
* @param[out] len Points to a size_t to write the range length to. |
| 635 |
* @param[in] cfg The WP configuration to get the range from. |
| 636 |
*/ |
| 637 |
void flashrom_wp_get_range(size_t *start, size_t *len, const struct flashrom_wp_cfg *cfg); |
| 638 |
|
| 639 |
/** |
| 640 |
* @brief Read the current WP configuration from a flash chip. |
| 641 |
* |
| 642 |
* @param[out] cfg Pointer to a struct flashrom_wp_cfg to store the chip's |
| 643 |
* configuration in. |
| 644 |
* @param[in] flash The flash context used to access the chip. |
| 645 |
* @return 0 on success |
| 646 |
* >0 on failure |
| 647 |
*/ |
| 648 |
enum flashrom_wp_result flashrom_wp_read_cfg(struct flashrom_wp_cfg *cfg, struct flashrom_flashctx *flash); |
| 649 |
/** |
| 650 |
* @brief Write a WP configuration to a flash chip. |
| 651 |
* |
| 652 |
* @param[in] flash The flash context used to access the chip. |
| 653 |
* @param[in] cfg The WP configuration to write to the chip. |
| 654 |
* @return 0 on success |
| 655 |
* >0 on failure |
| 656 |
*/ |
| 657 |
enum flashrom_wp_result flashrom_wp_write_cfg(struct flashrom_flashctx *flash, const struct flashrom_wp_cfg *cfg); |
| 658 |
|
| 659 |
/** |
| 660 |
* @brief Get a list of protection ranges supported by the flash chip. |
| 661 |
* |
| 662 |
* @param[out] ranges Points to a pointer of type struct flashrom_wp_ranges |
| 663 |
* that will be set if available ranges are found. Finding |
| 664 |
* available ranges may not always be possible, even if the |
| 665 |
* chip's protection range can be read or modified. *ranges |
| 666 |
* must be freed using @ref flashrom_wp_ranges_release. |
| 667 |
* @param[in] flash The flash context used to access the chip. |
| 668 |
* @return 0 on success |
| 669 |
* >0 on failure |
| 670 |
*/ |
| 671 |
enum flashrom_wp_result flashrom_wp_get_available_ranges(struct flashrom_wp_ranges **ranges, struct flashrom_flashctx *flash); |
| 672 |
/** |
| 673 |
* @brief Get a number of protection ranges in a range list. |
| 674 |
* |
| 675 |
* @param[in] ranges The range list to get the count from. |
| 676 |
* @return Number of ranges in the list. |
| 677 |
*/ |
| 678 |
size_t flashrom_wp_ranges_get_count(const struct flashrom_wp_ranges *ranges); |
| 679 |
/** |
| 680 |
* @brief Get a protection range from a range list. |
| 681 |
* |
| 682 |
* @param[out] start Points to a size_t to write the range's start to. |
| 683 |
* @param[out] len Points to a size_t to write the range's length to. |
| 684 |
* @param[in] ranges The range list to get the range from. |
| 685 |
* @param[in] index Index of the range to get. |
| 686 |
* @return 0 on success |
| 687 |
* >0 on failure |
| 688 |
*/ |
| 689 |
enum flashrom_wp_result flashrom_wp_ranges_get_range(size_t *start, size_t *len, const struct flashrom_wp_ranges *ranges, unsigned int index); |
| 690 |
/** |
| 691 |
* @brief Free a WP range list. |
| 692 |
* |
| 693 |
* @param[out] ranges Pointer to the flashrom_wp_ranges to free. |
| 694 |
*/ |
| 695 |
void flashrom_wp_ranges_release(struct flashrom_wp_ranges *ranges); |
| 696 |
|
| 697 |
/** @} */ /* end flashrom-wp */ |
| 698 |
|
| 699 |
#endif /* !__LIBFLASHROM_H__ */ |