[flashrom] [PATCH] TotalPhase Cheetah support stub

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Wed Nov 25 15:16:34 CET 2009


I wrote this Cheetah support stub months ago and carried it forward over
various interface changes. I don't have the hardware, so I'm not really
motivated to finish this.

This patch does:
- Hook up Cheetah support in the generic code
- Make sure it is disabled by default (zero footprint in the binary)
- Provide some #if 0 code as a good starting point
- Provide a compilable skeleton to be filled in

TODO for anyone who cares about Cheetah support:
- Implement cheetah_spi_init
- Implement cheetah_spi_shutdown
- Add an #include for the cheetah headers
- Change #if 0 to #if 1.

Given that this patch makes sure to have zero impact on the binary
(because it is compiled out by default) and because it lowers the
barrier for someone else to come and implement the rest of cheetah
support, I'm for merging.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

Index: flashrom-cheetah/flashrom.8
===================================================================
--- flashrom-cheetah/flashrom.8	(Revision 777)
+++ flashrom-cheetah/flashrom.8	(Arbeitskopie)
@@ -154,6 +154,8 @@
 .sp
 .BR "* buspiratespi" " (for flash ROMs attached to a Bus Pirate)"
 .sp
+.BR "* cheetah" " (for flash ROMs attached to a TotalPhase Cheetah SPI programmer)"
+.sp
 The dummy programmer has an optional parameter specifying the bus types it
 should support. For that you have to use the
 .B "flashrom -p dummy:type"
Index: flashrom-cheetah/flash.h
===================================================================
--- flashrom-cheetah/flash.h	(Revision 777)
+++ flashrom-cheetah/flash.h	(Arbeitskopie)
@@ -107,6 +107,9 @@
 #if BUSPIRATE_SPI_SUPPORT == 1
 	PROGRAMMER_BUSPIRATESPI,
 #endif
+#if CHEETAH_SUPPORT == 1
+	PROGRAMMER_CHEETAH,
+#endif
 	PROGRAMMER_INVALID /* This must always be the last entry. */
 };
 
@@ -497,6 +500,14 @@
 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);
 
+/* cheetah.c */
+int cheetah_spi_init(void);
+int cheetah_spi_shutdown(void);
+int cheetah_spi_command(unsigned int writecnt, unsigned int readcnt,
+			const unsigned char *writearr, unsigned char *readarr);
+int cheetah_spi_write_256(struct flashchip *flash, uint8_t *buf);
+int cheetah_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
+
 /* flashrom.c */
 extern char *programmer_param;
 extern int verbose;
@@ -538,6 +549,9 @@
 #if FT2232_SPI_SUPPORT == 1
 	SPI_CONTROLLER_FT2232,
 #endif
+#if CHEETAH_SUPPORT == 1
+	SPI_CONTROLLER_CHEETAH,
+#endif
 #if DUMMY_SUPPORT == 1
 	SPI_CONTROLLER_DUMMY,
 #endif
Index: flashrom-cheetah/spi.c
===================================================================
--- flashrom-cheetah/spi.c	(Revision 777)
+++ flashrom-cheetah/spi.c	(Arbeitskopie)
@@ -91,6 +91,15 @@
 	},
 #endif
 
