blob: 571c6198dfcc9d6491bb7ba1d4204b103194aff7 [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
dhendrix0ffc2eb2011-06-14 01:35:36 +000068int 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)
snelson63133f92010-01-04 17:15:23 +0000118
Simon Glass4c214132013-07-16 10:09:28 -0600119/* Erasing flash produces zeroes rather than ones */
120#define FEATURE_ERASE_TO_ZERO (1 << 8)
Duncan Laurie06ffd522015-10-26 12:56:08 -0700121#define FEATURE_UNBOUND_READ (1 << 10)
Simon Glass4c214132013-07-16 10:09:28 -0600122
David Hendricks8c084212015-11-17 22:29:36 -0800123struct voltage_range {
124 uint16_t min, max;
125};
126
rminnich8d3ff912003-10-25 17:01:29 +0000127struct flashchip {
uwedfcd15f2008-03-14 23:55:58 +0000128 const char *vendor;
uwe6ed6d952007-12-04 21:49:06 +0000129 const char *name;
hailfinger40167462009-05-31 17:57:34 +0000130
131 enum chipbustype bustype;
132
uwefa98ca12008-10-18 21:14:13 +0000133 /*
134 * With 32bit manufacture_id and model_id we can cover IDs up to
hailfinger428f2012007-12-31 01:49:00 +0000135 * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's
136 * Identification code.
137 */
138 uint32_t manufacture_id;
139 uint32_t model_id;
rminnich8d3ff912003-10-25 17:01:29 +0000140
stefanct707f13b2011-05-19 02:58:17 +0000141 /* Total chip size in kilobytes */
stefanctc5eb8a92011-11-23 09:13:48 +0000142 unsigned int total_size;
stefanct707f13b2011-05-19 02:58:17 +0000143 /* Chip page size in bytes */
stefanctc5eb8a92011-11-23 09:13:48 +0000144 unsigned int page_size;
snelson63133f92010-01-04 17:15:23 +0000145 int feature_bits;
rminnich8d3ff912003-10-25 17:01:29 +0000146
uwefa98ca12008-10-18 21:14:13 +0000147 /*
148 * Indicate if flashrom has been tested with this flash chip and if
stuge9cd64bd2008-05-03 04:34:37 +0000149 * everything worked correctly.
150 */
151 uint32_t tested;
152
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700153 int (*probe) (struct flashctx *flash);
hailfingerd5b35922009-06-03 14:46:22 +0000154
stefanctc5eb8a92011-11-23 09:13:48 +0000155 /* Delay after "enter/exit ID mode" commands in microseconds.
156 * NB: negative values have special meanings, see TIMING_* below.
157 */
158 signed int probe_timing;
hailfinger7df21362009-09-05 02:30:58 +0000159
160 /*
hailfingerc4fac582009-12-22 13:04:53 +0000161 * Erase blocks and associated erase function. Any chip erase function
162 * is stored as chip-sized virtual block together with said function.
stefanct707f13b2011-05-19 02:58:17 +0000163 * The first one that fits will be chosen. There is currently no way to
164 * influence that behaviour. For testing just comment out the other
165 * elements or set the function pointer to NULL.
hailfinger7df21362009-09-05 02:30:58 +0000166 */
167 struct block_eraser {
168 struct eraseblock{
stefanct312d9ff2011-06-12 19:47:55 +0000169 unsigned int size; /* Eraseblock size in bytes */
hailfinger7df21362009-09-05 02:30:58 +0000170 unsigned int count; /* Number of contiguous blocks with that size */
171 } eraseblocks[NUM_ERASEREGIONS];
stefanct9e6b98a2011-05-28 02:37:14 +0000172 /* a block_erase function should try to erase one block of size
173 * 'blocklen' at address 'blockaddr' and return 0 on success. */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700174 int (*block_erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
hailfinger7df21362009-09-05 02:30:58 +0000175 } block_erasers[NUM_ERASEFUNCTIONS];
176
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700177 int (*printlock) (struct flashctx *flash);
178 int (*unlock) (struct flashctx *flash);
179 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
180 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
181 uint8_t (*read_status) (const struct flashctx *flash);
182 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks8c084212015-11-17 22:29:36 -0800183 struct voltage_range voltage;
David Hendricksf7924d12010-06-10 21:26:44 -0700184 struct wp *wp;
rminnich8d3ff912003-10-25 17:01:29 +0000185};
186
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700187/* struct flashctx must always contain struct flashchip at the beginning. */
188struct flashctx {
189 const char *vendor;
190 const char *name;
191 enum chipbustype bustype;
192 uint32_t manufacture_id;
193 uint32_t model_id;
194 int total_size;
195 int page_size;
196 int feature_bits;
197 uint32_t tested;
198 int (*probe) (struct flashctx *flash);
199 int probe_timing;
200 struct block_eraser block_erasers[NUM_ERASEFUNCTIONS];
201 int (*printlock) (struct flashctx *flash);
202 int (*unlock) (struct flashctx *flash);
203 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
204 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
205 uint8_t (*read_status) (const struct flashctx *flash);
206 int (*write_status) (const struct flashctx *flash, int status);
207 struct voltage_range voltage;
208 struct wp *wp;
209 /* struct flashchip ends here. */
210 chipaddr virtual_memory;
211 /* Some flash devices have an additional register space. */
212 chipaddr virtual_registers;
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700213 struct registered_programmer *pgm;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700214};
215
216
Simon Glass4c214132013-07-16 10:09:28 -0600217/* This is the byte value we expect to see in erased regions of the flash */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700218int flash_erase_value(struct flashctx *flash);
Simon Glass4c214132013-07-16 10:09:28 -0600219
220/* This is a byte value that indicates that the region is not erased */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700221int flash_unerased_value(struct flashctx *flash);
Simon Glass4c214132013-07-16 10:09:28 -0600222
stuge9cd64bd2008-05-03 04:34:37 +0000223#define TEST_UNTESTED 0
224
uwe4e204a22009-05-28 15:07:42 +0000225#define TEST_OK_PROBE (1 << 0)
226#define TEST_OK_READ (1 << 1)
227#define TEST_OK_ERASE (1 << 2)
228#define TEST_OK_WRITE (1 << 3)
Duncan Laurie06ffd522015-10-26 12:56:08 -0700229#define TEST_OK_UREAD (1 << 4)
uwe4e204a22009-05-28 15:07:42 +0000230#define TEST_OK_PR (TEST_OK_PROBE | TEST_OK_READ)
231#define TEST_OK_PRE (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE)
David Hendricks26746032015-11-23 19:58:22 -0800232#define TEST_OK_PREU (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_UREAD)
233#define TEST_OK_PRU (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_UREAD)
hailfinger80f48682009-09-23 22:01:33 +0000234#define TEST_OK_PRW (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_WRITE)
uwe4e204a22009-05-28 15:07:42 +0000235#define TEST_OK_PREW (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_WRITE)
Duncan Laurie06ffd522015-10-26 12:56:08 -0700236#define TEST_OK_PREWU (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_WRITE | TEST_OK_UREAD)
237#define TEST_OK_MASK 0x1f
stuge9cd64bd2008-05-03 04:34:37 +0000238
Duncan Laurie06ffd522015-10-26 12:56:08 -0700239#define TEST_BAD_PROBE (1 << 5)
240#define TEST_BAD_READ (1 << 6)
241#define TEST_BAD_ERASE (1 << 7)
242#define TEST_BAD_WRITE (1 << 8)
243#define TEST_BAD_UREAD (1 << 9)
uwe4e204a22009-05-28 15:07:42 +0000244#define TEST_BAD_PREW (TEST_BAD_PROBE | TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE)
Duncan Laurie06ffd522015-10-26 12:56:08 -0700245#define TEST_BAD_PREWU (TEST_BAD_PROBE | TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE | TEST_BAD_UREAD)
246#define TEST_BAD_MASK 0x3e0
stuge9cd64bd2008-05-03 04:34:37 +0000247
hailfingerd5b35922009-06-03 14:46:22 +0000248/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
249 * field and zero delay.
Simon Glass8dc82732013-07-16 10:13:51 -0600250 *
hailfingerd5b35922009-06-03 14:46:22 +0000251 * SPI devices will always have zero delay and ignore this field.
252 */
253#define TIMING_FIXME -1
254/* this is intentionally same value as fixme */
255#define TIMING_IGNORED -1
256#define TIMING_ZERO -2
257
hailfinger48ed3e22011-05-04 00:39:50 +0000258extern const struct flashchip flashchips[];
Ramya Vijaykumare6a7ca82015-05-12 14:27:29 +0530259extern const struct flashchip flashchips_hwseq[];
ollie6a600992005-11-26 21:55:36 +0000260
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700261void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
262void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
263void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
264void chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
265uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr);
266uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr);
267uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr);
268void chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
269
uwe884cc8b2009-06-17 12:07:12 +0000270/* print.c */
271char *flashbuses_to_text(enum chipbustype bustype);
hailfingera50d60e2009-11-17 09:57:34 +0000272void print_supported(void);
hailfingera50d60e2009-11-17 09:57:34 +0000273void print_supported_wiki(void);
uwea3a82c92009-05-15 17:02:34 +0000274
uwe4529d202007-08-23 13:34:59 +0000275/* flashrom.c */
hailfingerb247c7a2010-03-08 00:42:32 +0000276enum write_granularity {
277 write_gran_1bit,
278 write_gran_1byte,
279 write_gran_256bytes,
280};
hailfinger80422e22009-12-13 22:28:00 +0000281extern enum chipbustype buses_supported;
uwee06bcf82009-04-24 16:17:41 +0000282extern int verbose;
krause2eb76212011-01-17 07:50:42 +0000283extern const char flashrom_version[];
hailfinger92cd8e32010-01-07 03:24:05 +0000284extern char *chip_to_probe;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700285void map_flash_registers(struct flashctx *flash);
286int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
287int erase_flash(struct flashctx *flash);
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700288int probe_flash(struct registered_programmer *pgm, int startchip, struct flashctx *fill_flash, int force);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700289int read_flash(struct flashctx *flash, uint8_t *buf,
David Hendrickse3451942013-03-21 17:23:29 -0700290 unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700291int read_flash_to_file(struct flashctx *flash, const char *filename);
hailfinger7b414742009-06-13 12:04:03 +0000292int min(int a, int b);
hailfinger7af83692009-06-15 17:23:36 +0000293int max(int a, int b);
hailfingerf76cc322010-11-09 22:00:31 +0000294void tolower_string(char *str);
stefanct52700282011-06-26 17:38:17 +0000295char *extract_param(char **haystack, const char *needle, const char *delim);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700296int verify_range(struct flashctx *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len, const char *message);
uwe884cc8b2009-06-17 12:07:12 +0000297char *strcat_realloc(char *dest, const char *src);
hailfinger92cd8e32010-01-07 03:24:05 +0000298void print_version(void);
hailfinger74819ad2010-05-15 15:04:37 +0000299void print_banner(void);
hailfingerf79d1712010-10-06 23:48:34 +0000300void list_programmers_linebreak(int startcol, int cols, int paren);
hailfinger92cd8e32010-01-07 03:24:05 +0000301int selfcheck(void);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700302int doit(struct flashctx *flash, int force, const char *filename, int read_it,
Simon Glass9ad06c12013-07-03 22:08:17 +0900303 int write_it, int erase_it, int verify_it, int extract_it,
304 const char *diff_file);
stefanct52700282011-06-26 17:38:17 +0000305int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename);
306int write_buf_to_file(unsigned char *buf, unsigned long size, const char *filename);
uwe884cc8b2009-06-17 12:07:12 +0000307
308#define OK 0
309#define NT 1 /* Not tested */
uwe4529d202007-08-23 13:34:59 +0000310
David Hendricks1ed1d352011-11-23 17:54:37 -0800311/* what to do in case of an error */
312enum error_action {
313 error_fail, /* fail immediately */
314 error_ignore, /* non-fatal error; continue */
315};
316
uwe97e8e272011-09-03 17:15:00 +0000317/* Something happened that shouldn't happen, but we can go on. */
mkarcher74d30132010-07-22 18:04:15 +0000318#define ERROR_NONFATAL 0x100
319
uwe97e8e272011-09-03 17:15:00 +0000320/* Something happened that shouldn't happen, we'll abort. */
321#define ERROR_FATAL -0xee
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700322#define ERROR_FLASHROM_BUG -200
323/* We reached one of the hardcoded limits of flashrom. This can be fixed by
324 * increasing the limit of a compile-time allocation or by switching to dynamic
325 * allocation.
326 * Note: If this warning is triggered, check first for runaway registrations.
327 */
328#define ERROR_FLASHROM_LIMIT -201
uwe97e8e272011-09-03 17:15:00 +0000329
David Hendricks1ed1d352011-11-23 17:54:37 -0800330/* Operation failed due to access restriction set in programmer or flash chip */
331#define ACCESS_DENIED -7
332extern enum error_action access_denied_action;
333
334/* convenience function for checking return codes */
335extern int ignore_error(int x);
336
snelson9cba3c62010-01-07 20:09:33 +0000337/* cli_output.c */
hailfinger63932d42010-06-04 23:20:21 +0000338/* Let gcc and clang check for correct printf-style format strings. */
339int print(int type, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
hailfingere7326b22010-01-09 03:22:31 +0000340#define MSG_ERROR 0
341#define MSG_INFO 1
342#define MSG_DEBUG 2
stefanctee850532011-08-04 17:40:25 +0000343#define MSG_DEBUG2 3
344#define MSG_BARF 4
hailfingere7326b22010-01-09 03:22:31 +0000345#define msg_gerr(...) print(MSG_ERROR, __VA_ARGS__) /* general errors */
346#define msg_perr(...) print(MSG_ERROR, __VA_ARGS__) /* programmer errors */
347#define msg_cerr(...) print(MSG_ERROR, __VA_ARGS__) /* chip errors */
348#define msg_ginfo(...) print(MSG_INFO, __VA_ARGS__) /* general info */
349#define msg_pinfo(...) print(MSG_INFO, __VA_ARGS__) /* programmer info */
350#define msg_cinfo(...) print(MSG_INFO, __VA_ARGS__) /* chip info */
351#define msg_gdbg(...) print(MSG_DEBUG, __VA_ARGS__) /* general debug */
352#define msg_pdbg(...) print(MSG_DEBUG, __VA_ARGS__) /* programmer debug */
353#define msg_cdbg(...) print(MSG_DEBUG, __VA_ARGS__) /* chip debug */
stefanctee850532011-08-04 17:40:25 +0000354#define msg_gdbg2(...) print(MSG_DEBUG2, __VA_ARGS__) /* general debug2 */
355#define msg_pdbg2(...) print(MSG_DEBUG2, __VA_ARGS__) /* programmer debug2 */
356#define msg_cdbg2(...) print(MSG_DEBUG2, __VA_ARGS__) /* chip debug2 */
hailfingere7326b22010-01-09 03:22:31 +0000357#define msg_gspew(...) print(MSG_BARF, __VA_ARGS__) /* general debug barf */
358#define msg_pspew(...) print(MSG_BARF, __VA_ARGS__) /* programmer debug barf */
359#define msg_cspew(...) print(MSG_BARF, __VA_ARGS__) /* chip debug barf */
snelson9cba3c62010-01-07 20:09:33 +0000360
Louis Yung-Chieh Lo1f6bbf52011-04-06 10:24:38 +0800361/* cli_mfg.c */
362extern int set_ignore_fmap;
hailfinger92cd8e32010-01-07 03:24:05 +0000363
uwe4529d202007-08-23 13:34:59 +0000364/* layout.c */
Louis Yung-Chieh Lo5d95f042011-09-01 17:33:06 +0800365int specified_partition();
uwe4529d202007-08-23 13:34:59 +0000366int read_romlayout(char *name);
367int find_romentry(char *name);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700368int handle_romentries(struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents);
369int add_fmap_entries(struct flashctx *flash);
Louis Yung-Chieh Lobb9049c2011-05-10 16:06:28 +0800370int get_num_include_args(void);
David Hendricksd0ea9ed2011-03-04 17:31:57 -0800371int register_include_arg(char *name);
372int process_include_args(void);
David Hendricksdf29a832013-06-28 14:33:51 -0700373int num_include_files(void);
374int included_regions_overlap(void);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700375int handle_romentries(struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents);
Louis Yung-Chieh Lo9c7525f2011-03-04 12:32:02 +0800376int handle_partial_read(
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700377 struct flashctx *flash,
Louis Yung-Chieh Lo9c7525f2011-03-04 12:32:02 +0800378 uint8_t *buf,
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700379 int (*read) (struct flashctx *flash, uint8_t *buf,
David Hendricksbec6e0c2011-11-23 16:40:04 -0800380 unsigned int start, unsigned int len),
381 int write_to_file);
Louis Yung-Chieh Lo9c7525f2011-03-04 12:32:02 +0800382 /* RETURN: the number of partitions that have beenpartial read.
383 * ==0 means no partition is specified.
384 * < 0 means writing file error. */
Louis Yung-Chieh Lo5d95f042011-09-01 17:33:06 +0800385int handle_partial_verify(
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700386 struct flashctx *flash,
Louis Yung-Chieh Lo5d95f042011-09-01 17:33:06 +0800387 uint8_t *buf,
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700388 int (*verify) (struct flashctx *flash, uint8_t *buf, unsigned int start,
David Hendricksbec6e0c2011-11-23 16:40:04 -0800389 unsigned int len, const char* message));
Louis Yung-Chieh Lo5d95f042011-09-01 17:33:06 +0800390 /* RETURN: ==0 means all identical.
391 !=0 means buf and flash are different. */
uwe4529d202007-08-23 13:34:59 +0000392
stepan745615e2007-10-15 21:44:47 +0000393/* spi.c */
hailfinger68002c22009-07-10 21:08:55 +0000394struct spi_command {
395 unsigned int writecnt;
396 unsigned int readcnt;
397 const unsigned char *writearr;
398 unsigned char *readarr;
399};
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700400int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
uwefa98ca12008-10-18 21:14:13 +0000401 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700402int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
403uint32_t spi_get_valid_read_addr(struct flashctx *flash);
uweaf9b4df2008-09-26 13:19:02 +0000404
David Hendricks8c084212015-11-17 22:29:36 -0800405#define NUM_VOLTAGE_RANGES 16
406extern struct voltage_range voltage_ranges[];
407/* returns number of unique voltage ranges, or <0 to indicate failure */
408extern int flash_supported_voltage_ranges(enum chipbustype bus);
409
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700410enum chipbustype get_buses_supported(void);
ollie5b621572004-03-20 16:46:10 +0000411#endif /* !__FLASH_H__ */