flash.h 23.9 KB
Newer Older
1
/*
2
 * This file is part of the flashrom project.
3
 *
4 5
 * Copyright (C) 2000 Silicon Integrated System Corporation
 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
6
 * Copyright (C) 2005-2009 coresystems GmbH
7
 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
8
 *
9 10 11 12
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
13
 *
14 15 16 17
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
18
 *
19 20 21
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22 23
 */

Ronald G. Minnich's avatar
Ronald G. Minnich committed
24 25 26
#ifndef __FLASH_H__
#define __FLASH_H__ 1

27
#include <stdint.h>
28
#include <stddef.h>
29
#include "hwaccess.h"
Patrick Georgi's avatar
Patrick Georgi committed
30 31 32 33 34
#ifdef _WIN32
#include <windows.h>
#undef min
#undef max
#endif
35

36 37
typedef unsigned long chipaddr;

38
enum programmer {
39
#if CONFIG_INTERNAL == 1
40
	PROGRAMMER_INTERNAL,
41
#endif
42
#if CONFIG_DUMMY == 1
43
	PROGRAMMER_DUMMY,
44
#endif
45
#if CONFIG_NIC3COM == 1
46
	PROGRAMMER_NIC3COM,
47
#endif
48
#if CONFIG_NICREALTEK == 1
49 50 51
	PROGRAMMER_NICREALTEK,
	PROGRAMMER_NICREALTEK2,
#endif	
52 53 54
#if CONFIG_NICNATSEMI == 1
	PROGRAMMER_NICNATSEMI,
#endif	
55
#if CONFIG_GFXNVIDIA == 1
56 57
	PROGRAMMER_GFXNVIDIA,
#endif
58
#if CONFIG_DRKAISER == 1
59
	PROGRAMMER_DRKAISER,
60
#endif
61
#if CONFIG_SATASII == 1
62
	PROGRAMMER_SATASII,
63
#endif
64
#if CONFIG_ATAHPT == 1
65 66
	PROGRAMMER_ATAHPT,
#endif
67
#if CONFIG_INTERNAL == 1
68
#if defined(__i386__) || defined(__x86_64__)
69
	PROGRAMMER_IT87SPI,
70
#endif
71
#endif
72 73
#if CONFIG_FT2232_SPI == 1
	PROGRAMMER_FT2232_SPI,
74
#endif
75
#if CONFIG_SERPROG == 1
76
	PROGRAMMER_SERPROG,
77
#endif
78 79
#if CONFIG_BUSPIRATE_SPI == 1
	PROGRAMMER_BUSPIRATE_SPI,
80
#endif
81
#if CONFIG_DEDIPROG == 1
82
	PROGRAMMER_DEDIPROG,
83 84 85
#endif
#if CONFIG_RAYER_SPI == 1
	PROGRAMMER_RAYER_SPI,
86
#endif
87
	PROGRAMMER_INVALID /* This must always be the last entry. */
88 89 90
};

extern enum programmer programmer;
91 92 93 94 95 96 97 98

struct programmer_entry {
	const char *vendor;
	const char *name;

	int (*init) (void);
	int (*shutdown) (void);

Uwe Hermann's avatar
Uwe Hermann committed
99 100
	void * (*map_flash_region) (const char *descr, unsigned long phys_addr,
				    size_t len);
101 102
	void (*unmap_flash_region) (void *virt_addr, size_t len);

103 104 105
	void (*chip_writeb) (uint8_t val, chipaddr addr);
	void (*chip_writew) (uint16_t val, chipaddr addr);
	void (*chip_writel) (uint32_t val, chipaddr addr);
106
	void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
107 108 109
	uint8_t (*chip_readb) (const chipaddr addr);
	uint16_t (*chip_readw) (const chipaddr addr);
	uint32_t (*chip_readl) (const chipaddr addr);
110
	void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
111
	void (*delay) (int usecs);
112 113 114 115
};

extern const struct programmer_entry programmer_table[];

116 117
int register_shutdown(void (*function) (void *data), void *data);

118
int programmer_init(char *param);
119 120 121 122 123 124 125
int programmer_shutdown(void);
void *programmer_map_flash_region(const char *descr, unsigned long phys_addr,
				  size_t len);
