Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2012 secunet Security Networks AG |
| 5 | * (Written by Nico Huber <nico.huber@secunet.com> for secunet) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 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. |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #ifndef __LIBFLASHROM_H__ |
| 19 | #define __LIBFLASHROM_H__ 1 |
| 20 | |
Nico Huber | e7cbfae | 2018-12-10 15:21:40 +0100 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <stddef.h> |
Mario Limonciello | 40f0757 | 2019-08-29 14:19:21 -0500 | [diff] [blame] | 23 | #include <stdbool.h> |
| 24 | #include <stdint.h> |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 25 | #include <stdarg.h> |
| 26 | |
| 27 | int flashrom_init(int perform_selfcheck); |
| 28 | int flashrom_shutdown(void); |
| 29 | /** @ingroup flashrom-general */ |
Nico Huber | d152fb9 | 2017-06-19 12:57:10 +0200 | [diff] [blame] | 30 | enum flashrom_log_level { |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 31 | FLASHROM_MSG_ERROR = 0, |
Nico Huber | e8e7a80 | 2017-06-19 12:38:39 +0200 | [diff] [blame] | 32 | FLASHROM_MSG_WARN = 1, |
| 33 | FLASHROM_MSG_INFO = 2, |
| 34 | FLASHROM_MSG_DEBUG = 3, |
| 35 | FLASHROM_MSG_DEBUG2 = 4, |
| 36 | FLASHROM_MSG_SPEW = 5, |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 37 | }; |
| 38 | /** @ingroup flashrom-general */ |
| 39 | typedef int(flashrom_log_callback)(enum flashrom_log_level, const char *format, va_list); |
| 40 | void flashrom_set_log_callback(flashrom_log_callback *); |
| 41 | |
Artur Raglis | 71b706f | 2019-06-05 19:24:52 +0200 | [diff] [blame] | 42 | /** @ingroup flashrom-query */ |
| 43 | enum flashrom_test_state { |
| 44 | FLASHROM_TESTED_OK = 0, |
| 45 | FLASHROM_TESTED_NT = 1, |
| 46 | FLASHROM_TESTED_BAD = 2, |
| 47 | FLASHROM_TESTED_DEP = 3, |
| 48 | FLASHROM_TESTED_NA = 4, |
| 49 | }; |
| 50 | |
| 51 | struct flashrom_flashchip_info { |
| 52 | const char *vendor; |
| 53 | const char *name; |
| 54 | unsigned int total_size; |
| 55 | struct flashrom_tested { |
| 56 | enum flashrom_test_state probe; |
| 57 | enum flashrom_test_state read; |
| 58 | enum flashrom_test_state erase; |
| 59 | enum flashrom_test_state write; |
| 60 | } tested; |
| 61 | }; |
| 62 | |
| 63 | struct flashrom_board_info { |
| 64 | const char *vendor; |
| 65 | const char *name; |
| 66 | enum flashrom_test_state working; |
| 67 | }; |
| 68 | |
| 69 | struct flashrom_chipset_info { |
| 70 | const char *vendor; |
| 71 | const char *chipset; |
| 72 | uint16_t vendor_id; |
| 73 | uint16_t chipset_id; |
| 74 | enum flashrom_test_state status; |
| 75 | }; |
| 76 | |
| 77 | const char *flashrom_version_info(void); |
| 78 | void flashrom_system_info(void); |
| 79 | const char **flashrom_supported_programmers(void); |
| 80 | struct flashrom_flashchip_info *flashrom_supported_flash_chips(void); |
| 81 | struct flashrom_board_info *flashrom_supported_boards(void); |
| 82 | struct flashrom_chipset_info *flashrom_supported_chipsets(void); |
| 83 | int flashrom_data_free(void *const p); |
| 84 | |
| 85 | /** @ingroup flashrom-prog */ |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 86 | struct flashrom_programmer; |
| 87 | int flashrom_programmer_init(struct flashrom_programmer **, const char *prog_name, const char *prog_params); |
| 88 | int flashrom_programmer_shutdown(struct flashrom_programmer *); |
| 89 | |
| 90 | struct flashrom_flashctx; |
| 91 | int flashrom_flash_probe(struct flashrom_flashctx **, const struct flashrom_programmer *, const char *chip_name); |
| 92 | size_t flashrom_flash_getsize(const struct flashrom_flashctx *); |
| 93 | int flashrom_flash_erase(struct flashrom_flashctx *); |
| 94 | void flashrom_flash_release(struct flashrom_flashctx *); |
| 95 | |
| 96 | /** @ingroup flashrom-flash */ |
| 97 | enum flashrom_flag { |
| 98 | FLASHROM_FLAG_FORCE, |
| 99 | FLASHROM_FLAG_FORCE_BOARDMISMATCH, |
| 100 | FLASHROM_FLAG_VERIFY_AFTER_WRITE, |
| 101 | FLASHROM_FLAG_VERIFY_WHOLE_CHIP, |
| 102 | }; |
| 103 | void flashrom_flag_set(struct flashrom_flashctx *, enum flashrom_flag, bool value); |
| 104 | bool flashrom_flag_get(const struct flashrom_flashctx *, enum flashrom_flag); |
| 105 | |
| 106 | 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] | 107 | 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] | 108 | int flashrom_image_verify(struct flashrom_flashctx *, const void *buffer, size_t buffer_len); |
| 109 | |
| 110 | struct flashrom_layout; |
Nico Huber | 305f417 | 2013-06-14 11:55:26 +0200 | [diff] [blame] | 111 | 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] | 112 | int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **, |
| 113 | struct flashrom_flashctx *, off_t offset, size_t length); |
| 114 | int flashrom_layout_read_fmap_from_buffer(struct flashrom_layout **layout, |
| 115 | struct flashrom_flashctx *, const uint8_t *buf, size_t len); |
Nico Huber | 454f613 | 2012-12-10 13:34:10 +0000 | [diff] [blame] | 116 | int flashrom_layout_include_region(struct flashrom_layout *, const char *name); |
| 117 | void flashrom_layout_release(struct flashrom_layout *); |
| 118 | void flashrom_layout_set(struct flashrom_flashctx *, const struct flashrom_layout *); |
| 119 | |
Arthur Heymans | c82900b | 2018-01-10 12:48:16 +0100 | [diff] [blame] | 120 | #endif /* !__LIBFLASHROM_H__ */ |