Patchwork Ponyprog2000 like hardware programmer, another try.

login
register
about
Submitter Virgil-Adrian Teaca
Date 2012-04-20 20:16:31
Message ID <CAOfppk5_zLAYpg5iMir=nBW51uy85CF4MtfcKaCD7mkapZH=XA@mail.gmail.com>
Download mbox | patch
Permalink /patch/3600/
State Superseded
Headers show

Comments

Virgil-Adrian Teaca - 2012-04-20 20:16:31
Hello,

there is another patch. Still, not works.
Binary files flashrom.orig/.svn/wc.db and flashrom/.svn/wc.db differ

Patch

diff -urN flashrom.orig/Makefile flashrom/Makefile
--- flashrom.orig/Makefile	2012-04-20 12:17:31.000000000 +0200
+++ flashrom/Makefile	2012-04-20 21:46:07.196044425 +0200
@@ -122,6 +122,11 @@ 
 else
 override CONFIG_RAYER_SPI = no
 endif
+ifeq ($(CONFIG_PONY_SPI), yes)
+UNSUPPORTED_FEATURES += CONFIG_PONY_SPI=yes
+else
+override CONFIG_PONY_SPI = no
+endif
 ifeq ($(CONFIG_NIC3COM), yes)
 UNSUPPORTED_FEATURES += CONFIG_NIC3COM=yes
 else
@@ -246,6 +251,11 @@ 
 else
 override CONFIG_RAYER_SPI = no
 endif
+ifeq ($(CONFIG_PONY_SPI), yes)
+UNSUPPORTED_FEATURES += CONFIG_PONY_SPI=yes
+else
+override CONFIG_PONY_SPI = no
+endif
 ifeq ($(CONFIG_ATAHPT), yes)
 UNSUPPORTED_FEATURES += CONFIG_ATAHPT=yes
 else
@@ -292,6 +302,9 @@ 
 # RayeR SPIPGM hardware support
 CONFIG_RAYER_SPI ?= yes
 
+# PonyProg2000 SPI hardware support
+CONFIG_PONY_SPI ?= yes
+
 # Always enable 3Com NICs for now.
 CONFIG_NIC3COM ?= yes
 
@@ -348,6 +361,9 @@ 
 ifeq ($(CONFIG_RAYER_SPI), yes)
 override CONFIG_BITBANG_SPI = yes
 else
+ifeq ($(CONFIG_PONY_SPI), yes)
+override CONFIG_BITBANG_SPI = yes
+else
 ifeq ($(CONFIG_INTERNAL), yes)
 override CONFIG_BITBANG_SPI = yes
 else
@@ -362,6 +378,7 @@ 
 endif
 endif
 endif
+endif
 
 ifeq ($(CONFIG_INTERNAL), yes)
 FEATURE_CFLAGS += -D'CONFIG_INTERNAL=1'
@@ -388,6 +405,11 @@ 
 NEED_PCI := yes
 endif
 
+ifeq ($(CONFIG_PONY_SPI), yes)
+FEATURE_CFLAGS += -D'CONFIG_PONY_SPI=1'
+PROGRAMMER_OBJS += pony_spi.o
+endif
+
 ifeq ($(CONFIG_BITBANG_SPI), yes)
 FEATURE_CFLAGS += -D'CONFIG_BITBANG_SPI=1'
 PROGRAMMER_OBJS += bitbang_spi.o
diff -urN flashrom.orig/flashrom.c flashrom/flashrom.c
--- flashrom.orig/flashrom.c	2012-02-26 11:12:57.000000000 +0100
+++ flashrom/flashrom.c	2012-04-20 18:07:32.284467707 +0200
@@ -201,6 +201,16 @@ 
 	},
 #endif
 
