blob: 257036227197a0dcccd3df7aa027f37b4f62c29d [file] [log] [blame]
Nico Huber454f6132012-12-10 13:34:10 +00001/*
2 * This file is part of the flashrom project.
3 *
Nikolai Artemievda1c8342021-10-21 00:58:12 +11004 * Copyright (C) 2010 Google Inc.
Nico Huber454f6132012-12-10 13:34:10 +00005 * 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 Huber454f6132012-12-10 13:34:10 +000017 */
18
19#ifndef __LIBFLASHROM_H__
20#define __LIBFLASHROM_H__ 1
21
Nico Hubere7cbfae2018-12-10 15:21:40 +010022#include <sys/types.h>
23#include <stddef.h>
Mario Limonciello40f07572019-08-29 14:19:21 -050024#include <stdbool.h>
25#include <stdint.h>
Nico Huber454f6132012-12-10 13:34:10 +000026#include <stdarg.h>
27
28int flashrom_init(int perform_selfcheck);
29int flashrom_shutdown(void);
30/** @ingroup flashrom-general */
Nico Huberd152fb92017-06-19 12:57:10 +020031enum flashrom_log_level {
Nico Huber454f6132012-12-10 13:34:10 +000032 FLASHROM_MSG_ERROR = 0,
Nico Hubere8e7a802017-06-19 12:38:39 +020033 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 Huber454f6132012-12-10 13:34:10 +000038};
39/** @ingroup flashrom-general */
40typedef int(flashrom_log_callback)(enum flashrom_log_level, const char *format, va_list);
41void flashrom_set_log_callback(flashrom_log_callback *);
42
Artur Raglis71b706f2019-06-05 19:24:52 +020043/** @ingroup flashrom-query */
44enum 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
52struct 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;
Sergii Dmytrukc720b6e2022-10-06 15:17:52 +030061 enum flashrom_test_state wp;
Artur Raglis71b706f2019-06-05 19:24:52 +020062 } tested;
63};
64
65struct flashrom_board_info {
66 const char *vendor;
67 const char *name;
68 enum flashrom_test_state working;
69};
70
71struct flashrom_chipset_info {
72 const char *vendor;
73 const char *chipset;
74 uint16_t vendor_id;
75 uint16_t chipset_id;
76 enum flashrom_test_state status;
77};
78
79const char *flashrom_version_info(void);
80void flashrom_system_info(void);
81const char **flashrom_supported_programmers(void);
82struct flashrom_flashchip_info *flashrom_supported_flash_chips(void);
83struct flashrom_board_info *flashrom_supported_boards(void);
84struct flashrom_chipset_info *flashrom_supported_chipsets(void);
85int flashrom_data_free(void *const p);
86
87/** @ingroup flashrom-prog */
Nico Huber454f6132012-12-10 13:34:10 +000088struct flashrom_programmer;
89int flashrom_programmer_init(struct flashrom_programmer **, const char *prog_name, const char *prog_params);
90int flashrom_programmer_shutdown(struct flashrom_programmer *);
91
92struct flashrom_flashctx;
93int flashrom_flash_probe(struct flashrom_flashctx **, const struct flashrom_programmer *, const char *chip_name);
94size_t flashrom_flash_getsize(const struct flashrom_flashctx *);
95int flashrom_flash_erase(struct flashrom_flashctx *);
96void flashrom_flash_release(struct flashrom_flashctx *);
97
98/** @ingroup flashrom-flash */
99enum flashrom_flag {
100 FLASHROM_FLAG_FORCE,
101 FLASHROM_FLAG_FORCE_BOARDMISMATCH,
102 FLASHROM_FLAG_VERIFY_AFTER_WRITE,
103 FLASHROM_FLAG_VERIFY_WHOLE_CHIP,
104};
105void flashrom_flag_set(struct flashrom_flashctx *, enum flashrom_flag, bool value);
106bool flashrom_flag_get(const struct flashrom_flashctx *, enum flashrom_flag);
107
108int flashrom_image_read(struct flashrom_flashctx *, void *buffer, size_t buffer_len);
Paul Kocialkowskif701f342018-01-15 01:10:36 +0300109int flashrom_image_write(struct flashrom_flashctx *, void *buffer, size_t buffer_len, const void *refbuffer);
Nico Huber454f6132012-12-10 13:34:10 +0000110int flashrom_image_verify(struct flashrom_flashctx *, const void *buffer, size_t buffer_len);
111
112struct flashrom_layout;
Nico Huber305f4172013-06-14 11:55:26 +0200113int flashrom_layout_read_from_ifd(struct flashrom_layout **, struct flashrom_flashctx *, const void *dump, size_t len);
Arthur Heymansc82900b2018-01-10 12:48:16 +0100114int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **,
115 struct flashrom_flashctx *, off_t offset, size_t length);
116int flashrom_layout_read_fmap_from_buffer(struct flashrom_layout **layout,
117 struct flashrom_flashctx *, const uint8_t *buf, size_t len);
Nico Huber454f6132012-12-10 13:34:10 +0000118int flashrom_layout_include_region(struct flashrom_layout *, const char *name);
119void flashrom_layout_release(struct flashrom_layout *);
120void flashrom_layout_set(struct flashrom_flashctx *, const struct flashrom_layout *);
121
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100122/** @ingroup flashrom-wp */
123enum flashrom_wp_result {
124 FLASHROM_WP_OK = 0,
125 FLASHROM_WP_ERR_CHIP_UNSUPPORTED = 1,
126 FLASHROM_WP_ERR_OTHER = 2,
127 FLASHROM_WP_ERR_READ_FAILED = 3,
128 FLASHROM_WP_ERR_WRITE_FAILED = 4,
Nikolai Artemievb6112a52021-10-21 02:28:23 +1100129 FLASHROM_WP_ERR_VERIFY_FAILED = 5,
Nikolai Artemiev9e1afb72021-10-21 02:29:22 +1100130 FLASHROM_WP_ERR_RANGE_UNSUPPORTED = 6,
131 FLASHROM_WP_ERR_MODE_UNSUPPORTED = 7,
132 FLASHROM_WP_ERR_RANGE_LIST_UNAVAILABLE = 8
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100133};
134
135enum flashrom_wp_mode {
136 FLASHROM_WP_MODE_DISABLED,
137 FLASHROM_WP_MODE_HARDWARE,
138 FLASHROM_WP_MODE_POWER_CYCLE,
139 FLASHROM_WP_MODE_PERMANENT
140};
141struct flashrom_wp_cfg;
Nikolai Artemiev077c0d12021-10-21 01:50:15 +1100142struct flashrom_wp_ranges;
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100143
144enum flashrom_wp_result flashrom_wp_cfg_new(struct flashrom_wp_cfg **);
145void flashrom_wp_cfg_release(struct flashrom_wp_cfg *);
146void flashrom_wp_set_mode(struct flashrom_wp_cfg *, enum flashrom_wp_mode);
147enum flashrom_wp_mode flashrom_wp_get_mode(const struct flashrom_wp_cfg *);
148void flashrom_wp_set_range(struct flashrom_wp_cfg *, size_t start, size_t len);
149void flashrom_wp_get_range(size_t *start, size_t *len, const struct flashrom_wp_cfg *);
150
151enum flashrom_wp_result flashrom_wp_read_cfg(struct flashrom_wp_cfg *, struct flashrom_flashctx *);
152enum flashrom_wp_result flashrom_wp_write_cfg(struct flashrom_flashctx *, const struct flashrom_wp_cfg *);
153
Nikolai Artemiev077c0d12021-10-21 01:50:15 +1100154enum flashrom_wp_result flashrom_wp_get_available_ranges(struct flashrom_wp_ranges **, struct flashrom_flashctx *);
155size_t flashrom_wp_ranges_get_count(const struct flashrom_wp_ranges *);
156enum flashrom_wp_result flashrom_wp_ranges_get_range(size_t *start, size_t *len, const struct flashrom_wp_ranges *, unsigned int index);
157void flashrom_wp_ranges_release(struct flashrom_wp_ranges *);
158
Arthur Heymansc82900b2018-01-10 12:48:16 +0100159#endif /* !__LIBFLASHROM_H__ */