blob: 96e9c6bba12ac280f887e4437d88d96748d09237 [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 *
uweb25f1ea2007-08-29 17:52:32 +000019 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
stepan5c3f1382007-02-06 19:47:50 +000022 */
23
rminnich8d3ff912003-10-25 17:01:29 +000024#ifndef __FLASH_H__
25#define __FLASH_H__ 1
26
ollie6a600992005-11-26 21:55:36 +000027#include <stdint.h>
hailfingerd43a4e32010-06-03 00:49:50 +000028#include <stddef.h>
hailfinger088dc812009-12-14 03:32:24 +000029#include "hwaccess.h"
oxygene3ad3b332010-01-06 22:14:39 +000030#ifdef _WIN32
31#include <windows.h>
32#undef min
33#undef max
34#endif
hailfingere1f062f2008-05-22 13:22:45 +000035
Stefan Reinauere64faaf2011-05-03 18:03:25 -070036/* Are timers broken? */
37extern int broken_timer;
38
Souvik Ghoshd75cd672016-06-17 14:21:39 -070039struct flashctx; /* forward declare */
hailfingerf294fa22010-09-25 22:53:44 +000040#define ERROR_PTR ((void*)-1)
41
hailfingeree9ee132010-10-08 00:37:55 +000042/* Error codes */
43#define TIMEOUT_ERROR -101
44
Louis Yung-Chieh Lo5d95f042011-09-01 17:33:06 +080045/* for verify_it variable in flashrom.c and cli_mfg.c */
46enum {
47 VERIFY_OFF = 0,
48 VERIFY_FULL,
49 VERIFY_PARTIAL,
50};
51
David Hendricks54777392015-01-11 18:55:14 -080052/*
53 * This is shared between handle_partial_read() and erase_and_write_flash().
54 * If a partial write is to be performed, the read function needs to guess what
55 * the eraseable block size is in case the region specified is not aligned. Then
56 * it can ensure any data within the same block but outside the specified region
57 * is read and later restored. The erase/write function will need to find a
58 * usable erase function with the same size.
59 *
60 * Some chips support multiple opcodes to erase a particular block size, so
61 * we'll leave that guesswork to erase_and_write_flash(). Any opcode is allowed
62 * so long as the alignment used during partial read and erase are the same.
63 */
64extern unsigned int required_erase_size;
65
hailfinger82719632009-05-16 21:22:56 +000066typedef unsigned long chipaddr;
67
David Hendricks93784b42016-08-09 17:00:38 -070068int register_shutdown(int (*function) (void *data), void *data);
Souvik Ghoshd75cd672016-06-17 14:21:39 -070069#define CHIP_RESTORE_CALLBACK int (*func) (struct flashctx *flash, uint8_t status)
David Hendricksbf36f092010-11-02 23:39:29 -070070
Souvik Ghoshd75cd672016-06-17 14:21:39 -070071int register_chip_restore(CHIP_RESTORE_CALLBACK, struct flashctx *flash, uint8_t status);
uweabe92a52009-05-16 22:36:00 +000072void *programmer_map_flash_region(const char *descr, unsigned long phys_addr,
73 size_t len);
74void programmer_unmap_flash_region(void *virt_addr, size_t len);
hailfingere5829f62009-06-05 17:48:08 +000075void programmer_delay(int usecs);
hailfingerba3761a2009-03-05 19:24:22 +000076
uwe16f99092008-03-12 11:54:51 +000077#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
78
hailfinger40167462009-05-31 17:57:34 +000079enum chipbustype {
hailfingere1e41ea2011-07-27 07:13:06 +000080 BUS_NONE = 0,
81 BUS_PARALLEL = 1 << 0,
82 BUS_LPC = 1 << 1,
83 BUS_FWH = 1 << 2,
84 BUS_SPI = 1 << 3,
hailfingerfe7cd9e2011-11-04 21:35:26 +000085 BUS_PROG = 1 << 4,
hailfingere1e41ea2011-07-27 07:13:06 +000086 BUS_NONSPI = BUS_PARALLEL | BUS_LPC | BUS_FWH,
hailfinger40167462009-05-31 17:57:34 +000087};
88
David Hendricks80f62d22010-10-08 11:09:35 -070089/* used to select bus which target chip resides */
90extern enum chipbustype target_bus;
91
hailfinger7df21362009-09-05 02:30:58 +000092/*
93 * How many different contiguous runs of erase blocks with one size each do
94 * we have for a given erase function?
95 */
96#define NUM_ERASEREGIONS 5
97
98/*
99 * How many different erase functions do we have per chip?
hailfingerc33d4732010-07-29 13:09:18 +0000100 * Atmel AT25FS010 has 6 different functions.
hailfinger7df21362009-09-05 02:30:58 +0000101 */
hailfingerc33d4732010-07-29 13:09:18 +0000102#define NUM_ERASEFUNCTIONS 6
hailfinger7df21362009-09-05 02:30:58 +0000103
hailfinger80dea312010-01-09 03:15:50 +0000104#define FEATURE_REGISTERMAP (1 << 0)
105#define FEATURE_BYTEWRITES (1 << 1)
snelsonc6855342010-01-28 23:55:12 +0000106#define FEATURE_LONG_RESET (0 << 4)
107#define FEATURE_SHORT_RESET (1 << 4)
108#define FEATURE_EITHER_RESET FEATURE_LONG_RESET
hailfingerb07dc972010-10-20 21:13:19 +0000109#define FEATURE_RESET_MASK (FEATURE_LONG_RESET | FEATURE_SHORT_RESET)
hailfinger80dea312010-01-09 03:15:50 +0000110#define FEATURE_ADDR_FULL (0 << 2)
111#define FEATURE_ADDR_MASK (3 << 2)
snelsonc6855342010-01-28 23:55:12 +0000112#define FEATURE_ADDR_2AA (1 << 2)
113#define FEATURE_ADDR_AAA (2 << 2)
mkarcher9ded5fe2010-04-03 10:27:08 +0000114#define FEATURE_ADDR_SHIFTED (1 << 5)
hailfingerc33d4732010-07-29 13:09:18 +0000115#define FEATURE_WRSR_EWSR (1 << 6)
116#define FEATURE_WRSR_WREN (1 << 7)
117#define FEATURE_WRSR_EITHER (FEATURE_WRSR_EWSR | FEATURE_WRSR_WREN)
David Hendricksff55cf62016-08-30 11:22:31 -0700118#define FEATURE_OTP (1 << 8)
119#define FEATURE_ERASE_TO_ZERO (1 << 9)
Duncan Laurie06ffd522015-10-26 12:56:08 -0700120#define FEATURE_UNBOUND_READ (1 << 10)
Simon Glass4c214132013-07-16 10:09:28 -0600121
David Hendricks8c084212015-11-17 22:29:36 -0800122struct voltage_range {
123 uint16_t min, max;
124};
125
Patrick Georgiac3423f2017-02-03 20:58:06 +0100126enum test_state {
127 OK = 0,
128 NT = 1, /* Not tested */
129 BAD, /* Known to not work */
130 DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */
131 NA, /* Not applicable (e.g. write support on ROM chips) */
132};
133
134#define TEST_UNTESTED (struct tested){ .probe = NT, .read = NT, .erase = NT, .write = NT, .uread = NT }
135
136#define TEST_OK_PROBE (struct tested){ .probe = OK, .read = NT, .erase = NT, .write = NT, .uread = NT }
137#define TEST_OK_PR (struct tested){ .probe = OK, .read = OK, .erase = NT, .write = NT, .uread = NT }
138#define TEST_OK_PRE (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = NT, .uread = NT }
139#define TEST_OK_PRU (struct tested){ .probe = OK, .read = OK, .erase = NT, .write = NT, .uread = OK }
140#define TEST_OK_PREU (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = NT, .uread = OK }
141#define TEST_OK_PREW (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = OK, .uread = NT }
142#define TEST_OK_PREWU (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = OK, .uread = OK }
143
144#define TEST_BAD_PROBE (struct tested){ .probe = BAD, .read = NT, .erase = NT, .write = NT, .uread = NT }
145#define TEST_BAD_PR (struct tested){ .probe = BAD, .read = BAD, .erase = NT, .write = NT, .uread = NT }
146#define TEST_BAD_PRE (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = NT, .uread = NT }
147#define TEST_BAD_PREW (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = BAD, .uread = NT }
148#define TEST_BAD_PREWU (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = BAD, .uread = BAD }
149
rminnich8d3ff912003-10-25 17:01:29 +0000150struct flashchip {
uwedfcd15f2008-03-14 23:55:58 +0000151 const char *vendor;
uwe6ed6d952007-12-04 21:49:06 +0000152 const char *name;
hailfinger40167462009-05-31 17:57:34 +0000153
154 enum chipbustype bustype;
155
uwefa98ca12008-10-18 21:14:13 +0000156 /*
157 * With 32bit manufacture_id and model_id we can cover IDs up to
hailfinger428f2012007-12-31 01:49:00 +0000158 * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's
159 * Identification code.
160 */
161 uint32_t manufacture_id;
162 uint32_t model_id;
rminnich8d3ff912003-10-25 17:01:29 +0000163
stefanct707f13b2011-05-19 02:58:17 +0000164 /* Total chip size in kilobytes */
stefanctc5eb8a92011-11-23 09:13:48 +0000165 unsigned int total_size;
stefanct707f13b2011-05-19 02:58:17 +0000166 /* Chip page size in bytes */
stefanctc5eb8a92011-11-23 09:13:48 +0000167 unsigned int page_size;
snelson63133f92010-01-04 17:15:23 +0000168 int feature_bits;
rminnich8d3ff912003-10-25 17:01:29 +0000169
Patrick Georgiac3423f2017-02-03 20:58:06 +0100170 /* Indicate how well flashrom supports different operations of this flash chip. */
171 struct tested {
172 enum test_state probe;
173 enum test_state read;
174 enum test_state erase;
175 enum test_state write;
176 enum test_state uread;
177 } tested;
stuge9cd64bd2008-05-03 04:34:37 +0000178
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700179 int (*probe) (struct flashctx *flash);
hailfingerd5b35922009-06-03 14:46:22 +0000180
stefanctc5eb8a92011-11-23 09:13:48 +0000181 /* Delay after "enter/exit ID mode" commands in microseconds.
182 * NB: negative values have special meanings, see TIMING_* below.
183 */
184 signed int probe_timing;
hailfinger7df21362009-09-05 02:30:58 +0000185
186 /*
hailfingerc4fac582009-12-22 13:04:53 +0000187 * Erase blocks and associated erase function. Any chip erase function
188 * is stored as chip-sized virtual block together with said function.
stefanct707f13b2011-05-19 02:58:17 +0000189 * The first one that fits will be chosen. There is currently no way to
190 * influence that behaviour. For testing just comment out the other
191 * elements or set the function pointer to NULL.
hailfinger7df21362009-09-05 02:30:58 +0000192 */
193 struct block_eraser {
Patrick Georgiac3423f2017-02-03 20:58:06 +0100194 struct eraseblock {
stefanct312d9ff2011-06-12 19:47:55 +0000195 unsigned int size; /* Eraseblock size in bytes */
hailfinger7df21362009-09-05 02:30:58 +0000196 unsigned int count; /* Number of contiguous blocks with that size */
197 } eraseblocks[NUM_ERASEREGIONS];
stefanct9e6b98a2011-05-28 02:37:14 +0000198 /* a block_erase function should try to erase one block of size
199 * 'blocklen' at address 'blockaddr' and return 0 on success. */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700200 int (*block_erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
hailfinger7df21362009-09-05 02:30:58 +0000201 } block_erasers[NUM_ERASEFUNCTIONS];
202
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700203 int (*printlock) (struct flashctx *flash);
204 int (*unlock) (struct flashctx *flash);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100205 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700206 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
207 uint8_t (*read_status) (const struct flashctx *flash);
208 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks8c084212015-11-17 22:29:36 -0800209 struct voltage_range voltage;
David Hendricksf7924d12010-06-10 21:26:44 -0700210 struct wp *wp;
rminnich8d3ff912003-10-25 17:01:29 +0000211};
212
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700213/* struct flashctx must always contain struct flashchip at the beginning. */
214struct flashctx {
Patrick Georgif3fa2992017-02-02 16:24:44 +0100215 struct flashchip *chip;
216
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700217 chipaddr virtual_memory;
218 /* Some flash devices have an additional register space. */
219 chipaddr virtual_registers;
220};
221
222
Simon Glass4c214132013-07-16 10:09:28 -0600223/* This is the byte value we expect to see in erased regions of the flash */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700224int flash_erase_value(struct flashctx *flash);
Simon Glass4c214132013-07-16 10:09:28 -0600225
226/* This is a byte value that indicates that the region is not erased */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700227int flash_unerased_value(struct flashctx *flash);
Simon Glass4c214132013-07-16 10:09:28 -0600228
David Hendricks40df5b52016-12-22 15:36:28 -0800229/* Given RDID info, return pointer to entry in flashchips[] */
230const struct flashchip *flash_id_to_entry(uint32_t mfg_id, uint32_t model_id);
231
hailfingerd5b35922009-06-03 14:46:22 +0000232/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
233 * field and zero delay.
Simon Glass8dc82732013-07-16 10:13:51 -0600234 *
hailfingerd5b35922009-06-03 14:46:22 +0000235 * SPI devices will always have zero delay and ignore this field.
236 */
237#define TIMING_FIXME -1
238/* this is intentionally same value as fixme */
239#define TIMING_IGNORED -1
240#define TIMING_ZERO -2
241
hailfinger48ed3e22011-05-04 00:39:50 +0000242extern const struct flashchip flashchips[];
Ramya Vijaykumare6a7ca82015-05-12 14:27:29 +0530243extern const struct flashchip flashchips_hwseq[];
ollie6a600992005-11-26 21:55:36 +0000244
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700245void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
246void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
247void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
248void chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
249uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr);
250uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr);
251uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr);
252void chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
253
uwe884cc8b2009-06-17 12:07:12 +0000254/* print.c */
255char *flashbuses_to_text(enum chipbustype bustype);
hailfingera50d60e2009-11-17 09:57:34 +0000256void print_supported(void);
hailfingera50d60e2009-11-17 09:57:34 +0000257void print_supported_wiki(void);
uwea3a82c92009-05-15 17:02:34 +0000258
uwe4529d202007-08-23 13:34:59 +0000259/* flashrom.c */
hailfingerb247c7a2010-03-08 00:42:32 +0000260enum write_granularity {
261 write_gran_1bit,
262 write_gran_1byte,
263 write_gran_256bytes,
264};
hailfinger80422e22009-12-13 22:28:00 +0000265extern enum chipbustype buses_supported;
Souvik Ghosh3c963a42016-07-19 18:48:15 -0700266extern int verbose_screen;
267extern int verbose_logfile;
krause2eb76212011-01-17 07:50:42 +0000268extern const char flashrom_version[];
hailfinger92cd8e32010-01-07 03:24:05 +0000269extern char *chip_to_probe;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700270void map_flash_registers(struct flashctx *flash);
271int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
272int erase_flash(struct flashctx *flash);
David Hendricksac1d25c2016-08-09 17:00:58 -0700273int probe_flash(int startchip, struct flashctx *fill_flash, int force);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700274int read_flash(struct flashctx *flash, uint8_t *buf,
David Hendrickse3451942013-03-21 17:23:29 -0700275 unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700276int read_flash_to_file(struct flashctx *flash, const char *filename);
hailfinger7b414742009-06-13 12:04:03 +0000277int min(int a, int b);
hailfinger7af83692009-06-15 17:23:36 +0000278int max(int a, int b);
hailfingerf76cc322010-11-09 22:00:31 +0000279void tolower_string(char *str);
stefanct52700282011-06-26 17:38:17 +0000280char *extract_param(char **haystack, const char *needle, const char *delim);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700281int verify_range(struct flashctx *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len, const char *message);
uwe884cc8b2009-06-17 12:07:12 +0000282char *strcat_realloc(char *dest, const char *src);
hailfinger92cd8e32010-01-07 03:24:05 +0000283void print_version(void);
Souvik Ghosh3c963a42016-07-19 18:48:15 -0700284void print_buildinfo(void);
hailfinger74819ad2010-05-15 15:04:37 +0000285void print_banner(void);
hailfingerf79d1712010-10-06 23:48:34 +0000286void list_programmers_linebreak(int startcol, int cols, int paren);
hailfinger92cd8e32010-01-07 03:24:05 +0000287int selfcheck(void);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700288int doit(struct flashctx *flash, int force, const char *filename, int read_it,
Simon Glass9ad06c12013-07-03 22:08:17 +0900289 int write_it, int erase_it, int verify_it, int extract_it,
290 const char *diff_file);
stefanct52700282011-06-26 17:38:17 +0000291int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename);
292int write_buf_to_file(unsigned char *buf, unsigned long size, const char *filename);
uwe884cc8b2009-06-17 12:07:12 +0000293
294#define OK 0
295#define NT 1 /* Not tested */
uwe4529d202007-08-23 13:34:59 +0000296
David Hendricks1ed1d352011-11-23 17:54:37 -0800297/* what to do in case of an error */
298enum error_action {
299 error_fail, /* fail immediately */
300 error_ignore, /* non-fatal error; continue */
301};
302
uwe97e8e272011-09-03 17:15:00 +0000303/* Something happened that shouldn't happen, but we can go on. */
mkarcher74d30132010-07-22 18:04:15 +0000304#define ERROR_NONFATAL 0x100
305
uwe97e8e272011-09-03 17:15:00 +0000306/* Something happened that shouldn't happen, we'll abort. */
307#define ERROR_FATAL -0xee
308
David Hendricks1ed1d352011-11-23 17:54:37 -0800309/* Operation failed due to access restriction set in programmer or flash chip */
310#define ACCESS_DENIED -7
311extern enum error_action access_denied_action;
312
313/* convenience function for checking return codes */
314extern int ignore_error(int x);
315
snelson9cba3c62010-01-07 20:09:33 +0000316/* cli_output.c */
Souvik Ghosh3c963a42016-07-19 18:48:15 -0700317#ifndef STANDALONE
318int open_logfile(const char * const filename);
319int close_logfile(void);
320void start_logging(void);
321#endif
Patrick Georgidbde2f12017-02-03 18:07:45 +0100322enum msglevel {
323 MSG_ERROR = 0,
324 MSG_WARN = 1,
325 MSG_INFO = 2,
326 MSG_DEBUG = 3,
327 MSG_DEBUG2 = 4,
328 MSG_SPEW = 5,
329};
hailfinger63932d42010-06-04 23:20:21 +0000330/* Let gcc and clang check for correct printf-style format strings. */
Patrick Georgidbde2f12017-02-03 18:07:45 +0100331int print(enum msglevel level, const char *fmt, ...)
332#ifdef __MINGW32__
333__attribute__((format(gnu_printf, 2, 3)));
334#else
335__attribute__((format(printf, 2, 3)));
336#endif
hailfingere7326b22010-01-09 03:22:31 +0000337#define msg_gerr(...) print(MSG_ERROR, __VA_ARGS__) /* general errors */
338#define msg_perr(...) print(MSG_ERROR, __VA_ARGS__) /* programmer errors */
339#define msg_cerr(...) print(MSG_ERROR, __VA_ARGS__) /* chip errors */
Patrick Georgidbde2f12017-02-03 18:07:45 +0100340#define msg_gwarn(...) print(MSG_WARN, __VA_ARGS__) /* general warnings */
341#define msg_pwarn(...) print(MSG_WARN, __VA_ARGS__) /* programmer warnings */
342#define msg_cwarn(...) print(MSG_WARN, __VA_ARGS__) /* chip warnings */
hailfingere7326b22010-01-09 03:22:31 +0000343#define msg_ginfo(...) print(MSG_INFO, __VA_ARGS__) /* general info */
344#define msg_pinfo(...) print(MSG_INFO, __VA_ARGS__) /* programmer info */
345#define msg_cinfo(...) print(MSG_INFO, __VA_ARGS__) /* chip info */
346#define msg_gdbg(...) print(MSG_DEBUG, __VA_ARGS__) /* general debug */
347#define msg_pdbg(...) print(MSG_DEBUG, __VA_ARGS__) /* programmer debug */
348#define msg_cdbg(...) print(MSG_DEBUG, __VA_ARGS__) /* chip debug */
stefanctee850532011-08-04 17:40:25 +0000349#define msg_gdbg2(...) print(MSG_DEBUG2, __VA_ARGS__) /* general debug2 */
350#define msg_pdbg2(...) print(MSG_DEBUG2, __VA_ARGS__) /* programmer debug2 */
351#define msg_cdbg2(...) print(MSG_DEBUG2, __VA_ARGS__) /* chip debug2 */
Patrick Georgidbde2f12017-02-03 18:07:45 +0100352#define msg_gspew(...) print(MSG_SPEW, __VA_ARGS__) /* general debug spew */
353#define msg_pspew(...) print(MSG_SPEW, __VA_ARGS__) /* programmer debug spew */
354#define msg_cspew(...) print(MSG_SPEW, __VA_ARGS__) /* chip debug spew */
snelson9cba3c62010-01-07 20:09:33 +0000355
stepan745615e2007-10-15 21:44:47 +0000356/* spi.c */
hailfinger68002c22009-07-10 21:08:55 +0000357struct spi_command {
358 unsigned int writecnt;
359 unsigned int readcnt;
360 const unsigned char *writearr;
361 unsigned char *readarr;
362};
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700363int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
uwefa98ca12008-10-18 21:14:13 +0000364 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700365int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
366uint32_t spi_get_valid_read_addr(struct flashctx *flash);
uweaf9b4df2008-09-26 13:19:02 +0000367
David Hendricks8c084212015-11-17 22:29:36 -0800368#define NUM_VOLTAGE_RANGES 16
369extern struct voltage_range voltage_ranges[];
370/* returns number of unique voltage ranges, or <0 to indicate failure */
371extern int flash_supported_voltage_ranges(enum chipbustype bus);
372
ollie5b621572004-03-20 16:46:10 +0000373#endif /* !__FLASH_H__ */