stepan | 5c3f138 | 2007-02-06 19:47:50 +0000 | [diff] [blame] | 1 | /* |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 2 | * This file is part of the flashrom project. |
stepan | 5c3f138 | 2007-02-06 19:47:50 +0000 | [diff] [blame] | 3 | * |
uwe | 555dd97 | 2007-09-09 20:21:05 +0000 | [diff] [blame] | 4 | * Copyright (C) 2000 Silicon Integrated System Corporation |
| 5 | * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com> |
stepan | 6d42c0f | 2009-08-12 09:27:45 +0000 | [diff] [blame] | 6 | * Copyright (C) 2005-2009 coresystems GmbH |
hailfinger | 77c5d93 | 2009-06-15 12:10:57 +0000 | [diff] [blame] | 7 | * Copyright (C) 2006-2009 Carl-Daniel Hailfinger |
stepan | 5c3f138 | 2007-02-06 19:47:50 +0000 | [diff] [blame] | 8 | * |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 9 | * 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. |
stepan | 5c3f138 | 2007-02-06 19:47:50 +0000 | [diff] [blame] | 13 | * |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 14 | * 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. |
stepan | 5c3f138 | 2007-02-06 19:47:50 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 20 | #ifndef __FLASH_H__ |
| 21 | #define __FLASH_H__ 1 |
| 22 | |
Edward O'Callaghan | 7b18871 | 2019-09-09 15:07:14 +1000 | [diff] [blame] | 23 | #include <inttypes.h> |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 24 | #include <stdio.h> |
ollie | 6a60099 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 25 | #include <stdint.h> |
hailfinger | d43a4e3 | 2010-06-03 00:49:50 +0000 | [diff] [blame] | 26 | #include <stddef.h> |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 27 | #include <stdarg.h> |
Edward O'Callaghan | a74ffcd | 2019-06-17 14:59:55 +1000 | [diff] [blame] | 28 | #include <stdbool.h> |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 29 | #if IS_WINDOWS |
oxygene | 3ad3b33 | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 30 | #include <windows.h> |
| 31 | #undef min |
| 32 | #undef max |
| 33 | #endif |
hailfinger | e1f062f | 2008-05-22 13:22:45 +0000 | [diff] [blame] | 34 | |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 35 | #define KiB (1024) |
| 36 | #define MiB (1024 * KiB) |
| 37 | |
| 38 | /* Assumes `n` and `a` are at most 64-bit wide (to avoid typeof() operator). */ |
| 39 | #define ALIGN_DOWN(n, a) ((n) & ~((uint64_t)(a) - 1)) |
| 40 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 41 | struct flashctx; /* forward declare */ |
hailfinger | f294fa2 | 2010-09-25 22:53:44 +0000 | [diff] [blame] | 42 | #define ERROR_PTR ((void*)-1) |
| 43 | |
hailfinger | ee9ee13 | 2010-10-08 00:37:55 +0000 | [diff] [blame] | 44 | /* Error codes */ |
Nikolai Artemiev | 1e0291b | 2020-04-15 10:29:26 +1000 | [diff] [blame] | 45 | #define ERROR_OOM -100 |
hailfinger | ee9ee13 | 2010-10-08 00:37:55 +0000 | [diff] [blame] | 46 | #define TIMEOUT_ERROR -101 |
| 47 | |
Edward O'Callaghan | 9b520dd | 2019-05-01 21:47:21 -0400 | [diff] [blame] | 48 | #define PRIxPTR_WIDTH ((int)(sizeof(uintptr_t)*2)) |
| 49 | |
Edward O'Callaghan | 1a3fd13 | 2019-06-04 14:18:55 +1000 | [diff] [blame] | 50 | /* for verify_it variable in flashrom.c and cli_classic.c */ |
Louis Yung-Chieh Lo | 5d95f04 | 2011-09-01 17:33:06 +0800 | [diff] [blame] | 51 | enum { |
| 52 | VERIFY_OFF = 0, |
| 53 | VERIFY_FULL, |
| 54 | VERIFY_PARTIAL, |
| 55 | }; |
| 56 | |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 57 | /* TODO: check using code for correct usage of types */ |
Kangheui Won | 4974cc1 | 2019-10-18 12:59:01 +1100 | [diff] [blame] | 58 | typedef uintptr_t chipaddr; |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 59 | #define PRIxPTR_WIDTH ((int)(sizeof(uintptr_t)*2)) |
Pavol Marko | ef4c6e8 | 2019-09-09 12:43:44 +0000 | [diff] [blame] | 60 | |
David Hendricks | 93784b4 | 2016-08-09 17:00:38 -0700 | [diff] [blame] | 61 | int register_shutdown(int (*function) (void *data), void *data); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 62 | #define CHIP_RESTORE_CALLBACK int (*func) (struct flashctx *flash, uint8_t status) |
David Hendricks | bf36f09 | 2010-11-02 23:39:29 -0700 | [diff] [blame] | 63 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 64 | int register_chip_restore(CHIP_RESTORE_CALLBACK, struct flashctx *flash, uint8_t status); |
uwe | abe92a5 | 2009-05-16 22:36:00 +0000 | [diff] [blame] | 65 | void *programmer_map_flash_region(const char *descr, unsigned long phys_addr, |
| 66 | size_t len); |
| 67 | void programmer_unmap_flash_region(void *virt_addr, size_t len); |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 68 | void programmer_delay(unsigned int usecs); |
hailfinger | ba3761a | 2009-03-05 19:24:22 +0000 | [diff] [blame] | 69 | |
uwe | 16f9909 | 2008-03-12 11:54:51 +0000 | [diff] [blame] | 70 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 71 | |
hailfinger | 4016746 | 2009-05-31 17:57:34 +0000 | [diff] [blame] | 72 | enum chipbustype { |
hailfinger | e1e41ea | 2011-07-27 07:13:06 +0000 | [diff] [blame] | 73 | BUS_NONE = 0, |
| 74 | BUS_PARALLEL = 1 << 0, |
| 75 | BUS_LPC = 1 << 1, |
| 76 | BUS_FWH = 1 << 2, |
| 77 | BUS_SPI = 1 << 3, |
hailfinger | fe7cd9e | 2011-11-04 21:35:26 +0000 | [diff] [blame] | 78 | BUS_PROG = 1 << 4, |
hailfinger | e1e41ea | 2011-07-27 07:13:06 +0000 | [diff] [blame] | 79 | BUS_NONSPI = BUS_PARALLEL | BUS_LPC | BUS_FWH, |
hailfinger | 4016746 | 2009-05-31 17:57:34 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
David Hendricks | 80f62d2 | 2010-10-08 11:09:35 -0700 | [diff] [blame] | 82 | /* used to select bus which target chip resides */ |
| 83 | extern enum chipbustype target_bus; |
| 84 | |
hailfinger | 7df2136 | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 85 | /* |
Edward O'Callaghan | f78fffc | 2019-06-17 12:40:12 +1000 | [diff] [blame] | 86 | * The following enum defines possible write granularities of flash chips. These tend to reflect the properties |
| 87 | * of the actual hardware not necesserily the write function(s) defined by the respective struct flashchip. |
| 88 | * The latter might (and should) be more precisely specified, e.g. they might bail out early if their execution |
| 89 | * would result in undefined chip contents. |
| 90 | */ |
| 91 | enum write_granularity { |
| 92 | /* We assume 256 byte granularity by default. */ |
| 93 | write_gran_256bytes = 0,/* If less than 256 bytes are written, the unwritten bytes are undefined. */ |
| 94 | write_gran_1bit, /* Each bit can be cleared individually. */ |
| 95 | write_gran_1byte, /* A byte can be written once. Further writes to an already written byte cause |
| 96 | * its contents to be either undefined or to stay unchanged. */ |
| 97 | write_gran_128bytes, /* If less than 128 bytes are written, the unwritten bytes are undefined. */ |
| 98 | write_gran_264bytes, /* If less than 264 bytes are written, the unwritten bytes are undefined. */ |
| 99 | write_gran_512bytes, /* If less than 512 bytes are written, the unwritten bytes are undefined. */ |
| 100 | write_gran_528bytes, /* If less than 528 bytes are written, the unwritten bytes are undefined. */ |
| 101 | write_gran_1024bytes, /* If less than 1024 bytes are written, the unwritten bytes are undefined. */ |
| 102 | write_gran_1056bytes, /* If less than 1056 bytes are written, the unwritten bytes are undefined. */ |
| 103 | write_gran_1byte_implicit_erase, /* EEPROMs and other chips with implicit erase and 1-byte writes. */ |
| 104 | }; |
| 105 | |
| 106 | /* |
hailfinger | 7df2136 | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 107 | * How many different contiguous runs of erase blocks with one size each do |
| 108 | * we have for a given erase function? |
| 109 | */ |
| 110 | #define NUM_ERASEREGIONS 5 |
| 111 | |
| 112 | /* |
| 113 | * How many different erase functions do we have per chip? |
Edward O'Callaghan | fadf15b | 2019-10-10 13:46:39 +1100 | [diff] [blame] | 114 | * Macronix MX25L25635F has 8 different functions. |
hailfinger | 7df2136 | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 115 | */ |
Edward O'Callaghan | fadf15b | 2019-10-10 13:46:39 +1100 | [diff] [blame] | 116 | #define NUM_ERASEFUNCTIONS 8 |
hailfinger | 7df2136 | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 117 | |
Edward O'Callaghan | f78fffc | 2019-06-17 12:40:12 +1000 | [diff] [blame] | 118 | /* Feature bits used for non-SPI only */ |
hailfinger | 80dea31 | 2010-01-09 03:15:50 +0000 | [diff] [blame] | 119 | #define FEATURE_REGISTERMAP (1 << 0) |
| 120 | #define FEATURE_BYTEWRITES (1 << 1) |
snelson | c685534 | 2010-01-28 23:55:12 +0000 | [diff] [blame] | 121 | #define FEATURE_LONG_RESET (0 << 4) |
| 122 | #define FEATURE_SHORT_RESET (1 << 4) |
| 123 | #define FEATURE_EITHER_RESET FEATURE_LONG_RESET |
hailfinger | b07dc97 | 2010-10-20 21:13:19 +0000 | [diff] [blame] | 124 | #define FEATURE_RESET_MASK (FEATURE_LONG_RESET | FEATURE_SHORT_RESET) |
hailfinger | 80dea31 | 2010-01-09 03:15:50 +0000 | [diff] [blame] | 125 | #define FEATURE_ADDR_FULL (0 << 2) |
| 126 | #define FEATURE_ADDR_MASK (3 << 2) |
snelson | c685534 | 2010-01-28 23:55:12 +0000 | [diff] [blame] | 127 | #define FEATURE_ADDR_2AA (1 << 2) |
| 128 | #define FEATURE_ADDR_AAA (2 << 2) |
mkarcher | 9ded5fe | 2010-04-03 10:27:08 +0000 | [diff] [blame] | 129 | #define FEATURE_ADDR_SHIFTED (1 << 5) |
Edward O'Callaghan | f78fffc | 2019-06-17 12:40:12 +1000 | [diff] [blame] | 130 | /* Feature bits used for SPI only */ |
hailfinger | c33d473 | 2010-07-29 13:09:18 +0000 | [diff] [blame] | 131 | #define FEATURE_WRSR_EWSR (1 << 6) |
| 132 | #define FEATURE_WRSR_WREN (1 << 7) |
| 133 | #define FEATURE_WRSR_EITHER (FEATURE_WRSR_EWSR | FEATURE_WRSR_WREN) |
David Hendricks | ff55cf6 | 2016-08-30 11:22:31 -0700 | [diff] [blame] | 134 | #define FEATURE_OTP (1 << 8) |
Edward O'Callaghan | 96a4f54 | 2020-06-29 16:51:24 +1000 | [diff] [blame] | 135 | #define FEATURE_QPI (1 << 9) |
| 136 | #define FEATURE_4BA_ENTER (1 << 10) /**< Can enter/exit 4BA mode with instructions 0xb7/0xe9 w/o WREN */ |
| 137 | #define FEATURE_4BA_ENTER_WREN (1 << 11) /**< Can enter/exit 4BA mode with instructions 0xb7/0xe9 after WREN */ |
| 138 | #define FEATURE_4BA_ENTER_EAR7 (1 << 12) /**< Can enter/exit 4BA mode by setting bit7 of the ext addr reg */ |
Edward O'Callaghan | 2748621 | 2019-07-26 21:59:55 +1000 | [diff] [blame] | 139 | #define FEATURE_4BA_EXT_ADDR (1 << 13) /**< Regular 3-byte operations can be used by writing the most |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 140 | significant address byte into an extended address register. */ |
Edward O'Callaghan | 2748621 | 2019-07-26 21:59:55 +1000 | [diff] [blame] | 141 | #define FEATURE_4BA_READ (1 << 14) /**< Native 4BA read instruction (0x13) is supported. */ |
| 142 | #define FEATURE_4BA_FAST_READ (1 << 15) /**< Native 4BA fast read instruction (0x0c) is supported. */ |
| 143 | #define FEATURE_4BA_WRITE (1 << 16) /**< Native 4BA byte program (0x12) is supported. */ |
Edward O'Callaghan | 3d0cbd4 | 2019-06-24 15:37:01 +1000 | [diff] [blame] | 144 | /* 4BA Shorthands */ |
| 145 | #define FEATURE_4BA_NATIVE (FEATURE_4BA_READ | FEATURE_4BA_FAST_READ | FEATURE_4BA_WRITE) |
| 146 | #define FEATURE_4BA (FEATURE_4BA_ENTER | FEATURE_4BA_EXT_ADDR | FEATURE_4BA_NATIVE) |
| 147 | #define FEATURE_4BA_WREN (FEATURE_4BA_ENTER_WREN | FEATURE_4BA_EXT_ADDR | FEATURE_4BA_NATIVE) |
Edward O'Callaghan | 96a4f54 | 2020-06-29 16:51:24 +1000 | [diff] [blame] | 148 | #define FEATURE_4BA_EAR7 (FEATURE_4BA_ENTER_EAR7 | FEATURE_4BA_EXT_ADDR | FEATURE_4BA_NATIVE) |
| 149 | /* |
| 150 | * Most flash chips are erased to ones and programmed to zeros. However, some |
| 151 | * other flash chips, such as the ENE KB9012 internal flash, work the opposite way. |
| 152 | */ |
| 153 | #define FEATURE_ERASED_ZERO (1 << 17) |
| 154 | #define FEATURE_NO_ERASE (1 << 18) |
Simon Glass | 4c21413 | 2013-07-16 10:09:28 -0600 | [diff] [blame] | 155 | |
Edward O'Callaghan | ef783e3 | 2020-08-10 19:54:27 +1000 | [diff] [blame] | 156 | #define ERASED_VALUE(flash) (((flash)->chip->feature_bits & FEATURE_ERASED_ZERO) ? 0x00 : 0xff) |
| 157 | #define UNERASED_VALUE(flash) (((flash)->chip->feature_bits & FEATURE_ERASED_ZERO) ? 0xff : 0x00) |
| 158 | |
David Hendricks | 8c08421 | 2015-11-17 22:29:36 -0800 | [diff] [blame] | 159 | struct voltage_range { |
| 160 | uint16_t min, max; |
| 161 | }; |
| 162 | |
Patrick Georgi | ac3423f | 2017-02-03 20:58:06 +0100 | [diff] [blame] | 163 | enum test_state { |
| 164 | OK = 0, |
| 165 | NT = 1, /* Not tested */ |
| 166 | BAD, /* Known to not work */ |
| 167 | DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */ |
| 168 | NA, /* Not applicable (e.g. write support on ROM chips) */ |
| 169 | }; |
| 170 | |
Alan Green | 5447a45 | 2019-07-30 13:57:52 +1000 | [diff] [blame] | 171 | #define TEST_UNTESTED (struct tested){ .probe = NT, .read = NT, .erase = NT, .write = NT } |
Patrick Georgi | ac3423f | 2017-02-03 20:58:06 +0100 | [diff] [blame] | 172 | |
Alan Green | 5447a45 | 2019-07-30 13:57:52 +1000 | [diff] [blame] | 173 | #define TEST_OK_PROBE (struct tested){ .probe = OK, .read = NT, .erase = NT, .write = NT } |
| 174 | #define TEST_OK_PR (struct tested){ .probe = OK, .read = OK, .erase = NT, .write = NT } |
| 175 | #define TEST_OK_PRE (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = NT } |
| 176 | #define TEST_OK_PREW (struct tested){ .probe = OK, .read = OK, .erase = OK, .write = OK } |
Patrick Georgi | ac3423f | 2017-02-03 20:58:06 +0100 | [diff] [blame] | 177 | |
Alan Green | 5447a45 | 2019-07-30 13:57:52 +1000 | [diff] [blame] | 178 | #define TEST_BAD_PROBE (struct tested){ .probe = BAD, .read = NT, .erase = NT, .write = NT } |
| 179 | #define TEST_BAD_PR (struct tested){ .probe = BAD, .read = BAD, .erase = NT, .write = NT } |
| 180 | #define TEST_BAD_PRE (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = NT } |
| 181 | #define TEST_BAD_PREW (struct tested){ .probe = BAD, .read = BAD, .erase = BAD, .write = BAD } |
Patrick Georgi | ac3423f | 2017-02-03 20:58:06 +0100 | [diff] [blame] | 182 | |
Nikolai Artemiev | a66b6cd | 2020-08-31 18:07:13 +1000 | [diff] [blame] | 183 | typedef int (erasefunc_t)(struct flashctx *flash, unsigned int addr, unsigned int blocklen); |
| 184 | |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 185 | struct flashchip { |
uwe | dfcd15f | 2008-03-14 23:55:58 +0000 | [diff] [blame] | 186 | const char *vendor; |
uwe | 6ed6d95 | 2007-12-04 21:49:06 +0000 | [diff] [blame] | 187 | const char *name; |
hailfinger | 4016746 | 2009-05-31 17:57:34 +0000 | [diff] [blame] | 188 | |
| 189 | enum chipbustype bustype; |
| 190 | |
uwe | fa98ca1 | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 191 | /* |
| 192 | * With 32bit manufacture_id and model_id we can cover IDs up to |
hailfinger | 428f201 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 193 | * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's |
| 194 | * Identification code. |
| 195 | */ |
| 196 | uint32_t manufacture_id; |
| 197 | uint32_t model_id; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 198 | |
stefanct | 707f13b | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 199 | /* Total chip size in kilobytes */ |
stefanct | c5eb8a9 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 200 | unsigned int total_size; |
stefanct | 707f13b | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 201 | /* Chip page size in bytes */ |
stefanct | c5eb8a9 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 202 | unsigned int page_size; |
snelson | 63133f9 | 2010-01-04 17:15:23 +0000 | [diff] [blame] | 203 | int feature_bits; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 204 | |
Patrick Georgi | ac3423f | 2017-02-03 20:58:06 +0100 | [diff] [blame] | 205 | /* Indicate how well flashrom supports different operations of this flash chip. */ |
| 206 | struct tested { |
| 207 | enum test_state probe; |
| 208 | enum test_state read; |
| 209 | enum test_state erase; |
| 210 | enum test_state write; |
Patrick Georgi | ac3423f | 2017-02-03 20:58:06 +0100 | [diff] [blame] | 211 | } tested; |
stuge | 9cd64bd | 2008-05-03 04:34:37 +0000 | [diff] [blame] | 212 | |
Edward O'Callaghan | cc1d0c9 | 2019-02-24 15:35:07 +1100 | [diff] [blame] | 213 | /* |
| 214 | * Group chips that have common command sets. This should ensure that |
| 215 | * no chip gets confused by a probing command for a very different class |
| 216 | * of chips. |
| 217 | */ |
| 218 | enum { |
| 219 | /* SPI25 is very common. Keep it at zero so we don't have |
| 220 | to specify it for each and every chip in the database.*/ |
| 221 | SPI25 = 0, |
Edward O'Callaghan | a9c8100 | 2019-02-24 15:54:40 +1100 | [diff] [blame] | 222 | SPI_EDI = 1, |
Edward O'Callaghan | cc1d0c9 | 2019-02-24 15:35:07 +1100 | [diff] [blame] | 223 | } spi_cmd_set; |
| 224 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 225 | int (*probe) (struct flashctx *flash); |
hailfinger | d5b3592 | 2009-06-03 14:46:22 +0000 | [diff] [blame] | 226 | |
stefanct | c5eb8a9 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 227 | /* Delay after "enter/exit ID mode" commands in microseconds. |
| 228 | * NB: negative values have special meanings, see TIMING_* below. |
| 229 | */ |
| 230 | signed int probe_timing; |
hailfinger | 7df2136 | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 231 | |
| 232 | /* |
hailfinger | c4fac58 | 2009-12-22 13:04:53 +0000 | [diff] [blame] | 233 | * Erase blocks and associated erase function. Any chip erase function |
| 234 | * is stored as chip-sized virtual block together with said function. |
stefanct | 707f13b | 2011-05-19 02:58:17 +0000 | [diff] [blame] | 235 | * The first one that fits will be chosen. There is currently no way to |
| 236 | * influence that behaviour. For testing just comment out the other |
| 237 | * elements or set the function pointer to NULL. |
hailfinger | 7df2136 | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 238 | */ |
| 239 | struct block_eraser { |
Patrick Georgi | ac3423f | 2017-02-03 20:58:06 +0100 | [diff] [blame] | 240 | struct eraseblock { |
stefanct | 312d9ff | 2011-06-12 19:47:55 +0000 | [diff] [blame] | 241 | unsigned int size; /* Eraseblock size in bytes */ |
hailfinger | 7df2136 | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 242 | unsigned int count; /* Number of contiguous blocks with that size */ |
| 243 | } eraseblocks[NUM_ERASEREGIONS]; |
stefanct | 9e6b98a | 2011-05-28 02:37:14 +0000 | [diff] [blame] | 244 | /* a block_erase function should try to erase one block of size |
| 245 | * 'blocklen' at address 'blockaddr' and return 0 on success. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 246 | int (*block_erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen); |
hailfinger | 7df2136 | 2009-09-05 02:30:58 +0000 | [diff] [blame] | 247 | } block_erasers[NUM_ERASEFUNCTIONS]; |
| 248 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 249 | int (*printlock) (struct flashctx *flash); |
| 250 | int (*unlock) (struct flashctx *flash); |
Patrick Georgi | ab8353e | 2017-02-03 18:32:01 +0100 | [diff] [blame] | 251 | int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 252 | int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); |
Edward O'Callaghan | 4fe3a97 | 2019-06-19 16:56:10 +1000 | [diff] [blame] | 253 | int (*set_4ba) (struct flashctx *flash); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 254 | uint8_t (*read_status) (const struct flashctx *flash); |
| 255 | int (*write_status) (const struct flashctx *flash, int status); |
Duncan Laurie | 25a4ca2 | 2019-04-25 12:08:52 -0700 | [diff] [blame] | 256 | int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read); |
David Hendricks | 8c08421 | 2015-11-17 22:29:36 -0800 | [diff] [blame] | 257 | struct voltage_range voltage; |
Edward O'Callaghan | 10e63d9 | 2019-06-17 14:12:52 +1000 | [diff] [blame] | 258 | enum write_granularity gran; |
Edward O'Callaghan | 2d00129 | 2019-06-26 14:35:03 +1000 | [diff] [blame] | 259 | |
| 260 | /* SPI specific options (TODO: Make it a union in case other bustypes get specific options.) */ |
| 261 | uint8_t wrea_override; /**< override opcode for write extended address register */ |
| 262 | |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 263 | struct wp *wp; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 264 | }; |
| 265 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 266 | /* struct flashctx must always contain struct flashchip at the beginning. */ |
| 267 | struct flashctx { |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 268 | struct flashchip *chip; |
Edward O'Callaghan | 79357b3 | 2020-08-02 01:24:58 +1000 | [diff] [blame^] | 269 | /* FIXME: The memory mappings should be saved in a more structured way. */ |
| 270 | /* The physical_* fields store the respective addresses in the physical address space of the CPU. */ |
| 271 | uintptr_t physical_memory; |
| 272 | /* The virtual_* fields store where the respective physical address is mapped into flashrom's address |
| 273 | * space. A value equivalent to (chipaddr)ERROR_PTR indicates an invalid mapping (or none at all). */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 274 | chipaddr virtual_memory; |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 275 | /* Some flash devices have an additional register space; semantics are like above. */ |
Edward O'Callaghan | 79357b3 | 2020-08-02 01:24:58 +1000 | [diff] [blame^] | 276 | uintptr_t physical_registers; |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 277 | chipaddr virtual_registers; |
Edward O'Callaghan | 20596a8 | 2019-06-13 14:47:03 +1000 | [diff] [blame] | 278 | struct registered_master *mst; |
Edward O'Callaghan | a74ffcd | 2019-06-17 14:59:55 +1000 | [diff] [blame] | 279 | |
| 280 | /* We cache the state of the extended address register (highest byte |
| 281 | * of a 4BA for 3BA instructions) and the state of the 4BA mode here. |
| 282 | * If possible, we enter 4BA mode early. If that fails, we make use |
| 283 | * of the extended address register. |
| 284 | */ |
| 285 | int address_high_byte; |
| 286 | bool in_4ba_mode; |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | |
David Hendricks | 40df5b5 | 2016-12-22 15:36:28 -0800 | [diff] [blame] | 290 | /* Given RDID info, return pointer to entry in flashchips[] */ |
| 291 | const struct flashchip *flash_id_to_entry(uint32_t mfg_id, uint32_t model_id); |
| 292 | |
hailfinger | d5b3592 | 2009-06-03 14:46:22 +0000 | [diff] [blame] | 293 | /* Timing used in probe routines. ZERO is -2 to differentiate between an unset |
| 294 | * field and zero delay. |
Simon Glass | 8dc8273 | 2013-07-16 10:13:51 -0600 | [diff] [blame] | 295 | * |
hailfinger | d5b3592 | 2009-06-03 14:46:22 +0000 | [diff] [blame] | 296 | * SPI devices will always have zero delay and ignore this field. |
| 297 | */ |
| 298 | #define TIMING_FIXME -1 |
| 299 | /* this is intentionally same value as fixme */ |
| 300 | #define TIMING_IGNORED -1 |
| 301 | #define TIMING_ZERO -2 |
| 302 | |
hailfinger | 48ed3e2 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 303 | extern const struct flashchip flashchips[]; |
Edward O'Callaghan | 6240c85 | 2019-07-02 15:49:58 +1000 | [diff] [blame] | 304 | extern const unsigned int flashchips_size; |
| 305 | |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 306 | extern const struct flashchip flashchips_hwseq[]; |
ollie | 6a60099 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 307 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 308 | void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); |
| 309 | void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr); |
| 310 | void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr); |
Stuart langley | c98e43f | 2020-03-26 20:27:36 +1100 | [diff] [blame] | 311 | void chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 312 | uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr); |
| 313 | uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr); |
| 314 | uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr); |
| 315 | void chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len); |
| 316 | |
uwe | 884cc8b | 2009-06-17 12:07:12 +0000 | [diff] [blame] | 317 | /* print.c */ |
Edward O'Callaghan | ab4993a | 2019-11-09 21:36:17 +1100 | [diff] [blame] | 318 | int print_supported(void); |
hailfinger | a50d60e | 2009-11-17 09:57:34 +0000 | [diff] [blame] | 319 | void print_supported_wiki(void); |
uwe | a3a82c9 | 2009-05-15 17:02:34 +0000 | [diff] [blame] | 320 | |
Edward O'Callaghan | 8dd5792 | 2019-03-15 16:21:34 +1100 | [diff] [blame] | 321 | /* helpers.c */ |
| 322 | uint32_t address_to_bits(uint32_t addr); |
Edward O'Callaghan | 2fc166e | 2019-09-09 00:51:20 +1000 | [diff] [blame] | 323 | unsigned int bitcount(unsigned long a); |
Edward O'Callaghan | d2799ab | 2019-09-09 16:30:31 +1000 | [diff] [blame] | 324 | #undef MIN |
| 325 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 326 | #undef MAX |
| 327 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
Edward O'Callaghan | 8dd5792 | 2019-03-15 16:21:34 +1100 | [diff] [blame] | 328 | int max(int a, int b); |
Edward O'Callaghan | f78fffc | 2019-06-17 12:40:12 +1000 | [diff] [blame] | 329 | int min(int a, int b); |
Edward O'Callaghan | 8dd5792 | 2019-03-15 16:21:34 +1100 | [diff] [blame] | 330 | char *strcat_realloc(char *dest, const char *src); |
| 331 | void tolower_string(char *str); |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 332 | uint8_t reverse_byte(uint8_t x); |
| 333 | void reverse_bytes(uint8_t *dst, const uint8_t *src, size_t length); |
| 334 | #ifdef __MINGW32__ |
| 335 | char* strtok_r(char *str, const char *delim, char **nextp); |
| 336 | char *strndup(const char *str, size_t size); |
| 337 | #endif |
| 338 | #if defined(__DJGPP__) || (!defined(__LIBPAYLOAD__) && !defined(HAVE_STRNLEN)) |
| 339 | size_t strnlen(const char *str, size_t n); |
| 340 | #endif |
Edward O'Callaghan | 8dd5792 | 2019-03-15 16:21:34 +1100 | [diff] [blame] | 341 | |
uwe | 4529d20 | 2007-08-23 13:34:59 +0000 | [diff] [blame] | 342 | /* flashrom.c */ |
krause | 2eb7621 | 2011-01-17 07:50:42 +0000 | [diff] [blame] | 343 | extern const char flashrom_version[]; |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 344 | extern const char *chip_to_probe; |
Edward O'Callaghan | f78fffc | 2019-06-17 12:40:12 +1000 | [diff] [blame] | 345 | char *flashbuses_to_text(enum chipbustype bustype); |
| 346 | extern enum chipbustype buses_supported; |
Edward O'Callaghan | 79357b3 | 2020-08-02 01:24:58 +1000 | [diff] [blame^] | 347 | int map_flash(struct flashctx *flash); |
| 348 | void unmap_flash(struct flashctx *flash); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 349 | int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); |
| 350 | int erase_flash(struct flashctx *flash); |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 351 | int probe_flash(struct registered_master *mst, int startchip, struct flashctx *fill_flash, int force); |
Edward O'Callaghan | f78fffc | 2019-06-17 12:40:12 +1000 | [diff] [blame] | 352 | int read_flash(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 353 | int read_flash_to_file(struct flashctx *flash, const char *filename); |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 354 | char *extract_param(const char *const *haystack, const char *needle, const char *delim); |
Edward O'Callaghan | 445b48b | 2020-08-13 12:25:17 +1000 | [diff] [blame] | 355 | int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len); |
hailfinger | 92cd8e3 | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 356 | void print_version(void); |
Souvik Ghosh | 3c963a4 | 2016-07-19 18:48:15 -0700 | [diff] [blame] | 357 | void print_buildinfo(void); |
hailfinger | 74819ad | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 358 | void print_banner(void); |
hailfinger | f79d171 | 2010-10-06 23:48:34 +0000 | [diff] [blame] | 359 | void list_programmers_linebreak(int startcol, int cols, int paren); |
hailfinger | 92cd8e3 | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 360 | int selfcheck(void); |
Edward O'Callaghan | f78fffc | 2019-06-17 12:40:12 +1000 | [diff] [blame] | 361 | int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename); |
Edward O'Callaghan | b2257cc | 2020-07-25 22:19:47 +1000 | [diff] [blame] | 362 | int write_buf_to_file(const unsigned char *buf, unsigned long size, const char *filename); |
Vadim Bendebury | 2f346a3 | 2018-05-21 10:24:18 -0700 | [diff] [blame] | 363 | |
| 364 | /* |
| 365 | * |
| 366 | * The main processing function of flashrom utility; it is invoked once |
| 367 | * command line parameters are processed and verified, and the type of the |
| 368 | * flash chip the programmer operates on has been determined. |
| 369 | * |
| 370 | * @flash pointer to the flash context matching the chip detected |
| 371 | * during initialization. |
| 372 | * @force when set proceed even if the chip is not known to work |
| 373 | * @filename pointer to the name of the file to read from or write to |
| 374 | * @read_it when true, flash contents are read into 'filename' |
| 375 | * @write_it when true, flash is programmed with 'filename' contents |
| 376 | * @erase_it when true, flash chip is erased |
| 377 | * @verify_it depending on the value verify the full chip, only changed |
| 378 | * areas, or none |
| 379 | * @extract_it extract all known flash chip regions into separate files |
| 380 | * @diff_file when deciding what areas to program, use this file's |
| 381 | * contents instead of reading the current chip contents |
| 382 | * @do_diff when true - compare result of the operation with either the |
| 383 | * original chip contents for 'diff_file' contents, is present. |
| 384 | * When false - do not diff, consider the chip erased before |
| 385 | * operation starts. |
| 386 | * |
| 387 | * Only one of 'read_it', 'write_it', and 'erase_it' is expected to be set, |
| 388 | * but this is not enforced. |
| 389 | * |
| 390 | * 'do_diff' must be set if 'diff_file' is set. If 'do_diff' is set, but |
| 391 | * 'diff_file' is not - comparison is done against the pre-operation chip |
| 392 | * contents. |
| 393 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 394 | int doit(struct flashctx *flash, int force, const char *filename, int read_it, |
Simon Glass | 9ad06c1 | 2013-07-03 22:08:17 +0900 | [diff] [blame] | 395 | int write_it, int erase_it, int verify_it, int extract_it, |
Vadim Bendebury | 2f346a3 | 2018-05-21 10:24:18 -0700 | [diff] [blame] | 396 | const char *diff_file, int do_diff); |
uwe | 884cc8b | 2009-06-17 12:07:12 +0000 | [diff] [blame] | 397 | |
| 398 | #define OK 0 |
| 399 | #define NT 1 /* Not tested */ |
uwe | 4529d20 | 2007-08-23 13:34:59 +0000 | [diff] [blame] | 400 | |
David Hendricks | 1ed1d35 | 2011-11-23 17:54:37 -0800 | [diff] [blame] | 401 | /* what to do in case of an error */ |
| 402 | enum error_action { |
| 403 | error_fail, /* fail immediately */ |
| 404 | error_ignore, /* non-fatal error; continue */ |
| 405 | }; |
| 406 | |
uwe | 97e8e27 | 2011-09-03 17:15:00 +0000 | [diff] [blame] | 407 | /* Something happened that shouldn't happen, but we can go on. */ |
mkarcher | 74d3013 | 2010-07-22 18:04:15 +0000 | [diff] [blame] | 408 | #define ERROR_NONFATAL 0x100 |
| 409 | |
uwe | 97e8e27 | 2011-09-03 17:15:00 +0000 | [diff] [blame] | 410 | /* Something happened that shouldn't happen, we'll abort. */ |
| 411 | #define ERROR_FATAL -0xee |
Edward O'Callaghan | 20596a8 | 2019-06-13 14:47:03 +1000 | [diff] [blame] | 412 | #define ERROR_FLASHROM_BUG -200 |
| 413 | /* We reached one of the hardcoded limits of flashrom. This can be fixed by |
| 414 | * increasing the limit of a compile-time allocation or by switching to dynamic |
| 415 | * allocation. |
| 416 | * Note: If this warning is triggered, check first for runaway registrations. |
| 417 | */ |
| 418 | #define ERROR_FLASHROM_LIMIT -201 |
| 419 | |
David Hendricks | 1ed1d35 | 2011-11-23 17:54:37 -0800 | [diff] [blame] | 420 | /* Operation failed due to access restriction set in programmer or flash chip */ |
| 421 | #define ACCESS_DENIED -7 |
| 422 | extern enum error_action access_denied_action; |
| 423 | |
| 424 | /* convenience function for checking return codes */ |
| 425 | extern int ignore_error(int x); |
| 426 | |
Edward O'Callaghan | 83c7700 | 2019-06-04 15:56:19 +1000 | [diff] [blame] | 427 | /* cli_common.c */ |
Edward O'Callaghan | 71e30b4 | 2019-06-04 16:16:13 +1000 | [diff] [blame] | 428 | void print_chip_support_status(const struct flashchip *chip); |
Edward O'Callaghan | 83c7700 | 2019-06-04 15:56:19 +1000 | [diff] [blame] | 429 | |
snelson | 9cba3c6 | 2010-01-07 20:09:33 +0000 | [diff] [blame] | 430 | /* cli_output.c */ |
Edward O'Callaghan | 83c7700 | 2019-06-04 15:56:19 +1000 | [diff] [blame] | 431 | extern enum flashrom_log_level verbose_screen; |
| 432 | extern enum flashrom_log_level verbose_logfile; |
Souvik Ghosh | 3c963a4 | 2016-07-19 18:48:15 -0700 | [diff] [blame] | 433 | #ifndef STANDALONE |
| 434 | int open_logfile(const char * const filename); |
| 435 | int close_logfile(void); |
| 436 | void start_logging(void); |
| 437 | #endif |
Edward O'Callaghan | 8d8d397 | 2019-02-24 20:40:10 +1100 | [diff] [blame] | 438 | enum flashrom_log_level { |
| 439 | FLASHROM_MSG_ERROR = 0, |
| 440 | FLASHROM_MSG_WARN = 1, |
| 441 | FLASHROM_MSG_INFO = 2, |
| 442 | FLASHROM_MSG_DEBUG = 3, |
| 443 | FLASHROM_MSG_DEBUG2 = 4, |
| 444 | FLASHROM_MSG_SPEW = 5, |
Patrick Georgi | dbde2f1 | 2017-02-03 18:07:45 +0100 | [diff] [blame] | 445 | }; |
hailfinger | 63932d4 | 2010-06-04 23:20:21 +0000 | [diff] [blame] | 446 | /* Let gcc and clang check for correct printf-style format strings. */ |
Edward O'Callaghan | 8d8d397 | 2019-02-24 20:40:10 +1100 | [diff] [blame] | 447 | int print(enum flashrom_log_level level, const char *fmt, ...) |
Patrick Georgi | dbde2f1 | 2017-02-03 18:07:45 +0100 | [diff] [blame] | 448 | #ifdef __MINGW32__ |
Edward O'Callaghan | c4d1f1c | 2020-04-17 13:27:23 +1000 | [diff] [blame] | 449 | # ifndef __MINGW_PRINTF_FORMAT |
| 450 | # define __MINGW_PRINTF_FORMAT gnu_printf |
| 451 | # endif |
| 452 | __attribute__((format(__MINGW_PRINTF_FORMAT, 2, 3))); |
Patrick Georgi | dbde2f1 | 2017-02-03 18:07:45 +0100 | [diff] [blame] | 453 | #else |
| 454 | __attribute__((format(printf, 2, 3))); |
| 455 | #endif |
Edward O'Callaghan | 8d8d397 | 2019-02-24 20:40:10 +1100 | [diff] [blame] | 456 | #define msg_gerr(...) print(FLASHROM_MSG_ERROR, __VA_ARGS__) /* general errors */ |
| 457 | #define msg_perr(...) print(FLASHROM_MSG_ERROR, __VA_ARGS__) /* programmer errors */ |
| 458 | #define msg_cerr(...) print(FLASHROM_MSG_ERROR, __VA_ARGS__) /* chip errors */ |
| 459 | #define msg_gwarn(...) print(FLASHROM_MSG_WARN, __VA_ARGS__) /* general warnings */ |
| 460 | #define msg_pwarn(...) print(FLASHROM_MSG_WARN, __VA_ARGS__) /* programmer warnings */ |
| 461 | #define msg_cwarn(...) print(FLASHROM_MSG_WARN, __VA_ARGS__) /* chip warnings */ |
| 462 | #define msg_ginfo(...) print(FLASHROM_MSG_INFO, __VA_ARGS__) /* general info */ |
| 463 | #define msg_pinfo(...) print(FLASHROM_MSG_INFO, __VA_ARGS__) /* programmer info */ |
| 464 | #define msg_cinfo(...) print(FLASHROM_MSG_INFO, __VA_ARGS__) /* chip info */ |
| 465 | #define msg_gdbg(...) print(FLASHROM_MSG_DEBUG, __VA_ARGS__) /* general debug */ |
| 466 | #define msg_pdbg(...) print(FLASHROM_MSG_DEBUG, __VA_ARGS__) /* programmer debug */ |
| 467 | #define msg_cdbg(...) print(FLASHROM_MSG_DEBUG, __VA_ARGS__) /* chip debug */ |
| 468 | #define msg_gdbg2(...) print(FLASHROM_MSG_DEBUG2, __VA_ARGS__) /* general debug2 */ |
| 469 | #define msg_pdbg2(...) print(FLASHROM_MSG_DEBUG2, __VA_ARGS__) /* programmer debug2 */ |
| 470 | #define msg_cdbg2(...) print(FLASHROM_MSG_DEBUG2, __VA_ARGS__) /* chip debug2 */ |
| 471 | #define msg_gspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* general debug spew */ |
| 472 | #define msg_pspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* programmer debug spew */ |
| 473 | #define msg_cspew(...) print(FLASHROM_MSG_SPEW, __VA_ARGS__) /* chip debug spew */ |
snelson | 9cba3c6 | 2010-01-07 20:09:33 +0000 | [diff] [blame] | 474 | |
stepan | 745615e | 2007-10-15 21:44:47 +0000 | [diff] [blame] | 475 | /* spi.c */ |
hailfinger | 68002c2 | 2009-07-10 21:08:55 +0000 | [diff] [blame] | 476 | struct spi_command { |
| 477 | unsigned int writecnt; |
| 478 | unsigned int readcnt; |
| 479 | const unsigned char *writearr; |
| 480 | unsigned char *readarr; |
| 481 | }; |
Nico Huber | 4c8a956 | 2017-10-15 11:20:58 +0200 | [diff] [blame] | 482 | #define NULL_SPI_CMD { 0, 0, NULL, NULL, } |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 483 | int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, |
uwe | fa98ca1 | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 484 | const unsigned char *writearr, unsigned char *readarr); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 485 | int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds); |
uwe | af9b4df | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 486 | |
David Hendricks | 8c08421 | 2015-11-17 22:29:36 -0800 | [diff] [blame] | 487 | #define NUM_VOLTAGE_RANGES 16 |
| 488 | extern struct voltage_range voltage_ranges[]; |
| 489 | /* returns number of unique voltage ranges, or <0 to indicate failure */ |
| 490 | extern int flash_supported_voltage_ranges(enum chipbustype bus); |
| 491 | |
Edward O'Callaghan | 4b94057 | 2019-08-02 01:44:47 +1000 | [diff] [blame] | 492 | enum chipbustype get_buses_supported(void); |
ollie | 5b62157 | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 493 | #endif /* !__FLASH_H__ */ |