void programmer_unmap_flash_region(void *virt_addr, size_t len);
void chip_writeb(uint8_t val, chipaddr addr);
void chip_writew(uint16_t val, chipaddr addr);
void chip_writel(uint32_t val, chipaddr addr);
126
void chip_writen(uint8_t *buf, chipaddr addr, size_t len);
127 128 129
uint8_t chip_readb(const chipaddr addr);
uint16_t chip_readw(const chipaddr addr);
uint32_t chip_readl(const chipaddr addr);
130
void chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
131
void programmer_delay(int usecs);
132

133
enum bitbang_spi_master_type {
134
	BITBANG_SPI_INVALID	= 0, /* This must always be the first entry. */
135 136 137
#if CONFIG_RAYER_SPI == 1
	BITBANG_SPI_MASTER_RAYER,
#endif
138 139
};

140 141
struct bitbang_spi_master {
	enum bitbang_spi_master_type type;
142

143
	/* Note that CS# is active low, so val=0 means the chip is active. */
144 145 146 147 148 149
	void (*set_cs) (int val);
	void (*set_sck) (int val);
	void (*set_mosi) (int val);
	int (*get_miso) (void);
};

150 151
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

152
enum chipbustype {
153
	CHIP_BUSTYPE_NONE	= 0,
154 155 156 157 158 159 160 161
	CHIP_BUSTYPE_PARALLEL	= 1 << 0,
	CHIP_BUSTYPE_LPC	= 1 << 1,
	CHIP_BUSTYPE_FWH	= 1 << 2,
	CHIP_BUSTYPE_SPI	= 1 << 3,
	CHIP_BUSTYPE_NONSPI	= CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH,
	CHIP_BUSTYPE_UNKNOWN	= CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI,
};

162 163 164 165 166 167 168 169 170 171 172
/*
 * How many different contiguous runs of erase blocks with one size each do
 * we have for a given erase function?
 */
#define NUM_ERASEREGIONS 5

/*
 * How many different erase functions do we have per chip?
 */
#define NUM_ERASEFUNCTIONS 5

173 174
#define FEATURE_REGISTERMAP	(1 << 0)
#define FEATURE_BYTEWRITES	(1 << 1)
175 176 177
#define FEATURE_LONG_RESET	(0 << 4)
#define FEATURE_SHORT_RESET	(1 << 4)
#define FEATURE_EITHER_RESET	FEATURE_LONG_RESET
178 179
#define FEATURE_ADDR_FULL	(0 << 2)
#define FEATURE_ADDR_MASK	(3 << 2)
180 181
#define FEATURE_ADDR_2AA	(1 << 2)
#define FEATURE_ADDR_AAA	(2 << 2)
Michael Karcher's avatar
Michael Karcher committed
182
#define FEATURE_ADDR_SHIFTED	(1 << 5)
183

184
struct flashchip {
185
	const char *vendor;
186
	const char *name;
187 188 189

	enum chipbustype bustype;

190 191
	/*
	 * With 32bit manufacture_id and model_id we can cover IDs up to
192 193 194 195 196
	 * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's
	 * Identification code.
	 */
	uint32_t manufacture_id;
	uint32_t model_id;
197 198 199

	int total_size;
	int page_size;
200
	int feature_bits;
201

202 203
	/*
	 * Indicate if flashrom has been tested with this flash chip and if
204 205 206 207
	 * everything worked correctly.
	 */
	uint32_t tested;

Uwe Hermann's avatar
Uwe Hermann committed
208
	int (*probe) (struct flashchip *flash);
209 210 211

	/* Delay after "enter/exit ID mode" commands in microseconds. */
	int probe_timing;
212 213

	/*
214 215
	 * Erase blocks and associated erase function. Any chip erase function
	 * is stored as chip-sized virtual block together with said function.
216 217 218 219 220 221 222 223 224
	 */
	struct block_eraser {
		struct eraseblock{
			unsigned int size; /* Eraseblock size */
			unsigned int count; /* Number of contiguous blocks with that size */
		} eraseblocks[NUM_ERASEREGIONS];
		int (*block_erase) (struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen);
	} block_erasers[NUM_ERASEFUNCTIONS];

225 226
	int (*printlock) (struct flashchip *flash);
	int (*unlock) (struct flashchip *flash);
Uwe Hermann's avatar
Uwe Hermann committed
227
	int (*write) (struct flashchip *flash, uint8_t *buf);
228
	int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len);
