blob: eab78ad11904cb5da1b256b60cb4f279bafc8f7c [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>
Mario Limonciello40f07572019-08-29 14:19:21 -050023#include <stdbool.h>
24#include <stdint.h>
Nico Huber454f6132012-12-10 13:34:10 +000025#include <stdarg.h>
26
27int flashrom_init(int perform_selfcheck);
28int flashrom_shutdown(void);
29/** @ingroup flashrom-general */
Nico Huberd152fb92017-06-19 12:57:10 +020030enum flashrom_log_level {
Nico Huber454f6132012-12-10 13:34:10 +000031 FLASHROM_MSG_ERROR = 0,
Nico Hubere8e7a802017-06-19 12:38:39 +020032 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 Huber454f6132012-12-10 13:34:10 +000037};
38/** @ingroup flashrom-general */
39typedef int(flashrom_log_callback)(enum flashrom_log_level, const char *format, va_list);
40void flashrom_set_log_callback(flashrom_log_callback *);
41
Artur Raglis71b706f2019-06-05 19:24:52 +020042/** @ingroup flashrom-query */
43enum 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
51struct 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
63struct flashrom_board_info {
64 const char *vendor;
65 const char *name;
66 enum flashrom_test_state working;
67};
68
69struct 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
77const char *flashrom_version_info(void);
Artur Raglis71b706f2019-06-05 19:24:52 +020078struct 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__ */