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@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. */ };
Hi Richard,
I remember that you once wrote that Cheetah support for flashrom would be desirable. I just posted a stub patch with Cheetah support to the flashrom mailing list. You may be interested in subscribing to the flashrom list: http://www.flashrom.org/mailman/listinfo/flashrom The patch is available for download here: http://patchwork.coreboot.org/patch/596/raw/
Regards, Carl-Daniel
On 25.11.2009 15:16, Carl-Daniel Hailfinger wrote:
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@gmx.net
Hi Richard,
I remember that you once wrote that Cheetah support for flashrom would be desirable. I just posted a stub patch with Cheetah support to the flashrom mailing list. You may be interested in subscribing to the flashrom list: http://www.flashrom.org/mailman/listinfo/flashrom
Right not I just would not have time to stay current. If there's a specific cheetah thread then you can point it out and I'll check the archives. Perhaps I should add the list to my mail with a filter on the word cheetah.
The patch is available for download here: http://patchwork.coreboot.org/patch/596/raw/
Is there anything I can test with this patch? I've enabled cheetah support in the makefile but If I change the #if 0 in cheetah_spi_comand I get compile errors.
Also I'll need some sort of switch to enable the target voltage of the programmer.
On 30.11.2009 00:23, Richard A. Smith wrote:
I remember that you once wrote that Cheetah support for flashrom would be desirable. I just posted a stub patch with Cheetah support to the flashrom mailing list. You may be interested in subscribing to the flashrom list: http://www.flashrom.org/mailman/listinfo/flashrom
Right not I just would not have time to stay current. If there's a specific cheetah thread then you can point it out and I'll check the archives. Perhaps I should add the list to my mail with a filter on the word cheetah.
Your choice. If you prefer to be in CC if I send any Cheetah patches, I can do that. No need to subscribe. I have whitelisted you as sender for the mailing list, so your mails will end up on the list without delay/moderation.
The patch is available for download here: http://patchwork.coreboot.org/patch/596/raw/
Is there anything I can test with this patch? I've enabled cheetah support in the makefile but If I change the #if 0 in cheetah_spi_comand I get compile errors.
That's sort of expected. I wrote a support stub (doesn't compile yet, needs a good way to detect headers) a few months ago, and then I forward ported the patch again and again. I posted the patch now because I wanted to gauge interest before I invest any more time into making it actually work. I don't have the hardware, so someone will need to test.
The cheetah libraries have an apparently GPL-incompatible header license (that's why I didn't develop further back then). It seems their API documentation doesn't mention any licensing restrictions for the API itself, so it should be possible to develop against the API without any major problems. The cheetah lib itself is a legal nightmare and it is entirely possible that flashrom may only use it if flashrom supports no other programmers (a lawyer needs to check this).
Also I'll need some sort of switch to enable the target voltage of the programmer.
Yes, hardware initialization is missing completely.
If flashrom support is still a worthwhile target from your point of view, I'll contact TotalPhase about the licensing of the headers/libraries (or give you a short summary what to ask if you want to contact them yourself as you're their customer and I'm not).
Regards, Carl-Daniel