Ronald G. Minnich's avatar
Ronald G. Minnich committed
229

230
	/* Some flash devices have an additional register space. */
231 232
	chipaddr virtual_memory;
	chipaddr virtual_registers;
233 234
};

235 236
#define TEST_UNTESTED	0

Uwe Hermann's avatar
Uwe Hermann committed
237 238 239 240 241 242
#define TEST_OK_PROBE	(1 << 0)
#define TEST_OK_READ	(1 << 1)
#define TEST_OK_ERASE	(1 << 2)
#define TEST_OK_WRITE	(1 << 3)
#define TEST_OK_PR	(TEST_OK_PROBE | TEST_OK_READ)
#define TEST_OK_PRE	(TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE)
243
#define TEST_OK_PRW	(TEST_OK_PROBE | TEST_OK_READ | TEST_OK_WRITE)
Uwe Hermann's avatar
Uwe Hermann committed
244
#define TEST_OK_PREW	(TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_WRITE)
245 246
#define TEST_OK_MASK	0x0f

Uwe Hermann's avatar
Uwe Hermann committed
247 248 249 250 251
#define TEST_BAD_PROBE	(1 << 4)
#define TEST_BAD_READ	(1 << 5)
#define TEST_BAD_ERASE	(1 << 6)
#define TEST_BAD_WRITE	(1 << 7)
#define TEST_BAD_PREW	(TEST_BAD_PROBE | TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE)
252 253
#define TEST_BAD_MASK	0xf0

254 255 256 257 258 259 260 261 262 263
/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
 * field and zero delay.
 * 
 * SPI devices will always have zero delay and ignore this field.
 */
#define TIMING_FIXME	-1
/* this is intentionally same value as fixme */
#define TIMING_IGNORED	-1
#define TIMING_ZERO	-2

264 265
extern struct flashchip flashchips[];

266
#if CONFIG_INTERNAL == 1
Uwe Hermann's avatar
Uwe Hermann committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
struct penable {
	uint16_t vendor_id;
	uint16_t device_id;
	int status;
	const char *vendor_name;
	const char *device_name;
	int (*doit) (struct pci_dev *dev, const char *name);
};

extern const struct penable chipset_enables[];

struct board_pciid_enable {
	/* Any device, but make it sensible, like the ISA bridge. */
	uint16_t first_vendor;
	uint16_t first_device;
	uint16_t first_card_vendor;
	uint16_t first_card_device;

	/* Any device, but make it sensible, like
	 * the host bridge. May be NULL.
	 */
	uint16_t second_vendor;
	uint16_t second_device;
	uint16_t second_card_vendor;
	uint16_t second_card_device;

Michael Karcher's avatar
Michael Karcher committed
293 294 295
	/* Pattern to match DMI entries */
	const char *dmi_pattern;

Uwe Hermann's avatar
Uwe Hermann committed
296 297 298 299 300 301 302
	/* The vendor / part name from the coreboot table. */
	const char *lb_vendor;
	const char *lb_part;

	const char *vendor_name;
	const char *board_name;

303
	int max_rom_decode_parallel;
304
	int status;
305
	int (*enable) (void);
Uwe Hermann's avatar
Uwe Hermann committed
306 307
};

308
extern const struct board_pciid_enable board_pciid_enables[];
Uwe Hermann's avatar
Uwe Hermann committed
309 310 311 312

struct board_info {
	const char *vendor;
	const char *name;
313 314 315 316 317
	const int working;
#ifdef CONFIG_PRINT_WIKI
	const char *url;
	const char *note;
#endif
Uwe Hermann's avatar
Uwe Hermann committed
318 319
};

320 321 322
extern const struct board_info boards_known[];
extern const struct board_info laptops_known[];

323
#endif
Uwe Hermann's avatar
Uwe Hermann committed
324

325
/* udelay.c */
326
void myusec_delay(int usecs);
327
void myusec_calibrate_delay(void);
328
void internal_delay(int usecs);
329

330
#if NEED_PCI == 1
331
/* pcidev.c */
332

333 334
extern uint32_t io_base_addr;
extern struct pci_access *pacc;
335
extern struct pci_dev *pcidev_dev;
336 337 338 339 340 341 342
struct pcidev_status {
	uint16_t vendor_id;
	uint16_t device_id;
	int status;
	const char *vendor_name;
	const char *device_name;
};
343
uint32_t pcidev_validate(struct pci_dev *dev, uint32_t bar, const struct pcidev_status *devs);
344
uint32_t pcidev_init(uint16_t vendor_id, uint32_t bar, const struct pcidev_status *devs);
345
#endif
346 347 348

