blob: a356d514c6737dc76ef34840140eb26525247f4f [file] [log] [blame]
hailfingera9df33c2009-05-09 00:54:55 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009 Carl-Daniel Hailfinger
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
hailfingera9df33c2009-05-09 00:54:55 +000021#include <string.h>
22#include <stdlib.h>
hailfinger668f3502009-06-01 00:02:11 +000023#include <ctype.h>
hailfingera9df33c2009-05-09 00:54:55 +000024#include <sys/types.h>
hailfingera9df33c2009-05-09 00:54:55 +000025#include "flash.h"
hailfingera8727712010-06-20 10:58:32 +000026#include "chipdrivers.h"
hailfinger428f6852010-07-27 22:41:39 +000027#include "programmer.h"
hailfingera9df33c2009-05-09 00:54:55 +000028
hailfinger1ef766d2010-07-06 09:55:48 +000029static void tolower_string(char *str)
30{
31 for (; *str != '\0'; str++)
32 *str = (char)tolower((unsigned char)*str);
33}
34
hailfingera9df33c2009-05-09 00:54:55 +000035int dummy_init(void)
36{
hailfinger1ef766d2010-07-06 09:55:48 +000037 char *bustext = NULL;
38
hailfinger50c335f2010-01-09 04:32:23 +000039 msg_pspew("%s\n", __func__);
hailfinger668f3502009-06-01 00:02:11 +000040
hailfingerddeb4ac2010-07-08 10:13:37 +000041 bustext = extract_programmer_param("bus");
hailfinger1ef766d2010-07-06 09:55:48 +000042 msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
43 if (!bustext)
44 bustext = strdup("parallel+lpc+fwh+spi");
hailfinger668f3502009-06-01 00:02:11 +000045 /* Convert the parameters to lowercase. */
hailfinger1ef766d2010-07-06 09:55:48 +000046 tolower_string(bustext);
hailfinger668f3502009-06-01 00:02:11 +000047
48 buses_supported = CHIP_BUSTYPE_NONE;
hailfinger1ef766d2010-07-06 09:55:48 +000049 if (strstr(bustext, "parallel")) {
hailfinger668f3502009-06-01 00:02:11 +000050 buses_supported |= CHIP_BUSTYPE_PARALLEL;
hailfinger50c335f2010-01-09 04:32:23 +000051 msg_pdbg("Enabling support for %s flash.\n", "parallel");
hailfinger668f3502009-06-01 00:02:11 +000052 }
hailfinger1ef766d2010-07-06 09:55:48 +000053 if (strstr(bustext, "lpc")) {
hailfinger668f3502009-06-01 00:02:11 +000054 buses_supported |= CHIP_BUSTYPE_LPC;
hailfinger50c335f2010-01-09 04:32:23 +000055 msg_pdbg("Enabling support for %s flash.\n", "LPC");
hailfinger668f3502009-06-01 00:02:11 +000056 }
hailfinger1ef766d2010-07-06 09:55:48 +000057 if (strstr(bustext, "fwh")) {
hailfinger668f3502009-06-01 00:02:11 +000058 buses_supported |= CHIP_BUSTYPE_FWH;
hailfinger50c335f2010-01-09 04:32:23 +000059 msg_pdbg("Enabling support for %s flash.\n", "FWH");
hailfinger668f3502009-06-01 00:02:11 +000060 }
hailfinger1ef766d2010-07-06 09:55:48 +000061 if (strstr(bustext, "spi")) {
hailfinger668f3502009-06-01 00:02:11 +000062 buses_supported |= CHIP_BUSTYPE_SPI;
63 spi_controller = SPI_CONTROLLER_DUMMY;
hailfinger50c335f2010-01-09 04:32:23 +000064 msg_pdbg("Enabling support for %s flash.\n", "SPI");
hailfinger668f3502009-06-01 00:02:11 +000065 }
66 if (buses_supported == CHIP_BUSTYPE_NONE)
hailfinger50c335f2010-01-09 04:32:23 +000067 msg_pdbg("Support for all flash bus types disabled.\n");
hailfinger1ef766d2010-07-06 09:55:48 +000068 free(bustext);
uwe75f401f2009-06-02 19:54:22 +000069 return 0;
hailfingera9df33c2009-05-09 00:54:55 +000070}
71
72int dummy_shutdown(void)
73{
hailfinger50c335f2010-01-09 04:32:23 +000074 msg_pspew("%s\n", __func__);
hailfingera9df33c2009-05-09 00:54:55 +000075 return 0;
76}
77
hailfinger11ae3c42009-05-11 14:13:25 +000078void *dummy_map(const char *descr, unsigned long phys_addr, size_t len)
79{
hailfinger50c335f2010-01-09 04:32:23 +000080 msg_pspew("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n",
81 __func__, descr, (unsigned long)len, phys_addr);
hailfinger11ae3c42009-05-11 14:13:25 +000082 return (void *)phys_addr;
83}
84
85void dummy_unmap(void *virt_addr, size_t len)
86{
hailfinger50c335f2010-01-09 04:32:23 +000087 msg_pspew("%s: Unmapping 0x%lx bytes at %p\n",
88 __func__, (unsigned long)len, virt_addr);
hailfinger11ae3c42009-05-11 14:13:25 +000089}
90
hailfinger82719632009-05-16 21:22:56 +000091void dummy_chip_writeb(uint8_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +000092{
hailfinger50c335f2010-01-09 04:32:23 +000093 msg_pspew("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +000094}
95
hailfinger82719632009-05-16 21:22:56 +000096void dummy_chip_writew(uint16_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +000097{
hailfinger50c335f2010-01-09 04:32:23 +000098 msg_pspew("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +000099}
100
hailfinger82719632009-05-16 21:22:56 +0000101void dummy_chip_writel(uint32_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000102{
hailfinger50c335f2010-01-09 04:32:23 +0000103 msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000104}
105
hailfinger9d987ef2009-06-05 18:32:07 +0000106void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len)
107{
108 size_t i;
hailfinger50c335f2010-01-09 04:32:23 +0000109 msg_pspew("%s: addr=0x%lx, len=0x%08lx, writing data (hex):",
110 __func__, addr, (unsigned long)len);
hailfinger9d987ef2009-06-05 18:32:07 +0000111 for (i = 0; i < len; i++) {
112 if ((i % 16) == 0)
hailfinger50c335f2010-01-09 04:32:23 +0000113 msg_pspew("\n");
114 msg_pspew("%02x ", buf[i]);
hailfinger9d987ef2009-06-05 18:32:07 +0000115 }
116}
117
hailfinger82719632009-05-16 21:22:56 +0000118uint8_t dummy_chip_readb(const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000119{
hailfinger50c335f2010-01-09 04:32:23 +0000120 msg_pspew("%s: addr=0x%lx, returning 0xff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000121 return 0xff;
122}
123
hailfinger82719632009-05-16 21:22:56 +0000124uint16_t dummy_chip_readw(const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000125{
hailfinger50c335f2010-01-09 04:32:23 +0000126 msg_pspew("%s: addr=0x%lx, returning 0xffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000127 return 0xffff;
128}
129
hailfinger82719632009-05-16 21:22:56 +0000130uint32_t dummy_chip_readl(const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000131{
hailfinger50c335f2010-01-09 04:32:23 +0000132 msg_pspew("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000133 return 0xffffffff;
134}
135
hailfinger9d987ef2009-06-05 18:32:07 +0000136void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len)
137{
hailfinger50c335f2010-01-09 04:32:23 +0000138 msg_pspew("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n",
139 __func__, addr, (unsigned long)len);
hailfinger9d987ef2009-06-05 18:32:07 +0000140 memset(buf, 0xff, len);
141 return;
142}
143
hailfinger68002c22009-07-10 21:08:55 +0000144int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
hailfingerf91e3b52009-05-14 12:59:36 +0000145 const unsigned char *writearr, unsigned char *readarr)
146{
147 int i;
148
hailfinger50c335f2010-01-09 04:32:23 +0000149 msg_pspew("%s:", __func__);
hailfingerf91e3b52009-05-14 12:59:36 +0000150
hailfinger50c335f2010-01-09 04:32:23 +0000151 msg_pspew(" writing %u bytes:", writecnt);
hailfingerf91e3b52009-05-14 12:59:36 +0000152 for (i = 0; i < writecnt; i++)
hailfinger50c335f2010-01-09 04:32:23 +0000153 msg_pspew(" 0x%02x", writearr[i]);
hailfingerf91e3b52009-05-14 12:59:36 +0000154
hailfinger50c335f2010-01-09 04:32:23 +0000155 msg_pspew(" reading %u bytes:", readcnt);
hailfingerf91e3b52009-05-14 12:59:36 +0000156 for (i = 0; i < readcnt; i++) {
hailfinger50c335f2010-01-09 04:32:23 +0000157 msg_pspew(" 0xff");
hailfingerf91e3b52009-05-14 12:59:36 +0000158 readarr[i] = 0xff;
159 }
160
hailfinger50c335f2010-01-09 04:32:23 +0000161 msg_pspew("\n");
hailfingerf91e3b52009-05-14 12:59:36 +0000162 return 0;
163}
hailfingera8727712010-06-20 10:58:32 +0000164
165int dummy_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
166{
167 /* Maximum read length is unlimited, use 64kB. */
168 return spi_read_chunked(flash, buf, start, len, 64 * 1024);
169}
170
hailfingerc7d06c62010-07-14 16:19:05 +0000171/* Is is impossible to trigger this code path because dummyflasher probing will
172 * never be successful, and the current frontend refuses to write in that case.
173 * Other frontends may allow writing even for non-detected chips, though.
174 */
175int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
176{
hailfingerc7d06c62010-07-14 16:19:05 +0000177 return spi_write_chunked(flash, buf, start, len, 256);
178}