blob: 52c2a8eaad26b08c94e6728c9fee76740a853497 [file] [log] [blame]
stepan5c3f1382007-02-06 19:47:50 +00001/*
uweb25f1ea2007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
stepan5c3f1382007-02-06 19:47:50 +00003 *
uwe555dd972007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
stepan6d42c0f2009-08-12 09:27:45 +00006 * Copyright (C) 2005-2009 coresystems GmbH
hailfinger77c5d932009-06-15 12:10:57 +00007 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
stepan5c3f1382007-02-06 19:47:50 +00008 *
uweb25f1ea2007-08-29 17:52:32 +00009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
stepan5c3f1382007-02-06 19:47:50 +000013 *
uweb25f1ea2007-08-29 17:52:32 +000014 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
stepan5c3f1382007-02-06 19:47:50 +000018 *
19 */
20
rminnich8d3ff912003-10-25 17:01:29 +000021#ifndef __FLASH_H__
22#define __FLASH_H__ 1
23
ollie6a600992005-11-26 21:55:36 +000024#include <stdint.h>
hailfingerd43a4e32010-06-03 00:49:50 +000025#include <stddef.h>
hailfinger088dc812009-12-14 03:32:24 +000026#include "hwaccess.h"
oxygene3ad3b332010-01-06 22:14:39 +000027#ifdef _WIN32
28#include <windows.h>
29#undef min
30#undef max
31#endif
hailfingere1f062f2008-05-22 13:22:45 +000032
Stefan Reinauere64faaf2011-05-03 18:03:25 -070033/* Are timers broken? */
34extern int broken_timer;
35
Souvik Ghoshd75cd672016-06-17 14:21:39 -070036struct flashctx; /* forward declare */
hailfingerf294fa22010-09-25 22:53:44 +000037#define ERROR_PTR ((void*)-1)
38
hailfingeree9ee132010-10-08 00:37:55 +000039/* Error codes */
40#define TIMEOUT_ERROR -101
41
Louis Yung-Chieh Lo5d95f042011-09-01 17:33:06 +080042/* for verify_it variable in flashrom.c and cli_mfg.c */
43enum {
44 VERIFY_OFF = 0,
45 VERIFY_FULL,
46 VERIFY_PARTIAL,
47};
48
hailfinger82719632009-05-16 21:22:56 +000049typedef unsigned long chipaddr;
50
David Hendricks93784b42016-08-09 17:00:38 -070051int register_shutdown(int (*function) (void *data), void *data);
Souvik Ghoshd75cd672016-06-17 14:21:39 -070052#define CHIP_RESTORE_CALLBACK int (*func) (struct flashctx *flash, uint8_t status)
David Hendricksbf36f092010-11-02 23:39:29 -070053
Souvik Ghoshd75cd672016-06-17 14:21:39 -070054int register_chip_restore(CHIP_RESTORE_CALLBACK, struct flashctx *flash, uint8_t status);
uweabe92a52009-05-16 22:36:00 +000055void *programmer_map_flash_region(const char *descr, unsigned long phys_addr,
56 size_t len);
57void programmer_unmap_flash_region(void *virt_addr, size_t len);
hailfingere5829f62009-06-05 17:48:08 +000058void programmer_delay(int usecs);
hailfingerba3761a2009-03-05 19:24:22 +000059
uwe16f99092008-03-12 11:54:51 +000060#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
61
hailfinger40167462009-05-31 17:57:34 +000062enum chipbustype {
hailfingere1e41ea2011-07-27 07:13:06 +000063 BUS_NONE = 0,
64 BUS_PARALLEL = 1 << 0,
65 BUS_LPC = 1 << 1,
66 BUS_FWH = 1 << 2,
67 BUS_SPI = 1 << 3,
hailfingerfe7cd9e2011-11-04 21:35:26 +000068 BUS_PROG = 1 << 4,
hailfingere1e41ea2011-07-27 07:13:06 +000069 BUS_NONSPI = BUS_PARALLEL | BUS_LPC | BUS_FWH,
hailfinger40167462009-05-31 17:57:34 +000070};
71
David Hendricks80f62d22010-10-08 11:09:35 -070072/* used to select bus which target chip resides */
73extern enum chipbustype target_bus;
74
hailfinger7df21362009-09-05 02:30:58 +000075/*
76 * How many different contiguous runs of erase blocks with one size each do
77 * we have for a given erase function?
78 */
79#define NUM_ERASEREGIONS 5
80
81/*
82 * How many different erase functions do we have per chip?
hailfingerc33d4732010-07-29 13:09:18 +000083 * Atmel AT25FS010 has 6 different functions.
hailfinger7df21362009-09-05 02:30:58 +000084 */
hailfingerc33d4732010-07-29 13:09:18 +000085#define NUM_ERASEFUNCTIONS 6
hailfinger7df21362009-09-05 02:30:58 +000086
hailfinger80dea312010-01-09 03:15:50 +000087#define FEATURE_REGISTERMAP (1 << 0)
88#define FEATURE_BYTEWRITES (1 << 1)
snelsonc6855342010-01-28 23:55:12 +000089#define FEATURE_LONG_RESET (0 << 4)
90#define FEATURE_SHORT_RESET (1 << 4)
91#define FEATURE_EITHER_RESET FEATURE_LONG_RESET
hailfingerb07dc972010-10-20 21:13:19 +000092#define FEATURE_RESET_MASK (FEATURE_LONG_RESET | FEATURE_SHORT_RESET)
hailfinger80dea312010-01-09 03:15:50 +000093#define FEATURE_ADDR_FULL (0 << 2)
94#define FEATURE_ADDR_MASK (3 << 2)
snelsonc6855342010-01-28 23:55:12 +000095#define FEATURE_ADDR_2AA (1 << 2)
96#define FEATURE_ADDR_AAA (2 << 2)
mkarcher9ded5fe2010-04-03 10:27:08 +000097#define FEATURE_ADDR_SHIFTED (1 << 5)
hailfingerc33d4732010-07-29 13:09:18 +000098#define FEATURE_WRSR_EWSR (1 << 6)
99#define FEATURE_WRSR_WREN (1 << 7)
100#define FEATURE_WRSR_EITHER (FEATURE_WRSR_EWSR | FEATURE_WRSR_WREN)
David Hendricksff55cf62016-08-30 11:22:31 -0700101#define FEATURE_OTP (1 << 8)
102#define FEATURE_ERASE_TO_ZERO (1 << 9)
Duncan Laurie06ffd522015-10-26 12:56:08 -0700103#define FEATURE_UNBOUND_READ (1 << 10)
William A. Kennington IIIf15c2fa2017-04-07 17:38:42 -0700104#define FEATURE_NO_ERASE (1 << 11)
Boris Baykov64d00c72016-06-11 18:28:59 +0200105#define FEATURE_4BA_SUPPORT (1 << 12)
Simon Glass4c214132013-07-16 10:09:28 -0600106
David Hendricks8c084212015-11-17 22:29:36 -0800107struct voltage_range {
108 uint16_t min, max;
109};
110
Patrick Georgiac3423f2017-02-03 20:58:06 +0100111enum test_state {
112 OK = 0,
113 NT = 1, /* Not tested */
114 BAD, /* Known to not work */
115 DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */
116 NA, /* Not applicable (e.g. write support on ROM chips) */
117};
118
119#define TEST_UNTESTED (struct tested){ .probe = NT, .read = NT, .erase = NT, .write = NT, .uread = NT }
120
121#define TEST_OK_PROBE (struct tested){ .probe = OK, .read = NT, .erase = NT, .write = NT, .uread = NT }
122#define TEST_OK_PR (struct tested){ .probe = OK, .read = OK, .erase = NT, .write = NT, .uread = NT }
123#define TEST_OK_PRE (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = NT, .uread = NT }
124#define TEST_OK_PRU (struct tested){ .probe = OK, .read = OK, .erase = NT, .write = NT, .uread = OK }
125#define TEST_OK_PREU (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = NT, .uread = OK }
126#define TEST_OK_PREW (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = OK, .uread = NT }
127#define TEST_OK_PREWU (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = OK, .uread = OK }
128
129#define TEST_BAD_PROBE (struct tested){ .probe = BAD, .read = NT, .erase = NT, .write = NT, .uread = NT }
130#define TEST_BAD_PR (struct tested){ .probe = BAD, .read = BAD, .erase = NT, .write = NT, .uread = NT }
131#define TEST_BAD_PRE (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = NT, .uread = NT }
132#define TEST_BAD_PREW (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = BAD, .uread = NT }
133#define TEST_BAD_PREWU (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = BAD, .uread = BAD }
134
rminnich8d3ff912003-10-25 17:01:29 +0000135struct flashchip {
uwedfcd15f2008-03-14 23:55:58 +0000136 const char *vendor;
uwe6ed6d952007-12-04 21:49:06 +0000137 const char *name;
hailfinger40167462009-05-31 17:57:34 +0000138
139 enum chipbustype bustype;
140
uwefa98ca12008-10-18 21:14:13 +0000141 /*
142 * With 32bit manufacture_id and model_id we can cover IDs up to
hailfinger428f2012007-12-31 01:49:00 +0000143 * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's
144 * Identification code.
145 */
146 uint32_t manufacture_id;
147 uint32_t model_id;
rminnich8d3ff912003-10-25 17:01:29 +0000148
stefanct707f13b2011-05-19 02:58:17 +0000149 /* Total chip size in kilobytes */
stefanctc5eb8a92011-11-23 09:13:48 +0000150 unsigned int total_size;
stefanct707f13b2011-05-19 02:58:17 +0000151 /* Chip page size in bytes */
stefanctc5eb8a92011-11-23 09:13:48 +0000152 unsigned int page_size;
snelson63133f92010-01-04 17:15:23 +0000153 int feature_bits;
rminnich8d3ff912003-10-25 17:01:29 +0000154
Boris Baykov1a2f5322016-06-11 18:29:00 +0200155 /* set of function pointers to use in 4-bytes addressing mode */
156 struct four_bytes_addr_funcs_set {
Ed Swierk28cf7992017-07-03 13:17:18 -0700157 int (*set_4ba) (struct flashctx *flash);
Boris Baykov1a2f5322016-06-11 18:29:00 +0200158 int (*read_nbyte) (struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len);
159 int (*program_byte) (struct flashctx *flash, unsigned int addr, const uint8_t databyte);
160 int (*program_nbyte) (struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len);
161 } four_bytes_addr_funcs;
162
Patrick Georgiac3423f2017-02-03 20:58:06 +0100163 /* Indicate how well flashrom supports different operations of this flash chip. */
164 struct tested {
165 enum test_state probe;
166 enum test_state read;
167 enum test_state erase;
168 enum test_state write;
169 enum test_state uread;
170 } tested;
stuge9cd64bd2008-05-03 04:34:37 +0000171
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700172 int (*probe) (struct flashctx *flash);
hailfingerd5b35922009-06-03 14:46:22 +0000173
stefanctc5eb8a92011-11-23 09:13:48 +0000174 /* Delay after "enter/exit ID mode" commands in microseconds.
175 * NB: negative values have special meanings, see TIMING_* below.
176 */
177 signed int probe_timing;
hailfinger7df21362009-09-05 02:30:58 +0000178
179 /*
hailfingerc4fac582009-12-22 13:04:53 +0000180 * Erase blocks and associated erase function. Any chip erase function
181 * is stored as chip-sized virtual block together with said function.
stefanct707f13b2011-05-19 02:58:17 +0000182 * The first one that fits will be chosen. There is currently no way to
183 * influence that behaviour. For testing just comment out the other
184 * elements or set the function pointer to NULL.
hailfinger7df21362009-09-05 02:30:58 +0000185 */
186 struct block_eraser {
Patrick Georgiac3423f2017-02-03 20:58:06 +0100187 struct eraseblock {
stefanct312d9ff2011-06-12 19:47:55 +0000188 unsigned int size; /* Eraseblock size in bytes */
hailfinger7df21362009-09-05 02:30:58 +0000189 unsigned int count; /* Number of contiguous blocks with that size */
190 } eraseblocks[NUM_ERASEREGIONS];
stefanct9e6b98a2011-05-28 02:37:14 +0000191 /* a block_erase function should try to erase one block of size
192 * 'blocklen' at address 'blockaddr' and return 0 on success. */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700193 int (*block_erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
hailfinger7df21362009-09-05 02:30:58 +0000194 } block_erasers[NUM_ERASEFUNCTIONS];
195
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700196 int (*printlock) (struct flashctx *flash);
197 int (*unlock) (struct flashctx *flash);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100198 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700199 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
200 uint8_t (*read_status) (const struct flashctx *flash);
201 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks8c084212015-11-17 22:29:36 -0800202 struct voltage_range voltage;
David Hendricksf7924d12010-06-10 21:26:44 -0700203 struct wp *wp;
rminnich8d3ff912003-10-25 17:01:29 +0000204};
205
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700206/* struct flashctx must always contain struct flashchip at the beginning. */
207struct flashctx {
Patrick Georgif3fa2992017-02-02 16:24:44 +0100208 struct flashchip *chip;
209
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700210 chipaddr virtual_memory;
211 /* Some flash devices have an additional register space. */
212 chipaddr virtual_registers;
213};
214
215
Simon Glass4c214132013-07-16 10:09:28 -0600216/* This is the byte value we expect to see in erased regions of the flash */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700217int flash_erase_value(struct flashctx *flash);
Simon Glass4c214132013-07-16 10:09:28 -0600218
219/* This is a byte value that indicates that the region is not erased */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700220int flash_unerased_value(struct flashctx *flash);
Simon Glass4c214132013-07-16 10:09:28 -0600221
David Hendricks40df5b52016-12-22 15:36:28 -0800222/* Given RDID info, return pointer to entry in flashchips[] */
223const struct flashchip *flash_id_to_entry(uint32_t mfg_id, uint32_t model_id);
224
hailfingerd5b35922009-06-03 14:46:22 +0000225/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
226 * field and zero delay.
Simon Glass8dc82732013-07-16 10:13:51 -0600227 *
hailfingerd5b35922009-06-03 14:46:22 +0000228 * SPI devices will always have zero delay and ignore this field.
229 */
230#define TIMING_FIXME -1
231/* this is intentionally same value as fixme */
232#define TIMING_IGNORED -1
233#define TIMING_ZERO -2
234
hailfinger48ed3e22011-05-04 00:39:50 +0000235extern const struct flashchip flashchips[];
Ramya Vijaykumare6a7ca82015-05-12 14:27:29 +0530236extern const struct flashchip flashchips_hwseq[];
ollie6a600992005-11-26 21:55:36 +0000237
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700238void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
239void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
240void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
241void chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
242uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr);
243uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr);
244uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr);
245void chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
246
uwe884cc8b2009-06-17 12:07:12 +0000247/* print.c */
248char *flashbuses_to_text(enum chipbustype bustype);
hailfingera50d60e2009-11-17 09:57:34 +0000249void print_supported(void);
hailfingera50d60e2009-11-17 09:57:34 +0000250void print_supported_wiki(void);
uwea3a82c92009-05-15 17:02:34 +0000251
Edward O'Callaghan8dd57922019-03-15 16:21:34 +1100252/* helpers.c */
253uint32_t address_to_bits(uint32_t addr);
254int bitcount(unsigned long a);
255int min(int a, int b);
256int max(int a, int b);
257char *strcat_realloc(char *dest, const char *src);
258void tolower_string(char *str);
259
uwe4529d202007-08-23 13:34:59 +0000260/* flashrom.c */
hailfingerb247c7a2010-03-08 00:42:32 +0000261enum write_granularity {
262 write_gran_1bit,
263 write_gran_1byte,
264 write_gran_256bytes,
265};
hailfinger80422e22009-12-13 22:28:00 +0000266extern enum chipbustype buses_supported;
Edward O'Callaghan8d8d3972019-02-24 20:40:10 +1100267extern enum flashrom_log_level verbose_screen;
268extern enum flashrom_log_level verbose_logfile;
krause2eb76212011-01-17 07:50:42 +0000269extern const char flashrom_version[];
hailfinger92cd8e32010-01-07 03:24:05 +0000270extern char *chip_to_probe;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700271void map_flash_registers(struct flashctx *flash);
272int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
273int erase_flash(struct flashctx *flash);
David Hendricksac1d25c2016-08-09 17:00:58 -0700274int probe_flash(int startchip, struct flashctx *fill_flash, int force);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700275int read_flash(struct flashctx *flash, uint8_t *buf,
David Hendrickse3451942013-03-21 17:23:29 -0700276 unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700277int read_flash_to_file(struct flashctx *flash, const char *filename);
stefanct52700282011-06-26 17:38:17 +0000278char *extract_param(char **haystack, const char *needle, const char *delim);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700279int verify_range(struct flashctx *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len, const char *message);
hailfinger92cd8e32010-01-07 03:24:05 +0000280void print_version(void);
Souvik Ghosh3c963a42016-07-19 18:48:15 -0700281void print_buildinfo(void);
hailfinger74819ad2010-05-15 15:04:37 +0000282void print_banner(void);
hailfingerf79d1712010-10-06 23:48:34 +0000283void list_programmers_linebreak(int startcol, int cols, int paren);
hailfinger92cd8e32010-01-07 03:24:05 +0000284int selfcheck(void);
Vadim Bendebury2f346a32018-05-21 10:24:18 -0700285
286/*
287 *
288 * The main processing function of flashrom utility; it is invoked once
289 * command line parameters are processed and verified, and the type of the
290 * flash chip the programmer operates on has been determined.
291 *
292 * @flash pointer to the flash context matching the chip detected
293 * during initialization.
294 * @force when set proceed even if the chip is not known to work
295 * @filename pointer to the name of the file to read from or write to
296 * @read_it when true, flash contents are read into 'filename'
297 * @write_it when true, flash is programmed with 'filename' contents
298 * @erase_it when true, flash chip is erased
299 * @verify_it depending on the value verify the full chip, only changed
300 * areas, or none
301 * @extract_it extract all known flash chip regions into separate files
302 * @diff_file when deciding what areas to program, use this file's
303 * contents instead of reading the current chip contents
304 * @do_diff when true - compare result of the operation with either the
305 * original chip contents for 'diff_file' contents, is present.
306 * When false - do not diff, consider the chip erased before
307 * operation starts.
308 *
309 * Only one of 'read_it', 'write_it', and 'erase_it' is expected to be set,
310 * but this is not enforced.
311 *
312 * 'do_diff' must be set if 'diff_file' is set. If 'do_diff' is set, but
313 * 'diff_file' is not - comparison is done against the pre-operation chip
314 * contents.
315 */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700316int doit(struct flashctx *flash, int force, const char *filename, int read_it,
Simon Glass9ad06c12013-07-03 22:08:17 +0900317 int write_it, int erase_it, int verify_it, int extract_it,
Vadim Bendebury2f346a32018-05-21 10:24:18 -0700318 const char *diff_file, int do_diff);
stefanct52700282011-06-26 17:38:17 +0000319int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename);
320int write_buf_to_file(unsigned char *buf, unsigned long size, const char *filename);
uwe884cc8b2009-06-17 12:07:12 +0000321
322#define OK 0
323#define NT 1 /* Not tested */
uwe4529d202007-08-23 13:34:59 +0000324
David Hendricks1ed1d352011-11-23 17:54:37 -0800325/* what to do in case of an error */
326enum error_action {
327 error_fail, /* fail immediately */
328 error_ignore, /* non-fatal error; continue */
329};
330
uwe97e8e272011-09-03 17:15:00 +0000331/* Something happened that shouldn't happen, but we can go on. */
mkarcher74d30132010-07-22 18:04:15 +0000332#define ERROR_NONFATAL 0x100
333
uwe97e8e272011-09-03 17:15:00 +0000334/* Something happened that shouldn't happen, we'll abort. */
335#define ERROR_FATAL -0xee
336
David Hendricks1ed1d352011-11-23 17:54:37 -0800337/* Operation failed due to access restriction set in programmer or flash chip */
338#define ACCESS_DENIED -7
339extern enum error_action access_denied_action;
340
341/* convenience function for checking return codes */
342extern int ignore_error(int x);
343
snelson9cba3c62010-01-07 20:09:33 +0000344/* cli_output.c */
Souvik Ghosh3c963a42016-07-19 18:48:15 -0700345#ifndef STANDALONE
346int open_logfile(const char * const filename);
347int close_logfile(void);
348void start_logging(void);
349#endif
Edward O'Callaghan8d8d3972019-02-24 20:40:10 +1100350enum flashrom_log_level {
351 FLASHROM_MSG_ERROR = 0,
352 FLASHROM_MSG_WARN = 1,
353 FLASHROM_MSG_INFO = 2,
354 FLASHROM_MSG_DEBUG = 3,
355 FLASHROM_MSG_DEBUG2 = 4,
356 FLASHROM_MSG_SPEW = 5,
Patrick Georgidbde2f12017-02-03 18:07:45 +0100357};
hailfinger63932d42010-06-04 23:20:21 +0000358/* Let gcc and clang check for correct printf-style format strings. */
Edward O'Callaghan8d8d3972019-02-24 20:40:10 +1100359int print(enum flashrom_log_level level, const char *fmt, ...)
Patrick Georgidbde2f12017-02-03 18:07:45 +0100360#ifdef __MINGW32__
361__attribute__((format(gnu_printf, 2, 3)));
362#else
363__attribute__((format(printf, 2, 3)));
364#endif
Edward O'Callaghan8d8d3972019-02-24 20:40:10 +1100365#define msg_gerr(...) print(FLASHROM_MSG_ERROR, __VA_ARGS__) /* general errors */
366#define msg_perr(...) print(FLASHROM_MSG_ERROR, __VA_ARGS__) /* programmer errors */
367#define msg_cerr(...) print(FLASHROM_MSG_ERROR, __VA_ARGS__) /* chip errors */
368#define msg_gwarn(...) print(FLASHROM_MSG_WARN, __VA_ARGS__) /* general warnings */
369#define msg_pwarn(...) print(FLASHROM_MSG_WARN, __VA_ARGS__) /* programmer warnings */
370#define msg_cwarn(...) print(FLASHROM_MSG_WARN, __VA_ARGS__) /* chip warnings */
371#define msg_ginfo(...) print(FLASHROM_MSG_INFO, __VA_ARGS__) /* general info */
372#define msg_pinfo(...) print(FLASHROM_MSG_INFO, __VA_ARGS__) /* programmer info */
373#define msg_cinfo(...) print(FLASHROM_MSG_INFO, __VA_ARGS__) /* chip info */
374#define msg_gdbg(...) print(FLASHROM_MSG_DEBUG, __VA_ARGS__) /* general debug */
375#define msg_pdbg(...) print(FLASHROM_MSG_DEBUG, __VA_ARGS__) /* programmer debug */
376#define msg_cdbg(...) print(FLASHROM_MSG_DEBUG, __VA_ARGS__) /* chip debug */
377#define msg_gdbg2(...) print(FLASHROM_MSG_DEBUG2, __VA_ARGS__) /* general debug2 */
378#define msg_pdbg2(...) print(FLASHROM_MSG_DEBUG2, __VA_ARGS__) /* programmer debug2 */
379#define msg_cdbg2(...) print(FLASHROM_MSG_DEBUG2, __VA_ARGS__) /* chip debug2 */
380#define msg_gspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* general debug spew */
381#define msg_pspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* programmer debug spew */
382#define msg_cspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* chip debug spew */
snelson9cba3c62010-01-07 20:09:33 +0000383
stepan745615e2007-10-15 21:44:47 +0000384/* spi.c */
hailfinger68002c22009-07-10 21:08:55 +0000385struct spi_command {
386 unsigned int writecnt;
387 unsigned int readcnt;
388 const unsigned char *writearr;
389 unsigned char *readarr;
390};
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700391int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
uwefa98ca12008-10-18 21:14:13 +0000392 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700393int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
394uint32_t spi_get_valid_read_addr(struct flashctx *flash);
uweaf9b4df2008-09-26 13:19:02 +0000395
David Hendricks8c084212015-11-17 22:29:36 -0800396#define NUM_VOLTAGE_RANGES 16
397extern struct voltage_range voltage_ranges[];
398/* returns number of unique voltage ranges, or <0 to indicate failure */
399extern int flash_supported_voltage_ranges(enum chipbustype bus);
400
ollie5b621572004-03-20 16:46:10 +0000401#endif /* !__FLASH_H__ */