/* print.c */
char *flashbuses_to_text(enum chipbustype bustype);
349
void print_supported(void);
350
#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT >= 1
351
void print_supported_pcidevs(const struct pcidev_status *devs);
352
#endif
353
void print_supported_wiki(void);
354

355
/* board_enable.c */
356 357
void w836xx_ext_enter(uint16_t port);
void w836xx_ext_leave(uint16_t port);
358
int it8705f_write_enable(uint8_t port);
359 360 361
uint8_t sio_read(uint16_t port, uint8_t reg);
void sio_write(uint16_t port, uint8_t reg, uint8_t data);
void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
362
int board_flash_enable(const char *vendor, const char *part);
363

364 365
/* chipset_enable.c */
int chipset_flash_enable(void);
366

367 368 369
/* processor_enable.c */
int processor_flash_enable(void);

370 371
/* physmap.c */
void *physmap(const char *descr, unsigned long phys_addr, size_t len);
372
void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
373
void physunmap(void *virt_addr, size_t len);
374 375
int setup_cpu_msr(int cpu);
void cleanup_cpu_msr(void);
376 377 378 379 380 381

/* cbtable.c */
void lb_vendor_dev_from_string(char *boardstring);
int coreboot_init(void);
extern char *lb_part, *lb_vendor;
extern int partvendor_from_cbtable;
382

Michael Karcher's avatar
Michael Karcher committed
383 384 385 386 387
/* dmi.c */
extern int has_dmi_support;
void dmi_init(void);
int dmi_match(const char *pattern);

388
/* internal.c */
389
#if NEED_PCI == 1
390 391 392 393 394 395 396 397
struct superio {
	uint16_t vendor;
	uint16_t port;
	uint16_t model;
};
extern struct superio superio;
#define SUPERIO_VENDOR_NONE	0x0
#define SUPERIO_VENDOR_ITE	0x1
398
struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
399
struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t class);
400 401 402
struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
			      uint16_t card_vendor, uint16_t card_device);
403
#endif
404
void get_io_perms(void);
405
void release_io_perms(void);
406
#if CONFIG_INTERNAL == 1
Michael Karcher's avatar
Michael Karcher committed
407
extern int is_laptop;
408
extern int force_boardenable;
409
extern int force_boardmismatch;
410
void probe_superio(void);
411 412
int internal_init(void);
int internal_shutdown(void);
413 414 415 416 417 418
void internal_chip_writeb(uint8_t val, chipaddr addr);
void internal_chip_writew(uint16_t val, chipaddr addr);
void internal_chip_writel(uint32_t val, chipaddr addr);
uint8_t internal_chip_readb(const chipaddr addr);
uint16_t internal_chip_readw(const chipaddr addr);
uint32_t internal_chip_readl(const chipaddr addr);
419
void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
420
#endif
421 422 423 424 425 426
void mmio_writeb(uint8_t val, void *addr);
void mmio_writew(uint16_t val, void *addr);
void mmio_writel(uint32_t val, void *addr);
uint8_t mmio_readb(void *addr);
uint16_t mmio_readw(void *addr);
uint32_t mmio_readl(void *addr);
427 428 429 430 431 432
void mmio_le_writeb(uint8_t val, void *addr);
void mmio_le_writew(uint16_t val, void *addr);
void mmio_le_writel(uint32_t val, void *addr);
uint8_t mmio_le_readb(void *addr);
uint16_t mmio_le_readw(void *addr);
uint32_t mmio_le_readl(void *addr);
433 434

/* programmer.c */
435
int noop_shutdown(void);
436 437
void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
void fallback_unmap(void *virt_addr, size_t len);
438 439
uint8_t noop_chip_readb(const chipaddr addr);
void noop_chip_writeb(uint8_t val, chipaddr addr);
440 441
void fallback_chip_writew(uint16_t val, chipaddr addr);
void fallback_chip_writel(uint32_t val, chipaddr addr);
442
void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
443 444
uint16_t fallback_chip_readw(const chipaddr addr);
uint32_t fallback_chip_readl(const chipaddr addr);
445
void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
446

