blob: a0da6dfe7379a5e1a08908e4eadff892e68e833f [file] [log] [blame]
Nico Huber454f6132012-12-10 13:34:10 +00001/*
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 Huber454f6132012-12-10 13:34:10 +000016 */
17
18#ifndef __LIBFLASHROM_H__
19#define __LIBFLASHROM_H__ 1
20
Nico Hubere7cbfae2018-12-10 15:21:40 +010021#include <sys/types.h>
22#include <stddef.h>
Nico Huber454f6132012-12-10 13:34:10 +000023#include <stdarg.h>
24
25int flashrom_init(int perform_selfcheck);
26int flashrom_shutdown(void);
27/** @ingroup flashrom-general */
Nico Huberd152fb92017-06-19 12:57:10 +020028enum flashrom_log_level {
Nico Huber454f6132012-12-10 13:34:10 +000029 FLASHROM_MSG_ERROR = 0,
Nico Hubere8e7a802017-06-19 12:38:39 +020030 FLASHROM_MSG_WARN = 1,
31 FLASHROM_MSG_INFO = 2,
32 FLASHROM_MSG_DEBUG = 3,
33 FLASHROM_MSG_DEBUG2 = 4,
34 FLASHROM_MSG_SPEW = 5,
Nico Huber454f6132012-12-10 13:34:10 +000035};
36/** @ingroup flashrom-general */
37typedef int(flashrom_log_callback)(enum flashrom_log_level, const char *format, va_list);
38void flashrom_set_log_callback(flashrom_log_callback *);
39
Artur Raglis71b706f2019-06-05 19:24:52 +020040/** @ingroup flashrom-query */
41enum flashrom_test_state {
42 FLASHROM_TESTED_OK = 0,
43 FLASHROM_TESTED_NT = 1,
44 FLASHROM_TESTED_BAD = 2,
45 FLASHROM_TESTED_DEP = 3,
46 FLASHROM_TESTED_NA = 4,
47};
48
49struct flashrom_flashchip_info {
50 const char *vendor;
51 const char *name;
52 unsigned int total_size;
53 struct flashrom_tested {
54 enum flashrom_test_state probe;
55 enum flashrom_test_state read;
56 enum flashrom_test_state erase;
57 enum flashrom_test_state write;
58 } tested;
59};
60
61struct flashrom_board_info {
62 const char *vendor;
63 const char *name;
64 enum flashrom_test_state working;
65};
66
67struct flashrom_chipset_info {
68 const char *vendor;
69 const char *chipset;
70 uint16_t vendor_id;
71 uint16_t chipset_id;
72 enum flashrom_test_state status;
73};
74
75const char *flashrom_version_info(void);
76void flashrom_system_info(void);
77const char **flashrom_supported_programmers(void);
78struct flashrom_flashchip_info *flashrom_supported_flash_chips(void);
79struct flashrom_board_info *flashrom_supported_boards(void);
80struct flashrom_chipset_info *flashrom_supported_chipsets(void);
81int flashrom_data_free(void *const p);
82
83/** @ingroup flashrom-prog */
Nico Huber454f6132012-12-10 13:34:10 +000084struct flashrom_programmer;
85int flashrom_programmer_init(struct flashrom_programmer **, const char *prog_name, const char *prog_params);
86int flashrom_programmer_shutdown(struct flashrom_programmer *);
87
88struct flashrom_flashctx;
89int flashrom_flash_probe(struct flashrom_flashctx **, const struct flashrom_programmer *, const char *chip_name);
90size_t flashrom_flash_getsize(const struct flashrom_flashctx *);
91int flashrom_flash_erase(struct flashrom_flashctx *);
92void flashrom_flash_release(struct flashrom_flashctx *);
93
94/** @ingroup flashrom-flash */
95enum flashrom_flag {
96 FLASHROM_FLAG_FORCE,
97 FLASHROM_FLAG_FORCE_BOARDMISMATCH,
98 FLASHROM_FLAG_VERIFY_AFTER_WRITE,
99 FLASHROM_FLAG_VERIFY_WHOLE_CHIP,
100};
101void flashrom_flag_set(struct flashrom_flashctx *, enum flashrom_flag, bool value);
102bool flashrom_flag_get(const struct flashrom_flashctx *, enum flashrom_flag);
103
104int flashrom_image_read(struct flashrom_flashctx *, void *buffer, size_t buffer_len);
Paul Kocialkowskif701f342018-01-15 01:10:36 +0300105int flashrom_image_write(struct flashrom_flashctx *, void *buffer, size_t buffer_len, const void *refbuffer);
Nico Huber454f6132012-12-10 13:34:10 +0000106int flashrom_image_verify(struct flashrom_flashctx *, const void *buffer, size_t buffer_len);
107
108struct flashrom_layout;
Nico Huber305f4172013-06-14 11:55:26 +0200109int flashrom_layout_read_from_ifd(struct flashrom_layout **, struct flashrom_flashctx *, const void *dump, size_t len);
Arthur Heymansc82900b2018-01-10 12:48:16 +0100110int flashrom_layout_read_fmap_from_rom(struct flashrom_layout **,
111 struct flashrom_flashctx *, off_t offset, size_t length);
112int flashrom_layout_read_fmap_from_buffer(struct flashrom_layout **layout,
113 struct flashrom_flashctx *, const uint8_t *buf, size_t len);
Nico Huber454f6132012-12-10 13:34:10 +0000114int flashrom_layout_include_region(struct flashrom_layout *, const char *name);
115void flashrom_layout_release(struct flashrom_layout *);
116void flashrom_layout_set(struct flashrom_flashctx *, const struct flashrom_layout *);
117
Arthur Heymansc82900b2018-01-10 12:48:16 +0100118#endif /* !__LIBFLASHROM_H__ */