dummyflasher.c 4.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * This file is part of the flashrom project.
 *
 * Copyright (C) 2009 Carl-Daniel Hailfinger
 *
 * 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.
 *
 * 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.
 *
 * 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
 */

#include <string.h>
#include <stdlib.h>
23
#include <ctype.h>
24 25
#include <sys/types.h>
#include "flash.h"
26
#include "chipdrivers.h"
27
#include "programmer.h"
28

29 30 31 32 33 34
static void tolower_string(char *str)
{
	for (; *str != '\0'; str++)
		*str = (char)tolower((unsigned char)*str);
}

35 36
int dummy_init(void)
{
37 38
	char *bustext = NULL;

39
	msg_pspew("%s\n", __func__);
40

41
	bustext = extract_programmer_param("bus");
42 43 44
	msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
	if (!bustext)
		bustext = strdup("parallel+lpc+fwh+spi");
45
	/* Convert the parameters to lowercase. */
46
	tolower_string(bustext);
47 48

	buses_supported = CHIP_BUSTYPE_NONE;
49
	if (strstr(bustext, "parallel")) {
50
		buses_supported |= CHIP_BUSTYPE_PARALLEL;
51
		msg_pdbg("Enabling support for %s flash.\n", "parallel");
52
	}
53
	if (strstr(bustext, "lpc")) {
54
		buses_supported |= CHIP_BUSTYPE_LPC;
55
		msg_pdbg("Enabling support for %s flash.\n", "LPC");
56
	}
57
	if (strstr(bustext, "fwh")) {
58
		buses_supported |= CHIP_BUSTYPE_FWH;
59
		msg_pdbg("Enabling support for %s flash.\n", "FWH");
60
	}
61
	if (strstr(bustext, "spi")) {
62 63
		buses_supported |= CHIP_BUSTYPE_SPI;
		spi_controller = SPI_CONTROLLER_DUMMY;
64
		msg_pdbg("Enabling support for %s flash.\n", "SPI");
65 66
	}
	if (buses_supported == CHIP_BUSTYPE_NONE)
67
		msg_pdbg("Support for all flash bus types disabled.\n");
68
	free(bustext);
69
	return 0;
70 71 72 73
}

int dummy_shutdown(void)
{
74
	msg_pspew("%s\n", __func__);
75 76 77
	return 0;
}

78 79
void *dummy_map(const char *descr, unsigned long phys_addr, size_t len)
{
80 81
	msg_pspew("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n",
		  __func__, descr, (unsigned long)len, phys_addr);
82 83 84 85 86
	return (void *)phys_addr;
}

void dummy_unmap(void *virt_addr, size_t len)
{
87 88
	msg_pspew("%s: Unmapping 0x%lx bytes at %p\n",
		  __func__, (unsigned long)len, virt_addr);
89 90
}

91
void dummy_chip_writeb(uint8_t val, chipaddr addr)
92
{
93
	msg_pspew("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val);
94 95
}

96
void dummy_chip_writew(uint16_t val, chipaddr addr)
97
{
98
	msg_pspew("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val);
99 100
}

101
void dummy_chip_writel(uint32_t val, chipaddr addr)
102
{
103
	msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
104 105
}

106 107 108
void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len)
{
	size_t i;
109 110
	msg_pspew("%s: addr=0x%lx, len=0x%08lx, writing data (hex):",
		  __func__, addr, (unsigned long)len);
111 112
	for (i = 0; i < len; i++) {
		if ((i % 16) == 0)
113 114
			msg_pspew("\n");
		msg_pspew("%02x ", buf[i]);
115 116 117
	}
}

118
uint8_t dummy_chip_readb(const chipaddr addr)
119
{
120
	msg_pspew("%s:  addr=0x%lx, returning 0xff\n", __func__, addr);
121 122 123
	return 0xff;
}

124
uint16_t dummy_chip_readw(const chipaddr addr)
125
{
126
	msg_pspew("%s:  addr=0x%lx, returning 0xffff\n", __func__, addr);
127 128 129
	return 0xffff;
}

130
uint32_t dummy_chip_readl(const chipaddr addr)
131
{
132
	msg_pspew("%s:  addr=0x%lx, returning 0xffffffff\n", __func__, addr);
133 134 135
	return 0xffffffff;
}

136 137
void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len)
{
138 139
	msg_pspew("%s:  addr=0x%lx, len=0x%lx, returning array of 0xff\n",
		  __func__, addr, (unsigned long)len);
140 141 142 143
	memset(buf, 0xff, len);
	return;
}

144
int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
145 146 147 148
		      const unsigned char *writearr, unsigned char *readarr)
{
	int i;

149
	msg_pspew("%s:", __func__);
150

151
	msg_pspew(" writing %u bytes:", writecnt);
152
	for (i = 0; i < writecnt; i++)
153
		msg_pspew(" 0x%02x", writearr[i]);
154

155
	msg_pspew(" reading %u bytes:", readcnt);
156
	for (i = 0; i < readcnt; i++) {
157
		msg_pspew(" 0xff");
158 159 160
		readarr[i] = 0xff;
	}

161
	msg_pspew("\n");
162 163
	return 0;
}
164 165 166 167 168 169 170

int dummy_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
{
	/* Maximum read length is unlimited, use 64kB. */
	return spi_read_chunked(flash, buf, start, len, 64 * 1024);
}

171 172 173 174 175 176 177 178
/* Is is impossible to trigger this code path because dummyflasher probing will
 * never be successful, and the current frontend refuses to write in that case.
 * Other frontends may allow writing even for non-detected chips, though.
 */
int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len)
{
	return spi_write_chunked(flash, buf, start, len, 256);
}