447
/* dummyflasher.c */
448
#if CONFIG_DUMMY == 1
449 450
int dummy_init(void);
int dummy_shutdown(void);
451 452
void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
void dummy_unmap(void *virt_addr, size_t len);
453 454 455
void dummy_chip_writeb(uint8_t val, chipaddr addr);
void dummy_chip_writew(uint16_t val, chipaddr addr);
void dummy_chip_writel(uint32_t val, chipaddr addr);
456
void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
457 458 459
uint8_t dummy_chip_readb(const chipaddr addr);
uint16_t dummy_chip_readw(const chipaddr addr);
uint32_t dummy_chip_readl(const chipaddr addr);
460
void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
461
int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
462
		      const unsigned char *writearr, unsigned char *readarr);
463
int dummy_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
464
int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
465
#endif
466

467
/* nic3com.c */
468
#if CONFIG_NIC3COM == 1
469 470
int nic3com_init(void);
int nic3com_shutdown(void);
471 472
void nic3com_chip_writeb(uint8_t val, chipaddr addr);
uint8_t nic3com_chip_readb(const chipaddr addr);
473
extern const struct pcidev_status nics_3com[];
474
#endif
475

476
/* gfxnvidia.c */
477
#if CONFIG_GFXNVIDIA == 1
478 479 480 481
int gfxnvidia_init(void);
int gfxnvidia_shutdown(void);
void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr);
uint8_t gfxnvidia_chip_readb(const chipaddr addr);
482
extern const struct pcidev_status gfx_nvidia[];
483
#endif
484

485
/* drkaiser.c */
486
#if CONFIG_DRKAISER == 1
487 488 489 490
int drkaiser_init(void);
int drkaiser_shutdown(void);
void drkaiser_chip_writeb(uint8_t val, chipaddr addr);
uint8_t drkaiser_chip_readb(const chipaddr addr);
491
extern const struct pcidev_status drkaiser_pcidev[];
492
#endif
493

494
/* nicrealtek.c */
495
#if CONFIG_NICREALTEK == 1
496 497 498 499 500
int nicrealtek_init(void);
int nicsmc1211_init(void);
int nicrealtek_shutdown(void);
void nicrealtek_chip_writeb(uint8_t val, chipaddr addr);
uint8_t nicrealtek_chip_readb(const chipaddr addr);
501 502
extern const struct pcidev_status nics_realtek[];
extern const struct pcidev_status nics_realteksmc1211[];
503 504
#endif

505 506 507 508 509 510
/* nicnatsemi.c */
#if CONFIG_NICNATSEMI == 1
int nicnatsemi_init(void);
int nicnatsemi_shutdown(void);
void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr);
uint8_t nicnatsemi_chip_readb(const chipaddr addr);
511
extern const struct pcidev_status nics_natsemi[];
512
#endif
513

514
/* satasii.c */
515
#if CONFIG_SATASII == 1
516 517 518 519
int satasii_init(void);
int satasii_shutdown(void);
void satasii_chip_writeb(uint8_t val, chipaddr addr);
uint8_t satasii_chip_readb(const chipaddr addr);
520
extern const struct pcidev_status satas_sii[];
521
#endif
522

523
/* atahpt.c */
524
#if CONFIG_ATAHPT == 1
525 526 527 528
int atahpt_init(void);
int atahpt_shutdown(void);
void atahpt_chip_writeb(uint8_t val, chipaddr addr);
uint8_t atahpt_chip_readb(const chipaddr addr);
529
extern const struct pcidev_status ata_hpt[];
530 531
#endif

532
/* ft2232_spi.c */
533 534
#define FTDI_FT2232H 0x6010
#define FTDI_FT4232H 0x6011
535
int ft2232_spi_init(void);
536
int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
537
int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
538
int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
539

540 541 542 543 544
/* rayer_spi.c */
#if CONFIG_RAYER_SPI == 1
int rayer_spi_init(void);
#endif

545
/* bitbang_spi.c */
546
int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
547 548
int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
int bitbang_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
549
int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
550

551
/* buspirate_spi.c */
552 553 554 555
struct buspirate_spispeeds {
	const char *name;
	const int speed;
};
556 557 558 559
int buspirate_spi_init(void);
int buspirate_spi_shutdown(void);
int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
560
int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
561

