Secret knowledge is cool, but public knowledge is better.
Implement all Dediprog commands found in USB traces, even if their
purpose is not yet known.
Annotate unknown commands with info about the call sequence they are
embedded in and the firmware version of the log.
Add a new shutdown command for firmware 5.x.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006(a)gmx.net>
Index: flashrom-dediprog_unknown_commands/dediprog.c
===================================================================
--- flashrom-dediprog_unknown_commands/dediprog.c (Revision 1232)
+++ flashrom-dediprog_unknown_commands/dediprog.c (Arbeitskopie)
@@ -27,6 +27,7 @@
#define DEFAULT_TIMEOUT 3000
static usb_dev_handle *dediprog_handle;
+static int dediprog_firmwareversion;
#if 0
/* Might be useful for other pieces of code as well. */
@@ -228,6 +229,7 @@
fw[1], fw[2]);
return 1;
}
+ dediprog_firmwareversion = fw[0];
return 0;
}
@@ -253,6 +255,32 @@
return 0;
}
+#if 0
+/* Something.
+ * Present in eng_detect_blink.log with firmware 3.1.8
+ * Always preceded by Command Receive Device String
+ */
+static int dediprog_command_b(void)
+{
+ int ret;
+ char buf[0x3];
+
+ memset(buf, 0, sizeof(buf));
+ ret = usb_control_msg(dediprog_handle, 0xc3, 0x7, 0x0, 0xef00, buf, 0x3, DEFAULT_TIMEOUT);
+ if (ret < 0) {
+ msg_perr("Command B failed (%s)!\n", usb_strerror());
+ return 1;
+ }
+ if ((ret != 0x3) || (buf[0] != 0xff) || (buf[1] != 0xff) ||
+ (buf[2] != 0xff)) {
+ msg_perr("Unexpected response to Command B!\n");
+ return 1;
+ }
+
+ return 0;
+}
+#endif
+
/* Command C is only sent after dediprog_check_devicestring, but not after every
* invocation of dediprog_check_devicestring. It is only sent after the first
* dediprog_command_a(); dediprog_check_devicestring() sequence in each session.
@@ -264,7 +292,7 @@
ret = usb_control_msg(dediprog_handle, 0x42, 0x4, 0x0, 0x0, NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) {
- msg_perr("Unexpected response to Command C!\n");
+ msg_perr("Command C failed (%s)!\n", usb_strerror());
return 1;
}
return 0;
@@ -274,6 +302,7 @@
/* Very strange. Seems to be a programmer keepalive or somesuch.
* Wait unsuccessfully for timeout ms to read one byte.
* Is usually called after setting voltage to 0.
+ * Present in all logs with Firmware 2.1.1 and 3.1.8
*/
static int dediprog_command_f(int timeout)
{
@@ -282,14 +311,90 @@
memset(buf, 0, sizeof(buf));
ret = usb_control_msg(dediprog_handle, 0xc2, 0x11, 0xff, 0xff, buf, 0x1, timeout);
+ /* This check is most probably wrong. Command F always causes a timeout
+ * in the logs, so we should check for timeout instead of checking for
+ * success.
+ */
+ if (ret != 0x1) {
+ msg_perr("Command F failed (%s)!\n", usb_strerror());
+ return 1;
+ }
+ return 0;
+}
+
+/* Start/stop blinking?
+ * Present in eng_detect_blink.log with firmware 3.1.8
+ * Preceded by Command J
+ */
+static int dediprog_command_g(void)
+{
+ int ret;
+
+ ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x03, NULL, 0x0, DEFAULT_TIMEOUT);
if (ret != 0x0) {
- msg_perr("Unexpected response to Command F!\n");
+ msg_perr("Command G failed (%s)!\n", usb_strerror());
return 1;
}
return 0;
}
+
+/* Something.
+ * Present in all logs with firmware 5.1.5
+ * Always preceded by Command Receive Device String
+ * Always followed by Command Set SPI Voltage nonzero
+ */
+static int dediprog_command_h(void)
+{
+ int ret;
+
+ ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x05, NULL, 0x0, DEFAULT_TIMEOUT);
+ if (ret != 0x0) {
+ msg_perr("Command H failed (%s)!\n", usb_strerror());
+ return 1;
+ }
+ return 0;
+}
#endif
+/* Shutdown for firmware 5.x?
+ * Present in all logs with firmware 5.1.5
+ * Often preceded by a SPI operation (Command Read SPI Bulk or Receive SPI)
+ * Always followed by Command Set SPI Voltage 0x0000
+ */
+static int dediprog_command_i(void)
+{
+ int ret;
+
+ ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x06, NULL, 0x0, DEFAULT_TIMEOUT);
+ if (ret != 0x0) {
+ msg_perr("Command I failed (%s)!\n", usb_strerror());
+ return 1;
+ }
+ return 0;
+}
+
+#if 0
+/* Start/stop blinking?
+ * Present in all logs with firmware 5.1.5
+ * Always preceded by Command Receive Device String on 5.1.5
+ * Always followed by Command Set SPI Voltage nonzero on 5.1.5
+ * Present in eng_detect_blink.log with firmware 3.1.8
+ * Preceded by Command B in eng_detect_blink.log
+ * Followed by Command G in eng_detect_blink.log
+ */
+static int dediprog_command_j(void)
+{
+ int ret;
+
+ ret = usb_control_msg(dediprog_handle, 0x42, 0x07, 0x09, 0x07, NULL, 0x0, DEFAULT_TIMEOUT);
+ if (ret != 0x0) {
+ msg_perr("Command J failed (%s)!\n", usb_strerror());
+ return 1;
+ }
+ return 0;
+}
+#endif
+
static int parse_voltage(char *voltage)
{
char *tmp = NULL;
@@ -445,9 +550,11 @@
/* URB 136 is just URB 9. */
/* URB 137 is just URB 11. */
- /* Command I is probably Start Bulk Read. Data is u16 blockcount, u16 blocksize. */
- /* Command J is probably Start Bulk Write. Data is u16 blockcount, u16 blocksize. */
- /* Bulk transfer sizes for Command I/J are always 512 bytes, rest is filled with 0xff. */
+ /* Command Start Bulk Read. Data is u16 blockcount, u16 blocksize. */
+ /* Command Start Bulk Write. Data is u16 blockcount, u16 blocksize. */
+ /* Bulk transfer sizes for Command Start Bulk Read/Write are always
+ * 512 bytes, rest is filled with 0xff.
+ */
return 0;
}
@@ -457,6 +564,10 @@
{
msg_pspew("%s\n", __func__);
+ /* Shutdown on firmware 5.x */
+ if (dediprog_firmwareversion == 5)
+ if (dediprog_command_i())
+ return 1;
/* URB 28. Command Set SPI Voltage to 0. */
if (dediprog_set_spi_voltage(0x0))
return 1;
--
http://www.hailfinger.org/
I have just tested the following patch:
http://patchwork.coreboot.org/patch/3469/
which I applied to flashrom r1472.
It is fantastic!
I can now program and verify a M25P16 in just 15 seconds. Every
bit as fast as the Windows app.
One comment about the patch. The first change (to lines 30,6)
should be removed, because it adds a duplicate copy of the
statement "static int dediprog_firmwareversion;" Other than
that, the patch looks fine to me.
Here is the bit that should be removed from the patch:
@@ -30,6 +30,7 @@
static usb_dev_handle *dediprog_handle;
static int dediprog_firmwareversion;
static int dediprog_endpoint;
+static int dediprog_firmwareversion;
#if 0
/* Might be useful for other pieces of code as well. */
Therefore:
Acked-by: Steven A. Falco <sfalco(a)coincident.com>
Am 19.12.2011 23:15 schrieb David Hendricks:
> On Fri, Dec 16, 2011 at 11:06 AM, Carl-Daniel Hailfinger <
> c-d.hailfinger.devel.2006(a)gmx.net> wrote:
>
>> Am 09.12.2011 05:02 schrieb David Hendricks:
>>> On Thu, Dec 8, 2011 at 12:18 PM, Carl-Daniel Hailfinger <
>>> c-d.hailfinger.devel.2006(a)gmx.net> wrote:
>>>
>>>>> Most likely no arm support?
>>>> Indeed, ARM support is missing. I think it is mainy held back by libpci
>>>> breakage for which we only have a really hackish workaround.
>>> For what it's worth, when I tested the patch earlier it worked on ARM
>> with
>>> that libpci hack.
>> The patch has been tested natively on FreeBSD, MinGW, Linux,
>> DragonFlyBSD, with gcc and clang, cross-compiled with clang on Linux for
>> Windows, cross-compiled with DJGPP on Linux for DOS, cross-compiled on
>> Linux for MinGW, natively on Linux PowerPC, ....
>>
>> Ack anyone?
>>
> Acked-by: David Hendricks <dhendrix(a)google.com>
Thanks, committed in r1476.
Regards,
Carl-Daniel
--
http://www.hailfinger.org/
Author: hailfinger
Date: Tue Dec 20 01:51:44 2011
New Revision: 1476
URL: http://flashrom.org/trac/flashrom/changeset/1476
Log:
Cross-compilation fixes
Switch from host OS detection to target OS detection.
Complain about unknown target OS/architecture.
Disable annoying format string warnings on DJGPP.
Native and cross-compilation now usually just require setting CC.
Examples:
make CC=i586-pc-msdosdjgpp-gcc
make CC="clang -m64"
make CC=i686-w64-mingw32-gcc
Tested for a boatload of native and cross compilation configurations.
There is a new target "make libpayload" in case you don't want to
specify all tools by hand.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006(a)gmx.net>
Acked-by: David Hendricks <dhendrix(a)google.com>
Added:
trunk/os.h
Modified:
trunk/Makefile
Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile Tue Dec 20 01:19:29 2011 (r1475)
+++ trunk/Makefile Tue Dec 20 01:51:44 2011 (r1476)
@@ -37,27 +37,40 @@
CFLAGS += -Werror
endif
-# FIXME We have to differentiate between host and target OS architecture.
-OS_ARCH ?= $(shell uname)
-ifneq ($(OS_ARCH), SunOS)
+# HOST_OS is only used to work around local toolchain issues.
+HOST_OS ?= $(shell uname)
+ifeq ($(HOST_OS), MINGW32_NT-5.1)
+# Explicitly set CC = gcc on MinGW, otherwise: "cc: command not found".
+CC = gcc
+endif
+ifneq ($(HOST_OS), SunOS)
STRIP_ARGS = -s
endif
-ifeq ($(OS_ARCH), Darwin)
+
+# Determine the destination processor architecture.
+# IMPORTANT: The following line must be placed before TARGET_OS is ever used
+# (of course), but should come after any lines setting CC because the line
+# below uses CC itself.
+override TARGET_OS := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E os.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
+
+ifeq ($(TARGET_OS), Darwin)
CPPFLAGS += -I/opt/local/include -I/usr/local/include
# DirectHW framework can be found in the DirectHW library.
LDFLAGS += -framework IOKit -framework DirectHW -L/opt/local/lib -L/usr/local/lib
endif
-ifeq ($(OS_ARCH), FreeBSD)
+ifeq ($(TARGET_OS), FreeBSD)
CPPFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib
endif
-ifeq ($(OS_ARCH), OpenBSD)
+ifeq ($(TARGET_OS), OpenBSD)
CPPFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib
endif
-ifeq ($(OS_ARCH), DOS)
+ifeq ($(TARGET_OS), DOS)
EXEC_SUFFIX := .exe
CPPFLAGS += -I../libgetopt -I../libpci/include
+# DJGPP has odd uint*_t definitions which cause lots of format string warnings.
+CPPFLAGS += -Wno-format
# FIXME Check if we can achieve the same effect with -L../libgetopt -lgetopt
LIBS += ../libgetopt/libgetopt.a
# Bus Pirate and Serprog are not supported under DOS (missing serial support).
@@ -84,9 +97,9 @@
endif
endif
-ifeq ($(OS_ARCH), MINGW32_NT-5.1)
-# Explicitly set CC = gcc on MinGW, otherwise: "cc: command not found".
-CC = gcc
+# FIXME: Should we check for Cygwin/MSVC as well?
+ifeq ($(TARGET_OS), MinGW)
+EXEC_SUFFIX := .exe
# MinGW doesn't have the ffs() function, but we can use gcc's __builtin_ffs().
CFLAGS += -Dffs=__builtin_ffs
# libusb-win32/libftdi stuff is usually installed in /usr/local.
@@ -166,10 +179,7 @@
endif
endif
-ifeq ($(OS_ARCH), libpayload)
-CC:=CC=i386-elf-gcc lpgcc
-AR:=i386-elf-ar
-RANLIB:=i386-elf-ranlib
+ifeq ($(TARGET_OS), libpayload)
CPPFLAGS += -DSTANDALONE
ifeq ($(CONFIG_DUMMY), yes)
UNSUPPORTED_FEATURES += CONFIG_DUMMY=yes
@@ -202,10 +212,10 @@
# Determine the destination processor architecture.
# IMPORTANT: The following line must be placed before ARCH is ever used
# (of course), but should come after any lines setting CC because the line
-# below uses CC itself. In some cases we set CC based on OS_ARCH, see above.
-override ARCH := $(strip $(shell LC_ALL=C $(CC) -E arch.h 2>/dev/null | grep -v '^\#'))
+# below uses CC itself.
+override ARCH := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E arch.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"'))
-ifeq ($(ARCH), "ppc")
+ifeq ($(ARCH), ppc)
# There's no PCI port I/O support on PPC/PowerPC, yet.
ifeq ($(CONFIG_NIC3COM), yes)
UNSUPPORTED_FEATURES += CONFIG_NIC3COM=yes
@@ -348,7 +358,7 @@
ifeq ($(CONFIG_INTERNAL), yes)
FEATURE_CFLAGS += -D'CONFIG_INTERNAL=1'
PROGRAMMER_OBJS += processor_enable.o chipset_enable.o board_enable.o cbtable.o dmi.o internal.o
-ifeq ($(ARCH),"x86")
+ifeq ($(ARCH), x86)
PROGRAMMER_OBJS += it87spi.o it85spi.o sb600spi.o wbsio_spi.o mcp6x_spi.o
PROGRAMMER_OBJS += ichspi.o ich_descriptors.o
else
@@ -476,7 +486,7 @@
endif
ifeq ($(NEED_NET), yes)
-ifeq ($(OS_ARCH), SunOS)
+ifeq ($(TARGET_OS), SunOS)
LIBS += -lsocket
endif
endif
@@ -485,18 +495,18 @@
CHECK_LIBPCI = yes
FEATURE_CFLAGS += -D'NEED_PCI=1'
PROGRAMMER_OBJS += pcidev.o physmap.o hwaccess.o
-ifeq ($(OS_ARCH), NetBSD)
+ifeq ($(TARGET_OS), NetBSD)
# The libpci we want is called libpciutils on NetBSD and needs NetBSD libpci.
LIBS += -lpciutils -lpci
# For (i386|x86_64)_iopl(2).
LIBS += -l$(shell uname -p)
else
-ifeq ($(OS_ARCH), DOS)
+ifeq ($(TARGET_OS), DOS)
# FIXME There needs to be a better way to do this
LIBS += ../libpci/lib/libpci.a
else
LIBS += -lpci
-ifeq ($(OS_ARCH), OpenBSD)
+ifeq ($(TARGET_OS), OpenBSD)
# For (i386|amd64)_iopl(2).
LIBS += -l$(shell uname -m)
endif
@@ -564,11 +574,16 @@
echo "found." || ( echo "not found."; \
rm -f .test.c .test$(EXEC_SUFFIX); exit 1)
@rm -f .test.c .test$(EXEC_SUFFIX)
- @printf "ARCH is "
+ @printf "Target arch is "
@# FreeBSD wc will output extraneous whitespace.
- @echo $(ARCH)|wc -l|grep -q '^[[:blank:]]*1[[:blank:]]*$$' || \
+ @echo $(ARCH)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' || \
( echo "unknown. Aborting."; exit 1)
@printf "%s\n" '$(ARCH)'
+ @printf "Target OS is "
+ @# FreeBSD wc will output extraneous whitespace.
+ @echo $(TARGET_OS)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' || \
+ ( echo "unknown. Aborting."; exit 1)
+ @printf "%s\n" '$(TARGET_OS)'
define LIBPCI_TEST
/* Avoid a failing test due to libpci header symbol shadowing breakage */
@@ -684,7 +699,9 @@
@echo Created $(EXPORTDIR)/flashrom-$(RELEASENAME).tar.bz2
djgpp-dos: clean
- make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip WARNERROR=no OS_ARCH=DOS
+ make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip
+libpayload: clean
+ make CC="CC=i386-elf-gcc lpgcc" AR=i386-elf-ar RANLIB=i386-elf-ranlib
.PHONY: all clean distclean compiler pciutils features export tarball dos featuresavailable
Added: trunk/os.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/os.h Tue Dec 20 01:51:44 2011 (r1476)
@@ -0,0 +1,58 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2011 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.
+ *
+ * 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
+ */
+
+/*
+ * Header file for OS checking.
+ */
+
+// Solaris
+#if defined (__sun) && (defined(__i386) || defined(__amd64))
+#define __FLASHROM_OS__ "SunOS"
+// OS X
+#elif defined(__MACH__) && defined(__APPLE__)
+#define __FLASHROM_OS__ "Darwin"
+// FreeBSD
+#elif defined(__FreeBSD__)
+#define __FLASHROM_OS__ "FreeBSD"
+// DragonFlyBSD
+#elif defined(__DragonFly__)
+#define __FLASHROM_OS__ "DragonFlyBSD"
+// NetBSD
+#elif defined(__NetBSD__)
+#define __FLASHROM_OS__ "NetBSD"
+// OpenBSD
+#elif defined(__OpenBSD__)
+#define __FLASHROM_OS__ "OpenBSD"
+// DJGPP
+#elif defined(__DJGPP__)
+#define __FLASHROM_OS__ "DOS"
+// MinGW (always has _WIN32 available)
+#elif defined(__MINGW32__)
+#define __FLASHROM_OS__ "MinGW"
+// Cygwin (usually without _WIN32)
+#elif defined( __CYGWIN__)
+#define __FLASHROM_OS__ "Cygwin"
+// libpayload
+#elif defined(__LIBPAYLOAD__)
+#define __FLASHROM_OS__ "libpayload"
+// Linux
+#elif defined(__linux__)
+#define __FLASHROM_OS__ "Linux"
+#endif
+__FLASHROM_OS__
Am 09.12.2011 05:02 schrieb David Hendricks:
> On Thu, Dec 8, 2011 at 12:18 PM, Carl-Daniel Hailfinger <
> c-d.hailfinger.devel.2006(a)gmx.net> wrote:
>
>>> Most likely no arm support?
>> Indeed, ARM support is missing. I think it is mainy held back by libpci
>> breakage for which we only have a really hackish workaround.
>
> For what it's worth, when I tested the patch earlier it worked on ARM with
> that libpci hack.
The patch has been tested natively on FreeBSD, MinGW, Linux,
DragonFlyBSD, with gcc and clang, cross-compiled with clang on Linux for
Windows, cross-compiled with DJGPP on Linux for DOS, cross-compiled on
Linux for MinGW, natively on Linux PowerPC, ....
Ack anyone?
Regards,
Carl-Daniel
--
http://www.hailfinger.org/