+#if CHEETAH_SUPPORT == 1
+	{ /* SPI_CONTROLLER_CHEETAH */
+		.command = cheetah_spi_command,
+		.multicommand = default_spi_send_multicommand,
+		.read = cheetah_spi_read,
+		.write_256 = spi_chip_write_1,
+	},
+#endif
+
 #if DUMMY_SUPPORT == 1
 	{ /* SPI_CONTROLLER_DUMMY */
 		.command = dummy_spi_send_command,
@@ -316,6 +325,9 @@
 #if FT2232_SPI_SUPPORT == 1
 	case SPI_CONTROLLER_FT2232:
 #endif
+#if CHEETAH_SUPPORT == 1
+	case SPI_CONTROLLER_CHEETAH:
+#endif
 #if DUMMY_SUPPORT == 1
 	case SPI_CONTROLLER_DUMMY:
 #endif
Index: flashrom-cheetah/Makefile
===================================================================
--- flashrom-cheetah/Makefile	(Revision 777)
+++ flashrom-cheetah/Makefile	(Arbeitskopie)
@@ -71,6 +71,9 @@
 # Bitbanging SPI infrastructure is not used yet.
 CONFIG_BITBANG_SPI ?= no
 
+# Cheetah support is unfinished.
+CONFIG_CHEETAH ?= no
+
 # Always enable 3Com NICs for now.
 CONFIG_NIC3COM ?= yes
 
@@ -108,6 +111,11 @@
 OBJS += bitbang_spi.o
 endif
 
+ifeq ($(CONFIG_CHEETAH), yes)
+FEATURE_CFLAGS += -D'CHEETAH_SUPPORT=1'
+OBJS += cheetah.o
+endif
+
 ifeq ($(CONFIG_NIC3COM), yes)
 FEATURE_CFLAGS += -D'NIC3COM_SUPPORT=1'
 OBJS += nic3com.o
Index: flashrom-cheetah/cheetah.c
===================================================================
--- flashrom-cheetah/cheetah.c	(Revision 0)
+++ flashrom-cheetah/cheetah.c	(Revision 0)
@@ -0,0 +1,72 @@
+/*
+ * 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; version 2 of the License.
+ * As a special exception, you may also incorporate this code into programs
+ * licensed under later versions of the GNU GPL provided your changes to
+ * this code are made available under the same conditions as the original code.
+ *
+ * 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>
+#include "flash.h"
+
+int cheetah_spi_init(void)
+{
+	printf("Cheetah support not yet implemented completely.\n");
+	buses_supported = CHIP_BUSTYPE_SPI;
+	spi_controller = SPI_CONTROLLER_CHEETAH;
+	return 0;
+}
+
+int cheetah_spi_shutdown(void)
+{
+	return 0;
+}
+
+int cheetah_spi_command(unsigned int writecnt, unsigned int readcnt,
+			const unsigned char *writearr, unsigned char *readarr)
+{
+	unsigned char *bufout = malloc(writecnt + readcnt);
+	unsigned char *bufin = malloc(writecnt + readcnt);
+	memcpy(bufout, writearr, writecnt);
+	/* Shift out 0x00 while reading data. */
+	memset(bufout + writecnt, 0x00, readcnt);
+	/* Make sure any non-read data is 0xff. */
+	memset(bufin + writecnt, 0xff, readcnt);
+#if 0
+	ch_spi_queue_clear(handle);
+	ch_spi_queue_oe(handle, 1);
+	ch_spi_queue_ss(handle, 1);
+	ch_spi_queue_array(handle, writecnt + readcnt, bufout);
+	ch_spi_queue_ss(handle, 0);
+	ch_spi_queue_oe(handle, 0);
+	ch_spi_batch_shift(handle, writecnt + readcnt, bufin);
+	ch_spi_queue_clear(handle);
+#endif
+	memcpy(readarr, bufin + writecnt, readcnt);
+	free(bufout);
+	free(bufin);
+	return 0;
+}
+
+int cheetah_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
+{
+	/* Maximum read length is 256 bytes. */
+	return spi_read_chunked(flash, buf, start, len, 256);
+}
+
+/* We could do 256-byte writes, but for now we use the generic 1-byte code. */
Index: flashrom-cheetah/flashrom.c
===================================================================
--- flashrom-cheetah/flashrom.c	(Revision 777)
+++ flashrom-cheetah/flashrom.c	(Arbeitskopie)
@@ -223,6 +223,25 @@
 	},
 #endif
 
+#if CHEETAH_SUPPORT == 1
+	{
+		.name			= "cheetah",
+		.init			= cheetah_spi_init,
+		.shutdown		= cheetah_spi_shutdown,
+		.map_flash_region	= dummy_map,
+		.unmap_flash_region	= dummy_unmap,
+		.chip_readb		= noop_chip_readb,
+		.chip_readw		= fallback_chip_readw,
+		.chip_readl		= fallback_chip_readl,
+		.chip_readn		= fallback_chip_readn,
+		.chip_writeb		= noop_chip_writeb,
+		.chip_writew		= fallback_chip_writew,
+		.chip_writel		= fallback_chip_writel,
+		.chip_writen		= fallback_chip_writen,
+		.delay			= internal_delay,
+	},
+#endif
+
 	{}, /* This entry corresponds to PROGRAMMER_INVALID. */
 };
 


-- 
Developer quote of the month: 
"We are juggling too many chainsaws and flaming arrows and tigers."





More information about the flashrom mailing list