562 563 564 565 566 567
/* dediprog.c */
int dediprog_init(void);
int dediprog_shutdown(void);
int dediprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);

568
/* flashrom.c */
569 570 571 572 573
enum write_granularity {
	write_gran_1bit,
	write_gran_1byte,
	write_gran_256bytes,
};
574 575 576 577 578 579 580 581
extern enum chipbustype buses_supported;
struct decode_sizes {
	uint32_t parallel;
	uint32_t lpc;
	uint32_t fwh;
	uint32_t spi;
};
extern struct decode_sizes max_rom_decode;
582
extern int programmer_may_write;
583
extern unsigned long flashbase;
Uwe Hermann's avatar
Uwe Hermann committed
584
extern int verbose;
585
extern const char * const flashrom_version;
586
extern char *chip_to_probe;
587
void map_flash_registers(struct flashchip *flash);
588
int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
589
int erase_flash(struct flashchip *flash);
590
struct flashchip *probe_flash(struct flashchip *first_flash, int force);
591
int read_flash_to_file(struct flashchip *flash, char *filename);
592 593
void check_chip_supported(struct flashchip *flash);
int check_max_decode(enum chipbustype buses, uint32_t size);
594
int min(int a, int b);
595
int max(int a, int b);
596
char *extract_param(char **haystack, char *needle, char *delim);
597
char *extract_programmer_param(char *param_name);
598 599
int check_erased_range(struct flashchip *flash, int start, int len);
int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message);
600
int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gran);
601
char *strcat_realloc(char *dest, const char *src);
602
void print_version(void);
603
void print_banner(void);
604
int selfcheck(void);
605
int doit(struct flashchip *flash, int force, char *filename, int read_it, int write_it, int erase_it, int verify_it);
606 607 608

#define OK 0
#define NT 1    /* Not tested */
609

610
/* cli_output.c */
611 612
/* Let gcc and clang check for correct printf-style format strings. */
int print(int type, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
#define MSG_ERROR	0
#define MSG_INFO	1
#define MSG_DEBUG	2
#define MSG_BARF	3
#define msg_gerr(...)	print(MSG_ERROR, __VA_ARGS__)	/* general errors */
#define msg_perr(...)	print(MSG_ERROR, __VA_ARGS__)	/* programmer errors */
#define msg_cerr(...)	print(MSG_ERROR, __VA_ARGS__)	/* chip errors */
#define msg_ginfo(...)	print(MSG_INFO, __VA_ARGS__)	/* general info */
#define msg_pinfo(...)	print(MSG_INFO, __VA_ARGS__)	/* programmer info */
#define msg_cinfo(...)	print(MSG_INFO, __VA_ARGS__)	/* chip info */
#define msg_gdbg(...)	print(MSG_DEBUG, __VA_ARGS__)	/* general debug */
#define msg_pdbg(...)	print(MSG_DEBUG, __VA_ARGS__)	/* programmer debug */
#define msg_cdbg(...)	print(MSG_DEBUG, __VA_ARGS__)	/* chip debug */
#define msg_gspew(...)	print(MSG_BARF, __VA_ARGS__)	/* general debug barf  */
#define msg_pspew(...)	print(MSG_BARF, __VA_ARGS__)	/* programmer debug barf  */
#define msg_cspew(...)	print(MSG_BARF, __VA_ARGS__)	/* chip debug barf  */
629

630 631 632
/* cli_classic.c */
int cli_classic(int argc, char *argv[]);

633
/* layout.c */
Peter Stuge's avatar
Peter Stuge committed
634
int show_id(uint8_t *bios, int size, int force);
635 636
int read_romlayout(char *name);
int find_romentry(char *name);
637
int handle_romentries(uint8_t *buffer, struct flashchip *flash);
638

639
/* spi.c */
640 641
enum spi_controller {
	SPI_CONTROLLER_NONE,
642
#if CONFIG_INTERNAL == 1
643
#if defined(__i386__) || defined(__x86_64__)
644 645 646 647 648 649
	SPI_CONTROLLER_ICH7,
	SPI_CONTROLLER_ICH9,
	SPI_CONTROLLER_IT87XX,
	SPI_CONTROLLER_SB600,
	SPI_CONTROLLER_VIA,
	SPI_CONTROLLER_WBSIO,
650
#endif
651
#endif
652
#if CONFIG_FT2232_SPI == 1
653
	SPI_CONTROLLER_FT2232,
654
#endif
655
#if CONFIG_DUMMY == 1
656
	SPI_CONTROLLER_DUMMY,
657
#endif
658
#if CONFIG_BUSPIRATE_SPI == 1
659
	SPI_CONTROLLER_BUSPIRATE,
660
#endif
661
#if CONFIG_DEDIPROG == 1
662
	SPI_CONTROLLER_DEDIPROG,
663 664 665
#endif
#if CONFIG_RAYER_SPI == 1
	SPI_CONTROLLER_RAYER,
666
#endif
667
	SPI_CONTROLLER_INVALID /* This must always be the last entry. */
668
};
669
extern const int spi_programmer_count;
670 671 672 673 674 675
struct spi_command {
	unsigned int writecnt;
	unsigned int readcnt;
	const unsigned char *writearr;
	unsigned char *readarr;
};
676 677 678
struct spi_programmer {
	int (*command)(unsigned int writecnt, unsigned int readcnt,
		   const unsigned char *writearr, unsigned char *readarr);
679
	int (*multicommand)(struct spi_command *cmds);
680 681 682

	/* Optimized functions for this programmer */
	int (*read)(struct flashchip *flash, uint8_t *buf, int start, int len);
683
	int (*write_256)(struct flashchip *flash, uint8_t *buf, int start, int len);
684
};
685

686
extern enum spi_controller spi_controller;
687
extern const struct spi_programmer spi_programmer[];
688
int spi_send_command(unsigned int writecnt, unsigned int readcnt,
689
		const unsigned char *writearr, unsigned char *readarr);
690
int spi_send_multicommand(struct spi_command *cmds);
691 692
int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
			     const unsigned char *writearr, unsigned char *readarr);