+#if CONFIG_PONY_SPI == 1
+	{
+		.name			= "pony_spi",
+		.init			= pony_spi_init,
+		.map_flash_region	= fallback_map,
+		.unmap_flash_region	= fallback_unmap,
+		.delay			= internal_delay,
+},
+#endif
+
 #if CONFIG_NICINTEL == 1
 	{
 		.name			= "nicintel",
diff -urN flashrom.orig/pony_spi.c flashrom/pony_spi.c
--- flashrom.orig/pony_spi.c	1970-01-01 01:00:00.000000000 +0100
+++ flashrom/pony_spi.c	2012-04-20 22:10:53.271245666 +0200
@@ -0,0 +1,190 @@ 
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2012 Virgil-Adrian Teaca
+ *
+ * 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.
+ *
+ * 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
+ */
+
+/* Driver for the SI-Prog like hardware by Lancos.com.
+ * See http://www.lancos.com/siprogsch.html for schematics and instructions.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include "flash.h"
+#include "programmer.h"
+
+/* We have:
+ *
+ * MOSI  -> DTR
+ * MISO  -> CTS (negated value)
+ * SCK   -> RTS
+ * CS#   -> TXD
+ *
+ */
+
+static struct termios initial_settings, tio;
+
+fdtype serial_fd;
+
+static void pony_bitbang_set_cs(int val)
+{
+	ioctl( serial_fd, val ? TIOCSBRK : TIOCCBRK, 0 );
+}
+
+static void pony_bitbang_set_sck(int val)
+{
+	int s;
+
+	ioctl( serial_fd, TIOCMGET, &s );
+
+	if( val ) {
+		s|= TIOCM_RTS;
+	}
+	else {
+		s &= ~TIOCM_RTS;
+	}
+
+	ioctl( serial_fd, TIOCMSET, &s );
+}
+
+static void pony_bitbang_set_mosi( int val )
+{
+	int s;
+
+	ioctl(serial_fd, TIOCMGET, &s);
+
+	if(val) {
+		s|= TIOCM_DTR;
+	}
+	else {
+		s&=~ TIOCM_DTR;
+	}
+
+	ioctl( serial_fd, TIOCMSET, &s );
+}
+
+static int pony_bitbang_get_miso(void)
+{
+  	/* Note that MISO is negated by the programmer. */
+	int s, tmp;
+
+	ioctl( serial_fd, TIOCMGET, &s );
+
+	tmp = ! ( s & TIOCM_CTS);
+
+	return tmp;
+}
+
+static const struct bitbang_spi_master bitbang_spi_master_pony = {
+	.type = BITBANG_SPI_MASTER_PONY,
+	.set_cs = pony_bitbang_set_cs,
+	.set_sck = pony_bitbang_set_sck,
+	.set_mosi = pony_bitbang_set_mosi,
+	.get_miso = pony_bitbang_get_miso,
+	.half_period = 0,
+};
+
+static int pony_shutdown(void *data)
+{
+	tcsetattr (serial_fd, TCSANOW, &initial_settings);
+
+	close(serial_fd);
+
+	return 0;
+}
+
+static fdtype pony_open_device(char *dev, unsigned int baud)
+{
+	fdtype fd = open(dev, O_RDWR);
+
+	if (fd == -1)
+	{
+	  	msg_perr("Error: cannot open device %s\n", dev);
+
+		exit(1);
+	}
+
+	tcgetattr (fd, &initial_settings);
+
+	tio = initial_settings;
+
+	tio.c_iflag = IGNBRK | IGNPAR;
+	tio.c_oflag = 0;
+	tio.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
+	tio.c_lflag = 0;
+
+	tcsetattr (fd, TCSANOW, &tio);
+
+	return fd;
+}
+
+int pony_spi_init(void)
+{
+	char *device;
+	char *baudport;
+	int have_device = 0;
+
+	/* the parameter is on format "dev=/dev/device:baud" */
+	device = extract_programmer_param("dev");
+	if (device && strlen(device)) {
+		baudport = strstr(device, ":");
+		if (baudport) {
+			/* Split device from baudrate. */
+			*baudport = '\0';
+			baudport++;
+		}
+		if (!baudport || !strlen(baudport)) {
+			msg_perr("Error: No baudrate specified.\n"
+				 "Use flashrom -p pony_spi:dev=/dev/device:baud\n");
+			free(device);
+			return 1;
+		}
+		if (strlen(device)) {
+			serial_fd = pony_open_device(device, atoi(baudport));
+			have_device++;
+		}
+	}
+	if (device && !strlen(device)) {
+		msg_perr("Error: No device specified.\n"
+			 "Use flashrom -p pony_spi:dev=/dev/device:baud\n");
+		free(device);
+		return 1;
+	}
+	free(device);
+
+	if (!have_device) {
+		msg_perr("Error: No device specified.\n"
+			 "Use flashrom -p pony_spi:dev=/dev/device:baud\n");
+		return 1;
+	}
+
+	if (register_shutdown(pony_shutdown, NULL))
+		return 1;
+
+	/* Get the initial value before writing to any line. */
+
+	if (bitbang_spi_init(&bitbang_spi_master_pony))
+		return 1;
+
+	return 0;
+}
diff -urN flashrom.orig/programmer.h flashrom/programmer.h
--- flashrom.orig/programmer.h	2012-03-13 16:52:50.000000000 +0100
+++ flashrom/programmer.h	2012-04-20 18:27:12.852629967 +0200
@@ -69,6 +69,9 @@ 
 #if CONFIG_RAYER_SPI == 1
 	PROGRAMMER_RAYER_SPI,
 #endif
+#if CONFIG_PONY_SPI == 1
+	PROGRAMMER_PONY_SPI,
+#endif
 #if CONFIG_NICINTEL == 1
 	PROGRAMMER_NICINTEL,
 #endif
@@ -110,6 +113,9 @@ 
 #if CONFIG_RAYER_SPI == 1
 	BITBANG_SPI_MASTER_RAYER,
 #endif
+#if CONFIG_PONY_SPI == 1
+	BITBANG_SPI_MASTER_PONY,
+#endif
 #if CONFIG_NICINTEL_SPI == 1
 	BITBANG_SPI_MASTER_NICINTEL,
 #endif
@@ -430,6 +436,11 @@ 
 int rayer_spi_init(void);
 #endif
 
+/* pony_spi.c */
+#if CONFIG_PONY_SPI == 1
+int pony_spi_init(void);
+#endif
+
 /* bitbang_spi.c */
 int bitbang_spi_init(const struct bitbang_spi_master *master);