2007-02-06 19:47:50 +00:00
|
|
|
/*
|
2007-08-29 17:52:32 +00:00
|
|
|
* This file is part of the flashrom project.
|
2007-02-06 19:47:50 +00:00
|
|
|
*
|
2007-09-09 20:21:05 +00:00
|
|
|
* Copyright (C) 2000 Silicon Integrated System Corporation
|
|
|
|
|
* Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
|
2009-08-12 09:27:45 +00:00
|
|
|
* Copyright (C) 2005-2009 coresystems GmbH
|
2009-06-15 12:10:57 +00:00
|
|
|
* Copyright (C) 2006-2009 Carl-Daniel Hailfinger
|
2007-02-06 19:47:50 +00:00
|
|
|
*
|
2007-08-29 17:52:32 +00:00
|
|
|
* 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.
|
2007-02-06 19:47:50 +00:00
|
|
|
*
|
2007-08-29 17:52:32 +00:00
|
|
|
* 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.
|
2007-02-06 19:47:50 +00:00
|
|
|
*/
|
|
|
|
|
|
2003-09-12 22:41:53 +00:00
|
|
|
#ifndef __FLASH_H__
|
|
|
|
|
#define __FLASH_H__ 1
|
|
|
|
|
|
2015-01-10 09:32:50 +00:00
|
|
|
#include "platform.h"
|
|
|
|
|
|
2013-06-16 10:30:08 +00:00
|
|
|
#include <inttypes.h>
|
2013-07-13 23:21:05 +00:00
|
|
|
#include <stdio.h>
|
2005-11-26 21:55:36 +00:00
|
|
|
#include <stdint.h>
|
2010-06-03 00:49:50 +00:00
|
|
|
#include <stddef.h>
|
2012-12-10 13:34:12 +00:00
|
|
|
#include <stdarg.h>
|
2013-06-23 22:15:39 +00:00
|
|
|
#include <stdbool.h>
|
2015-01-10 09:32:50 +00:00
|
|
|
#if IS_WINDOWS
|
2010-01-06 22:14:39 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
#undef min
|
|
|
|
|
#undef max
|
|
|
|
|
#endif
|
2008-05-22 13:22:45 +00:00
|
|
|
|
2017-06-19 12:57:10 +02:00
|
|
|
#include "libflashrom.h"
|
2016-04-27 15:56:14 +02:00
|
|
|
#include "layout.h"
|
|
|
|
|
|
2010-09-25 22:53:44 +00:00
|
|
|
#define ERROR_PTR ((void*)-1)
|
|
|
|
|
|
2010-10-08 00:37:55 +00:00
|
|
|
/* Error codes */
|
2012-06-08 15:27:47 +00:00
|
|
|
#define ERROR_OOM -100
|
2010-10-08 00:37:55 +00:00
|
|
|
#define TIMEOUT_ERROR -101
|
|
|
|
|
|
2013-07-13 23:31:37 +00:00
|
|
|
/* TODO: check using code for correct usage of types */
|
|
|
|
|
typedef uintptr_t chipaddr;
|
2013-07-17 23:46:44 +00:00
|
|
|
#define PRIxPTR_WIDTH ((int)(sizeof(uintptr_t)*2))
|
2009-05-16 21:22:56 +00:00
|
|
|
|
2011-06-14 01:35:36 +00:00
|
|
|
int register_shutdown(int (*function) (void *data), void *data);
|
2014-08-31 00:09:21 +00:00
|
|
|
int shutdown_free(void *data);
|
2013-07-17 23:46:44 +00:00
|
|
|
void *programmer_map_flash_region(const char *descr, uintptr_t phys_addr, size_t len);
|
2009-05-16 22:36:00 +00:00
|
|
|
void programmer_unmap_flash_region(void *virt_addr, size_t len);
|
2014-05-02 15:41:42 +00:00
|
|
|
void programmer_delay(unsigned int usecs);
|
2009-03-05 19:24:22 +00:00
|
|
|
|
2008-03-12 11:54:51 +00:00
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
|
|
|
|
2009-05-31 17:57:34 +00:00
|
|
|
enum chipbustype {
|
2011-07-27 07:13:06 +00:00
|
|
|
BUS_NONE = 0,
|
|
|
|
|
BUS_PARALLEL = 1 << 0,
|
|
|
|
|
BUS_LPC = 1 << 1,
|
|
|
|
|
BUS_FWH = 1 << 2,
|
|
|
|
|
BUS_SPI = 1 << 3,
|
2011-11-04 21:35:26 +00:00
|
|
|
BUS_PROG = 1 << 4,
|
2011-07-27 07:13:06 +00:00
|
|
|
BUS_NONSPI = BUS_PARALLEL | BUS_LPC | BUS_FWH,
|
2009-05-31 17:57:34 +00:00
|
|
|
};
|
|
|
|
|
|
2012-09-21 12:52:50 +00:00
|
|
|
/*
|
2013-04-01 19:34:53 +00:00
|
|
|
* The following enum defines possible write granularities of flash chips. These tend to reflect the properties
|
|
|
|
|
* of the actual hardware not necesserily the write function(s) defined by the respective struct flashchip.
|
|
|
|
|
* The latter might (and should) be more precisely specified, e.g. they might bail out early if their execution
|
|
|
|
|
* would result in undefined chip contents.
|
2012-09-21 12:52:50 +00:00
|
|
|
*/
|
|
|
|
|
enum write_granularity {
|
2013-04-01 19:34:53 +00:00
|
|
|
/* We assume 256 byte granularity by default. */
|
|
|
|
|
write_gran_256bytes = 0,/* If less than 256 bytes are written, the unwritten bytes are undefined. */
|
|
|
|
|
write_gran_1bit, /* Each bit can be cleared individually. */
|
|
|
|
|
write_gran_1byte, /* A byte can be written once. Further writes to an already written byte cause
|
|
|
|
|
* its contents to be either undefined or to stay unchanged. */
|
2015-10-16 02:16:20 +00:00
|
|
|
write_gran_128bytes, /* If less than 128 bytes are written, the unwritten bytes are undefined. */
|
2013-04-01 19:34:53 +00:00
|
|
|
write_gran_264bytes, /* If less than 264 bytes are written, the unwritten bytes are undefined. */
|
|
|
|
|
write_gran_512bytes, /* If less than 512 bytes are written, the unwritten bytes are undefined. */
|
|
|
|
|
write_gran_528bytes, /* If less than 528 bytes are written, the unwritten bytes are undefined. */
|
|
|
|
|
write_gran_1024bytes, /* If less than 1024 bytes are written, the unwritten bytes are undefined. */
|
|
|
|
|
write_gran_1056bytes, /* If less than 1056 bytes are written, the unwritten bytes are undefined. */
|
2014-06-16 22:36:17 +00:00
|
|
|
write_gran_1byte_implicit_erase, /* EEPROMs and other chips with implicit erase and 1-byte writes. */
|
2012-09-21 12:52:50 +00:00
|
|
|
};
|
|
|
|
|
|
2009-09-05 02:30:58 +00:00
|
|
|
/*
|
|
|
|
|
* 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?
|
2017-11-10 22:54:13 +01:00
|
|
|
* Macronix MX25L25635F has 8 different functions.
|
2009-09-05 02:30:58 +00:00
|
|
|
*/
|
2017-11-10 22:54:13 +01:00
|
|
|
#define NUM_ERASEFUNCTIONS 8
|
2009-09-05 02:30:58 +00:00
|
|
|
|
2013-07-25 22:54:25 +00:00
|
|
|
/* Feature bits used for non-SPI only */
|
2010-01-09 03:15:50 +00:00
|
|
|
#define FEATURE_REGISTERMAP (1 << 0)
|
2010-01-28 23:55:12 +00:00
|
|
|
#define FEATURE_LONG_RESET (0 << 4)
|
|
|
|
|
#define FEATURE_SHORT_RESET (1 << 4)
|
|
|
|
|
#define FEATURE_EITHER_RESET FEATURE_LONG_RESET
|
2010-10-20 21:13:19 +00:00
|
|
|
#define FEATURE_RESET_MASK (FEATURE_LONG_RESET | FEATURE_SHORT_RESET)
|
2010-01-09 03:15:50 +00:00
|
|
|
#define FEATURE_ADDR_FULL (0 << 2)
|
|
|
|
|
#define FEATURE_ADDR_MASK (3 << 2)
|
2010-01-28 23:55:12 +00:00
|
|
|
#define FEATURE_ADDR_2AA (1 << 2)
|
|
|
|
|
#define FEATURE_ADDR_AAA (2 << 2)
|
2010-04-03 10:27:08 +00:00
|
|
|
#define FEATURE_ADDR_SHIFTED (1 << 5)
|
2013-07-25 22:54:25 +00:00
|
|
|
/* Feature bits used for SPI only */
|
2010-07-29 13:09:18 +00:00
|
|
|
#define FEATURE_WRSR_EWSR (1 << 6)
|
|
|
|
|
#define FEATURE_WRSR_WREN (1 << 7)
|
2013-07-25 22:54:25 +00:00
|
|
|
#define FEATURE_WRSR_EITHER (FEATURE_WRSR_EWSR | FEATURE_WRSR_WREN)
|
2012-02-15 23:40:23 +00:00
|
|
|
#define FEATURE_OTP (1 << 8)
|
2013-03-15 02:03:16 +00:00
|
|
|
#define FEATURE_QPI (1 << 9)
|
2017-11-10 21:10:20 +01:00
|
|
|
#define FEATURE_4BA_ENTER (1 << 10) /**< Can enter/exit 4BA mode with instructions 0xb7/0xe9 w/o WREN */
|
|
|
|
|
#define FEATURE_4BA_ENTER_WREN (1 << 11) /**< Can enter/exit 4BA mode with instructions 0xb7/0xe9 after WREN */
|
|
|
|
|
#define FEATURE_4BA_EXT_ADDR (1 << 12) /**< Regular 3-byte operations can be used by writing the most
|
2017-10-14 17:47:28 +02:00
|
|
|
significant address byte into an extended address register. */
|
2017-11-10 21:10:20 +01:00
|
|
|
#define FEATURE_4BA_READ (1 << 13) /**< Native 4BA read instruction (0x13) is supported. */
|
2017-11-10 22:54:13 +01:00
|
|
|
#define FEATURE_4BA_FAST_READ (1 << 14) /**< Native 4BA fast read instruction (0x0c) is supported. */
|
|
|
|
|
#define FEATURE_4BA_WRITE (1 << 15) /**< Native 4BA byte program (0x12) is supported. */
|
|
|
|
|
/* 4BA Shorthands */
|
|
|
|
|
#define FEATURE_4BA_NATIVE (FEATURE_4BA_READ | FEATURE_4BA_FAST_READ | FEATURE_4BA_WRITE)
|
|
|
|
|
#define FEATURE_4BA (FEATURE_4BA_ENTER | FEATURE_4BA_EXT_ADDR | FEATURE_4BA_NATIVE)
|
|
|
|
|
#define FEATURE_4BA_WREN (FEATURE_4BA_ENTER_WREN | FEATURE_4BA_EXT_ADDR | FEATURE_4BA_NATIVE)
|
2018-01-15 01:06:09 +03:00
|
|
|
/*
|
|
|
|
|
* Most flash chips are erased to ones and programmed to zeros. However, some
|
|
|
|
|
* other flash chips, such as the ENE KB9012 internal flash, work the opposite way.
|
|
|
|
|
*/
|
|
|
|
|
#define FEATURE_ERASED_ZERO (1 << 16)
|
2015-05-23 20:30:30 -07:00
|
|
|
#define FEATURE_NO_ERASE (1 << 17)
|
2018-01-15 01:06:09 +03:00
|
|
|
|
|
|
|
|
#define ERASED_VALUE(flash) (((flash)->chip->feature_bits & FEATURE_ERASED_ZERO) ? 0x00 : 0xff)
|
2010-01-04 17:15:23 +00:00
|
|
|
|
2014-05-26 00:36:24 +00:00
|
|
|
enum test_state {
|
|
|
|
|
OK = 0,
|
|
|
|
|
NT = 1, /* Not tested */
|
|
|
|
|
BAD, /* Known to not work */
|
|
|
|
|
DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */
|
|
|
|
|
NA, /* Not applicable (e.g. write support on ROM chips) */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define TEST_UNTESTED (struct tested){ .probe = NT, .read = NT, .erase = NT, .write = NT }
|
|
|
|
|
|
|
|
|
|
#define TEST_OK_PROBE (struct tested){ .probe = OK, .read = NT, .erase = NT, .write = NT }
|
|
|
|
|
#define TEST_OK_PR (struct tested){ .probe = OK, .read = OK, .erase = NT, .write = NT }
|
|
|
|
|
#define TEST_OK_PRE (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = NT }
|
|
|
|
|
#define TEST_OK_PREW (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = OK }
|
|
|
|
|
|
|
|
|
|
#define TEST_BAD_PROBE (struct tested){ .probe = BAD, .read = NT, .erase = NT, .write = NT }
|
|
|
|
|
#define TEST_BAD_PR (struct tested){ .probe = BAD, .read = BAD, .erase = NT, .write = NT }
|
|
|
|
|
#define TEST_BAD_PRE (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = NT }
|
|
|
|
|
#define TEST_BAD_PREW (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = BAD }
|
|
|
|
|
|
2012-12-10 13:34:10 +00:00
|
|
|
struct flashrom_flashctx;
|
|
|
|
|
#define flashctx flashrom_flashctx /* TODO: Agree on a name and convert all occurences. */
|
2012-08-25 01:17:58 +00:00
|
|
|
typedef int (erasefunc_t)(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
|
2011-12-14 22:25:15 +00:00
|
|
|
|
2002-01-29 18:21:41 +00:00
|
|
|
struct flashchip {
|
2008-03-14 23:55:58 +00:00
|
|
|
const char *vendor;
|
2007-12-04 21:49:06 +00:00
|
|
|
const char *name;
|
2009-05-31 17:57:34 +00:00
|
|
|
|
|
|
|
|
enum chipbustype bustype;
|
|
|
|
|
|
2008-10-18 21:14:13 +00:00
|
|
|
/*
|
|
|
|
|
* With 32bit manufacture_id and model_id we can cover IDs up to
|
2007-12-31 01:49:00 +00:00
|
|
|
* (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's
|
|
|
|
|
* Identification code.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t manufacture_id;
|
|
|
|
|
uint32_t model_id;
|
2002-01-29 18:21:41 +00:00
|
|
|
|
2011-05-19 02:58:17 +00:00
|
|
|
/* Total chip size in kilobytes */
|
2011-11-23 09:13:48 +00:00
|
|
|
unsigned int total_size;
|
2011-05-19 02:58:17 +00:00
|
|
|
/* Chip page size in bytes */
|
2011-11-23 09:13:48 +00:00
|
|
|
unsigned int page_size;
|
2010-01-04 17:15:23 +00:00
|
|
|
int feature_bits;
|
2002-01-29 18:21:41 +00:00
|
|
|
|
2014-05-26 00:36:24 +00:00
|
|
|
/* Indicate how well flashrom supports different operations of this flash chip. */
|
|
|
|
|
struct tested {
|
|
|
|
|
enum test_state probe;
|
|
|
|
|
enum test_state read;
|
|
|
|
|
enum test_state erase;
|
|
|
|
|
enum test_state write;
|
|
|
|
|
} tested;
|
2008-05-03 04:34:37 +00:00
|
|
|
|
2018-01-15 01:10:00 +03:00
|
|
|
/*
|
|
|
|
|
* Group chips that have common command sets. This should ensure that
|
|
|
|
|
* no chip gets confused by a probing command for a very different class
|
|
|
|
|
* of chips.
|
|
|
|
|
*/
|
|
|
|
|
enum {
|
|
|
|
|
/* SPI25 is very common. Keep it at zero so we don't have
|
|
|
|
|
to specify it for each and every chip in the database.*/
|
|
|
|
|
SPI25 = 0,
|
2018-01-15 01:07:46 +03:00
|
|
|
SPI_EDI = 1,
|
2018-01-15 01:10:00 +03:00
|
|
|
} spi_cmd_set;
|
|
|
|
|
|
2011-12-14 22:25:15 +00:00
|
|
|
int (*probe) (struct flashctx *flash);
|
2009-06-03 14:46:22 +00:00
|
|
|
|
2011-11-23 09:13:48 +00:00
|
|
|
/* Delay after "enter/exit ID mode" commands in microseconds.
|
|
|
|
|
* NB: negative values have special meanings, see TIMING_* below.
|
|
|
|
|
*/
|
|
|
|
|
signed int probe_timing;
|
2009-09-05 02:30:58 +00:00
|
|
|
|
|
|
|
|
/*
|
2009-12-22 13:04:53 +00:00
|
|
|
* Erase blocks and associated erase function. Any chip erase function
|
|
|
|
|
* is stored as chip-sized virtual block together with said function.
|
2011-05-19 02:58:17 +00:00
|
|
|
* The first one that fits will be chosen. There is currently no way to
|
|
|
|
|
* influence that behaviour. For testing just comment out the other
|
|
|
|
|
* elements or set the function pointer to NULL.
|
2009-09-05 02:30:58 +00:00
|
|
|
*/
|
|
|
|
|
struct block_eraser {
|
2014-08-06 15:09:15 +00:00
|
|
|
struct eraseblock {
|
2011-06-12 19:47:55 +00:00
|
|
|
unsigned int size; /* Eraseblock size in bytes */
|
2009-09-05 02:30:58 +00:00
|
|
|
unsigned int count; /* Number of contiguous blocks with that size */
|
|
|
|
|
} eraseblocks[NUM_ERASEREGIONS];
|
2011-05-28 02:37:14 +00:00
|
|
|
/* a block_erase function should try to erase one block of size
|
|
|
|
|
* 'blocklen' at address 'blockaddr' and return 0 on success. */
|
2011-12-14 22:25:15 +00:00
|
|
|
int (*block_erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
|
2009-09-05 02:30:58 +00:00
|
|
|
} block_erasers[NUM_ERASEFUNCTIONS];
|
|
|
|
|
|
2011-12-14 22:25:15 +00:00
|
|
|
int (*printlock) (struct flashctx *flash);
|
|
|
|
|
int (*unlock) (struct flashctx *flash);
|
2014-05-09 21:16:21 +00:00
|
|
|
int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
|
2011-12-14 22:25:15 +00:00
|
|
|
int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
|
|
|
|
|
struct voltage {
|
2011-06-03 07:26:31 +00:00
|
|
|
uint16_t min;
|
|
|
|
|
uint16_t max;
|
|
|
|
|
} voltage;
|
2013-03-03 23:49:48 +00:00
|
|
|
enum write_granularity gran;
|
2011-12-14 22:25:15 +00:00
|
|
|
};
|
2003-09-12 22:41:53 +00:00
|
|
|
|
2012-12-10 13:34:10 +00:00
|
|
|
struct flashrom_flashctx {
|
2012-08-25 01:17:58 +00:00
|
|
|
struct flashchip *chip;
|
2014-08-30 23:39:51 +00:00
|
|
|
/* FIXME: The memory mappings should be saved in a more structured way. */
|
|
|
|
|
/* The physical_* fields store the respective addresses in the physical address space of the CPU. */
|
|
|
|
|
uintptr_t physical_memory;
|
|
|
|
|
/* The virtual_* fields store where the respective physical address is mapped into flashrom's address
|
|
|
|
|
* space. A value equivalent to (chipaddr)ERROR_PTR indicates an invalid mapping (or none at all). */
|
2009-05-16 21:22:56 +00:00
|
|
|
chipaddr virtual_memory;
|
2014-08-30 23:39:51 +00:00
|
|
|
/* Some flash devices have an additional register space; semantics are like above. */
|
|
|
|
|
uintptr_t physical_registers;
|
2009-05-16 21:22:56 +00:00
|
|
|
chipaddr virtual_registers;
|
2014-07-19 22:03:29 +00:00
|
|
|
struct registered_master *mst;
|
2016-04-29 16:40:15 +02:00
|
|
|
const struct flashrom_layout *layout;
|
|
|
|
|
struct single_layout fallback_layout;
|
2012-12-10 13:34:10 +00:00
|
|
|
struct {
|
|
|
|
|
bool force;
|
|
|
|
|
bool force_boardmismatch;
|
|
|
|
|
bool verify_after_write;
|
|
|
|
|
bool verify_whole_chip;
|
|
|
|
|
} flags;
|
2017-10-14 17:47:28 +02:00
|
|
|
/* We cache the state of the extended address register (highest byte
|
|
|
|
|
of a 4BA for 3BA instructions) and the state of the 4BA mode here.
|
|
|
|
|
If possible, we enter 4BA mode early. If that fails, we make use
|
|
|
|
|
of the extended address register. */
|
|
|
|
|
int address_high_byte;
|
|
|
|
|
bool in_4ba_mode;
|
2002-01-29 18:21:41 +00:00
|
|
|
};
|
|
|
|
|
|
2009-06-03 14:46:22 +00:00
|
|
|
/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
|
|
|
|
|
* field and zero delay.
|
2018-01-15 01:07:46 +03:00
|
|
|
*
|
2009-06-03 14:46:22 +00:00
|
|
|
* 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
|
|
|
|
|
|
2011-05-04 00:39:50 +00:00
|
|
|
extern const struct flashchip flashchips[];
|
2014-05-26 22:05:31 +00:00
|
|
|
extern const unsigned int flashchips_size;
|
2005-11-26 21:55:36 +00:00
|
|
|
|
2011-12-18 15:01:24 +00:00
|
|
|
void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
|
|
|
|
|
void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
|
|
|
|
|
void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
|
2014-05-09 21:16:21 +00:00
|
|
|
void chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
|
2011-12-18 15:01:24 +00:00
|
|
|
uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr);
|
|
|
|
|
uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr);
|
|
|
|
|
uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr);
|
|
|
|
|
void chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
|
|
|
|
|
|
2009-06-17 12:07:12 +00:00
|
|
|
/* print.c */
|
2012-10-23 13:06:46 +00:00
|
|
|
int print_supported(void);
|
2009-11-17 09:57:34 +00:00
|
|
|
void print_supported_wiki(void);
|
2009-05-15 17:02:34 +00:00
|
|
|
|
2014-06-12 00:04:32 +00:00
|
|
|
/* helpers.c */
|
|
|
|
|
uint32_t address_to_bits(uint32_t addr);
|
|
|
|
|
int bitcount(unsigned long a);
|
|
|
|
|
int max(int a, int b);
|
|
|
|
|
int min(int a, int b);
|
|
|
|
|
char *strcat_realloc(char *dest, const char *src);
|
|
|
|
|
void tolower_string(char *str);
|
2014-11-01 22:56:06 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
|
char* strtok_r(char *str, const char *delim, char **nextp);
|
|
|
|
|
#endif
|
2016-05-03 10:48:02 +02:00
|
|
|
#if defined(__DJGPP__) || (!defined(__LIBPAYLOAD__) && !defined(HAVE_STRNLEN))
|
2015-01-27 18:07:50 +00:00
|
|
|
size_t strnlen(const char *str, size_t n);
|
|
|
|
|
#endif
|
2014-06-12 00:04:32 +00:00
|
|
|
|
2007-08-23 13:34:59 +00:00
|
|
|
/* flashrom.c */
|
2011-01-17 07:50:42 +00:00
|
|
|
extern const char flashrom_version[];
|
2012-12-30 01:23:17 +00:00
|
|
|
extern const char *chip_to_probe;
|
2016-05-03 10:48:02 +02:00
|
|
|
char *flashbuses_to_text(enum chipbustype bustype);
|
2014-08-30 23:39:51 +00:00
|
|
|
int map_flash(struct flashctx *flash);
|
|
|
|
|
void unmap_flash(struct flashctx *flash);
|
2011-12-14 22:25:15 +00:00
|
|
|
int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
|
|
|
|
|
int erase_flash(struct flashctx *flash);
|
2014-07-19 22:03:29 +00:00
|
|
|
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *fill_flash, int force);
|
2011-12-14 22:25:15 +00:00
|
|
|
int read_flash_to_file(struct flashctx *flash, const char *filename);
|
2012-12-30 01:23:17 +00:00
|
|
|
char *extract_param(const char *const *haystack, const char *needle, const char *delim);
|
2014-05-09 21:16:21 +00:00
|
|
|
int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len);
|
2018-01-15 01:06:09 +03:00
|
|
|
int need_erase(const uint8_t *have, const uint8_t *want, unsigned int len, enum write_granularity gran, const uint8_t erased_value);
|
2010-01-07 03:24:05 +00:00
|
|
|
void print_version(void);
|
2012-06-06 09:17:06 +00:00
|
|
|
void print_buildinfo(void);
|
2010-05-15 15:04:37 +00:00
|
|
|
void print_banner(void);
|
2010-10-06 23:48:34 +00:00
|
|
|
void list_programmers_linebreak(int startcol, int cols, int paren);
|
2010-01-07 03:24:05 +00:00
|
|
|
int selfcheck(void);
|
2011-06-26 17:38:17 +00:00
|
|
|
int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename);
|
2014-05-09 21:16:21 +00:00
|
|
|
int write_buf_to_file(const unsigned char *buf, unsigned long size, const char *filename);
|
2013-06-14 11:55:26 +02:00
|
|
|
int prepare_flash_access(struct flashctx *, bool read_it, bool write_it, bool erase_it, bool verify_it);
|
|
|
|
|
void finalize_flash_access(struct flashctx *);
|
2016-04-29 18:39:01 +02:00
|
|
|
int do_read(struct flashctx *, const char *filename);
|
|
|
|
|
int do_erase(struct flashctx *);
|
2018-01-15 01:10:36 +03:00
|
|
|
int do_write(struct flashctx *, const char *const filename, const char *const referencefile);
|
2016-04-29 18:39:01 +02:00
|
|
|
int do_verify(struct flashctx *, const char *const filename);
|
2009-06-17 12:07:12 +00:00
|
|
|
|
2011-09-03 17:15:00 +00:00
|
|
|
/* Something happened that shouldn't happen, but we can go on. */
|
2010-07-22 18:04:15 +00:00
|
|
|
#define ERROR_NONFATAL 0x100
|
|
|
|
|
|
2011-09-03 17:15:00 +00:00
|
|
|
/* Something happened that shouldn't happen, we'll abort. */
|
|
|
|
|
#define ERROR_FATAL -0xee
|
2011-12-20 00:19:29 +00:00
|
|
|
#define ERROR_FLASHROM_BUG -200
|
|
|
|
|
/* We reached one of the hardcoded limits of flashrom. This can be fixed by
|
|
|
|
|
* increasing the limit of a compile-time allocation or by switching to dynamic
|
|
|
|
|
* allocation.
|
|
|
|
|
* Note: If this warning is triggered, check first for runaway registrations.
|
|
|
|
|
*/
|
|
|
|
|
#define ERROR_FLASHROM_LIMIT -201
|
2011-09-03 17:15:00 +00:00
|
|
|
|
2014-08-08 23:52:33 +00:00
|
|
|
/* cli_common.c */
|
|
|
|
|
void print_chip_support_status(const struct flashchip *chip);
|
|
|
|
|
|
2010-01-07 20:09:33 +00:00
|
|
|
/* cli_output.c */
|
2017-06-19 12:57:10 +02:00
|
|
|
extern enum flashrom_log_level verbose_screen;
|
|
|
|
|
extern enum flashrom_log_level verbose_logfile;
|
2012-06-06 09:17:06 +00:00
|
|
|
#ifndef STANDALONE
|
|
|
|
|
int open_logfile(const char * const filename);
|
|
|
|
|
int close_logfile(void);
|
|
|
|
|
void start_logging(void);
|
|
|
|
|
#endif
|
2017-06-19 12:57:10 +02:00
|
|
|
int flashrom_print_cb(enum flashrom_log_level level, const char *fmt, va_list ap);
|
2010-06-04 23:20:21 +00:00
|
|
|
/* Let gcc and clang check for correct printf-style format strings. */
|
2017-06-19 12:57:10 +02:00
|
|
|
int print(enum flashrom_log_level level, const char *fmt, ...)
|
2013-07-13 23:21:05 +00:00
|
|
|
#ifdef __MINGW32__
|
2018-03-03 18:40:24 +01:00
|
|
|
# ifndef __MINGW_PRINTF_FORMAT
|
|
|
|
|
# define __MINGW_PRINTF_FORMAT gnu_printf
|
|
|
|
|
# endif
|
2017-10-26 18:45:00 +02:00
|
|
|
__attribute__((format(__MINGW_PRINTF_FORMAT, 2, 3)));
|
2013-07-13 23:21:05 +00:00
|
|
|
#else
|
|
|
|
|
__attribute__((format(printf, 2, 3)));
|
|
|
|
|
#endif
|
2017-06-19 12:57:10 +02:00
|
|
|
#define msg_gerr(...) print(FLASHROM_MSG_ERROR, __VA_ARGS__) /* general errors */
|
|
|
|
|
#define msg_perr(...) print(FLASHROM_MSG_ERROR, __VA_ARGS__) /* programmer errors */
|
|
|
|
|
#define msg_cerr(...) print(FLASHROM_MSG_ERROR, __VA_ARGS__) /* chip errors */
|
|
|
|
|
#define msg_gwarn(...) print(FLASHROM_MSG_WARN, __VA_ARGS__) /* general warnings */
|
|
|
|
|
#define msg_pwarn(...) print(FLASHROM_MSG_WARN, __VA_ARGS__) /* programmer warnings */
|
|
|
|
|
#define msg_cwarn(...) print(FLASHROM_MSG_WARN, __VA_ARGS__) /* chip warnings */
|
|
|
|
|
#define msg_ginfo(...) print(FLASHROM_MSG_INFO, __VA_ARGS__) /* general info */
|
|
|
|
|
#define msg_pinfo(...) print(FLASHROM_MSG_INFO, __VA_ARGS__) /* programmer info */
|
|
|
|
|
#define msg_cinfo(...) print(FLASHROM_MSG_INFO, __VA_ARGS__) /* chip info */
|
|
|
|
|
#define msg_gdbg(...) print(FLASHROM_MSG_DEBUG, __VA_ARGS__) /* general debug */
|
|
|
|
|
#define msg_pdbg(...) print(FLASHROM_MSG_DEBUG, __VA_ARGS__) /* programmer debug */
|
|
|
|
|
#define msg_cdbg(...) print(FLASHROM_MSG_DEBUG, __VA_ARGS__) /* chip debug */
|
|
|
|
|
#define msg_gdbg2(...) print(FLASHROM_MSG_DEBUG2, __VA_ARGS__) /* general debug2 */
|
|
|
|
|
#define msg_pdbg2(...) print(FLASHROM_MSG_DEBUG2, __VA_ARGS__) /* programmer debug2 */
|
|
|
|
|
#define msg_cdbg2(...) print(FLASHROM_MSG_DEBUG2, __VA_ARGS__) /* chip debug2 */
|
|
|
|
|
#define msg_gspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* general debug spew */
|
|
|
|
|
#define msg_pspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* programmer debug spew */
|
|
|
|
|
#define msg_cspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* chip debug spew */
|
2010-01-07 20:09:33 +00:00
|
|
|
|
2007-08-23 13:34:59 +00:00
|
|
|
/* layout.c */
|
2011-12-25 09:12:16 +00:00
|
|
|
int register_include_arg(char *name);
|
2014-05-09 21:16:21 +00:00
|
|
|
int read_romlayout(const char *name);
|
2013-09-23 14:21:06 +00:00
|
|
|
int normalize_romentries(const struct flashctx *flash);
|
2013-09-15 14:01:06 +00:00
|
|
|
void layout_cleanup(void);
|
2007-08-23 13:34:59 +00:00
|
|
|
|
2007-10-15 21:44:47 +00:00
|
|
|
/* spi.c */
|
2009-07-10 21:08:55 +00:00
|
|
|
struct spi_command {
|
|
|
|
|
unsigned int writecnt;
|
|
|
|
|
unsigned int readcnt;
|
|
|
|
|
const unsigned char *writearr;
|
|
|
|
|
unsigned char *readarr;
|
|
|
|
|
};
|
2017-10-15 11:20:58 +02:00
|
|
|
#define NULL_SPI_CMD { 0, 0, NULL, NULL, }
|
2011-12-18 15:01:24 +00:00
|
|
|
int spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
|
|
|
|
|
int spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
|
2007-08-23 13:34:59 +00:00
|
|
|
|
2011-12-20 00:19:29 +00:00
|
|
|
enum chipbustype get_buses_supported(void);
|
2004-03-20 16:46:10 +00:00
|
|
|
#endif /* !__FLASH_H__ */
|