693
int default_spi_send_multicommand(struct spi_command *cmds);
694
uint32_t spi_get_valid_read_addr(void);
695

696
/* ichspi.c */
697 698
extern int ichspi_lock;
extern uint32_t ichspi_bbar;
699
extern void *ich_spibar;
700
int ich_init_opcodes(void);
701
int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
702
		    const unsigned char *writearr, unsigned char *readarr);
703
int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
704
int ich_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len);
705
int ich_spi_send_multicommand(struct spi_command *cmds);
706

707
/* it87spi.c */
708 709
void enter_conf_mode_ite(uint16_t port);
void exit_conf_mode_ite(uint16_t port);
710
struct superio probe_superio_ite(void);
711
int init_superio_ite(void);
712
int it87spi_init(void);
713
int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
714
			const unsigned char *writearr, unsigned char *readarr);
715
int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
716
int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
717

718
/* sb600spi.c */
719
int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt,
720
		      const unsigned char *writearr, unsigned char *readarr);
721
int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
722
int sb600_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
723
extern uint8_t *sb600_spibar;
724

Peter Stuge's avatar
Peter Stuge committed
725
/* wbsio_spi.c */
726
int wbsio_check_for_spi(void);
727
int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermann's avatar
Uwe Hermann committed
728
		      const unsigned char *writearr, unsigned char *readarr);
729
int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Peter Stuge's avatar
Peter Stuge committed
730

731 732 733 734 735 736 737
/* serprog.c */
int serprog_init(void);
int serprog_shutdown(void);
void serprog_chip_writeb(uint8_t val, chipaddr addr);
uint8_t serprog_chip_readb(const chipaddr addr);
void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
void serprog_delay(int delay);
738 739

/* serial.c */
Patrick Georgi's avatar
Patrick Georgi committed
740 741 742 743 744 745
#if _WIN32
typedef HANDLE fdtype;
#else
typedef int fdtype;
#endif

746
void sp_flush_incoming(void);
Patrick Georgi's avatar
Patrick Georgi committed
747
fdtype sp_openserport(char *dev, unsigned int baud);
748
void __attribute__((noreturn)) sp_die(char *msg);
Patrick Georgi's avatar
Patrick Georgi committed
749
extern fdtype sp_fd;
750 751 752
int serialport_shutdown(void);
int serialport_write(unsigned char *buf, unsigned int writecnt);
int serialport_read(unsigned char *buf, unsigned int readcnt);
Uwe Hermann's avatar
Uwe Hermann committed
753

754
#endif				/* !__FLASH_H__ */