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.
16  */
17 
18 #ifndef __LIBFLASHROM_H__
19 #define __LIBFLASHROM_H__ 1
20 
21 #include <sys/types.h>
22 #include <stddef.h>
23 #include <stdbool.h>
24 #include <stdint.h>
25 #include <stdarg.h>
26 
27 int flashrom_init(int perform_selfcheck);
28 int flashrom_shutdown(void);
29 /** @ingroup flashrom-general */
30 enum flashrom_log_level {
31 	FLASHROM_MSG_ERROR	= 0,
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,
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 
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 */
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);
107 int flashrom_image_write(struct flashrom_flashctx *, void *buffer, size_t buffer_len, const void *refbuffer);
108 int flashrom_image_verify(struct flashrom_flashctx *, const void *buffer, size_t buffer_len);
109 
110 struct flashrom_layout;
111 int flashrom_layout_read_from_ifd(struct flashrom_layout **, struct flashrom_flashctx *, const void *dump, size_t len);
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);
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 
120 #endif				/* !__LIBFLASHROM_H__ */
121