Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
Nikolai Artemiev | da1c834 | 2021-10-21 00:58:12 +1100 | [diff] [blame] | 4 | * Copyright (C) 2010 Google Inc. |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 5 | * Copyright (C) 2012 secunet Security Networks AG |
| 6 | * (Written by Nico Huber <nico.huber@secunet.com> for secunet) |
| 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; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #ifndef __LIBFLASHROM_H__ |
| 20 | #define __LIBFLASHROM_H__ 1 |
| 21 | |
Nico Huber | e7cbfae | 2018-12-10 15:21:40 +0100 | [diff] [blame] | 22 | #include <sys/types.h> |
| 23 | #include <stddef.h> |
Mario Limonciello | 40f0757 | 2019-08-29 14:19:21 -0500 | [diff] [blame] | 24 | #include <stdbool.h> |
| 25 | #include <stdint.h> |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 26 | #include <stdarg.h> |
| 27 | |
| 28 | int flashrom_init(int perform_selfcheck); |
| 29 | int flashrom_shutdown(void); |
| 30 | /** @ingroup flashrom-general */ |
Nico Huber | d152fb9 | 2017-06-19 12:57:10 +0200 | [diff] [blame] | 31 | enum flashrom_log_level { |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 32 | FLASHROM_MSG_ERROR = 0, |
Nico Huber | e8e7a80 | 2017-06-19 12:38:39 +0200 | [diff] [blame] | 33 | FLASHROM_MSG_WARN = 1, |
| 34 | FLASHROM_MSG_INFO = 2, |
| 35 | FLASHROM_MSG_DEBUG = 3, |
| 36 | FLASHROM_MSG_DEBUG2 = 4, |
| 37 | FLASHROM_MSG_SPEW = 5, |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 38 | }; |
| 39 | /** @ingroup flashrom-general */ |
| 40 | typedef int(flashrom_log_callback)(enum flashrom_log_level, const char *format, va_list); |
| 41 | void flashrom_set_log_callback(flashrom_log_callback *); |
| 42 | |
Artur Raglis | 71b706f | 2019-06-05 19:24:52 +0200 | [diff] [blame] | 43 | /** @ingroup flashrom-query */ |
| 44 | enum flashrom_test_state { |
| 45 | FLASHROM_TESTED_OK = 0, |
| 46 | FLASHROM_TESTED_NT = 1, |
| 47 | FLASHROM_TESTED_BAD = 2, |
| 48 | FLASHROM_TESTED_DEP = 3, |
| 49 | FLASHROM_TESTED_NA = 4, |
| 50 | }; |
| 51 | |
| 52 | struct flashrom_flashchip_info { |
| 53 | const char *vendor; |
| 54 | const char *name; |
| 55 | unsigned int total_size; |
| 56 | struct flashrom_tested { |
| 57 | enum flashrom_test_state probe; |
| 58 | enum flashrom_test_state read; |
| 59 | enum flashrom_test_state erase; |
| 60 | enum flashrom_test_state write; |
| 61 | } tested; |
| 62 | }; |
| 63 | |
| 64 | struct flashrom_board_info { |
| 65 | const char *vendor; |
| 66 | const char *name; |
| 67 | enum flashrom_test_state working; |
| 68 | }; |
| 69 | |
| 70 | struct flashrom_chipset_info { |
| 71 | const char *vendor; |
| 72 | const char *chipset; |
| 73 | uint16_t vendor_id; |
| 74 | uint16_t chipset_id; |
| 75 | enum flashrom_test_state status; |
| 76 | }; |
| 77 | |
| 78 | const char *flashrom_version_info(void); |
| 79 | void flashrom_system_info(void); |
| 80 | const char **flashrom_supported_programmers(void); |
| 81 | struct flashrom_flashchip_info *flashrom_supported_flash_chips(void); |
| 82 | struct flashrom_board_info *flashrom_supported_boards(void); |
| 83 | struct flashrom_chipset_info *flashrom_supported_chipsets(void); |
| 84 | int flashrom_data_free(void *const p); |
| 85 | |
| 86 | /** @ingroup flashrom-prog */ |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 87 | struct flashrom_programmer; |
| 88 | int flashrom_programmer_init(struct flashrom_programmer **, const char *prog_name, const char *prog_params); |
| 89 | int flashrom_programmer_shutdown(struct flashrom_programmer *); |
| 90 | |
| 91 | struct flashrom_flashctx; |
| 92 | int flashrom_flash_probe(struct flashrom_flashctx **, const struct flashrom_programmer *, const char *chip_name); |
| 93 | size_t flashrom_flash_getsize(const struct flashrom_flashctx *); |
| 94 | int flashrom_flash_erase(struct flashrom_flashctx *); |
| 95 | void flashrom_flash_release(struct flashrom_flashctx *); |
| 96 | |
| 97 | /** @ingroup flashrom-flash */ |
| 98 | enum flashrom_flag { |
| 99 | FLASHROM_FLAG_FORCE, |
| 100 | FLASHROM_FLAG_FORCE_BOARDMISMATCH, |
| 101 | FLASHROM_FLAG_VERIFY_AFTER_WRITE, |
| 102 | FLASHROM_FLAG_VERIFY_WHOLE_CHIP, |
| 103 | }; |
| 104 | void flashrom_flag_set(struct flashrom_flashctx *, enum flashrom_flag, bool value); |
| 105 | bool flashrom_flag_get(const struct flashrom_flashctx *, enum flashrom_flag); |
| 106 | |
| 107 | int flashrom_image_read(struct flashrom_flashctx *, void *buffer, size_t buffer_len); |
Paul Kocialkowski | f701f34 | 2018-01-15 01:10:36 +0300 | [diff] [blame] | 108 | int flashrom_image_write(struct flashrom_flashctx *, void *buffer, size_t buffer_len, const void *refbuffer); |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 109 | int flashrom_image_verify(struct flashrom_flashctx *, const void *buffer, size_t buffer_len); |
| 110 | |
| 111 | struct flashrom_layout; |
Nico Huber | 305f417 | 2013-06-14 11:55:26 +0200 | [diff] [blame] | 112 | int flashrom_layout_read_from_ifd(struct flashrom_layout **, struct flashrom_flashctx *, const void *dump, size_t len); |
Arthur Heymans | c82900b | 2018-01-10 12:48:16 +0100 | [diff] [blame] | 113 | int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **, |
| 114 | struct flashrom_flashctx *, off_t offset, size_t length); |
| 115 | int flashrom_layout_read_fmap_from_buffer(struct flashrom_layout **layout, |
| 116 | struct flashrom_flashctx *, const uint8_t *buf, size_t len); |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 117 | int flashrom_layout_include_region(struct flashrom_layout *, const char *name); |
| 118 | void flashrom_layout_release(struct flashrom_layout *); |
| 119 | void flashrom_layout_set(struct flashrom_flashctx *, const struct flashrom_layout *); |
| 120 | |
Nikolai Artemiev | da1c834 | 2021-10-21 00:58:12 +1100 | [diff] [blame] | 121 | /** @ingroup flashrom-wp */ |
| 122 | enum flashrom_wp_result { |
| 123 | FLASHROM_WP_OK = 0, |
| 124 | FLASHROM_WP_ERR_CHIP_UNSUPPORTED = 1, |
| 125 | FLASHROM_WP_ERR_OTHER = 2, |
| 126 | FLASHROM_WP_ERR_READ_FAILED = 3, |
| 127 | FLASHROM_WP_ERR_WRITE_FAILED = 4, |
Nikolai Artemiev | b6112a5 | 2021-10-21 02:28:23 +1100 | [diff] [blame] | 128 | FLASHROM_WP_ERR_VERIFY_FAILED = 5, |
Nikolai Artemiev | 9e1afb7 | 2021-10-21 02:29:22 +1100 | [diff] [blame] | 129 | FLASHROM_WP_ERR_RANGE_UNSUPPORTED = 6, |
| 130 | FLASHROM_WP_ERR_MODE_UNSUPPORTED = 7, |
| 131 | FLASHROM_WP_ERR_RANGE_LIST_UNAVAILABLE = 8 |
Nikolai Artemiev | da1c834 | 2021-10-21 00:58:12 +1100 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | enum flashrom_wp_mode { |
| 135 | FLASHROM_WP_MODE_DISABLED, |
| 136 | FLASHROM_WP_MODE_HARDWARE, |
| 137 | FLASHROM_WP_MODE_POWER_CYCLE, |
| 138 | FLASHROM_WP_MODE_PERMANENT |
| 139 | }; |
| 140 | struct flashrom_wp_cfg; |
Nikolai Artemiev | 077c0d1 | 2021-10-21 01:50:15 +1100 | [diff] [blame] | 141 | struct flashrom_wp_ranges; |
Nikolai Artemiev | da1c834 | 2021-10-21 00:58:12 +1100 | [diff] [blame] | 142 | |
| 143 | enum flashrom_wp_result flashrom_wp_cfg_new(struct flashrom_wp_cfg **); |
| 144 | void flashrom_wp_cfg_release(struct flashrom_wp_cfg *); |
| 145 | void flashrom_wp_set_mode(struct flashrom_wp_cfg *, enum flashrom_wp_mode); |
| 146 | enum flashrom_wp_mode flashrom_wp_get_mode(const struct flashrom_wp_cfg *); |
| 147 | void flashrom_wp_set_range(struct flashrom_wp_cfg *, size_t start, size_t len); |
| 148 | void flashrom_wp_get_range(size_t *start, size_t *len, const struct flashrom_wp_cfg *); |
| 149 | |
| 150 | enum flashrom_wp_result flashrom_wp_read_cfg(struct flashrom_wp_cfg *, struct flashrom_flashctx *); |
| 151 | enum flashrom_wp_result flashrom_wp_write_cfg(struct flashrom_flashctx *, const struct flashrom_wp_cfg *); |
| 152 | |
Nikolai Artemiev | 077c0d1 | 2021-10-21 01:50:15 +1100 | [diff] [blame] | 153 | enum flashrom_wp_result flashrom_wp_get_available_ranges(struct flashrom_wp_ranges **, struct flashrom_flashctx *); |
| 154 | size_t flashrom_wp_ranges_get_count(const struct flashrom_wp_ranges *); |
| 155 | enum flashrom_wp_result flashrom_wp_ranges_get_range(size_t *start, size_t *len, const struct flashrom_wp_ranges *, unsigned int index); |
| 156 | void flashrom_wp_ranges_release(struct flashrom_wp_ranges *); |
| 157 | |
Arthur Heymans | c82900b | 2018-01-10 12:48:16 +0100 | [diff] [blame] | 158 | #endif /* !__LIBFLASHROM_H__ */ |